[PYTHON] Kombinationsoptimierung - typisches Problem - Minimum des Gesamtflächenbaumproblems

Typisches Problem und Ausführungsmethode

Minimales Problem mit dem gesamten Flächenbaum

Wenn das Gewicht der Seite $ e $ im ungerichteten Graphen $ G = (V, E) $ $ w (e) $ ist, ist die Summe der Gewichte der Seite auf dem gesamten Baum $ T = (V, E_T) $ $ Suchen Sie den gesamten Baum, der \ sum_ {e \ in E_T} {w (e)} $ minimiert.

Ausführungsmethode

usage


Signature: nx.minimum_spanning_tree(G, weight='weight')
Docstring:
Return a minimum spanning tree or forest of an undirected
weighted graph.

A minimum spanning tree is a subgraph of the graph (a tree) with
the minimum sum of edge weights.

python


#CSV-Daten
import pandas as pd, networkx as nx, matplotlib.pyplot as plt
from ortoolpy import graph_from_table, networkx_draw
tbn = pd.read_csv('data/node0.csv')
tbe = pd.read_csv('data/edge0.csv')
g = graph_from_table(tbn, tbe)[0]
t = nx.minimum_spanning_tree(g)
pos = networkx_draw(g)
nx.draw_networkx_edges(t, pos, width=3)
plt.show()
print(t.edges())

Ergebnis


[(0, 1), (0, 3), (0, 4), (2, 3), (4, 5)]

mst2.png

python


# pandas.DataFrame
from ortoolpy.optimization import MinimumSpanningTree
MinimumSpanningTree('data/edge0.csv')
node1 node2 capacity weight
0 0 1 2 1
1 0 3 2 2
2 0 4 2 2
3 2 3 2 3
4 4 5 2 1

python


#Zufällige Daten
import math, networkx as nx, matplotlib.pyplot as plt
from ortoolpy import networkx_draw
g = nx.random_graphs.fast_gnp_random_graph(10, 0.3, 1)
pos = nx.spring_layout(g)
for i, j in g.edges():
    g.adj[i][j]['weight'] = math.sqrt(sum((pos[i] - pos[j])**2))
t = nx.minimum_spanning_tree(g)
pos = networkx_draw(g, nx.spring_layout(g))
nx.draw_networkx_edges(t, pos, width=3)
plt.show()

mst.png

Daten

Recommended Posts

Kombinationsoptimierung - typisches Problem - Minimum des Gesamtflächenbaumproblems
Kombinationsoptimierung - typisches Problem - Mindestkostenflussproblem
Kombinationsoptimierung - typisches Problem-Rucksack-Problem
Kombinationsoptimierung - typisches Problem - n-dimensionales Packungsproblem
Kombinationsoptimierungstypisches Problem-Minimum-Vertex-Covering-Problem
Kombinationsoptimierung - typisches problemstabiles Matching-Problem
Kombinationsoptimierungstypisches Problem-verallgemeinertes Zuordnungsproblem
Kombinationsoptimierung - typisches Problem beim Packen von Problembehältern
Kombinationsoptimierung - typisches Problem - Maximum-Matching-Problem
Kombinationsoptimierung - typisches Problem - sekundäres Zuordnungsproblem
Kombinationsoptimierung - typisches Problem - Problem mit dem kürzesten Weg
Kombinationsoptimierung - typisches Problem - Kombinationsauktionsproblem
Kombinationsoptimierung - typisches Problem - Maximum-Flow-Problem
Kombinationsoptimierungstypisches Problem-Aggregat-Abdeckungsproblem
Kombinationsoptimierung - typisches Problem-Gewichtsanpassungsproblem
Kombinationsoptimierung - typisches Problem bei der Platzierung von Problemeinrichtungen
Kombinationsoptimierung - typisches Problem-Job-Shop-Problem
Kombinationsoptimierung - typisches Problem - maximales Schnittproblem
Kombinationsoptimierung - typisches Problem - Rundschreiben Verkäufer Problem
Kombinationsoptimierung - typisches Problem bei der Planung der Problemarbeit
Kombinationsoptimierungstypisches Problem-Maximum-Stabil-Set-Problem
Kombinationsoptimierung - typisches Problem - Problem der chinesischen Postzustellung
Kombinationsoptimierung - Typisches Problem - Problem bei der Platzierung der Einrichtung ohne Kapazitätsbeschränkung
Kombinationsoptimierung - Minimum Cut Problem
Minimaler Gesamtflächenbaum in C #