StructuredSolution¶

class StructuredSolution¶

Bases: object

Class for an solution vector in a ‘structured’ form.

A Structured form is [1, [2, 3, 4], 5], when 1 and 5 are the result of two elemental variable (say, IntegerVariable) and [2, 3, 4] is a result of a ‘variable list’ (e.g. IntegerVariableList) containing three elemental variables. The structured form can show the structual indication of the variable list in the solution vector.

Methods

__init__

Initialize the class.

copy

Duplicate the class instance.

from_solution_dict

Construct a solution in StructuredSolution from a solution dictionary with a 'structured' format.

to_flat

Convert to the FlatSolution.

to_solution_dict

Return corresponding StructuredSolutionDict class instance.

Attributes

names

The names of the variables.

values

The solution vector in a 'structured' list.

__getitem__(i: int) tuple[str, bool | int | float | list[bool] | list[int] | list[float]]¶

Return a tuple of a variable name and a corresponding value.

Parameters:

i (int) – Index.

Returns:

A tuple of a variable name and a corresponding value.

Return type:

tuple[str, bool | int | float | list[bool] | list[int] | list[float]]

__init__(variables: Variables, x: list[bool | int | float | list[bool] | list[int] | list[float]] | None = None) None¶

Initialize the class.

Parameters:
__iter__() Iterator[tuple]¶
__len__() int¶

The length of the solution.

Note that in StructuredSolution, a variable list element is counted as 1 in the length.

Returns:

The length.

Return type:

int

copy() StructuredSolution¶

Duplicate the class instance.

Returns:

The duplicated class instance.

Return type:

StructuredSolution

from_solution_dict(
solution_dict_universe: dict[str, Any] | StructuredSolutionDict,
) StructuredSolution¶

Construct a solution in StructuredSolution from a solution dictionary with a ‘structured’ format.

Parameters:

solution_dict_universe (dict[str, Any] | StructuredSolutionDict) – A solution dictionary with a ‘structured’ format. This can contains values for variables other than the ones exist in the solution. I.e. solution_dict_universe can be a entire solution for a multi-objective optimization whereas this class discribes an individual solution of one of the objective functions.

Returns:

The converted solution.

Return type:

StructuredSolution

to_flat() FlatSolution¶

Convert to the FlatSolution.

Raises:

ValueError – If the number of variables does not match to the number of the element in the value list.

Returns:

The converted solution.

Return type:

FlatSolution

to_solution_dict() StructuredSolutionDict¶

Return corresponding StructuredSolutionDict class instance.

Returns:

The solution dictionary of a variable (list) name and value(s) with a ‘structure’d format..

Return type:

StructuredSolutionDict

__dict__ = mappingproxy({'__module__': 'amplify_bbopt.solution_type', '__doc__': "Class for an solution vector in a 'structured' form.\n\n    A Structured form is [1, [2, 3, 4], 5], when 1 and 5 are the result of two elemental variable (say, :obj:`IntegerVariable`) and [2, 3, 4] is a result of a 'variable list' (e.g. :obj:`IntegerVariableList`) containing three elemental variables. The structured form can show the structual indication of the variable list in the solution vector.\n    ", '__init__': <function StructuredSolution.__init__>, 'values': <property object>, 'to_flat': <function StructuredSolution.to_flat>, '__len__': <function StructuredSolution.__len__>, '__getitem__': <function StructuredSolution.__getitem__>, '__iter__': <function StructuredSolution.__iter__>, 'names': <property object>, 'to_solution_dict': <function StructuredSolution.to_solution_dict>, 'from_solution_dict': <function StructuredSolution.from_solution_dict>, 'copy': <function StructuredSolution.copy>, '__dict__': <attribute '__dict__' of 'StructuredSolution' objects>, '__weakref__': <attribute '__weakref__' of 'StructuredSolution' objects>, '__annotations__': {'_values': 'list[bool | int | float | list[bool] | list[int] | list[float]]'}})¶
__weakref__¶

list of weak references to the object (if defined)

property names: list[str]¶

The names of the variables.

Note that in StructuredSolution, a name of variable list is considered, rather than the its elemental variables’ names.

property values: list[bool | int | float | list[bool] | list[int] | list[float]]¶

The solution vector in a ‘structured’ list.