Solution

class iohblade.solution.Solution(code='', name='', description='', configspace=None, generation=0, parent_ids=None, operator=None, task_prompt='')

Bases: object

Represents a candidate solution (an individual) in the evolutionary algorithm. Each individual has properties such as code, fitness, feedback, and metadata for additional information.

add_metadata(key, value)

Adds key-value pairs to the metadata dictionary.

Parameters:
  • key (str) – The key for the metadata.

  • value – The value associated with the key.

copy()

Returns a copy of this solution, with a new unique ID and a reference to the current solution as its parent.

Returns:

A new instance of Individual with the same attributes but a different ID.

Return type:

Individual

empty_copy()

Returns a copy of this solution, with a new unique ID and a reference to the current solution as its parent but without other fields.

Returns:

A new instance of Individual with the same attributes but a different ID.

Return type:

Individual

fitness_is_valid() → bool

Checks validity of fitness.

from_dict(data)

Updates the Solution instance from a dictionary. :param data: A dictionary representation of the individual. :type data: dict

Returns:

None

get_metadata(key)

Get a metadata item from the dictionary.

Parameters:

key (str) – The key for the metadata to obtain.

get_summary()

Returns a string summary of this solution’s key attributes.

Returns:

A string representing the solution in a summary format.

Return type:

str

set_operator(operator)

Sets the operator name that generated this individual.

Parameters:

operator (str | tuple) – The name of the operator, or, as passed by LLaMEA >= 1.4, a tuple (Operator, *parent_ids). The tuple is stored as text plus operator_id so the solution stays picklable without LLaMEA installed (the evaluation subprocess does not have it).

set_scores(fitness: float | Fitness, feedback='', error: Exception | None = None)

Set the score of current instance of individual.

Parameters:
  • fitness (float | Fitness) – Fitness/Score of the individual. It is of type float when single objective, or Fitness when multi-objective.

  • feedback (str) – Feedback for the LLM, suggest improvements or target score.

  • error (Exception | str | None) – Exception encountered while evaluating the code, or an error message. Any previous error is cleared; None or "" means no error.

Returns:

self.

Return type:

Solution

to_dict()

Converts the individual to a dictionary.

Returns:

A dictionary representation of the individual.

Return type:

dict

to_json()

Converts the individual to a JSON string.

Returns:

A JSON string representation of the individual.

Return type:

str