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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Quintiq file version 2.0
#parent: #root
Method LogDetailsCPLEX (
  MathematicalProgram program,
  String comment,
  const LibOpt_Scope scope
)
{
  TextBody:
  [*
    statistics := program.Statistics();
    msg2 := 'pml inf: ' + statistics.MaxPrimalInfeasibility().AsQUILL();
    msg3 := 'pml resdl: ' + statistics.MaxPrimalResidual().AsQUILL(); 
    msg4 := 'dual inf: ' + statistics.MaxDualInfeasibility().AsQUILL(); 
    msg5 := 'dual resdl: ' + statistics.MaxDualResidual().AsQUILL(); 
    msg6 := 'max int inf:' + statistics.MaxIntInfeasibility().AsQUILL(); 
    msg7 := 'kappa:' + statistics.Kappa().AsQUILL(); 
    msg8 := 'kappamax:' + statistics.KappaMax().AsQUILL();
    msg9 := 'illposed=' + statistics.KappaIllPosed().AsQUILL() + 'susp=' + statistics.KappaSuspicious().AsQUILL() + 'unstable=' + statistics.KappaUnstable().AsQUILL() 
    + 'stable=' + statistics.KappaStable().AsQUILL()
     
    msgstats := msg2 + msg3 + msg4 + msg5 + msg6 + msg7 + msg8 + msg9; 
    
    lvlmsg := 'lvl'+ [String](this.CurrentSubOptimizerLevel().LevelNumber()) + ifexpr(  this.CurrentSubOptimizerLevel().IsExtraPTQTYLevelMetaOptimizer(), '[PTQTYmin] ', ' ' ); 
    nrgoalterms := ifexpr(  not this.UseHierarchicalCPLEXGoals(), counter(  program.Goal().Terms(), Elements, t, true, not t.Coefficient() = 0), Number::MaxNumber() ); 
    msg := lvlmsg + 'no solution'; 
    
    if ( program.HasSolution() ) 
    {
      if ( this.UseHierarchicalCPLEXGoals() ) 
      {
        msg := ''; 
        maxlevel := this.GetMaxLevelNumberForHierarchicalGoals( this.GetRunContextConst(), scope ); 
        for ( i := 0; i <= maxlevel; i++ ) 
        {
          nameofgoal := CapacityPlanningSuboptimizer::HierarchicalGoalLevelName( i ); 
          try
          {
            goalvalue := program.GoalValue( nameofgoal );
            goal := program.Goal( nameofgoal );  
            //abstol := goal.AbsTolerance(); 
      
            msg := msg + 'level='+ [String]i + 'goal=' + [String] goalvalue + 'goalterms=' + [ String] goal.Terms().Elements( relsize ) + String::NewLine();  
            this.AllLevelsOptimal( this.AllLevelsOptimal() and program.Optimal() ) ; 
          }
          onerror
          {
            // we skip levels
          }
        }
        optimal := ifexpr(  program.Optimal(), 'optimal', 'suboptimal' ); 
        msg := msg + optimal + ' absgap=' + program.AbsoluteGap().AsQUILL() + msgstats;
        this.DetailsCPLEX( msg ); 
      }
      else
      {
        msg := lvlmsg + 'goal=' + [String] program.GoalValue() + 'absgap=' + [String] program.AbsoluteGap(); 
        this.DetailsCPLEX( this.DetailsCPLEX() + comment + msg + 'gterms=' + [String] nrgoalterms + msgstats + String::NewLine() );
        this.AllLevelsOptimal( this.AllLevelsOptimal() and program.Optimal() ) ; 
      }
    }
    else
    {
      this.DetailsCPLEX( this.DetailsCPLEX() + msg ); 
      this.AllLevelsOptimal( false ); 
    }
    
    msg_kpilowerbounds := guard( program.RetrieveString( 'message_kpilowerbound' ), '' ); 
    this.DetailsCPLEX( this.DetailsCPLEX() + msg_kpilowerbounds );
    
    nrshiftbinaries := guard( [Number] program.RetrieveReal( 'NrShiftBinaries' ), 0 ); 
    this.DetailsCPLEXNrShiftBinaries( nrshiftbinaries ); 
    /* for debugging purpose. Example to log some variable values:
    v1 := program.astype( CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm ).TotalUnitPeriodCampaignUtilizationSlackVariables().Find();
    msg := ''; 
    if ( not isnull( v1 ) and program.HasSolution() ) 
    {
      msg := msg + 'TotalUnitPeriodCampaignUtilizationSlackVariables=' + [String] v1.OptimalValue() + String::NewLine();    
      v2 := program.astype( CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm ).TotalCampaignSequencingCombiSlackVariables().Get();
      msg := msg + 'TotalCampaignSequencingCombiSlackVariables=' + [String] v2.OptimalValue() + String::NewLine();    
      v3 := program.astype( CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm ).TotalCampaignMinQtyUnderVariables().Get();
      msg := msg + 'TotalCampaignMinQtyUnderVariables=' + [String] v3.OptimalValue() + String::NewLine();    
      v4 := program.astype( CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm ).TotalCampaignMaxQtyOverVariables().Get();
      msg := msg + 'TotalCampaignMaxQtyOverVariables=' + [String] v4.OptimalValue() + String::NewLine();    
      v5 := program.astype( CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm ).TotalCampaignMinDurationUnderVariables().Get();
      msg := msg + 'TotalCampaignMinDurationUnderVariables=' + [String] v5.OptimalValue() + String::NewLine();    
      v6 := program.astype( CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm ).TotalCampaignMaxDurationOverVariables().Get();
      msg := msg + 'TotalCampaignMaxDurationOverVariables=' + [String] v6.OptimalValue() + String::NewLine();
      this.DetailsCPLEX( this.DetailsCPLEX() + msg ); 
    }
    */
  *]
  InterfaceProperties { Accessibility: 'Module' }
}