qilisdk.core.comparison
Comparisons between expressions.
A Comparison relates two Expression operands with one of
the six ComparisonOperation relations. It is not an Expression itself: it is the
relation type that Constraint is built from. Build one with the
LT()/LEQ()/EQ()/NEQ()/GT()/GEQ() helpers rather than by hand.
Attributes
Classes
str(object='') -> str |
|
A comparison (equality or inequality) between two |
Functions
|
'Less Than' mathematical operation. |
|
'Less Than or equal to' mathematical operation. |
|
'Equal to' mathematical operation. |
|
'Not Equal to' mathematical operation. |
|
'Greater Than' mathematical operation. |
|
'Greater Than or equal to' mathematical operation. |
Module Contents
- class ComparisonOperation[font]
Bases:
qilisdk.core.types.QiliEnumstr(object=””) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to “utf-8”. errors defaults to “strict”.
Initialize self. See help(type(self)) for accurate signature.
- LT = '<'[font]
- LEQ = '<='[font]
- EQ = '=='[font]
- NEQ = '!='[font]
- GT = '>'[font]
- GEQ = '>='[font]
- LT(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]
“Less Than” mathematical operation.
- Paràmetres:
lhs (
RealNumber | Expression) – the left hand side of the comparison term.rhs (
RealNumber | Expression) – the right hand side of the comparison term.
- Retorna:
a comparison term with the structure lhs < rhs.
- Tipus de retorn:
- LessThan[font]
- LEQ(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]
“Less Than or equal to” mathematical operation.
- Paràmetres:
lhs (
RealNumber | Expression) – the left hand side of the comparison term.rhs (
RealNumber | Expression) – the right hand side of the comparison term.
- Retorna:
a comparison term with the structure lhs <= rhs.
- Tipus de retorn:
- LessThanOrEqual[font]
- EQ(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]
“Equal to” mathematical operation.
- Paràmetres:
lhs (
RealNumber | Expression) – the left hand side of the comparison term.rhs (
RealNumber | Expression) – the right hand side of the comparison term.
- Retorna:
a comparison term with the structure lhs == rhs.
- Tipus de retorn:
- Equal[font]
- NEQ(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]
“Not Equal to” mathematical operation.
- Paràmetres:
lhs (
RealNumber | Expression) – the left hand side of the comparison term.rhs (
RealNumber | Expression) – the right hand side of the comparison term.
- Retorna:
a comparison term with the structure lhs != rhs.
- Tipus de retorn:
- NotEqual[font]
- GT(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]
“Greater Than” mathematical operation.
- Paràmetres:
lhs (
RealNumber | Expression) – the left hand side of the comparison term.rhs (
RealNumber | Expression) – the right hand side of the comparison term.
- Retorna:
a comparison term with the structure lhs > rhs.
- Tipus de retorn:
- GreaterThan[font]
- GEQ(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression) Comparison[font]
“Greater Than or equal to” mathematical operation.
- Paràmetres:
lhs (
RealNumber | Expression) – the left hand side of the comparison term.rhs (
RealNumber | Expression) – the right hand side of the comparison term.
- Retorna:
a comparison term with the structure lhs >= rhs.
- Tipus de retorn:
- GreaterThanOrEqual[font]
- class Comparison(lhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, rhs: qilisdk.core.types.RealNumber | qilisdk.core.expression.Expression, operation: ComparisonOperation)[font]
A comparison (equality or inequality) between two
Expressionoperands.The relation is normalized at construction to
lhs - rhs <op> 0with the additive constant moved to the right-hand side (solhscarries no constant andrhsis that constant).Initialize a new comparison term.
- Paràmetres:
lhs (
RealNumber | Expression) – the left hand side of the comparison.rhs (
RealNumber | Expression) – the right hand side of the comparison.operation (
ComparisonOperation) – the comparison operation.
- Llença:
TypeError – if an operand is neither a number nor an
Expression.
- property operation: ComparisonOperation[font]
The comparison operation.
- property lhs: qilisdk.core.expression.Expression[font]
The left hand side of the comparison term.
- property rhs: qilisdk.core.expression.Expression[font]
The right hand side of the comparison term.
- variables() list[qilisdk.core.variables.BaseVariable][font]
Collect the unique variables in the comparison term.
- Retorna:
the variables, sorted by label.
- Tipus de retorn:
list[BaseVariable]
- property degree: int[font]
The maximum degree of the two sides of the comparison term.
- to_binary() Comparison[font]
Encode the continuous variables of both sides into binary.
- Retorna:
the comparison term with both sides encoded into binary.
- Tipus de retorn:
- evaluate(var_values: collections.abc.Mapping[qilisdk.core.variables.BaseVariable, qilisdk.core.types.RealNumber | list[int]]) bool[font]
Evaluate the comparison given a set of variable values.
- Paràmetres:
var_values (
Mapping[BaseVariable,RealNumber | list[int]]) – the variable assignment.- Retorna:
the result of the comparison.
- Tipus de retorn:
bool
- Llença:
ValueError – if evaluation yields a complex value.