繁体   English   中英

python 中的模拟退火

[英]simulated annealing in python

我有一个名为 Cal_SINR 的 function 正在返回一个元组,我需要的是一个名为 current_SINR 的变量,我正在尝试应用模拟退火算法来仅接受比 current_SINR 更大的 SINR 值,但它有时返回的值小于当前和我不知道是什么问题。

这是模拟退火部分的代码:

temp = 100
min_temp = 1
cooling = 0.9
changes = 0
max_changes = 300
accepted_solutions = 0
while temp > min_temp:
     while changes < max_changes:
       new_state = Cal_SINR(random.randint(200,300) , random.randint(10,40))
       new_SINR = new_state[1]
       delta = new_SINR - Current_SINR
        if delta > 0:
          Current_SINR = new_SINR
          changes = changes +1
          accepted_solutions = accepted_solutions +1
       else:
        p = math.exp((delta*-1)/temp)     
        if random.random() < p:
            Current_SINR = new_SINR
            changes = changes +1
            accepted_solutions = accepted_solutions +1
        else:
            break

temp = temp * cooling

好吧,如果 delta < 0 你仍然有一个Current_SINR = new_SINR语句,它将以一定的概率执行,所以在这种情况下它会减少。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM