Skip to content

Commit

Permalink
ModelExplorer: write SOS #232
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Mar 19, 2024
1 parent 89f0ba0 commit ea37f1d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion include/mp/flat/constr_keeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,15 @@ class ConstraintKeeper final
cons_[i].con_.SetName(vn[i].MakeCurrentName());
}

/// ForEachActive().
/// Copy names to ValueNodes
void CopyNames2ValueNodes() {
auto& vn = GetValueNode().GetStrVec();
assert(vn.size()==cons_.size());
for (auto i=vn.size(); i--; )
vn[i] = std::string(cons_[i].con_.name());
}

/// ForEachActive().
/// Deletes every constraint where fn() returns true.
template <class Fn>
void ForEachActive(Fn fn) {
Expand Down
9 changes: 9 additions & 0 deletions include/mp/flat/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ class FlatConverter :
if (var_names_.size()) {
/// Check that constr / obj names are present too?
GetValuePresolver().CleanUpNameNodes();
// They are at top level of the reformulation tree
TransferNames2Node((SOS1Constraint*)nullptr);
TransferNames2Node((SOS2Constraint*)nullptr);
auto vm = GetValuePresolver().
PresolveNames({
{var_names_},
Expand All @@ -557,6 +560,12 @@ class FlatConverter :
}
}

template <class Con>
void TransferNames2Node(Con* pcon) {
auto& ck = GetConstraintKeeper(pcon);
ck.CopyNames2ValueNodes();
}

/// Fill model traits for license check.
/// To be called after ConvertModel().
/// KEEP THIS UP2DATE.
Expand Down
5 changes: 4 additions & 1 deletion include/mp/valcvt-node.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ class ValueNode {
/// Retrieve whole vector<VCString&>&
operator const std::vector<VCString>& () const { return vStr_; }

/// Retrieve whole vector<VCString&>&
/// Retrieve whole const vector<VCString&>&
const std::vector<VCString>& GetStrVec() const { return vStr_; }

/// Retrieve whole vector<VCString&>&
std::vector<VCString>& GetStrVec() { return vStr_; }


/////////////////////// Access individual values ///////////////////////

Expand Down

0 comments on commit ea37f1d

Please sign in to comment.