Search code examples
optimizationbinarypyomoglpk

Adding a penalty constraint into an optimization model


I am still quite new to Pyomo and optimization in general, but have recently come across a problem, and so I am hoping that someone can push me in the right direction. I have developed a supply chain optimisation model that had production sites with various capacities and these sites deliver various products to various customers. I have recently upgraded the model to account for penalty costs for sites that produce fewer items than their minimum "contractual" amounts. Example if a site has a minimum production threshold of 50, it can produce 40 but then it needs to pay a penalty ((50-40)*$1). I did this by adding a binary variable, multiplied by cost per unit shortfall, multiplied by the shortfall variable in the objective function. The problem is I get an error saying this is now a quadratic function

This is the error>>RuntimeError: Selected solver is unable to handle objective functions with quadratic terms. Objective at issue: objective.

I have done quite a bit or research but have not found a way to get around preventing converting this into a quadratic function by adding the penalty into the mix (by multiplying a variable with another variable). So my question is, are there some tricks or methodologies someone can point me to. I can use a different solver, its just I assume by converting this into a quadratic this will require a lot more computational power (slowing the run time down). Thanks very much!


Solution

  • This is is very doable and not uncommon. You should be able to formulate this and keep everything linear.

    The clearest general approach is to add an additional variable for the overtime/under production/etc. and then include that in the objective function, multiplied by a penalty that would make it less favorable than "regular" production.

    Here is a similar example: https://stackoverflow.com/a/67483886/10789207