concepts.dsl.constraint.NamedConstraintSatisfactionProblem#
- class NamedConstraintSatisfactionProblem[source]#
Bases:
ConstraintSatisfactionProblem
Methods
add_constraint
(c[, note])Add a constraint to the constraint satisfaction problem.
add_domain_value
(identifier, value)Add a value to the domain of a variable.
add_equal_constraint
(left[, right, note])Add an equality constraint.
clone
([constraints])Clone the constraint satisfaction problem.
empty
()get_domain
(identifier)Get the domain of a variable.
get_name
(identifier, default)get_type
(identifier)Get the type of a variable.
ground_assignment_value
(assignments, identifier)ground_assignment_value_partial
(assignments, ...)new_actionable_var
(dtype[, wrap])Create a new actionable variable.
new_constant_var
(name, dtype[, domain, wrap])new_named_actionable_var
(name, dtype[, ...])new_var
(dtype[, domain, actionable, name, ...])Create a new variable.
print_assignment_dict
(assignments)replace_constants
(assignments)with_group
(expression[, note])Add a group constraint.
Attributes
A mapping from variable indices to the variable objects.
A list of tuples (index, index), indicating that the first index should be solved earlier than the second index.
A list of constraints.
A mapping from variable names to variable indices.
- __init__(index2record=None, name2optimistic_value=None, index_order=None, constraints=None, counter=0, state_timestamp=0)[source]#
Initialize a constraint satisfaction problem.
- Parameters:
index2record (Dict[int, OptimisticValueRecord] | None) – a mapping from variable indices to the variable objects.
index_order (List[Tuple[int, int]] | None) – a list of tuples (index, index), indicating that the first index should be solved earlier than the second index.
constraints (List[Constraint] | None) – a list of constraints.
counter (int) – the counter for generating new variable indices.
name2optimistic_value (Dict[str, OptimisticValue] | None)
state_timestamp (int)
- __new__(**kwargs)#
- add_constraint(c, note=None)#
Add a constraint to the constraint satisfaction problem.
- Parameters:
c (Constraint) – the constraint to be added.
note (Any | None) – the note of the constraint.
- add_domain_value(identifier, value)#
Add a value to the domain of a variable.
- add_equal_constraint(left, right=None, note=None)#
Add an equality constraint.
- Parameters:
left (TensorValue | OptimisticValue) – the left hand side of the equality constraint.
right (TensorValue | OptimisticValue | bool | None) – the right hand side of the equality constraint.
note (Any | None) – the note of the constraint.
- clone(constraints=None)[source]#
Clone the constraint satisfaction problem.
- Parameters:
constraints (List[Constraint] | None) – the constraints to be replaced into the cloned constraint satisfaction problem. If None, the constraints of the original constraint satisfaction problem will be used.
- Return type:
- empty()#
- get_domain(identifier)#
Get the domain of a variable.
- ground_assignment_value_partial(assignments, identifier)#
- Parameters:
assignments (Dict[int, Assignment])
identifier (int)
- Return type:
- increment_state_timestamp()#
- new_actionable_var(dtype, wrap=False, **kwargs)#
Create a new actionable variable.
- Parameters:
dtype (TensorValueTypeBase | PyObjValueType) – the type of the variable.
wrap (bool) – whether to wrap the variable index into an OptimisticValue.
- Return type:
- new_constant_var(name, dtype, domain=None, wrap=False)[source]#
- Parameters:
name (str)
dtype (TensorValueTypeBase | PyObjValueType)
wrap (bool)
- Return type:
- new_named_actionable_var(name, dtype, domain=None, wrap=False)[source]#
- Parameters:
name (str)
dtype (TensorValueTypeBase | PyObjValueType)
wrap (bool)
- Return type:
- new_var(dtype, domain=None, actionable=False, name=None, is_constant=False, wrap=False)#
Create a new variable.
- Parameters:
dtype (TensorValueTypeBase | PyObjValueType) – the type of the variable.
domain (Set[Any] | None) – the domain of the variable. If None, it will be assumed to the full domain of the type.
actionable (bool) – whether the variable is actionable.
name (str | None) – the name of the variable.
is_constant (bool) – whether the variable is constant.
wrap (bool) – whether to wrap the variable index into an OptimisticValue.
- Returns:
The index of the new variable (int) if wrap is False, or the wrapped OptimisticValue if wrap is True.
- Return type:
- print_assignment_dict(assignments)#
- Parameters:
assignments (Dict[int, Assignment])
- replace_constants(assignments)[source]#
- Parameters:
assignments (Dict[str, TensorValue])
- Return type:
- with_group(expression, note=None)#
Add a group constraint.
- Parameters:
expression (ValueOutputExpression)
note (Any)
- constraints: List[Constraint]#
A list of constraints.
- index2record: Dict[int, OptimisticValueRecord]#
A mapping from variable indices to the variable objects.
- index_order: List[Tuple[int, int]]#
A list of tuples (index, index), indicating that the first index should be solved earlier than the second index.
- name2optimistic_value: Dict[str, OptimisticValue]#
A mapping from variable names to variable indices.