当前位置:网站首页>4 a company has branches in six cities C1, C2, C3... C6. The connection between cities Ci and CJ (I, j=1,2,3,... 6) and the cost are listed in the following weighted adjacency matrix C
4 a company has branches in six cities C1, C2, C3... C6. The connection between cities Ci and CJ (I, j=1,2,3,... 6) and the cost are listed in the following weighted adjacency matrix C
2022-07-19 14:15:00 【Excited Xiao Fei】
python- Catalogue of mathematical modeling series articles
`
: The fifth chapter is 4 Little topic
List of articles
subject
4 A company is 6 Cities c1,c2,c3…c6 There are branches in , Known cities ci To cj(I,j=1,2,3,…6) The connection case and the cost are listed in the following weighted adjacency matrix C in .
C=[[0,50,-,40,25,10],
[50,0,15,20,-,25],
[-,15,0,10,20,-],
[40,20,10,0,10,25],
[25,-,20,10,0,55],
[10,25,-,25,55,0]]
- Express no straight path
(1) Judge whether the adjacency matrix is a directed or undirected graph ?
According to the formula ,ai j ={wij,(vi,vj) Belong to E,wij Is the weight
1,vi,vj adjacent
0 vi,vj Not adjacent ). Judge the symmetry of the matrix, which is an undirected weighted graph
(2) Draw the corresponding weighting graph ?

(3) Seeking from the city C1 set out , The minimum cost route and cost to other cities ?
analysis : This problem is the minimum path weight problem from the fixed point to the other points ,Dijkstra Algorithm
The code is as follows ( Example ):
from importlib.resources import path
import networkx as nx
import numpy as np
L=[(1,2,50),(1,4,40),(1,5,25),(1,6,10),
(2,3,15),(2,4,20),(2,6,25),
(3,4,10),(3,5,20),
(4,5,10),(4,6,25),
(5,6,55),]
G=nx.Graph()
G.add_weighted_edges_from(L)
path=nx.shortest_path(G,1,weight='weight')
cost=nx.shortest_path_length(G,1,weight='weight')
print('path:',path);print('cost:',cost)
for i in range(1,7):
print('c1 to c{} short length:'.format(i),path[i])
Calculated value
path: {1: [1], 2: [1, 6, 2], 4: [1, 6, 4], 5: [1, 5], 6: [1, 6], 3: [1, 5, 3]}
cost: {1: 0, 6: 10, 5: 25, 2: 35, 4: 35, 3: 45}
c1 to c1 short length: [1]
c1 to c2 short length: [1, 6, 2]
c1 to c3 short length: [1, 5, 3]
c1 to c4 short length: [1, 6, 4]
c1 to c5 short length: [1, 5]
c1 to c6 short length: [1, 6]
边栏推荐
- 暑期rhcsa培训第一天作业
- Analyze and hook sshd to hijack password
- [7.14] code source - [open box] [XOR inverse] [continuous subsequence] [trigonometric fruit count]
- 96. 不同的二叉搜索树
- [7.9] code source - [number selection] [sequence operation] [minimum or spanning tree]
- 【ACWing】2492. HH的项链
- JSON path syntax introduction and usage scenarios
- Luogu p2422 good feeling solution
- O'Neill's RPS curve compilation method (original by Dr. Tao)
- 华为无线设备配置智能漫游
猜你喜欢

【Acwing】第60场周赛 题解

96. Different binary search trees

ModuleNotFoundError: No module named ‘_distutils_hack‘

Tencent cloud object storage operation process

Interview with Android development companies, make these three preparations and plan yourself

Microservice calling component feign practice

Okaleido或杀出NFT重围,你看好它吗?

asterisk: rejected because extension not found in context ‘from-ipphone‘

华为无线设备配置频谱导航

FreeRTOS个人笔记-支持多优先级
随机推荐
跑通Caffe ResNet-50网络实现图片分类——基于华为云Ai1s
【Acwing】第60场周赛 题解
Silent AI: how does shengteng AI solve the problem of sign language learning with large models?
Okaleido或杀出NFT重围,你看好它吗?
asterisk: rejected because extension not found in context ‘from-ipphone‘
「技术播客月」Day 10: Meta Podcast: 聊聊播客这件事
Ranking of top ten ERP software systems at home and abroad!
Uniapp Gaode map positioning function
分析并HOOK SSHD来劫持密码
STL string replication comparison
Interview with Android development companies, make these three preparations and plan yourself
Tke mounts CFS across cloud networking
Notes with a face value of 10exp (303)
【ACWing】2492. HH Necklace
Robotics at Google:Laura Graesser | i-Sim2Real:在紧密的人机交互循环中强化学习机器人策略
华为无线设备配置用户CAC
[acwing] solution of the 60th weekly match
Google Earth engine - 1992 present mixed coordinate ocean model, water temperature and salinity (global ocean data set HYCOM)
Microservice calling component feign practice
Méthode de compilation de la courbe RPS d'O'Neill (originale par le Dr Tao)