optimize: Enforce start solution with at least two elements Closes #205 (#207)

* mate -> cxTwoPoints needs at least two elements.
This commit is contained in:
Dominique Lasserre 2024-11-18 20:54:39 +01:00 committed by GitHub
parent e18201dcb3
commit c7eb3ec63b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,7 @@ from typing import Any, Optional, Tuple
import numpy as np import numpy as np
from deap import algorithms, base, creator, tools from deap import algorithms, base, creator, tools
from pydantic import BaseModel, Field, model_validator from pydantic import BaseModel, Field, field_validator, model_validator
from typing_extensions import Self from typing_extensions import Self
from akkudoktoreos.class_akku import EAutoParameters, PVAkku, PVAkkuParameters from akkudoktoreos.class_akku import EAutoParameters, PVAkku, PVAkkuParameters
@ -40,6 +40,14 @@ class OptimizationParameters(BaseModel):
raise ValueError("Input lists have different lenghts") raise ValueError("Input lists have different lenghts")
return self return self
@field_validator("start_solution")
def validate_start_solution(
cls, start_solution: Optional[list[float]]
) -> Optional[list[float]]:
if start_solution is not None and len(start_solution) < 2:
raise ValueError("Requires at least two values.")
return start_solution
class EAutoResult(BaseModel): class EAutoResult(BaseModel):
"""This object contains information related to the electric vehicle and its charging and discharging behavior.""" """This object contains information related to the electric vehicle and its charging and discharging behavior."""