@@ -30,6 +30,26 @@ AbsoluteValueConstraint::AbsoluteValueConstraint( unsigned b, unsigned f )
3030 setPhaseStatus ( PhaseStatus::PHASE_NOT_FIXED );
3131}
3232
33+ AbsoluteValueConstraint::AbsoluteValueConstraint ( const String &serializedAbs )
34+ : _haveEliminatedVariables( false )
35+ {
36+ String constraintType = serializedAbs.substring ( 0 , 13 );
37+ ASSERT ( constraintType == String ( " absoluteValue" ) );
38+
39+ // Remove the constraint type in serialized form
40+ String serializedValues = serializedAbs.substring ( 14 , serializedAbs.length () - 14 );
41+ List<String> values = serializedValues.tokenize ( " ," );
42+
43+ ASSERT ( values.size () == 2 );
44+
45+ auto var = values.begin ();
46+ _f = atoi ( var->ascii () );
47+ ++var;
48+ _b = atoi ( var->ascii () );
49+
50+ setPhaseStatus ( PhaseStatus::PHASE_NOT_FIXED );
51+ }
52+
3353PiecewiseLinearFunctionType AbsoluteValueConstraint::getType () const
3454{
3555 return PiecewiseLinearFunctionType::ABSOLUTE_VALUE;
@@ -274,6 +294,23 @@ void AbsoluteValueConstraint::eliminateVariable( unsigned variable, double /* fi
274294 _haveEliminatedVariables = true ;
275295}
276296
297+ void AbsoluteValueConstraint::dump ( String &output ) const
298+ {
299+ output = Stringf ( " AbsoluteValueCosntraint: x%u = Abs( x%u ). Active? %s. PhaseStatus = %u (%s).\n " ,
300+ _f, _b,
301+ _constraintActive ? " Yes" : " No" ,
302+ _phaseStatus, phaseToString ( _phaseStatus ).ascii ()
303+ );
304+
305+ output += Stringf ( " b in [%s, %s], " ,
306+ _lowerBounds.exists ( _b ) ? Stringf ( " %lf" , _lowerBounds[_b] ).ascii () : " -inf" ,
307+ _upperBounds.exists ( _b ) ? Stringf ( " %lf" , _upperBounds[_b] ).ascii () : " inf" );
308+
309+ output += Stringf ( " f in [%s, %s]" ,
310+ _lowerBounds.exists ( _f ) ? Stringf ( " %lf" , _lowerBounds[_f] ).ascii () : " -inf" ,
311+ _upperBounds.exists ( _f ) ? Stringf ( " %lf" , _upperBounds[_f] ).ascii () : " inf" );
312+ }
313+
277314void AbsoluteValueConstraint::updateVariableIndex ( unsigned oldIndex, unsigned newIndex )
278315{
279316 ASSERT ( oldIndex == _b || oldIndex == _f );
@@ -429,6 +466,24 @@ void AbsoluteValueConstraint::fixPhaseIfNeeded()
429466 }
430467}
431468
469+ String AbsoluteValueConstraint::phaseToString ( PhaseStatus phase )
470+ {
471+ switch ( phase )
472+ {
473+ case PHASE_NOT_FIXED:
474+ return " PHASE_NOT_FIXED" ;
475+
476+ case PHASE_POSITIVE:
477+ return " PHASE_POSITIVE" ;
478+
479+ case PHASE_NEGATIVE:
480+ return " PHASE_NEGATIVE" ;
481+
482+ default :
483+ return " UNKNOWN" ;
484+ }
485+ };
486+
432487void AbsoluteValueConstraint::setPhaseStatus ( PhaseStatus phaseStatus )
433488{
434489 _phaseStatus = phaseStatus;
0 commit comments