-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
125 lines (80 loc) · 2.12 KB
/
Copy pathNode.java
File metadata and controls
125 lines (80 loc) · 2.12 KB
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
import java.util.Vector;
// The node class
public class Node {
private Vector <Integer> node;
private final int n_dim;
// The current score, the from-start score, and the heuristic score of the node.
public double f_score, g_score, h_score;
// Whether the node is passable or not.
public boolean is_passable;
public Node(Vector <Integer> node, boolean is_passable) {
this.node = node;
n_dim = node.size();
this.is_passable = is_passable;
}
public Node( Node n ) {
this.node = n.node;
this.n_dim = n.n_dim;
this.f_score = n.f_score;
this.g_score = n.g_score;
this.h_score = n.h_score;
this.is_passable = n.is_passable;
}
public Node(Integer node1, Integer node2, boolean is_passable) {
node = new Vector <Integer> ();
node.add(node1);
node.add(node2);
n_dim = 2;
this.is_passable = is_passable;
}
//Override equals() method
public boolean equals( Object obj ) {
if( !(obj instanceof Node) )
return false;
Node compNode = (Node) obj;
if( !( this.is_passable == compNode.is_passable ) )
return false;
if( !( this.node.equals(compNode.node) ))
return false;
if( !( this.n_dim == compNode.n_dim ) )
return false;
return true;
}
//Override hashcode() method
public int hashcode() {
int hash = 7;
hash = (int) (31 * hash + Math.ceil( this.absolute_value() ));
return hash;
}
public double distance(Node n){
double distance = 0.0;
if(n.n_dim != n_dim) {
return -1;
}
else {
for( int i = 0; i < n_dim; i++)
distance += ( node.elementAt(i) - n.node.elementAt(i) ) *
( node.elementAt(i) - n.node.elementAt(i) );
return distance;
}
}
public double absolute_value() {
double abs = 0.0;
for( int i = 0; i < n_dim; i++)
abs += ( node.elementAt(i) ) * ( node.elementAt(i) );
return abs;
}
public double get_heuristic_score( Node n ) {
return distance( n );
}
public Vector <Integer> getVector () {
return node;
}
public int changeValue(Vector <Integer> n) {
if( n.size() != n_dim)
return -1;
else
node = n;
return 0;
}
}