concepts.dsl.constraint#

Data structures for Constraint Satisfaction Problems (CSPs).

In general, a CSP can be represented as a tuple of variables, domains (for each variable), and constraints. Here, we only consider constraints of the following form: function(*arguments) == rv. Internally:

  • Each variable can either be a determined TensorValue or an OptimisticValue (i.e., undetermined value).

    For TensorValue, the representation contains its data type and the actual value. For OptimisticValue, the representation contains its data type and a single integer, representing the index of the variable.

  • Each constraint is represented as a Constraint object, which contains the function, arguments, and the return value.
    The function is represented as a string (only for equality constraints), or BoolOpType (and, or, not), or QuantificationOpType (forall, exists),

    or Function objects. Both arguments and return values can be DeterminedValue or OptimisticValue.

  • The index of optimistic values starts from -2147483647 (i.e., OPTIM_MAGIC_NUMBER). Therefore, they can be directly stored in tensors without any conversion,

    which is helpful for implementing CSP-based expression executors. There are a few helper functions to convert between optimistic values and their indices.

Module attributes

AssignmentDict

A mapping from variable indices to assignment values.

Functions

cvt_opt_value(value[, dtype])

Convert a value to OptimisticValue or a (determined) TensorValue.

ground_assignment_value(assignments, identifier)

Get the value of a variable based on the assignment dictionary.

is_optimistic_value(v)

Check if a value is an optimistic identifier.

maybe_optimistic_string(v)

If v is an optimistic value, return a string representation of the optimistic identifier, otherwise return str(v).

optimistic_value_id(v)

Get the optimistic identifier from an optimistic value.

print_assignment_dict(assignments[, csp])

Print an assignment dictionary.

Classes

Assignment

An assignment of a variable.

AssignmentType

See class Assignment.

Constraint

A constraint is basically a equality expression: function(*arguments) == rv.

ConstraintSatisfactionProblem

A constraint satisfaction problem.

EqualityConstraint

A special constraint for equality constraints.

GroupConstraint

GroupTypeClass

NamedConstraintSatisfactionProblem

OptimisticValue

An optimistic value object holds a pair of data type and an optimistic identifier.

OptimisticValueRecord

SimulationFluentConstraintFunction

SimulationConstraint is a special kind of constraint that asserts the return value of the function is the grounding of a predicate after executing action action_index in the simulation.