fuzzy_dl_owl2.fuzzydl.milp.variable

Defines a symbolic variable structure used to represent degrees of satisfaction within linear expressions for fuzzy description logic ontologies.

Description

Symbolic variables are modeled to encapsulate essential properties such as a unique identifier, a specific domain type, and numeric constraints defined by lower and upper bounds. The design automatically adjusts these numeric boundaries based on the variable type, ensuring that binary and semi-continuous variables are constrained between zero and one, while continuous and integer types default to infinite ranges. To facilitate the construction of optimization models, static factory methods provide convenient interfaces for generating specific variable types, and a class-level counter enables the automatic creation of unique sequential names. Equality comparisons rely primarily on the variable’s name, while hashing incorporates the full state including type and bounds to ensure consistent behavior within hash-based collections. Additionally, the implementation supports cloning for independent copies and includes flags to identify variables acting as datatype fillers within the broader fuzzy logic framework.

Attributes

BinaryVar

FreeVar

IntegerVar

UpVar

Classes

Variable

This class models a symbolic variable used within linear expressions, typically to represent degrees of satisfaction in fuzzy description logic ontologies. It encapsulates properties such as a unique name, a specific type (e.g., binary, integer, or continuous), and corresponding lower and upper bounds that are automatically adjusted based on the variable type. Users can instantiate variables directly or utilize static factory methods to create specific variable types, while a class-level counter facilitates the automatic generation of unique sequential names. Additionally, the class provides functionality to flag variables as datatype fillers and supports cloning for creating independent copies.

Module Contents

UML Class Diagram for Variable

UML Class Diagram for Variable

class Variable(name: str, v_type: fuzzy_dl_owl2.fuzzydl.util.constants.VariableType)

This class models a symbolic variable used within linear expressions, typically to represent degrees of satisfaction in fuzzy description logic ontologies. It encapsulates properties such as a unique name, a specific type (e.g., binary, integer, or continuous), and corresponding lower and upper bounds that are automatically adjusted based on the variable type. Users can instantiate variables directly or utilize static factory methods to create specific variable types, while a class-level counter facilitates the automatic generation of unique sequential names. Additionally, the class provides functionality to flag variables as datatype fillers and supports cloning for creating independent copies.

Parameters:
  • VARIABLE_NAME (str) – Default prefix used for generating names of new variables.

  • VARIABLE_NUMBER (int) – Counter used to generate unique identifiers for automatically created variables.

  • lower_bound (float) – The minimum value the variable can assume.

  • upper_bound (float) – The upper limit of the variable’s domain, representing the maximum value it can assume.

  • name (str) – Unique identifier for the variable instance, determining its string representation and equality.

  • type (VariableType) – An enumeration specifying the variable’s domain (e.g., binary, continuous, integer), which determines its valid value range and implicitly sets its lower and upper bounds.

  • datatype_filler (bool) – Flag indicating whether the variable is a filler value for a datatype restriction.

__eq__(value: Self) bool

Determines equality between the current instance and another object by comparing their string representations. The method converts both self and the provided value to strings and returns True if these representations are identical, otherwise False. This implies that two distinct objects are considered equal if they produce the same string output, and the comparison does not depend on object identity or specific attribute values beyond what is captured by the __str__ method. Note that this implementation does not perform strict type checking on the input value, meaning it will attempt to compare against any object that supports string conversion.

Parameters:

value (Self) – The instance to compare against the current object, where equality is determined by comparing their string representations.

Returns:

True if the string representation of the current instance is equal to the string representation 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: object) bool

Determines whether the current Variable instance is not equal to the specified value. This method implements the behavior of the inequality operator (!=) by returning the logical negation of the equality comparison. Consequently, its behavior regarding type compatibility and comparison logic is entirely dependent on the implementation of the __eq__ method; if __eq__ returns NotImplemented or raises an error for a given type, this method will propagate that behavior. There are no side effects associated with this operation.

Parameters:

value (object) – The object to compare with the current instance.

Returns:

True if the object is not equal to the specified value, otherwise False.

Return type:

bool

__repr__() str

Returns a string representation of the Variable instance, intended for debugging and interactive use. This method delegates directly to the __str__ implementation, ensuring that the output is identical to the user-facing string representation. Consequently, any formatting logic or exceptions raised during string conversion will be reflected in the result of this method.

Returns:

A string representation of the object, equivalent to the result of str(self).

Return type:

str

__str__() str

Returns the string representation of the Variable instance, which is defined as the value of its name attribute. This method is automatically invoked by built-in functions like str() and print() to provide a human-readable identifier for the object. The operation has no side effects and relies on the name attribute being present on the instance.

Returns:

Returns the name of the object.

Return type:

str

clone() Self

Creates and returns a new Variable instance that is a copy of the current object. The new instance is initialized with the same name and type attributes as the original, ensuring that the two objects are distinct but share the same initial data. This method does not modify the original Variable instance; however, if the name or type attributes are mutable objects, the clone will reference the same underlying objects rather than creating deep copies of them.

Returns:

A new instance of the class that is a copy of the current object.

Return type:

Self

static get_binary_variable(name: str) Self

Creates and returns a new variable instance constrained to binary values, typically representing a boolean state or a yes/no decision. This factory method accepts a string identifier for the variable and initializes it with the specific type attribute required for binary constraints within the optimization model. As a static method, it serves as a convenient constructor for generating binary variables without requiring an existing instance of the class.

Parameters:

name (str) – The identifier or label for the binary variable.

Returns:

A new binary variable instance with the specified name.

Return type:

Self

static get_continuous_variable(name: str) Self

Creates a new instance of the Variable class specifically configured to represent a continuous variable. This static method accepts a single string argument representing the variable’s name and initializes the object with the type set to CONTINUOUS. The operation has no side effects on existing state, as it simply constructs and returns a new object, though the behavior depends on the underlying Variable constructor’s handling of the provided name argument.

Parameters:

name (str) – The identifier or label for the continuous variable.

Returns:

A new continuous variable instance initialized with the specified name.

Return type:

Self

get_datatype_filler_type() bool

Returns the boolean value of the datatype_filler attribute associated with this variable. This method serves as a getter to determine if the variable is flagged as a datatype filler. It does not modify the object’s state and has no side effects, though it will raise an AttributeError if the underlying attribute has not been initialized.

Returns:

Returns the boolean value of the datatype_filler attribute.

Return type:

bool

static get_integer_variable(name: str) Self

This static method acts as a factory for creating a Variable instance specifically configured to represent an integer type. It accepts a string argument representing the variable’s name and returns a new Variable object initialized with that name and the type set to VariableType.INTEGER. The method does not modify any existing state and relies on the underlying Variable constructor for handling the provided name.

Parameters:

name (str) – The identifier or label for the integer variable.

Returns:

A new instance representing an integer variable with the specified name.

Return type:

Self

get_lower_bound() float

Retrieves the lower bound value currently assigned to this variable instance. This method acts as a simple accessor for the lower_bound attribute, returning the numerical constraint that defines the minimum limit for the variable. It performs no computation and does not alter the state of the object, though the specific meaning of the returned value—such as whether it represents a hard constraint or a default initialization—depends on the broader logic of the Variable class.

Returns:

The lower bound value.

Return type:

float

static get_new_variable(v_type: fuzzy_dl_owl2.fuzzydl.util.constants.VariableType) Self

Generates a new Variable instance with a unique, auto-generated name based on the specified variable type. The method increments an internal class-level counter to ensure that each subsequent call produces a distinct identifier, combining a static name prefix with the current counter value. This process modifies the class state by updating the counter, meaning the generated names are sequential and dependent on the history of calls to this method.

Parameters:

v_type (VariableType) – The type of the new variable instance to be created.

Returns:

A new Variable instance with a unique, auto-generated name and the specified type.

Return type:

Self

static get_semi_continuous_variable(name: str) Self

This static method serves as a factory for creating a Variable instance with its type explicitly set to semi-continuous. It accepts a string representing the variable’s name and returns a new Variable object configured accordingly. By using this method, the caller ensures the variable is initialized with the correct classification for optimization contexts where the variable must be either zero or within a specific continuous range.

Parameters:

name (str) – The identifier or label for the variable instance.

Returns:

A Variable instance representing a semi-continuous variable with the specified name.

Return type:

Self

get_type() fuzzy_dl_owl2.fuzzydl.util.constants.VariableType

Retrieves the type classification associated with the variable instance. This method returns the value stored in the internal type attribute, which defines the specific data type or category of the variable. It is a read-only operation that does not modify the object’s state, and it simply returns whatever value is currently assigned to the type attribute.

Returns:

The type of the variable represented by this instance.

Return type:

VariableType

get_upper_bound() float

Retrieves the upper bound limit defined for this variable. This method returns the floating-point value stored in the upper_bound attribute, representing the maximum permissible value the variable can assume within its specific context. As a simple accessor, it performs no state modifications or calculations, directly exposing the internal constraint value to the caller.

Returns:

The upper bound value.

Return type:

float

set_binary_variable() None

Marks the current variable instance as a binary variable, effectively restricting its domain to discrete values of 0 and 1. This method updates the variable’s internal type attribute by delegating to the set_type method with the appropriate enumeration value. As this operation modifies the object’s state in place, any previous type assignment associated with the variable will be overwritten.

set_datatype_filler_variable() None

Marks the variable instance as a datatype filler by setting the datatype_filler attribute to True. This operation is typically used to designate the variable as a placeholder or default value intended to satisfy a specific data type requirement within a schema or data processing pipeline. The method modifies the object’s state in place and does not return any value.

set_name(name: str) None

Assigns the provided string identifier to the instance, overwriting any existing value stored in the name attribute. This method directly mutates the object’s state to reflect the new label. While the signature expects a string, the implementation performs no type validation, meaning any object passed as the name will be stored.

Parameters:

name (str) – The new name to assign to the instance.

set_type(v_type: fuzzy_dl_owl2.fuzzydl.util.constants.VariableType) None

Updates the variable’s type to the specified value and automatically adjusts the variable’s bounds to match standard defaults for that type. When the type is set to BINARY or SEMI_CONTINUOUS, the lower and upper bounds are reset to 0.0 and 1.0, respectively. For CONTINUOUS or INTEGER types, the bounds are set to negative and positive infinity. This method modifies the variable’s state in place and asserts that the provided type is valid.

Parameters:

v_type (VariableType) – The type of the variable (e.g., continuous, integer, binary, or semi-continuous). Setting this type automatically updates the variable’s default bounds to standard values appropriate for the selection.

VARIABLE_NAME: str = 'y'
VARIABLE_NUMBER: int = 0
datatype_filler: bool = False
lower_bound: float = 0.0
name: str
type: fuzzy_dl_owl2.fuzzydl.util.constants.VariableType = None
upper_bound: float = 0.0
BinaryVar
FreeVar
IntegerVar
UpVar