-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuto.java
More file actions
154 lines (142 loc) · 4.16 KB
/
Auto.java
File metadata and controls
154 lines (142 loc) · 4.16 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import java.io.*;
import java.awt.*;
import java.applet.*;
import java.net.*;
import java.util.*;
import java.lang.*;
public class Auto {
public int id;
public int origin;
public int destination;
public int status;
public int currentNode;
public int previousNode;
public int currentposition; // the index that indicate position on the route;
public double vot; //value of time, unit in $/min;
public double travelbudge; //travel budget, unit in dollar;
final static int path_info_attributes = 2;
final static int route_info_attributes = 3;
final static int large = 50; //the largest number of nodes on each path;
final static int nullindicator = -9;
final static int infinite = 999;
public int path[];
public double path_info[];
//0: nodes on the route;
//1: time cost;
public int route[];
public double route_info[];
//0: nodes on the route;
//1: time cost;
//2: total money cost;
public Auto(int id, int origin, int destination, double vot, double travelbudget) {
this.id = id;
this.origin = origin;
this.destination = destination;
this.status = 0;
this.currentNode = origin;
this.previousNode = this.currentNode;
this.currentposition = 0;
this.path = new int[large];
this.path_info = new double[path_info_attributes];
this.route = new int[large];
this.route_info = new double[route_info_attributes];
this.vot = vot;
this.travelbudge = travelbudget;
path[0] = origin;
for (int i=1;i<large;i++){
path[i] = nullindicator;
}
path_info[0] = 1;
path_info[1] = infinite;
for (int i=0;i<large;i++){
route[i] = large;
}
route_info[0] = nullindicator;
route_info[1] = infinite;
route_info[2] = infinite;
}
public boolean addNode(int nextNode, double linkcost){
boolean existCircle=false;
if (nextNode == this.destination){
this.previousNode = this.currentNode;
this.currentNode = nextNode;
this.status =1;
this.path_info[0] = this.path_info[0]+1;
int pathindex;
pathindex = (int)this.path_info[0]-1;
this.path[pathindex] = nextNode;
this.path_info[1] = this.path_info[1]+linkcost;
}else{
int breakindex=0;
int index = (int)this.path_info[0]-1;
while (index>=0 && existCircle==false){
if (this.path[index] == nextNode){
existCircle = true;
breakindex = index;
}else{
index--;
}
}
if (existCircle == false){
this.previousNode = this.currentNode;
this.currentNode = nextNode;
this.path_info[0] = this.path_info[0]+1;
int pathindex;
pathindex = (int)this.path_info[0]-1;
this.path[pathindex] = nextNode;
this.path_info[1] = this.path_info[1]+linkcost;
}else{
this.previousNode = this.currentNode;
this.currentNode = nextNode; //which is the same as path[breakindex];
int pathindex;
pathindex = (int)this.path_info[0]-1;
while(pathindex>breakindex){
this.path[pathindex]=nullindicator;
this.path_info[0] -= 1;
pathindex--;
}
}
}
return(existCircle);
}
public void pathIncrement(int nextNodeId, double linkcost){
this.path_info[0] = this.path_info[0]+1;
int pathindex;
pathindex = (int)this.path_info[0]-1;
this.path[pathindex] = nextNodeId; //Add the next node to node chain of path;
this.path_info[1] = this.path_info[1]+linkcost; //Add the length cost to total pathcost;
}
public void copypathToroute(){
//Copy current path to route choice;
for (int i=0;i<large;i++){
this.route[i]=this.path[i];
}
for (int i=0;i<path_info_attributes;i++){
this.route_info[i] = this.path_info[i];
}
}
public void reset(){
//Used in case erase both path and route infor;
//travelbudge, vot, origin, destination, id remain unchanged;
this.status = 0;
this.currentNode =this.origin;
this.previousNode = this.origin;
this.currentposition = 0;
this.path = new int[large];
this.path_info = new double[path_info_attributes];
this.route = new int[large];
this.route_info = new double[route_info_attributes];
path[0] = origin;
for (int i=1;i<large;i++){
path[i] = nullindicator;
}
path_info[0] = 1;
path_info[1] = infinite;
for (int i=0;i<large;i++){
route[i] = large;
}
route_info[0] = nullindicator;
route_info[1] = infinite;
route_info[2] = infinite;
}
}