yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Quintiq file version 2.0
#parent: #root
StaticMethod NewAbsConstraint (MathematicalProgram program, LibOpt_UIGraphNode node, LibOpt_UIGraphNodes elements, 
  String constr_name, String pos_id, String neg_id, 
  Real offset) declarative
{
  TextBody:
  [*
    if( elements.Size() > 0 )
    {
      constr := program.NewConstraint( constr_name, node );
      var := program.Variable( LibOpt_UIGraph::VarX(), node );
      traverse( elements, Elements, elem )
      {
        var_elem := program.Variable( LibOpt_UIGraph::VarX(), elem );
        constr.NewTerm( -1.0 / elements.Size(), var_elem );
      }
      
      var_dist_pos := program.Variable( pos_id, node );
      var_dist_neg := program.Variable( neg_id, node );
      constr.NewTerm(  1.0, var_dist_pos );
      constr.NewTerm( -1.0, var_dist_neg );
      
      constr.Sense( MPConstraintSense::Equal().AsString() );
      constr.RHSValue( offset );
      constr.NewTerm( 1.0, var );
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}