Initializing help system before first use

Introductory examples


Type: Programming
Rating: 3 (intermediate)
Description: Introductory examples from the whitepaper 'Robust Optimization with Xpress'. Topics covered by the examples:
  • Price of robustness: cost_of_robustness.mos (calculating the cost of having uncertainty in the model)
  • Working with nominal values:
    nominalvalue_0base.mos (simple robust model without nominal values);
    nominalvalue_2base.mos (simple robust model with a nominal valued uncertain);
    nominalvalue_none.mos (uncertainty as an addition to a coefficient);
    nominalvalue_rule2.mos (using uncertains with nominal value as coefficients);
    nominalvalue_shift1.mos (basic version without nominal values);
    nominalvalue_shift2.mos (defining nominal values);
    nominalvalue_shift3.mos (substituting the effect of the nominal values);
    nominalvalue_simple.mos (uncertainty as a coefficient)
  • Overlapping uncertainty:
    overlapping_cardinality.mos (cardinality constraint with overlapping uncertainty sets);
    overlapping_polyhedral.mos, overlapping_polyhedral2.mos (polyhedral uncertainty set with overlapping use in robust constraints)
  • Working with scenarios:
    scenario_simple.mos (simple robust optimization model with scenario based uncertainty);
    scenario_simple_deterministic.mos (deterministic version of the simple scenario problem)
  • Special cases:
    careful_equalities.mos (robust problem with equality constraint);
    careful_unbounded_uncertain.mos (robust problem with an unbounded uncertain)
File(s): cost_of_robustness.mos, nominalvalue_0base.mos, nominalvalue_2base.mos, nominalvalue_none.mos, nominalvalue_rule2.mos, nominalvalue_shift1.mos, nominalvalue_shift2.mos, nominalvalue_shift3.mos, nominalvalue_simple.mos, overlapping_cardinality.mos, overlapping_polyhedral.mos, overlapping_polyhedral2.mos, scenario_simple.mos, scenario_simple_deterministic.mos, careful_equalities.mos, careful_unbounded_uncertain.mos


cost_of_robustness.mos
(!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model PriceRobustness
  uses "mmrobust"                    ! Load the robust library

  declarations
    x : mpvar
    u : uncertain
  end-declarations

  0 <= u
  u <= 3

  (1+u)*x <= 1

  maximize(XPRS_NOMINAL, x)
  nominal_objective := getobjval
  writeln("Objective at nominal values:", nominal_objective );

  maximize(x)
  robust_objective := getobjval
  writeln("Robust objective:", robust_objective );
  writeln("Price of robustness:", nominal_objective - robust_objective );
  writeln("Worst value of uncertain:", u.sol)

end-model

nominalvalue_0base.mos
 (!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Nominalvalues
 uses "mmrobust"                    ! Load the robust library

declarations
 x : mpvar
 u : uncertain
end-declarations

0 <= u
     u <= 1

(1+u)*x <= 1

maximize(x)

writeln("x = ", getsol(x))

end-model

nominalvalue_2base.mos
 (!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Nominalvalues
 uses "mmrobust"                    ! Load the robust library

declarations
 x : mpvar
 u : uncertain
end-declarations

0 <= u
     u <= 1

u := 2                   ! Shifts the center of the uncertain

(1+u)*x <= 1

maximize(x)

writeln("x = ", getsol(x))

end-model

nominalvalue_none.mos
 (!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Nominalvalues
 uses "mmrobust"                    ! Load the robust library

declarations
  x : mpvar
  u : uncertain
end-declarations

(5+u)*x <= 1

end-model

nominalvalue_rule2.mos
 (!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Nominalvalues
 uses "mmrobust"                    ! Load the robust library

! Real valued coefficients
declarations
 x : mpvar
 r : real
end-declarations

r := 3

C1 := (1+r)*x <= 1

r := 5

maximize(x)

writeln("x = ", getsol(x))

sethidden(C1, true)      ! Make the existing constraint hidden

! Uncertain coefficients
declarations 
 y : mpvar
 u : uncertain
end-declarations

u := 3

(1+u)*y <= 1

u := 5

maximize(XPRS_NOMINAL, y)

writeln("y = ", getsol(y))

end-model

nominalvalue_shift1.mos
 (!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Nominalvalues
 uses "mmrobust"                    ! Load the robust library

declarations
 x,y : mpvar
 e,f : uncertain
end-declarations
     
e^2 + f^2 <= 2      ! An ellipsoidal uncertainty constraint

e*x + f*y <= 1

maximize(x + y)

writeln("x = ", getsol(x), ",  y = ", getsol(y))

end-model

nominalvalue_shift2.mos
 (!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Nominalvalues
 uses "mmrobust"                    ! Load the robust library

declarations
 x,y : mpvar
 e,f : uncertain
end-declarations
     
e^2 + f^2 <= 2

e := 1
f := 1

e*x + f*y <= 1

maximize(x + y)

writeln("x = ", getsol(x), ",  y = ", getsol(y))

end-model

nominalvalue_shift3.mos
 (!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Nominalvalues
 uses "mmrobust"                    ! Load the robust library

declarations
 x,y : mpvar
 e,f : uncertain
end-declarations
     
e^2 + f^2 <= 2

(e+1)*x + (f+1)*y <= 1

maximize(x + y)

writeln("x = ", getsol(x), ",  y = ", getsol(y))

end-model

nominalvalue_simple.mos
 (!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Nominalvalues
 uses "mmrobust"                    ! Load the robust library

declarations
  x : mpvar
  u : uncertain
end-declarations

u:= 5                             ! Setting the nominal value
u*x <= 1

end-model

overlapping_cardinality.mos
(!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Careful
 uses "mmrobust"                    ! Load the robust library

  declarations
    x,y,z: mpvar
    ex, ey, ez: uncertain
  end-declarations

  x is_binary ; y is_binary ; z is_binary

  20*x + 10*y + 5*z >= 20

  ex>=0 ; ex<=1 
  ey>=0 ; ey<=1
  ez>=0 ; ez<=1

  cardinality({ex,ey,ez},1)   ! Allow only one of the uncertains to be nonzero

  setparam("ROBUST_UNCERTAIN_OVERLAP",true)   ! Allow overlaps
  
  10*(x-x*ex) + 10*(y-y*ey) + 10*(z-z*ez) >= 10
  10*(x-x*ex) + 10*(y-y*ey) + 10*(z-z*ez) <= 20
    
  maximize(x+y+z)

  writeln("x = ", getsol(x), "  y = ", getsol(y), "  z = ", getsol(z))

end-model

overlapping_polyhedral.mos
(!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper
   - This file purposely terminates with an error, 
   - completed version: overlapping_polyhedral2.mos -
   
   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Careful
 uses "mmrobust"                    ! Load the robust library

 declarations
  x, y: mpvar
  e, f : uncertain
 end-declarations

 x*e <= 1
 y*f <= 1

 e >= 0
 f >= 0
 e+f <= 1
 
 maximize(x+y)

 writeln("x = ", getsol(x), "  y = ", getsol(y))

end-model

overlapping_polyhedral2.mos
(!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       rev. May 2017
*******************************************************!)
model Careful
 uses "mmrobust"                    ! Load the robust library

 declarations
  x, y: mpvar
  e, f : uncertain
 end-declarations

 RobC1:= x*e <= 1
 RobC2:= y*f <= 1

 e >= 0
 f >= 0
 e+f <= 1
 
 setparam("XPRS_PROBNAME","h")
 
 setparam("ROBUST_UNCERTAIN_OVERLAP", true)
 
 maximize(x+y)

 writeln("x = ", getsol(x), "  y = ", getsol(y))
 writeln("constraint RobC1: x*e <= 1, uncertains (e,f) = (", 
         getsol (e,RobC1), ",", getsol(f,RobC1), ")")
 writeln("constraint RobC2: y*f <= 1, uncertains (e,f) = (", 
         getsol (e,RobC2), ",", getsol(f,RobC2), ")")

end-model

scenario_simple.mos
(!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       rev. May 2017 
*******************************************************!)
model Knapsack
 uses "mmrobust"                    ! Load the robust library

 declarations
  x, y : mpvar
  e, f : uncertain 
  HISTDATA: array(range, set of uncertain) of real
 end-declarations 

 ! Load historical data for e and f
 HISTDATA(1, e) := 1
 HISTDATA(1, f) := 2
 HISTDATA(2, e) := 3
 HISTDATA(2, f) := 1
 HISTDATA(3, e) := 3
 HISTDATA(3, f) := 2

 e*x + f * y <= 1

 ! Generate a solution that would be feasible for ALL historic realizations
 scenario(HISTDATA)

 maximize(x+y)   

 writeln("x = ", getsol(x), "  y = ", getsol(y))

end-model

scenario_simple_deterministic.mos
(!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       rev. May 2017 
*******************************************************!)
model Scenario
 uses "mmxprs"                    ! Load the optimizer library

 declarations
  x, y : mpvar
 end-declarations 

 Scenario1 := 1 * x + 2 * y <= 1
 Scenario2 := 3 * x + 1 * y <= 1
 Scenario3 := 3 * x + 2 * y <= 1

 maximize(x+y)   

 writeln("x = ", getsol(x), "  y = ", getsol(y))

end-model

careful_equalities.mos
(!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Careful
 uses "mmrobust"                    ! Load the robust library

 declarations
  x, y, z : mpvar
  e : uncertain
 end-declarations

 e <= 1
 e >= 0

 x + y + e*z = 10
 
 maximize(z)

 writeln("x = ", getsol(x), "  y = ", getsol(y), "  z = ", getsol(z))

end-model

careful_unbounded_uncertain.mos
(!******************************************************
   Mosel Example Problems
   ======================   

   Example model for the 
   Robust Optimization with Xpress white paper

   (c) 2014 Fair Isaac Corporation
       
*******************************************************!)
model Careful
 uses "mmrobust"                    ! Load the robust library

 declarations
  x, y, z : mpvar
  e : uncertain
 end-declarations

 x + y + e*z <= 10
 
 maximize(z)

 writeln("x = ", getsol(x), "  y = ", getsol(y), "  z = ", getsol(z))

end-model

© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.