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.

get_domain(identifier)

Get the domain of a variable.

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

all_constants_resolved

index2record

A mapping from variable indices to the variable objects.

index_order

A list of tuples (index, index), indicating that the first index should be solved earlier than the second index.

constraints

A list of constraints.

name2optimistic_value

A mapping from variable names to variable indices.

__init__(index2record=None, name2optimistic_value=None, index_order=None, constraints=None, counter=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) –

__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.

Parameters:
  • identifier (int) –

  • value (Any) –

add_equal_constraint(left, right=None, note=None)#

Add an equality constraint.

Parameters:
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:

ConstraintSatisfactionProblem

get_domain(identifier)#

Get the domain of a variable.

Parameters:

identifier (int) –

Return type:

Set[Any] | None

get_type(identifier)#

Get the type of a variable.

Parameters:

identifier (int) –

Return type:

TensorValueTypeBase | PyObjValueType

ground_assignment_value(assignments, identifier)[source]#
Parameters:
Return type:

Any

ground_assignment_value_partial(assignments, identifier)#
Parameters:
Return type:

Any

new_actionable_var(dtype, wrap=False, **kwargs)#

Create a new actionable variable.

Parameters:
Return type:

int | OptimisticValue

new_constant_var(name, dtype, domain=None, wrap=False)[source]#
Parameters:
Return type:

int | OptimisticValue

new_named_actionable_var(name, dtype, domain=None, wrap=False)[source]#
Parameters:
Return type:

int | OptimisticValue

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:

int | OptimisticValue

print_assignment_dict(assignments)#
Parameters:

assignments (Dict[int, Assignment]) –

replace_constants(assignments)[source]#
Parameters:

assignments (Dict[str, TensorValue]) –

Return type:

NamedConstraintSatisfactionProblem

with_group(expression, note=None)#

Add a group constraint.

Parameters:
property all_constants_resolved: bool#
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.