### Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

## Simulated Annealing in C#

The simulated annealing is a metaheuristic, a random search algorithm inspired from physics sciences. In this example, we will doing a simple thing : adjusting one coefficent for having a better results for the algorithm to found the global minimum of the function :

f(X)=0.11(0.5 X² + Cos[Pi X] - 2 Sin[2 Pi X] + Cos[3 Pi X]*Sin[Pi X] in [-5; 5].

1

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

// {...}

// COEF is the Most important value to adjust.

// energy = COEF x myFunction(x)

// Change this value until having a quality results for Simulated Annealing.

COEF = 1; // <- Try with 1, 10, 100, 1000.....

// After running the playground :

// When ct0 =~ ct1 or ct2 =~ ct3, its a bad adjustement.

// A possible good situation is when ct2 =~ 2 x ct1 and ct3 =~ K x ct2 where K depends of number of local optimum.

// The number of simulations is now fixed to 200.

// Next time we will see how to change for better precisions.

// {...}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Suggested playgrounds

Open Source Your Knowledge: become a Contributor and help others learn.
Create New Content