fuzzy_dl_owl2.fuzzydl.milp.inequation

Encapsulates mathematical inequalities of the form expression compared to zero for use in fuzzy description logic ontologies.

Description

The software models linear constraints by pairing a mathematical expression with a relational operator, ensuring the right-hand side is always normalized to zero. It supports the creation of greater-than, less-than, and equality constraints through static factory methods, which simplify the instantiation process by automatically assigning the appropriate operator type. Internally, the logic delegates term and constant retrieval to the encapsulated expression object while providing mechanisms to clone the inequality and check if the expression evaluates to zero. Standard object behaviors such as hashing, equality comparison, and string representation are implemented to facilitate the use of these constraints within sets, dictionaries, and debugging workflows.

Attributes

EqualTo

GreaterThan

LessThan

Classes

Inequation

Represents a mathematical inequality of the form expression (>= | <= | =) 0, typically utilized within fuzzy description logic ontologies to model the degree of satisfaction of a concept by an individual. The class encapsulates a linear expression on the left-hand side and a comparison operator, ensuring the right-hand side is always normalized to zero. Users can instantiate instances directly by providing an expression and an inequality type, or utilize static factory methods for convenience. The class provides functionality to access the underlying terms and constants, clone the object, and generate string representations, while also enforcing that the provided expression is non-empty upon initialization.

Module Contents

UML Class Diagram for Inequation

UML Class Diagram for Inequation

class Inequation(exp: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression, i_type: fuzzy_dl_owl2.fuzzydl.util.constants.InequalityType)[source]

Represents a mathematical inequality of the form expression (>= | <= | =) 0, typically utilized within fuzzy description logic ontologies to model the degree of satisfaction of a concept by an individual. The class encapsulates a linear expression on the left-hand side and a comparison operator, ensuring the right-hand side is always normalized to zero. Users can instantiate instances directly by providing an expression and an inequality type, or utilize static factory methods for convenience. The class provides functionality to access the underlying terms and constants, clone the object, and generate string representations, while also enforcing that the provided expression is non-empty upon initialization.

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[source]

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[source]

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[source]

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[source]

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[source]

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[source]

Creates and returns a new instance that is a shallow copy of the current inequality, initialized with the same expression and type properties. This method allows for the duplication of the object without altering the original, making it useful for preserving state or branching logic. However, because the copy is shallow, any mutable objects contained within the expression or type attributes will be shared between the original and the clone, so modifications to those nested objects will affect both instances.

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[source]

This static method serves as a factory for creating an Inequation instance that specifically represents an equality condition. It accepts a single Expression object and returns a new Inequation configured with the InequalityType.EQUAL type. The method performs no modification of the input expression and has no side effects, simply wrapping the provided expression in the appropriate structure.

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[source]

Returns the constant value associated with the inequation by accessing the constant term of the internal expression and applying a negation. This operation effectively retrieves the constant component as it would appear on the opposite side of the inequality, often used to normalize the constraint or extract the right-hand side value. The method is a pure calculation with no side effects on the object’s state.

Returns:

The negative of the constant value associated with the expression.

Return type:

float

get_string_type() str[source]

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][source]

Extracts and returns the individual terms comprising the expression side of the inequation. The operation is delegated to the get_terms method of the internal expression object (self.expr), ensuring consistency with how the expression itself defines its components. The result is a list of Term objects, which may be empty if the expression is simplified to zero or contains no variable terms. This method does not modify the state of the inequation.

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[source]

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:

InequalityType

static greater_then(exp: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression) Self[source]

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[source]

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[source]

Constructs a new Inequation instance representing a strict “less than” relationship. This static factory method accepts an Expression object and initializes the inequality with the LESS_THAN type. It provides a semantic shortcut for creating inequality objects without directly specifying the inequality type in the constructor.

Parameters:

exp (Expression) – The expression representing the right-hand side of the inequality.

Returns:

Returns a new instance representing a “less than” inequality involving the provided expression.

Return type:

Self

expr: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression
type: fuzzy_dl_owl2.fuzzydl.util.constants.InequalityType
EqualTo
GreaterThan
LessThan