Change the objective function and resolve?

1,062 views
Skip to first unread message

Frank Olaf Sem-Jacobsen

unread,
Nov 22, 2014, 3:32:01 AM11/22/14
to pulp-or...@googlegroups.com
Hi guys,

I have a problem which I want to optimise along two different axis in sequence. E.g., first I want to minimise costs, and I then want to add this cost as a constraint and try to maximise some other parameter of the same problem. This would give me the best possible solution for the minimal cost.

This could be quite easily done by simply  building the first problem and solving it, and then building the second problem with a modified objective function (to minimise a different combination of parameters) and adding the solution of the first problem as a constraint to the second. However, I find that most of my time is spent generating the problem. Building the constraints appears to be quite expensive, so I would prefer to find some solution that allows me to reuse the existing problem. This requires me to be able to change the objective function, i.e. replace it with something different, as well as adding the cost result from the first solution as a constraint to the existing problem and solve it again. I would suspect that this also would decrease the solution time for the second problem since we are starting with a valid but suboptimal solution.

Alternatively, is there perhaps a way to build these two requirements into a single LP? I have both targets as part of the objective function already, combined with a weight parameter, but tuning this parameter to give me the type of optimal solution that I'm looking for for any combination of input parameters is impossible, I fear.

Do you have any suggestions for how I could move forward with something like this? I have not been able to find any references to replacing the objective function in the documentation, so maybe it is not possible?

Thanks.

Stuart Mitchell

unread,
Nov 22, 2014, 11:30:55 PM11/22/14
to pulp-or...@googlegroups.com

You just add a new objective with += in the same way you added it in the beginning the old objective will be replaced.

You can also use LpProblem.set objective() which does the same thing or use the LpProblem.sequentialSolve () function which takes a list of objectives and tolerances and does what you want to do.

Stu

--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.
Visit this group at http://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.

Roland Vincze

unread,
Jun 3, 2016, 10:08:54 AM6/3/16
to pulp-or-discuss
Hello!

I would like to use more objectives as well (actually a number of 4), but sometimes minimising sometimes maximising. How does the sequentialSolve function work? How can I add all the objectives to the model? Is there any documentation of this functionality?

Thanks,
Roland

Stuart Mitchell

unread,
Jun 5, 2016, 8:40:27 PM6/5/16
to pulp-or...@googlegroups.com
documentation is in https://github.com/coin-or/pulp/blob/master/src/pulp/pulp.py#L1649

the function assumes you want to minimise all objectives. So please multiply all maximise objectives by -1 to convert the objective to a minimise objective.

Stu


For more options, visit https://groups.google.com/d/optout.



--
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

Roland Vincze

unread,
Jun 8, 2016, 8:27:47 AM6/8/16
to pulp-or...@googlegroups.com
I see. Could you please give me a short example code? I don't know what objects to provide as the 'objectives' argument (I tried LpProblem, but that does not work).

--
You received this message because you are subscribed to a topic in the Google Groups "pulp-or-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pulp-or-discuss/9UJhy45UM_Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pulp-or-discu...@googlegroups.com.

Stuart Mitchell

unread,
Jun 8, 2016, 9:17:47 PM6/8/16
to pulp-or...@googlegroups.com
LpAffineExpression some thing like

>>> a + b + c
Reply all
Reply to author
Forward
0 new messages