haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Quintiq file version 2.0
#parent: #root
Method InitConstraintsForUnitPeriodTools (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope,
  const CapacityPlanningSuboptimizer subopt
) const
{
  Description: 'Initialize constraints for unit periods'
  TextBody:
  [*
    period := this.Period_MP();
    algorithm := subopt; 
    
    scalefactor_ptqty_toolisused := algorithm.ScaleConstraintTerm( typeof( MPPTQtyVariable ), typeof( MPUnitPeriodToolIsUsedConstraint ) );
    scalefactor_unitperiodtoolisused_nroftoolchange := algorithm.ScaleConstraintTerm( typeof( MPUnitPeriodToolIsUsedVariable ), typeof( MPUnitPeriodNrOfToolChangeConstraint ) );
    
    unitperiodoperations := algorithm.GetOperationsForUnitPeriod( scope, this );
    
    //UnitPeriodNrOfToolChange = sum( UnitPeriodToolIsUsed ) - 1
    constUnitPeriodNrOfToolChange := program.UnitPeriodNrOfToolChangeConstraints().New( this ); 
    constUnitPeriodNrOfToolChange.Sense( '>=' );
    constUnitPeriodNrOfToolChange.RHSValue( algorithm.ScaleConstraintRHS( typeof( MPUnitPeriodNrOfToolChangeConstraint ), -1.0 ) );
    
    
    varUnitPeriodNrOfToolChange := program.UnitPeriodNrOfToolChangeVariables().Find( this );
    scalefactor_unitperiodnroftoolchange_nroftoolchange := algorithm.ScaleConstraintTerm( typeof( MPUnitPeriodNrOfToolChangeVariable ) , typeof( MPUnitPeriodNrOfToolChangeConstraint ) );
    
    if( not isnull( varUnitPeriodNrOfToolChange ) )
    {
      constUnitPeriodNrOfToolChange.NewTerm( 1.0 * scalefactor_unitperiodnroftoolchange_nroftoolchange, varUnitPeriodNrOfToolChange );
    }
    
    traverse( this, ToolInUnitPeriod.Tool, tool )
    {
      varUnitPeriodToolIsUsed := program.UnitPeriodToolIsUsedVariables().Get( this, tool );  
    
      //if( not isnull( varUnitPeriodToolIsUsed ) )
      {
        constUnitPeriodNrOfToolChange.NewTerm( -1.0 * scalefactor_unitperiodtoolisused_nroftoolchange, varUnitPeriodToolIsUsed ); 
        
        constUnitPeriodToolIsUsed := program.UnitPeriodToolIsUsedConstraints().New( this, tool );
        constUnitPeriodToolIsUsed.RHSValue( 0 );
        constUnitPeriodToolIsUsed.Sense( "=" );
    
        traverse( unitperiodoperations, 
                  Elements, 
                  operation, 
                  guard( operation.RoutingStep().Tool() = tool.Name(), false ) )
        {
          ptqtyvar := program.PTQtyVariables().Find( operation, period );
          if( not isnull( ptqtyvar ) )
          {
            constUnitPeriodToolIsUsed.NewTerm( scalefactor_ptqty_toolisused, ptqtyvar );
          }
        }
        program.NewIfNotThenConstraint( AlgorithmNameConstraint::UnitPeriodToolIsUseGeneral( this, tool.Name() ), varUnitPeriodToolIsUsed, constUnitPeriodToolIsUsed )                                   
      }                                         
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}