Using Pyomo with PyInstaller

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Using Pyomo with PyInstaller



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


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?




1 Answer
1



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 Solutionn" + '-'*60)
pyomo_postprocess(None, model, results)



Then you can use the >>> pyinstaller concreteProblem.py -F --add-binary "C:UsersUSERNAMEAppDataLocalContinuumanaconda2Librarybinglpsol.exe"


pyinstaller concreteProblem.py -F --add-binary "C:UsersUSERNAMEAppDataLocalContinuumanaconda2Librarybinglpsol.exe"






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard