EdNegron
EdNegron

Reputation: 1

How to declare an objective function (Minimize) and it's constraints with upper and lower limits on Python?

I have a linear programming problem with 8 variables.How I can generate a set of constraints (equalities and/or inequalities) with upper and lower bounds on Python in order to minimize an objective function?. I am specifically asking to do it with Pyomo solver if possible,if not using any other solver on Python (e.g., Gurobi, Cplex,etc) is fine, I just want to have an idea on how to tackle this problems on Python.

Upvotes: 0

Views: 434

Answers (1)

Alex Fleischer
Alex Fleischer

Reputation: 10062

Very simple bus and zoo example:

import pyomo.environ as pyo
from pyomo.opt import SolverFactory

opt = pyo.SolverFactory('cplex')

model = pyo.ConcreteModel()

model.nbBus = pyo.Var([40,30], domain=pyo.PositiveIntegers)

model.OBJ = pyo.Objective(expr = 500*model.nbBus[40] + 400*model.nbBus[30])

model.Constraint1 = pyo.Constraint(expr = 40*model.nbBus[40] + 30*model.nbBus[30] >= 300)

results = opt.solve(model)

print("nbBus40=",model.nbBus[40].value)
print("nbBus30=",model.nbBus[30].value)

Upvotes: 0

Related Questions