資源簡介
本資源為采用模擬退火算法解多元函數的極值問題。提供了暴力解法的代碼和模擬退火算法的代碼,通過對比可以發現模擬退火算法可以在時間上得到極大的提高。

代碼片段和文件信息
import?os
import?numpy?as?np
import?matplotlib.pyplot?as?plt
i?=?0
time?=?[]
fx?=?[]
x1?=?[]
x2?=?[]
x3?=?[]
x4?=?[]
with?open(‘out.txt‘?‘r‘)?as?file:
????context?=?file.read()
????context?=?context.split()
????for?i?in?range(len(context)):
????????if(i%6==0):
????????????time.append(int(context[i]))
????????if(i%6==1):
????????????fx.append(float(context[i]))
????????if(i%6==2):
????????????x1.append(float(context[i]))
????????if(i%6==3):
????????????x2.append(float(context[i]))
????????if(i%6==4):
????????????x3.append(float(context[i]))
????????if(i%6==5):
????????????x4.append(float(context[i]))
????????i?=?i?+?1
????????
#?數據清洗干凈,下面繪圖
plt.rcParams[‘font.sans-serif‘]=[‘SimHei‘]?#顯示中文標簽
plt.rcParams[‘axes.unicode_minus‘]=False
plt.plot(time?fx?marker?=?‘o‘?c?=?‘r‘?label?=?‘a=0.3‘)
plt.xlabel(‘迭代次數‘?fontsize?=?18)
plt.ylabel(‘目標函數F(x)‘?fontsize?=?18)
plt.xticks(fontsize?=?15)
plt.yticks(fontsize?=?15)
plt.savefig(“fx.svg“bbox_inches=‘tight‘)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????73186??2020-07-07?17:53??模擬退火算法解多元函數極值\.ipynb_checkpoints\繪圖-checkpoint.ipynb
?????文件???????1055??2020-07-07?16:38??模擬退火算法解多元函數極值\fx.py
?????文件??????35967??2020-07-07?18:10??模擬退火算法解多元函數極值\fx.svg
?????文件???????2074??2020-07-07?16:23??模擬退火算法解多元函數極值\out.txt
?????文件??????10373??2020-07-07?15:20??模擬退火算法解多元函數極值\out_t.txt
?????文件??????10943??2020-07-07?15:14??模擬退火算法解多元函數極值\out_temp.txt
?????文件??????36271??2020-07-07?17:54??模擬退火算法解多元函數極值\x1.svg
?????文件??????33682??2020-07-07?17:55??模擬退火算法解多元函數極值\x2.svg
?????文件??????36699??2020-07-07?17:56??模擬退火算法解多元函數極值\x3.svg
?????文件??????34509??2020-07-07?17:57??模擬退火算法解多元函數極值\x4.svg
?????文件???????1545??2020-07-07?12:29??模擬退火算法解多元函數極值\暴力解法.cpp
?????文件???????3602??2020-07-07?16:23??模擬退火算法解多元函數極值\模擬退火算法.cpp
?????文件??????72477??2020-07-07?17:57??模擬退火算法解多元函數極值\繪圖.ipynb
?????文件???????6864??2020-07-07?15:18??模擬退火算法解多元函數極值\問題.md
?????文件?????438503??2020-07-07?15:18??模擬退火算法解多元函數極值\問題.pdf
?????目錄??????????0??2020-07-07?14:42??模擬退火算法解多元函數極值\.ipynb_checkpoints
?????目錄??????????0??2020-07-07?18:12??模擬退火算法解多元函數極值
-----------?---------??----------?-----??----
???????????????797750????????????????????17
- 上一篇:WPE封包工具
- 下一篇:東華大學 Linux課程考試題庫 羅辛 完全版
評論
共有 條評論