Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More error checking in MixedIntegerLinearProgram #20304

Closed
mkoeppe opened this issue Mar 27, 2016 · 20 comments
Closed

More error checking in MixedIntegerLinearProgram #20304

mkoeppe opened this issue Mar 27, 2016 · 20 comments

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented Mar 27, 2016

The get_values method silently ignored non-variables.

CC: @dimpase @nathanncohen

Component: numerical

Author: Matthias Koeppe

Branch/Commit: 7d7aeed

Reviewer: Vincent Delecroix

Issue created by migration from https://trac.sagemath.org/ticket/20304

@mkoeppe mkoeppe added this to the sage-7.2 milestone Mar 27, 2016
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 27, 2016

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 27, 2016

comment:2

The get_values method silently ignored non-variables.


New commits:

dc3895bMixedIntegerLinearProgram.get_values: Input checking

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 27, 2016

Author: Matthias Koeppe

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 27, 2016

Commit: dc3895b

@mkoeppe

This comment has been minimized.

@videlec
Copy link
Contributor

videlec commented Mar 29, 2016

Reviewer: Vincent Delecroix

@videlec
Copy link
Contributor

videlec commented Mar 29, 2016

comment:4

Please use new style error ValueError(msg) instead of ValueError, msg (Python 3 compatibility).

Would be better to use repr rather than str. The output of "{!r}".format(l) is nicer than str(l). As you can see

sage: l = 1
sage: str(l)
'1'
sage: "{!r}".format(l)
'1'
sage: l = '1'
sage: str(l)
'1'
sage: "{!r}".format(l)
"'1'"

The following are not caught correctly

sage: M1 = MixedIntegerLinearProgram()
sage: M2 = MixedIntegerLinearProgram()
sage: x = M1.new_variable()
sage: y = M1.new_variable()
sage: z = M2.new_variable()
sage: M2.add_constraint(z[0] <= 5)
sage: M2.solve()
0.0
sage: M2.get_values(x)              # should be a ValueError
Traceback (most recent call last):
...
KeyError: x_0
sage: M2.get_values(y)              # should be a ValueError
{}

@videlec
Copy link
Contributor

videlec commented Mar 29, 2016

comment:5

And if the input is not a variable it would be better to raise a TypeError rather than a ValueError.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 29, 2016

Changed commit from dc3895b to 4290bde

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 29, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

4290bdeMixedIntegerLinearProgram: use new style error ValueError(msg) instead of ValueError, msg (Python 3 compatibility).

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 29, 2016

Changed commit from 4290bde to 13e82d9

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 29, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

67a263dMIPVariable: New method mip
13e82d9MixedIntegerLinearProgram.get_values: Also check that a MIPVariable is from the right MIP

@videlec
Copy link
Contributor

videlec commented Mar 29, 2016

comment:9

Nice.

Last thing: the first error should be a ValueError. The type is indeed the good one!

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 29, 2016

comment:10

Should I then make it a ValueError also when it's a string, but not one that names a variable?
(If so, what's the right way to test if it is a string?)

@videlec
Copy link
Contributor

videlec commented Mar 29, 2016

comment:11

Replying to @mkoeppe:

Should I then make it a ValueError also when it's a string, but not one that names a variable?
(If so, what's the right way to test if it is a string?)

Not necessarily (one can assume that the "good" way of calling this function is with a MIP variable). Though, to test if the object x is a string you can use isinstance(x, str) (which returns a boolean).

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 29, 2016

comment:12

I was confused, it actually does not accept strings -- only MIPVariable objects.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 29, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

7d7aeedMixedIntegerLinearProgram.get_values: Raise TypeError when not a MIPVariable, ValueError when from the wrong MIP

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 29, 2016

Changed commit from 13e82d9 to 7d7aeed

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Mar 30, 2016

comment:15

Thanks for reviewing!

@vbraun
Copy link
Member

vbraun commented Mar 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants