[14de469] | 1 | /** \file graph.cpp
|
---|
[6ac7ee] | 2 | *
|
---|
[14de469] | 3 | * Function implementations for the class graph.
|
---|
[6ac7ee] | 4 | *
|
---|
[14de469] | 5 | */
|
---|
| 6 |
|
---|
| 7 | using namespace std;
|
---|
| 8 |
|
---|
[f66195] | 9 | #include "atom.hpp"
|
---|
| 10 | #include "bond.hpp"
|
---|
| 11 | #include "config.hpp"
|
---|
[5621c3] | 12 | #include "graph.hpp"
|
---|
[f66195] | 13 | #include "molecule.hpp"
|
---|
[14de469] | 14 |
|
---|
[5621c3] | 15 | /***************************************** Implementations for graph classes ********************************/
|
---|
[14de469] | 16 |
|
---|
[f66195] | 17 | ///** Constructor of class Graph.
|
---|
| 18 | // */
|
---|
| 19 | //Graph::Graph()
|
---|
| 20 | //{
|
---|
| 21 | //};
|
---|
| 22 | //
|
---|
| 23 | ///** Destructor of class Graph.
|
---|
| 24 | // * Destructor does release memory for nodes and edges contained in its lists as well.
|
---|
| 25 | // */
|
---|
| 26 | //Graph::~Graph()
|
---|
| 27 | //{
|
---|
| 28 | //};
|
---|
| 29 | //
|
---|
| 30 | ///** Constructor of class SubGraph.
|
---|
| 31 | // */
|
---|
| 32 | //SubGraph::SubGraph()
|
---|
| 33 | //{
|
---|
| 34 | //};
|
---|
| 35 | //
|
---|
| 36 | ///** Destructor of class SubGraph.
|
---|
| 37 | // * Note that destructor does not deallocate either nodes or edges! (this is done by its subgraph!)
|
---|
| 38 | // */
|
---|
| 39 | //SubGraph::~SubGraph()
|
---|
| 40 | //{
|
---|
| 41 | //};
|
---|
| 42 | //
|
---|
| 43 | ///** Constructor of class Node.
|
---|
| 44 | // */
|
---|
| 45 | //Node::Node()
|
---|
| 46 | //{
|
---|
| 47 | //};
|
---|
| 48 | //
|
---|
| 49 | ///** Destructor of class Node.
|
---|
| 50 | // */
|
---|
| 51 | //Node::~Node()
|
---|
| 52 | //{
|
---|
| 53 | //};
|
---|
| 54 | //
|
---|
| 55 | ///** Constructor of class Edge.
|
---|
| 56 | // */
|
---|
| 57 | //Edge::Edge()
|
---|
| 58 | //{
|
---|
| 59 | //};
|
---|
| 60 | //
|
---|
| 61 | ///** Destructor of class Edge.
|
---|
| 62 | // */
|
---|
| 63 | //Edge::~Edge()
|
---|
| 64 | //{
|
---|
| 65 | //};
|
---|
[5621c3] | 66 |
|
---|
| 67 |
|
---|
[f66195] | 68 | //bool operator < (KeySet SubgraphA, KeySet SubgraphB)
|
---|
| 69 | //{
|
---|
| 70 | // return KeyCompare(SubgraphA, SubgraphB);
|
---|
| 71 | //};
|
---|
[5621c3] | 72 |
|
---|
[f66195] | 73 | /** Checking whether KeySet is not already present in Graph, if so just adds factor.
|
---|
| 74 | * \param *out output stream for debugging
|
---|
| 75 | * \param &set KeySet to insert
|
---|
| 76 | * \param &graph Graph to insert into
|
---|
| 77 | * \param *counter pointer to unique fragment count
|
---|
| 78 | * \param factor energy factor for the fragment
|
---|
[5621c3] | 79 | */
|
---|
[f66195] | 80 | void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment)
|
---|
[5621c3] | 81 | {
|
---|
[f66195] | 82 | GraphTestPair testGraphInsert;
|
---|
[14de469] | 83 |
|
---|
[f66195] | 84 | testGraphInsert = Fragment->Leaflet->insert(GraphPair (*Fragment->FragmentSet,pair<int,double>(Fragment->FragmentCounter,Fragment->TEFactor))); // store fragment number and current factor
|
---|
| 85 | if (testGraphInsert.second) {
|
---|
| 86 | *out << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " successfully inserted." << endl;
|
---|
| 87 | Fragment->FragmentCounter++;
|
---|
| 88 | } else {
|
---|
| 89 | *out << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first << endl;
|
---|
| 90 | ((*(testGraphInsert.first)).second).second += Fragment->TEFactor; // increase the "created" counter
|
---|
| 91 | *out << Verbose(2) << "New factor is " << ((*(testGraphInsert.first)).second).second << "." << endl;
|
---|
| 92 | }
|
---|
[5621c3] | 93 | };
|
---|
[f66195] | 94 | //void inline InsertIntoGraph(ofstream *out, KeyStack &stack, Graph &graph, int *counter, double factor)
|
---|
| 95 | //{
|
---|
| 96 | // // copy stack contents to set and call overloaded function again
|
---|
| 97 | // KeySet set;
|
---|
| 98 | // for(KeyStack::iterator runner = stack.begin(); runner != stack.begin(); runner++)
|
---|
| 99 | // set.insert((*runner));
|
---|
| 100 | // InsertIntoGraph(out, set, graph, counter, factor);
|
---|
| 101 | //};
|
---|
[5621c3] | 102 |
|
---|
[f66195] | 103 | /** Inserts each KeySet in \a graph2 into \a graph1.
|
---|
| 104 | * \param *out output stream for debugging
|
---|
| 105 | * \param graph1 first (dest) graph
|
---|
| 106 | * \param graph2 second (source) graph
|
---|
| 107 | * \param *counter keyset counter that gets increased
|
---|
[5621c3] | 108 | */
|
---|
[f66195] | 109 | void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter)
|
---|
[5621c3] | 110 | {
|
---|
[f66195] | 111 | GraphTestPair testGraphInsert;
|
---|
[5621c3] | 112 |
|
---|
[f66195] | 113 | for(Graph::iterator runner = graph2.begin(); runner != graph2.end(); runner++) {
|
---|
| 114 | testGraphInsert = graph1.insert(GraphPair ((*runner).first,pair<int,double>((*counter)++,((*runner).second).second))); // store fragment number and current factor
|
---|
| 115 | if (testGraphInsert.second) {
|
---|
| 116 | *out << Verbose(2) << "KeySet " << (*counter)-1 << " successfully inserted." << endl;
|
---|
| 117 | } else {
|
---|
| 118 | *out << Verbose(2) << "KeySet " << (*counter)-1 << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first << endl;
|
---|
| 119 | ((*(testGraphInsert.first)).second).second += (*runner).second.second;
|
---|
| 120 | *out << Verbose(2) << "New factor is " << (*(testGraphInsert.first)).second.second << "." << endl;
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
[5621c3] | 123 | };
|
---|
[14de469] | 124 |
|
---|