| 370 | } |
| 371 | |
| 372 | void MILPEncoder::encodeDisjunctionConstraint( GurobiWrapper &gurobi, |
| 373 | DisjunctionConstraint *disj, |
| 374 | bool relax ) |
| 375 | { |
| 376 | if ( !disj->isActive() ) |
| 377 | return; |
| 378 | |
| 379 | // terms for Gurobi |
| 380 | List<GurobiWrapper::Term> terms; |
| 381 | List<PiecewiseLinearCaseSplit> disjuncts = disj->getCaseSplits(); |
| 382 | for ( unsigned i = 0; i < disjuncts.size(); ++i ) |
| 383 | { |
| 384 | // add a binary variable for each disjunct |
| 385 | gurobi.addVariable( Stringf( "a%u_%u", _binVarIndex, i ), |
| 386 | 0, |
| 387 | 1, |
| 388 | relax ? GurobiWrapper::CONTINUOUS : GurobiWrapper::BINARY ); |
| 389 | |
| 390 | terms.append( GurobiWrapper::Term( 1, Stringf( "a%u_%u", _binVarIndex, i ) ) ); |
| 391 | } |
| 392 | |
| 393 | // add constraint: a_1 + a_2 + ... + >= 1 |
| 394 | gurobi.addGeqConstraint( terms, 1 ); |
| 395 | |
| 396 | // Add each disjunct as indicator constraints |
| 397 | terms.clear(); |
| 398 | unsigned index = 0; |
| 399 | for ( const auto &disjunct : disjuncts ) |
| 400 | { |
| 401 | String binVarName = Stringf( "a%u_%u", _binVarIndex, index ); |
| 402 | for ( const auto &tightening : disjunct.getBoundTightenings() ) |
| 403 | { |
| 404 | // add indicator constraint: a_1 => disjunct1, etc. |
| 405 | terms.append( |
| 406 | GurobiWrapper::Term( 1, getVariableNameFromVariable( tightening._variable ) ) ); |
| 407 | if ( tightening._type == Tightening::UB ) |
| 408 | gurobi.addLeqIndicatorConstraint( binVarName, 1, terms, tightening._value ); |
| 409 | else |
| 410 | gurobi.addGeqIndicatorConstraint( binVarName, 1, terms, tightening._value ); |
| 411 | terms.clear(); |
| 412 | } |
| 413 | ++index; |
| 414 | } |
| 415 | |
| 416 | _binVarIndex++; |
| 417 | } |
| 418 | |
| 419 | void MILPEncoder::encodeSignConstraint( GurobiWrapper &gurobi, SignConstraint *sign, bool relax ) |
| 420 | { |
nothing calls this directly
no test coverage detected