MCPcopy Create free account
hub / github.com/NeuralNetworkVerification/Marabou / encodeSignConstraint

Method encodeSignConstraint

src/engine/MILPEncoder.cpp:419–460  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

417}
418
419void MILPEncoder::encodeSignConstraint( GurobiWrapper &gurobi, SignConstraint *sign, bool relax )
420{
421 ASSERT( GlobalConfiguration::PL_CONSTRAINTS_ADD_AUX_EQUATIONS_AFTER_PREPROCESSING );
422
423 if ( !sign->isActive() || sign->phaseFixed() )
424 {
425 ASSERT( ( FloatUtils::gte( _tableau.getLowerBound( sign->getB() ), 0 ) &&
426 FloatUtils::areEqual( _tableau.getLowerBound( sign->getF() ), 1 ) ) ||
427 ( FloatUtils::lte( _tableau.getUpperBound( sign->getB() ), 0 ) &&
428 FloatUtils::areEqual( _tableau.getUpperBound( sign->getF() ), -1 ) ) );
429 return;
430 }
431
432 unsigned targetVariable = sign->getF();
433 DEBUG( {
434 unsigned sourceVariable = sign->getB();
435
436 double sourceLb = _tableau.getLowerBound( sourceVariable );
437 double sourceUb = _tableau.getUpperBound( sourceVariable );
438 ASSERT( !FloatUtils::isNegative( sourceUb ) && FloatUtils::isNegative( sourceLb ) );
439 } );
440
441 /*
442 We have added f <= -2/lb b + 1 and f >= 2/ub * b - 1. We just need to specify
443 f is either -1 or 1. That is f = 2 * (a - 0.5)
444
445 f is 1 if a is 1 and -1 if a is 0.
446 Moreover, when f is 1, 1 <= -2 / lb_b * b + 1, thus, b >= 0.
447 When f is -1, -1 >= 2/ub_b * b - 1, thus, b <= 0.
448 */
449 gurobi.addVariable( Stringf( "a%u", _binVarIndex ),
450 0,
451 1,
452 relax ? GurobiWrapper::CONTINUOUS : GurobiWrapper::BINARY );
453
454 List<GurobiWrapper::Term> terms;
455 terms.append( GurobiWrapper::Term( 1, Stringf( "x%u", targetVariable ) ) );
456 terms.append( GurobiWrapper::Term( -2, Stringf( "a%u", _binVarIndex ) ) );
457 gurobi.addEqConstraint( terms, -1 );
458
459 ++_binVarIndex;
460}
461
462void MILPEncoder::encodeSigmoidConstraint( GurobiWrapper &gurobi, SigmoidConstraint *sigmoid )
463{

Callers

nothing calls this directly

Calls 11

StringfClass · 0.85
TermClass · 0.50
isActiveMethod · 0.45
phaseFixedMethod · 0.45
getLowerBoundMethod · 0.45
getBMethod · 0.45
getFMethod · 0.45
getUpperBoundMethod · 0.45
addVariableMethod · 0.45
appendMethod · 0.45
addEqConstraintMethod · 0.45

Tested by

no test coverage detected