Debian Codegraph @

Kernel/ToDoList.h

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 #ifndef TODOLIST_H
21 #define TODOLIST_Hcxx . . $ `Kernel/ToDoList.h:21:9`!
22
23 #include <vector>
24
25 #include "globaldef.h"cxx . . $ `<file>/Kernel/globaldef.h`/
26 #include "fpp_assert.h"cxx . . $ `<file>/Kernel/fpp_assert.h`/
27 #include "PriorityMatrix.h"cxx . . $ `<file>/Kernel/PriorityMatrix.h`/
28 #include "tRareSaveStack.h"cxx . . $ `<file>/Kernel/tRareSaveStack.h`/
29
30 /// the entry of TODO table
31 struct ToDoEntrycxx . . $ ToDoEntry#
32 {
33 /// node to include concept
34 DlCompletionTreecxx . . $ DlCompletionTree#* Nodecxx . . $ ToDoEntry#Node. = nullptr;
35 /// offset of included concept in Node's label
36 // (it's not possible to use pointers because
37 // std::vector invalidates them)
38 int offsetcxx . . $ ToDoEntry#offset. = 0;
39
40 /// empty c'tor
41 ToDoEntrycxx . . $ ToDoEntry#ToDoEntry(49f6e7a06ebc5aa8).() = default;
42 /// init c'tor
43 ToDoEntrycxx . . $ ToDoEntry#ToDoEntry(8eafcbdc06e60ab5). ( DlCompletionTreecxx . . $ DlCompletionTree#* n, int off ) : Nodecxx . . $ ToDoEntry#Node.(n), offsetcxx . . $ ToDoEntry#offset.(off) {}
44 }; // ToDoEntry
45
46 /// All-in-one version of arrayToDoTable
47 class ToDoListcxx . . $ ToDoList#
48 {
49 protected: // classes
50 /// class for saving/restoring ToDoQueue
51 class QueueSaveStatecxx . . $ ToDoList#QueueSaveState#
52 {
53 public: // members
54 /// save start point of queue of entries
55 size_tcxx . . $ size_t# spcxx . . $ ToDoList#QueueSaveState#sp. = 0;
56 /// save end point of queue of entries
57 size_tcxx . . $ size_t# epcxx . . $ ToDoList#QueueSaveState#ep. = 0;
58 }; // QueueSaveState
59 //--------------------------------------------------------------------------
60
61 /// class to represent single queue
62 class arrayQueuecxx . . $ ToDoList#arrayQueue#
63 {
64 protected: // members
65 /// waiting ops queue
66 stdcxx . . $ std/::vectorcxx . . $ std/vector#<ToDoEntrycxx . . $ ToDoEntry#> Waitcxx . . $ ToDoList#arrayQueue#Wait.;
67 /// start pointer; points to the 1st element in the queue
68 size_tcxx . . $ size_t# sPointercxx . . $ ToDoList#arrayQueue#sPointer. = 0;
69
70 protected: // types
71 /// type for restore the whole queue
72 class QueueRestorercxx . . $ ToDoList#arrayQueue#QueueRestorer#: public TRestorercxx . . $ TRestorer#
73 {
74 protected: // members
75 /// copy of a queue
76 stdcxx . . $ std/::vectorcxx . . $ std/vector#<ToDoEntrycxx . . $ ToDoEntry#> Waitcxx . . $ ToDoList#arrayQueue#QueueRestorer#Wait.;
77 /// pointer to a queue to restore
78 arrayQueuecxx . . $ ToDoList#arrayQueue#* queuecxx . . $ ToDoList#arrayQueue#QueueRestorer#queue.;
79 /// start pointer
80 size_tcxx . . $ size_t# spcxx . . $ ToDoList#arrayQueue#QueueRestorer#sp.;
81
82 public: // interface
83 /// init c'tor
84 explicit QueueRestorercxx . . $ ToDoList#arrayQueue#QueueRestorer#QueueRestorer(d888d4b2e002d7f7). ( arrayQueuecxx . . $ ToDoList#arrayQueue#* q ) : Waitcxx . . $ ToDoList#arrayQueue#QueueRestorer#Wait.(q->Waitcxx . . $ ToDoList#arrayQueue#Wait.), queuecxx . . $ ToDoList#arrayQueue#QueueRestorer#queue.(q), spcxx . . $ ToDoList#arrayQueue#QueueRestorer#sp.(q->sPointercxx . . $ ToDoList#arrayQueue#sPointer.) {}
85 /// restore: copy the queue back, adjust pointers
86 void restorecxx . . $ ToDoList#arrayQueue#QueueRestorer#restore(49f6e7a06ebc5aa8). () override { stdcxx . . $ std/::swapcxx . . $ std/swap(c5338bf58a130c1b).(queuecxx . . $ ToDoList#arrayQueue#QueueRestorer#queue.->Waitcxx . . $ ToDoList#arrayQueue#Wait., Waitcxx . . $ ToDoList#arrayQueue#QueueRestorer#Wait.); queuecxx . . $ ToDoList#arrayQueue#QueueRestorer#queue.->sPointercxx . . $ ToDoList#arrayQueue#sPointer. = spcxx . . $ ToDoList#arrayQueue#QueueRestorer#sp.; }
87 };
88
89 public: // interface
90 /// c'tor: init queue with proper size and reset it
91 arrayQueuecxx . . $ ToDoList#arrayQueue#arrayQueue(49f6e7a06ebc5aa8).()
92 {
93 Waitcxx . . $ ToDoList#arrayQueue#Wait..reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(50); // initial size
94 Waitcxx . . $ ToDoList#arrayQueue#Wait..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).();
95 }
96
97 /// add entry to a queue
98 virtual void addcxx . . $ ToDoList#arrayQueue#add(8eafcbdc06e60ab5). ( DlCompletionTreecxx . . $ DlCompletionTree#* node, int offset ) { Waitcxx . . $ ToDoList#arrayQueue#Wait..emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(node,offset); }
99 /// clear queue
100 void clearcxx . . $ ToDoList#arrayQueue#clear(49f6e7a06ebc5aa8). ( void ) { sPointercxx . . $ ToDoList#arrayQueue#sPointer. = 0; Waitcxx . . $ ToDoList#arrayQueue#Wait..clearcxx . . $ std/vector#clear(49f6e7a06ebc5aa8).(); }
101 /// check if queue empty
102 bool emptycxx . . $ ToDoList#arrayQueue#empty(50ce9a9e25b4a850). ( void ) const { return sPointercxx . . $ ToDoList#arrayQueue#sPointer. == Waitcxx . . $ ToDoList#arrayQueue#Wait..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).(); }
103 /// get next entry from the queue; works for non-empty queues
104 const ToDoEntrycxx . . $ ToDoEntry#* getcxx . . $ ToDoList#arrayQueue#get(f5089fa5cf30e3eb). ( void ) { return &(Waitcxx . . $ ToDoList#arrayQueue#Wait.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).sPointercxx . . $ ToDoList#arrayQueue#sPointer.++]); }
105
106 /// save queue content to the given entry
107 void savecxx . . $ ToDoList#arrayQueue#save(bad2c4ff489632d2). ( QueueSaveStatecxx . . $ ToDoList#QueueSaveState#& tss ) const
108 {
109 tss.spcxx . . $ ToDoList#QueueSaveState#sp. = sPointercxx . . $ ToDoList#arrayQueue#sPointer.;
110 tss.epcxx . . $ ToDoList#QueueSaveState#ep. = Waitcxx . . $ ToDoList#arrayQueue#Wait..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).();
111 }
112 /// restore queue content from the given entry
113 void restorecxx . . $ ToDoList#arrayQueue#restore(2a82421cebf2d9a). ( const QueueSaveStatecxx . . $ ToDoList#QueueSaveState#& tss )
114 {
115 sPointercxx . . $ ToDoList#arrayQueue#sPointer. = tss.spcxx . . $ ToDoList#QueueSaveState#sp.;
116 Waitcxx . . $ ToDoList#arrayQueue#Wait..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(tss.epcxx . . $ ToDoList#QueueSaveState#ep.);
117 }
118 }; // arrayQueue
119 //--------------------------------------------------------------------------
120
121 /// class to represent single priority queue
122 class queueQueuecxx . . $ ToDoList#queueQueue#: public arrayQueuecxx . . $ ToDoList#arrayQueue#
123 {
124 protected: // members
125 /// stack to save states for the overwritten queue
126 TRareSaveStackcxx . . $ TRareSaveStack#* stackcxx . . $ ToDoList#queueQueue#stack.;
127
128 public: // interface
129 /// c'tor: make an empty queue
130 explicit queueQueuecxx . . $ ToDoList#queueQueue#queueQueue(42cb56d1e32a93f). ( TRareSaveStackcxx . . $ TRareSaveStack#* s ) : arrayQueuecxx . . $ ToDoList#arrayQueue#(), stackcxx . . $ ToDoList#queueQueue#stack.(s) {}
131
132 /// add entry to a queue
133 void addcxx . . $ ToDoList#queueQueue#add(8eafcbdc06e60ab5). ( DlCompletionTreecxx . . $ DlCompletionTree#* Node, int offset ) override
134 {
135 auto nominalLevel = Node->getNominalLevelcxx . . $ DlCompletionTree#getNominalLevel(72085aa11f4b6e09).();
136 auto greaterNominalLevel = [=] (const ToDoEntrycxx . . $ ToDoEntry#& entry) { return entry.Nodecxx . . $ ToDoEntry#Node.->getNominalLevelcxx . . $ DlCompletionTree#getNominalLevel(72085aa11f4b6e09).() > nominalLevel; };
137 if ( emptycxx . . $ ToDoList#arrayQueue#empty(50ce9a9e25b4a850).() || // no problems with empty queue and if no priority clashes
138 !greaterNominalLevel(cxx . . $ ToDoList#queueQueue#add(8eafcbdc06e60ab5).$anonymous_type_0#`operator()`(76f5196cce31f876).Waitcxx . . $ ToDoList#arrayQueue#Wait..backcxx . . $ std/vector#back(feee51535944b307).()) )
139 {
140 Waitcxx . . $ ToDoList#arrayQueue#Wait..emplace_backcxx . . $ std/vector#emplace_back(b3d147e3bb711c35).(Node,offset);
141 return;
142 }
143
144 // here we need to put new entry into a proper place
145 // this will invalidate the array so save it
146 stackcxx . . $ ToDoList#queueQueue#stack.->pushcxx . . $ TRareSaveStack#push(1cbbef85a2ba1293).(new QueueRestorercxx . . $ ToDoList#arrayQueue#QueueRestorer#(this));
147 // find a place for the new entry
148 auto i = stdcxx . . $ std/::find_ifcxx . . $ std/find_if(f0a0a4f94ee5cb00). ( Waitcxx . . $ ToDoList#arrayQueue#Wait..begincxx . . $ std/vector#begin(33b10a496a38335b).()+cxx . . $ __gnu_cxx/__normal_iterator#operator+(d0cb2d2ebd313f38).sPointercxx . . $ ToDoList#arrayQueue#sPointer., Waitcxx . . $ ToDoList#arrayQueue#Wait..endcxx . . $ std/vector#end(33b10a496a38335b).(), greaterNominalLevel );
149 Waitcxx . . $ ToDoList#arrayQueue#Wait..emplacecxx . . $ std/vector#emplace(f067880028bce17f).(icxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ea0f1a22ba5f21a0).,Node,offset);
150 }
151 }; // queueQueue
152 //--------------------------------------------------------------------------
153
154 protected: // internal typedefs
155 /// typedef for NN-queue (which should support complete S/R)
156 typedef queueQueuecxx . . $ ToDoList#queueQueue# NNQueuecxx . . $ ToDoList#NNQueue#;
157
158 protected: // classes
159 /// class for saving/restoring array TODO table
160 class SaveStatecxx . . $ ToDoList#SaveState#
161 {
162 public: // members
163 /// save state for queueID
164 QueueSaveStatecxx . . $ ToDoList#QueueSaveState# backupIDcxx . . $ ToDoList#SaveState#backupID.;
165 /// save state for queueNN
166 QueueSaveStatecxx . . $ ToDoList#QueueSaveState# backupNNcxx . . $ ToDoList#SaveState#backupNN.;
167 /// save state of all regular queues
168 QueueSaveStatecxx . . $ ToDoList#QueueSaveState# backupcxx . . $ ToDoList#SaveState#backup.[nRegularOpscxx . . $ nRegularOps.];
169 /// save number-of-entries to do
170 unsigned int noecxx . . $ ToDoList#SaveState#noe. = 0;
171 }; // SaveState
172 //--------------------------------------------------------------------------
173
174 protected: // members
175 /// waiting ops queue for IDs
176 arrayQueuecxx . . $ ToDoList#arrayQueue# queueIDcxx . . $ ToDoList#queueID.;
177 /// waiting ops queue for <= ops in nominal nodes
178 NNQueuecxx . . $ ToDoList#NNQueue# queueNNcxx . . $ ToDoList#queueNN.;
179 /// waiting ops queues
180 arrayQueuecxx . . $ ToDoList#arrayQueue# Waitcxx . . $ ToDoList#Wait.[nRegularOpscxx . . $ nRegularOps.];
181 /// stack of saved states
182 TSaveStackcxx . . $ TSaveStack#<SaveStatecxx . . $ ToDoList#SaveState#> SaveStackcxx . . $ ToDoList#SaveStack.;
183 /// priority matrix
184 const ToDoPriorMatrixcxx . . $ ToDoPriorMatrix#& Matrixcxx . . $ ToDoList#Matrix.;
185 /// number of un-processed entries
186 unsigned int noecxx . . $ ToDoList#noe. = 0;
187
188 protected: // methods
189 /// save current TODO table content to given saveState entry
190 void saveStatecxx . . $ ToDoList#saveState(426bc096d514f306). ( SaveStatecxx . . $ ToDoList#SaveState#* tss )
191 {
192 queueIDcxx . . $ ToDoList#queueID..savecxx . . $ ToDoList#arrayQueue#save(bad2c4ff489632d2).(tss->backupIDcxx . . $ ToDoList#SaveState#backupID.);
193 queueNNcxx . . $ ToDoList#queueNN..savecxx . . $ ToDoList#arrayQueue#save(bad2c4ff489632d2).(tss->backupNNcxx . . $ ToDoList#SaveState#backupNN.);
194 for ( auto i = 0; i < nRegularOpscxx . . $ nRegularOps.; ++i )
195 Waitcxx . . $ ToDoList#Wait.[i].savecxx . . $ ToDoList#arrayQueue#save(bad2c4ff489632d2).(tss->backupcxx . . $ ToDoList#SaveState#backup.[i]);
196
197 tss->noecxx . . $ ToDoList#SaveState#noe. = noecxx . . $ ToDoList#noe.;
198 }
199 /// restore TODO table content from given saveState entry
200 void restoreStatecxx . . $ ToDoList#restoreState(4791f5b0a891466c). ( const SaveStatecxx . . $ ToDoList#SaveState#* tss )
201 {
202 queueIDcxx . . $ ToDoList#queueID..restorecxx . . $ ToDoList#arrayQueue#restore(2a82421cebf2d9a).(tss->backupIDcxx . . $ ToDoList#SaveState#backupID.);
203 queueNNcxx . . $ ToDoList#queueNN..restorecxx . . $ ToDoList#arrayQueue#restore(2a82421cebf2d9a).(tss->backupNNcxx . . $ ToDoList#SaveState#backupNN.);
204 for ( auto i = 0; i < nRegularOpscxx . . $ nRegularOps.; ++i )
205 Waitcxx . . $ ToDoList#Wait.[i].restorecxx . . $ ToDoList#arrayQueue#restore(2a82421cebf2d9a).(tss->backupcxx . . $ ToDoList#SaveState#backup.[i]);
206
207 noecxx . . $ ToDoList#noe. = tss->noecxx . . $ ToDoList#SaveState#noe.;
208 }
209
210 public:
211 /// init c'tor
212 ToDoListcxx . . $ ToDoList#ToDoList(762f1cbf1ec4e008).( const ToDoPriorMatrixcxx . . $ ToDoPriorMatrix#& matrix, TRareSaveStackcxx . . $ TRareSaveStack#* stack ) : queueNNcxx . . $ ToDoList#queueNN.(stack), Matrixcxx . . $ ToDoList#Matrix.(matrix) {}
213 /// no copy c'tor
214 ToDoListcxx . . $ ToDoList#ToDoList(e33c792e89b5a26d).( const ToDoListcxx . . $ ToDoList#& ) = delete;
215 /// no assignment
216 ToDoListcxx . . $ ToDoList#& operatorcxx . . $ ToDoList#`operator=`(c438f642f8349e44). = ( const ToDoListcxx . . $ ToDoList#& ) = delete;
217 /// d'tor: delete all entries
218 ~cxx . . $ ToDoList#`~ToDoList`(49f6e7a06ebc5aa8).ToDoListcxx . . $ ToDoList#() { clearcxx . . $ ToDoList#clear(49f6e7a06ebc5aa8).(); }
219
220 // global methods
221
222 /// clear TODO table
223 void clearcxx . . $ ToDoList#clear(49f6e7a06ebc5aa8). ( void )
224 {
225 queueIDcxx . . $ ToDoList#queueID..clearcxx . . $ ToDoList#arrayQueue#clear(49f6e7a06ebc5aa8).();
226 queueNNcxx . . $ ToDoList#queueNN..clearcxx . . $ ToDoList#arrayQueue#clear(49f6e7a06ebc5aa8).();
227 for ( auto& queue: Waitcxx . . $ ToDoList#Wait. )
228 queue.clearcxx . . $ ToDoList#arrayQueue#clear(49f6e7a06ebc5aa8).();
229
230 SaveStackcxx . . $ ToDoList#SaveStack..clearcxx . . $ growingArrayP#clear(49f6e7a06ebc5aa8).();
231 noecxx . . $ ToDoList#noe. = 0;
232 }
233 /// check if TODO table is empty
234 bool emptycxx . . $ ToDoList#empty(50ce9a9e25b4a850). ( void ) const { return !noecxx . . $ ToDoList#noe.; }
235
236 // work with entries
237
238 /// add entry with given NODE and CONCEPT with given OFFSET to the TODO table
239 void addEntrycxx . . $ ToDoList#addEntry(6f2cfd92839f4348). ( DlCompletionTreecxx . . $ DlCompletionTree#* node, DagTagcxx . . $ DagTag# type, BipolarPointercxx . . $ BipolarPointer# bp, int offset )
240 {
241 auto index = Matrixcxx . . $ ToDoList#Matrix..getIndexcxx . . $ ToDoPriorMatrix#getIndex(a85f1ffef8419fb8). ( type, isPositivecxx . . $ isPositive(83c267b20bac841a).(bp), node->isNominalNodecxx . . $ DlCompletionTree#isNominalNode(50ce9a9e25b4a850).() );
242 switch ( index )
243 {
244 case nRegularOpscxx . . $ nRegularOps.: // unused entry
245 return;
246 case iIdcxx . . $ iId.: // ID
247 queueIDcxx . . $ ToDoList#queueID..addcxx . . $ ToDoList#arrayQueue#add(8eafcbdc06e60ab5).(node,offset); break;
248 case iNNcxx . . $ iNN.: // NN
249 queueNNcxx . . $ ToDoList#queueNN..addcxx . . $ ToDoList#queueQueue#add(8eafcbdc06e60ab5).(node,offset); break;
250 default: // regular queue
251 Waitcxx . . $ ToDoList#Wait.[index].addcxx . . $ ToDoList#arrayQueue#add(8eafcbdc06e60ab5).(node,offset); break;
252 }
253 ++noecxx . . $ ToDoList#noe.;
254 }
255 /// add entry with given NODE and CONCEPT of a TYPE to the ToDo table
256 void addEntrycxx . . $ ToDoList#addEntry(554b0186d7b682ae). ( DlCompletionTreecxx . . $ DlCompletionTree#* node, DagTagcxx . . $ DagTag# type, BipolarPointercxx . . $ BipolarPointer# bp )
257 { addEntrycxx . . $ ToDoList#addEntry(6f2cfd92839f4348). ( node, type, bp, node->labelcxx . . $ DlCompletionTree#label(d7a009c437cd4657).().getLastcxx . . $ CGLabel#getLast(6006887bf52ae696).(type) ); }
258 /// get the next TODO entry. @return NULL if the table is empty
259 const ToDoEntrycxx . . $ ToDoEntry#* getNextEntrycxx . . $ ToDoList#getNextEntry(f5089fa5cf30e3eb). ( void );
260
261 // save/restore methods
262
263 /// save current state using internal stack
264 void savecxx . . $ ToDoList#save(49f6e7a06ebc5aa8). ( void ) { saveStatecxx . . $ ToDoList#saveState(426bc096d514f306).(SaveStackcxx . . $ ToDoList#SaveStack..pushcxx . . $ TSaveStack#push(155dc7f103cdb9db).()); }
265 /// restore state using internal stack
266 void restorecxx . . $ ToDoList#restore(49f6e7a06ebc5aa8). ( void ) { fpp_assertcxx . . $ `Kernel/fpp_assert.h:46:10`! ( !SaveStack.empty() ); restoreStatecxx . . $ ToDoList#restoreState(4791f5b0a891466c).(SaveStackcxx . . $ ToDoList#SaveStack..popcxx . . $ TSaveStack#pop(155dc7f103cdb9db).()); }
267 /// restore state to the given level using internal stack
268 void restorecxx . . $ ToDoList#restore(cb2f890c2fdad230). ( unsigned int level ) { restoreStatecxx . . $ ToDoList#restoreState(4791f5b0a891466c).(SaveStackcxx . . $ ToDoList#SaveStack..popcxx . . $ TSaveStack#pop(18e8862a30c27574).(level)); }
269 }; // ToDoList
270
271 inline const ToDoEntrycxx . . $ ToDoEntry#* ToDoListcxx . . $ ToDoList# :: getNextEntrycxx . . $ ToDoList#getNextEntry(f5089fa5cf30e3eb). ( void )
272 {
273 #ifdef ENABLE_CHECKING
274 fpp_assert ( !empty () ); // safety check
275 #endif
276
277 // decrease amount of elements-to-process
278 --noecxx . . $ ToDoList#noe.;
279
280 // check ID queue
281 if ( !queueIDcxx . . $ ToDoList#queueID..emptycxx . . $ ToDoList#arrayQueue#empty(50ce9a9e25b4a850).() )
282 return queueIDcxx . . $ ToDoList#queueID..getcxx . . $ ToDoList#arrayQueue#get(f5089fa5cf30e3eb).();
283
284 // check NN queue
285 if ( !queueNNcxx . . $ ToDoList#queueNN..emptycxx . . $ ToDoList#arrayQueue#empty(50ce9a9e25b4a850).() )
286 return queueNNcxx . . $ ToDoList#queueNN..getcxx . . $ ToDoList#arrayQueue#get(f5089fa5cf30e3eb).();
287
288 // check regular queues
289 for ( auto& queue: Waitcxx . . $ ToDoList#Wait. )
290 if ( !queue.emptycxx . . $ ToDoList#arrayQueue#empty(50ce9a9e25b4a850).() )
291 return queue.getcxx . . $ ToDoList#arrayQueue#get(f5089fa5cf30e3eb).();
292
293 // that's impossible, but still...
294 return nullptr;
295 }
296
297 #endif