Path: blob/main/notebooks/08/01-bim-robust-optimization.ipynb
663 views
8.1 Robust BIM microchip production problem
Preamble: Install Pyomo and a solver
This cell selects and verifies various global solvers for the notebook. In this notebook, we need the MILO solver HiGHS, but also the NLO solver ipopt and the MINLO solvers bonmin or gurobi to deal with nonlinear optimization problems. We install the latter two using the IDAES module and its extensions, which include the pre-compiled binary for these solvers.
Original BIM production planning model
The full description of the BIM production problem, can be found here. The resulting linear optimization problem was formulated as follows:
Robust BIM production planning models
Suppose now that there is uncertainty affecting the microchip production at BIM. Specifically, the company notices that not the amount of copper needed for the two types of microchips is not exactly 4 and 2 gr, but varies due to some external factors affecting the production process. How does this uncertainty affect the optimal production plan?
To get a feeling for what happens, let us first perform some simulations and data analysis on them. We start by simulating a sample of observed copper consumption pairs for the production of f logic chips and g memory chips. The amounts vary around the original values, 4 gr and 2 gr, respectively, according to two independent lognormal distributions.
Box uncertainty for copper consumption
A very simple and somehow naive uncertainty set can be the minimal box that contains all the simulated data.
Using this empirical box uncertainty set, we can consider the following robust variant of their optimization model:
The above model has an infinite number of constraints, one for every realization of the uncertain coefficients . However, using linear duality, we can deal with this and obtain a robustified linear optimization problem that we can solve.
Robust counterpart of box uncertainty
The first thing to notice is that the copper consumption is modeled by constraints that are equivalent to bounding the following optimization problem:
or
Now we use linear duality to realize that the above is equivalent to:
and the constraint imposed by the last problem is equivalent to:
The only thing we need to do is add the new auxiliary variables and constraints to the original model and implement them in Pyomo.
We may want to impose the box uncertainty set to be symmetric with respect to the nominal values and just choose its width . This leads to a different optimal robust solution.
Integer solution variant
The original BIM model gave integer solutions, but not the robust version. If we need integer solutions then we should impose that to the nature of the variables, which in this case of box uncertainty is easy to do since the model remains linear, although it will be mixed integer.
Let us see how the optimal solution behave as we vary the width of the box uncertainty set from 0 to 0.5.
We can visualize how these quantities change as a function of :
Cardinality-constrained uncertainty set
Let us now make different assumptions regarding the uncertainty related to the copper consumption. More specifically, we now assume that each uncertain coefficient may deviate by at most from the nominal value but no more than will actually deviate.
Robust counterpart of cardinality-constrained uncertainty
Lagrange duality yields the following modification to the problem as equivalent to the robust model stated above:
Adversarial approach for the budgeted uncertainty set
Instead of adopting the approach of robust counterparts, we could also use the adversarial approach where we initially solve the problem for the nominal value of the data. Then, we iteratively search for scenarios that make the current solution violate the copper constraint, and pre-solve the problem to take this scenario into account. To do so, we need to slightly modify our problem formulation function to allow for many scenarios for the parameter .
We also need a function that for a given solution finds the worst-possible realization of the uncertainty restricted by the parameters and . In other words, its role is to solve the following maximization problem for a given solution :
Such a function is implemented below and takes as argument also the maximum magnitude of the individual deviations and the total budget .
We wrap the two functions above into a loop of the adversarial approach, which begins with a non-perturbation assumption and gradually generates violating scenarios, reoptimizing until the maximum constraint violation is below a tolerable threshold.
It takes only two scenarios to be added to the baseline scenario to arrive at the solution which is essentially robust! For that reason, in many settings the adversarial approach is very viable. In fact, because the budgeted uncertainty set for two uncertain parameters has at most 8 vertices, we are guaranteed that it would never take more than 8 iterations to reach a fully robust solution (constraint violation of exactly ).
This is not true, however, if the uncertainty set is not a polytope, but is, for example, an ellipsoid (ball) with infinitely many extreme points - it is expected that there will always be some minuscule constraint violation remaining after a certain number of iterations.
We will now illustrate how to use conic optimization to solve the problem using robust counterparts for an ellipsoidal uncertainty set.
Ball uncertainty set
Let us now make yet another different assumption regarding the uncertainty related to copper consumption. More specifically, we assume that the two uncertain coefficients and can vary in a 2-dimensional ball centered around the point and with radius .
Robust counterpart of ball uncertainty
A straightforward reformulation leads to the equivalent constraint:
By defining and , we may write:
We now need to add this newly obtained conic constraint to the original BIM model. The Pyomo documentation says a conic constraint is expressed in 'pyomo' in simple variables and this table reports the syntax.
Now the optimization problem is nonlinear, but dedicated solvers can leverage the fact that is conic and solve it efficiently. Specifically, cplex, gurobi and xpress support second-order cones. On the other hand, ipopt is a generic solver for nonlinear optimization problems.
The solvers bonmin, cplex, gurobi and xpress are capable of solving the mixed integer version of the same model:
Implementing second-order cones using pyomo.environ
Noting that is for equivalent to and knowing that the commercial solvers (gurobi, cplex and express) support convex quadratic inequalities, we can model this variant in pyomo.environ as follows. Note that the essential part to make the model convex is having the right hand side nonnegative.