• Gurobi Staff
Hi Maik,

Copying your snippet in Python gives me a different error message:
gurobipy.GurobiError: Variable has not yet been added to the model

The reason is that the sum is over $$\texttt{div[prod_vars[i],demand[i]]}$$. In Gurobi, you cannot use decision variables as indices. Please take a look at different types of the optimization problems supported by the Gurobi Optimizer.

I am still not clear what the decision variables are in your problem.
• You have 10 orders for 4 different products.
• Each product has a capacity. As an example, there are orders 4, 5, 7, and 10 for product 1, but only three of them can be delivered using product 1 because the capacity for product 1 is three.
Can an order be delivered using a different product? For example, is it possible to deliver order 10 using product 2 which is the most similar one to product 1 (it has the lowest deviation value in the div matrix)? Do you want to find which product should be used to deliver each order to minimize the deviation between the products used to deliver orders from the original required products?

Best regards,
Maliheh

Hi Maliheh,

Concerning your general questions about the optimization problem: Yes :) I think you got it all right! The aim is to find a production plan that sticks to the ressources and then minimizes the devitation from the originial demand plan.

I wanted to minimize the total deviation in a way that the optimizer sets a certain product for each order. So there should be a decision variable for each order which contains an integer referring to the corresponding product. Then there was a demand vector and a production plan vector, whose pairwise value devationen could be extraced from the given div matrix and summarized.

I understand, that this does not seem possible in gurobi the way I tried to build it. Is there another way you can think of realizing this kind of task?

Best regards,

Maik

• Gurobi Staff

Hi Maik,

You can define the decision variables as binary variables $$x_{ij}$$ being equal to 1 if order $$i$$ is delivered by product $$j$$ and to 0 otherwise.

Let us further define $$r_i$$ to represent the required product for order $$i$$ (it is the demand dictionary in your example) and $$d_{kj}$$ to represent the penalty of serving an order using product $$j$$ instead of product $$k$$ (it is the div dictionary in your example) . As an example, $$r_1 = 3, r_2 = 2, ...$$ and $$d_{11} = 0, d_{12}=0.2, ...$$.

You can then define your objective function as $$\sum_{i, j} d_{r_{i}j} x_{ij}$$. For example, if order 1 is delivered by product 4 instead of 3, we will have $$x_{14} = 1$$ and the penalty will be $$d_{34} \times x_{14} = 0.6$$. You, of course, will need to add constraints to make sure that each order is delivered by one product and that the capacity constraint is satisfied.

Best regards,

Maliheh