| 541 | } |
| 542 | |
| 543 | void MaxConstraint::transformToUseAuxVariables( InputQuery &inputQuery ) |
| 544 | { |
| 545 | if ( _auxToElement.size() > 0 ) |
| 546 | return; |
| 547 | |
| 548 | bool fInInput = false; |
| 549 | for ( const auto &element : _elements ) |
| 550 | { |
| 551 | // If element is equal to _f, skip this step. |
| 552 | // The reason is to avoid adding equations like `1.00x00 -1.00x00 -1.00x01 = 0.00`. |
| 553 | if ( element == _f ) |
| 554 | { |
| 555 | fInInput = true; |
| 556 | continue; |
| 557 | } |
| 558 | // Create an aux variable |
| 559 | unsigned auxVariable = inputQuery.getNumberOfVariables(); |
| 560 | inputQuery.setNumberOfVariables( auxVariable + 1 ); |
| 561 | |
| 562 | // f >= element, or f - element - aux = 0, for non-negative aux |
| 563 | Equation equation( Equation::EQ ); |
| 564 | equation.addAddend( 1.0, _f ); |
| 565 | equation.addAddend( -1.0, element ); |
| 566 | equation.addAddend( -1.0, auxVariable ); |
| 567 | equation.setScalar( 0 ); |
| 568 | inputQuery.addEquation( equation ); |
| 569 | |
| 570 | // Set the bounds for the aux variable |
| 571 | inputQuery.setLowerBound( auxVariable, 0 ); |
| 572 | |
| 573 | _elementToAux[element] = auxVariable; |
| 574 | _auxToElement[auxVariable] = element; |
| 575 | } |
| 576 | if ( fInInput ) |
| 577 | { |
| 578 | List<unsigned> toRemove; |
| 579 | for ( const auto &element : _elements ) |
| 580 | { |
| 581 | if ( element == _f ) |
| 582 | continue; |
| 583 | toRemove.append( element ); |
| 584 | } |
| 585 | for ( const auto &element : toRemove ) |
| 586 | eliminateCase( element ); |
| 587 | _obsolete = true; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | void MaxConstraint::getCostFunctionComponent( LinearExpression &cost, PhaseStatus phase ) const |
| 592 | { |