00001 // 00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH) 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 00024 #include <iterator> 00025 #include <assert.h> 00026 00027 #include <omnetpp.h> 00028 00029 #include "GiaNeighborCandidateList.h" 00030 00031 00032 uint32_t GiaNeighborCandidateList::getSize() 00033 { 00034 return candidates.size(); 00035 } 00036 00037 void GiaNeighborCandidateList::add(const NodeHandle& node) 00038 { 00039 assert(!(node.isUnspecified())); 00040 candidates.insert( node ); 00041 } 00042 00043 void GiaNeighborCandidateList::remove(uint32_t position) 00044 { 00045 std::set<NodeHandle>::iterator it = candidates.begin(); 00046 for (uint32_t i=0; i<position; i++) { 00047 it++; 00048 } 00049 candidates.erase( it ); 00050 } 00051 00052 void GiaNeighborCandidateList::remove(const NodeHandle& node) 00053 { 00054 candidates.erase(node); 00055 } 00056 00057 bool GiaNeighborCandidateList::contains(const NodeHandle& node) 00058 { 00059 if(node.getKey().isUnspecified()) 00060 return false; 00061 00062 std::set<NodeHandle>::iterator it = candidates.find(node); 00063 00064 if(it != candidates.end() && it->getKey() == node.getKey()) 00065 return true; 00066 else 00067 return false; 00068 } 00069 00070 //bad code 00071 const NodeHandle& GiaNeighborCandidateList::get( uint32_t position ) 00072 { 00073 if ( position >= candidates.size() ) 00074 return NodeHandle::UNSPECIFIED_NODE; 00075 else { 00076 std::set<NodeHandle>::iterator it = candidates.begin(); 00077 for (uint32_t i=0; i<position; i++) { 00078 it++; 00079 } 00080 return *it; 00081 } 00082 } 00083 00084 const NodeHandle& GiaNeighborCandidateList::getRandomCandidate() 00085 { 00086 return get(intuniform(0, getSize())); 00087 } 00088 00089 // int GiaNeighborCandidateList::getPosition( NodeHandle node ) 00090 // { 00091 // if ( !contains(node) ) 00092 // return -1; 00093 // else 00094 // { 00095 // uint i = 0; 00096 // std::set<NodeHandle>::iterator theIterator; 00097 // for( theIterator = candidates.begin(); theIterator != candidates.end(); theIterator++ ) 00098 // { 00099 // if ( theIterator->key == node.getKey() ) 00100 // return i++; 00101 // } 00102 // } 00103 // return -1; 00104 // } 00105 00106 void GiaNeighborCandidateList::clear() 00107 { 00108 candidates.clear(); 00109 }