fuzzy-dl-owl2 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fuzzy_dl_owl2/__init__.py +2 -0
- fuzzy_dl_owl2/fuzzydl/__init__.py +23 -0
- fuzzy_dl_owl2/fuzzydl/assertion/__init__.py +2 -0
- fuzzy_dl_owl2/fuzzydl/assertion/assertion.py +72 -0
- fuzzy_dl_owl2/fuzzydl/assertion/atomic_assertion.py +19 -0
- fuzzy_dl_owl2/fuzzydl/concept/__init__.py +13 -0
- fuzzy_dl_owl2/fuzzydl/concept/all_some_concept.py +85 -0
- fuzzy_dl_owl2/fuzzydl/concept/approximation_concept.py +147 -0
- fuzzy_dl_owl2/fuzzydl/concept/atomic_concept.py +91 -0
- fuzzy_dl_owl2/fuzzydl/concept/choquet_integral.py +64 -0
- fuzzy_dl_owl2/fuzzydl/concept/concept.py +230 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/__init__.py +10 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/crisp_concrete_concept.py +60 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/fuzzy_concrete_concept.py +63 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/fuzzy_number/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/fuzzy_number/triangular_fuzzy_number.py +127 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/left_concrete_concept.py +70 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/linear_concrete_concept.py +70 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/modified_concrete_concept.py +66 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/right_concrete_concept.py +70 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/trapezoidal_concrete_concept.py +96 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/triangular_concrete_concept.py +89 -0
- fuzzy_dl_owl2/fuzzydl/concept/ext_threshold_concept.py +77 -0
- fuzzy_dl_owl2/fuzzydl/concept/has_value_concept.py +51 -0
- fuzzy_dl_owl2/fuzzydl/concept/implies_concept.py +144 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/__init__.py +6 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_concept_interface.py +17 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_concepts_interface.py +18 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_role_concept_interface.py +14 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_role_interface.py +15 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_value_interface.py +21 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_weighted_concepts_interface.py +29 -0
- fuzzy_dl_owl2/fuzzydl/concept/modified/__init__.py +3 -0
- fuzzy_dl_owl2/fuzzydl/concept/modified/linearly_modified_concept.py +32 -0
- fuzzy_dl_owl2/fuzzydl/concept/modified/modified_concept.py +59 -0
- fuzzy_dl_owl2/fuzzydl/concept/modified/triangularly_modified_concept.py +33 -0
- fuzzy_dl_owl2/fuzzydl/concept/negated_nominal.py +42 -0
- fuzzy_dl_owl2/fuzzydl/concept/operator_concept.py +707 -0
- fuzzy_dl_owl2/fuzzydl/concept/owa_concept.py +57 -0
- fuzzy_dl_owl2/fuzzydl/concept/qowa_concept.py +62 -0
- fuzzy_dl_owl2/fuzzydl/concept/quasi_sugeno_integral.py +46 -0
- fuzzy_dl_owl2/fuzzydl/concept/self_concept.py +45 -0
- fuzzy_dl_owl2/fuzzydl/concept/string_concept.py +35 -0
- fuzzy_dl_owl2/fuzzydl/concept/sugeno_integral.py +83 -0
- fuzzy_dl_owl2/fuzzydl/concept/threshold_concept.py +81 -0
- fuzzy_dl_owl2/fuzzydl/concept/truth_concept.py +83 -0
- fuzzy_dl_owl2/fuzzydl/concept/value_concept.py +67 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_concept.py +55 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_max_concept.py +63 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_min_concept.py +57 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_sum_concept.py +62 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_sum_zero_concept.py +62 -0
- fuzzy_dl_owl2/fuzzydl/concept_equivalence.py +20 -0
- fuzzy_dl_owl2/fuzzydl/concrete_feature.py +94 -0
- fuzzy_dl_owl2/fuzzydl/degree/__init__.py +4 -0
- fuzzy_dl_owl2/fuzzydl/degree/degree.py +79 -0
- fuzzy_dl_owl2/fuzzydl/degree/degree_expression.py +57 -0
- fuzzy_dl_owl2/fuzzydl/degree/degree_numeric.py +57 -0
- fuzzy_dl_owl2/fuzzydl/degree/degree_variable.py +54 -0
- fuzzy_dl_owl2/fuzzydl/domain_axiom.py +8 -0
- fuzzy_dl_owl2/fuzzydl/exception/__init__.py +2 -0
- fuzzy_dl_owl2/fuzzydl/exception/fuzzy_ontology_exception.py +4 -0
- fuzzy_dl_owl2/fuzzydl/exception/inconsistent_ontology_exception.py +4 -0
- fuzzy_dl_owl2/fuzzydl/feature_function.py +148 -0
- fuzzy_dl_owl2/fuzzydl/fuzzydl_to_owl2.py +920 -0
- fuzzy_dl_owl2/fuzzydl/fuzzydl_to_owl2_java.py +953 -0
- fuzzy_dl_owl2/fuzzydl/general_concept_inclusion.py +82 -0
- fuzzy_dl_owl2/fuzzydl/individual/__init__.py +3 -0
- fuzzy_dl_owl2/fuzzydl/individual/created_individual.py +219 -0
- fuzzy_dl_owl2/fuzzydl/individual/individual.py +113 -0
- fuzzy_dl_owl2/fuzzydl/individual/representative_individual.py +37 -0
- fuzzy_dl_owl2/fuzzydl/knowledge_base.py +9037 -0
- fuzzy_dl_owl2/fuzzydl/label.py +32 -0
- fuzzy_dl_owl2/fuzzydl/milp/__init__.py +7 -0
- fuzzy_dl_owl2/fuzzydl/milp/expression.py +186 -0
- fuzzy_dl_owl2/fuzzydl/milp/inequation.py +55 -0
- fuzzy_dl_owl2/fuzzydl/milp/milp_helper.py +787 -0
- fuzzy_dl_owl2/fuzzydl/milp/show_variables_helper.py +151 -0
- fuzzy_dl_owl2/fuzzydl/milp/solution.py +45 -0
- fuzzy_dl_owl2/fuzzydl/milp/term.py +76 -0
- fuzzy_dl_owl2/fuzzydl/milp/variable.py +89 -0
- fuzzy_dl_owl2/fuzzydl/modifier/__init__.py +3 -0
- fuzzy_dl_owl2/fuzzydl/modifier/linear_modifier.py +76 -0
- fuzzy_dl_owl2/fuzzydl/modifier/modifier.py +39 -0
- fuzzy_dl_owl2/fuzzydl/modifier/triangular_modifier.py +76 -0
- fuzzy_dl_owl2/fuzzydl/parser/ParserConstants.py +406 -0
- fuzzy_dl_owl2/fuzzydl/parser/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzydl/parser/dl_parser.py +2029 -0
- fuzzy_dl_owl2/fuzzydl/parser/ebnf.lark +290 -0
- fuzzy_dl_owl2/fuzzydl/parser/larkx.py +70 -0
- fuzzy_dl_owl2/fuzzydl/primitive_concept_definition.py +81 -0
- fuzzy_dl_owl2/fuzzydl/query/__init__.py +14 -0
- fuzzy_dl_owl2/fuzzydl/query/all_instances_query.py +50 -0
- fuzzy_dl_owl2/fuzzydl/query/bnp_query.py +22 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/__init__.py +4 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/defuzzify_query.py +76 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/lom_defuzzify_query.py +19 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/mom_defuzzify_query.py +88 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/som_defuzzify_query.py +20 -0
- fuzzy_dl_owl2/fuzzydl/query/instance_query.py +19 -0
- fuzzy_dl_owl2/fuzzydl/query/kb_satisfiable_query.py +32 -0
- fuzzy_dl_owl2/fuzzydl/query/max/__init__.py +5 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_instance_query.py +45 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_query.py +31 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_related_query.py +45 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_satisfiable_query.py +73 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_subsumes_query.py +64 -0
- fuzzy_dl_owl2/fuzzydl/query/min/__init__.py +5 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_instance_query.py +50 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_query.py +31 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_related_query.py +57 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_satisfiable_query.py +80 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_subsumes_query.py +65 -0
- fuzzy_dl_owl2/fuzzydl/query/query.py +38 -0
- fuzzy_dl_owl2/fuzzydl/query/related_query.py +15 -0
- fuzzy_dl_owl2/fuzzydl/query/satisfiable_query.py +37 -0
- fuzzy_dl_owl2/fuzzydl/query/subsumption_query.py +20 -0
- fuzzy_dl_owl2/fuzzydl/range_axiom.py +7 -0
- fuzzy_dl_owl2/fuzzydl/relation.py +47 -0
- fuzzy_dl_owl2/fuzzydl/restriction/__init__.py +2 -0
- fuzzy_dl_owl2/fuzzydl/restriction/has_value_restriction.py +16 -0
- fuzzy_dl_owl2/fuzzydl/restriction/restriction.py +34 -0
- fuzzy_dl_owl2/fuzzydl/role_parent_with_degree.py +10 -0
- fuzzy_dl_owl2/fuzzydl/util/__init__.py +3 -0
- fuzzy_dl_owl2/fuzzydl/util/config_reader.py +56 -0
- fuzzy_dl_owl2/fuzzydl/util/constants.py +424 -0
- fuzzy_dl_owl2/fuzzydl/util/util.py +73 -0
- fuzzy_dl_owl2/fuzzyowl2/__init__.py +5 -0
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2.py +1513 -0
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2_java.py +1409 -0
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2_to_fuzzydl.py +917 -0
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2_to_fuzzydl_java.py +956 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/__init__.py +0 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/choquet_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/concept_definition.py +14 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/fuzzy_datatype.py +22 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/fuzzy_modifier.py +4 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/fuzzy_nominal_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/fuzzy_property.py +5 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/left_shoulder_function.py +17 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/linear_function.py +17 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/linear_modifier.py +13 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/modified_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/modified_function.py +17 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/modified_property.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/owa_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/property_definition.py +10 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/qowa_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/quasi_sugeno_concept.py +21 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/right_shoulder_function.py +17 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/sugeno_concept.py +21 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/trapezoidal_function.py +25 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/triangular_function.py +21 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/triangular_modifer.py +21 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_max_concept.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_min_concept.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_sum_concept.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_sum_zero_concept.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/parser/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzyowl2/parser/owl2_parser.py +491 -0
- fuzzy_dl_owl2/fuzzyowl2/util/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzyowl2/util/constants.py +112 -0
- fuzzy_dl_owl2-1.0.0.dist-info/LICENSE +427 -0
- fuzzy_dl_owl2-1.0.0.dist-info/METADATA +299 -0
- fuzzy_dl_owl2-1.0.0.dist-info/RECORD +167 -0
- fuzzy_dl_owl2-1.0.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.degree.degree import Degree
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.degree.degree_numeric import DegreeNumeric
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Label:
|
|
9
|
+
def __init__(self, concept: Concept, weight: Degree) -> None:
|
|
10
|
+
self.concept: Concept = concept
|
|
11
|
+
self.weight: Degree = weight
|
|
12
|
+
|
|
13
|
+
def __str__(self) -> str:
|
|
14
|
+
return f"{self.concept} {self.weight}"
|
|
15
|
+
|
|
16
|
+
def __eq__(self, cw: typing.Self) -> bool:
|
|
17
|
+
if self.concept != cw.concept:
|
|
18
|
+
return False
|
|
19
|
+
return self.weights_equal(self.weight, cw.weight)
|
|
20
|
+
|
|
21
|
+
def __ne__(self, cw: typing.Self) -> bool:
|
|
22
|
+
return not (self == cw)
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def weights_equal(w1: Degree, w2: Degree) -> bool:
|
|
26
|
+
if not w1.__class__ == w2.__class__:
|
|
27
|
+
return False
|
|
28
|
+
return (
|
|
29
|
+
not w1.is_numeric()
|
|
30
|
+
or typing.cast(DegreeNumeric, w1).get_numerical_value()
|
|
31
|
+
== typing.cast(DegreeNumeric, w2).get_numerical_value()
|
|
32
|
+
)
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
import trycast
|
|
4
|
+
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.util import constants
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Expression:
|
|
11
|
+
|
|
12
|
+
@typing.overload
|
|
13
|
+
def __init__(self, constant: typing.Union[int, float]) -> None: ...
|
|
14
|
+
|
|
15
|
+
@typing.overload
|
|
16
|
+
def __init__(self, constant: typing.Union[int, float], *terms: Term) -> None: ...
|
|
17
|
+
|
|
18
|
+
@typing.overload
|
|
19
|
+
def __init__(self, *terms: Term) -> None: ...
|
|
20
|
+
|
|
21
|
+
@typing.overload
|
|
22
|
+
def __init__(self, expr: typing.Self) -> None: ...
|
|
23
|
+
|
|
24
|
+
@typing.overload
|
|
25
|
+
def __init__(self, v: typing.Union[list[Variable], set[Variable]]) -> None: ...
|
|
26
|
+
|
|
27
|
+
def __init__(self, *args) -> None:
|
|
28
|
+
if len(args) == 1:
|
|
29
|
+
if isinstance(args[0], constants.NUMBER):
|
|
30
|
+
self.__expression_init_1(*args)
|
|
31
|
+
elif isinstance(args[0], Expression):
|
|
32
|
+
self.__expression_init_4(*args)
|
|
33
|
+
elif trycast.trycast(typing.Union[list[Variable], set[Variable]], args[0]):
|
|
34
|
+
self.__expression_init_5(*args)
|
|
35
|
+
elif isinstance(args[0], Term):
|
|
36
|
+
self.__expression_init_3(*args)
|
|
37
|
+
else:
|
|
38
|
+
raise ValueError
|
|
39
|
+
else:
|
|
40
|
+
if isinstance(args[0], constants.NUMBER) and all(
|
|
41
|
+
isinstance(a, Term) for a in args[1:]
|
|
42
|
+
):
|
|
43
|
+
self.__expression_init_2(*args)
|
|
44
|
+
elif all(isinstance(a, Term) for a in args):
|
|
45
|
+
self.__expression_init_3(*args)
|
|
46
|
+
else:
|
|
47
|
+
raise ValueError
|
|
48
|
+
|
|
49
|
+
def __expression_init_1(self, constant: typing.Union[int, float]) -> None:
|
|
50
|
+
assert isinstance(constant, constants.NUMBER)
|
|
51
|
+
self.constant: typing.Union[int, float] = constant
|
|
52
|
+
self.terms: list[Term] = []
|
|
53
|
+
|
|
54
|
+
def __expression_init_2(
|
|
55
|
+
self, constant: typing.Union[int, float], *terms: Term
|
|
56
|
+
) -> None:
|
|
57
|
+
assert len(terms) > 0
|
|
58
|
+
self.__expression_init_1(constant)
|
|
59
|
+
self.terms: list[Term] = [t for t in terms]
|
|
60
|
+
|
|
61
|
+
def __expression_init_3(self, *terms: Term) -> None:
|
|
62
|
+
self.__expression_init_2(0.0, *terms)
|
|
63
|
+
|
|
64
|
+
def __expression_init_4(self, expr: typing.Self) -> None:
|
|
65
|
+
self.__expression_init_2(expr.constant, *expr.terms)
|
|
66
|
+
|
|
67
|
+
def __expression_init_5(
|
|
68
|
+
self, v: typing.Union[list[Variable], set[Variable]]
|
|
69
|
+
) -> None:
|
|
70
|
+
self.__expression_init_2(0.0, *[Term(1.0, var) for var in v])
|
|
71
|
+
|
|
72
|
+
def get_terms(self) -> list[Term]:
|
|
73
|
+
return self.terms
|
|
74
|
+
|
|
75
|
+
def get_constant(self) -> typing.Union[int, float]:
|
|
76
|
+
return self.constant
|
|
77
|
+
|
|
78
|
+
def set_constant(self, constant: typing.Union[int, float]) -> None:
|
|
79
|
+
self.constant = constant
|
|
80
|
+
|
|
81
|
+
def clone(self) -> typing.Self:
|
|
82
|
+
return Expression(self.constant, *self.terms)
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def negate_expression(expr: typing.Self) -> typing.Self:
|
|
86
|
+
return -expr
|
|
87
|
+
|
|
88
|
+
@staticmethod
|
|
89
|
+
def add_constant(
|
|
90
|
+
expr: typing.Self, constant: typing.Union[int, float]
|
|
91
|
+
) -> typing.Self:
|
|
92
|
+
return constant + expr
|
|
93
|
+
|
|
94
|
+
def increment_constant(self) -> None:
|
|
95
|
+
self.constant += 1
|
|
96
|
+
|
|
97
|
+
def add_term(self, term: Term) -> None:
|
|
98
|
+
for idx, t in enumerate(self.terms):
|
|
99
|
+
if t == term:
|
|
100
|
+
self.terms[idx] = t + term
|
|
101
|
+
return
|
|
102
|
+
self.terms.append(term)
|
|
103
|
+
assert len(self.terms) > 0
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def add_term_(exp: typing.Self, term: Term) -> typing.Self:
|
|
107
|
+
curr_expr: Expression = exp
|
|
108
|
+
curr_expr.add_term(term)
|
|
109
|
+
return curr_expr
|
|
110
|
+
|
|
111
|
+
@staticmethod
|
|
112
|
+
def add_expressions(expr1: typing.Self, expr2: typing.Self) -> typing.Self:
|
|
113
|
+
return expr1 + expr2
|
|
114
|
+
|
|
115
|
+
@staticmethod
|
|
116
|
+
def subtract_expressions(expr1: typing.Self, expr2: typing.Self) -> typing.Self:
|
|
117
|
+
return expr1 - expr2
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
def multiply_constant(
|
|
121
|
+
expr: typing.Self, constant: typing.Union[int, float]
|
|
122
|
+
) -> typing.Self:
|
|
123
|
+
return expr * constant
|
|
124
|
+
|
|
125
|
+
def get_constant_term(self, var: Variable) -> typing.Union[int, float]:
|
|
126
|
+
for term in self.terms:
|
|
127
|
+
if term.get_var() == var:
|
|
128
|
+
return term.get_coeff()
|
|
129
|
+
return 0.0
|
|
130
|
+
|
|
131
|
+
def __neg__(self) -> typing.Self:
|
|
132
|
+
return Expression(-self.get_constant(), *[-t for t in self.get_terms()])
|
|
133
|
+
|
|
134
|
+
def __add__(
|
|
135
|
+
self, value: typing.Union[int, float, typing.Self, Term]
|
|
136
|
+
) -> typing.Self:
|
|
137
|
+
if isinstance(value, constants.NUMBER):
|
|
138
|
+
return Expression(self.get_constant() + value, *self.get_terms())
|
|
139
|
+
elif isinstance(value, Term):
|
|
140
|
+
result: Expression = self
|
|
141
|
+
result.add_term(value)
|
|
142
|
+
return result
|
|
143
|
+
result: Expression = self
|
|
144
|
+
for term in value.get_terms():
|
|
145
|
+
result.add_term(term)
|
|
146
|
+
result.constant += value.get_constant()
|
|
147
|
+
return result
|
|
148
|
+
|
|
149
|
+
def __radd__(self, scalar: typing.Union[int, float]) -> typing.Self:
|
|
150
|
+
return self + scalar
|
|
151
|
+
|
|
152
|
+
def __sub__(self, expr: typing.Union[int, float, typing.Self, Term]) -> typing.Self:
|
|
153
|
+
return self + (-expr)
|
|
154
|
+
|
|
155
|
+
def __rsub__(self, scalar: typing.Union[int, float]) -> typing.Self:
|
|
156
|
+
return -self + scalar
|
|
157
|
+
|
|
158
|
+
def __mul__(self, scalar: typing.Union[int, float]) -> typing.Self:
|
|
159
|
+
return Expression(
|
|
160
|
+
self.get_constant() * scalar,
|
|
161
|
+
*[t * scalar for t in self.get_terms()],
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
def __rmul__(self, scalar: typing.Union[int, float]) -> typing.Self:
|
|
165
|
+
return self * scalar
|
|
166
|
+
|
|
167
|
+
def __truediv__(self, scalar: typing.Union[int, float]) -> typing.Self:
|
|
168
|
+
return self * (1 / scalar)
|
|
169
|
+
|
|
170
|
+
def __repr__(self) -> str:
|
|
171
|
+
return str(self)
|
|
172
|
+
|
|
173
|
+
def __str__(self) -> str:
|
|
174
|
+
parts: list[str] = []
|
|
175
|
+
if self.constant != 0.0:
|
|
176
|
+
parts.append(str(self.constant))
|
|
177
|
+
|
|
178
|
+
for term in self.terms:
|
|
179
|
+
n: float = float(term.get_coeff())
|
|
180
|
+
if n == 1.0:
|
|
181
|
+
parts.append(f"+ {term.get_var()}")
|
|
182
|
+
elif n == -1.0:
|
|
183
|
+
parts.append(f"- {term.get_var()}")
|
|
184
|
+
else:
|
|
185
|
+
parts.append(f"{n} {term.get_var()}")
|
|
186
|
+
return " ".join(parts)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import InequalityType
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Inequation:
|
|
9
|
+
def __init__(self, exp: Expression, i_type: InequalityType) -> None:
|
|
10
|
+
assert exp is not None and len(exp.get_terms()) > 0
|
|
11
|
+
self.type: InequalityType = i_type
|
|
12
|
+
self.expr: Expression = exp
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def greater_then(exp: Expression) -> typing.Self:
|
|
16
|
+
return Inequation(exp, InequalityType.GREATER_THAN)
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def less_than(exp: Expression) -> typing.Self:
|
|
20
|
+
return Inequation(exp, InequalityType.LESS_THAN)
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def equal_to(exp: Expression) -> typing.Self:
|
|
24
|
+
return Inequation(exp, InequalityType.EQUAL)
|
|
25
|
+
|
|
26
|
+
def clone(self) -> typing.Self:
|
|
27
|
+
return Inequation(self.expr, self.type)
|
|
28
|
+
|
|
29
|
+
def get_terms(self) -> list[Term]:
|
|
30
|
+
return self.expr.get_terms()
|
|
31
|
+
|
|
32
|
+
def get_constant(self) -> float:
|
|
33
|
+
return -self.expr.get_constant()
|
|
34
|
+
|
|
35
|
+
def get_type(self) -> InequalityType:
|
|
36
|
+
return self.type
|
|
37
|
+
|
|
38
|
+
def get_string_type(self) -> str:
|
|
39
|
+
if self.type == InequalityType.EQUAL:
|
|
40
|
+
return self.type.value
|
|
41
|
+
elif self.type == InequalityType.LESS_THAN:
|
|
42
|
+
return "<="
|
|
43
|
+
assert self.type == InequalityType.GREATER_THAN
|
|
44
|
+
return ">="
|
|
45
|
+
|
|
46
|
+
def __repr__(self) -> str:
|
|
47
|
+
return str(self)
|
|
48
|
+
|
|
49
|
+
def __str__(self) -> str:
|
|
50
|
+
return f"{self.expr} {self.get_string_type()} 0"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
GreaterThan = Inequation.greater_then
|
|
54
|
+
LessThan = Inequation.less_than
|
|
55
|
+
EqualTo = Inequation.equal_to
|