diff --git a/include/mp/flat/constr_keeper.h b/include/mp/flat/constr_keeper.h index 41b61c05f..28393b2ee 100644 --- a/include/mp/flat/constr_keeper.h +++ b/include/mp/flat/constr_keeper.h @@ -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 void ForEachActive(Fn fn) { diff --git a/include/mp/flat/converter.h b/include/mp/flat/converter.h index ccad7aeff..879c02d02 100644 --- a/include/mp/flat/converter.h +++ b/include/mp/flat/converter.h @@ -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_}, @@ -557,6 +560,12 @@ class FlatConverter : } } + template + void TransferNames2Node(Con* pcon) { + auto& ck = GetConstraintKeeper(pcon); + ck.CopyNames2ValueNodes(); + } + /// Fill model traits for license check. /// To be called after ConvertModel(). /// KEEP THIS UP2DATE. diff --git a/include/mp/valcvt-node.h b/include/mp/valcvt-node.h index 1afd4309d..fca26fb3b 100644 --- a/include/mp/valcvt-node.h +++ b/include/mp/valcvt-node.h @@ -208,9 +208,12 @@ class ValueNode { /// Retrieve whole vector& operator const std::vector& () const { return vStr_; } - /// Retrieve whole vector& + /// Retrieve whole const vector& const std::vector& GetStrVec() const { return vStr_; } + /// Retrieve whole vector& + std::vector& GetStrVec() { return vStr_; } + /////////////////////// Access individual values ///////////////////////