Debian Codegraph @

Kernel/dlVertex.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 <algorithm>
21 #include <iostream>
22
23 #include "dlVertex.h"cxx . . $ `<file>/Kernel/dlVertex.h`/
24 #include "dlDag.h"cxx . . $ `<file>/Kernel/dlDag.h`/
25 #include "tDataEntry.h"cxx . . $ `<file>/Kernel/tDataEntry.h`/
26
27 // adds a child to 'AND' vertex.
28 // if finds a contrary pair of concepts -- returns TRUE
29 // else return false
30 bool DLVertexcxx . . $ DLVertex# :: addChildcxx . . $ DLVertex#addChild(83c267b20bac841a). ( BipolarPointercxx . . $ BipolarPointer# bp )
31 {
32 // if adds to broken vertex -- do nothing;
33 if ( Opcxx . . $ DLVertexTagDFS#Op. == dtBadcxx . . $ dtBad. )
34 return true;
35
36 // if adds TOP -- nothing to do
37 if ( bp == bpTOPcxx . . $ bpTOP. )
38 return false;
39
40 // if adding BOTTOM -- return clash (empty vertex) immediately
41 // this can happen in case of nested simplifications; see bNested1
42 if ( bp == bpBOTTOMcxx . . $ bpBOTTOM. )
43 return true;
44
45 // find appropriate place to insert
46 auto v = getValuecxx . . $ getValue(46cc46841198e427).(bp);
47
48 auto it = Childcxx . . $ DLVertex#Child..begincxx . . $ std/vector#begin(33b10a496a38335b).(), end = Childcxx . . $ DLVertex#Child..endcxx . . $ std/vector#end(33b10a496a38335b).();
49 it =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(137d99c30d158c3). stdcxx . . $ std/::find_if_notcxx . . $ std/find_if_not(f0a0a4f94ee5cb00). ( it, end, [=] (BipolarPointercxx . . $ BipolarPointer# p) { return getValuecxx . . $ getValue(46cc46841198e427).(p) < v; } );
50
51 if ( it ==cxx . . $ __gnu_cxx/`operator==`(ef3c5749062e825c). end ) // finish
52 {
53 Childcxx . . $ DLVertex#Child..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(bp);
54 return false;
55 }
56
57 // we finds a place with |Child[i]| >= v
58 if ( *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).it == bp ) // concept already exists
59 return false;
60 else if ( *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).it == inversecxx . . $ inverse(7864480464b09eea).(bp) )
61 return true;
62
63 // bp is new, add it to the set
64 Childcxx . . $ DLVertex#Child..insertcxx . . $ std/vector#insert(e54735f7c99f2c9d). ( itcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0)., bp );
65
66 // FIXME: add some simplification (about AR.C1, AR.c2 etc)
67 return false;
68 }
69
70 // Sort given entry in the order defined by flags in a DAG.
71 // the overall sorted entry structure looks like
72 // fffA..M..Zlll if sortAscend set, and
73 // fffZ..M..Alll if sortAscend cleared.
74 // here 's' means "always first" entries, like neg-primconcepts,
75 // and 'l' means "always last" entries, like looped concepts
76 void DLVertexcxx . . $ DLVertex# :: sortEntrycxx . . $ DLVertex#sortEntry(dd585ec903520274). ( const DLDagcxx . . $ DLDag#& dag )
77 {
78 // safety check
79 if ( Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() != dtAndcxx . . $ dtAnd. )
80 return;
81
82 // auto comp = [&dag] (const BipolarPointer l, const BipolarPointer r) { return dag.less(l,r); };
83 // std::sort ( Child.begin(), Child.end(), comp );
84 BipolarPointercxx . . $ BipolarPointer# x; // value of moved element
85 size_tcxx . . $ size_t# size = Childcxx . . $ DLVertex#Child..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).();
86
87 for ( size_tcxx . . $ size_t# i = 1; i < size; ++i )
88 {
89 x = Childcxx . . $ DLVertex#Child.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).i];
90
91 // put x to the place s.t. SxL, where S <= x < L wrt dag.less()
92 size_tcxx . . $ size_t# j = i;
93 for ( ; j > 0 && dag.lesscxx . . $ DLDag#less(88e30549ca55c866). ( x, Childcxx . . $ DLVertex#Child.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).j-1] ); --j )
94 Childcxx . . $ DLVertex#Child.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).j] = Childcxx . . $ DLVertex#Child.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).j-1];
95
96 // insert new element on it's place
97 Childcxx . . $ DLVertex#Child.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).j] = x;
98 }
99 }
100
101 /*
102 // sortirovka vstavkami s minimumom (na budushhee)
103 template <typename T>
104 inline void insertSortGuarded(T a[], long size) {
105 T x;
106 long i, j;
107 T backup = a[0]; // ????????? ?????? ?????? ???????
108
109 setMin(a[0]); // ???????? ?? ???????????
110
111 // ????????????? ??????
112 for ( i=1; i < size; i++) {
113 x = a[i];
114
115 for ( j=i-1; a[j] > x; j--)
116 a[j+1] = a[j];
117
118 a[j+1] = x;
119 }
120
121 // ???????? backup ?? ?????????? ?????
122 for ( j=1; j<size && a[j] < backup; j++)
123 a[j-1] = a[j];
124
125 // ??????? ????????
126 a[j-1] = backup;
127 }
128 */
129
130 const char* DLVertexcxx . . $ DLVertex# :: getTagNamecxx . . $ DLVertex#getTagName(a9f41ea0e82d88cf). ( void ) const
131 {
132 switch (Opcxx . . $ DLVertexTagDFS#Op.)
133 {
134 case dtTopcxx . . $ dtTop.: return "*TOP*";
135 case dtBadcxx . . $ dtBad.: return "bad-tag";
136 case dtNConceptcxx . . $ dtNConcept.:return "concept";
137 case dtPConceptcxx . . $ dtPConcept.:return "primconcept";
138 case dtPSingletoncxx . . $ dtPSingleton.:return "prim-singleton";
139 case dtNSingletoncxx . . $ dtNSingleton.:return "singleton";
140 case dtDataTypecxx . . $ dtDataType.: return "data-type";
141 case dtDataValuecxx . . $ dtDataValue.: return "data-value";
142 case dtDataExprcxx . . $ dtDataExpr.: return "data-expr";
143 case dtAndcxx . . $ dtAnd.: return "and";
144 case dtForallcxx . . $ dtForall.: return "all";
145 case dtLEcxx . . $ dtLE.: return "at-most";
146 case dtIrrcxx . . $ dtIrr.: return "irreflexive";
147 case dtProjcxx . . $ dtProj.: return "projection";
148 case dtNNcxx . . $ dtNN.: return "NN-stopper";
149 case dtChoosecxx . . $ dtChoose.: return "choose";
150 default: return "UNKNOWN";
151 };
152 }
153
154
155 void
156 DLVertexcxx . . $ DLVertex# :: Printcxx . . $ DLVertex#Print(490063bd7e6d8d5d). ( stdcxx . . $ std/::ostreamcxx . . $ std/ostream#& o ) const
157 {
158 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "[d(" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getDepthcxx . . $ DLVertexStatistic#getDepth(27106ebd64dc40f5).(true) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "/" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getDepthcxx . . $ DLVertexStatistic#getDepth(27106ebd64dc40f5).(false)
159 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "),s(" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getSizecxx . . $ DLVertexStatistic#getSize(27106ebd64dc40f5).(true) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "/" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getSizecxx . . $ DLVertexStatistic#getSize(27106ebd64dc40f5).(false)
160 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "),b(" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getBranchcxx . . $ DLVertexStatistic#getBranch(27106ebd64dc40f5).(true) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "/" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getBranchcxx . . $ DLVertexStatistic#getBranch(27106ebd64dc40f5).(false)
161 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "),g(" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getGenercxx . . $ DLVertexStatistic#getGener(27106ebd64dc40f5).(true) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "/" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getGenercxx . . $ DLVertexStatistic#getGener(27106ebd64dc40f5).(false)
162 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "),f(" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getFreqcxx . . $ DLVertexStatistic#getFreq(27106ebd64dc40f5).(true) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "/" <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). getFreqcxx . . $ DLVertexStatistic#getFreq(27106ebd64dc40f5).(false) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")] ";
163 o <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getTagNamecxx . . $ DLVertex#getTagName(a9f41ea0e82d88cf).();
164
165 switch ( Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() )
166 {
167 case dtAndcxx . . $ dtAnd.: // nothing to do (except for printing operands)
168 break;
169
170 case dtTopcxx . . $ dtTop.: // nothing to do
171 case dtNNcxx . . $ dtNN.:
172 return;
173
174 case dtDataExprcxx . . $ dtDataExpr.:
175 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ `operator<<`(71e68dfacb67ce94). *static_cast<const TDataEntrycxx . . $ TDataEntry#*>(getConceptcxx . . $ DLVertex#getConcept(1867504d72698304).())->getFacetcxx . . $ TDataEntry#getFacet(e55f2b8bb1ed2996).();
176 return;
177
178 case dtDataValuecxx . . $ dtDataValue.: // named entry -- just like concept names
179 case dtDataTypecxx . . $ dtDataType.:
180
181 case dtPConceptcxx . . $ dtPConcept.:
182 case dtNConceptcxx . . $ dtNConcept.:
183 case dtPSingletoncxx . . $ dtPSingleton.:
184 case dtNSingletoncxx . . $ dtNSingleton.:
185 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '(' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getConceptcxx . . $ DLVertex#getConcept(1867504d72698304).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ") " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (isNNameTagcxx . . $ isNNameTag(7b512e7165d9f2af).(Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).()) ? "=" : "[=") <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).();
186 return;
187
188 case dtLEcxx . . $ dtLE.:
189 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). getNumberLEcxx . . $ DLVertex#getNumberLE(ddd8539a2fcdd4ce).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).();
190 return;
191
192 case dtForallcxx . . $ dtForall.:
193 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '{' <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). getStatecxx . . $ DLVertex#getState(ddd8539a2fcdd4ce).() <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '}' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).();
194 return;
195
196 case dtIrrcxx . . $ dtIrr.:
197 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
198 return;
199
200 case dtProjcxx . . $ dtProj.:
201 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getRolecxx . . $ DLVertex#getRole(69f26110a94b259f).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " => " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getProjRolecxx . . $ DLVertex#getProjRole(69f26110a94b259f).()->getNamecxx . . $ TNamedEntry#getName(a9f41ea0e82d88cf).();
202 return;
203
204 case dtChoosecxx . . $ dtChoose.:
205 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). getCcxx . . $ DLVertex#getC(455f465bc33b4cdf).();
206 return;
207
208 default:
209 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error printing vertex of type " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). getTagNamecxx . . $ DLVertex#getTagName(a9f41ea0e82d88cf).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "(" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). Typecxx . . $ DLVertexTagDFS#Type(d9c59f5f195b46b8).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ")";
210 fpp_unreachablecxx . . $ `Kernel/fpp_assert.h:49:9`!();
211 }
212
213 // print operands of the concept constructor
214 for ( const_iteratorcxx . . $ DLVertex#const_iterator# q = begincxx . . $ DLVertex#begin(d2502ee2ca3b883a).(); q !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). endcxx . . $ DLVertex#end(d2502ee2ca3b883a).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).q )
215 o <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).q;
216 }