File tree Expand file tree Collapse file tree 18 files changed +452
-0
lines changed Expand file tree Collapse file tree 18 files changed +452
-0
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,4 @@ quick_sort_project/programming_question2.py
42
42
quick_sort_project /solution.txt
43
43
quick_sort_project /test.txt
44
44
quick_sort_project /__pycache__
45
+ min_cut_project /min_cut.py
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ """
2
+ File : run.py
3
+ Author : Drew Verlee
4
+ Date : 16.07.13.
5
+ Email : drew.verlee@gmail.com
6
+ GitHub : https://github.com/Midnightcoffee/
7
+ Description : putting it all together
8
+ """
9
+
10
+ from tools import lowest , file_to_graph
11
+ from min_cut import min_cut
12
+ from copy import deepcopy
13
+
14
+ def main (afile ):
15
+ """ takes afile argument"""
16
+ G = file_to_graph (afile )
17
+ return min ([min_cut (deepcopy (G )) for x in range (100 )])
18
+
19
+
20
+ if __name__ == '__main__' :
21
+ print (main ('kargerMinCut.txt' ))
Original file line number Diff line number Diff line change
1
+ file contains a list rep of a undirected graph
2
+ 200 vertices labled 1 to 200
3
+ v neighbors
4
+ 6 7 9 ...
5
+
6
+ run the randombized contradction algorithm for the min cut problem to compute
7
+ the min cut.
8
+
9
+ HINT!: figure out an implementation of the edge ontracitions.
10
+
11
+
12
+
13
+ cut into two parts
14
+ undirected
15
+ set a set b
16
+ edge --- edge
17
+ edge --- edge
18
+
19
+ so above we have two cuts
20
+
21
+
22
+ directed
23
+ set a set b
24
+ edge ---> edge
25
+ edge --- edge
26
+ now one cut
27
+
28
+
29
+ min cut: fewest number of crossing edges. allow parallel edges - ---
30
+
31
+
32
+ random contraction algorithm:
33
+ random sampling,
34
+
35
+
36
+ input: undirected graph G = (v, e)
37
+ parelle edges allowed
38
+
39
+ return compute a cut wit the fewest number of crossing edges (a min cut)
40
+
41
+ while there are more than 2 vertices:
42
+ pick a remaining edge (u, v) uniformaly at randombized
43
+ merge (or "contract") u and v into a single vertex
44
+ remove self-loops
45
+ return at represented by final 2 vertices
46
+
47
+ items:
48
+ have need
49
+ file need graph
50
+ want a graph like {v :set([n, n]}
51
+
52
+ then
53
+ graph min cut?
54
+
55
+
56
+ tools needed
57
+ file_to_graph
58
+
Original file line number Diff line number Diff line change
1
+ 1 2 3 4 7
2
+ 2 1 3 4
3
+ 3 1 2 4
4
+ 4 1 2 3 5
5
+ 5 4 6 7 8
6
+ 6 5 7 8
7
+ 7 1 5 6 8
8
+ 8 5 6 7
Original file line number Diff line number Diff line change
1
+ 1 2 3
2
+ 2 1 3 4
3
+ 3 1 2 4
4
+ 4 2 3
Original file line number Diff line number Diff line change
1
+ """
2
+ File : test_main.py
3
+ Author : Drew Verlee
4
+ Date : 16.07.13.
5
+ Email : drew.verlee@gmail.com
6
+ GitHub : https://github.com/Midnightcoffee/
7
+ Description : TODO add description
8
+ """
9
+
10
+ import unittest
11
+ from min_cut_project .run import main
12
+
13
+ class TestMain (unittest .TestCase ):
14
+ """main tests"""
15
+
16
+
17
+ def test_one (self ):
18
+ expected = 2
19
+ result = main ('one.txt' )
20
+ self .assertEqual (expected , result )
21
+
22
+ def test_two (self ):
23
+ expected = 2
24
+ result = main ('two.txt' )
25
+ self .assertEqual (expected , result )
26
+
27
+ def test_three (self ):
28
+ expected = 1
29
+ result = main ('three.txt' )
30
+ self .assertEqual (expected , result )
31
+
32
+ if __name__ == '__main__' :
33
+ unittest .main ()
Original file line number Diff line number Diff line change
1
+ """
2
+ File : test_min_cut.py
3
+ Author : Drew Verlee
4
+ Date : 16.07.13.
5
+ Email : drew.verlee@gmail.com
6
+ GitHub : https://github.com/Midnightcoffee/
7
+ Description : test min cut
8
+ """
9
+
10
+ import unittest
11
+ from min_cut_project .min_cut import min_cut
12
+ from min_cut_project .tools import file_to_graph
13
+
14
+ class TestMinCut (unittest .TestCase ):
15
+ """try to find the mind cut"""
16
+
17
+ def setUp (self ):
18
+ a_file = 'test_data.txt'
19
+ self .G = file_to_graph (a_file )
20
+
21
+ def test_small_data (self ):
22
+ expected = [2 , 3 ]
23
+ returned = min_cut (self .G )
24
+ self .assertIn (returned , expected )
25
+
26
+ if __name__ == '__main__' :
27
+ unittest .main ()
You can’t perform that action at this time.
0 commit comments