Debian Codegraph @

FaCT++.Python/lib/Kernel/DataReasoning.cpp

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2005-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "DataReasoning.h"
21
22 //toms code start
23 bool DataTypeReasoner :: addDataEntry ( BipolarPointer p, const DepSet& dep )
24 {
25 switch ( DLHeap[p].Type() )
26 {
27 case dtDataType: // get appropriate type
28 {
29 DataTypeAppearance* type = getDTAbyType(getDataEntry(p));
30
31 if ( LLM.isWritable(llCDAction) ) // level of logging
32 LL << ' ' << (isPositive(p) ? '+' : '-') << getDataEntry(p)->getName();
33
34 return setTypePresence ( type, isPositive(p), dep );
35 }
36 case dtDataValue:
37 return processDataValue ( isPositive(p), getDataEntry(p), dep );
38 case dtDataExpr:
39 return processDataExpr ( isPositive(p), getDataEntry(p), dep );
40 case dtAnd: // processed by general reasoning
41 return false;
42 default:
43 fpp_unreachable();
44 }
45 }
46
47 // ---------- Processing different alternatives
48
49 bool
50 DataTypeAppearance::DepInterval :: checkMinMaxClash ( DepSet& dep ) const
51 {
52 // we are interested in a NEG intervals iff a PType is set
53 if ( !Constraints.closed() )
54 return false;
55
56 const ComparableDT& Min = Constraints.min;
57 const ComparableDT& Max = Constraints.max;
58
59 // normal interval
60 if ( Min < Max )
61 return false;
62
63 // >?x and <?y leads to clash for y < x
64 // >5 and <5, >=5 and <5, >5 and <=5 leads to clash
65 if ( Max < Min || Constraints.minExcl || Constraints.maxExcl )
66 {
67 dep += locDep;
68 return true;
69 }
70
71 return false;
72 }
73
74 bool
75 DataTypeAppearance :: addPosInterval ( const TDataInterval& Int, const DepSet& dep )
76 {
77 DTConstraint aux;
78 if ( Int.hasMin() )
79 {
80 Constraints.swap(aux);
81 setLocal ( /*min=*/true, /*excl=*/Int.minExcl, Int.min, dep );
82 if ( addIntervals ( aux.begin(), aux.end() ) )
83 return true;
84 aux.clear();
85 }
86 if ( Int.hasMax() )
87 {
88 Constraints.swap(aux);
89 setLocal ( /*min=*/false, /*excl=*/Int.maxExcl, Int.max, dep );
90 if ( addIntervals ( aux.begin(), aux.end() ) )
91 return true;
92 aux.clear();
93 }
94 if ( Constraints.empty() )
95 return reportClash ( accDep, "C-MM" );
96 return false;
97 }
98
99 bool
100 DataTypeAppearance :: addNegInterval ( const TDataInterval& Int, const DepSet& dep )
101 {
102 // negative interval -- make a copies
103 DTConstraint aux;
104 Constraints.swap(aux);
105
106 if ( Int.hasMin() )
107 {
108 setLocal ( /*min=*/false, /*excl=*/!Int.minExcl, Int.min, dep );
109 if ( addIntervals ( aux.begin(), aux.end() ) )
110 return true;
111 }
112 if ( Int.hasMax() )
113 {
114 setLocal ( /*min=*/ true, /*excl=*/!Int.maxExcl, Int.max, dep );
115 if ( addIntervals ( aux.begin(), aux.end() ) )
116 return true;
117 }
118 aux.clear();
119 if ( Constraints.empty() )
120 return reportClash ( accDep, "C-MM" );
121 return false;
122 }
123
124 // comparison methods
125
126 /// @return true iff there is at least one point that two DTA share
127 bool
128 DataTypeAppearance :: operator == ( const DataTypeAppearance& other ) const
129 {
130 if ( Constraints.size() != 1 && other.Constraints.size() != 1 )
131 return false; // FORNOW: just a single interval
132 const TDataInterval& i0 = Constraints[0].getDataInterval();
133 const TDataInterval& i1 = other.Constraints[0].getDataInterval();
134 if ( !i0.closed() || !i1.closed() ) // FORNOW: only closed ones
135 return false;
136 const ComparableDT& min0 = i0.min;
137 const ComparableDT& min1 = i1.min;
138 const ComparableDT& max0 = i0.max;
139 const ComparableDT& max1 = i1.max;
140 if ( max0 < min1 || max1 < min0 ) // no intersection
141 return false;
142 // here there is an intersection: minx-miny-maxz-maxt
143 if ( min0 == max1 && (i0.minExcl || i1.maxExcl) ) // no touch with a border
144 return false;
145 if ( min1 == max0 && (i1.minExcl || i0.maxExcl) ) // no touch with a border
146 return false;
147 return true;
148 }
149
150 /// @return true iff there is at least one point in OTHER that there is not in THIS
151 bool
152 DataTypeAppearance :: operator < ( const DataTypeAppearance& other ) const
153 {
154 if ( Constraints.size() != 1 && other.Constraints.size() != 1 )
155 return false; // FORNOW: just a single interval
156 const TDataInterval& i0 = Constraints[0].getDataInterval();
157 const TDataInterval& i1 = other.Constraints[0].getDataInterval();
158 if ( !i1.hasMax() ) // always can find larger one
159 return true;
160 // here i1.max exists
161 if ( !i0.hasMin() ) // always can find a smaller one
162 return true;
163 // here i0.min exists
164 if ( i0.min < i1.max ) // {5,} and {,7}
165 return true;
166 if ( i0.min == i1.max && i0.minExcl && !i1.maxExcl )
167 return true; // (5,} and {,5]
168 // note that (6,} and {,5] are not in the < relation
169 return false;
170 }
171