陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Quintiq file version 2.0
#parent: #root
Method AddClosureTripsOperations (
  output LibOpt_Scope out_scope
)
{
  TextBody:
  [*
    addedopperiods := 0; 
    
    /*
    wopuld need correction because in case of lead time period will be different for the input pispips
    traverse(  out_scope.GetPISPIPInOptimizerRun(), Elements, pispip ) 
    {
      traverse( pispip, ProductInStockingPoint_MP.OperationOutput.Operation, op, op.IsEnabled() ) 
      {
        if ( not out_scope.Contains( op.OperationInOptimizerRun() ) )
        {
          inputpispips := selectset(  op, 
                                      OperationInput.ProductInStockingPoint_MP.ProductInStockingPointInPeriodPlanning, 
                                      inppispip, 
                                      true, 
                                      inppispip.Period_MP() = pispip.Period_MP() ); 
                                      
          outputpispips := selectset( op, 
                                      OperationOutput.ProductInStockingPoint_MP.ProductInStockingPointInPeriodPlanning, 
                                      outpispip, 
                                      true, 
                                      outpispip.Period_MP() = pispip.Period_MP() ); 
                                                                                      
          if ( forall( inputpispips, 
                       Elements, inppispip,  
                       out_scope.Contains( inppispip.PISPIPInOptimizerRun() ) )  
               and 
               forall( outputpispips, 
                       Elements, outpispip,  
                       out_scope.Contains( outpispip.PISPIPInOptimizerRun() )  ) )
          { 
            out_scope.Add( op ); 
      
            // Add the units to which those operations belong to unitsforoptimization
            unit := op.Unit();
            out_scope.Add(  unit ); 
            period := pispip.Period_MP(); 
    
            // Add the related unit periods to unitperiodsforoptimization
            unitperiod := UnitPeriod::FindUnitPeriodTypeIndex( unit.ID(), period.Start(), period.End() );
            if( not unitperiod.IsPeriodFrozen() )
            {
              out_scope.Add(  unitperiod ); 
            }  
      
            // Create/Select the related periodtaskoperation and add it to PTOperationsForOptimization
            periodtaskoperation := PeriodTaskOperation::FindPeriodTaskOperationTypeIndex( period.Start() , op.ID() );
        
            if( isnull( periodtaskoperation ) )
            {
              periodtaskoperation := PeriodTaskOperation::Create( op, unitperiod, 0.0, false );
              // I think this transaction propagate is necessary, we need to get the dependent demand from the newly created periodtask
              Transaction::Transaction().Propagate( relation( PeriodTaskOperation, DependentDemand ) )
        
            }
              out_scope.Add( periodtaskoperation );   
            }
            addedopperiods++; 
         }     
      }
    }
    */
    
    addedpit := 0; 
    traverse(  out_scope.GetPISPIPInOptimizerRun(), Elements, pispip ) 
    {
      traverse(  pispip, astype( ProductInStockingPointInPeriodPlanningLeaf ).AsArrivalPISPIP, pit ) 
      {
        if ( out_scope.Contains( pit.Trip().TripInOptimizerRun() )
             and out_scope.Contains( pit.DeparturePISPIP().PISPIPInOptimizerRun() ) 
             and not out_scope.Contains( pit.ProductInTripInOptimizerRun() ) )
        {
          out_scope.Add( pit ); 
          addedpit++  
        }
      }        
    }
    debuginfo( 'Closure added (op, period):', addedopperiods, ' added pit:', addedpit );
  *]
  InterfaceProperties { Accessibility: 'Module' }
}