知識
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!
數(shù)學模型作業(yè)(3)
發(fā)表時間:2020-10-16
發(fā)布人:葵宇科技
瀏覽次數(shù):117
- 數(shù)學模型作業(yè)(2)中計算歐式距離有誤,已更改。
- 內(nèi)容(代碼)接數(shù)學模型作業(yè)(2)
- 初學python和數(shù)學模型,不足之處請大佬指出。
- 給個贊(上次已經(jīng)騙過關注了~~~)
- 2020-10-19更新:解決Gurobi:from gurobipy import used; unable to detect undefined names 問題
- 導入相關參數(shù)
shape = 613
alpha1 = 25
alpha2 = 15
beta1 = 20
beta2 = 25
theta = 30
delta = 0.001
- 建立 List 格式的垂直校正點集合 V 和水平校正點集合 H,保存在一個 txt文件中。
# 建立垂直校正點集合V和水平校正點集合H
V = []
H = []
VH = []
for i in range(0, shape):
if prop[i] == 1:
V.append(i)
if prop[i] == 0:
H.append(i)
VH = V + H
file = open('校正點集合.txt', 'w')
for i in range(len(VH)):
s = str(VH[i]) + '\n'
file.write(s)
file.close()
- 用 python 輸出減少邊之后最短路模型的鄰接矩陣,存放在excel 文件中。
- 分析:
(1) 剪枝可以剪去任意點為起點到垂直校正點不符合垂直校正條件的枝
(2)剪枝可以剪去任意點為起點到水平校正點不符合水平校正條件的枝
(3) 剪枝可以剪去以B點為終點,距離超過 θ / δ \theta/\delta θ/δ的枝 - 安裝gurobi,參考另一篇(Gurobi9.0.3安裝)
- 將距離矩陣dist轉換為tupledict類型,用dict_dist存放鄰接矩陣(要調(diào)用gurobi庫:from gurobipy import *)
# 將距離矩陣dist轉換為tupledict類型,用dict_dist存放鄰接矩陣
dict_dist = {}
for i in range(shape):
for j in range(shape):
dict_dist[i, j] = dist[i][j]
dict_dist = tupledict(dict_dist)
- 剪枝實現(xiàn)
# step1:剪去到垂直校正點不符合要求的邊
for i in range(1, shape-1):
for j in V:
if dist[i][j] > min(alpha1, alpha2) / delta:
dict_dist[i, j] = 0
# step2:剪去到水平校正點不符合要求的邊
for i in range(1, shape-1):
for j in H:
if dist[i][j] > min(beta1, beta2) / delta:
dict_dist[i, j] = 0
# step3:剪去距離終點B超過30000m的邊
for i in range(shape-1):
if dist[i][shape-1] > theta / delta:
dict_dist[i, shape-1] = 0
# 定義邊集
edge = []
for i in range(shape):
for j in range(shape):
if dict_dist[i, j] != 0:
edge.append((i, j))
print("剪枝之后的邊數(shù):", len(edge))
- 鄰接矩陣存入excel表格
# 將 剪枝后的鄰接矩陣寫入到 dict_dist_save.xlsx 中
dict_dist_save = np.zeros(shape=(shape, shape))
for i in range(shape):
for j in range(shape):
dict_dist_save[i][j] = dict_dist[i, j]
dict_dist_save = pd.DataFrame(dict_dist_save)
writer = pd.ExcelWriter('dict_dist.xlsx')
dict_dist_save.to_excel(writer, 'sheet1')
writer.save()
- 結果
相關案例查看更多
相關閱讀
- 云南做網(wǎng)站
- web開發(fā)
- 模版消息
- 二叉樹
- 網(wǎng)絡公司電話
- 云南小程序開發(fā)報價
- 百度小程序
- 微信分銷
- 云南微信小程序開發(fā)
- 云南網(wǎng)站制作哪家好
- 云南小程序開發(fā)制作
- 昆明網(wǎng)站設計
- 小程序開發(fā)聯(lián)系方式
- 云南網(wǎng)站建設公司地址
- 云南小程序被騙
- 大理小程序開發(fā)
- python開發(fā)小程序
- 北京小程序開發(fā)
- 云南軟件開發(fā)
- 人人商城
- 云南網(wǎng)站建設哪家強
- 網(wǎng)站收錄
- 關鍵詞快速排名
- 云南網(wǎng)站建設首選
- 紅河小程序開發(fā)
- 生成海報
- 云南小程序設計
- 昆明軟件公司
- 報廢車拆解系統(tǒng)
- 百度小程序公司