Ask Your Question
1

Get index of a set constraint

asked 9 years ago

tom123 gravatar image

Using SageMath I'm trying to implement a method for the solution of a problem where I in an iterative way add a set of constraints, try to solve the problem to check if exist a solution, if not i remove the constraints and restart.

 try:
    p.solve()           
 except RuntimeError:
    p.remove_constraint(index)

Given a set of constraint that I add, how to get their indexes so that I can remove them?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 9 years ago

vdelecroix gravatar image

The constraints should be in the order you entered them. To remove the last just do

sage: p.remove_constraint(p.number_of_constraints() - 1)
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 9 years ago

Seen: 314 times

Last updated: Jan 09 '16