示例#1
0
 def test3_computed_flow(self):
   """
   Test 3 is based on
   http://en.wikipedia.org/wiki/Edmonds%E2%80%93Karp_algorithm#Example
   """
   mf.setup("test3.csv")
   mf.maxflow()
   self.assertEquals(mf.final_flow(), 5)
示例#2
0
 def test1_bfs_one_level(self):
   mf.setup("test1.csv")
   mf.maxflow(bfs_max_iterations=1)
   mf.db.execute("SELECT * FROM terminated_paths;")
   paths = mf.db.fetchall()
   self.assertEquals(len(paths), 2)
   self.assertIn(([1, 4], [1, 2, 4]), paths)
   self.assertIn(([2, 5], [1, 3, 4]), paths)
示例#3
0
 def test2_computed_flow(self):
   """
   Test 2 is based on
   http://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm#Integral_example
   """
   mf.setup("test2.csv")
   mf.maxflow()
   self.assertEquals(mf.final_flow(), 2000)
示例#4
0
 def test1_one_flow(self):
   mf.setup("test1.csv")
   mf.maxflow(flow_max_iterations=1)
   mf.final_flow()
   mf.db.execute("SELECT id FROM flow WHERE flow > 0;")
   flows = mf.db.fetchall()
   self.assertEquals(len(flows), 2)
   self.assertIn((1,), flows)
   self.assertIn((4,), flows)
示例#5
0
    def test4_max_flow_edges(self):
        mf.setup("test4.csv")
        mf.maxflow()
        mf.final_flow()
        mf.db.execute("SELECT flow FROM flow " "WHERE src = 7 AND dst = 8;")
        capacity1 = int(mf.db.fetchone()[0])
        self.assertEquals(capacity1, 10)

        mf.db.execute("SELECT flow FROM flow " "WHERE src = 4 AND dst = 8;")
        capacity2 = int(mf.db.fetchone()[0])
        self.assertEquals(capacity2, 10)
示例#6
0
  def test1_edge_flows(self):
    mf.setup("test1.csv")
    mf.maxflow()
    mf.final_flow()
    mf.db.execute("SELECT flow FROM flow ORDER BY id;")
    assigned_flows = mf.db.fetchall()
    expected_flows = [1, 1, 0, 1, 1]

    for i, f in enumerate(expected_flows):
      expected = assigned_flows[i][0]
      self.assertEquals(f, expected,
                        "Flow {}: expected:{} found:{}".format(i, f, expected))
  def test4_max_flow_edges(self):
    mf.setup("test4.csv")
    mf.maxflow()
    mf.final_flow()
    mf.db.execute("SELECT flow FROM flow "
                  "WHERE src = 7 AND dst = 8;")
    capacity1 = int(mf.db.fetchone()[0])
    self.assertEquals(capacity1, 10)

    mf.db.execute("SELECT flow FROM flow "
                  "WHERE src = 4 AND dst = 8;")
    capacity2 = int(mf.db.fetchone()[0])
    self.assertEquals(capacity2, 10)
示例#8
0
 def test1_computed_flow(self):
   mf.setup("test1.csv")
   mf.maxflow()
   self.assertEquals(mf.final_flow(), 2)
示例#9
0
 def test4_total_flow(self):
     mf.setup("test4.csv")
     mf.maxflow()
     self.assertEquals(mf.final_flow(), 20)
示例#10
0
 def test4_total_flow(self):
   mf.setup("test4.csv")
   mf.maxflow()
   self.assertEquals(mf.final_flow(), 20)
示例#11
0
 def test1_capacity_in_residual_graph(self):
   mf.setup("test1.csv")
   mf.maxflow()
   mf.db.execute("SELECT capacity FROM edge, flip_edge WHERE id=reverse_id AND forward_id=1")
   residual_flow = mf.db.fetchone()[0]
   self.assertEquals(residual_flow, 1)