1. Homepage
  2. Programming
  3. CSCI-GA 3033-009 Rigorous Software Development - Programming Project 2 - Dijkstra's Algorithm

CSCI-GA 3033-009 Rigorous Software Development - Programming Project 2 - Dijkstra's Algorithm

Engage in a Conversation
CSCI-GA 3033Rigorous Software DevelopmentJavaDijkstras Algorithm

Rigorous Software Development - Spring 2012 Thomas Wies CourseNana.COM

Programming Project 2 - Dijkstra's Algorithm CourseNana.COM

  CourseNana.COM

Please submit your solution via email to the instructor with CC to ly603@nyu.edu. The CourseNana.COM

deadline for the project is May 18. CourseNana.COM

  CourseNana.COM

The goal of this project is to implement and (partially) verify Dijkstra's algorithm for computing the single-source shortest paths to all vertices in a directed graph. CourseNana.COM

  CourseNana.COM

Part 1 Implementing and Verifying a Heap-Based Priority Queue CourseNana.COM

Dijkstra's algorithm uses a priority queue for e cient exploration of the vertices in the graph. In the  rst part of this project you will implement and verify a heap-based priority queue. CourseNana.COM

  CourseNana.COM

Your priority queue should have the following signature: CourseNana.COM

class PriorityQueue<T(==)> CourseNana.COM

{ CourseNana.COM

constructor Init(N: nat); CourseNana.COM

method insert(t: T, k: int); CourseNana.COM

function method min(): T CourseNana.COM

method deleteMin(); CourseNana.COM

method decreaseKey(t: T, k: int); CourseNana.COM

function method isEmpty(): bool; CourseNana.COM

} CourseNana.COM

  CourseNana.COM

The priority queue should maintain a set of T values that are ordered by integer keys. There should always be at most one key/value pair for any T value in the queue. The constructortakes the initial capacity as argument. The decreaseKey operations sets the key for thegiven value t to k. It may assume that k is not larger than the old key associated with t. CourseNana.COM

  CourseNana.COM

The semantics of the remaining operations is as expected. CourseNana.COM

(a) Implement the priority queue operations. Make sure that all operations have the expected worst-case running times of a heap-based implementation. In  particular, insert, deleteMin, and decreaseKey should all run in time O(log(n)), where n is the size of the queue. The operations min and isEmpty should run in constant time. CourseNana.COM

(b) Add a dynamic frame to your priority queue implementations and add an invariant that ties it to the representation of the queue. Use Dafny to check that all queue operations satisfy there modi es clauses and preserve the representation invariant. CourseNana.COM

  CourseNana.COM

(c) Add contracts to all operations to specify their functional behavior. You may introduceadditional ghost  elds as you see  t. Use Dafny to verify that all contracts are satisfied by your implementation. Add additional representation invariants to your implementation if necessary. CourseNana.COM

  CourseNana.COM

Hint: The Boogie source code distribution contains a partial heap-based priority queueimplementation. See Test/dafny1/PriorityQueue.dfy. This implementation only 1 stores keys instead of key/value pairs but you can use it as a starting point for your ownimplementation. CourseNana.COM

  CourseNana.COM

Part 2 Implementing and Verifying Dijkstra's Algorithm CourseNana.COM

  CourseNana.COM

In the second part of this project you will implement Dijkstra's Algorithm in Dafny and verify it against your priority queue implementation. CourseNana.COM

  CourseNana.COM

(a) Use the class Graph provided on the course web site and your priority queue implementation from Part 1 to implement a method CourseNana.COM

  CourseNana.COM

method shortestPaths(G: Graph, source : int) CourseNana.COM

returns (prev: array<int>) CourseNana.COM

requires G != null && G.Valid; CourseNana.COM

requires G.hasVertex(source); CourseNana.COM

  CourseNana.COM

The method should use Dijkstra's algorithm to compute an array prev. The array prevencodes (in inverse order) the shortest paths from the vertex source in the graph G toall other vertices in the graph. More precisely, prev maps a vertex i to its immediate predecessor on the shortest path from source to i if the path exists, and -1 otherwise. CourseNana.COM

  CourseNana.COM

An object G of class Graph represents a directed graph with vertices 0 to G.size-1 and edges encoded as adjacency lists for each vertex (see  eld neighbors). In your implementation you may assume that all edges in G have weight 1, i.e., the shortest distance between two vertices u and v is the in mum of the lengths of all paths from u to v in G. CourseNana.COM

  CourseNana.COM

(b) Use Dafny to verify that your implementation always terminates and that it satisfies all the contracts of the priority queue operations. Add loop invariants and decrease expressions to your implementation as you see  t. You do not need to verify that your implementation satis es the speci cation of Dijkstra's algorithm, i.e., that it actually computes the shortest paths. CourseNana.COM

Hint 1: To make your life easier, avoid adding additional state to the objects of class Graph, e.g., by extending the class with additional mutable  elds such as arrays. Keep all additional state local to the method shortestPaths. CourseNana.COM

Hint 2: You can start with Part 2 before you have finished Part 1. To do this, you need to provide an axiomatic interface specification of the priority queue. For example, an axiomatic interface specification of a set data structure is shown in Figure 1. Note that in the interface specification, the method isEmpty itself is used to denote the return value in the postcondition that defines the behavior of isEmpty. To tie the knot, once you are done with Part 1 you need to make sure that your implementation of the priority queue actually satisfies the axiomatic specification that you used in Part 2. CourseNana.COM

  CourseNana.COM

class Set<T(==)> CourseNana.COM

{ CourseNana.COM

ghost var Repr: set<objects>; CourseNana.COM

ghost var Contents: set<T>; CourseNana.COM

predicate Valid { this in Repr }; CourseNana.COM

... CourseNana.COM

method insert(x: T) CourseNana.COM

requires Valid; CourseNana.COM

modifies Repr; CourseNana.COM

ensures Valid; CourseNana.COM

ensures fresh(Repr - old(Repr)); CourseNana.COM

ensures Contents = old(Contents) + {x}; CourseNana.COM

function method isEmpty(x: T): bool CourseNana.COM

requires Valid; CourseNana.COM

reads Repr; CourseNana.COM

ensures isEmpty() <==> (Contents == {}); CourseNana.COM

} CourseNana.COM

  CourseNana.COM

Figure 1: Axiomatic interface speci cation of a set ADT CourseNana.COM

  CourseNana.COM

Part 3 Stretch Goals CourseNana.COM

  CourseNana.COM

If you are up for a challenge you can try to achieve one or both of the following stretch goals. CourseNana.COM

  CourseNana.COM

(a) For better performance, Dijkstra's algorithm is usually implemented using a priority queue based on Fibonacci heaps. Implement and verify such a priority queue. CourseNana.COM

(b) Verify that your implementation of Dijkstra's algorithm really computes the shortest paths to all vertices in the given graph. You can look at the implementation of the Shorr-Waite graph marking algorithm provided with the Boogie distribution to get some inspiration how to do this. Though, verifying Dijkstra's algorithm is more difficult and you might hit the limitations of what you can prove with the automated theorem prover underlying Dafny. CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
CSCI-GA 3033代写,Rigorous Software Development代写,Java代写,Dijkstras Algorithm代写,CSCI-GA 3033代编,Rigorous Software Development代编,Java代编,Dijkstras Algorithm代编,CSCI-GA 3033代考,Rigorous Software Development代考,Java代考,Dijkstras Algorithm代考,CSCI-GA 3033help,Rigorous Software Developmenthelp,Javahelp,Dijkstras Algorithmhelp,CSCI-GA 3033作业代写,Rigorous Software Development作业代写,Java作业代写,Dijkstras Algorithm作业代写,CSCI-GA 3033编程代写,Rigorous Software Development编程代写,Java编程代写,Dijkstras Algorithm编程代写,CSCI-GA 3033programming help,Rigorous Software Developmentprogramming help,Javaprogramming help,Dijkstras Algorithmprogramming help,CSCI-GA 3033assignment help,Rigorous Software Developmentassignment help,Javaassignment help,Dijkstras Algorithmassignment help,CSCI-GA 3033solution,Rigorous Software Developmentsolution,Javasolution,Dijkstras Algorithmsolution,