Skip to content

Solution

evotoolkit.core.Solution

Represents a candidate solution in the evolutionary process.

Source code in src/evotoolkit/core/solution.py
class Solution:
    """Represents a candidate solution in the evolutionary process."""

    def __init__(
        self,
        sol_string,
        other_info: dict = None,
        evaluation_res: EvaluationResult = None,
    ):
        self.sol_string = sol_string
        self.other_info = other_info
        self.evaluation_res = evaluation_res

Example

from evotoolkit.core import Solution, EvaluationResult

eval_res = EvaluationResult(valid=True, score=0.95, additional_info={"generation": 3})
solution = Solution(
    sol_string="def f(x): return x**2",
    evaluation_res=eval_res,
    other_info={"method": "mutation"}
)

print(solution.sol_string)
print(f"Score: {solution.evaluation_res.score}")