Reuse model for heuristic algorithm

65 views
Skip to first unread message

juan pineros

unread,
May 8, 2020, 5:13:05 PM5/8/20
to pulp-or-discuss
Hello community,
I contact you, to see if by maybe you can guide me with a problem that I have, which is related to a structure to do a Heuristic in PULP.

Currently I already have my model created, but it takes about 15 minutes to be created, and knowing that the heuristic must be solved at least 20 times, I would like to save that time (15 * 20 min = 6.5 hours).

Now I don't know if you know any function of PULP or PYTHON that will help me to do that and save as the base model, and then in each interaction use fixValeu to fix some variables with the interaction past value and others selected randomly (I already know how to do that, I keep in a dic the result of the past interaction and in the new use the dic information that I need, regarding the new one I only change its binary value).

Using fixValeu it told me the uperbound and lowBound of the variables, and it is generating not knowing how to do to develop this heuristic.

In advance, thank you very much for the attention

I hope you can help me and if perhaps PULP is not able, which one would you recommend to me to be implemented in it?

Ivan Calderon

unread,
May 9, 2020, 2:12:20 PM5/9/20
to pulp-or-discuss
Hi Juan,

I don't know if this is going to help you, but yuo may try ussing python's threading or multiprocessing, but preferably threading because it seems that you need to share some values.

Franco Peschiera

unread,
May 10, 2020, 1:34:23 PM5/10/20
to pulp-or-discuss
Hello Juan,

Regarding the time it takes to build your model, are you able to share the code you're using to build the model in pulp?

Because, in my experience, building the model should not take too much time. Of course it depends on your data and your model but if you share your code maybe we can help make it faster if possible. I've reduced the time to build models by several orders of magnitude by changing the python code.

With respect to the other part of the message, I fear I did not understand what you are asking.

regards,

Franco

juan pineros

unread,
May 12, 2020, 10:55:31 AM5/12/20
to pulp-or...@googlegroups.com
Thanks for your answer.

The question is How can I load or reuse a model  (file.lp), because I need to solve this with some variables fix each interaction.

--
New posters to this group are moderated which can take up to 48 hours, so please be patient if your first post takes a while to turn up.
---
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 view this discussion on the web visit https://groups.google.com/d/msgid/pulp-or-discuss/d7bfb44a-dfb1-496e-b46c-6483a6c1ad5d%40googlegroups.com.

Stuart Mitchell

unread,
May 12, 2020, 6:03:03 PM5/12/20
to pulp-or...@googlegroups.com
Hi you can't use the 'file.lp' in pulp but you can solve a problem multiple times.
Though with the default solver a new lp file will be generated it will not usually take very long at all.

Stu

Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru


Franco Peschiera

unread,
May 15, 2020, 6:35:13 AM5/15/20
to pulp-or-discuss

You can fix variables after a solve statement and the solve again. For example, something like this:

import pulp as pl

x = pl.LpVariable(...)
pb = pl.LpProblem()

#.. build the probl with constraints

pb.solve()

# you can here fix some variables and then do:
x.setInitialValue()
x.fixValue()

pb.solve()

In case it’s useful there is a copy method to the LpProblem.

I haven’t used it, but I’m guessing it would go something like this:

import pulp as pl

x = pl.LpVariable(...)
pb = pl.LpProblem()

#.. build the probl with constraints

pb.solve()

# you can here fix some variables and then do:
pb1 = pb.copy()
x.setInitialValue()
x.fixValue()
# maybe add more constraints to pb1
# pb should remain the same

pb1.solve()

The only thing to take into account is that variables are shared between models.

regards,

Franco

To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.

--
New posters to this group are moderated which can take up to 48 hours, so please be patient if your first post takes a while to turn up.
---
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-discuss+unsubscribe@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages