GMSSolutionLoader

(class from pyomo.contrib.solver.solvers.gms_sol_reader)

class pyomo.contrib.solver.solvers.gms_sol_reader.GMSSolutionLoader(pyomo_model, gdx_data: dict[str, tuple[float, float]], gms_info: GAMSWriterInfo)[source]

Bases: SolutionLoader

Loader for solvers that create .gms files (e.g., gams)

__init__(pyomo_model, gdx_data: dict[str, tuple[float, float]], gms_info: GAMSWriterInfo) None[source]

Methods

__init__(pyomo_model, gdx_data, gms_info)

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

solution(solution_id)

Return a view object that can be used to access a specific solution

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=None)[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]

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() None

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

load_solution() None

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.

solution(solution_id: Any) SolutionLoaderView

Return a view object that can be used to access a specific solution

The resulting SolutionLoaderView object can be used in two ways. First, as a context manager:

results = solver.solve(model)
with results.solution(2) as soln:
    soln.load_vars()
    soln.load_import_suffixes()

or

results = solver.solve(model)
with results.solution(2):
    results.load_vars()
    results.load_import_suffixes()

Or as if it were a SolutionLoader:

Parameters:

solution_id (Any) – The solution identifier to “activate” and make available