Skip to content

Commit

Permalink
ModelExplorer: defined vars #232
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Mar 19, 2024
1 parent ea37f1d commit 9646be4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
21 changes: 18 additions & 3 deletions CHANGES.mp.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@ Summary of recent updates to the AMPL MP Library
================================================


## unreleased
## 20240319
- *SOS constraints*.
- Fixed handling of SOS2 constraints created by AMPL
as reformulations of PL expressions (`option
pl_linearize 1`, default; set to 0 to use the solver's
native PL functions if supported, or MP linearization.)
- Disallow repeated weights for SOS constraints
(suffixes `.sosno`/`.ref`.)
- *Reformulation explorer*.
- Upgraded option `writegraph` exports the reformulation
graph which can be explored with the script in
support/modelexplore (WIP.)
- *Native handling of POW(x, INT)*.
- Power expressions with positive integer exponent
are passed natively to the solvers accepting them,
vs previously quadratic or linear reformulation.
- For best performance, global solving capability
might be needed (e.g., Gurobi: `global=1`.)
- *Unused acc: options*.
- The constraint acceptance options *acc:...*
- *Option `report_times`*.
- *Unused `acc:` options*.
- The constraint acceptance options `acc:...`
for non-handled constraints are ignored
(previously triggered error.)
- *NLWPY*.
- Python NL Writer API for MIQP models.
- Available on PyPI.


## 20240115
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ endif() ## NOT SKIP_BUILD_MP
include_directories(include)

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(MP_DATE 20240115)
set(MP_DATE 20240319)

set(MP_SYSINFO "${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}")

Expand Down
6 changes: 1 addition & 5 deletions src/expr-writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,7 @@ void ExprWriter<ExprTypes, VN>::VisitPLTerm(PLTerm e) {
for (int i = 1, n = e.num_slopes(); i < n; ++i)
writer_ << ", " << e.slope(i);
writer_ << ">> ";
NumericExpr arg = e.arg();
if (Variable var = ExprTypes::template Cast<Variable>(arg))
writer_ << "x" << (var.index() + 1);
else
writer_ << "e" << ((ExprTypes::template Cast<CommonExpr>(arg)).index() + 1);
Visit( e.arg() );
}

template <typename ExprTypes, typename VN>
Expand Down
5 changes: 5 additions & 0 deletions support/modelexplore/scripts/python/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self):
self._graph = DiGraph() ## Underlyng graph

self._vars = [] ## Pointers to various parts of the graph
self._dvars = []
self._cons_NL_all = []
self._cons_NL = { ## NL + SOS
"All" : [],
Expand All @@ -31,6 +32,9 @@ def __init__(self):
def UpdateVar(self, idx, data):
self._updateNodeData(self._vars, idx, data)

def UpdateDefVar(self, idx, data):
self._updateNodeData(self._dvars, idx, data)

def UpdateNLObj(self, idx, data):
self._updateNodeData(self._objs_NL, idx, data)

Expand Down Expand Up @@ -75,6 +79,7 @@ def _updateMap(self, data1, data2):
def MatchOrigModel(self, keyw):
result = {}
result["NL Variables"] = self._matchRecords(self._vars, keyw, "is_from_nl")
result["NL Defined Variables"] = self._matchRecords(self._dvars, keyw)
result["NL Objectives"] = self._matchRecords(self._objs_NL, keyw)
result["NL Constraints"] \
= self._matchRecords(self._cons_NL.get("All"), keyw)
Expand Down
2 changes: 2 additions & 0 deletions support/modelexplore/scripts/python/modelreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def _processLine(self, line: str):
def _addDataChunk(self, chunk):
if "VAR_index" in chunk:
self._model.UpdateVar(chunk["VAR_index"], chunk)
elif "NL_COMMON_EXPR_index" in chunk:
self._model.UpdateDefVar(chunk["NL_COMMON_EXPR_index"], chunk)
elif "NL_OBJECTIVE_index" in chunk:
self._model.UpdateNLObj(chunk["NL_OBJECTIVE_index"], chunk)
elif "NL_CON_TYPE" in chunk:
Expand Down

0 comments on commit 9646be4

Please sign in to comment.