| 1 | < | #include <iostream> | 
| 2 | < | #include <stdlib.h> | 
| 1 | > | /* | 
| 2 | > | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 3 | > | * | 
| 4 | > | * The University of Notre Dame grants you ("Licensee") a | 
| 5 | > | * non-exclusive, royalty free, license to use, modify and | 
| 6 | > | * redistribute this software in source and binary code form, provided | 
| 7 | > | * that the following conditions are met: | 
| 8 | > | * | 
| 9 | > | * 1. Acknowledgement of the program authors must be made in any | 
| 10 | > | *    publication of scientific results based in part on use of the | 
| 11 | > | *    program.  An acceptable form of acknowledgement is citation of | 
| 12 | > | *    the article in which the program was described (Matthew | 
| 13 | > | *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 | > | *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 | > | *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 | > | *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 | > | * | 
| 18 | > | * 2. Redistributions of source code must retain the above copyright | 
| 19 | > | *    notice, this list of conditions and the following disclaimer. | 
| 20 | > | * | 
| 21 | > | * 3. Redistributions in binary form must reproduce the above copyright | 
| 22 | > | *    notice, this list of conditions and the following disclaimer in the | 
| 23 | > | *    documentation and/or other materials provided with the | 
| 24 | > | *    distribution. | 
| 25 | > | * | 
| 26 | > | * This software is provided "AS IS," without a warranty of any | 
| 27 | > | * kind. All express or implied conditions, representations and | 
| 28 | > | * warranties, including any implied warranty of merchantability, | 
| 29 | > | * fitness for a particular purpose or non-infringement, are hereby | 
| 30 | > | * excluded.  The University of Notre Dame and its licensors shall not | 
| 31 | > | * be liable for any damages suffered by licensee as a result of | 
| 32 | > | * using, modifying or distributing the software or its | 
| 33 | > | * derivatives. In no event will the University of Notre Dame or its | 
| 34 | > | * licensors be liable for any lost revenue, profit or data, or for | 
| 35 | > | * direct, indirect, special, consequential, incidental or punitive | 
| 36 | > | * damages, however caused and regardless of the theory of liability, | 
| 37 | > | * arising out of the use of or inability to use software, even if the | 
| 38 | > | * University of Notre Dame has been advised of the possibility of | 
| 39 | > | * such damages. | 
| 40 | > | */ | 
| 41 | > |  | 
| 42 | > | #include <functional> | 
| 43 | > | #include <iterator> | 
| 44 | > | #include <utility> | 
| 45 |  |  | 
| 46 |  | #include "brains/Exclude.hpp" | 
| 47 |  |  | 
| 48 | < | Exclude* Exclude::_instance = 0; | 
| 48 | > | namespace oopse { | 
| 49 |  |  | 
| 50 | < | Exclude* Exclude::Instance() { | 
| 51 | < | if (_instance == 0) { | 
| 52 | < | _instance = new Exclude; | 
| 50 | > | int *Exclude::getExcludeList() { | 
| 51 | > |  | 
| 52 | > | if (modified_) { | 
| 53 | > | excludeList_.clear(); | 
| 54 | > |  | 
| 55 | > | for (std::set<std::pair<int,int> >::iterator i = excludeSet_.begin();i != excludeSet_.end(); ++i) { | 
| 56 | > | excludeList_.push_back(i->first + 1); | 
| 57 | > | excludeList_.push_back(i->second + 1); | 
| 58 | > | } | 
| 59 | > | modified_ = false; | 
| 60 | > | } | 
| 61 | > |  | 
| 62 | > | return excludeList_.size() > 0 ? &(excludeList_[0]) : NULL; | 
| 63 |  | } | 
| 12 | – | return _instance; | 
| 13 | – | } | 
| 64 |  |  | 
| 65 | < | Exclude::Exclude(){ | 
| 16 | < | exPairs = NULL; | 
| 17 | < | newFortranArrayNeeded = 1; | 
| 18 | < | } | 
| 65 | > | void Exclude::addPair(int i, int j) { | 
| 66 |  |  | 
| 67 | < | Exclude::~Exclude() { | 
| 68 | < | if (exPairs != NULL) { | 
| 69 | < | delete[] exPairs; | 
| 67 | > | if (i == j) { | 
| 68 | > | return; | 
| 69 | > | } else if (i > j) { | 
| 70 | > | std::swap(i, j); | 
| 71 | > | } | 
| 72 | > |  | 
| 73 | > | std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j)); | 
| 74 | > |  | 
| 75 | > | if (iter == excludeSet_.end()) { | 
| 76 | > | excludeSet_.insert(std::make_pair(i, j)); | 
| 77 | > | modified_ = true; | 
| 78 | > | } | 
| 79 |  | } | 
| 80 | < | delete _instance; | 
| 80 | > |  | 
| 81 | > | void Exclude::addPairs(std::set<int>& set1, std::set<int>& set2) { | 
| 82 | > | for (std::set<int>::iterator iter1 = set1.begin(); iter1 !=  set1.end(); ++ iter1) { | 
| 83 | > | for(std::set<int>::iterator iter2 = set2.begin(); iter2 != set2.end(); ++ iter2) { | 
| 84 | > | this->addPair(*iter1, * iter2); | 
| 85 | > | } | 
| 86 | > | } | 
| 87 |  | } | 
| 26 | – |  | 
| 27 | – | int* Exclude::getFortranArray(){ | 
| 28 | – |  | 
| 29 | – | set<pair<int, int> >::iterator  i; | 
| 30 | – | int j; | 
| 88 |  |  | 
| 89 | < | if (newFortranArrayNeeded != 0) { | 
| 90 | < | delete[] exPairs; | 
| 91 | < | exPairs = new int[2*getSize()]; | 
| 92 | < | j = 0; | 
| 93 | < | for(i = excludeSet.begin(); i != excludeSet.end(); ++i) { | 
| 94 | < | exPairs[j] = (*i).first; | 
| 38 | < | j++; | 
| 39 | < | exPairs[j] = (*i).second; | 
| 40 | < | j++; | 
| 89 | > | template<typename IterType1, typename IterType2> | 
| 90 | > | void Exclude::addPairs(IterType1 iter1_first, IterType1 iter1_last, IterType2 iter2_first, IterType2 iter2_last) { | 
| 91 | > | for (IterType1 iter1 = iter1_first; iter1 != iter1_last; ++ iter1) { | 
| 92 | > | for(IterType2 iter2 = iter2_first; iter2 != iter2_last; ++ iter2) { | 
| 93 | > | this->addPair(*iter1, * iter2); | 
| 94 | > | } | 
| 95 |  | } | 
| 42 | – | newFortranArrayNeeded = 0; | 
| 43 | – | } | 
| 44 | – |  | 
| 45 | – | return exPairs; | 
| 96 |  | } | 
| 97 |  |  | 
| 98 | + | void Exclude::removePair(int i, int j) { | 
| 99 |  |  | 
| 100 | < | void Exclude::addPair(int i, int j) { | 
| 101 | < |  | 
| 102 | < | if (!hasPair(i, j)) { | 
| 103 | < |  | 
| 53 | < | if (i != j) { | 
| 54 | < |  | 
| 55 | < | if (i < j) | 
| 56 | < | excludeSet.insert(make_pair(i, j)); | 
| 57 | < | else | 
| 58 | < | excludeSet.insert(make_pair(j, i)); | 
| 100 | > | if (i == j) { | 
| 101 | > | return; | 
| 102 | > | } else if (i > j) { | 
| 103 | > | std::swap(i, j); | 
| 104 |  | } | 
| 105 |  |  | 
| 106 | < | newFortranArrayNeeded = 1; | 
| 106 | > |  | 
| 107 | > | std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j)); | 
| 108 | > |  | 
| 109 | > | if (iter != excludeSet_.end()) { | 
| 110 | > | excludeSet_.erase(iter); | 
| 111 | > | modified_ = true; | 
| 112 | > | } | 
| 113 |  | } | 
| 114 |  |  | 
| 115 | + | void Exclude::removePairs(std::set<int>& set1, std::set<int>& set2) { | 
| 116 | + | for (std::set<int>::iterator iter1 = set1.begin(); iter1 !=  set1.end(); ++ iter1) { | 
| 117 | + | for(std::set<int>::iterator iter2 = set2.begin(); iter2 != set2.end(); ++ iter2) { | 
| 118 | + | this->removePair(*iter1, * iter2); | 
| 119 | + | } | 
| 120 | + | } | 
| 121 |  | } | 
| 122 |  |  | 
| 123 | + | template<typename IterType1, typename IterType2> | 
| 124 | + | void Exclude::removePairs(IterType1 iter1_first, IterType1 iter1_last, IterType2 iter2_first, IterType2 iter2_last) { | 
| 125 | + | for (IterType1 iter1 = iter1_first; iter1 != iter1_last; ++ iter1) { | 
| 126 | + | for(IterType2 iter2 = iter2_first; iter2 != iter2_last; ++ iter2) { | 
| 127 | + | this->removePair(*iter1, * iter2); | 
| 128 | + | } | 
| 129 | + | } | 
| 130 | + | } | 
| 131 |  |  | 
| 132 | < | void Exclude::printMe( void ){ | 
| 132 | > | bool Exclude::hasPair(int i, int j) { | 
| 133 |  |  | 
| 134 | < | set<pair<int, int> >::iterator  i; | 
| 135 | < | int index; | 
| 136 | < |  | 
| 137 | < | index = 0; | 
| 138 | < | for(i = excludeSet.begin(); i != excludeSet.end(); ++i) { | 
| 134 | > | if (i == j) { | 
| 135 | > | return false; | 
| 136 | > | } else if (i > j) { | 
| 137 | > | std::swap(i, j); | 
| 138 | > | } | 
| 139 |  |  | 
| 140 | < | std::cerr << "exclude[" << index << "] i, j: " << (*i).first << " - " << (*i).second << "\n"; | 
| 141 | < | index++; | 
| 142 | < |  | 
| 78 | < | } | 
| 79 | < | } | 
| 140 | > | std::set<std::pair<int, int> >::iterator  iter = excludeSet_.find(std::make_pair(i, j)); | 
| 141 | > | return iter == excludeSet_.end() ? false : true; | 
| 142 | > | } | 
| 143 |  |  | 
| 144 | < | int Exclude::hasPair(int i, int j) { | 
| 144 | > | int Exclude::getSize() { | 
| 145 | > | return excludeSet_.size(); | 
| 146 | > | } | 
| 147 |  |  | 
| 148 | < | set<pair<int, int> >::iterator  position; | 
| 148 | > | std::ostream& operator <<(std::ostream& o, Exclude& e) { | 
| 149 | > | std::set<std::pair<int, int> >::iterator i; | 
| 150 |  |  | 
| 151 | < | if (i != j) { | 
| 86 | < | if (i < j) | 
| 87 | < | position = excludeSet.find(make_pair(i, j)); | 
| 88 | < | else | 
| 89 | < | position = excludeSet.find(make_pair(j, i)); | 
| 151 | > | int index; | 
| 152 |  |  | 
| 153 | < | if (position != excludeSet.end()) | 
| 92 | < | return 1; | 
| 93 | < | else | 
| 94 | < | return 0; | 
| 95 | < | } else | 
| 96 | < | return 0; | 
| 97 | < | } | 
| 153 | > | index = 0; | 
| 154 |  |  | 
| 155 | < | int Exclude::getSize() { | 
| 156 | < | return excludeSet.size(); | 
| 155 | > | for(i = e.excludeSet_.begin(); i != e.excludeSet_.end(); ++i) { | 
| 156 | > | o << "exclude[" << index << "] i, j: " << (*i).first << " - " | 
| 157 | > | << (*i).second << "\n"; | 
| 158 | > | index++; | 
| 159 | > | } | 
| 160 | > |  | 
| 161 | > | return o; | 
| 162 | > | } | 
| 163 | > |  | 
| 164 |  | } | 
| 165 | + |  | 
| 166 | + |  |