| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2012 University of Bonn. All rights reserved. | 
|---|
| 5 | * Copyright (C)  2013 Frederik Heber. All rights reserved. | 
|---|
| 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 |  | 
|---|
| 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 |  | 
|---|
| 43 | //#include "CodePatterns/MemDebug.hpp" | 
|---|
| 44 |  | 
|---|
| 45 | #include "HomologyGraph.hpp" | 
|---|
| 46 |  | 
|---|
| 47 | #include <iostream> | 
|---|
| 48 |  | 
|---|
| 49 | HomologyGraph::HomologyGraph(const KeySet &keyset) : | 
|---|
| 50 | nodes(detail::getNodesFromKeySet(keyset)), | 
|---|
| 51 | edges(detail::getEdgesFromKeySet(keyset)) | 
|---|
| 52 | {} | 
|---|
| 53 |  | 
|---|
| 54 | HomologyGraph::HomologyGraph(const IndexSet &index) : | 
|---|
| 55 | nodes(detail::getNodesFromIndexSet(index)), | 
|---|
| 56 | edges(detail::getEdgesFromIndexSet(index)) | 
|---|
| 57 | {} | 
|---|
| 58 |  | 
|---|
| 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 | } | 
|---|
| 105 |  | 
|---|
| 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 |  | 
|---|
| 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 |  | 
|---|
| 126 | void HomologyGraph::printNodes(std::ostream& ost) const | 
|---|
| 127 | { | 
|---|
| 128 | for (nodes_t::const_iterator nodeiter = nodes.begin(); | 
|---|
| 129 | nodeiter != nodes.end(); | 
|---|
| 130 | ++nodeiter) { | 
|---|
| 131 | if ( nodeiter != nodes.begin()) | 
|---|
| 132 | ost << ", "; | 
|---|
| 133 | ost << nodeiter->second << "x " << nodeiter->first; | 
|---|
| 134 | } | 
|---|
| 135 | } | 
|---|
| 136 |  | 
|---|
| 137 | void HomologyGraph::printEdges(std::ostream& ost) const | 
|---|
| 138 | { | 
|---|
| 139 | for (edges_t::const_iterator edgeiter = edges.begin(); | 
|---|
| 140 | edgeiter != edges.end(); | 
|---|
| 141 | ++edgeiter) { | 
|---|
| 142 | if ( edgeiter != edges.begin()) | 
|---|
| 143 | ost << ", "; | 
|---|
| 144 | ost << edgeiter->second << "x " << edgeiter->first; | 
|---|
| 145 | } | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | std::ostream& operator<<(std::ostream& ost, const HomologyGraph &graph) | 
|---|
| 149 | { | 
|---|
| 150 | graph.printNodes(ost); | 
|---|
| 151 | graph.printEdges(ost); | 
|---|
| 152 | return ost; | 
|---|
| 153 | } | 
|---|
| 154 |  | 
|---|
| 155 | // | 
|---|
| 156 | //// we need to explicitly instantiate the serialization functions | 
|---|
| 157 | //BOOST_CLASS_EXPORT_IMPLEMENT(HomologyGraph) | 
|---|