SolutionLoaderView

(class from pyomo.contrib.solver.common.solution_loader)

class pyomo.contrib.solver.common.solution_loader.SolutionLoaderView(loader: SolutionLoader, solution_id: Any)[source]

Bases: object

A view onto a specific solution_id from a SolutionLoader

This implements SolutionLoader API for accessing a specific solution_id from a SolutionLoader instance. You can use instances of this class in two ways:

As a SolutionLoader object:

Accessing the public methods on this view will activate the corresponding solution_id and return the result from the underlying loader object.

As a context manager:

If you use this object as a context manager, then the solution_id is activated upon entry and deactivated upon exit. Within the context, you can access either the SolutionLoader API methods on this context manager, or on the underlying loader object to query or access the result.

Parameters:
  • loader (SolutionLoader) – The underlying loader object that this is a view into

  • solution_id (Any) – The solution identifier to activate before accessing results.

__init__(loader: SolutionLoader, solution_id: Any)[source]

Methods

__init__(loader, solution_id)

get_duals([cons_to_load])

Returns a dictionary mapping constraint to dual value.

get_number_of_solutions()

The number of solutions available through this SolutionLoader

get_reduced_costs([vars_to_load])

Returns a ComponentMap mapping variable to reduced cost.

get_solution_ids()

Return the list of available solution identdiers.

get_vars([vars_to_load])

Returns a ComponentMap mapping variable to var value.

load_import_suffixes()

Clear import suffixes on the model and load data returned by the solver.

load_solution()

Load the solution (everything that can be) back into the model

load_vars([vars_to_load])

Load the primal variable values at the solution into the Pyomo model Var objects

Member Documentation

get_duals(cons_to_load: Sequence[ConstraintData] | None = None) dict[ConstraintData, float][source]

Returns a dictionary mapping constraint to dual value.

Parameters:

cons_to_load (Sequence[ConstraintData]) – A list of the constraints whose duals should be retrieved. If cons_to_load is None, then the duals for all constraints will be retrieved.

Returns:

duals – Maps constraints to dual values

Return type:

dict[ConstraintData, float]

get_number_of_solutions() int[source]

The number of solutions available through this SolutionLoader

Returns:

num_solutions – Indicates the number of solutions found

Return type:

int

get_reduced_costs(vars_to_load: Sequence[VarData] | None = None) Mapping[VarData, float][source]

Returns a ComponentMap mapping variable to reduced cost.

Parameters:

vars_to_load (Sequence[VarData]) – A list of the variables whose reduced cost should be retrieved. If vars_to_load is None, then the reduced costs for all variables will be retrieved.

Returns:

reduced_costs – Maps variables to reduced costs

Return type:

ComponentMap[VarData, float]

get_solution_ids() list[Any][source]

Return the list of available solution identdiers.

If there are multiple solutions available, this will return a list of the solution identifiers that can be passed to solution() to activate individual solutions from the solver’s solution pool. If only one solution is available, this will return [None]. If no solutions are available, this will return []

Returns:

solutions_ids – The identifiers for multiple solutions

Return type:

list[Any]

get_vars(vars_to_load: Sequence[VarData] | None = None) Mapping[VarData, float][source]

Returns a ComponentMap mapping variable to var value.

Parameters:

vars_to_load (Sequence[VarData]) – A list of the Pyomo variables whose solution value should be retrieved. If vars_to_load is None, then the values for all variables will be retrieved.

Returns:

primals – Maps variables to solution values

Return type:

ComponentMap[VarData, float]

load_import_suffixes()[source]

Clear import suffixes on the model and load data returned by the solver.

load_solution()[source]

Load the solution (everything that can be) back into the model

load_vars(vars_to_load: Sequence[VarData] | None = None) None[source]

Load the primal variable values at the solution into the Pyomo model Var objects

Parameters:

vars_to_load (Sequence[VarData]) – A list of the minimum set of Pyomo variables whose solution should be loaded. If vars_to_load is None, then the solution to all primal variables will be loaded. Even if vars_to_load is specified, the values of other variables may also be loaded depending on the interface.