API Reference¶
paramita.modelling module¶
Expression
module-attribute
¶
Bool
¶
Boolean expression node.
Represents a named boolean variable in the expression system.
UnaryOperation
¶
BinaryOperation
¶
Binary boolean operation node.
Represents an operation with two operands (e.g. AND, OR, XOR).
UnaryIntegerOperation
¶
Unary integer operation node.
Represents a unary arithmetic operation on integer expressions (e.g. negation).
BinaryIntegerOperation
¶
Binary integer operation node.
Represents a binary arithmetic operation on integer expressions (e.g. +, -, *).
PseudoBooleanOperation
¶
Pseudo-boolean constraint node.
Represents a comparison between integer expressions (e.g. <=, >=, ==).
Type
¶
Bases: Enum
Type of pseudo-boolean comparison operation.
And
¶
Logical AND of two expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Left-hand expression. |
required |
rhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Right-hand expression. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
An expression representing |
Or
¶
Logical OR of two expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Left-hand expression. |
required |
rhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Right-hand expression. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
An expression representing |
Not
¶
Logical negation of an expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operand
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Expression to negate. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
The negated expression. |
If
¶
Logical implication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Antecedent. |
required |
rhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Consequent. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
An expression representing |
Iff
¶
Logical equivalence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Left-hand expression. |
required |
rhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Right-hand expression. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
An expression representing |
Xor
¶
Exclusive OR of two expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Left-hand expression. |
required |
rhs
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Right-hand expression. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
An expression representing |
Minus
¶
Unary minus for integer expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operand
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Expression to negate. |
required |
Returns:
| Type | Description |
|---|---|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
The negated expression. |
Add
¶
Addition of two integer expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Left-hand operand. |
required |
rhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Sum of lhs and rhs. |
Subtract
¶
Subtraction of two integer expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Left-hand operand. |
required |
rhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Difference lhs - rhs. |
Multiply
¶
Multiplication of two integer expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Left-hand operand. |
required |
rhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Product of lhs and rhs. |
LessThan
¶
Less-than comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Left-hand operand. |
required |
rhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Boolean expression for lhs < rhs. |
LessOrEqual
¶
Less-than-or-equal comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Left-hand operand. |
required |
rhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Boolean expression for lhs <= rhs. |
Equal
¶
Equality comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Left-hand operand. |
required |
rhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Boolean expression for lhs == rhs. |
GreaterOrEqual
¶
Greater-than-or-equal comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Left-hand operand. |
required |
rhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Boolean expression for lhs >= rhs. |
GreaterThan
¶
Greater-than comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Left-hand operand. |
required |
rhs
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Right-hand operand. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Boolean expression for lhs > rhs. |
DimacsVariablePool
¶
Pool of DIMACS variables.
Maintains a mapping between named variables and DIMACS integer literals.
decode_literal
¶
Decode a DIMACS literal into its variable name (if known).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
literal
|
int
|
DIMACS literal. |
required |
Returns:
| Type | Description |
|---|---|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | None
|
Variable name corresponding to the literal. |
get_variable
¶
Get or create a DIMACS variable for a given name.
If the name has not been seen previously by the pool, a new DIMACS variable is introduced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variable name. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The DIMACS variable associated to this name in this pool. |
add_to_container
¶
Transforms a boolean expression into CNF and appends the resulting clauses to the given clause container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Boolean expression to add to the container. |
required |
cnf_transformer
|
Callable[[Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool], Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool]
|
Transformation applied to the expression. |
required |
container
|
ClauseContainer
|
Clause container where the clauses are added. |
required |
var_pool
|
DimacsVariablePool
|
Variable pool used to allocate and resolve DIMACS variables. |
required |
add_to_weighted_container
¶
Encodes an optimization objective and hard constraints into a weighted clause container.
The objective expression must be linear. The hard constraints are first transformed using the provided CNF transformation function before being encoded and added as hard clauses. Terms in the objective that are not clauses are reified.
The returned value corresponds to the constant component of the objective expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
int | Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool | UnaryIntegerOperation | BinaryIntegerOperation
|
Linear integer objective expression to encode. |
required |
subject_to
|
Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool
|
Boolean constraints that must hold. |
required |
cnf_transformer
|
Callable[[Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool], Bool | UnaryOperation | BinaryOperation | PseudoBooleanOperation | bool]
|
Transformation applied to constraint expressions prior to CNF conversion. |
required |
container
|
WClauseContainer
|
Weighted clause container where the clauses are added. |
required |
var_pool
|
DimacsVariablePool
|
Variable pool used to allocate and resolve DIMACS variables. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The constant component of the objective expression. |