-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertex.java
82 lines (72 loc) · 1.78 KB
/
Vertex.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
import java.util.LinkedList;
import java.util.List;
//added the code below
import java.util.HashMap;
public class Vertex implements Comparable<Vertex> {
public String name;
private List<Edge> adjacent;
public int posX = 0;
public int posY = 0;
// added the variables below:
public boolean visited;
public int pathCost;
public Vertex previousPointer;
public HashMap<Vertex, Integer> vertices;
public double weightedCost;
/**
* Construct a new vertex containing an adjacency list.
*
* @param vertexName
* a unique identifier for this vertex.
* @param x
* the x coordinate for this vertex
* @param y
* the y coordinate for this vertex
*/
public Vertex(String vertexName, int x, int y) {
name = vertexName;
adjacent = new LinkedList<Edge>();
posX = x;
posY = y;
// added the initialization below
pathCost = Integer.MAX_VALUE;
visited = false;
previousPointer = null;
vertices = new HashMap<Vertex, Integer>();
weightedCost = Integer.MAX_VALUE;
}
/**
* Construct a new vertex containing an adjacency list.
*
* @param vertexName
* a unique identifier for this vertex.
*/
public Vertex(String vertexName) {
this(vertexName, 0, 0);
}
/**
* Retrieve the list of edges connected to this vertex.
*
* @return a list of edges connected to this vertex.
*/
public List<Edge> getEdges() {
return adjacent;
}
/**
* Connect an edge to this vertex.
*
* @param e
* The new edge to connect to this vertex.
*/
public void addEdge(Edge e) {
adjacent.add(e);
}
public String toString() {
return name;
}
public int compareTo(Vertex v) {
Double thisWeightedCost = this.weightedCost;
Double vWeightedCost = v.weightedCost;
return (thisWeightedCost.compareTo(vWeightedCost));
}
}