Skip to content

MaxDivSolver

MaxDivSolver

MaxDivSolver(
    vectors: ndarray,
    k: int,
    distance_metric: DistanceMetric,
    diversity_metric: DiversityMetric,
    diversity_tie_breakers: list[DiversityMetric],
    constraints: list[Constraint],
    solver_steps: list[SolverStep],
    seed: int = 42,
)

Solver that combines a maximum diversity problem with a solver configuration.

Use MaxDivSolverBuilder to create instances -- it provides convenient defaults, presets and validation.

Initialize the MaxDivSolver with the given configuration.

Parameters:

Name Type Description Default
vectors ndarray

(n x d ndarray) A set of n vectors in d dimensions.

required
k int

(int) The number of vectors to be selected from the input set ('universe').

required
distance_metric DistanceMetric

(DistanceMetric) The distance metric to use.

required
diversity_metric DiversityMetric

(DiversityMetric) The diversity metric to use.

required
diversity_tie_breakers list[DiversityMetric]

(list[DiversityMetric]) A list of diversity tie-breaker metrics to use.

required
constraints list[Constraint]

(list[Constraint]) A list of m constraints to try to satisfy during solving.

required
solver_steps list[SolverStep]

(list[SolverStep]) A list of solver steps to execute, the first of which needs to be an InitializationStep, while all latter ones need to be OptimizationSteps.

required
seed int

(int) Random seed for the solver.

42

solve

solve(verbosity: int = 10) -> MaxDivSolution

Solve the maximum diversity problem with the given configuration.

Parameters:

Name Type Description Default
verbosity int

(int) The verbosity level. 0 = silent, 10 = tqdm progress bar per solver step 2x = progress table with iteration count, metrics, elapsed time, ... 20 --> slowest updates (spacing increasing with 10%) 21 --> slower updates (spacing increasing with 5%) 22 --> faster updates (spacing increasing with 2%) 23 --> fastest updates (spacing increasing with 1%)

   25  -->  debug mode       (1% spacing + debug info column)
10

Returns:

Type Description
MaxDivSolution

A MaxDivSolution object representing the solution found.