-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphADT.java
127 lines (112 loc) · 5.67 KB
/
GraphADT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.util.List;
import java.util.NoSuchElementException;
/**
* This ADT represents a directed graph data structure with positive edge weights.
*
* @param NodeType the data type stored at each graph vertex
* @param EdgeType the data type stored at each graph edge as a Number whose doubleValue() method returns a value >=0.0
*/
public interface GraphADT<NodeType,EdgeType extends Number> {
/**
* Insert a new vertex into the graph.
*
* @param data the data item stored in the new vertex
* @return true if the data can be inserted as a new vertex, false if it is already in the graph
* @throws NullPointerException if data is null
*/
public boolean insertVertex(NodeType data);
/**
* Remove a vertex from the graph.
* Also removes all edges adjacent to the vertex from the graph (all edges that have the vertex as a source or a destination vertex).
*
* @param data the data item stored in the vertex to remove
* @return true if a vertex with *data* has been removed, false if it was not in the graph
* @throws NullPointerException if data is null
*/
public boolean removeVertex(NodeType data);
/**
* Insert a new directed edge with a positive edges weight into the graph.
*
* @param source the data item contained in the source vertex for the edge
* @param target the data item contained in the target vertex for the edge
* @param weight the weight for the edge (has to be a positive Number)
* @return true if the edge could be inserted or its weight updated, false if the edge with the same weight was already in the graph with the graph
* @throws IllegalArgumentException if either sourceVertex or targetVertex or both are not in the graph, or weight is < 0
* @throws NullPointerException if either sourceVertex or targetVertex or both are null
*/
public boolean insertEdge(NodeType source, NodeType target, EdgeType weight);
/**
* Remove an edge from the graph.
*
* @param source the data item contained in the source vertex for the edge
* @param target the data item contained in the target vertex for the edge
* @return true if the edge could be removed, false if it was not in the graph
* @throws IllegalArgumentException if either sourceVertex or targetVertex or both are not in the graph
* @throws NullPointerException if either sourceVertex or targetVertex or both are null
*/
public boolean removeEdge(NodeType source, NodeType target);
/**
* Check if the graph contains a vertex with data item *data*.
*
* @param v the data item to check check for
* @return true if data item is stored in a vertex of the graph, false otherwise
* @throws NullPointerException if *data* is null
*/
public boolean containsVertex(NodeType data);
/**
* Check if edge is in the graph.
*
* @param source the data item contained in the source vertex for the edge
* @param target the data item contained in the target vertex for the edge
* @return true if the edge is in the graph, false if it is not in the graph
* @throws NullPointerException if either sourceVertex or targetVertex or both are null
*/
public boolean containsEdge(NodeType source, NodeType target);
/**
* Return the weight of an edge.
*
* @param source the data item contained in the source vertex for the edge
* @param target the data item contained in the target vertex for the edge
* @return the weight of the edge (0 or positive integer)
* @throws IllegalArgumentException if either sourceVertex or targetVertex or both are not in the graph
* @throws NullPointerException if either sourceVertex or targetVertex or both are null
* @throws NoSuchElementException if edge is not in the graph
*/
public EdgeType getWeight(NodeType source, NodeType target);
/**
* Returns the shortest path between startingVertex and destinationVertex.
* Uses Dijkstra's shortest path algorithm to find the shortest path.
*
* @param start the data item in the starting vertex for the path
* @param end the data item in the destination vertex for the path
* @return list of data item in vertices in order on the shortest path between vertex with data item startingVertex and vertex with data item destinationVertex, including both startingVertex and destinationVertex
*/
public List<NodeType> shortestPath(NodeType start, NodeType end);
/**
* Returns the cost of the path (sum over edge weights) between startingVertex and destinationVertex.
* Uses Dijkstra's shortest path algorithm to find the shortest path.
*
* @param start the data item in the starting vertex for the path
* @param end the data item in the destination vertex for the path
* @return the cost of the shortest path between vertex with data item startingVertex and vertex with data item destinationVertex, including both startingVertex and destinationVertex
*/
public double getPathCost(NodeType start, NodeType end);
/**
* Check if the graph is empty (does not contain any vertices or edges).
*
* @return true if the graph does not contain any vertices or edges, false otherwise
*/
public boolean isEmpty();
/**
* Return the number of edges in the graph.
*
* @return the number of edges in the graph
*/
public int getEdgeCount();
/**
* Return the number of vertices in the graph
*
* @return the number of vertices in the graph
*/
public int getVertexCount();
}