Source

pplp / benchmark / test_costflow.py

from graph import Graph
from costflow import costflow, costflow_cvxopt

def test_basic():
    g = Graph()
    g.add_arc(1, -1)
    g.add_arc(2, -1)
    g.add_arc(1, -1)
    g.add_node([2], [0])
    g.add_node([0], [1])
    g.add_node([1], [2])
    assert costflow(g) == -3
    assert costflow_cvxopt(g) == -3 

def test_simple1():
    g = Graph()    
    g.add_arc(1, 0)
    g.add_arc(1, 0)
    g.add_arc(1, -1)
    g.add_arc(1, -1)
    g.add_arc(10, 0)
    g.add_node([4], [0, 1])
    g.add_node([0], [2])
    g.add_node([1], [3])
    g.add_node([2, 3], [4])
    assert costflow(g) == -2
    assert costflow_cvxopt(g) == -2
    from cPickle import dump
    dump(g, open('graph.pi', 'w'), -1)