sa.cpp

Go to the documentation of this file.
00001 // $Id: sa.cpp,v 1.7 2008/02/28 14:57:33 gottschling Exp $
00002 
00003 #include "angel/include/sa.hpp"
00004 
00005 #include <cmath>
00006 
00007 namespace angel {
00008 
00009   using namespace std;
00010   using namespace boost;
00011 
00012 // =====================================================
00013 // neighbourhoods
00014 // =====================================================
00015 
00016 void neighbor_swap (const std::vector<int>& old_seq, std::vector<int>& seq) {
00017   seq= old_seq;
00018   int size= old_seq.size();
00019   // assert (size > 1); // otherwise endless loop
00020   THROW_DEBUG_EXCEPT_MACRO (size <= 1, consistency_exception, "Nothing to swap -> endless loop"); 
00021 
00022   size_t r1= angel::random (size);
00023   size_t r2= angel::random (size);
00024   while (r2 == r1) r2= angel::random (size); // should be different
00025   std::swap (seq[r1], seq[r2]); 
00026 }
00027 
00028 } // namespace angel
00029 

Generated on Wed Mar 11 10:33:11 2009 for angel by  doxygen 1.5.3