3

Is it possible to create a standalone executable file with PyInstaller which solves an optimization problem with Pyomo?

For example, I can solve the optimization problem

min_x {2*x_1 + 3*x_2 : x_i >= 0, 3*x_1 + 4*x_2 >= 1}

by creating a file "concreteProblem.py" with the following contents

from __future__ import division
from pyomo.environ import *

model = ConcreteModel()

model.x = Var([1,2], domain=NonNegativeReals)

model.OBJ = Objective(expr = 2*model.x[1] + 3*model.x[2])

model.Constraint1 = Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)

and then entering

pyomo solve --solver=glpk concreteProblem.py

in the command line.

Can I use PyInstaller to construct a standalone executable which does the same thing?

Garrett
  • 181
  • 5

1 Answers1

0

Add following code at the end, This emulates what the pyomo command-line tools does.

if __name__ == '__main__':
    from pyomo.opt import SolverFactory
    import pyomo.environ
    opt = SolverFactory("glpk")
    results = opt.solve(model)
    #sends results to stdout
    results.write()
    print("\nDisplaying Solution\n" + '-'*60)
    pyomo_postprocess(None, model, results)

Then you can use the >>> pyinstaller concreteProblem.py -F --add-binary "C:\Users\USERNAME\AppData\Local\Continuum\anaconda2\Library\bin\glpsol.exe"

Aman
  • 339
  • 3
  • 12