From 2ccb0234f1a94aacd5dabd75453b0ffd0226e56e Mon Sep 17 00:00:00 2001 From: Edward Date: Tue, 3 Mar 2015 16:44:25 -0800 Subject: [PATCH 1/2] push for merge --- test_graph.py | 72 ++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/test_graph.py b/test_graph.py index 7a5b5a3..feeebd2 100644 --- a/test_graph.py +++ b/test_graph.py @@ -257,45 +257,47 @@ def test_find_paths(): assert g.get_path_weight(['a','b','c']) == 2 assert g.find_shortest_path('a', 'c') == (['a', 'c'], 1) -# def test_real_short(): -# g = Graph() -# g.add_node('a') -# g.add_edge('a', 'b', 9) -# g.add_edge('a', 'e', 3) -# g.add_edge('b', 'c', 6) -# g.add_edge('b', 'e', 9000) -# g.add_edge('c', 'd', 6) -# g.add_edge('e', 'c', 5) -# g.add_edge('e', 'd', 1) -# g.add_edge('e', 'f', 3) -# g.add_edge('f', 'a', 8) - -# print g.find_paths('a','d',[],[]) -# assert g.find_shortest_path('a', 'd') == (['a', 'e', 'd'], 4) - - -# def test_real_long(): -# g = Graph() -# g.add_node('a') -# g.add_edge('a', 'b', 1) -# g.add_edge('a', 'e', 9000) -# g.add_edge('b', 'c', 1) -# g.add_edge('c', 'e', 1) -# g.add_edge('c', 'd', 6) -# g.add_edge('e', 'd', 3) -# g.add_edge('e', 'f', 1) -# g.add_edge('f', 'd', 1) +def test_real_short(): + g = Graph() + g.add_node('a') + g.add_edge('a', 'b', 9) + g.add_edge('a', 'e', 3) + g.add_edge('b', 'c', 6) + g.add_edge('b', 'e', 9000) + g.add_edge('c', 'd', 6) + g.add_edge('e', 'c', 5) + g.add_edge('e', 'd', 1) + g.add_edge('e', 'f', 3) + g.add_edge('f', 'a', 8) -# assert g.find_shortest_path('a', 'd') == (['a', 'b', 'c', 'e', 'f', 'd'], 5) + print g.find_paths('a','d',[],[]) + assert g.find_shortest_path('a', 'd') == (['a', 'e', 'd'], 4) -def test_short(): + +def test_real_long(): g = Graph() + g.add_node('a') g.add_edge('a', 'b', 1) - g.add_edge('b', 'd', 1) - g.add_edge('a', 'c', 1) - g.add_edge('c', 'd', 3) - g.add_edge('d', 'e', 1) - assert g.find_shortest_path('a', 'e') == (['a','b','d','e'], 3) + g.add_edge('a', 'e', 9000) + g.add_edge('b', 'c', 1) + g.add_edge('c', 'e', 1) + g.add_edge('c', 'd', 6) + g.add_edge('e', 'd', 3) + g.add_edge('e', 'f', 1) + g.add_edge('f', 'd', 1) + + assert g.find_shortest_path('a', 'd') == (['a', 'b', 'c', 'e', 'f', 'd'], 5) + +# def test_short(): +# g = Graph() +# g.add_edge('a', 'b', 10000) +# g.add_edge('b', 'd', 1) +# g.add_edge('a', 'c', 1) +# g.add_edge('c', 'd', 2) +# g.add_edge('c', 'e', 1) +# g.add_edge('e', 'd', 2) +# g.add_edge('a', 'd', 3) +# assert g.find_shortest_path('a', 'd') == (['a','b','d'], 2) From 99fa57e5bda00c0adb3e662ed9dfb9f4df760ceb Mon Sep 17 00:00:00 2001 From: Matthew Lee Date: Tue, 3 Mar 2015 22:44:21 -0800 Subject: [PATCH 2/2] Added something to readme. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 303f968..322db94 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,7 @@ Code Fellows Dev Accelerator: This repository will be for implementations of cla parens.py: -Includes a function balanceness() that takes string and determines if it is 'open', 'balanced', or 'broken', depending on the sequence of parenthesis contained. 'Open', 'balanced', and 'broken' are respectively determined as more leading '('s than ')'s, equal number of leading '(' and ')', and any sequence including ')' that do not have a preceding '('. 'Open' strings are represented by returning a 1, 'balanced' by 0, and 'broken' by -1, with an emptry string being considered 'balanced'. \ No newline at end of file +Includes a function balanceness() that takes string and determines if it is 'open', 'balanced', or 'broken', depending on the sequence of parenthesis contained. 'Open', 'balanced', and 'broken' are respectively determined as more leading '('s than ')'s, equal number of leading '(' and ')', and any sequence including ')' that do not have a preceding '('. 'Open' strings are represented by returning a 1, 'balanced' by 0, and 'broken' by -1, with an emptry string being considered 'balanced'. + +Shortest-path algorithms: +Making a decision regarding which algorithm to use to implement finding the 'shortest-path' between two vertices in a graph will probably be motivated by the nature of the use. For problems where edges represent either a cost, difficulty or some other deterrent of 'traveling' from one node to another, location or some state, then Djikstra's algorithm or some other which simply minimize the total weight of a single path, will do just fine. However, if perhaps you are interested in knowing the 'shortest-path' between all points, then perhaps the Floyd-Warshall would be more appropriate, or if speed of determination of path was important, than maybe yet another algorithm would be more appropriate. \ No newline at end of file