Netlogo simulated annealing

55 Views Asked by At

Good morning or Afternoon

I am here today as I have been trying to write my own simulated annealing algorithm regarding a species in Netlogo. The species I am trying to use an SA on has its own binary set which is a 16 digits binary set that is randomized from the start, each number in the set represents an action/enhancement, for example, the first placement in the 16 digit set is a + 2-speed enhancement. However I have been back and forth with this algorithm and have not had much luck, currently, I have set the temperature of the simulation to 10 and i have tried to decrease the temperature over time and even on each procedure, I am trying to find the optimal configuration of the species which I predict will be all 1s turned on but I want to actually see that happen.

What is happening though is the algorithm jumps straight to temperature 0, I can understand why that is but I don't know a better way to decrement the temperature over time. Also, I am trying to evaluate the fitness score and if it is better than the previous score then keep the better one but this has also been quite a problem.

I don't know whether this question or problem is understandable but if it is not please ask any questions which might help you understand my current issue.

Thanks

Nathan Don

This is what I have currently

  ask fish 810 [
    actions ; Actions have been defined where i have corresponded each value as an action 
    set color red
    set tempreture 10




set tempreture tempreture * (1 - cooling_rate / 100)

      if tempreture = 10 [
        set binary replace-item random 16 binary random 2
        ;set tempreture tempreture - 1
      ]
      if tempreture = 9 [
        set binary replace-item random 14 binary random 2
      ;set tempreture tempreture - 1
      ]
      if tempreture = 8 [
        set binary replace-item random 12 binary random 2
      ;set tempreture tempreture - 1
      ]
      if tempreture = 7 [
        set binary replace-item random 10 binary random 2
      ;set tempreture tempreture - 1
      ]
      if tempreture = 6 [
        set binary replace-item random 8 binary random 2
      ;set tempreture tempreture - 1
      ]
      if tempreture = 5 [
        set binary replace-item random 6 binary random 2
      ;set tempreture tempreture - 1
      ]
      if tempreture = 4 [
        set binary replace-item random 4 binary random 2
      ;set tempreture tempreture - 1
      ]
      if tempreture = 3 [
        set binary replace-item random 3 binary random 2
      ;set tempreture tempreture - 1
      ]
      if tempreture = 2 [
        set binary replace-item random 2 binary random 2
      ;set tempreture tempreture - 1
      ]
      if tempreture = 1 [
        set binary replace-item random 1 binary random 2
      ;set tempreture tempreture - 1
      ]
      if tempreture = 0 [
        Show fitness_score
      stop
      
    ]


    ]


  show tempreture

 ; tick


end```

1

There are 1 best solutions below

3
On

From what I see, it is simply a spelling error. You set temperature to 10 but in the rest of your code you are using tempreture.

Edit: Some more problems I found with the code:

  • You start with temperature at 10 and immediately let it decrease. That means that it would be impossible to ever fulfill the if tempreture = 10 condition

  • Every time the fish executes this procedure, tempreture is set back to 10. That means you will never reach the lower ones.

  • You let the temperature by a certain faction each time but the changes to your binary set only happen when temperature reaches a whole number. Maybe you want to trigger the condition when the milestone is passed, not just when it is reached exactly? Something along these lines would work for that

    let previous-tempreture tempreture
    
    set tempreture tempreture * (1 - cooling_rate / 100)
    
    if previous-tempreture > 10 and tempreture <= 10 [
      set binary replace-item random 16 binary random 2
    ]
    if previous-tempreture > 9 and tempreture <= 9 [
      set binary replace-item random 14 binary random 2
    ]