On Monday, May 14, 2012 7:32:25 PM UTC-5, Emil wrote: > > lp = MixedIntegerLinearProgram(maximization=True) > x = lp.new_variable() > > Then I do: > > nlp = copy(lp) > x = nlp.new_variable() > > The variable 'x' now seems to contain different variables. So I cannot > add any constraints that use the existing variables. Or is there some > way to do this? Thanks, >
x *should* contain different variables, for two reasons. First, nlp already has a variable (a copy of the one you created for lp), so if you ask nlp to create a new variable for it, it won't return the variable lp created earlier. Second, after copying lp to nlp, you might want to change some variables in one from real to integer, or vice-versa. Also, I don't think Sage has ever let you create variables & add constraints that way. I don't know why, but if I want a variable with a compact notation, I've found MILP lets you do it this way: sage: x, y = lp[0], lp[1] but NOT sage: x, y = lp.new_variable(), lp.new_variable() You'll get variables alright, but you can't add constraints using the second. The first works fine. To add constraints, I usually do the following: sage: lp = MixedIntegerLinearProgram(maximization=False) sage: lp.add_constraint(2*lp[0] + 3*lp[1] <= 1) sage: nlp = copy(lp) sage: nlp.add_constraint(3*lp[0] - 2*lp[1] <= 1) Or, if you like, use x, y, etc., defining them as I did above (the FIRST way). regards john perry -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org