Solution

(class from pyomo.contrib.alternative_solutions.solution)

class pyomo.contrib.alternative_solutions.solution.Solution(model, variable_list, include_fixed=True, objective=None)[source]

Bases: object

A class to store solutions from a Pyomo model.

variables

A map between Pyomo variables and their values for a solution.

Type:

ComponentMap

fixed_vars

The set of Pyomo variables that are fixed in a solution.

Type:

ComponentSet

objective

A map between Pyomo objectives and their values for a solution.

Type:

ComponentMap

pprint():

Prints a solution.

get_variable_name_values(self, ignore_fixed_vars=False):

Get a dictionary of variable name-variable value pairs.

get_fixed_variable_names(self):

Get a list of fixed-variable names.

get_objective_name_values(self):

Get a dictionary of objective name-objective value pairs.

__init__(model, variable_list, include_fixed=True, objective=None)[source]

Constructs a Pyomo Solution object.

Parameters:
  • model (ConcreteModel) – A concrete Pyomo model.

  • variable_list (A collection of Pyomo _GenereralVarData variables) – The variables for which the solution will be stored.

  • include_fixed (boolean) – Boolean indicating that fixed variables should be added to the solution.

  • objective (None or Objective) – The objective functions for which the value will be saved. None indicates that the active objective should be used, but a different objective can be stored as well.

Methods

__init__(model, variable_list[, ...])

Constructs a Pyomo Solution object.

get_fixed_variable_names()

Get a list of fixed-variable names.

get_variable_name_values([include_fixed, ...])

Get a dictionary of variable name-variable value pairs.

pprint([round_discrete, sort_keys, indent])

Print the solution variables and objective values.

to_dict([round_discrete])

to_string([round_discrete, sort_keys, indent])

Attributes

objective_value

rtype: The value of the objective.

Member Documentation

get_fixed_variable_names()[source]

Get a list of fixed-variable names.

Return type:

A list of the variable names that are fixed.

get_variable_name_values(include_fixed=True, round_discrete=True)[source]

Get a dictionary of variable name-variable value pairs.

Parameters:
  • include_fixed (boolean) – If True, then include fixed variables in the dictionary.

  • round_discrete (boolean) – If True, then round discrete variable values in the dictionary.

Return type:

Dictionary mapping variable names to variable values.

pprint(round_discrete=True, sort_keys=True, indent=4)[source]

Print the solution variables and objective values.

Parameters:

rounded_discrete (boolean) – If True, then round discrete variable values before printing.

property objective_value

rtype: The value of the objective.