Calculation of the shortest network distance between arbitrary m sub-nodes of complex network

The content of this article comes from my python final assignment, and it is published in the hope that it can give some ideas for solving problems to those who need it


1. Problem description

insert image description here
The so-called "networks" are actually a collection of nodes and edges. If the node pair (i, j) corresponds to the same edge as (j, i), then the network is an undirected network, otherwise it is a directed network. If each edge is assigned a corresponding weight, then the network is a weighted network (weighted networks), otherwise it is an unweighted network (unweighted networks), as shown in Figure 2-1.

Figure 2-1 Examples of network types
insert image description here
(a) Unauthorized and undirected network (b) Weighted network (c) Unauthorized and directed network

If nodes are connected according to certain rules, the resulting network is called "regular network". If nodes connect edges in a completely random manner, the resulting networks are called "random networks". If nodes are connected according to a certain (self-)organization principle, it will evolve into various networks, which are called "complex networks".
There are three common ways to store images.

①Adjacency matrix, which is implemented by a two-dimensional array, G[u][v] is the weight of the <u, v> side. If it is not weighted, the weight can be regarded as 1.
insert image description here
insert image description here

②Adjacency list. In C/C++ competitions, vector G[MAXN_V] is generally used to simulate the structure of the adjacency list. The adjacency list is suitable for dense and dense graphs, which saves space compared to the adjacency matrix. The advantage is that it is quick to learn, high readability, and can be easily matched with STL in C++.
insert image description here

③Chained forward star, this is also the data structure I commonly use to save pictures in the C/C++ algorithm competition. My next program in python will use this data structure.
insert image description here

2. Ideas for answers

 After research and discussion, it was found that this is a Steiner tree , a combinatorial optimization problem. Similar to the minimum spanning tree, it is a kind of shortest network. The minimum spanning tree is to find the shortest network in a given set of points and edges to connect all points. And the Min Steiner tree allows to add extra points outside the given point, so that the shortest network overhead generated is minimal. That is to say, the nodes in the Min Steiner tree can use the nodes not in the network as "pedals" so that it is possible to obtain a shorter path required for connectivity. So the problem is to solve several Steiner trees.
First of all, we must know that the subgraph of the answer must be a tree, because if there is a ring in the answer, if any edge on the ring is deleted, the total connectivity cost will become smaller. Then let dp[i][s] represent a tree rooted at i, including the minimum cost of all points in the set S required in the title. For the specific state transition and algorithm flow chart, see 3 program flow and system design.
 Looking at the cases where m=2, 3, 4, 5, and 6, as m increases, the length of the shortest network distance will generally increase, and also That is, the cost of connecting m nodes has increased, but the running time each time is still very fast, and the result can be run out in almost less than 1 second. Of course, it is the premise that m network sub-nodes must be selected well. The reason should be due to the chain forward star storage method, the optimized dijkstra of the heap and the algorithm design of the minimum Steiner tree.

For the code of the answer, please refer to the P6192 [Template] Minimal Steiner Tree - Minimal Steiner Tree I wrote before .
But it's the C++ version. It's a bit incomplete to put the python version of the code up, because it needs to work with the input file in csv format. The complex network data entered is based on our campus.

I directly upload the file to CSDN, download it if you need it, the file is as follows↓
Attachment

Guess you like

Origin blog.csdn.net/qq_45732909/article/details/125106303