陈清红
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
Quintiq file version 2.0
#parent: #root
Method SetCPLEXParametersNonHierarchicalGoal (
  MathematicalProgram program,
  const StrategyLevelMacroPlan runlevel,
  const LibOpt_Scope scope
) const
{
  Description: 'Set the parameters (time limit, gap, etc) of the optimizer, according to setting per iteration'
  TextBody:
  [*
    // soh yee Jul-2-2013 (created)
    // ResetParameters is removing all parameters that were set by AddBooleanParameter, AddNumberParameter, AddRealParameter, AddStringParameter.
    // That includes the AbsoluteGap and RelativeGap that we set below with AddRealParameter
    
    assert( not this.UseHierarchicalCPLEXGoals(), 'not expecting this code to be executed for multi-level cplex ' ) 
    
    runcontext := this.GetRunContextConst(); 
    rcm := this.GetRunContextMeta();
    
    if ( runcontext.IsMetaIteration() ) 
    {
      if ( runcontext.GetIsMIP() ) 
      {
        program.AddRealParameter( 2010, rcm.OptionIntegralityTolerance() ); // use default for meta unless user sets it explicitly
        if ( not runcontext.UseShiftOptimization() or this.IsHardShiftOptimizationLevel( runcontext, scope ) ) 
        {    
          program.AddRealParameter( 2009, rcm.OptionRelativeMIPGap() ); // use default for meta unless user sets it explicitly 
        }
      }    
    }
    else
    {
      if( runlevel.UseAbsoluteGap() )
      {
        program.AddRealParameter( 2008, runlevel.AbsoluteGap() );      // absolute gap tolerance
        program.AddRealParameter( 2009, 0.0 ); // explicitly must set rel gap to 0, otherwise solver can still terminate early based on that 
      }
      else
      {
        program.AddRealParameter( 2009, runlevel.RelativeGap() );      // relative gap tolerance
        program.AddRealParameter( 2008, 0.0 ); // explicitly must set abs gap to 0, otherwise solver can still terminate early based on that 
      }
    }
    
    this.ActivateSolverSettings( program, runlevel );        // activate the solver settings for the next level
    
    timelimit := [Real]runlevel.TimeLimit();
    if ( runcontext.IsMetaIteration() and not this.IsFullPlanMetaPriorFocus() ) 
    {
      factor := 4; 
      timelimit := factor * rcm.OptionMaxTimePerIterationSeconds(); // set time out to be 'factor' X the target time used for tuning
      debuginfo(  'Time out cplex:', timelimit ); 
    }
    program.TimeLimit( timelimit );                    // time limit
    
    if( runcontext.IsForBenchmarking() )     // For total time limit of the benchmarking execution
    {
      if ( program.Threads() > runcontext.MaxNumberOfThreadsForBenchmarking() ) 
      {
        
        program.Threads( runcontext.MaxNumberOfThreadsForBenchmarking() ); 
      }
    }
    
    maxthreadsglobal := ifexpr( this.MacroPlan().IsSizingParameterOn(), this.MacroPlan().ResourceManager_MP().MaxThreadForOptimization(), Number::MaxNumber() ); 
    program.Threads( minvalue( program.Threads(), maxthreadsglobal ) ); // limit by sizing parameter setting
    program.AddNumberParameter( 1067, program.Threads() ); // otherwise CPLEX log shows thread parameter is not used
    
    debuginfo(  'program.Threads() = ', program.Threads() );
  *]
  InterfaceProperties { Accessibility: 'Module' }
}