Solution¶
- class iohblade.solution.Solution(code='', name='', description='', configspace=None, generation=0, parent_ids=[], operator=None)¶
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.
- Args:
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:
Individual: A new instance of Individual with the same attributes but a different ID.
- from_dict(data)¶
Updates the Solution instance from a dictionary.
- Args:
data (dict): A dictionary representation of the individual.
- Returns:
None
- get_metadata(key)¶
Get a metadata item from the dictionary.
- Args:
key (str): The key for the metadata to obtain.
- get_summary()¶
Returns a string summary of this solution’s key attributes.
- Returns:
str: A string representing the solution in a summary format.
- set_operator(operator)¶
Sets the operator name that generated this individual.
- Args:
operator (str): The name of the operator (for logging purposes).
- set_scores(fitness, feedback='', error='')¶
- to_dict()¶
Converts the individual to a dictionary.
- Returns:
dict: A dictionary representation of the individual.
- to_json()¶
Converts the individual to a JSON string.
- Returns:
str: A JSON string representation of the individual.