or-fusion / pyomo_simplemodel

An extension of Pyomo that defines a simple modeling class that is similar to PuLP
Other
6 stars 6 forks source link

Only binary vars working #3

Closed SanPen closed 5 years ago

SanPen commented 5 years ago

Hi, I am toying around with the SimpleModel and I cannot solve a super simple example with real vars.

from pyomo.contrib.simplemodel import *

# Create model
model = SimpleModel(maximize=True)

# Variables
x = model.var('x', [1, 2], within=NonNegativeReals)

# Objective
model += x[1] + 2 * x[2]

# Constraint
model += (3 * x[1] + 4 * x[2]) >= 1
model += (2 * x[1] + 5 * x[2]) >= 2

# Optimize
status = model.solve('xpress')

# Print the status of the solved LP
print("Status = %s" % status.solver.termination_condition)

# Print the value of the variables at the optimum
for i in [1, 2]:
    print("%s = %f" % (x[i], x[i].value))

# Print the value of the objective
print("Objective = %f" % model.objective().expr())

model.display()
whart222 commented 5 years ago

What type of error do you get? Pyomo's support for xpress is limited, so that might be the issue.

SanPen commented 5 years ago

The problem solve() returns status unknown and the variables' content is None as a consequence.

The solver is in the PATH variable and all seems to work. I can run regular pyomo models.

whart222 commented 5 years ago

Your problem is unbounded below, so there is no solution to report.

I agree that xpress should return a more sensible status. I tried using glpk, and I got a similarly uninformative

SanPen commented 5 years ago

Great thanks!