Debian Codegraph @

Kernel/modelCacheIan.cpp

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2003-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 <ostream>
21
22 #include "modelCacheIan.h"cxx . . $ `<file>/Kernel/modelCacheIan.h`/
23
24 /// clear the cache
25 void
26 modelCacheIancxx . . $ modelCacheIan# :: clearcxx . . $ modelCacheIan#clear(49f6e7a06ebc5aa8). ( void )
27 {
28 posDConceptscxx . . $ modelCacheIan#posDConcepts..clearcxx . . $ TSetAsTree#clear(49f6e7a06ebc5aa8).();
29 posNConceptscxx . . $ modelCacheIan#posNConcepts..clearcxx . . $ TSetAsTree#clear(49f6e7a06ebc5aa8).();
30 negDConceptscxx . . $ modelCacheIan#negDConcepts..clearcxx . . $ TSetAsTree#clear(49f6e7a06ebc5aa8).();
31 negNConceptscxx . . $ modelCacheIan#negNConcepts..clearcxx . . $ TSetAsTree#clear(49f6e7a06ebc5aa8).();
32 #ifdef RKG_USE_SIMPLE_RULES
33 extraDConcepts.clear();
34 extraNConcepts.clear();
35 #endif
36 existsRolescxx . . $ modelCacheIan#existsRoles..clearcxx . . $ TSetAsTree#clear(49f6e7a06ebc5aa8).();
37 forallRolescxx . . $ modelCacheIan#forallRoles..clearcxx . . $ TSetAsTree#clear(49f6e7a06ebc5aa8).();
38 funcRolescxx . . $ modelCacheIan#funcRoles..clearcxx . . $ TSetAsTree#clear(49f6e7a06ebc5aa8).();
39 curStatecxx . . $ modelCacheIan#curState. = csValidcxx . . $ csValid.;
40 }
41
42 void modelCacheIancxx . . $ modelCacheIan# :: processConceptcxx . . $ modelCacheIan#processConcept(adb2ecfc6a6b7458). ( const DLVertexcxx . . $ DLVertex#& cur, bool pos, bool det )
43 {
44 switch ( cur.Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() )
45 {
46 case dtTopcxx . . $ dtTop.: // sanity checks
47 case dtDataTypecxx . . $ dtDataType.: // data entries can not be cached
48 case dtDataValuecxx . . $ dtDataValue.:
49 case dtDataExprcxx . . $ dtDataExpr.:
50 fpp_unreachablecxx . . $ `Kernel/fpp_assert.h:49:9`!();
51
52 case dtNConceptcxx . . $ dtNConcept.: // add concepts to Concepts
53 case dtPConceptcxx . . $ dtPConcept.:
54 case dtNSingletoncxx . . $ dtNSingleton.:
55 case dtPSingletoncxx . . $ dtPSingleton.:
56 (det ? getDConceptscxx . . $ modelCacheIan#getDConcepts(60cdb7ab70d95073).(pos) : getNConceptscxx . . $ modelCacheIan#getNConcepts(60cdb7ab70d95073).(pos)).insertcxx . . $ TSetAsTree#insert(cb2f890c2fdad230).(static_cast<const ClassifiableEntrycxx . . $ ClassifiableEntry#*>(cur.getConceptcxx . . $ DLVertex#getConcept(1867504d72698304).())->indexcxx . . $ ClassifiableEntry#index(ddd8539a2fcdd4ce).());
57 break;
58
59 case dtIrrcxx . . $ dtIrr.: // for \neg \ER.Self: add R to AR-set
60 case dtForallcxx . . $ dtForall.: // add AR.C roles to forallRoles
61 case dtLEcxx . . $ dtLE.: // for <= n R: add R to forallRoles
62 if ( unlikelycxx . . $ `Kernel/globaldef.h:29:10`! ( cur.getRole()->isTop() ) ) // force clash to every other edge
63 (pos ? forallRolescxx . . $ modelCacheIan#forallRoles. : existsRolescxx . . $ modelCacheIan#existsRoles.).completeSetcxx . . $ TSetAsTree#completeSet(49f6e7a06ebc5aa8).();
64 else if ( pos ) // no need to deal with existentials here: they would be created through edges
65 {
66 if ( cur.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->isSimplecxx . . $ TRole#isSimple(50ce9a9e25b4a850).() )
67 forallRolescxx . . $ modelCacheIan#forallRoles..insertcxx . . $ TSetAsTree#insert(cb2f890c2fdad230).(cur.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->indexcxx . . $ ClassifiableEntry#index(ddd8539a2fcdd4ce).());
68 else
69 processAutomatoncxx . . $ modelCacheIan#processAutomaton(c29169630048b37c).(cur);
70 }
71 break;
72
73 default: // all other -- nothing to do
74 break;
75 }
76 }
77
78 void
79 modelCacheIancxx . . $ modelCacheIan# :: processAutomatoncxx . . $ modelCacheIan#processAutomaton(c29169630048b37c). ( const DLVertexcxx . . $ DLVertex#& cur )
80 {
81 const RAStateTransitionscxx . . $ RAStateTransitions#& RST = cur.getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->getAutomatoncxx . . $ TRole#getAutomaton(63b0d77ccf579a4).()[cxx . . $ RoleAutomaton#`operator[]`(49d1c2a99a57610b).cur.getStatecxx . . $ DLVertex#getState(ddd8539a2fcdd4ce).()];
82
83 // for every transition starting from a given state,
84 // add the role that is accepted by a transition
85 for ( const auto& trans: RST )
86 for ( const auto& R: trans )
87 forallRolescxx . . $ modelCacheIan#forallRoles..insertcxx . . $ TSetAsTree#insert(cb2f890c2fdad230).(R->indexcxx . . $ ClassifiableEntry#index(ddd8539a2fcdd4ce).());
88 }
89
90 modelCacheStatecxx . . $ modelCacheState# modelCacheIancxx . . $ modelCacheIan# :: canMergecxx . . $ modelCacheIan#canMerge(be618e219bff59e1). ( const modelCacheInterfacecxx . . $ modelCacheInterface#* cache ) const
91 {
92 if ( hasNominalClashcxx . . $ modelCacheInterface#hasNominalClash(93d0908592e17c06).(cache) ) // fail to merge due to nominal presence
93 return csFailedcxx . . $ csFailed.;
94
95 // check if something goes wrong
96 if ( cache->getStatecxx . . $ modelCacheInterface#getState(2c070a27c5715e50). () != csValidcxx . . $ csValid. || getStatecxx . . $ modelCacheIan#getState(2c070a27c5715e50). () != csValidcxx . . $ csValid. )
97 return mergeStatuscxx . . $ mergeStatus(eb6c078af0bc04eb). ( cache->getStatecxx . . $ modelCacheInterface#getState(2c070a27c5715e50). (), getStatecxx . . $ modelCacheIan#getState(2c070a27c5715e50). () );
98
99 // here both models are valid;
100
101 if ( auto cacheIan = dynamic_cast<const modelCacheIancxx . . $ modelCacheIan#*>(cache) )
102 return isMergeableIancxx . . $ modelCacheIan#isMergeableIan(344470c102e55d69).(cacheIan);
103 if ( auto cacheSingleton = dynamic_cast<const modelCacheSingletoncxx . . $ modelCacheSingleton#*>(cache) )
104 return isMergeableSingletoncxx . . $ modelCacheIan#isMergeableSingleton(82cef7062dc31a0c).(cacheSingleton->getValuecxx . . $ modelCacheSingleton#getValue(455f465bc33b4cdf).());
105 if ( dynamic_cast<const modelCacheConstcxx . . $ modelCacheConst#*>(cache) )
106 return csValidcxx . . $ csValid.; // as we checked for the invalid
107 // something unexpected
108 return csUnknowncxx . . $ csUnknown.;
109 }
110
111 modelCacheStatecxx . . $ modelCacheState#
112 modelCacheIancxx . . $ modelCacheIan# :: isMergeableSingletoncxx . . $ modelCacheIan#isMergeableSingleton(82cef7062dc31a0c). ( BipolarPointercxx . . $ BipolarPointer# bp ) const
113 {
114 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( isValid(bp) );
115 auto pos = isPositivecxx . . $ isPositive(83c267b20bac841a).(bp);
116 auto Singleton = getValuecxx . . $ getValue(46cc46841198e427).(bp);
117
118 // deterministic clash
119 if ( getDConceptscxx . . $ modelCacheIan#getDConcepts(ae3169f0774a60fb).(!pos).containscxx . . $ TSetAsTree#contains(8de63fdb265b07c1).(Singleton) )
120 return csInvalidcxx . . $ csInvalid.;
121 // non-det clash
122 else if ( getNConceptscxx . . $ modelCacheIan#getNConcepts(ae3169f0774a60fb).(!pos).containscxx . . $ TSetAsTree#contains(8de63fdb265b07c1).(Singleton) )
123 return csFailedcxx . . $ csFailed.;
124
125 return csValidcxx . . $ csValid.;
126 }
127
128 modelCacheStatecxx . . $ modelCacheState# modelCacheIancxx . . $ modelCacheIan# :: isMergeableIancxx . . $ modelCacheIan#isMergeableIan(344470c102e55d69). ( const modelCacheIancxx . . $ modelCacheIan#* cache ) const
129 {
130 if ( posDConceptscxx . . $ modelCacheIan#posDConcepts..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(cache->negDConceptscxx . . $ modelCacheIan#negDConcepts.)
131 || cache->posDConceptscxx . . $ modelCacheIan#posDConcepts..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(negDConceptscxx . . $ modelCacheIan#negDConcepts.)
132 # ifdef RKG_USE_SIMPLE_RULES
133 || getExtra(/*det=*/true).intersects(cache->getExtra(/*det=*/true))
134 # endif
135 )
136 return csInvalidcxx . . $ csInvalid.;
137 else if ( posDConceptscxx . . $ modelCacheIan#posDConcepts..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(cache->negNConceptscxx . . $ modelCacheIan#negNConcepts.)
138 || posNConceptscxx . . $ modelCacheIan#posNConcepts..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(cache->negDConceptscxx . . $ modelCacheIan#negDConcepts.)
139 || posNConceptscxx . . $ modelCacheIan#posNConcepts..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(cache->negNConceptscxx . . $ modelCacheIan#negNConcepts.)
140 || cache->posDConceptscxx . . $ modelCacheIan#posDConcepts..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(negNConceptscxx . . $ modelCacheIan#negNConcepts.)
141 || cache->posNConceptscxx . . $ modelCacheIan#posNConcepts..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(negDConceptscxx . . $ modelCacheIan#negDConcepts.)
142 || cache->posNConceptscxx . . $ modelCacheIan#posNConcepts..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(negNConceptscxx . . $ modelCacheIan#negNConcepts.)
143 # ifdef RKG_USE_SIMPLE_RULES
144 || getExtra(/*det=*/true).intersects(cache->getExtra(/*det=*/false))
145 || getExtra(/*det=*/false).intersects(cache->getExtra(/*det=*/true))
146 || getExtra(/*det=*/false).intersects(cache->getExtra(/*det=*/false))
147 # endif
148 || existsRolescxx . . $ modelCacheIan#existsRoles..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(cache->forallRolescxx . . $ modelCacheIan#forallRoles.)
149 || cache->existsRolescxx . . $ modelCacheIan#existsRoles..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(forallRolescxx . . $ modelCacheIan#forallRoles.)
150 || funcRolescxx . . $ modelCacheIan#funcRoles..intersectscxx . . $ TSetAsTree#intersects(ab1fdfb4b5c1098c).(cache->funcRolescxx . . $ modelCacheIan#funcRoles.) )
151 return csFailedcxx . . $ csFailed.;
152 else // could be merged
153 return csValidcxx . . $ csValid.;
154 }
155
156 modelCacheStatecxx . . $ modelCacheState# modelCacheIancxx . . $ modelCacheIan# :: mergecxx . . $ modelCacheIan#merge(3c316d00313db7eb). ( const modelCacheInterfacecxx . . $ modelCacheInterface#* cache )
157 {
158 fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( cache != nullptr );
159
160 // check for nominal clash
161 if ( hasNominalClashcxx . . $ modelCacheInterface#hasNominalClash(93d0908592e17c06).(cache) )
162 {
163 curStatecxx . . $ modelCacheIan#curState. = csFailedcxx . . $ csFailed.;
164 return getStatecxx . . $ modelCacheIan#getState(2c070a27c5715e50).();
165 }
166
167 if ( auto cacheIan = dynamic_cast<const modelCacheIancxx . . $ modelCacheIan#*>(cache) )
168 mergeIancxx . . $ modelCacheIan#mergeIan(98877cad36d42a4d).(cacheIan);
169 else if ( auto cacheSingleton = dynamic_cast<const modelCacheSingletoncxx . . $ modelCacheSingleton#*>(cache) )
170 mergeSingletoncxx . . $ modelCacheIan#mergeSingleton(d4f767463ce0a6b3).(cacheSingleton->getValuecxx . . $ modelCacheSingleton#getValue(455f465bc33b4cdf).());
171 else if ( dynamic_cast<const modelCacheConstcxx . . $ modelCacheConst#*>(cache) )
172 curStatecxx . . $ modelCacheIan#curState. = mergeStatuscxx . . $ mergeStatus(eb6c078af0bc04eb). ( getStatecxx . . $ modelCacheIan#getState(2c070a27c5715e50).(), cache->getStatecxx . . $ modelCacheInterface#getState(2c070a27c5715e50).() ); // adds TOP/BOTTOM
173 else
174 fpp_unreachablecxx . . $ `Kernel/fpp_assert.h:49:9`!();
175
176 updateNominalStatuscxx . . $ modelCacheInterface#updateNominalStatus(5cc94ca22787ebea).(cache);
177 return getStatecxx . . $ modelCacheIan#getState(2c070a27c5715e50).();
178 }
179
180 /// actual merge with a singleton cache
181 void
182 modelCacheIancxx . . $ modelCacheIan# :: mergeSingletoncxx . . $ modelCacheIan#mergeSingleton(d4f767463ce0a6b3). ( BipolarPointercxx . . $ BipolarPointer# bp )
183 {
184 modelCacheStatecxx . . $ modelCacheState# newState = isMergeableSingletoncxx . . $ modelCacheIan#isMergeableSingleton(82cef7062dc31a0c).(bp);
185
186 if ( newState != csValidcxx . . $ csValid. ) // some clash occurred: adjust state
187 curStatecxx . . $ modelCacheIan#curState. = mergeStatuscxx . . $ mergeStatus(eb6c078af0bc04eb). ( getStatecxx . . $ modelCacheIan#getState(2c070a27c5715e50).(), newState );
188 else // add singleton; no need to change state here
189 getDConceptscxx . . $ modelCacheIan#getDConcepts(60cdb7ab70d95073).(isPositivecxx . . $ isPositive(83c267b20bac841a).(bp)).insertcxx . . $ TSetAsTree#insert(cb2f890c2fdad230).(getValuecxx . . $ getValue(46cc46841198e427).(bp));
190 }
191
192 /// actual merge with an Ian's cache
193 void
194 modelCacheIancxx . . $ modelCacheIan# :: mergeIancxx . . $ modelCacheIan#mergeIan(98877cad36d42a4d). ( const modelCacheIancxx . . $ modelCacheIan#* cache )
195 {
196 // setup curState
197 curStatecxx . . $ modelCacheIan#curState. = isMergeableIancxx . . $ modelCacheIan#isMergeableIan(344470c102e55d69).(cache);
198
199 // merge all sets:
200 posDConceptscxx . . $ modelCacheIan#posDConcepts. |=cxx . . $ TSetAsTree#`operator|=`(452ddc3fba9a18ae). cache->posDConceptscxx . . $ modelCacheIan#posDConcepts.;
201 posNConceptscxx . . $ modelCacheIan#posNConcepts. |=cxx . . $ TSetAsTree#`operator|=`(452ddc3fba9a18ae). cache->posNConceptscxx . . $ modelCacheIan#posNConcepts.;
202 negDConceptscxx . . $ modelCacheIan#negDConcepts. |=cxx . . $ TSetAsTree#`operator|=`(452ddc3fba9a18ae). cache->negDConceptscxx . . $ modelCacheIan#negDConcepts.;
203 negNConceptscxx . . $ modelCacheIan#negNConcepts. |=cxx . . $ TSetAsTree#`operator|=`(452ddc3fba9a18ae). cache->negNConceptscxx . . $ modelCacheIan#negNConcepts.;
204 #ifdef RKG_USE_SIMPLE_RULES
205 extraDConcepts |= cache->extraDConcepts;
206 extraNConcepts |= cache->extraNConcepts;
207 #endif
208 existsRolescxx . . $ modelCacheIan#existsRoles. |=cxx . . $ TSetAsTree#`operator|=`(452ddc3fba9a18ae). cache->existsRolescxx . . $ modelCacheIan#existsRoles.;
209 forallRolescxx . . $ modelCacheIan#forallRoles. |=cxx . . $ TSetAsTree#`operator|=`(452ddc3fba9a18ae). cache->forallRolescxx . . $ modelCacheIan#forallRoles.;
210 funcRolescxx . . $ modelCacheIan#funcRoles. |=cxx . . $ TSetAsTree#`operator|=`(452ddc3fba9a18ae). cache->funcRolescxx . . $ modelCacheIan#funcRoles.;
211 }
212
213 // logging
214 void
215 modelCacheIancxx . . $ modelCacheIan# :: logCacheEntryImplcxx . . $ modelCacheIan#logCacheEntryImpl(83f5f38750778ac8). ( void ) const
216 {
217 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\nIan cache: posDConcepts = ";
218 posDConceptscxx . . $ modelCacheIan#posDConcepts..printcxx . . $ TSetAsTree#print(490063bd7e6d8d5d).(LLcxx . . $ LL.);
219 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", posNConcepts = ";
220 posNConceptscxx . . $ modelCacheIan#posNConcepts..printcxx . . $ TSetAsTree#print(490063bd7e6d8d5d).(LLcxx . . $ LL.);
221 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", negDConcepts = ";
222 negDConceptscxx . . $ modelCacheIan#negDConcepts..printcxx . . $ TSetAsTree#print(490063bd7e6d8d5d).(LLcxx . . $ LL.);
223 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", negNConcepts = ";
224 negNConceptscxx . . $ modelCacheIan#negNConcepts..printcxx . . $ TSetAsTree#print(490063bd7e6d8d5d).(LLcxx . . $ LL.);
225 #ifdef RKG_USE_SIMPLE_RULES
226 LL << ", extraDConcepts = ";
227 extraDConcepts.print(LL);
228 LL << ", extraNConcepts = ";
229 extraNConcepts.print(LL);
230 #endif
231 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", existsRoles = ";
232 existsRolescxx . . $ modelCacheIan#existsRoles..printcxx . . $ TSetAsTree#print(490063bd7e6d8d5d).(LLcxx . . $ LL.);
233 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", forallRoles = ";
234 forallRolescxx . . $ modelCacheIan#forallRoles..printcxx . . $ TSetAsTree#print(490063bd7e6d8d5d).(LLcxx . . $ LL.);
235 LLcxx . . $ LL. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", funcRoles = ";
236 funcRolescxx . . $ modelCacheIan#funcRoles..printcxx . . $ TSetAsTree#print(490063bd7e6d8d5d).(LLcxx . . $ LL.);
237 }