fuzzy_dl_owl2.fuzzydl.degree.degree_variable
A symbolic wrapper for algebraic variables allows degrees of satisfaction in a fuzzy logic system to be treated as unknowns that must be solved for rather than fixed constants.
Description
By encapsulating a Variable instance, the implementation enables the degree to participate in linear mathematical operations, such as addition, subtraction, and scalar multiplication, by generating the necessary Term and Expression objects required by the underlying solver. The design explicitly distinguishes symbolic degrees from numeric values, ensuring that type-checking methods correctly identify the entity as non-numeric while still allowing it to act as a right-hand side operand in inequality constraints. Through factory methods and cloning capabilities, the class facilitates the construction of complex constraint systems where satisfaction levels are dynamically determined during the solving process. Equality and hashing behaviors are delegated directly to the underlying variable to ensure consistency within hash-based collections used during constraint generation.
Classes
This class encapsulates a symbolic representation of a degree of satisfaction, where the magnitude is not a fixed numeric value but is instead defined by a variable. It serves as a bridge between the abstract concept of a "degree" and the algebraic manipulation of variables, allowing the degree to participate in mathematical expressions and constraints. By wrapping a Variable instance, it enables operations such as addition, subtraction, and scalar multiplication within expressions, as well as the creation of inequalities where the variable acts as the right-hand side. Unlike numeric degrees, this entity is identified as non-numeric, making it suitable for contexts where the satisfaction level is dynamic or unknown and must be solved for rather than hardcoded. |
Module Contents
UML Class Diagram for DegreeVariable
- class DegreeVariable(variable: fuzzy_dl_owl2.fuzzydl.milp.variable.Variable)[source]
Bases:
fuzzy_dl_owl2.fuzzydl.degree.degree.Degree
This class encapsulates a symbolic representation of a degree of satisfaction, where the magnitude is not a fixed numeric value but is instead defined by a variable. It serves as a bridge between the abstract concept of a “degree” and the algebraic manipulation of variables, allowing the degree to participate in mathematical expressions and constraints. By wrapping a Variable instance, it enables operations such as addition, subtraction, and scalar multiplication within expressions, as well as the creation of inequalities where the variable acts as the right-hand side. Unlike numeric degrees, this entity is identified as non-numeric, making it suitable for contexts where the satisfaction level is dynamic or unknown and must be solved for rather than hardcoded.
- Parameters:
variable (Variable) – Symbolic variable representing the degree, used to construct algebraic expressions and inequalities.
- __eq__(degree: fuzzy_dl_owl2.fuzzydl.degree.degree.Degree) bool[source]
Determines whether the current DegreeVariable instance is equal to another object. Equality is established only if the provided argument is also an instance of DegreeVariable and the underlying variable, accessed via get_variable(), is identical to that of the current instance. If the argument is of a different type or the underlying variables do not match, the method returns False.
- Parameters:
degree (Degree) – The degree object to compare against for equality.
- Returns:
True if the provided object is a DegreeVariable representing the same underlying variable, otherwise False.
- Return type:
bool
- __hash__() int[source]
Computes a hash value for the DegreeVariable instance based on its underlying variable. The method retrieves the variable using get_variable() and returns its hash value, ensuring that the hash is consistent with the equality definition. This allows DegreeVariable instances to be used effectively in hash-based collections like sets and dictionaries, where two instances representing the same variable will yield the same hash.
- Returns:
An integer hash value derived from the underlying variable.
- Return type:
int
- __str__() str[source]
Returns a human-readable string representation of the DegreeVariable instance, formatted as “Degree(variable)” where “variable” is the value of the instance’s variable attribute. This method is implicitly invoked by the built-in str() function and print operations. It performs no side effects on the object’s state, though it relies on the string conversion of the underlying variable attribute.
- Returns:
Returns a string representation of the object in the format ‘Degree(variable)’.
- Return type:
str
- add_to_expression(expr: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression) fuzzy_dl_owl2.fuzzydl.milp.expression.Expression[source]
Incorporates the variable represented by this DegreeVariable into a given expression by adding it as a term with a coefficient of 1.0. The method returns a new Expression object representing the sum of the input and the variable, ensuring that the original expression is not modified. This function is primarily used for incrementally constructing expressions where the specific degree variable needs to be included, relying on the underlying Expression class to handle the addition logic.
- Parameters:
expr (Expression) – The expression to which the term is added.
- Returns:
The resulting Expression after adding a term with a coefficient of 1.0 and the instance’s variable to the input expression.
- Return type:
- clone() Self[source]
Creates and returns a new instance of DegreeVariable that corresponds to the same underlying variable as the current instance. This method achieves this by calling the get_degree factory method, passing the internal variable reference to generate the copy. The operation is side-effect-free with respect to the original object, meaning the state of the current instance remains unchanged.
- Returns:
A new instance of the class representing the same underlying variable.
- Return type:
Self
- create_inequality_with_degree_rhs(
- expr: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression,
- inequality_type: fuzzy_dl_owl2.fuzzydl.util.constants.InequalityType,
Creates an inequality constraint where the degree variable serves as the right-hand side operand relative to the provided expression. The method constructs a new Inequation instance by subtracting the degree variable from the input expression using a coefficient of -1.0. This results in a constraint that effectively compares the expression to the degree variable according to the specified inequality_type (e.g., less than or equal to). The operation does not modify the input expression or the variable itself.
- Parameters:
expr (Expression) – The expression representing the left-hand side of the inequality.
inequality_type (InequalityType) – The relational operator (e.g., less than, greater than) defining the inequality.
- Returns:
Returns an Inequation representing the inequality expr [inequality_type] self.variable.
- Return type:
- static get_degree(value: fuzzy_dl_owl2.fuzzydl.milp.variable.Variable) Self[source]
Constructs a DegreeVariable instance using the provided Variable object as its underlying value. This static method serves as a factory function to explicitly wrap or cast a generic variable into a degree-specific representation. It does not modify the input variable but rather creates a new instance, delegating the actual initialization logic to the DegreeVariable constructor.
- Parameters:
value (Variable) – The variable to be converted into a DegreeVariable.
- Returns:
A DegreeVariable instance initialized with the provided variable.
- Return type:
Self
- get_variable() fuzzy_dl_owl2.fuzzydl.milp.variable.Variable[source]
Retrieves the underlying Variable instance stored within the DegreeVariable object. This method serves as a getter for the internal variable attribute, providing access to the symbolic variable associated with the specific degree. It is a read-only operation that does not alter the state of the instance.
- Returns:
The Variable instance associated with this object.
- Return type:
- is_number_not_one() bool[source]
Determines whether the instance represents a numeric value that is not equal to one. For the DegreeVariable class, this method unconditionally returns False, indicating that the entity does not satisfy the condition of being a number distinct from one. This behavior suggests that within the module’s type hierarchy, a DegreeVariable is either treated as a non-numeric entity or is implicitly associated with the value one.
- Returns:
Always returns False.
- Return type:
bool
- is_number_zero() bool[source]
Checks if the instance represents the numerical value zero. This method always returns False, reflecting that a DegreeVariable is a symbolic entity and not a constant. It is primarily used to distinguish variables from numeric constants during expression evaluation or simplification.
- Returns:
True if the number is zero, False otherwise.
- Return type:
bool
- is_numeric() bool[source]
Indicates that this variable does not represent a numeric constant. Unlike concrete numbers or evaluated expressions, a DegreeVariable is a symbolic entity, so this method always returns False to signal that it cannot be treated as a raw numeric value during computations or type checking.
- Returns:
True if the object is numeric, False otherwise.
- Return type:
bool
- multiply_constant(constant: float) fuzzy_dl_owl2.fuzzydl.milp.expression.Expression[source]
Multiplies the variable represented by this instance by a specified scalar constant to generate a new linear expression. The method constructs a Term object using the provided constant as the coefficient and the current variable, then wraps this term within an Expression object. This operation does not modify the original DegreeVariable instance; instead, it returns a distinct Expression representing the product of the constant and the variable.
- Parameters:
constant (float) – The numeric coefficient for the variable in the resulting term.
- Returns:
A new Expression representing the product of the provided constant and the variable.
- Return type:
- subtract_from_expression( ) fuzzy_dl_owl2.fuzzydl.milp.expression.Expression[source]
Subtracts the variable represented by this DegreeVariable instance from a given expression. It performs this operation by adding a term with a coefficient of -1.0 and the instance’s variable to the input expression. The method returns a new Expression object containing the result, ensuring that the original input expression remains unmodified.
- Parameters:
expr (Expression) – The expression from which the current term is subtracted.
- Returns:
A new Expression representing the result of subtracting the variable from the provided expression.
- Return type: