Removing Constraints

1,888 views
Skip to first unread message

ESR

unread,
Jun 27, 2016, 7:07:15 AM6/27/16
to pulp-or-discuss
Hi,

I'm doing several optimisations in a sequence. I'm aware that one can:
 - add constraints (just in the normal way)
 - add variables (just in the normal way)
 - remove variables (by making upper and lower bounds zero)
 - change objective (by just re-assigning it in the normal way)

But how do I remove constraints? If this is possible, I'd really appreciate it if you could help me out.

Thanks,
ESR

ESR

unread,
Jul 12, 2016, 12:04:20 PM7/12/16
to pulp-or-discuss
Aha, got it. Just posting to help others.

Suppose you create a problem variable called prob, add stuff to it, solve it etc.
Now you want to change prob, and then resolve it (since building it again from scratch can be time-consuming).

To add variables, do it normally
To remove variables, can just ignore them in the constraints or set them equal to zero.
To add constraints, do it normally
To remove constraints, do:     del prob.constraints[constraint_name]
To change the objective, do it normally

Something to watch out for: duplicating problem variables leads to problems

Stuart Mitchell

unread,
Jul 12, 2016, 7:39:24 PM7/12/16
to pulp-or...@googlegroups.com
Great sorry your original email got lost in my inbox while traveling.

but that is the way to do it.

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 https://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.



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

Nathan Petty

unread,
Oct 19, 2017, 10:13:58 AM10/19/17
to pulp-or-discuss
Looking for an efficient way to remove variables from a problem.

The suggestion here: "To remove variables, can just ignore them in the constraints or set them equal to zero."  Does not work effectively for any problems of realistic size because, for example, setting their value to 0 and/or ignoring them from constraints does not prevent them from the extremely expensive memory and CPU cost of loading them into the problem.

Column-wise modeling, supported by PULP, allows variables to be seamlessly added to the problem, with specific callouts to the constraints that are applicable.  It seems like there should be a reverse operation where you identify a variable to remove, and it removes that column from A matrix (constraints and objective).

Re-declaring the variables from scratch is not an option if the number of variables is large and the number of variables I want to remove is smaller.  You might ask, what's the point of removing a small number of variables, a small number of variables isn't going to slow down solve that much.  Actually, if you are doing this iteratively, trimming the variable set between many many solves, you can see why adding 5 mil vars to a problem over and over will destroy the algorithm speed.  On the other hand, removing 10k variables over and over takes miliseconds.

Nathan Petty

unread,
Nov 17, 2017, 9:09:06 AM11/17/17
to pulp-or-discuss
Looking for an efficient way to remove variables from a problem.

The suggestion here: "To remove variables, can just ignore them in the constraints or set them equal to zero."  Does not work effectively for any problems of realistic size because, for example, setting their value to 0 and/or ignoring them from constraints does not prevent them from the extremely expensive memory and CPU cost of loading them into the problem.

Column-wise modeling, supported by PULP, allows variables to be seamlessly added to the problem, with specific callouts to the constraints that are applicable.  It seems like there should be a reverse operation where you identify a variable to remove, and it removes that column from A matrix (constraints and objective).

Re-declaring the variables from scratch is not an option if the number of variables is large and the number of variables I want to remove is smaller.  You might ask, what's the point of removing a small number of variables, a small number of variables isn't going to slow down solve that much.  Actually, if you are doing this iteratively, trimming the variable set between many many solves, you can see why adding 5 mil vars to a problem over and over will destroy the algorithm speed.  On the other hand, removing 10k variables over and over takes miliseconds.

Stuart Mitchell

unread,
Nov 20, 2017, 4:03:02 PM11/20/17
to pulp-or...@googlegroups.com
I sorry Nathan but at the moment there is no easy way to do this.

Stu

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

Nathan Petty

unread,
Nov 22, 2017, 12:31:23 PM11/22/17
to pulp-or...@googlegroups.com
Thanks Stu, I'll try what I can to get around this. Kind Regards, Nathan
> 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/W_fyEfQpKJg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
Reply all
Reply to author
Forward
0 new messages