| [7b6b21f] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2012 University of Bonn. All rights reserved. | 
|---|
| [5aaa43] | 5 | * Copyright (C)  2013 Frederik Heber. All rights reserved. | 
|---|
| [7b6b21f] | 6 | * Please see the COPYING file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 7 | * | 
|---|
|  | 8 | * | 
|---|
|  | 9 | *   This file is part of MoleCuilder. | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *    MoleCuilder is free software: you can redistribute it and/or modify | 
|---|
|  | 12 | *    it under the terms of the GNU General Public License as published by | 
|---|
|  | 13 | *    the Free Software Foundation, either version 2 of the License, or | 
|---|
|  | 14 | *    (at your option) any later version. | 
|---|
|  | 15 | * | 
|---|
|  | 16 | *    MoleCuilder is distributed in the hope that it will be useful, | 
|---|
|  | 17 | *    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 18 | *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
|  | 19 | *    GNU General Public License for more details. | 
|---|
|  | 20 | * | 
|---|
|  | 21 | *    You should have received a copy of the GNU General Public License | 
|---|
|  | 22 | *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
|  | 23 | */ | 
|---|
|  | 24 |  | 
|---|
|  | 25 | /* | 
|---|
|  | 26 | * HomologyGraph.cpp | 
|---|
|  | 27 | * | 
|---|
|  | 28 | *  Created on: Sep 24, 2012 | 
|---|
|  | 29 | *      Author: heber | 
|---|
|  | 30 | */ | 
|---|
|  | 31 |  | 
|---|
|  | 32 |  | 
|---|
|  | 33 | // include config.h | 
|---|
|  | 34 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 35 | #include <config.h> | 
|---|
|  | 36 | #endif | 
|---|
|  | 37 |  | 
|---|
| [67db80] | 38 | // include headers that implement a archive in simple text format | 
|---|
|  | 39 | // otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect | 
|---|
|  | 40 | #include <boost/archive/text_oarchive.hpp> | 
|---|
|  | 41 | #include <boost/archive/text_iarchive.hpp> | 
|---|
|  | 42 |  | 
|---|
| [9eb71b3] | 43 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| [7b6b21f] | 44 |  | 
|---|
|  | 45 | #include "HomologyGraph.hpp" | 
|---|
|  | 46 |  | 
|---|
| [54a561] | 47 | #include <iostream> | 
|---|
| [77b350] | 48 |  | 
|---|
|  | 49 | HomologyGraph::HomologyGraph(const KeySet &keyset) : | 
|---|
|  | 50 | nodes(detail::getNodesFromKeySet(keyset)), | 
|---|
|  | 51 | edges(detail::getEdgesFromKeySet(keyset)) | 
|---|
|  | 52 | {} | 
|---|
|  | 53 |  | 
|---|
| [372c912] | 54 | HomologyGraph::HomologyGraph(const IndexSet &index) : | 
|---|
|  | 55 | nodes(detail::getNodesFromIndexSet(index)), | 
|---|
|  | 56 | edges(detail::getEdgesFromIndexSet(index)) | 
|---|
|  | 57 | {} | 
|---|
|  | 58 |  | 
|---|
| [7b6b21f] | 59 | bool HomologyGraph::operator<(const HomologyGraph &graph) const | 
|---|
|  | 60 | { | 
|---|
|  | 61 | if (nodes < graph.nodes) { | 
|---|
|  | 62 | return true; | 
|---|
|  | 63 | } else if (nodes > graph.nodes) { | 
|---|
|  | 64 | return false; | 
|---|
|  | 65 | } else { | 
|---|
|  | 66 | if (edges < graph.edges) | 
|---|
|  | 67 | return true; | 
|---|
|  | 68 | else | 
|---|
|  | 69 | return false; | 
|---|
|  | 70 | } | 
|---|
|  | 71 | } | 
|---|
|  | 72 |  | 
|---|
|  | 73 | bool HomologyGraph::operator>(const HomologyGraph &graph) const | 
|---|
|  | 74 | { | 
|---|
|  | 75 | if (nodes > graph.nodes) { | 
|---|
|  | 76 | return true; | 
|---|
|  | 77 | } else if (nodes < graph.nodes) { | 
|---|
|  | 78 | return false; | 
|---|
|  | 79 | } else { | 
|---|
|  | 80 | if (edges > graph.edges) | 
|---|
|  | 81 | return true; | 
|---|
|  | 82 | else | 
|---|
|  | 83 | return false; | 
|---|
|  | 84 | } | 
|---|
|  | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 | bool HomologyGraph::operator==(const HomologyGraph &graph) const | 
|---|
|  | 88 | { | 
|---|
|  | 89 | if (nodes != graph.nodes) { | 
|---|
|  | 90 | return false; | 
|---|
|  | 91 | } else { | 
|---|
|  | 92 | return (edges == graph.edges); | 
|---|
|  | 93 | } | 
|---|
|  | 94 | } | 
|---|
|  | 95 |  | 
|---|
|  | 96 | HomologyGraph& HomologyGraph::operator=(const HomologyGraph &graph) | 
|---|
|  | 97 | { | 
|---|
|  | 98 | // self-assignment check | 
|---|
|  | 99 | if (this != &graph) { | 
|---|
|  | 100 | const_cast<nodes_t &>(nodes) = graph.nodes; | 
|---|
|  | 101 | const_cast<edges_t &>(edges) = graph.edges; | 
|---|
|  | 102 | } | 
|---|
|  | 103 | return *this; | 
|---|
|  | 104 | } | 
|---|
| [54a561] | 105 |  | 
|---|
| [e920d3d] | 106 | bool HomologyGraph::hasTimesAtomicNumber(const size_t _number, const size_t _times) const | 
|---|
|  | 107 | { | 
|---|
|  | 108 | size_t count = 0; | 
|---|
|  | 109 | for (nodes_t::const_iterator iter = nodes.begin(); iter != nodes.end(); ++iter) { | 
|---|
|  | 110 | if ((iter->first).getAtomicNumber() == _number) | 
|---|
|  | 111 | count += iter->second; | 
|---|
|  | 112 | } | 
|---|
|  | 113 | return (count == _times); | 
|---|
|  | 114 | } | 
|---|
|  | 115 |  | 
|---|
| [7c1091] | 116 | bool HomologyGraph::hasGreaterEqualTimesAtomicNumber(const size_t _number, const size_t _times) const | 
|---|
|  | 117 | { | 
|---|
|  | 118 | size_t count = 0; | 
|---|
|  | 119 | for (nodes_t::const_iterator iter = nodes.begin(); iter != nodes.end(); ++iter) { | 
|---|
|  | 120 | if ((iter->first).getAtomicNumber() == _number) | 
|---|
|  | 121 | count += iter->second; | 
|---|
|  | 122 | } | 
|---|
|  | 123 | return (count >= _times); | 
|---|
|  | 124 | } | 
|---|
|  | 125 |  | 
|---|
| [0afe00] | 126 | void HomologyGraph::printNodes(std::ostream& ost) const | 
|---|
| [54a561] | 127 | { | 
|---|
| [0afe00] | 128 | for (nodes_t::const_iterator nodeiter = nodes.begin(); | 
|---|
|  | 129 | nodeiter != nodes.end(); | 
|---|
| [f7ce2b] | 130 | ++nodeiter) { | 
|---|
| [0afe00] | 131 | if ( nodeiter != nodes.begin()) | 
|---|
| [f7ce2b] | 132 | ost << ", "; | 
|---|
|  | 133 | ost << nodeiter->second << "x " << nodeiter->first; | 
|---|
|  | 134 | } | 
|---|
| [0afe00] | 135 | } | 
|---|
|  | 136 |  | 
|---|
|  | 137 | void HomologyGraph::printEdges(std::ostream& ost) const | 
|---|
|  | 138 | { | 
|---|
|  | 139 | for (edges_t::const_iterator edgeiter = edges.begin(); | 
|---|
|  | 140 | edgeiter != edges.end(); | 
|---|
| [f7ce2b] | 141 | ++edgeiter) { | 
|---|
| [0afe00] | 142 | if ( edgeiter != edges.begin()) | 
|---|
| [f7ce2b] | 143 | ost << ", "; | 
|---|
|  | 144 | ost << edgeiter->second << "x " << edgeiter->first; | 
|---|
|  | 145 | } | 
|---|
| [0afe00] | 146 | } | 
|---|
|  | 147 |  | 
|---|
|  | 148 | std::ostream& operator<<(std::ostream& ost, const HomologyGraph &graph) | 
|---|
|  | 149 | { | 
|---|
|  | 150 | graph.printNodes(ost); | 
|---|
|  | 151 | graph.printEdges(ost); | 
|---|
| [54a561] | 152 | return ost; | 
|---|
|  | 153 | } | 
|---|
|  | 154 |  | 
|---|
| [a2a2f7] | 155 | // | 
|---|
|  | 156 | //// we need to explicitly instantiate the serialization functions | 
|---|
|  | 157 | //BOOST_CLASS_EXPORT_IMPLEMENT(HomologyGraph) | 
|---|