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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Quintiq file version 2.0
#parent: #root
MethodOverride CreateRun () as LibOpt_Run
{
  TextBody:
  [*
    mp := this.Optimization().astype( Optimization ).MacroPlan(); 
    settings := this.ActiveSettings().astype( OptimizerMetaSettings ); 
    puzzle := select( mp, OptimizerPuzzle, puzzle, true, puzzle.Name() = settings.PuzzleName() ); 
    
    periodstart := minselect( mp, Period_MP, p, not p.IsHistorical(), p.StartDate() ); 
    periodend := mp.LastPlanningPeriod(); 
    
    this.Optimization().astype( Optimization ).GetPeriodsForOTS( periodstart, periodend, settings ); 
    
    issmartplan := false; 
    issmartplanforperiodtask := false;  
    hastotalsupplyuser := false; 
    totalsupplyuser := 0.0; 
    smartplanpispips := null( ProductInStockingPointInPeriodPlanningLeafs ); 
    isupstreamsmartplan := false; 
    ismiddleoutsmartplan := false; 
    isonlyplanonestepupstream := false; 
    ispostprocessing := false; 
    isforcenoautoscaling := true; 
    isoverridemanualplanning := settings.OverrideManualPlanning(); 
    isinventoryoptimizationrun := false; 
    isusingselectedunits := false; 
    units := null( Units ); 
    process := null( Process_MP ); 
    
    strategy := null( Strategy ); 
    if ( isnull( mp.StrategyMacroPlan() ) ) // use exising strategy if exists (for regular optimizer run this will have been set, 
    {                                       // for OTS we have a workaround via method  LibOpt_BT_RunSequenceElement.MyMethodTemp that copies the strategy
                                            // only thing we support at the moment for 'play' button from libopt optimizer from is to repeat for strategy that has been run already
                                            // for updating target KPIs for LibOpt_BT benchmark application we create the following bogus strategy
      strategy := construct( Strategy, Name := 'dummy workaround' ); 
      strategy.StrategyLevel( relnew, Level := 0, StrategyName := strategy.Name(), SolverSettingGroupName := 'Default' ); 
    }                                                          
    
    // fetch legacy algorithmrun object (still used for benchmark runs LibOBT)
    algrun := mp.InitializeOptimizerRun( issmartplan, 
                                         issmartplanforperiodtask, 
                                         hastotalsupplyuser, 
                                         totalsupplyuser, 
                                         smartplanpispips, 
                                         isupstreamsmartplan, 
                                         ismiddleoutsmartplan, 
                                         isonlyplanonestepupstream, 
                                         ispostprocessing,
                                         isforcenoautoscaling, 
                                         strategy, 
                                         isoverridemanualplanning, 
                                         periodstart, 
                                         periodend, 
                                         isinventoryoptimizationrun, 
                                         isusingselectedunits, 
                                         units, 
                                         process, 
                                         puzzle );  
    
    run := super.CreateRun(); 
    run :=this.CreateRunWithContexts( algrun, run, units, periodstart, periodend ); 
    
    rcm := select( run, RunContext.astype( RunContextMeta ), rc, true, true ); 
    
    // put OTS settings onto runcontext meta
    rcm.OptionAutoTuneNeighborhoodSize( settings.OptionAutoTuneNeighborhoodSize() ); 
    rcm.OptionMaxNumberOfPISPIPSForNeighborhood( settings.OptionMaxNumberOfPISPIPSForNeighborhood() ); 
    rcm.OptionMaxNumberOfPISPIPSForNeighborhoodOriginal( rcm.OptionMaxNumberOfPISPIPSForNeighborhood() ); 
    rcm.OptionRollbackAlwaysAccept( settings.OptionRollbackAlwaysAccept() ); 
    rcm.OptionStopOnInfeasible( settings.OptionStopOnInfeasible()); 
    
    return run;
  *]
}