PropagatorVariables
BoolEvaluateVariable
¶
Represents a boolean evaluation variable, which is a special case of EvaluateVariable that is expected to evaluate to a boolean value. This class can be used for variables that are expected to represent conditions or constraints that must hold.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the variable. |
expression |
VariableValue
|
The VariableValue instance being evaluated. |
decision_level
property
¶
decision_level: int
Return the decision level at which the value was set.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Decision level of the variable. |
expressions
property
¶
expressions: set[VariableValue]
Return the set of VariableValue instances associated with this variable.
Returns:
| Type | Description |
|---|---|
set[VariableValue]
|
set[VariableValue]: Set containing the VariableValue of this boolean evaluation variable. |
literals
property
¶
parents
property
¶
parents: list[VariableType]
Return parent variables.
Returns:
| Type | Description |
|---|---|
list[VariableType]
|
list[VariableType]: Empty list (bool evaluate variables have no parents). |
__init__
¶
Initialize a BoolEvaluateVariable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the variable. |
required |
expr
|
Expr
|
Expression to evaluate, expected to yield a boolean value. |
required |
literal
|
int
|
Literal controlling whether this variable is active. |
required |
true_lit
|
int
|
Literal representing the true value of the variable. |
required |
false_lit
|
int
|
Literal representing the false value of the variable. |
required |
bad_lit
|
int
|
Literal representing a bad value of the variable. |
required |
add_self_to_evaluations
¶
add_self_to_evaluations(e: Evaluations) -> None
This variable is not added to the evaluation dictionary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
Evaluations
|
Evaluations object to update. |
required |
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> EvaluationResult
Evaluate the expression and return an EvaluationResult.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
Evaluations
|
Current variable evaluations. |
required |
ctl
|
PropagateControl
|
PropagateControl |
required |
env
|
dict[Any, Any]
|
Environment for evaluation. |
required |
get_errors
¶
get_errors() -> propagator_warning_t
Return warnings collected during evaluation.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings. |
get_value
¶
get_value() -> ValueStatus | bool | Bad
Return the current value of the boolean evaluation variable.
Returns:
| Type | Description |
|---|---|
ValueStatus | bool | Bad
|
ValueStatus | bool | expression.Bad: Current value, or NOT_SET. |
has_domain
¶
has_domain() -> bool
Return whether the variable has a domain.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Always True for BoolEvaluateVariable. |
has_unassigned
¶
has_unassigned() -> bool
Check whether the boolean evaluation variable is unassigned.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the value is NOT_SET. |
infer
¶
DictVariable
¶
A dict variable with a name and a set of key-value expressions.
This is supposed to mirror the multimap_declare/2 and multimap_assign/4 atom in the ASP encoding. multimap_declare is this class, while each multimap_assign adds a possible key-value pair to the dict.
Implements the VariableType protocol.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the dict variable. |
var |
Symbol
|
Clingo symbol for the variable. |
expressions |
set[VariableValue]
|
Dictionary mapping keys to SetVariableValue instances. |
value |
ValueStatus | Multimap[Symbol, Any]
|
Current value of the dict variable. |
literal |
int
|
Literal for the dict declaration. |
assigned |
bool | None
|
Truth value of the dict declaration. |
decision_level |
int
|
Decision level of the current value. |
parents |
list[VariableType]
|
Parent variables. |
errors |
propagator_warning_t
|
List of warnings or errors encountered during evaluation. |
is_user_variable |
bool
|
Whether this variable is defined by the user or is an internal variable |
expressions
property
¶
expressions: set[VariableValue]
Return the set of VariableValue instances representing possible keys and their associated values.
Returns:
| Type | Description |
|---|---|
set[VariableValue]
|
set[VariableValue]: Set of possible key expressions. |
literals
property
¶
__init__
¶
Initialize a DictVariable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the dict variable. |
required |
var
|
Symbol
|
Clingo symbol identifying the variable. |
required |
lit
|
int
|
Literal for the dict declaration. |
required |
is_user_variable
|
bool
|
Whether this variable is defined by the user or is an internal variable. |
False
|
add_self_to_evaluations
¶
add_self_to_evaluations(e: Evaluations) -> None
Add this variable's value into the given Evaluations object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
Evaluations
|
Evaluations object to update. |
required |
add_value
¶
add_value(key: Expr, expr: Expr, lit: int) -> None
Add a key-value pair to the dict variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Expr
|
Expression for the key. |
required |
expr
|
Expr
|
Expression for the value. |
required |
lit
|
int
|
Literal for assignment. |
required |
discern_value
¶
discern_value() -> ValueStatus | Multimap[Symbol, Any]
Returns a dictionary mapping keys to their assigned values. If any value is unassigned, returns None for that key.
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> EvaluationResult
Evaluate all values in the dictionary and return (changed, conflict). For DictVariable, conflict should never occur.
get_errors
¶
get_errors() -> propagator_warning_t
Get all errors from the dict variable and its key-value pairs. Bad value warnings are filtered out for non user variables.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings or errors. |
get_value
¶
get_value() -> ValueStatus | Multimap[Symbol, Any]
Get the current value of the dict variable.
Returns:
| Type | Description |
|---|---|
ValueStatus | Multimap[Symbol, Any]
|
ValueStatus | multimap.Multimap[clingo.Symbol, Any]: Current dict value or NOT_SET. |
has_domain
¶
has_domain() -> bool
Check if the dict variable has a domain (any key-value pairs).
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if there are key-value pairs, False otherwise. |
has_unassigned
¶
has_unassigned() -> bool
Check whether any key/value expression is still unassigned.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any key/value expression is unassigned. |
infer
¶
Curently this return an empty set as it does not support any inferences. This is here for compatibility with the VariableType protocol.
EnsureVariable
¶
Represents an 'ensure' atom, which ensures a certain expression holds. Implements the VariableType protocol.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the ensure atom. |
expression |
VariableValue
|
The VariableValue instance being ensured. |
value |
ValueStatus | bool
|
Current value of the expression. |
decision_level |
int
|
Decision level at which the value was set. |
expressions
property
¶
expressions: set[VariableValue]
Return the set of VariableValue instances associated with this variable.
Returns:
| Type | Description |
|---|---|
set[VariableValue]
|
set[VariableValue]: Set containing the VariableValue of this ensure variable. |
literals
property
¶
parents
property
¶
parents: list[VariableType]
Return parent variables.
Returns:
| Type | Description |
|---|---|
list[VariableType]
|
list[VariableType]: Empty list (ensure variables have no parents). |
__init__
¶
add_self_to_evaluations
¶
add_self_to_evaluations(e: Evaluations) -> None
Does nothing, as ensure variables are not added to the evaluation dictionary. This is here for compatibility with the VariableType protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
Evaluations
|
Evaluations object to update. |
required |
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> EvaluationResult
Evaluate the expression and return a tuple (changed, conflict). changed is True if the value has changed. conflict is True if there is a conflict.
get_errors
¶
get_errors() -> propagator_warning_t
Return warnings collected during evaluation.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings. |
get_value
¶
get_value() -> ValueStatus | bool
Return the current value of the ensure variable.
Returns:
| Type | Description |
|---|---|
ValueStatus | bool
|
ValueStatus | bool: Current value, or NOT_SET. |
has_domain
¶
has_domain() -> bool
Return whether the variable has a domain.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Always True for ensure variables. |
has_unassigned
¶
has_unassigned() -> bool
Check whether the ensure variable is unassigned.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the value is NOT_SET. |
infer
¶
Curently this return an empty set as it does not support any inferences. This is here for compatibility with the VariableType protocol.
EvaluateVariable
¶
Represents an evaluate atom defined by an operator and arguments of the operator.
Attributes:
| Name | Type | Description |
|---|---|---|
op |
Operator
|
The operator for the expression. |
args |
list[Expr]
|
List of argument expressions. |
value |
Any
|
The current value of the evaluation. |
literal |
int
|
The associated literal. |
errors |
propagator_warning_t
|
List of warnings or errors encountered during evaluation. |
var
property
¶
var: Symbol
Return a symbolic representation of this evaluation variable.
Returns:
| Type | Description |
|---|---|
Symbol
|
clingo.Symbol: A symbolic representation of this variable. |
__init__
¶
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> bool
Evaluate the expression
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
Evaluations
|
Current variable evaluations. |
required |
ctl
|
PropagateControl
|
PropagateControl for checking literal assignments and decision levels. |
required |
env
|
dict[Any, Any]
|
Environment for evaluation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the value has changed, False otherwise. |
get_errors
¶
get_errors() -> propagator_warning_t
Return warnings collected while evaluating this operation.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings. |
Evaluations
¶
Manages the current evaluations of variables.
Attributes:
| Name | Type | Description |
|---|---|---|
evaluations |
evaluations_type
|
Dictionary mapping variable symbols to their evaluated values. |
false_assignments |
list[Symbol]
|
List of variables that are assigned false. |
existing_vars |
dict[Symbol, int]
|
List of variables that exist in the current evaluation. |
init
¶
init(variables: Iterable[VariableType])
Initialize the existing variables list based on the provided variables. This method should be called before any evaluations are updated to ensure that the existing variables are correctly tracked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables
|
Iterable[VariableType]
|
Iterable of variables to initialize from. |
required |
update_evaluations
¶
update_evaluations(variables: Iterable[VariableType]) -> None
Build a plain Python dictionary from a collection of variables.
The resulting dictionary maps each variable symbol to its evaluated value.
Variables that are assigned false are listed under the FALSE_ASSIGNMENTS key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables
|
Iterable[VariableType]
|
Iterable of variables to export. Variables must implement the |
required |
var_usable
¶
var_usable(var: Symbol) -> bool
Check if a variable is usable in the current evaluation.
A variable is considered usable if it has an assigned value, is listed as a false assignment or does not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
Symbol
|
Variable symbol to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the variable is usable, False otherwise. |
OptimizationHandler
¶
Handles multiple optimization sums, each with a priority.
Attributes:
| Name | Type | Description |
|---|---|---|
sums |
list[OptimizationSum]
|
List of OptimizationSum instances. Note that this is a list and not a dict. OptimizationSums are ordered by priority, with higher priority sums coming first. |
expressions
property
¶
expressions: set[VariableValue]
Return the set of VariableValue instances representing all expressions in all optimization sums.
Returns:
| Type | Description |
|---|---|
set[VariableValue]
|
set[VariableValue]: Set of expressions in all optimization sums. |
literals
property
¶
add_value
¶
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> bool
Evaluate all optimization sums and return True if any value has changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
Evaluations
|
Current variable evaluations. |
required |
ctl
|
PropagateControl
|
Clingo propagate control. |
required |
env
|
dict[Any, Any]
|
Evaluation environment. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any value has changed, False otherwise. |
get_errors
¶
get_errors() -> propagator_warning_t
Get all errors from all optimization sums.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings or errors. |
get_sum_count
¶
get_sum_count() -> int
Get the number of optimization sums.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of optimization sums. |
get_value
¶
has_unassigned
¶
OptimizationSum
¶
Represents a sum for optimization purposes, holding expressions and their priorities.
Attributes:
| Name | Type | Description |
|---|---|---|
expressions |
set[VariableValue]
|
List of (clingo.Symbol, VariableValue) pairs. The symbol is the variable associated with the expresssion. The value of the expression is what is used in the sum. |
value |
int | float
|
The current sum value. |
priority |
int
|
Priority of the optimization sum. |
decision_level |
int
|
Decision level at which the value was set. |
expressions
property
¶
expressions: set[VariableValue]
Return the set of VariableValue instances representing the expressions in the optimization sum.
Returns:
| Type | Description |
|---|---|
set[VariableValue]
|
set[VariableValue]: Set of expressions in the optimization sum. |
literals
property
¶
__init__
¶
__init__(priority: int = 0) -> None
Initialize an OptimizationSum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
priority
|
int
|
Priority of the optimization sum. |
0
|
add_value
¶
add_value(var: Symbol, expr: Expr, lit: int) -> None
Add a value to the optimization sum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
Symbol
|
Clingo symbol for the variable. |
required |
expr
|
Expr
|
Expression to evaluate. |
required |
lit
|
int
|
Associated literal. |
required |
discern_value
¶
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> bool
Evaluate the optimization sum and return True if the value has changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
Evaluations
|
Current variable evaluations. |
required |
ctl
|
PropagateControl
|
Clingo propagate control. |
required |
env
|
dict[Any, Any]
|
Evaluation environment. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the value has changed, False otherwise. |
get_errors
¶
get_errors() -> propagator_warning_t
Get all errors from the evaluation of the optimization sum.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings or errors. |
get_value
¶
has_unassigned
¶
has_unassigned() -> bool
Check if any value in the optimization sum is unassigned.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any value is unassigned, False otherwise. |
SetVariable
¶
A set variable with a name and a set of value expressions.
This is supposed to mirror the set_declare/2 and set_assign/3 atom in the ASP encoding. set_declare is this class, while each set_assign adds a possible value to the set.
Implements the VariableType protocol.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the set variable. |
var |
Symbol
|
Clingo symbol for the variable. |
expressions |
set[VariableValue]
|
SetVariableValue instance holding possible values. |
value |
ValueStatus | frozenset[Any]
|
Current value of the set variable. |
literal |
int
|
Literal for the set declaration. |
assigned |
bool | None
|
Truth value of the set declaration. |
decision_level |
int
|
Decision level of the set declaration. |
parents |
list[VariableType]
|
Parent variables. |
errors |
propagator_warning_t
|
List of warnings or errors encountered during evaluation. |
is_user_variable |
bool
|
Whether this variable is defined by the user or is an internal variable |
expressions
property
¶
expressions: set[VariableValue]
Return the set of VariableValue instances representing possible set elements.
Returns:
| Type | Description |
|---|---|
set[VariableValue]
|
set[VariableValue]: Set of possible element expressions. |
literals
property
¶
__init__
¶
Initialize a SetVariable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the set variable. |
required |
var
|
Symbol
|
Clingo symbol identifying the variable. |
required |
lit
|
int
|
Literal for the set declaration. |
required |
is_user_variable
|
bool
|
Whether this variable is defined by the user or is an internal variable. |
False
|
add_self_to_evaluations
¶
add_self_to_evaluations(e: Evaluations) -> None
Add this variable's value into an output dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
Evaluations
|
Evaluations object to update. |
required |
add_value
¶
add_value(arg: Expr, lit: int) -> None
Add a potential value expression to the set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
Expr
|
Expression representing one possible set element. |
required |
lit
|
int
|
Literal for the corresponding |
required |
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> EvaluationResult
Evaluate the expression and return an EvaluationResult.
get_errors
¶
get_errors() -> propagator_warning_t
Return warnings/errors collected during evaluation. Bad value warnings are filtered out for non user variables
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
Warnings and errors for this set and its elements. |
get_value
¶
If there is an unassigned value, return None. Otherwise return the set of assigned values without the None values.
has_domain
¶
has_domain() -> bool
Check whether the set has a domain.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if at least one value can be assigned. |
has_unassigned
¶
has_unassigned() -> bool
Check whether any element expression is still unassigned.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if at least one element is unassigned. |
infer
¶
Curently this return an empty set as it does not support any inferences. This is here for compatibility with the VariableType protocol.
SetVariableValue
¶
Represents a set of possible values for a set variable.
Attributes:
| Name | Type | Description |
|---|---|---|
values |
Set of VariableValue instances representing possible values. |
literals
property
¶
add_value
¶
add_value(arg: Expr, lit: int) -> None
Add a candidate value to the set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
Expr
|
Expression for a set element. |
required |
lit
|
int
|
Literal guarding the element. |
required |
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> bool
Evaluate the expression and return True if the value has changed.
get_errors
¶
get_errors() -> propagator_warning_t
Return warnings collected while evaluating set elements.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings. |
get_value
¶
If there is an unassigned value, return None. Otherwise return the set of assigned values without the None values.
has_domain
¶
has_domain() -> bool
Return whether at least one value expression is present.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any value expression exists. |
has_unassigned
¶
has_unassigned() -> bool
Check whether any element value is still unassigned.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any element is NOT_SET. |
SharedValue
¶
TODO
var
property
¶
var: Symbol
Return a symbolic representation of this evaluation variable.
Returns:
| Type | Description |
|---|---|
Symbol
|
clingo.Symbol: A symbolic representation of this variable. |
__init__
¶
__init__(expr: Expr, literal: int = -1)
Initialize an EvaluateVariable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
op
|
Operator to apply. |
required | |
args
|
Operands for the operator. |
required | |
literal
|
int
|
Literal controlling whether this operation is active. |
-1
|
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> bool
Evaluate the expression
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
Evaluations
|
Current variable evaluations. |
required |
ctl
|
PropagateControl
|
PropagateControl for checking literal assignments and decision levels. |
required |
env
|
dict[Any, Any]
|
Environment for evaluation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the value has changed, False otherwise. |
get_errors
¶
get_errors() -> propagator_warning_t
Return warnings collected while evaluating this operation.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings. |
Variable
¶
A variable with a name and a value expression.
Class to hold the expressions assigned to a variable (via variable_define, variable_declare, etc). It also evaluates them and discerns the appropriate value for the variable, while keeping track of the decision level and errors.
Implements the VariableType protocol.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the variable. |
var |
Symbol
|
Clingo symbol for the variable. |
expressions |
set[VariableValue]
|
Set of possible values (VariableValue). |
value |
Any
|
Current value of the variable. |
parents |
list[VariableType]
|
Parent variables. |
decision_level |
int
|
Decision level at which the value was set. |
domain_literals |
set[int]
|
Literals defining the domain. |
errors |
propagator_warning_t
|
List of warnings or errors encountered during evaluation. |
is_user_variable |
bool
|
Whether this variable is defined by the user or is an internal variable |
literals
property
¶
__init__
¶
add_self_to_evaluations
¶
add_self_to_evaluations(e: Evaluations) -> None
Add this variable's value to the evaluation dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
Evaluations
|
Evaluations object to update. |
required |
add_value
¶
Add a possible value expression for this variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
Expr
|
Expression representing a candidate value. |
required |
value_lit
|
int
|
Literal for the value assignment. |
required |
domain_lit
|
int
|
Literal indicating the truth value of the domain/declaration context. |
required |
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> EvaluationResult
Evaluate the expression and return an EvaluationResult.
get_errors
¶
get_errors() -> propagator_warning_t
Return warnings collected while evaluating candidate values. Bad value warnings are filtered out for non user variables.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings. |
get_values
¶
has_domain
¶
has_domain() -> bool
Return whether at least one value expression is available.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any candidate expression exists. |
has_unassigned
¶
has_unassigned() -> bool
Check whether any candidate value is still unassigned.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if any candidate value is NOT_SET. |
infer
¶
VariableManager
¶
Manages variables in the propagator. This includes storing variables, retrieving them by name and type, and resetting them based on decision levels.
Attributes:
| Name | Type | Description |
|---|---|---|
variables |
dict[Symbol, dict[VariableTypeNames, VariableType]]
|
Dictionary mapping variable names to VariableType instances. |
add_user_variable_name
¶
add_user_variable_name(name: Symbol) -> None
Add a variable name to the set of user variable names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Symbol
|
The variable name to add. |
required |
add_variable
¶
add_variable(name: Symbol, variable: VariableType) -> None
Add a variable to the manager. We assume that this is called only once for a given VariableType
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
VariableType
|
The VariableType instance to add. |
required |
delete_variable
¶
delete_variable(name: Symbol) -> None
Delete a variable by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Symbol
|
The name of the variable to delete. |
required |
Raises: KeyError: If the variable with the specified name does not exist.
get_variable
¶
get_variable(name: Symbol, var_type: VariableTypeNames) -> VariableType
Get a variable by name and type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Symbol
|
The name of the variable to retrieve. |
required |
var_type
|
VariableTypeNames
|
The type of the variable to retrieve. |
required |
Returns: The VariableType instance if found. Raises: KeyError: If the variable with the specified name and type does not exist.
get_variables
¶
get_variables() -> Iterable[VariableType]
Get all variables managed by this VariableManager. Returns: Iterable[VariableType]: An iterable of all VariableType instances.
get_variables_by_type
¶
get_variables_by_type(var_type: VariableTypeNames) -> Iterable[VariableType]
Get all variables of a specific type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var_type
|
VariableTypeNames
|
The type of variables to retrieve. |
required |
Returns: Iterable[VariableType]: An iterable of VariableType instances of the specified type.
has_var_type
¶
has_var_type(name: Symbol, var_type: VariableTypeNames) -> bool
Check if a variable of a specific type exists for a given name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Symbol
|
The name of the variable to check. |
required |
var_type
|
VariableTypeNames
|
The type of the variable to check. |
required |
Returns: bool: True if the variable of the specified type exists, False otherwise.
VariableType
¶
Bases: Protocol
Protocol for variable types used in the propagator. Defines the required interface for variables.
VariableValue
¶
Represents a single expression appearing in an assignment atom.
Attributes:
| Name | Type | Description |
|---|---|---|
expr |
Expr
|
The expression to evaluate. |
value |
Any
|
The current value of the expression. |
literal |
int
|
The associated literal. |
assigned |
bool | None
|
Whether the literal is assigned. |
decision_level |
int
|
The decision level at which the value was set. |
errors |
propagator_warning_t
|
List of warnings or errors encountered during evaluation. |
literals
property
¶
__init__
¶
__init__(expr: Expr, lit: int)
Initialize a VariableValue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
Expr
|
Expression associated with the variable. |
required |
lit
|
int
|
The literal controlling whether this expression is evaluated. |
required |
evaluate
¶
evaluate(evaluations: Evaluations, ctl: PropagateControl, env: dict[Any, Any]) -> bool
Evaluate the expression
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
Evaluations
|
Current variable evaluations. |
required |
ctl
|
PropagateControl
|
PropagateControl for checking literal assignments and decision levels. |
required |
env
|
dict[Any, Any]
|
Environment for evaluation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the value has changed, False otherwise. |
get_errors
¶
get_errors() -> propagator_warning_t
Return warnings collected while evaluating this value.
Returns:
| Name | Type | Description |
|---|---|---|
propagator_warning_t |
propagator_warning_t
|
List of warnings. |