pyglobalsearch.PySolutionSet#

class pyglobalsearch.PySolutionSet(solutions)#

Bases: object

A collection of local solutions found by the optimization algorithm.

The OQNLP algorithm typically finds multiple local solutions during its search. This class stores all solutions and provides methods to access them, find the best solution, and iterate over the results.

Solutions are automatically sorted by objective function value (best first).

Examples#

Get optimization results and access solutions:

>>> result = gs.optimize(problem, params)
>>> # Access best solution
>>> best = result.best_solution()
>>> if best:
...     print(f"Best: x = {best.x()}, f(x) = {best.fun()}")
>>> # Check number of solutions
>>> print(f"Found {len(result)} solutions")
>>> # Iterate over all solutions
>>> for i, solution in enumerate(result):
...     print(f"Solution {i}: f(x) = {solution.fun()}")
>>> # Access specific solution by index
>>> second_best = result[1] if len(result) > 1 else None
__init__()#

Methods

__init__()

best_solution()

Returns the best solution in the set based on the objective function value.

is_empty()

Returns true if the solution set contains no solutions.

Attributes

solutions

The list of local solutions found by the optimization algorithm.

best_solution()#

Returns the best solution in the set based on the objective function value.

Returns:

The solution with the lowest objective function value, or None if the set is empty

Return type:

PyLocalSolution or None

is_empty()#

Returns true if the solution set contains no solutions.

Returns:

True if the solution set is empty, False otherwise

Return type:

bool

solutions#

The list of local solutions found by the optimization algorithm.

Returns:

The list of local solutions found by the optimization algorithm

Return type:

list[PyLocalSolution]