20 #include "vnl/vnl_random.h"
21 #include "vnl/vnl_math.h"
24 : m_Permutation( nullptr )
35 if( costAfter <= costBefore )
41 vnl_random rng( (
unsigned int) rand() );
44 const double threshold = rng.drand64( 0.0 , 1.0);
47 double likelihood = std::exp( - ( costAfter - costBefore ) / temperature );
49 if( threshold < likelihood )
59 m_Permutation = permutation;
67 if( m_Permutation.IsNull() )
69 MBI_ERROR <<
"Trying to run simulated annealing on empty permutation.";
73 if( !m_Permutation->HasCostFunction() )
75 MBI_ERROR <<
"Trying to run simulated annealing on empty cost function.";
80 m_Permutation->Initialize();
83 for(
double currentTemperature( temperature );
84 currentTemperature > 0.00001;
85 currentTemperature = currentTemperature / stepSize )
88 m_Permutation->Permutate( currentTemperature );
93 m_Permutation->CleanUp();
itk::SmartPointer< Self > Pointer
void SetPermutation(mitk::ConnectomicsSimulatedAnnealingPermutationBase::Pointer permutation)
ConnectomicsSimulatedAnnealingManager()
~ConnectomicsSimulatedAnnealingManager()
void RunSimulatedAnnealing(double temperature, double stepSize)
bool AcceptChange(double costBefore, double costAfter, double temperature)