Skip to content

Custom Solvers

Guide for integrating custom solvers with the use case framework.

Solver Interface

Any solver that can accept a Model and return a Solution works with the framework.

Example: Custom Solver Wrapper

class CustomSolver:
    """Wrapper for custom optimization solver."""

    def __init__(self, **config):
        self.config = config

    def solve(self, model):
        """Solve the model and return solution."""
        # Convert model to solver format
        solver_model = self._convert_model(model)

        # Solve
        raw_solution = self._solve_internal(solver_model)

        # Convert back to framework format
        solution = self._convert_solution(raw_solution)

        return solution

Using with Use Cases

from luna_usecases.traveling_salesman_problem import TspInstance

instance = TspInstance(...)
model = instance.formulate()

# Use custom solver
solver = CustomSolver(time_limit=60)
solution = solver.solve(model)

# Interpret results
result = instance.interpret(solution)

See Also