Ask Your Question
1

What happened to the dim parameter of new_variable?

asked 2019-12-27 18:02:45 +0100

dsejas gravatar image

Hello, Sage community!

I remember I could do this in order to have a bi-indexed variable for MILPs:

LP = MixedIntegerLinearProgram(maximization=True)
x = LP.new_variable(nonnegative=True, dim=2)

So, the syntax x[1][2] is valid. This behavior is documented in some books and manuals for SageMath (perhaps, a little dated now).

However, I just tried to do this in one of my programs, and Sage responded:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-350071b4e772> in <module>()
----> 1 x = LP.new_variable(nonnegative=True, dim=Integer(2))

/Scientific/SageMath/local/lib/python3.7/site-packages/sage/numerical/mip.pyx in sage.numerical.mip.MixedIntegerLinearProgram.new_variable (build/cythonized/sage/numerical/mip.c:6019)()
    701         self._backend.problem_name(name)
    702 
--> 703     def new_variable(self, real=False, binary=False, integer=False, nonnegative=False, name="",
    704                      indices=None):
    705         r"""

TypeError: new_variable() got an unexpected keyword argument 'dim'

Actually, LP.new_variable?? shows me the signature of the new_variable function, but the dim argument is missing.

Did something change? How can I get the same behavior now?

SageMath version: 9.0-beta8

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-12-28 02:34:15 +0100

dsejas gravatar image

updated 2019-12-28 02:35:14 +0100

Hello, Sage Community!

By checking the history of changes to the file <SAGE>/sage/numerical/mip.pyx, <SAGE> stands for the directory where I installed SageMath, I have just learned that the dim parameter of the new_variable subroutine was remove in favor of a more productive, more efficient approach: now it's possible to index these variables with arbitrary indexes. In particular, I could use x[1,2], which solves my question, and is much more elegant. Also, I could use x['USA-EU'] if I wanted this variable to represent the quantity of product sent from USA to EU.

By the way, here is where the change happened.

I think this is an amazing feature! And I am leaving this answer in case anyone has a similar question. Or would like to consult an extra resource.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-12-27 18:02:45 +0100

Seen: 289 times

Last updated: Dec 28 '19