| 1 | gezelter | 2204 | /* | 
| 2 | gezelter | 1930 | * 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 | gezelter | 1490 |  | 
| 46 | tim | 1492 | #include "brains/Exclude.hpp" | 
| 47 | gezelter | 1490 |  | 
| 48 | gezelter | 1930 | namespace oopse { | 
| 49 | gezelter | 1490 |  | 
| 50 | gezelter | 2204 | int *Exclude::getExcludeList() { | 
| 51 | gezelter | 1490 |  | 
| 52 | gezelter | 1930 | if (modified_) { | 
| 53 | gezelter | 2204 | excludeList_.clear(); | 
| 54 | gezelter | 1490 |  | 
| 55 | gezelter | 2204 | 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 | gezelter | 1930 | } | 
| 61 |  |  |  | 
| 62 |  |  | return excludeList_.size() > 0 ? &(excludeList_[0]) : NULL; | 
| 63 | gezelter | 2204 | } | 
| 64 | gezelter | 1490 |  | 
| 65 | gezelter | 2204 | void Exclude::addPair(int i, int j) { | 
| 66 | gezelter | 1930 |  | 
| 67 |  |  | if (i == j) { | 
| 68 | gezelter | 2204 | return; | 
| 69 | gezelter | 1930 | } else if (i > j) { | 
| 70 | gezelter | 2204 | std::swap(i, j); | 
| 71 | gezelter | 1490 | } | 
| 72 | gezelter | 1930 |  | 
| 73 |  |  | std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j)); | 
| 74 |  |  |  | 
| 75 |  |  | if (iter == excludeSet_.end()) { | 
| 76 | gezelter | 2204 | excludeSet_.insert(std::make_pair(i, j)); | 
| 77 |  |  | modified_ = true; | 
| 78 | gezelter | 1930 | } | 
| 79 | gezelter | 2204 | } | 
| 80 | gezelter | 1490 |  | 
| 81 | gezelter | 2204 | void Exclude::removePair(int i, int j) { | 
| 82 | gezelter | 1490 |  | 
| 83 | gezelter | 1930 | if (i == j) { | 
| 84 | gezelter | 2204 | return; | 
| 85 | gezelter | 1930 | } else if (i > j) { | 
| 86 | gezelter | 2204 | std::swap(i, j); | 
| 87 | gezelter | 1490 | } | 
| 88 |  |  |  | 
| 89 |  |  |  | 
| 90 | gezelter | 1930 | std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j)); | 
| 91 |  |  |  | 
| 92 |  |  | if (iter != excludeSet_.end()) { | 
| 93 | gezelter | 2204 | excludeSet_.erase(iter); | 
| 94 |  |  | modified_ = true; | 
| 95 | gezelter | 1930 | } | 
| 96 | gezelter | 2204 | } | 
| 97 | gezelter | 1490 |  | 
| 98 | gezelter | 2204 | bool Exclude::hasPair(int i, int j) { | 
| 99 | gezelter | 1490 |  | 
| 100 | gezelter | 1930 | if (i == j) { | 
| 101 | gezelter | 2204 | return false; | 
| 102 | gezelter | 1930 | } else if (i > j) { | 
| 103 | gezelter | 2204 | std::swap(i, j); | 
| 104 | gezelter | 1930 | } | 
| 105 | gezelter | 1490 |  | 
| 106 | gezelter | 1930 | std::set<std::pair<int, int> >::iterator  iter = excludeSet_.find(std::make_pair(i, j)); | 
| 107 |  |  | return iter == excludeSet_.end() ? false : true; | 
| 108 | gezelter | 2204 | } | 
| 109 | gezelter | 1490 |  | 
| 110 | gezelter | 2204 | int Exclude::getSize() { | 
| 111 | gezelter | 1930 | return excludeSet_.size(); | 
| 112 | gezelter | 2204 | } | 
| 113 | gezelter | 1490 |  | 
| 114 | gezelter | 2204 | std::ostream& operator <<(std::ostream& o, Exclude& e) { | 
| 115 | gezelter | 1930 | std::set<std::pair<int, int> >::iterator i; | 
| 116 | gezelter | 1490 |  | 
| 117 | gezelter | 1930 | int index; | 
| 118 | gezelter | 1490 |  | 
| 119 | gezelter | 1930 | index = 0; | 
| 120 | gezelter | 1490 |  | 
| 121 | gezelter | 1930 | for(i = e.excludeSet_.begin(); i != e.excludeSet_.end(); ++i) { | 
| 122 | gezelter | 2204 | o << "exclude[" << index << "] i, j: " << (*i).first << " - " | 
| 123 |  |  | << (*i).second << "\n"; | 
| 124 |  |  | index++; | 
| 125 | gezelter | 1930 | } | 
| 126 |  |  |  | 
| 127 |  |  | return o; | 
| 128 | gezelter | 2204 | } | 
| 129 | gezelter | 1490 |  | 
| 130 |  |  | } | 
| 131 | gezelter | 1930 |  | 
| 132 |  |  |  |