coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
533 stars 93 forks source link

enforce types #92

Closed jurasofish closed 4 years ago

jurasofish commented 4 years ago

Previously types were not enforced when adding, multiplying etc. This could easily lead to users ending up with None variables in in their program with no idea how they got there due to user mistakes, for example after neglecting to convert strings to numbers after importing from a file before using them.

The error messages I've added could certainly be made a bit more specific.

e.g. before:

Screen Shot 2020-04-26 at 11 16 59 am

e.g. after:

Screen Shot 2020-04-26 at 11 17 33 am
jurasofish commented 4 years ago

I should note that I opted not to use NotImplemented in the arithmetic functions. This allows the library to retain tighter control over operator overloading. Otherwise, for example, >= constraints could be flipped to <= constraints if the type is not supported in __ge__. This might not be desirable.