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

UnboundLocalError when printing the problem structure #139

Closed
costezki opened this issue Jul 10, 2017 · 1 comment
Closed

UnboundLocalError when printing the problem structure #139

costezki opened this issue Jul 10, 2017 · 1 comment

Comments

@costezki
Copy link

I bumped into the error "UnboundLocalError: local variable 's' referenced before assignment" when I use the following code. A full stack trace is available after it.
I run it on Ubuntu-64 using Python 2.7.13 and pulp version is 1.6.6.

import pulp

my_lp_problem = pulp.LpProblem("My LP Problem", pulp.LpMaximize)

x = pulp.LpVariable('x', lowBound=0, cat='Continuous')
y = pulp.LpVariable('y', lowBound=2, cat='Continuous')

# Objective function
my_lp_problem += 4 * x + 3 * y, "Z"

# Constraints
my_lp_problem += 2 * y <= 25 - x
my_lp_problem += 4 * y >= 2 * x - 8
my_lp_problem += y <= 2 * x - 5

my_lp_problem
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/IPython/core/formatters.pyc in __call__(self, obj)
    697                 type_pprinters=self.type_printers,
    698                 deferred_pprinters=self.deferred_printers)
--> 699             printer.pretty(obj)
    700             printer.flush()
    701             return stream.getvalue()

/usr/local/lib/python2.7/dist-packages/IPython/lib/pretty.pyc in pretty(self, obj)
    381                             if callable(meth):
    382                                 return meth(obj, self, cycle)
--> 383             return _default_pprint(obj, self, cycle)
    384         finally:
    385             self.end_group()

/usr/local/lib/python2.7/dist-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
    501     if _safe_getattr(klass, '__repr__', None) not in _baseclass_reprs:
    502         # A user-provided repr. Find newlines and replace them with p.break_()
--> 503         _repr_pprint(obj, p, cycle)
    504         return
    505     p.begin_group(1, '<')

/usr/local/lib/python2.7/dist-packages/IPython/lib/pretty.pyc in _repr_pprint(obj, p, cycle)
    699     """A pprint that just redirects to the normal repr function."""
    700     # Find newlines and replace them with p.break_()
--> 701     output = repr(obj)
    702     for idx,output_line in enumerate(output.splitlines()):
    703         if idx:

/usr/local/lib/python2.7/dist-packages/pulp/pulp.pyc in __repr__(self)
   1141         string += "VARIABLES\n"
   1142         for v in self.variables():
-> 1143             s += v.asCplexLpVariable() + " " + LpCategories[v.cat] + "\n"
   1144         return s
   1145 

UnboundLocalError: local variable 's' referenced before assignment
@stumitchell
Copy link
Contributor

Sorry that was some merge problems from me should be fixed in 1.6.7 please check.

Would be nice if we could figure out how to run CI against all of the solvers.

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

No branches or pull requests

2 participants