1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

組合せ最適化 - 典型問題 - 最大安定集合問題

Last updated at Posted at 2015-07-10

典型問題と実行方法
##最大安定集合問題
無向グラフ$G=(V, E)$において、重みの和が最大の安定集合(互いに隣接していない節点の集合)を求めよ。

##実行方法

usage
Signature: maximum_stable_set(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_stable_set
tbn = pd.read_csv('data/node0.csv')
tbe = pd.read_csv('data/edge0.csv')
g = graph_from_table(tbn, tbe)[0]
t = maximum_stable_set(g)
pos = networkx_draw(g, node_color='white')
nx.draw_networkx_nodes(g, pos, nodelist=t[1])
plt.show()
print(t)
結果
(5.0, [1, 4])

mss2.png

python
# pandas.DataFrame
from ortoolpy.optimization import MaximumStableSet
MaximumStableSet('data/node0.csv','data/edge0.csv')
id x y demand weight
1 1 5 8 1 3
4 4 2 2 1 2
python
# 乱数データ
import networkx as nx, matplotlib.pyplot as plt
from ortoolpy import networkx_draw, maximum_stable_set
g = nx.random_graphs.fast_gnp_random_graph(10, 0.3, 1)
t = maximum_stable_set(g)
pos = networkx_draw(g, nx.spring_layout(g), node_color='white')
nx.draw_networkx_nodes(g, pos, nodelist=t[1])
plt.show()

mss.png

##データ

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?