2

More than 3 years have passed since last update.

# 組合せ最適化 - 典型問題 - 最大カット問題

Last updated at Posted at 2015-07-10

## 実行方法

usage
Signature: maximum_cut(g, weight='weight')
Docstring:

g: グラフ(node:weight)
weight: 重みの属性文字

カットの重みの合計と片方の頂点番号リスト

python
# CSVデータ
import pandas as pd, networkx as nx, matplotlib.pyplot as plt
from ortoolpy import graph_from_table, networkx_draw, maximum_cut
g = graph_from_table(tbn, tbe)[0]
t = maximum_cut(g)
pos = networkx_draw(g, node_color='white')
nx.draw_networkx_nodes(g, pos, nodelist=t[1])
plt.show()
print(t)


(27.0, [2, 4, 5])


python
# pandas.DataFrame
from ortoolpy.optimization import MaximumCut
MaximumCut('data/node0.csv','data/edge0.csv')[1]

id x y demand weight
2 2 10 5 0 1
4 4 2 2 1 2
5 5 0 5 1 1
python
# 乱数データ
import networkx as nx, matplotlib.pyplot as plt
from ortoolpy import networkx_draw
g = nx.random_graphs.fast_gnp_random_graph(10, 0.3, 4)
for i, j in g.edges():
t = maximum_cut(g)
pos = networkx_draw(g, nx.spring_layout(g), node_color='white')
nx.draw_networkx_nodes(g, pos, nodelist=t[1])
plt.show()


## データ

Register as a new user and use Qiita more conveniently

1. You get articles that match your needs
2. You can efficiently read back useful information
3. You can use dark theme
What you can do with signing up
2