title: Pyomo: Access Solution From Python Code
body: <p>I have a linear integer programme I want to solve. I installed solver glpk (thanks to <a href="https://stackoverflow.com/questions/20690195/how-do-you-install-glpk-solver-along-with-pyomo-in-winpython/37918417#37918417">this answer</a>) and pyomo. I wrote code like this:</p>
  
  <pre><code>from pyomo.environ import *
  from pyomo.opt import SolverFactory
  
  a = 370
  b = 420
  c = 2
  
  model             = ConcreteModel()
  model.x           = Var([1,2], domain=NonNegativeIntegers)
  model.Objective   = Objective(expr = a * 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)
  </code></pre>
  
  <p>This produces solution to file <code>results.yaml</code>.</p>
  
  <p>I have many problems I want to solve using the same model but with different <code>a</code>, <code>b</code>, and <code>c</code> values. I want to assign different values to <code>a</code>, <code>b</code>, and <code>c</code>, solve the model, obtain solution of <code>model.x[1]</code> and <code>model.x[2]</code>, and have a listing of <code>a</code>, <code>b</code>, <code>c</code>, <code>model.x[1]</code> and <code>model.x[2]</code>. I read <a href="https://software.sandia.gov/downloads/pub/pyomo/PyomoOnlineDocs.html#_a_simple_concrete_pyomo_model" rel="noreferrer">documentation</a> but examples only write solutions to file such as <code>results.yaml</code>.</p>
  
  <p>Is there any way I can access to solution values from code?</p>
  
  <p>Thanks,</p>