On Tue, Jul 7, 2020 at 12:17 PM chandra chowdhury <pc.chandr...@gmail.com> wrote: > > For max=1, there is no solution but for max=2 it has solution. > How can we find upper bound of max using loop for similar > problem? > > p = MixedIntegerLinearProgram(solver='GLPK') > x = p.new_variable() > p.set_binary(x) > p.set_objective(x[0] ) > p.add_constraint(x[0]+x[1],max=1) > p.add_constraint(x[0],min=1) > p.add_constraint(x[1],min=1) > > print p.show() > print p.solve() > A=p.get_values(x) > print A
in this case you don't even need a loop, you can compute the minimal "max" directly: sage: p = MixedIntegerLinearProgram(solver='GLPK') ....: x = p.new_variable() ....: p.set_binary(x) ....: p.set_objective(-x[0]-x[1]) ....: p.add_constraint(x[0],min=1) ....: p.add_constraint(x[1],min=1) ....: p.show() ....: p.solve() ....: p.get_values([x]) ....: Maximization: - x_0 - x_1 Constraints: 1.0 <= x_0 1.0 <= x_1 Variables: x_0 is a boolean variable (min=0.0, max=1.0) x_1 is a boolean variable (min=0.0, max=1.0) -2.0 [{0: 1.0, 1: 1.0}] > > On Mon, Jul 6, 2020 at 11:06 PM chandra chowdhury <pc.chandr...@gmail.com> > wrote: >> >> Hi, >> I am trying to solve MILP using Sage. Problem is if there is no solution >> it gives an error. Instead of an error, I want to change constraints >> (like if initial max=100 which does not give solution, new max=101 which may >> give solution) >> and run the solver automatically. >> >> p = MixedIntegerLinearProgram(solver='GLPK') >> .... >> p.solve() >> >> sage.numerical.mip.MIPSolverException: GLPK: Problem has no feasible >> solution > > -- > You received this message because you are subscribed to the Google Groups > "sage-support" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sage-support+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sage-support/CAC3pSBLinEG_4tubDWocwmjRfgw4nCRjo_pqgXaOrLdxqt8qrg%40mail.gmail.com. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/CAAWYfq0Rz8MSNTCqgQmD5_908m4YGe-i0o0J7c%3DKBYgxEuyzvg%40mail.gmail.com.