fuzzy_dl_owl2.fuzzydl.query.min.min_query
Implements a minimization query to find the lowest value of an objective expression subject to constraints in a knowledge base.
Description
Designed to calculate the minimum value of a specific objective function, the software operates within a fuzzy description logic framework by interacting with a knowledge base. The execution workflow involves resolving the assertional component of the knowledge base and then cloning the structure to perform a safe optimization that isolates the calculation from the original data. To maintain system stability, the logic explicitly handles potential inconsistencies in the ontology by catching specific exceptions and returning a designated failure solution instead of propagating errors. Performance tracking is integrated into the process, measuring the duration from initialization to the final result, which allows for the evaluation of computational efficiency alongside the retrieved minimum value.
Classes
This class defines a minimization query used to retrieve the smallest possible value of a specific expression subject to the constraints defined in a knowledge base. It operates by accepting an objective expression during initialization and, upon execution, verifying the consistency of the knowledge base before performing an optimization to find the minimum. Users should instantiate this class with the expression they wish to minimize and pass it to a solver, noting that it handles inconsistent knowledge bases by returning a specific failure solution. |
Module Contents
UML Class Diagram for MinQuery
- class MinQuery(expr: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression)
Bases:
fuzzy_dl_owl2.fuzzydl.query.query.Query
This class defines a minimization query used to retrieve the smallest possible value of a specific expression subject to the constraints defined in a knowledge base. It operates by accepting an objective expression during initialization and, upon execution, verifying the consistency of the knowledge base before performing an optimization to find the minimum. Users should instantiate this class with the expression they wish to minimize and pass it to a solver, noting that it handles inconsistent knowledge bases by returning a specific failure solution.
- Parameters:
obj_expr (Any) – The expression representing the objective function to be minimized.
- __str__() str
Returns a string representation of the minimum query, formatted as a partial expression involving the object’s target expression and a greater-than-or-equal-to operator. The output string combines the stored object expression with a question mark and the comparison symbol, providing a human-readable or serialization-friendly version of the query structure. This method has no side effects and does not alter the internal state of the object.
- Returns:
A string representation of the object, formatted as the object expression followed by a parameter placeholder and the greater-than-or-equal-to operator.
- Return type:
str
- preprocess(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) None
Prepares the internal state of the query object based on the provided knowledge base. This method is intended to be overridden by subclasses to perform specific initialization logic, such as validating the knowledge base structure, indexing relevant entities, or constructing intermediate data structures required for efficient query execution. Since it modifies the object’s state, it should be invoked prior to executing the main query logic, and subclasses may raise exceptions if the provided knowledge base is incompatible with the specific query requirements.
- Parameters:
kb (KnowledgeBase) – The knowledge base object to be preprocessed.
- solve(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) fuzzy_dl_owl2.fuzzydl.milp.solution.Solution
Executes the minimization query by first resolving the ABox of the provided knowledge base and then optimizing a clone of that base against the query’s objective expression. The method tracks the total execution time required for these operations. If the knowledge base is found to be inconsistent, the method catches the resulting exception and returns a specific Solution object indicating an inconsistent state; otherwise, it returns the Solution obtained from the optimization process.
- Parameters:
kb (KnowledgeBase) – The knowledge base containing the ontology and data to be solved and optimized. The ABox is solved directly on this instance, while optimization is performed on a clone.
- Returns:
The optimization Solution, or a Solution flagged as inconsistent when the knowledge base is inconsistent.
- Return type:
- obj_expr