bool SimulatedAnnealing::transitionAccepted(IBestSolutionManager& bestSolutionManager, ISolution& currentSolution, ISolution& newSolution, ALNS_Iteration_Status& status) { double temperature = coolingSchedule->getCurrentTemperature(); if(newSolution < currentSolution) { return true; } else { double difference = newSolution.getPenalizedObjectiveValue() - currentSolution.getPenalizedObjectiveValue(); double randomVal = static_cast<double>(rand())/static_cast<double>(RAND_MAX); return (exp(-1*difference/temperature)>randomVal); } }
ExponentialCoolingSchedule::ExponentialCoolingSchedule(ISolution& initSol, CoolingSchedule_Parameters& csParam) { // The fields are instantiated to default values. this->maximumIt = csParam.maxIt; this->currentIt = 0; this->currentThreshold = 0; this->nbThresholds = csParam.nbThresholds; this->decreasingFactor = csParam.expPercentageKept; this->runTime = csParam.maxRT; currentTemperature = (csParam.setupPercentage*initSol.getPenalizedObjectiveValue())/(-log(0.5)); }
MixLinearCoolingSchedule::MixLinearCoolingSchedule(ISolution& initSol, CoolingSchedule_Parameters& csParam) { startTemperature = (csParam.setupPercentage*initSol.getPenalizedObjectiveValue())/(-log(0.5)); runTime = csParam.maxRT; maxIt = csParam.maxIt; currentIt = 0; }