fuzzy_dl_owl2.fuzzydl.milp.inequation
Encapsulates linear constraints of the form \(E \bowtie 0\) within a mixed-integer linear programming framework, normalizing the right-hand side to zero while supporting equality, less-than, and greater-than relations.
Description
The software defines a structure for representing mathematical linear constraints where the right-hand side is always normalized to zero, simplifying the handling of inequalities within a solver or optimization engine. By encapsulating an algebraic expression alongside a relational operator, it allows for the precise definition of constraints such as less-than, greater-than, or equal-to relationships. Static factory methods are provided to streamline the instantiation of specific inequality types, acting as convenient aliases for the constructor. Furthermore, the implementation includes standard object comparison and hashing mechanisms, enabling these constraints to be used effectively within hash-based collections like sets and dictionaries while ensuring that string representations remain human-readable for debugging purposes.
Attributes
Classes
Encodes a linear constraint $E bowtie 0$ with $bowtie in {=, le, ge}$. |
Module Contents
UML Class Diagram for Inequation
- class Inequation(exp: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression, i_type: fuzzy_dl_owl2.fuzzydl.util.constants.InequalityType)
Encodes a linear constraint $E bowtie 0$ with $bowtie in {=, le, ge}$. The right-hand side is always normalised to zero;
MILPHelper.add_new_constraintshifts the expression by aDegreewhen the target bound is not zero.Factory aliases:
GreaterThan,LessThan,EqualTo.- Parameters:
type (InequalityType) – Specifies the relational operator of the inequality, determining if the expression is greater than, less than, or equal to zero.
expr (Expression) – Mathematical expression representing the left-hand side of the inequality, which is compared to zero.
- __eq__(value: Self) bool
Determines whether the current instance is equal to another Inequation object by comparing their internal attributes. The method returns True only if both the underlying expression (expr) and the inequality type (type) of the two objects match exactly; otherwise, it returns False. This strict comparison ensures that two inequalities are considered equivalent only when they represent the same mathematical relationship involving the same expression.
- Parameters:
value (Self) – The object to compare for equality.
- Returns:
True if the expression and type of the current instance match those of the provided value, otherwise False.
- Return type:
bool
- __hash__() int
Calculates the hash value for the instance by hashing its string representation, enabling the object to be used as a key in dictionaries or as an element in sets. This implementation relies on the __str__ method to determine the object’s identity for hashing purposes. It is important to note that if the object is mutable and its string representation changes after it has been added to a hash-based collection, the hash value will change, potentially causing the object to become lost or inaccessible within that collection.
- Returns:
An integer hash value derived from the string representation of the object.
- Return type:
int
- __ne__(value: Self) bool
Defines the behavior of the inequality operator for instances of this class. The method determines if the current object differs from the provided value by evaluating the equality comparison and negating the result. Consequently, the logic and any potential side effects are entirely dependent on the implementation of the equality operator (__eq__). It returns a boolean value indicating whether the two instances are distinct.
- Parameters:
value (Self) – The object to compare against for inequality.
- Returns:
True if the current instance is not equal to the specified value, False otherwise.
- Return type:
bool
- __repr__() str
Returns the official string representation of the mathematical inequality, intended primarily for debugging and logging. This implementation delegates directly to the standard string conversion logic, ensuring that the formal representation matches the user-friendly display format. Consequently, invoking the representation function on an instance yields the same output as converting it to a string.
- Returns:
A string representation of the object.
- Return type:
str
- __str__() str
Returns a human-readable string representation of the inequality, formatted as ‘expression operator 0’. The method constructs this string by combining the string representation of the expression attribute, the specific inequality operator returned by get_string_type, and the constant zero. This representation is primarily used for display purposes and debugging.
- Returns:
Returns a string representation of the object formatted as ‘{expression} {type} 0’.
- Return type:
str
- clone() Self
Returns a shallow copy $(E, bowtie)$.
- Returns:
A new instance of the class initialized with the same expression and type as the current object.
- Return type:
Self
- static equal_to(exp: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression) Self
Factory for $E = 0$.
- Parameters:
exp (Expression) – The expression to compare against for equality.
- Returns:
An Inequation representing that the current expression is equal to the provided expression.
- Return type:
Self
- get_constant() float
Returns the right-hand side constant $-c_0$ (since the stored form is $E bowtie 0$).
- Returns:
The negative of the constant value associated with the expression.
- Return type:
float
- get_string_type() str
Returns a string representation of the inequality operator defined by the instance. It translates the internal InequalityType enumeration into a specific mathematical symbol, mapping equality to its standard value and mapping less-than or greater-than types to the inclusive operators “<=” and “>=” respectively. The method relies on the internal type being one of the defined enumeration values and will raise an assertion error if an unexpected type is encountered.
- Returns:
The string representation of the inequality operator (e.g., ‘<=’, ‘>=’, or ‘=’).
- Return type:
str
- get_terms() list[fuzzy_dl_owl2.fuzzydl.milp.term.Term]
Returns the terms of the underlying expression $E$.
- Returns:
A list of Term objects representing the constituent terms of the expression.
- Return type:
list[Term]
- get_type() fuzzy_dl_owl2.fuzzydl.util.constants.InequalityType
Retrieves the specific classification of the inequality represented by the current instance. This method acts as an accessor for the internal type attribute, returning the InequalityType value that defines the relational operator (such as less-than or greater-than) governing the equation. As this is a read-only operation, it has no side effects and simply exposes the state of the object for use by solvers, formatters, or other dependent logic.
- Returns:
The specific type of inequality represented by this instance.
- Return type:
- static greater_then(exp: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression) Self
Creates and returns a new Inequation instance representing a “greater than” relationship involving the provided expression. This static method acts as a factory, wrapping the given Expression object within an Inequation structure and explicitly setting the inequality type to GREATER_THAN. It does not modify the input expression and relies on the Inequation constructor to handle the specific initialization logic.
- Parameters:
exp (Expression) – The expression operand to be used in the greater-than inequality.
- Returns:
Returns a new Inequation instance representing a greater-than inequality with the provided expression.
- Return type:
Self
- is_zero() bool
Determines whether the underlying expression of the inequation evaluates to zero. It returns True only if all coefficients of the terms in the expression are zero and the constant term is also zero, indicating that the expression is identically zero regardless of variable values.
- Returns:
True if the expression is zero (i.e., all coefficients and the constant term are zero), otherwise False.
- Return type:
bool
- static less_than(exp: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression) Self
Factory for $E le 0$.
- Parameters:
exp (Expression) – The expression representing the left-hand side of the inequality.
- Returns:
Returns a new instance representing a “less than” inequality involving the provided expression.
- Return type:
Self
- EqualTo
- GreaterThan
- LessThan