Re: [sage-devel] copying MixedIntegerLinearProgram problem
Dear Dima! Thank you for your interest! (I was away for the weekend...) remove_constraint takes as input the index of the constraint to be >> removed! It is unlikely, that add_constraint(variable==0) creates an >> indexed constraint, but perhaps I am mistaken. >> > > Somewhat naively, I'd just check that p.number_of_constraints() goes up > (p.number_of_constraints() calls backend's nrows()), and then remove > the constraint number p.remove_constraint()-1 > > (that is, assuming the backend does not do reordering of them, which is > hopefully the case) > I'll check whether this works. What I would expect however, is that having the constraint a+b <= 2, adding the constraint a == 0 I'd end up with b <= 2 a == 0 instead of a+b <= 2 a == 0. On the other hand, this all will be very slow, unless you do a warm > restart, i.e. you are able to save the state > of the solver before you add the constraint. > And indeed, how do you know that p.solve() will do the warm restart? > Well, apparently it did. > Do you mean to say that formerly you had this happening to you, now it > does not work? > exactly! > Anyhow, I have a problem understanding the code in the original sample > does. Doesn't an exception in the loop throws you out of the loop? > And what the objective function? Would it be more efficient to minimise > assignment[box, colour] rather than set it to 0 and try the feasibility(?) > problem? > If it's indeed a feasibility problem that you are solving, then you could > simply solve for the minimisation of assignment[box, colour], and > if this assignment is 0, then the constraint is OK, otherwise it is not... > > Yes, it's a feasability problem. I want to assign boxes colours, subject to various constraints. First I check whether there is a solution at all. If so, I go through all boxes in this solution, and modify the problem: I insist that the colour the box receives is different from "colour", by adding the constraint assignment[box, colour] == 0. If there still is a solution, I haven't learned anything useful (for my problem) However, if there is no solution, I know that box "box" *must* be coloured with colour "colour". Best, Martin -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
On Friday, May 13, 2016 at 3:16:28 PM UTC+1, Martin R wrote: > > remove_constraint takes as input the index of the constraint to be > removed! It is unlikely, that add_constraint(variable==0) creates an > indexed constraint, but perhaps I am mistaken. > all the constraints are indexed, surely. p.number_of_constraints() is the total number. You can in fact see what happens at the backend: p.get_backend().nrows() is the number of constraints as known to the backend, and p.remove_constraint() simply calls the corresponding backend function. Somewhat naively, I'd just check that p.number_of_constraints() goes up (p.number_of_constraints() calls backend's nrows()), and then remove the constraint number p.remove_constraint()-1 (that is, assuming the backend does not do reordering of them, which is hopefully the case) On the other hand, this all will be very slow, unless you do a warm restart, i.e. you are able to save the state of the solver before you add the constraint. And indeed, how do you know that p.solve() will do the warm restart? Do you mean to say that formerly you had this happening to you, now it does not work? Anyhow, I have a problem understanding the code in the original sample does. Doesn't an exception in the loop throws you out of the loop? And what the objective function? Would it be more efficient to minimise assignment[box, colour] rather than set it to 0 and try the feasibility(?) problem? If it's indeed a feasibility problem that you are solving, then you could simply solve for the minimisation of assignment[box, colour], and if this assignment is 0, then the constraint is OK, otherwise it is not... Dima > Am Freitag, 13. Mai 2016 15:25:17 UTC+2 schrieb Dima Pasechnik: >> >> On Friday, May 13, 2016 at 9:53:13 AM UTC+1, Martin R wrote: >>> >>> >>> Yes, and then? I don't think I can remove it again, can I? >>> sage: p.remove_constraint? Docstring: Removes a constraint from self. I do not thing that this works, because a constraint may (and often >>> will be) subsumed by other constraints already there. >>> >> >> It either works, or else please do a bug report... >> If you added a redundant constraint, its removal should have no effect, >> isn't it? >> >> -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
remove_constraint takes as input the index of the constraint to be removed! It is unlikely, that add_constraint(variable==0) creates an indexed constraint, but perhaps I am mistaken. Am Freitag, 13. Mai 2016 15:25:17 UTC+2 schrieb Dima Pasechnik: > > On Friday, May 13, 2016 at 9:53:13 AM UTC+1, Martin R wrote: >> >> >> Yes, and then? I don't think I can remove it again, can I? >> >>> >>> sage: p.remove_constraint? >>> Docstring: >>>Removes a constraint from self. >>> >>> I do not thing that this works, because a constraint may (and often will >> be) subsumed by other constraints already there. >> > > It either works, or else please do a bug report... > If you added a redundant constraint, its removal should have no effect, > isn't it? > > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
On Friday, May 13, 2016 at 9:53:13 AM UTC+1, Martin R wrote: > > > Yes, and then? I don't think I can remove it again, can I? > >> >> sage: p.remove_constraint? >> Docstring: >>Removes a constraint from self. >> >> I do not thing that this works, because a constraint may (and often will > be) subsumed by other constraints already there. > It either works, or else please do a bug report... If you added a redundant constraint, its removal should have no effect, isn't it? -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
Yes, and then? I don't think I can remove it again, can I? > > sage: p.remove_constraint? > Docstring: >Removes a constraint from self. > > I do not thing that this works, because a constraint may (and often will be) subsumed by other constraints already there. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
On Thursday, May 12, 2016 at 6:17:33 PM UTC+1, Martin R wrote: > > > So, what is the proper way to do it? As I wrote, it's not really an >>> option to solve the whole problem for each new constraint... >>> >> >> add a constraint, and solve again? >> >> Yes, and then? I don't think I can remove it again, can I? > sage: p.remove_constraint? Docstring: Removes a constraint from self. > As I wrote, pseudo-code is as follows, and keep in mind that large_list > really is a large list... > > p = MixedIntegerLinearProgram(constraint_generation=True, > solver="CPLEX") # solver="GLPK") # twice as long # > assignment = p.new_variable(binary=True) > > p.add_constraint(... some relations in terms of assignment[box, > colour] ... ) > > p.solve() > > for (box, colour) in large_list: > p_new = copy(p) > p_new.add_constraint(assignment[box, colour] == 0) > try: > p_new.solve() > > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
> So, what is the proper way to do it? As I wrote, it's not really an >> option to solve the whole problem for each new constraint... >> > > add a constraint, and solve again? > > Yes, and then? I don't think I can remove it again, can I? As I wrote, pseudo-code is as follows, and keep in mind that large_list really is a large list... p = MixedIntegerLinearProgram(constraint_generation=True, solver="CPLEX") # solver="GLPK") # twice as long # assignment = p.new_variable(binary=True) p.add_constraint(... some relations in terms of assignment[box, colour] ... ) p.solve() for (box, colour) in large_list: p_new = copy(p) p_new.add_constraint(assignment[box, colour] == 0) try: p_new.solve() -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
On Thursday, May 12, 2016 at 4:16:07 PM UTC+1, Martin R wrote: > > So, what is the proper way to do it? As I wrote, it's not really an > option to solve the whole problem for each new constraint... > add a constraint, and solve again? Dima > > Martin > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
So, what is the proper way to do it? As I wrote, it's not really an option to solve the whole problem for each new constraint... Martin -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
On 2016-05-12 15:32, Vincent Delecroix wrote: Hi, The point is that you are not able anymore to use variables from other problems. For good reasons obviously... -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] copying MixedIntegerLinearProgram problem
Hi, The point is that you are not able anymore to use variables from other problems. Namely "assignment" is a variable from "p" not "p_new". Vincent On 12/05/16 02:18, 'Martin R' via sage-devel wrote: Hi there! I am having a severe problem with a program of mine that stopped working, very likely after upgrading to 7.2.beta5, but I'm afraid I don't know from which version. (I believe something after 7.1) The error I get is: ValueError: Variable MIPVariable of dimension 1 is a variable from a different problem What I want to do is: check whether a MILP has a solution, and if so, check whether it still has a solution if I add a further constraint. The MILP's take a very long time to solve. What I do and what worked until very recently is roughly: p = MixedIntegerLinearProgram(constraint_generation=True, solver="CPLEX") # solver="GLPK") # twice as long # assignment = p.new_variable(binary=True) p.add_constraint(... some relations in terms of assignment[box, colour] ... ) p.solve() for (box, colour) in large_list: p_new = copy(p) p_new.add_constraint(assignment[box, colour] == 0) try: p_new.solve() bang! What should I do? I don't have a minimal example exhibiting the error, but if absolutely needed, I'd try to create one. Many thanks, Martin -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.