hongji.li
2023-11-07 1a1ba3ad5ed9e4380185aa1ccad20204a0e5f115
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
Quintiq file version 2.0
#parent: #root
Method FixVariableStyleGuide (
  MPVariable var,
  Real bound,
  Boolean setuppperbound,
  Boolean setlowerbound,
  Boolean applyscaling
) const
{
  Description: 'fixing cplex variables according to modeling style guide'
  TextBody:
  [*
    if (applyscaling ) 
    {
      bound := this.ScaleVariable( var, bound );   // scale the bound  
    }
    
    if( var.VariableType() = 'Binary' or var.VariableType() = 'Integer' )
    {
      if ( setlowerbound ) 
      {
        var.LowerBound( bound - 0.1 );
      }
      if ( setuppperbound ) 
      {
        var.UpperBound( bound + 0.1 );
      }
    }
    else
    {
      // Scale everything by a big factor to avoid the epsilon arithmetic of Quill
      big := 1e+10;
      // guard against a MaxReal upper bound, or MinReal lower bound from the init variables
      lb := Real::MinReal();
      ub := Real::MaxReal();
      if( var.LowerBound().IsFinite() )
      {
        lb := var.LowerBound() * big;
      }
      if( var.UpperBound().IsFinite() )
      {
        ub := var.UpperBound() * big;
      }
      opt := bound * big;
     
      lb := maxvalue( lb, minvalue( ub, opt ) )
      ub := minvalue( ub, maxvalue( lb, opt ) )
     
      // Avoid very small range between lb and ub:
      // Compare the bound range to 1e-10, also using scaling
      if( ub - lb <= 1e-10 * big )
      {
        ub := lb;
      }
     
      // Unscale the values and apply them
      if ( setlowerbound ) 
      {
        var.LowerBound( lb / big );
      }
      if ( setuppperbound ) 
      {
        var.UpperBound( ub / big );
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}