欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

數(shù)學模型作業(yè)(3) - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設/小程序開發(fā)/軟件開發(fā)

知識

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!

您當前位置>首頁 » 新聞資訊 » 技術分享 >

數(shù)學模型作業(yè)(3)

發(fā)表時間:2020-10-16

發(fā)布人:葵宇科技

瀏覽次數(shù):117

  1. 數(shù)學模型作業(yè)(2)中計算歐式距離有誤,已更改。
  2. 內(nèi)容(代碼)接數(shù)學模型作業(yè)(2)
  3. 初學python和數(shù)學模型,不足之處請大佬指出。
  4. 給個贊(上次已經(jīng)騙過關注了~~~)
  5. 2020-10-19更新:解決Gurobi:from gurobipy import used; unable to detect undefined names 問題
  1. 導入相關參數(shù)
shape = 613
alpha1 = 25
alpha2 = 15
beta1 = 20
beta2 = 25
theta = 30
delta = 0.001
  1. 建立 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()
  1. 用 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()
  1. 結果
    在這里插入圖片描述在這里插入圖片描述

相關案例查看更多