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

__init__

Initialize the class.

copy

Duplicate the class instance.

from_solution_dict

Construct FlatSolution solution from a solution dictionary or FlatSolution.

to_solution_dict

Return the corresponding FlatSolutionDict class instance.

to_structured

Convert to StructuredSolution.

Attributes

names

A list of names of variables in the solution.

values

The solution vector in a 'flat' form.

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

Return a tuple of a variable name and a corresponding value in the solution.

Parameters:

i (int) – Index.

Returns:

A tuple of the variable name and a corresponding value.

Return type:

tuple[str, bool | int | float]

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

Initialize the class.

Parameters:
  • variables (Variables) – Decision variables directly related to the solution.

  • x (list[bool | int | float] | None, optional) – A solution value vector. Defaults to None.

__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:

int

copy() FlatSolution¶

Duplicate the class instance.

Returns:

The duplicated class instance.

Return type:

FlatSolution

from_solution_dict(
solution_dict_universe: dict[str, Any] | FlatSolutionDict,
) FlatSolution¶

Construct FlatSolution solution from a solution dictionary or FlatSolution.

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:

FlatSolution

to_solution_dict() FlatSolutionDict¶

Return the corresponding FlatSolutionDict class instance.

Returns:

The convrted solution.

Return type:

FlatSolutionDict

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:

StructuredSolution

__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.

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

The solution vector in a ‘flat’ form.