Main.Assignment3 History
Hide minor edits - Show changes to output
Changed lines 24-27 from:
To retrieve command-line arguments inside a python program import the @@sys@@ module, and use the @@sys.argv@@ variable. See details [[http://effbot.org/librarybook/sys.htm| here]].
to:
Comments:
* Running your program should bring up a window with the visualization of the tiling.
* Your program should randomly choose the position in the board that is supposed to be blank. Use Python's @@random@@ module for that.
* To retrieve command-line arguments inside a python program import the @@sys@@ module, and use the @@sys.argv@@ variable. See details [[http://effbot.org/librarybook/sys.htm| here]].
* Running your program should bring up a window with the visualization of the tiling.
* Your program should randomly choose the position in the board that is supposed to be blank. Use Python's @@random@@ module for that.
* To retrieve command-line arguments inside a python program import the @@sys@@ module, and use the @@sys.argv@@ variable. See details [[http://effbot.org/librarybook/sys.htm| here]].
Changed line 24 from:
To retrieve command-line arguments inside a python program import the @@sys@ module, and use the @@sys.argv@@ variable. See details [[http://effbot.org/librarybook/sys.htm| here]].
to:
To retrieve command-line arguments inside a python program import the @@sys@@ module, and use the @@sys.argv@@ variable. See details [[http://effbot.org/librarybook/sys.htm| here]].
Added lines 24-25:
To retrieve command-line arguments inside a python program import the @@sys@ module, and use the @@sys.argv@@ variable. See details [[http://effbot.org/librarybook/sys.htm| here]].
Changed line 28 from:
A solution which does not follow the inductive proof, will not be accepted.
to:
A solution which does not follow the inductive proof, will not be accepted.
Changed lines 16-17 from:
Correctness of your program will be verified visually: you need to produce a visualization of the tiling produced by your program. We suggest one of two options for producing the image - [[http://matplotlib.org | matplotlib]], which is a plotting library for python, and [[http://wiki.python.org/moin/TkInter | tkinter]], which is the standard Python GUI package. With matplotlib, you may find the [[http://matplotlib.org/api/artist_api.html?highlight=polygon#matplotlib.patches.Polygon | polygon]] command useful (here are some [[http://matplotlib.org/examples/pylab_examples/hatch_demo.html | examples]]). If you decide to use tkinter, here are some starting points: [[Canvas tutorial | http://effbot.org/tkinterbook/canvas.htm]], and [[http://zetcode.com/gui/tkinter/drawing/|another one]].
to:
Correctness of your program will be verified visually: you need to produce a visualization of the tiling produced by your program. We suggest one of two options for producing the image - [[http://matplotlib.org | matplotlib]], which is a plotting library for python, and [[http://wiki.python.org/moin/TkInter | tkinter]], which is the standard Python GUI package. With matplotlib, you may find the [[http://matplotlib.org/api/artist_api.html?highlight=polygon#matplotlib.patches.Polygon | polygon]] command useful (here are some [[http://matplotlib.org/examples/pylab_examples/hatch_demo.html | examples]]). If you decide to use tkinter, here are some starting points: [[ http://effbot.org/tkinterbook/canvas.htm | Canvas tutorial]], and [[http://zetcode.com/gui/tkinter/drawing/|another one]].
Changed line 26 from:
A solution which does not follow the inductive proof, will not be accepted.
to:
A solution which does not follow the inductive proof, will not be accepted.
Changed line 19 from:
(:source lang=shell:)
to:
(:source lang=bash:)
Changed line 9 from:
And here's an example for an 8x8 board:
to:
And here's an example of a solution for an 8x8 board:
Changed lines 14-18 from:
(:source lang=python:)
import math
math.atan2(y / x
to:
There is a nice [[http://www3.amherst.edu/~nstarr/trom/puzzle-8by8/ | tromino applet]] that can help you.
Correctness of your program will be verified visually: you need to produce a visualization of the tiling produced by your program. We suggest one of two options for producing the image - [[http://matplotlib.org | matplotlib]], which is a plotting library for python, and [[http://wiki.python.org/moin/TkInter | tkinter]], which is the standard Python GUI package. With matplotlib, you may find the [[http://matplotlib.org/api/artist_api.html?highlight=polygon#matplotlib.patches.Polygon | polygon]] command useful (here are some [[http://matplotlib.org/examples/pylab_examples/hatch_demo.html | examples]]). If you decide to use tkinter, here are some starting points: [[Canvas tutorial | http://effbot.org/tkinterbook/canvas.htm]], and [[http://zetcode.com/gui/tkinter/drawing/|another one]].
Submit your code as a single python program called @@HW3.py@@, which will be executed as:
(:source lang=shell:)
python HW3.py 3
Correctness of your program will be verified visually: you need to produce a visualization of the tiling produced by your program. We suggest one of two options for producing the image - [[http://matplotlib.org | matplotlib]], which is a plotting library for python, and [[http://wiki.python.org/moin/TkInter | tkinter]], which is the standard Python GUI package. With matplotlib, you may find the [[http://matplotlib.org/api/artist_api.html?highlight=polygon#matplotlib.patches.Polygon | polygon]] command useful (here are some [[http://matplotlib.org/examples/pylab_examples/hatch_demo.html | examples]]). If you decide to use tkinter, here are some starting points: [[Canvas tutorial | http://effbot.org/tkinterbook/canvas.htm]], and [[http://zetcode.com/gui/tkinter/drawing/|another one]].
Submit your code as a single python program called @@HW3.py@@, which will be executed as:
(:source lang=shell:)
python HW3.py 3
Changed lines 22-81 from:
You may use Python's built in sorted() or list.sort() methods which are described in full detail at:
http://wiki.python.org/moin/HowTo/Sorting
Here are some python code snippets to help you develop your code.
To create a list of num_points random points in two dimensions:
(:source lang=python:)
from random import uniform
points = [(uniform(0,1), uniform(0,1)) for i in range(num_points)]
(:sourceend:)
you can plot the points using the matplotlib plotting library (it is installed on department linux machines):
(:source lang=python:)
x = [point[0] for point in points]
y = [point[1] for point in points]
from matplotlib import pylab
pylab.plot(x, y, 'ob')
# depending on the platform you use you may need to tell
# matplotlib to show the figure:
pylab.show()
(:sourceend:)
Now suppose that you grouped together the points that belong to a given octagon, and its x and y coordinates are given by lists called oct_x and oct_y then you can display the octagon using:
(:source lang=python:)
oct_x.append(oct_x[0])
oct_y.append(oct_y[0])
pylab.plot(oct_x, oct_y, '-k')
(:sourceend:)
!!!Implementation details:
We should be able to run your code, given in a file HW3.py as:
(:source lang=python:)
python HW3.py input_file output_file
(:sourceend:)
where input_file is a comma-delimited file with two columns containing the input data points:
(:source lang=python:)
x1,y1
x2,y2
x3,y3
...
xn,yn
(:sourceend:)
and output_file is the output file which specifies the octagons in comma delimited format. Each line in the file indicates which data points belong to an octagon. A line
p1,p2,p3,p4,p5,p6,p7,p8
indicates the indices of the data points in the input file (0-based indexing).
At the top of your program put a comment that describes your algorithm and provides an analysis of its running time. The running time of your algorithm should be ''O(n log n)''.
to:
for an 8x8 board.
Changed line 26 from:
to:
A solution which does not follow the inductive proof, will not be accepted.
Changed lines 3-18 from:
!!!Due: April 2nd at 5pm. Extended until 4/6 at 5pm.
!!!The octagon problem
You are given a set of ''n'' points in two dimensions (i.e. each point has two coordinates x, and y), where ''n'' is a multiple of 8.
Your task is to draw a set of octagons through these points, where no two octagons share a point or intersect, and the sides of each octagon do not intersect as well.
For simplicity assume each point has coordinates between 0 and 1.
Solve this problem using a divide and conquer approach.
We propose you use a two stage approach: first choose how to divide the n points into octagons, so that they won't intersect, and a second stage which decides the order in which the points in an octagon need to be joined together such that no two sides of the octagon intersect.
For the second stage, here is a simple solution that you can use:
Pick the lowest point of the set (smallest x coordinate). If there are ties, pick the rightmost. Set that point as the origin and sort the remaining points w.r.t their polar angles.
The polar angle of a point (x,y) is given by:
!!!The octagon problem
You are given a set of ''
Your task is to draw a set of octagons through these points, where no two octagons share a point or intersect, and the sides of each octagon do not intersect as well.
For simplicity assume each point has coordinates between 0 and 1
Solve this problem using a divide and conquer approach.
We propose you use a two stage approach: first choose how to divide the n points into octagons, so that they won't intersect, and a second stage which decides the order in which the points in an octagon need to be joined together such that no two sides of the octagon intersect.
For the second stage, here is a simple solution that you can use:
Pick the lowest point of the set (smallest x coordinate). If there are ties, pick the rightmost. Set that point as the origin and sort the remaining points w.r.t their polar angles.
The polar angle of a point (x,y) is given by:
to:
!!!Due: October 24th at 5pm.
!!!Tiling with Trominos
Solve the following problem: tile a chessboard of size 2^n x 2^n with one square missing with L-shaped [[http://en.wikipedia.org/wiki/Tromino | trominos]]. Here's how a tromino looks like: http://nrich.maths.org/content/id/7026/trisquare.png
And here's an example for an 8x8 board:
http://www3.amherst.edu/~nstarr/trom/v-21.gif
There is a simple [[http://www.cut-the-knot.org/Curriculum/Geometry/Tromino.shtml | proof by induction]] that this is possible.
This proof can be easily translated into a divide and conquer algorithm for solving the problem.
!!!Tiling with Trominos
Solve the following problem: tile a chessboard of size 2^n x 2^n with one square missing with L-shaped [[http://en.wikipedia.org/wiki/Tromino | trominos]]. Here's how a tromino looks like: http://nrich.maths.org/content/id/7026/trisquare.png
And here's an example for an 8x8 board:
http://www3.amherst.edu/~nstarr/trom/v-21.gif
There is a simple [[http://www.cut-the-knot.org/Curriculum/Geometry/Tromino.shtml | proof by induction]] that this is possible.
This proof can be easily translated into a divide and conquer algorithm for solving the problem.
Changed line 81 from:
Simply dividing the points into octagons along a fixed direction is a valid solution, but as discussed in class, we are looking for a more creative solution! And it needs to be a divide-and-conquer algorithm.
to:
Simply dividing the points into octagons along a fixed direction is a valid solution, but as discussed in class, we are looking for a more creative solution! And it needs to be a divide-and-conquer algorithm.
Changed lines 3-4 from:
!!!Due: April 2nd at 5pm.
to:
!!!Due: April 2nd at 5pm. Extended until 4/6 at 5pm.
Added lines 83-85:
!!!Note:
Simply dividing the points into octagons along a fixed direction is a valid solution, but as discussed in class, we are looking for a more creative solution! And it needs to be a divide-and-conquer algorithm.
Simply dividing the points into octagons along a fixed direction is a valid solution, but as discussed in class, we are looking for a more creative solution! And it needs to be a divide-and-conquer algorithm.
Changed lines 44-45 from:
# depending on the platform you use you may need to tell matplotlib to
# show the figure:
to:
# depending on the platform you use you may need to tell
# matplotlib to show the figure:
# matplotlib to show the figure:
Added lines 44-46:
# depending on the platform you use you may need to tell matplotlib to
# show the figure:
pylab.show()
# show the figure:
pylab.show()
Changed line 8 from:
Your task is to draw a set of octagons through these points, where no to octagons share a point or intersect, and the sides of each octagon do not intersect as well.
to:
Your task is to draw a set of octagons through these points, where no two octagons share a point or intersect, and the sides of each octagon do not intersect as well.
Changed line 78 from:
At the top of your program put a comment that describes your algorithm and provides an analysis of its running time. You algorithm should be ''O(log n)''.
to:
At the top of your program put a comment that describes your algorithm and provides an analysis of its running time. The running time of your algorithm should be ''O(n log n)''.
Changed lines 3-4 from:
!!!Due: Apriil 2nd at 5pm.
to:
!!!Due: April 2nd at 5pm.
Changed line 59 from:
python HW2.py input_file output_file
to:
python HW3.py input_file output_file
Added lines 77-78:
At the top of your program put a comment that describes your algorithm and provides an analysis of its running time. You algorithm should be ''O(log n)''.
Changed line 7 from:
You are given a set of '''n''' points in two dimensions (i.e. each point has two coordinates x, and y), where '''n''' is a multiple of 8.
to:
You are given a set of ''n'' points in two dimensions (i.e. each point has two coordinates x, and y), where ''n'' is a multiple of 8.
Added line 64:
(:source lang=python:)
Added line 70:
(:sourceend:)
Changed lines 1-8 from:
!!Programming Assignment 3 - Dijkstra's algorithm
!!!Due: March 21st at 5pm.
In this assignment you will program Dijkstra's shortest path algorithm. Your implementation should use a heap-based priority queue to prioritize the order of processing unexplored nodes inthe graph; on a given graph with n nodes and m edges, the running time of your implementation of Dijkstra's algorithm should be O(m log n). We will look at the code to verify that your implementation satisfies this bound. So, as before, you can't use Python dictionaries in your graph class, except during reading the graph from the input file.
Your code should be structured as a single python file called @@HW3.py@@. We will call to test your code as:
Your code should be structured as a single python file called @@HW3.py@@. We will call to test your code as
to:
!!Programming Assignment 3 - Divide and Conquer
!!!Due: Apriil 2nd at 5pm.
!!!The octagon problem
You are given a set of '''n''' points in two dimensions (i.e. each point has two coordinates x, and y), where '''n''' is a multiple of 8.
Your task is to draw a set of octagons through these points, where no to octagons share a point or intersect, and the sides of each octagon do not intersect as well.
For simplicity assume each point has coordinates between 0 and 1.
Solve this problem using a divide and conquer approach.
We propose you use a two stage approach: first choose how to divide the n points into octagons, so that they won't intersect, and a second stage which decides the order in which the points in an octagon need to be joined together such that no two sides of the octagon intersect.
For the second stage, here is a simple solution that you can use:
Pick the lowest point of the set (smallest x coordinate). If there are ties, pick the rightmost. Set that point as the origin and sort the remaining points w.r.t their polar angles.
The polar angle of a point (x,y) is given by:
!!!Due: Apriil 2nd at 5pm.
!!!The octagon problem
You are given a set of '''n''' points in two dimensions (i.e. each point has two coordinates x, and y), where '''n''' is a multiple of 8.
Your task is to draw a set of octagons through these points, where no to octagons share a point or intersect, and the sides of each octagon do not intersect as well.
For simplicity assume each point has coordinates between 0 and 1.
Solve this problem using a divide and conquer approach.
We propose you use a two stage approach: first choose how to divide the n points into octagons, so that they won't intersect, and a second stage which decides the order in which the points in an octagon need to be joined together such that no two sides of the octagon intersect.
For the second stage, here is a simple solution that you can use:
Pick the lowest point of the set (smallest x coordinate). If there are ties, pick the rightmost. Set that point as the origin and sort the remaining points w.r.t their polar angles.
The polar angle of a point (x,y) is given by:
Changed lines 20-29 from:
import HW3
# you should implement a method for loading a directed graph
# called load_directed_dot:
g = HW3.load_directed_dot(file_name)
# find a shortest path between start_node and end_node
path = HW3.dijkstra(g, start_node, end_node)
# note that you may use a dictionary to convert the names of
# start_node and end_node to their internal representation as
# node indices. This is the only exception to our "no dictionaries" rule!
# The return value should be a list of nodes that are on the shortest path.
# you should implement a method for loading a directed graph
# called load_directed_dot:
g = HW3.load_directed_dot(file_name
# find a shortest path between start_node and end_node
path = HW3.dijkstra(g, start_node, end_node)
# note that you may use a dictionary to convert the names of
# start_node and end_node to their internal representation as
# node indices. This is the only exception to our "no dictionaries" rule!
# The return value should be a list of nodes that are on the shortest path.
to:
import math
math.atan2(y / x)
math.atan2(y / x)
Changed lines 23-32 from:
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 -> node2 weight@@, where @@weight@@ is the cost of the edge.
For example, the @@dot@@ formatted file corresponding to the graph in Figure 4.7 (page 139 in the book) is located [[http://www.cs.colostate.edu/~sutton/cs320/figure4_7.dot | here]] and is shown below.
%block text-align=center% %height=300px%http://www.cs.colostate.edu/~sutton/cs320/figure4_7.gif
In this case, the call @@HW3.dijkstra(g,'s','y')@@ would return the list @@['s','u','x','y'].@@
You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
to:
To understand the algorithm, read about [[http://en.wikipedia.org/wiki/Polar_coordinate_system | polar coordinates]].
You may use Python's built in sorted() or list.sort() methods which are described in full detail at:
http://wiki.python.org/moin/HowTo/Sorting
Here are some python code snippets to help you develop your code.
To create a list of num_points random points in two dimensions:
(:source lang=python:)
from random import uniform
points = [(uniform(0,1), uniform(0,1)) for i in range(num_points)]
(:sourceend:)
you can plot the points using the matplotlib plotting library (it is installed on department linux machines):
(:source lang=python:)
x = [point[0] for point in points]
y = [point[1] for point in points]
from matplotlib import pylab
pylab.plot(x, y, 'ob')
(:sourceend:)
Now suppose that you grouped together the points that belong to a given octagon, and its x and y coordinates are given by lists called oct_x and oct_y then you can display the octagon using:
(:source lang=python:)
oct_x.append(oct_x[0])
oct_y.append(oct_y[0])
pylab.plot(oct_x, oct_y, '-k')
(:sourceend:)
!!!Implementation details:
We should be able to run your code, given in a file HW3.py as:
(:source lang=python:)
python HW2.py input_file output_file
(:sourceend:)
where input_file is a comma-delimited file with two columns containing the input data points:
x1,y1
x2,y2
x3,y3
...
xn,yn
and output_file is the output file which specifies the octagons in comma delimited format. Each line in the file indicates which data points belong to an octagon. A line
p1,p2,p3,p4,p5,p6,p7,p8
indicates the indices of the data points in the input file (0-based indexing).
You may use Python's built in sorted() or list.sort() methods which are described in full detail at:
http://wiki.python.org/moin/HowTo/Sorting
Here are some python code snippets to help you develop your code.
To create a list of num_points random points in two dimensions:
(:source lang=python:)
from random import uniform
points = [(uniform(0,1), uniform(0,1)) for i in range(num_points)]
(:sourceend:)
you can plot the points using the matplotlib plotting library (it is installed on department linux machines):
(:source lang=python:)
x = [point[0] for point in points]
y = [point[1] for point in points]
from matplotlib import pylab
pylab.plot(x, y, 'ob')
(:sourceend:)
Now suppose that you grouped together the points that belong to a given octagon, and its x and y coordinates are given by lists called oct_x and oct_y then you can display the octagon using:
(:source lang=python:)
oct_x.append(oct_x[0])
oct_y.append(oct_y[0])
pylab.plot(oct_x, oct_y, '-k')
(:sourceend:)
!!!Implementation details:
We should be able to run your code, given in a file HW3.py as:
(:source lang=python:)
python HW2.py input_file output_file
(:sourceend:)
where input_file is a comma-delimited file with two columns containing the input data points:
x1,y1
x2,y2
x3,y3
...
xn,yn
and output_file is the output file which specifies the octagons in comma delimited format. Each line in the file indicates which data points belong to an octagon. A line
p1,p2,p3,p4,p5,p6,p7,p8
indicates the indices of the data points in the input file (0-based indexing).
Changed lines 3-4 from:
!!!Due: March 14th at 5pm.
to:
!!!Due: March 21st at 5pm.
Changed lines 22-30 from:
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 -> node2 weight@@, where @@weight@@ is the cost of the edge. On ramct we provide a small example. You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
to:
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 -> node2 weight@@, where @@weight@@ is the cost of the edge.
For example, the @@dot@@ formatted file corresponding to the graph in Figure 4.7 (page 139 in the book) is located [[http://www.cs.colostate.edu/~sutton/cs320/figure4_7.dot | here]] and is shown below.
%block text-align=center% %height=300px%http://www.cs.colostate.edu/~sutton/cs320/figure4_7.gif
In this case, the call @@HW3.dijkstra(g,'s','y')@@ would return the list @@['s','u','x','y'].@@
You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
For example, the @@dot@@ formatted file corresponding to the graph in Figure 4.7 (page 139 in the book) is located [[http://www.cs.colostate.edu/~sutton/cs320/figure4_7.dot | here]] and is shown below.
%block text-align=center% %height=300px%http://www.cs.colostate.edu/~sutton/cs320/figure4_7.gif
In this case, the call @@HW3.dijkstra(g,'s','y')@@ would return the list @@['s','u','x','y'].@@
You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
Changed line 22 from:
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 -> node2 weight@@. On ramct we provide a small example. You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
to:
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 -> node2 weight@@, where @@weight@@ is the cost of the edge. On ramct we provide a small example. You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
Changed line 22 from:
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 -> node2@@. You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
to:
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 -> node2 weight@@. On ramct we provide a small example. You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
Changed line 22 from:
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 --> node2@@. You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
to:
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 -> node2@@. You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
Changed line 13 from:
g = HW2.load_directed_dot(file_name)
to:
g = HW3.load_directed_dot(file_name)
Changed line 15 from:
path = HW2.dijkstra(g, start_node, end_node)
to:
path = HW3.dijkstra(g, start_node, end_node)
Changed lines 5-6 from:
In this assignment you will program Dikstra's shortest path algorithm. Your implementation should use a heap-based priority queue to prioritize the order of processing unexplored nodes inthe graph; on a given graph with n nodes and m edges, the running time of your implementation of Dijkstra's algorithm should be O(m log n). We will look at the code to verify that your implementation satisfies this bound. So, as before, you can't use Python dictionaries in your graph class, except during reading the graph from the input file.
to:
In this assignment you will program Dijkstra's shortest path algorithm. Your implementation should use a heap-based priority queue to prioritize the order of processing unexplored nodes inthe graph; on a given graph with n nodes and m edges, the running time of your implementation of Dijkstra's algorithm should be O(m log n). We will look at the code to verify that your implementation satisfies this bound. So, as before, you can't use Python dictionaries in your graph class, except during reading the graph from the input file.
Changed lines 11-12 from:
# you should implement a method for loading a directed graph called load_directed_dot:
to:
# you should implement a method for loading a directed graph
# called load_directed_dot:
# called load_directed_dot:
Changed lines 16-18 from:
# note that you may use a dictionary to convert the names of start_node and end_node
# to their internal representation as node indices. This is the only exception to
# our "no dictionaries" rule!
to:
# note that you may use a dictionary to convert the names of
# start_node and end_node to their internal representation as
# node indices. This is the only exception to our "no dictionaries" rule!
# start_node and end_node to their internal representation as
# node indices. This is the only exception to our "no dictionaries" rule!
Changed line 3 from:
!!!Due: Feb 18th at 5pm.
to:
!!!Due: March 14th at 5pm.
Added lines 1-21:
!!Programming Assignment 3 - Dijkstra's algorithm
!!!Due: Feb 18th at 5pm.
In this assignment you will program Dikstra's shortest path algorithm. Your implementation should use a heap-based priority queue to prioritize the order of processing unexplored nodes inthe graph; on a given graph with n nodes and m edges, the running time of your implementation of Dijkstra's algorithm should be O(m log n). We will look at the code to verify that your implementation satisfies this bound. So, as before, you can't use Python dictionaries in your graph class, except during reading the graph from the input file.
Your code should be structured as a single python file called @@HW3.py@@. We will call to test your code as:
(:source lang=python:)
import HW3
# you should implement a method for loading a directed graph called load_directed_dot:
g = HW2.load_directed_dot(file_name)
# find a shortest path between start_node and end_node
path = HW2.dijkstra(g, start_node, end_node)
# note that you may use a dictionary to convert the names of start_node and end_node
# to their internal representation as node indices. This is the only exception to
# our "no dictionaries" rule!
# The return value should be a list of nodes that are on the shortest path.
(:sourceend:)
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 --> node2@@. You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
!!!Due: Feb 18th at 5pm.
In this assignment you will program Dikstra's shortest path algorithm. Your implementation should use a heap-based priority queue to prioritize the order of processing unexplored nodes inthe graph; on a given graph with n nodes and m edges, the running time of your implementation of Dijkstra's algorithm should be O(m log n). We will look at the code to verify that your implementation satisfies this bound. So, as before, you can't use Python dictionaries in your graph class, except during reading the graph from the input file.
Your code should be structured as a single python file called @@HW3.py@@. We will call to test your code as:
(:source lang=python:)
import HW3
# you should implement a method for loading a directed graph called load_directed_dot:
g = HW2.load_directed_dot(file_name)
# find a shortest path between start_node and end_node
path = HW2.dijkstra(g, start_node, end_node)
# note that you may use a dictionary to convert the names of start_node and end_node
# to their internal representation as node indices. This is the only exception to
# our "no dictionaries" rule!
# The return value should be a list of nodes that are on the shortest path.
(:sourceend:)
The graph is loaded from a file in @@dot@@ format. In this case we are dealing with a directed graph so an edge is represented as @@node1 --> node2@@. You will need to add a @@change_key@@ method to your heap implementation. Page 65 in the book has a useful hint; as we discussed in class, you will need to @@heapify_up@@ or @@heapify_down@@ after a change key operation, depending on whether the key was increased or decreased.
