FlatSolution¶
- class FlatSolution¶
Bases:
object
Class for a solution vector type in a ‘flat’ form.
An example flat form is [1, 2, 3, 4, 5], when (for example) 1 and 2 are the result from two elemental variables (e.g.
IntegerVariable
), and [2, 3, 4] is a result of a ‘variable list’ (IntegerVariableList
) which contains three elemental variables. There is no structual indication of the ‘variable list’ values, and all elemental variables are flattened out.Methods
Initialize the class.
Duplicate the class instance.
Construct
FlatSolution
solution from a solution dictionary orFlatSolution
.Return the corresponding
FlatSolutionDict
class instance.Convert to
StructuredSolution
.Attributes
- __getitem__(i: int) tuple[str, bool | int | float] ¶
Return a tuple of a variable name and a corresponding value in the solution.
- __init__(variables: Variables, x: list[bool | int | float] | None = None) None ¶
Initialize the class.
- __iter__() Iterator[tuple] ¶
A tuple of a variable name and a corresponding value.
- Yields:
tuple[str, bool | int | float] – A tuple of a variable name and a corresponding value
- __len__() int ¶
The length of the solution vector.
Note that in
FlatSolution
, a variable list element with the size N is counted as N in the length.- Returns:
length
- Return type:
- copy() FlatSolution ¶
Duplicate the class instance.
- Returns:
The duplicated class instance.
- Return type:
- from_solution_dict(
- solution_dict_universe: dict[str, Any] | FlatSolutionDict,
Construct
FlatSolution
solution from a solution dictionary orFlatSolution
.- Parameters:
solution_dict_universe (dict[str, Any] | FlatSolutionDict) – A solution dictionary. 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 solution.
- Return type:
- to_solution_dict() FlatSolutionDict ¶
Return the corresponding
FlatSolutionDict
class instance.- Returns:
The convrted solution.
- Return type:
- to_structured() StructuredSolution ¶
Convert to
StructuredSolution
.- Raises:
ValueError – If length of the input value vector is not same as
Variables.num_elemental_variables
.- Returns:
The solution value vector.
- Return type:
- __dict__ = mappingproxy({'__module__': 'amplify_bbopt.solution_type', '__doc__': "Class for a solution vector type in a 'flat' form.\n\n An example flat form is [1, 2, 3, 4, 5], when (for example) 1 and 2 are the result from two elemental variables (e.g. :obj:`IntegerVariable`), and [2, 3, 4] is a result of a 'variable list' (:obj:`IntegerVariableList`) which contains three elemental variables. There is no structual indication of the 'variable list' values, and all elemental variables are flattened out.\n ", '__init__': <function FlatSolution.__init__>, 'values': <property object>, 'to_structured': <function FlatSolution.to_structured>, '__len__': <function FlatSolution.__len__>, '__getitem__': <function FlatSolution.__getitem__>, '__iter__': <function FlatSolution.__iter__>, 'names': <property object>, '_get_names': <function FlatSolution._get_names>, 'to_solution_dict': <function FlatSolution.to_solution_dict>, 'from_solution_dict': <function FlatSolution.from_solution_dict>, 'copy': <function FlatSolution.copy>, '__dict__': <attribute '__dict__' of 'FlatSolution' objects>, '__weakref__': <attribute '__weakref__' of 'FlatSolution' objects>, '__annotations__': {'_values': 'list[bool | int | float]'}})¶
- __weakref__¶
list of weak references to the object (if defined)
- property names: list[str]¶
A list of names of variables in the solution.
Note that in
FlatSolution
, a name of variable list is NOT considered. Rather, names of its elemental variables are considered in the list of names.