g.mazzaglia
g.mazzaglia

Reputation: 11

Save Pyomo model Variable

I'm doing an optimization problem and after give the command:

results = solver.solve(model,tee=True)

I will have all my variables solved inside the model object.

There is a way to save and load this model object?

Upvotes: 0

Views: 953

Answers (1)

Jean Martin
Jean Martin

Reputation: 101

The variables will be inside your "model" object, if you have a variable called "A":

model.A.value

will give you its value (or model.A[index].value if it is indexed)

  • If you just want to use the results later in your code just call the value when needed (as shown above)
  • If you want to save them for later The best is to have a function that exports the results towards dictionaries, panda dataframes, and then you can save to txt, csv or excel files using pickle or pandas for excel.
  • You can also save your entire model to a file using "cloudpickle" (it will however not work if you try to open it with a too different environment)

Upvotes: 1

Related Questions