admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
Quintiq file version 2.0
#parent: #root
MethodOverride InitializeReactive (
  const LibOpt_Task task,
  MathematicalProgram program
) const as stream[Object]
{
  TextBody:
  [*
    debuginfo( 'Asynchronous start = ', DateTime::ActualTime() ); 
    start_init_reactive := OS::PrecisionCounter(); 
    scope := task.Scope(); 
    runcontext := this.GetRunContextConst();  
    pispipssmartplan := scope.GetSmartPlanPISPIPsInOptimizerRunConst(); 
    
    userperiodtasks := runcontext.GetUserPeriodTaskOperationsConst(); 
    userproductintrips :=runcontext.GetUserProductInTrips(); 
    
    start_init_varsgoals := OS::PrecisionCounter(); 
    
    programcast := program.astype( CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm ); 
    
    pispipsinrun := scope.GetPISPIPInOptimizerRunConst(); 
    pispsinrun := scope.GetProductInStockingPointInOptimizerRunConst(); 
    leafpispipsinrun := selectset(  pispipsinrun, Elements.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispip, true, true ); 
    pitinrun := scope.GetProductInTripInOptimizerRunConst(); 
    
    programcast.StoreReal( 'start_init_reactive', start_init_reactive ); 
    this.CapacityPlanningAlgorithmInitInstance( programcast, runcontext, scope );  
    
    // initialize variables 
    start_init_varsgoals := OS::PrecisionCounter(); 
    
    this.CapacityPlanningAlgorithmInitVariables( programcast, runcontext, userperiodtasks, userproductintrips, pispipssmartplan, scope, pispipsinrun, leafpispipsinrun, pispsinrun, pitinrun ); 
    
    this.SetStartSolutionForPTLotSizes( programcast, runcontext, scope ); 
    
    this.SetStartSolutionForCampaignSequencing( programcast, runcontext, scope ); 
    
    if ( this.UseHierarchicalCPLEXGoals() ) 
    {
      this.CapacityPlanningAlgorithmInitGoals( programcast, runcontext, scope  );// workaround we should add the goal after cloning because otherwise the goal term constant become = nr of threads. 
                                                                             // but for hierarchical goals this currently produces a core bug
    }
    
    end_init_varsgoals := OS::PrecisionCounter(); 
    duration_unit_vargoals := ((end_init_varsgoals - start_init_varsgoals) / OS::PrecisionCounterFrequency()); 
    programcast.StoreReal( 'duration_init_vargoals', duration_unit_vargoals ); 
    
    startclone := OS::PrecisionCounter(); 
    clone1 := program.Clone().astype( CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm ); 
    clone2 := program.Clone().astype( CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm ); 
    endclone := OS::PrecisionCounter(); 
    durationclone := (endclone - startclone )/ OS::PrecisionCounterFrequency(); 
    
    msgclone := '#time to clone (ms) =' + [String] durationclone + 
                '#vars clone1=' + [String] clone1.Variables( relsize );
    programcast.StoreString(  'timetoclone_msg', msgclone ); 
    
    if ( not this.UseHierarchicalCPLEXGoals() ) 
    {
      this.CapacityPlanningAlgorithmInitGoals( programcast, runcontext, scope  );// workaround we should add the goal after cloning because otherwise the goal term constant become = nr of threads. 
    }
    
    stream1 := this->CapacityPlanningAlgorithmInitConstraints_ParallelTypeA( programcast, pispipssmartplan, userperiodtasks, task, pispipsinrun, leafpispipsinrun, pispsinrun, pitinrun ); 
    stream2 := this->CapacityPlanningAlgorithmInitConstraints_ParallelTypeB( clone1, pispipssmartplan, task, pispipsinrun, leafpispipsinrun, pispsinrun, pitinrun ); 
    stream3 := this->CapacityPlanningAlgorithmInitConstraints_ParallelTypeC( clone2, pispipssmartplan, task, pispipsinrun, leafpispipsinrun, pispsinrun, pitinrun ); 
    
    // note we run this.FilterCPLEXNoiseInitialization( program, runcontext ) in above parallel threads (filters RHS of constraints)
    // meaning this filtering is excluded from any constraints added below. 
    
    return stream1->Merge( stream2, stream3 )
           ->| programcast->CapacityPlanningSuboptimizer::InitReactiveFinalize( clone1, clone2, runcontext, scope, this, leafpispipsinrun )
           ->| emit( this )
  *]
}