1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | * Copyright (C) 2013 Frederik Heber. All rights reserved.
|
---|
6 | *
|
---|
7 | *
|
---|
8 | * This file is part of MoleCuilder.
|
---|
9 | *
|
---|
10 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation, either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * DepthFirstSearchAnalysis.cpp
|
---|
26 | *
|
---|
27 | * Created on: Feb 16, 2011
|
---|
28 | * Author: heber
|
---|
29 | */
|
---|
30 |
|
---|
31 | // include config.h
|
---|
32 | #ifdef HAVE_CONFIG_H
|
---|
33 | #include <config.h>
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #include "CodePatterns/MemDebug.hpp"
|
---|
37 |
|
---|
38 | #include "DepthFirstSearchAnalysis.hpp"
|
---|
39 |
|
---|
40 | #include <algorithm>
|
---|
41 | #include <functional>
|
---|
42 |
|
---|
43 | #include "Atom/atom.hpp"
|
---|
44 | #include "Bond/bond.hpp"
|
---|
45 | #include "CodePatterns/Assert.hpp"
|
---|
46 | #include "CodePatterns/Info.hpp"
|
---|
47 | #include "CodePatterns/Log.hpp"
|
---|
48 | #include "CodePatterns/Verbose.hpp"
|
---|
49 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
50 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
51 | #include "Graph/ListOfLocalAtoms.hpp"
|
---|
52 | #include "molecule.hpp"
|
---|
53 | #include "MoleculeLeafClass.hpp"
|
---|
54 | #include "MoleculeListClass.hpp"
|
---|
55 | #include "World.hpp"
|
---|
56 |
|
---|
57 | DepthFirstSearchAnalysis::DepthFirstSearchAnalysis() :
|
---|
58 | CurrentGraphNr(0),
|
---|
59 | ComponentNumber(0),
|
---|
60 | BackStepping(false)
|
---|
61 | {
|
---|
62 | ResetAllBondsToUnused();
|
---|
63 | }
|
---|
64 |
|
---|
65 | DepthFirstSearchAnalysis::~DepthFirstSearchAnalysis()
|
---|
66 | {}
|
---|
67 |
|
---|
68 | void DepthFirstSearchAnalysis::Init()
|
---|
69 | {
|
---|
70 | CurrentGraphNr = 0;
|
---|
71 | ComponentNumber = 0;
|
---|
72 | BackStepping = false;
|
---|
73 | std::for_each(World::getInstance().getAtomIter(),World::getInstance().atomEnd(),
|
---|
74 | std::mem_fun(&atom::resetGraphNr));
|
---|
75 | std::for_each(World::getInstance().getAtomIter(),World::getInstance().atomEnd(),
|
---|
76 | std::mem_fun(&atom::InitComponentNr));
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | bond::ptr DepthFirstSearchAnalysis::FindNextUnused(atom *vertex) const
|
---|
81 | {
|
---|
82 | const BondList& ListOfBonds = vertex->getListOfBonds();
|
---|
83 | for (BondList::const_iterator Runner = ListOfBonds.begin();
|
---|
84 | Runner != ListOfBonds.end();
|
---|
85 | ++Runner)
|
---|
86 | if ((*Runner)->IsUsed() == GraphEdge::white)
|
---|
87 | return ((*Runner));
|
---|
88 | return bond::ptr();
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | void DepthFirstSearchAnalysis::ResetAllBondsToUnused() const
|
---|
93 | {
|
---|
94 | World::AtomComposite allatoms = World::getInstance().getAllAtoms();
|
---|
95 | for(World::AtomComposite::const_iterator AtomRunner = allatoms.begin();
|
---|
96 | AtomRunner != allatoms.end();
|
---|
97 | ++AtomRunner) {
|
---|
98 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
|
---|
99 | for(BondList::const_iterator BondRunner = ListOfBonds.begin();
|
---|
100 | BondRunner != ListOfBonds.end();
|
---|
101 | ++BondRunner)
|
---|
102 | if ((*BondRunner)->leftatom == *AtomRunner)
|
---|
103 | (*BondRunner)->ResetUsed();
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | void DepthFirstSearchAnalysis::SetNextComponentNumber(atom *vertex, int nr) const
|
---|
108 | {
|
---|
109 | size_t i = 0;
|
---|
110 | ASSERT(vertex != NULL,
|
---|
111 | "DepthFirstSearchAnalysis::SetNextComponentNumber() - Given vertex is NULL!");
|
---|
112 | const BondList& ListOfBonds = vertex->getListOfBonds();
|
---|
113 | for (; i < ListOfBonds.size(); i++) {
|
---|
114 | if (vertex->ComponentNr[i] == -1) { // check if not yet used
|
---|
115 | vertex->ComponentNr[i] = nr;
|
---|
116 | break;
|
---|
117 | } else if (vertex->ComponentNr[i] == nr) // if number is already present, don't add another time
|
---|
118 | break; // breaking here will not cause error!
|
---|
119 | }
|
---|
120 | ASSERT(i < ListOfBonds.size(),
|
---|
121 | "DepthFirstSearchAnalysis::SetNextComponentNumber() - All Component entries are already occupied!");
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | bool DepthFirstSearchAnalysis::PickLocalBackEdges(const ListOfLocalAtoms_t &ListOfLocalAtoms, std::deque<bond::ptr > *&LocalStack) const
|
---|
126 | {
|
---|
127 | bool status = true;
|
---|
128 | if (BackEdgeStack.empty()) {
|
---|
129 | ELOG(1, "Reference BackEdgeStack is empty!");
|
---|
130 | return false;
|
---|
131 | }
|
---|
132 | std::deque<bond::ptr > MyBackEdgeStack = BackEdgeStack;
|
---|
133 |
|
---|
134 | do { // go through all bonds and push local ones
|
---|
135 | const bond::ptr &Binder = MyBackEdgeStack.front(); // loop the stack for next item
|
---|
136 | MyBackEdgeStack.pop_front();
|
---|
137 | LOG(3, "INFO: Current candidate edge " << *Binder << ".");
|
---|
138 | const ListOfLocalAtoms_t::const_iterator leftiter = ListOfLocalAtoms.find(Binder->leftatom->getNr());
|
---|
139 | ASSERT( leftiter != ListOfLocalAtoms.end(),
|
---|
140 | "DepthFirstSearchAnalysis::PickLocalBackEdges() - could not find atom id "
|
---|
141 | +toString(Binder->leftatom->getNr())+" in ListOfLocalAtoms.");
|
---|
142 | atom * const Walker = leftiter->second; // get one atom in the reference molecule
|
---|
143 | if (Walker != NULL) { // if this Walker exists in the subgraph ...
|
---|
144 | const BondList& ListOfBonds = Walker->getListOfBonds();
|
---|
145 | for (BondList::const_iterator Runner = ListOfBonds.begin();
|
---|
146 | Runner != ListOfBonds.end();
|
---|
147 | ++Runner) {
|
---|
148 | atom * const OtherAtom = (*Runner)->GetOtherAtom(Walker);
|
---|
149 | const ListOfLocalAtoms_t::const_iterator rightiter = ListOfLocalAtoms.find((*Runner)->rightatom->getNr());
|
---|
150 | if (OtherAtom == rightiter->second) { // found the bond
|
---|
151 | LocalStack->push_front((*Runner));
|
---|
152 | LOG(3, "INFO: Found local edge " << *(*Runner) << ".");
|
---|
153 | break;
|
---|
154 | }
|
---|
155 | }
|
---|
156 | }
|
---|
157 | } while (!MyBackEdgeStack.empty());
|
---|
158 |
|
---|
159 | return status;
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 | void DepthFirstSearchAnalysis::OutputGraphInfoPerAtom() const
|
---|
165 | {
|
---|
166 | LOG(1, "Final graph info for each atom is:");
|
---|
167 | World::ConstAtomComposite allatoms = const_cast<const World &>(World::getInstance()).
|
---|
168 | getAllAtoms();
|
---|
169 | for_each(allatoms.begin(),allatoms.end(),mem_fun(&atom::OutputGraphInfo));
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | void DepthFirstSearchAnalysis::OutputGraphInfoPerBond() const
|
---|
174 | {
|
---|
175 | LOG(1, "Final graph info for each bond is:");
|
---|
176 | World::ConstAtomComposite allatoms = const_cast<const World &>(World::getInstance()).
|
---|
177 | getAllAtoms();
|
---|
178 | for(World::ConstAtomComposite::const_iterator AtomRunner = allatoms.begin();
|
---|
179 | AtomRunner != allatoms.end();
|
---|
180 | ++AtomRunner) {
|
---|
181 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
|
---|
182 | for(BondList::const_iterator BondRunner = ListOfBonds.begin();
|
---|
183 | BondRunner != ListOfBonds.end();
|
---|
184 | ++BondRunner)
|
---|
185 | if ((*BondRunner)->leftatom == *AtomRunner) {
|
---|
186 | const bond::ptr Binder = *BondRunner;
|
---|
187 | if (DoLog(2)) {
|
---|
188 | std::stringstream output;
|
---|
189 | output << ((Binder->Type == GraphEdge::TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <";
|
---|
190 | output << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.";
|
---|
191 | Binder->leftatom->OutputComponentNumber(&output);
|
---|
192 | output << " === ";
|
---|
193 | output << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.";
|
---|
194 | Binder->rightatom->OutputComponentNumber(&output);
|
---|
195 | output << ">.";
|
---|
196 | LOG(2, output.str());
|
---|
197 | }
|
---|
198 | if (Binder->Cyclic) // cyclic ??
|
---|
199 | LOG(3, "Lowpoint at each side are equal: CYCLIC!");
|
---|
200 | }
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | unsigned int DepthFirstSearchAnalysis::CyclicBondAnalysis() const
|
---|
206 | {
|
---|
207 | unsigned int NoCyclicBonds = 0;
|
---|
208 | World::ConstAtomComposite allatoms = const_cast<const World &>(World::getInstance()).
|
---|
209 | getAllAtoms();
|
---|
210 | for(World::ConstAtomComposite::const_iterator AtomRunner = allatoms.begin();
|
---|
211 | AtomRunner != allatoms.end();
|
---|
212 | ++AtomRunner) {
|
---|
213 | const BondList& ListOfBonds = (*AtomRunner)->getListOfBonds();
|
---|
214 | for(BondList::const_iterator BondRunner = ListOfBonds.begin();
|
---|
215 | BondRunner != ListOfBonds.end();
|
---|
216 | ++BondRunner)
|
---|
217 | if ((*BondRunner)->leftatom == *AtomRunner)
|
---|
218 | if ((*BondRunner)->rightatom->LowpointNr == (*BondRunner)->leftatom->LowpointNr) { // cyclic ??
|
---|
219 | (*BondRunner)->Cyclic = true;
|
---|
220 | NoCyclicBonds++;
|
---|
221 | }
|
---|
222 | }
|
---|
223 | return NoCyclicBonds;
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | void DepthFirstSearchAnalysis::SetWalkersGraphNr(atom *&Walker)
|
---|
228 | {
|
---|
229 | if (!BackStepping) { // if we don't just return from (8)
|
---|
230 | Walker->GraphNr = CurrentGraphNr;
|
---|
231 | Walker->LowpointNr = CurrentGraphNr;
|
---|
232 | LOG(1, "Setting Walker[" << Walker->getName() << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << ".");
|
---|
233 | AtomStack.push_front(Walker);
|
---|
234 | CurrentGraphNr++;
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | void DepthFirstSearchAnalysis::ProbeAlongUnusedBond(atom *&Walker, bond::ptr &Binder)
|
---|
240 | {
|
---|
241 | atom *OtherAtom = NULL;
|
---|
242 |
|
---|
243 | do { // (3) if Walker has no unused egdes, go to (5)
|
---|
244 | BackStepping = false; // reset backstepping flag for (8)
|
---|
245 | if (Binder == NULL) // if we don't just return from (11), Binder is already set to next unused
|
---|
246 | Binder = FindNextUnused(Walker);
|
---|
247 | if (Binder == NULL)
|
---|
248 | break;
|
---|
249 | LOG(2, "Current Unused Bond is " << *Binder << ".");
|
---|
250 | // (4) Mark Binder used, ...
|
---|
251 | Binder->MarkUsed(GraphEdge::black);
|
---|
252 | OtherAtom = Binder->GetOtherAtom(Walker);
|
---|
253 | LOG(2, "(4) OtherAtom is " << OtherAtom->getName() << ".");
|
---|
254 | if (OtherAtom->GraphNr != -1) {
|
---|
255 | // (4a) ... if "other" atom has been visited (GraphNr != 0), set lowpoint to minimum of both, go to (3)
|
---|
256 | Binder->Type = GraphEdge::BackEdge;
|
---|
257 | BackEdgeStack.push_front(Binder);
|
---|
258 | Walker->LowpointNr = (Walker->LowpointNr < OtherAtom->GraphNr) ? Walker->LowpointNr : OtherAtom->GraphNr;
|
---|
259 | LOG(3, "(4a) Visited: Setting Lowpoint of Walker[" << Walker->getName() << "] to " << Walker->LowpointNr << ".");
|
---|
260 | } else {
|
---|
261 | // (4b) ... otherwise set OtherAtom as Ancestor of Walker and Walker as OtherAtom, go to (2)
|
---|
262 | Binder->Type = GraphEdge::TreeEdge;
|
---|
263 | OtherAtom->Ancestor = Walker;
|
---|
264 | Walker = OtherAtom;
|
---|
265 | LOG(3, "(4b) Not Visited: OtherAtom[" << OtherAtom->getName() << "]'s Ancestor is now " << OtherAtom->Ancestor->getName() << ", Walker is OtherAtom " << OtherAtom->getName() << ".");
|
---|
266 | break;
|
---|
267 | }
|
---|
268 | Binder.reset();
|
---|
269 | } while (1); // (3)
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | void DepthFirstSearchAnalysis::CheckForaNewComponent(atom *&Walker, ConnectedSubgraph &Subgraph)
|
---|
274 | {
|
---|
275 | atom *OtherAtom = NULL;
|
---|
276 |
|
---|
277 | // (5) if Ancestor of Walker is ...
|
---|
278 | LOG(1, "(5) Number of Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "] is " << Walker->Ancestor->GraphNr << ".");
|
---|
279 |
|
---|
280 | if (Walker->Ancestor->GraphNr != Root->GraphNr) {
|
---|
281 | // (6) (Ancestor of Walker is not Root)
|
---|
282 | if (Walker->LowpointNr < Walker->Ancestor->GraphNr) {
|
---|
283 | // (6a) set Ancestor's Lowpoint number to minimum of of its Ancestor and itself, go to Step(8)
|
---|
284 | Walker->Ancestor->LowpointNr = (Walker->Ancestor->LowpointNr < Walker->LowpointNr) ? Walker->Ancestor->LowpointNr : Walker->LowpointNr;
|
---|
285 | LOG(2, "(6) Setting Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << ".");
|
---|
286 | } else {
|
---|
287 | // (7) (Ancestor of Walker is a separating vertex, remove all from stack till Walker (including), these and Ancestor form a component
|
---|
288 | Walker->Ancestor->SeparationVertex = true;
|
---|
289 | LOG(2, "(7) Walker[" << Walker->getName() << "]'s Ancestor[" << Walker->Ancestor->getName() << "]'s is a separating vertex, creating component.");
|
---|
290 | SetNextComponentNumber(Walker->Ancestor, ComponentNumber);
|
---|
291 | LOG(3, "(7) Walker[" << Walker->getName() << "]'s Ancestor's Compont is " << ComponentNumber << ".");
|
---|
292 | SetNextComponentNumber(Walker, ComponentNumber);
|
---|
293 | LOG(3, "(7) Walker[" << Walker->getName() << "]'s Compont is " << ComponentNumber << ".");
|
---|
294 | do {
|
---|
295 | ASSERT(!AtomStack.empty(), "DepthFirstSearchAnalysis_CheckForaNewComponent() - AtomStack is empty!");
|
---|
296 | OtherAtom = AtomStack.front();
|
---|
297 | AtomStack.pop_front();
|
---|
298 | Subgraph.push_back(OtherAtom);
|
---|
299 | SetNextComponentNumber(OtherAtom, ComponentNumber);
|
---|
300 | LOG(3, "(7) Other[" << OtherAtom->getName() << "]'s Compont is " << ComponentNumber << ".");
|
---|
301 | } while (OtherAtom != Walker);
|
---|
302 | ComponentNumber++;
|
---|
303 | }
|
---|
304 | // (8) Walker becomes its Ancestor, go to (3)
|
---|
305 | LOG(2, "(8) Walker[" << Walker->getName() << "] is now its Ancestor " << Walker->Ancestor->getName() << ", backstepping. ");
|
---|
306 | Walker = Walker->Ancestor;
|
---|
307 | BackStepping = true;
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 |
|
---|
312 | void DepthFirstSearchAnalysis::CleanRootStackDownTillWalker(atom *&Walker, bond::ptr &Binder, ConnectedSubgraph &Subgraph)
|
---|
313 | {
|
---|
314 | atom *OtherAtom = NULL;
|
---|
315 |
|
---|
316 | if (!BackStepping) { // coming from (8) want to go to (3)
|
---|
317 | // (9) remove all from stack till Walker (including), these and Root form a component
|
---|
318 | //AtomStack.Output(out);
|
---|
319 | SetNextComponentNumber(Root, ComponentNumber);
|
---|
320 | LOG(3, "(9) Root[" << Root->getName() << "]'s Component is " << ComponentNumber << ".");
|
---|
321 | SetNextComponentNumber(Walker, ComponentNumber);
|
---|
322 | LOG(3, "(9) Walker[" << Walker->getName() << "]'s Component is " << ComponentNumber << ".");
|
---|
323 | do {
|
---|
324 | ASSERT(!AtomStack.empty(), "DepthFirstSearchAnalysis::CleanRootStackDownTillWalker() - AtomStack is empty!");
|
---|
325 | OtherAtom = AtomStack.front();
|
---|
326 | AtomStack.pop_front();
|
---|
327 | Subgraph.push_back(OtherAtom);
|
---|
328 | SetNextComponentNumber(OtherAtom, ComponentNumber);
|
---|
329 | LOG(3, "(7) Other[" << OtherAtom->getName() << "]'s Component is " << ComponentNumber << ".");
|
---|
330 | } while (OtherAtom != Walker);
|
---|
331 | ComponentNumber++;
|
---|
332 |
|
---|
333 | // (11) Root is separation vertex, set Walker to Root and go to (4)
|
---|
334 | Walker = Root;
|
---|
335 | Binder = FindNextUnused(Walker);
|
---|
336 | if (Binder != NULL) { // Root is separation vertex
|
---|
337 | LOG(1, "(10) Walker is Root[" << Root->getName() << "], next Unused Bond is " << *Binder << ".");
|
---|
338 | LOG(1, "(11) Root is a separation vertex.");
|
---|
339 | Walker->SeparationVertex = true;
|
---|
340 | } else {
|
---|
341 | LOG(1, "(10) Walker is Root[" << Root->getName() << "], no next Unused Bond.");
|
---|
342 | }
|
---|
343 | }
|
---|
344 | }
|
---|
345 |
|
---|
346 |
|
---|
347 | const std::deque<bond::ptr >& DepthFirstSearchAnalysis::getBackEdgeStack() const
|
---|
348 | {
|
---|
349 | return BackEdgeStack;
|
---|
350 | }
|
---|
351 |
|
---|
352 |
|
---|
353 | void DepthFirstSearchAnalysis::operator()()
|
---|
354 | {
|
---|
355 | Info FunctionInfo("DepthFirstSearchAnalysis");
|
---|
356 | ListOfConnectedSubgraphs.clear();
|
---|
357 | int OldGraphNr = 0;
|
---|
358 | atom *Walker = NULL;
|
---|
359 | bond::ptr Binder;
|
---|
360 |
|
---|
361 | if (World::getInstance().numAtoms() == 0)
|
---|
362 | return;
|
---|
363 |
|
---|
364 | Init();
|
---|
365 |
|
---|
366 | LOG(0, "STATUS: Start walking the bond graph.");
|
---|
367 | for(World::AtomIterator iter = World::getInstance().getAtomIter();
|
---|
368 | iter != World::getInstance().atomEnd();) { // don't advance, is done at the end
|
---|
369 | Root = *iter;
|
---|
370 | // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all
|
---|
371 | AtomStack.clear();
|
---|
372 |
|
---|
373 | // put into new subgraph molecule and add this to list of subgraphs
|
---|
374 | ConnectedSubgraph CurrentSubgraph;
|
---|
375 | CurrentSubgraph.push_back(Root);
|
---|
376 |
|
---|
377 | OldGraphNr = CurrentGraphNr;
|
---|
378 | Walker = Root;
|
---|
379 | do { // (10)
|
---|
380 | do { // (2) set number and Lowpoint of Atom to i, increase i, push current atom
|
---|
381 | SetWalkersGraphNr(Walker);
|
---|
382 |
|
---|
383 | ProbeAlongUnusedBond(Walker, Binder);
|
---|
384 |
|
---|
385 | if (Binder == NULL) {
|
---|
386 | LOG(2, "No more Unused Bonds.");
|
---|
387 | break;
|
---|
388 | } else
|
---|
389 | Binder.reset();
|
---|
390 | } while (1); // (2)
|
---|
391 |
|
---|
392 | // if we came from backstepping, yet there were no more unused bonds, we end up here with no Ancestor, because Walker is Root! Then we are finished!
|
---|
393 | if ((Walker == Root) && (Binder == NULL))
|
---|
394 | break;
|
---|
395 |
|
---|
396 | CheckForaNewComponent( Walker, CurrentSubgraph);
|
---|
397 |
|
---|
398 | CleanRootStackDownTillWalker(Walker, Binder, CurrentSubgraph);
|
---|
399 |
|
---|
400 | } while ((BackStepping) || (Binder != NULL)); // (10) halt only if Root has no unused edges
|
---|
401 |
|
---|
402 | ListOfConnectedSubgraphs.push_back(CurrentSubgraph);
|
---|
403 | // From OldGraphNr to CurrentGraphNr ranges an disconnected subgraph
|
---|
404 | std::stringstream output;
|
---|
405 | output << CurrentSubgraph;
|
---|
406 | LOG(1, "INFO: Disconnected subgraph ranges from " << OldGraphNr << " to "
|
---|
407 | << CurrentGraphNr-1 << ": " << output.str());
|
---|
408 |
|
---|
409 | // step on to next root
|
---|
410 | while (iter != World::getInstance().atomEnd()) {
|
---|
411 | if ((*iter)->GraphNr != -1) { // if already discovered, step on
|
---|
412 | iter++;
|
---|
413 | } else {
|
---|
414 | LOG(1,"Current next subgraph root candidate is " << (*iter)->getName()
|
---|
415 | << " with GraphNr " << (*iter)->GraphNr << ".");
|
---|
416 | break;
|
---|
417 | }
|
---|
418 | }
|
---|
419 | }
|
---|
420 | LOG(0, "STATUS: Done walking the bond graph.");
|
---|
421 |
|
---|
422 | // set cyclic bond criterium on "same LP" basis
|
---|
423 | CyclicBondAnalysis();
|
---|
424 |
|
---|
425 | OutputGraphInfoPerAtom();
|
---|
426 |
|
---|
427 | OutputGraphInfoPerBond();
|
---|
428 | }
|
---|
429 |
|
---|
430 | void DepthFirstSearchAnalysis::UpdateMoleculeStructure() const
|
---|
431 | {
|
---|
432 | // remove all of World's molecules
|
---|
433 | for (World::MoleculeIterator iter = World::getInstance().getMoleculeIter();
|
---|
434 | World::getInstance().getMoleculeIter() != World::getInstance().moleculeEnd();
|
---|
435 | iter = World::getInstance().getMoleculeIter()) {
|
---|
436 | // TODO: remove when deprecated MoleculeListClass is gone
|
---|
437 | World::getInstance().getMolecules()->erase(*iter);
|
---|
438 | World::getInstance().destroyMolecule(*iter);
|
---|
439 | }
|
---|
440 | // instantiate new molecules
|
---|
441 | molecule *newmol = NULL;
|
---|
442 | for (ConnectedSubgraphList::const_iterator iter = ListOfConnectedSubgraphs.begin();
|
---|
443 | iter != ListOfConnectedSubgraphs.end();
|
---|
444 | ++iter) {
|
---|
445 | newmol = (*iter).getMolecule();
|
---|
446 | if (DoLog(2)) {
|
---|
447 | LOG(2, "STATUS: Creating new molecule:");
|
---|
448 | std::stringstream output;
|
---|
449 | newmol->Output(&output);
|
---|
450 | std::stringstream outstream(output.str());
|
---|
451 | std::string line;
|
---|
452 | while (getline(outstream, line)) {
|
---|
453 | LOG(2, "\t"+line);
|
---|
454 | }
|
---|
455 | }
|
---|
456 | }
|
---|
457 | }
|
---|
458 |
|
---|
459 | MoleculeLeafClass *DepthFirstSearchAnalysis::getMoleculeStructure() const
|
---|
460 | {
|
---|
461 | MoleculeLeafClass *Subgraphs = new MoleculeLeafClass(NULL);
|
---|
462 | MoleculeLeafClass *MolecularWalker = Subgraphs;
|
---|
463 | for (World::MoleculeIterator iter = World::getInstance().getMoleculeIter();
|
---|
464 | iter != World::getInstance().moleculeEnd();
|
---|
465 | ++iter) {
|
---|
466 | // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include
|
---|
467 | MolecularWalker = new MoleculeLeafClass(MolecularWalker);
|
---|
468 | MolecularWalker->Leaf = (*iter);
|
---|
469 | }
|
---|
470 | return Subgraphs;
|
---|
471 | }
|
---|
472 |
|
---|