## Server Bug Fix: Formulation of assignment problem as Linear Optimization

In the anti-tumor treatment with radiotherapy, it is possible to irradiate the tumoral mass from different positions with different intensities. For each of these possibilities, however, one has to take into account the harmful side effects that the treatment causes to the adjacent organs.
Suppose you have a discrete set of positions from which the tumor can be irradiated and want to decide with what level of intensity to irradiate the tumor from each position. You must consider a number of adjacent organs to preserve and for every possible position you have
the data expressing the percentage of radiation that would affect the tumor and the percentage of radiation that would strike each of the adjacent organs. In fact, the following table shows the percentage of radiation going from each position (on the columns) to the tumor and to the adjacent organs (on the rows).

$$begin{array}{cccccc} hline & 1& 2&3&4&5 \ hline text{Tumor} & 0.4 & 0.3 & 0.25 & 0.7 & 0.5 \ text{Organ 1} & 0.1 & 0 & 0 & 0.1 & 0.2 \ text{Organ 2} & 0.1 & 0 & 0.15 & 0 & 0.1 \ text{Organ 3} & 0 & 0.1 & 0 & 0 & 0 \ text{Organ 4} & 0 & 0.2 & 0.1 & 0.1 & 0 \ hline end{array}$$

The intensity of radiation which can be used in the treatment is limited to 60 Gray and there are upper bounds on the quantity of radiations coming from each position as follows

$$begin{array}{cc} hline text{Position} & text{Upper limit} \ hline 1 & 12 \ 2 & 13\ 3 & 10\ 4 & 15\ 5 & 15\ hline end{array}$$

You want to maximize the quantity of radiations affecting the tumor but also respect the following tolerance levels for each adjacent organ

$$begin{array}{cc} hline text{Organ #} & text{Max Gray per organ} \ hline 1 & 5.5 \ 2 & 9.0\ 3 & 6.0\ 4 & 2.4\ hline end{array}$$

How to formulate the above problem as a linear optimization problem to find the quantity or radiation which has to be supplied from each position in order to maximize the quantity received by the target tumor, but respecting the limit of radiation per organ?

Thanks.

It is not an assignment problem.

You get to decide the intensity of each position. Suppose $$y_i$$ is the intensity from position $$i$$ that you decide to apply, then the quantity of treatment of tumor that we want to maximize is

$$max_y0.4y_1+0.3y_2+0.25y_3+0.7y_4+0.5y_5$$

Also you need to limit the total intensity, hence $$sum_i y_i le 60$$

Exercises left for you:

• Also you have to limit the intensity from each angle. I will leave this task to you. For the first treatment. $$y_1 le 12$$.

• Also, note that we have to consider the tolerance level of each organ. I will also leave this task for you. For the first organ, the constraint is $$0.1y_1+0.1y_4+0.2y_5 le 5.5.$$

Don’t forget the nonnegative constraint too.

Tagged : /

## Math Genius: Dealing with ABSOLUTE VALUE and IF STATEMENT in linear integer programming

I am trying to write a linear constraint that computes the absolute value of a difference, only if both the variables $$x$$ and $$y$$ are different from zero.

$$x,y$$ are binary variables while $$s$$ is a positive integer variable. $$a$$ and $$b$$ are positive integer coefficients.

$$|xa-yb| leq s$$ only if $$x neq 0$$ and $$y neq 0$$

for the first part I did:

$$(xa-yb) leq s$$ and $$-(xa-yb) leq s$$

but I don’t know how to proceed with the second part, if that is ever possible.

You can change $$dots le s$$ to $$dots le s + M(2 – x – y)$$ where $$M$$ is an a priori upper bound on $$|xa-yb|$$. If either or both of the binary variables is 0, the inequality will not be restrictive.

You can enforce
$$(x = 1 land y = 1) implies |a-b| le s$$
with linear constraint
$$|a-b|(x + y – 1) le s.$$

Do you instead (or also) want to enforce
$$|a-b| le s implies (x = 1 land y = 1),$$
which is the converse?

## Server Bug Fix: How to add logical OR constraint in OR-Tools?

Let’s say nurses normally do 1 shift

``````for d in all_days:
for s in all_shifts:
model.Add(sum(shifts[(n, d, s)] for n in all_nurses) == 1)
``````

But I want to make nurses either do 1 shift or 3 shifts (but no 2 shifts). How do I combine between

``````        model.Add(sum(shifts[(n, d, s)] for n in all_nurses) == 1)
``````

and

``````        model.Add(sum(shifts[(n, d, s)] for n in all_nurses) == 3)
``````

?

You can also do:

``````model.AddLinearExpressionInDomain(sum(variables), cp_model.Domain.FromValues([1, 3]))
``````

Or even:

``````for d in all_days:
for s in all_shifts:
b = model.NewBoolVar("")
model.Add(sum(shifts[(n, d, s)] for n in all_nurses) == 1).OnlyEnforceIf(b)
model.Add(sum(shifts[(n, d, s)] for n in all_nurses) == 3).OnlyEnforceIf(b.Not())
``````

PS:

Let’s say nurses normally do 1 shift

Wouldn’t that be:

``````for n in all_nurses:
model.Add(sum(shifts[(n, d, s)] for d in all_days for s in all_shifts) == 1)
``````

Introduce a binary variable $$x_{d,s}$$ and change the right hand side to $$1+2x_{d,s}$$.

Tagged : / /

## Math Genius: Converting a conditional constraint (if-then) to integer linear programming.

How can I linearly express the following conditional constraint: If x1 = 1 (x1 is selected) then x2+x3 = 0 (x2 and x3 is not selected) if x1,x2 and x3 are binary?

Rewriting your logical proposition in conjunctive normal form somewhat automatically yields two linear constraints:
$$begin{equation} x_1 implies (neg x_2 land neg x_3) \ neg x_1 lor (neg x_2 land neg x_3) \ (neg x_1 lor neg x_2) land (neg x_1 lor neg x_3) \ ((1- x_1) + (1- x_2) ge 1) land ((1- x_1) + (1- x_3) ge 1) \ (x_1 + x_2 le 1) land (x_1 + x_3 le 1) end{equation}$$
Another approach is to form a single big-M constraint:
$$x_2+x_3le 2(1-x_1).$$ But that is weaker, being an aggregation of the previous two constraints. For example, the big-M constraint does not cut off $$x=(1/2,1/4,3/4)$$.

## Server Bug Fix: Branch and bound algorithm programming code

I want to solve an integer programming problem using the branch and bound method, but I’m having trouble finding the programming code. From what I saw, almost all algorithms use it for traveling salesman problems or job assignment cases. I need the branch and bound algorithm code to solve the problem of integer programming for optimization cases, with the aim of maximization or minimization. Does anyone have a source regarding branch and bound code for the optimization case? Or can anyone suggest where I can find the code? If anyone has it, please let me know. Any programming language doesn’t matter as long as it can solve the problem of maximization or minimization in integer programming problems. Thanks.

There are several open-source software packages that use branch-and-bound to solve integer programming, for example:

Depending on the type of your MIP, there are numerous open-source options:

All of the above: SCIP (free for academics)

If you want to work inside Excel (or LibreOffice), you might look at OpenSolver. Google’s OR-Tools includes the CBC solver and the option to use GLPK, SCIP or Gurobi. (Gurobi is commercial software with a free academic license.)

## Server Bug Fix: How to use the least number of colours to colour different routes of a bus route such that no two intersecting routes will have the same colour

I would like to know of a method in which if provided say 10 routes with details regarding which route intersects with which another route, we can use the least number of colours to colour the routes, without the intersecting routes having the same colour.

For example, say Route 1 intersects with Route 2,3,6,7,9.

Route 2 intersects with Route 1,3,5,7 and so on…

One can use the same colour again.

How should one go about assigning colours to each route and also minimize the number of colours used?

Recognize that each route can be viewed as being a node on a graph. Edges connect nodes if the routes the nodes represent intersect. This is the canonical graph coloring problem for which there are a number of exact and approximate algorithms. Specifically, you’re trying to find a constructive algorithm for determining the chromatic number.

For 10 routes and low recalculation volume, I’d suggest building a simple brute-force algorithm as the quickest way of getting an answer.

## Math Genius: How can i find the solution of this NP-hard optimization problem?

I have an NP-Hard optimization problem of the form:

begin{align} & min {{sumlimits_{i=1}^{M}{{{a}_{i}}}}_{{}}} \ & s.t{{.}::::_{{}}}{{_{{}}}_{{}}}sumlimits_{i=1}^{M}{{{a}_{i}}{{a}_{i+k}}}>0:: : :{{,}_{{}}}{{_{{}}}_{{}}}forall k=0,1,ldots ,M-1 \ & :::::::::::{{a}_{i}}in left{ 0,1 right}::::::::::{{,}_{{}}}i=1,ldots ,M. \ end{align}

How can I found any optimum or sub-optimum solution?

You can linearize the quadratic constraint by introducing a binary variable $$b_{i,k}$$ to represent the product $$a_i a_{i+k}$$. The new constraints are:
begin{align} sum_i b_{i,k} &ge 1 &&text{for all k}\ b_{i,k} &le a_i &&text{for all i and k}\ b_{i,k} &le a_{i+k} &&text{for all i and k} end{align}

## Ubuntu HowTo: Open source MILP solver for quick “good enough” solution

I have a problem that I have already posted elsewhere in OR.stack, but the question is focused around a large binary MILP (about 1 million decision variables). Ultimately, I am more time constrained than optimality constrained. I have an academic version of gurobi and it is able to provide feasible, good enough solutions quite fast (a few minutes). I am looking for a solver that I can use in python that will return the best solution once it hits a max time limit.

I have been using google ORtools with the CBC and SAT integer solvers, but any time I try to invoke a time limit it starts solving and then either ignores the time limit or when it hits, because it hasn’t found the “optimal” solution it returns no solution.

When I use CBC from time to time, it returns the best solution it has found even if it runs into the time limit. I guess, in your case, it has not even found a feasible solution.

I call it this way:

``````cbc file.lp sec 600 solve printi csv solu mysolution.csv
``````

On difficult binary problems, I had some success enabling zero-half cuts or adding more cuts then by default. Have you tried that?

Interestingly enough, one of the best source-open (!= open source) solvers is often overlooked: SCIP (download here); there is a Python interface (PySCIPOpt), too.

The parameter you need is `limits/time`.

edit: right, SCIP comes with a license and is not entirely free. AFAIK, the price tag is small when you use it commercially, the revenues are used mainly to directly support and sustain the research and development.

Depending on your time window, you could try compiling and running CBC in threaded mode. Time is key here because although CBC is many times faster in threaded mode, it takes forever to initialize each new thread, especially for problems that size.

If your time window is enough to account for the generation overhead, CBC could do the trick.

To be honest, however, once we start going to 1m+ variables, that’s really pushing the limits of what open source is capable of.