import java.util.*; /** * A representation of a graph. * Assumes that we do not have negative cost edges in the graph. */ public class MyGraph implements Graph { private Collection myVertices; // the vertices in this graph private Collection myEdges; // the edges in this graph /** * Creates a MyGraph object with the given collection of vertices * and the given collection of edges. * @param v a collection of the vertices in this graph * @param e a collection of the edges in this graph */ public MyGraph(Collection v, Collection e) { // YOUR CODE HERE } /** * Return the collection of vertices of this graph * @return the vertices as a collection (which is anything iterable) */ public Collection vertices() { // YOUR CODE HERE } /** * Return the collection of edges of this graph * @return the edges as a collection (which is anything iterable) */ public Collection edges() { // YOUR CODE HERE } /** * Return a collection of vertices adjacent to a given vertex v. * i.e., the set of all vertices w where edges v -> w exist in the graph. * Return an empty collection if there are no adjacent vertices. * @param v one of the vertices in the graph * @return an iterable collection of vertices adjacent to v in the graph * @throws IllegalArgumentException if v does not exist. */ public Collection adjacentVertices(Vertex v) { // YOUR CODE HERE } /** * Test whether vertex b is adjacent to vertex a (i.e. a -> b) in a directed graph. * Assumes that we do not have negative cost edges in the graph. * @param a one vertex * @param b another vertex * @return cost of edge if there is a directed edge from a to b in the graph, * return -1 otherwise. * @throws IllegalArgumentException if a or b do not exist. */ public int isAdjacent(Vertex a, Vertex b) { // YOUR CODE HERE } /** * Returns the shortest path from a to b in the graph. Assumes positive * edge weights. Uses Dijkstra's algorithm. * @param a the starting vertex * @param b the destination vertex * @param path a list in which the path will be stored, in order, the first * being the start vertex and the last being the destination vertex. The * list will be empty if no such path exists. NOTE: the list will be * cleared of any previous data. path is not expected to contain any data * needed by the method when the method is called. It is used to allow * us to return multiple values from the function. * @return the length of the shortest path from a to b, -1 if no such path * exists. * @throws IllegalArgumentException if a or b does not exist. */ public int shortestPath(Vertex a, Vertex b, List path) { // YOUR CODE HERE } }