# 7.5 Problem Modification and Reoptimization¶

Often one might want to solve not just a single optimization problem, but a sequence of problems, each differing only slightly from the previous one. This section demonstrates how to modify and re-optimize an existing problem. The example we study is a simple production planning model.

Problem modifications regarding variables, cones, objective function and constraints can be grouped in categories:

• adding constraints and variables,
• modifying existing constraints.

Adding new variables and constraints is very easy. Modifications to existing constraints are more cumbersome, and the user should consider whether it is not worth rebuilding the model from scratch in such case. The amount of work required by Fusion to update the optimizer task may outweigh the potential gains.

Depending on the type of modification, MOSEK may be able to optimize the modified problem more efficiently exploiting the information and internal state from the previous execution. After optimization, the solution is always stored internally, and is available before next optimization. The former optimal solution may be still feasible, but no longer optimal; or it may remain optimal if the modification of the objective function was small.

In general, MOSEK exploits dual information and availability of an optimal basis from the previous execution. The simplex optimizer is well suited for exploiting an existing primal or dual feasible solution. Restarting capabilities for interior-point methods are still not as reliable and effective as those for the simplex algorithm. More information can be found in Chapter 10 of the book [Chv83].

Parameter settings (see Sec. 8.4 (Setting solver parameters)) can also be changed between optimizations.

## 7.5.1 Example: Production Planning¶

A company manufactures three types of products. Suppose the stages of manufacturing can be split into three parts: Assembly, Polishing and Packing. In the table below we show the time required for each stage as well as the profit associated with each product.

Product no. Assembly (minutes) Polishing (minutes) Packing (minutes) Profit ($) 0 2 3 2 1.50 1 4 2 3 2.50 2 3 3 2 3.00 With the current resources available, the company has $$100,000$$ minutes of assembly time, $$50,000$$ minutes of polishing time and $$60,000$$ minutes of packing time available per year. We want to know how many items of each product the company should produce each year in order to maximize profit? Denoting the number of items of each type by $$x_0,x_1$$ and $$x_2$$, this problem can be formulated as a linear optimization problem: (1)$\begin{split}\begin{array}{lcccccll} \mbox{maximize} & 1.5 x_0 & + & 2.5 x_1 & + & 3.0 x_2 & & \\ \mbox{subject to} & 2 x_0 & + & 4 x_1 & + & 3 x_2 & \leq & 100000, \\ & 3 x_0 & + & 2 x_1 & + & 3 x_2 & \leq & 50000, \\ & 2 x_0 & + & 3 x_1 & + & 2 x_2 & \leq & 60000, \end{array}\end{split}$ and $x_0,x_1,x_2 \geq 0.$ Code in Listing 8 loads and solves this problem. Listing 8 Setting up and solving problem (1) Click here to download.  auto c = new_array_ptr<double, 1>({ 1.5, 2.5, 3.0 }); auto A = new_array_ptr<double, 2>({ {2, 4, 3}, {3, 2, 3}, {2, 3, 2} }); auto b = new_array_ptr<double, 1>({ 100000.0, 50000.0, 60000.0 }); int numvar = 3; int numcon = 3; // Create a model and input data Model::t M = new Model(); auto M_ = monty::finally([&]() { M->dispose(); }); auto x = M->variable(numvar, Domain::greaterThan(0.0)); auto con = M->constraint(Expr::mul(A, x), Domain::lessThan(b)); M->objective(ObjectiveSense::Maximize, Expr::dot(c, x)); // Solve the problem M->solve();  ## 7.5.2 Changing the Linear Constraint Matrix¶ Suppose we want to change the time required for assembly of product $$0$$ to $$3$$ minutes. This corresponds to setting $$a_{0,0} = 3$$. Now the Constraint provides the method Constraint.add, which sums the constraint expression with another expression and updates the constraint expression. In our case the update we need is $$1\cdot x_0$$ (since $$2+1=3$$).  con->index(0)->add(x->index(0));  The problem now has the form: (2)$\begin{split}\begin{array} {lccccccl} \mbox{maximize} & 1.5 x_0 & + & 2.5 x_1 & + & 3.0 x_2 & & \\ \mbox{subject to} & 3 x_0 & + & 4 x_1 & + & 3 x_2 & \leq & 100000, \\ & 3 x_0 & + & 2 x_1 & + & 3 x_2 & \leq & 50000, \\ & 2 x_0 & + & 3 x_1 & + & 2 x_2 & \leq & 60000, \\ \end{array}\end{split}$ and $x_0,x_1,x_2 \geq 0.$ After this operation we can reoptimize the problem. ## 7.5.3 Appending Variables¶ We now want to add a new product with the following data: Product no. Assembly (minutes) Polishing (minutes) Packing (minutes) Profit ($)
3 4 0 1 1.00

This corresponds to creating a new variable $$x_3$$, appending a new column to the $$A$$ matrix and setting a new term in the objective. We do this in Listing 9

Listing 9 How to add a new variable (column) Click here to download.
  /*************** Add a new variable ******************************/
// Create a variable and a compound view of all variables
auto x3 = M->variable(Domain::greaterThan(0.0));
auto xNew = Var::vstack(x, x3);
// Add to the exising constraint
con->add(Expr::mul(x3, new_array_ptr<double, 1>({ 4, 0, 1 })));
// Change the objective to include x3
M->objective(ObjectiveSense::Maximize, Expr::dot(new_array_ptr<double, 1>({1.5,2.5,3.0,1.0}), xNew));


After this operation the new problem is:

(3)$\begin{split}\begin{array}{lccccccccl} \mbox{maximize} & 1.5 x_0 & + & 2.5 x_1 & + & 3.0 x_2 & + & 1.0 x_3 & & \\ \mbox{subject to} & 3 x_0 & + & 4 x_1 & + & 3 x_2 & + & 4 x_3 & \leq & 100000, \\ & 3 x_0 & + & 2 x_1 & + & 3 x_2 & & & \leq & 50000, \\ & 2 x_0 & + & 3 x_1 & + & 2 x_2 & + & 1 x_3 & \leq & 60000, \end{array}\end{split}$

and

$x_0,x_1,x_2,x_3 \geq 0.$

## 7.5.4 Appending Constraints¶

Now suppose we want to add a new stage to the production process called Quality control for which $$30000$$ minutes are available. The time requirement for this stage is shown below:

Product no. Quality control (minutes)
0 1
1 2
2 1
3 1

This corresponds to adding the constraint

$x_0 + 2 x_1 + x_2 + x_3 \leq 30000$

to the problem. This is done as follows.

Listing 10 Adding a new constraint. Click here to download.
  /**************** Add a new constraint *****************************/
M->constraint(Expr::dot(xNew, new_array_ptr<double, 1>({1, 2, 1, 1})), Domain::lessThan(30000.0));


Again, we can continue with re-optimizing the modified problem.