angel  mercurial changeset:
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 #############################################################
00004 # This file is part of angel released under the BSD license #
00005 # The full COPYRIGHT notice can be found in the top         #
00006 # level directory of the angel distribution                 #
00007 #############################################################
00008 */
00009 
00010 
00011 #include "angel/include/sa.hpp"
00012 
00013 #include <cmath>
00014 
00015 namespace angel {
00016 
00017   using namespace std;
00018   using namespace boost;
00019 
00020 // =====================================================
00021 // neighbourhoods
00022 // =====================================================
00023 
00024 void neighbor_swap (const std::vector<int>& old_seq, std::vector<int>& seq) {
00025   seq= old_seq;
00026   int size= old_seq.size();
00027   // assert (size > 1); // otherwise endless loop
00028   THROW_DEBUG_EXCEPT_MACRO (size <= 1, consistency_exception, "Nothing to swap -> endless loop"); 
00029 
00030   size_t r1= angel::random (size);
00031   size_t r2= angel::random (size);
00032   while (r2 == r1) r2= angel::random (size); // should be different
00033   std::swap (seq[r1], seq[r2]); 
00034 }
00035 
00036 } // namespace angel
00037 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines