Skip to content

Commit

Permalink
Redefine Not by a linear expr
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Aug 28, 2024
1 parent ea950a1 commit 6e6c366
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions include/mp/flat/redef/MIP/logical_not.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ class NotConverter_MIP :

/// Convert in both contexts (full reification)
void Convert(const ItemType& nc, int ) {
/// Obtain negation variable via map
int var_res_lin = GetMC().AssignResultVar2Args(
LinearFunctionalConstraint(
{{{-1.0}, {nc.GetArguments()[0]}}, 1.0}));
GetMC().AddConstraint_AS_ROOT(LinConEQ{ // Could use RedefineVariable()
{ {-1.0, 1.0},
{nc.GetResultVar(), var_res_lin} },
{0.0}});
LinearFunctionalConstraint funccon {{{{-1.0}, {nc.GetArguments()[0]}}, 1.0}};
funccon.SetContext( GetMC().GetInitExprContext(nc.GetResultVar()) );
GetMC().RedefineVariable(nc.GetResultVar(), std::move(funccon));
// Old way, no expression: /// Obtain negation variable via map
// int var_res_lin = GetMC().AssignResultVar2Args(
// LinearFunctionalConstraint(
// {{{-1.0}, {nc.GetArguments()[0]}}, 1.0}));
// GetMC().AddConstraint_AS_ROOT(LinConEQ{ // Could use RedefineVariable()
// { {-1.0, 1.0},
// {nc.GetResultVar(), var_res_lin} },
// {0.0}});
}

/// Reuse the stored ModelConverter
Expand Down

0 comments on commit 6e6c366

Please sign in to comment.