avl._core.var module
- class avl._core.var.Var(*args, auto_random: bool = True, fmt: ~collections.abc.Callable[[...], str] = <class 'str'>)[source]
- __init__(*args, auto_random: bool = True, fmt: ~collections.abc.Callable[[...], str] = <class 'str'>) None[source]
Initialize an instance of the class.
- Parameters:
value (Any) – The value associated with the instance.
auto_random (bool, optional) – Flag to enable or disable automatic randomness. Defaults to True.
- property value
Property to abstract the value and ensure it’s always cast when assigned
- get_min() int[source]
Get the minimum value that can be represented by this variable.
- Returns:
The minimum value based on the sign and width of the variable.
- Return type:
int
- get_max() int[source]
Get the maximum value that can be represented by this variable.
- Returns:
The maximum value.
- Return type:
int
- add_constraint(name: str, constraint: BoolRef, hard: bool = True, target: dict | None = None)[source]
Add a constraint to the object.
- Parameters:
name (str) – The name of the constraint.
constraint (function) – The constraint function to add.
hard (bool, optional) – Flag to indicate if the constraint is hard or soft. Defaults to True.
target (dict, optional) – The target dictionary to store the constraint. Defaults to None.
- remove_constraint(name: str) None[source]
Remove a constraint from the object.
- Parameters:
name (str) – The name of the constraint to remove.
- randomize(hard: list | None = None, soft: list | None = None) None[source]
This method randomizes the value of the variable by considering hard and soft constraints. It uses an optimization solver to find a suitable value that satisfies the constraints.
- Parameters:
hard (list, optional) – Optional list of hard constraints to be added. Each constraint is a tuple where the first element is the constraint expression and the second element is the constraint value.
soft (list, optional) – Optional list of soft constraints to be added. Each constraint is a tuple where the first element is the constraint expression and the second element is the constraint value.
Hard and soft constraints follow the SV naming convention. Hard constraints must be satisfied, otherwise an error is raised. Soft constraints will attempt to be satisfied, but if not, the solver will return a solution that minimizes the number of unsatisfied constraints.
- Raises:
ValueError – If an unknown variable is encountered in the model.
Exception – If the solver fails to randomize the variable.