i have linear integer programme want solve. installed solver glpk (thanks this answer) , pyomo. wrote code this:
from pyomo.environ import * pyomo.opt import solverfactory = 370 b = 420 c = 2 model = concretemodel() model.x = var([1,2], domain=nonnegativeintegers) model.objective = objective(expr = * model.x[1] + b * model.x[2], sense=minimize) model.constraint1 = constraint(expr = model.x[1] + model.x[2] == c) # ... more constraints opt = solverfactory('glpk') results = opt.solve(model)
this produces solution file results.yaml
.
i have many problems want solve using same model different a
, b
, , c
values. want assign different values a
, b
, , c
, solve model, obtain solution of model.x[1]
, model.x[2]
, , have listing of a
, b
, c
, model.x[1]
, model.x[2]
. read documentation examples write solutions file such results.yaml
.
is there way can access solution values code?
thanks,
i'm not sure if looking for, way have variables being printed in 1 of scripts.
from pyomo.environ import * pyomo.opt import solverfactory pyomo.core import var m = abstractmodel() opt = solverfactory('glpk') # vars, params, objective, constraints.... instance = m.create_instance('input.dat') # reading in datafile results = opt.solve(instance, tee=true) results.write() instance.solutions.load_from(results) v in instance.component_objects(var, active=true): print ("variable",v) varobject = getattr(instance, str(v)) index in varobject: print (" ",index, varobject[index].value)
Comments
Post a Comment