StructuredSolution¶
- class StructuredSolution¶
Bases:
objectClass 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
Initialize the class.
Duplicate the class instance.
Construct a solution in
StructuredSolutionfrom a solution dictionary with a 'structured' format.Convert to the
FlatSolution.Return corresponding
StructuredSolutionDictclass instance.Attributes
- __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.
- __init__(variables: Variables, x: list[bool | int | float | list[bool] | list[int] | list[float]] | None = None) None¶
Initialize the class.
- __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:
- copy() StructuredSolution¶
Duplicate the class instance.
- Returns:
The duplicated class instance.
- Return type:
- from_solution_dict(
- solution_dict_universe: dict[str, Any] | StructuredSolutionDict,
Construct a solution in
StructuredSolutionfrom 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:
- 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:
- to_solution_dict() StructuredSolutionDict¶
Return corresponding
StructuredSolutionDictclass instance.- Returns:
The solution dictionary of a variable (list) name and value(s) with a ‘structure’d format..
- Return type:
- __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.