11
14

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 5 years have passed since last update.

็ต„ๅˆใ›ๆœ€้ฉๅŒ– - ๅ…ธๅž‹ๅ•้กŒ - ๆœ€ๅฐ่ฒป็”จๆตๅ•้กŒ

11
Last updated at Posted at 2015-07-10

ๅ…ธๅž‹ๅ•้กŒใจๅฎŸ่กŒๆ–นๆณ•

ๆœ€ๅฐ่ฒป็”จๆตๅ•้กŒ

ๆœ‰ๅ‘ใ‚ฐใƒฉใƒ•$G=(V,E)$ใซใŠใ„ใฆใ€ๅ„่พบใฎๅฎน้‡ใจ้‡ใฟใ•ใ‚‰ใซ็ฏ€็‚นใฎ้œ€่ฆ้‡ใŒไธŽใˆใ‚‰ใ‚ŒใŸใจใใ€ๅ„่พบใฎๅฎน้‡ใ‚’่ถ…้Žใ›ใšใซๅ„่พบใฎๆต้‡ใซๅฏพใ™ใ‚‹้‡ใฟใฎ็ทๅ’ŒใŒๆœ€ๅฐใจใชใ‚‹ใƒ•ใƒญใƒผใ‚’ๆฑ‚ใ‚ใ‚ˆใ€‚

  • ๅ„็ฏ€็‚นใซใŠใ„ใฆใ€ใ€Œๆตๅ…ฅ้‡ - ๆตๅ‡บ้‡ใ€ใฏใ€้œ€่ฆ้‡ใจ็ญ‰ใ—ใ„ใ€‚
  • ้œ€่ฆ้‡ใŒ่ฒ ใฎๅ ดๅˆใ€ไพ›็ตฆ้‡ใ‚’่กจใ™ใ€‚
  • ๅ…จใฆใฎ็ฏ€็‚นใฎ้œ€่ฆ้‡ใฎๅ’Œใฏ0ใงใชใ‘ใ‚Œใฐใ„ใ‘ใชใ„ใ€‚

ๅฎŸ่กŒๆ–นๆณ•

usage
Signature: nx.min_cost_flow(G, demand='demand', capacity='capacity', weight='weight')
Docstring:
Return a minimum cost flow satisfying all demands in digraph G.

G is a digraph with edge costs and capacities and in which nodes
have demand, i.e., they want to send or receive some amount of
flow. A negative demand means that the node wants to send flow, a
positive demand means that the node want to receive flow. A flow on
the digraph G satisfies all demand if the net flow into each node
is equal to the demand of that node.
python
# CSVใƒ‡ใƒผใ‚ฟ
import pandas as pd, networkx as nx
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, directed=True)[0]
result = nx.min_cost_flow(g)
for i, d in result.items():
    for j, f in d.items():
        if f: print((i, j), f)
็ตๆžœ
(0, 1) 1
(0, 3) 1
(0, 4) 2
(4, 5) 1
python
# pandas.DataFrame
from ortoolpy.optimization import MinCostFlow
MinCostFlow('data/node0.csv','data/edge0.csv')
node1 node2 capacity weight flow
0 0 1 2 1 1
1 0 3 2 2 1
2 0 4 2 2 2
3 4 5 2 1 1
python
# ไนฑๆ•ฐใƒ‡ใƒผใ‚ฟ
import networkx as nx
g = nx.fast_gnp_random_graph(8, 0.2, 1, True)
g.nodes[1]['demand'] = -2 # ไพ›็ตฆ
g.nodes[7]['demand'] = 2 # ้œ€่ฆ
g.adj[2][7]['capacity'] = 1 # ๅฎน้‡
result = nx.min_cost_flow(g)
for i, d in result.items():
    for j, f in d.items():
        if f: print((i, j), f)
็ตๆžœ
(1, 2) 2
(2, 3) 1
(2, 7) 1
(3, 7) 1

ใƒ‡ใƒผใ‚ฟ

11
14
1

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
11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?