-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelicop.java
More file actions
148 lines (137 loc) · 3.43 KB
/
Helicop.java
File metadata and controls
148 lines (137 loc) · 3.43 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
import java.util.ArrayList;
/**
* Instance tridy {@code Helicop} predstavuji proces vrtulniku v simulaci.
* @author kolovsky
* @author jmacura
* @version 1.00.000
*/
class Helicop extends Process{
public Node start;
public Node end;
public int kolik;
public static int lastID;
public int id;
ArrayList<String> log = new ArrayList<String>();
int startTime;
/**
* konstruktor
* @param time Kdy ma vrtulnik vyletet
* @param start Odkud
* @param end Kam
* @param kolik Kolik veze
*/
public Helicop(int time,Node start, Node end, int kolik)
{
super(time);
this.id = lastID;
incrementID();
this.start = start;
this.end = end;
nextWork = 0;
this.kolik = kolik;
this.startTime = time;
}
/**
* metoda volana po vybrani z fronty
*/
public void goOn(){
if (nextWork == 0) { //nakladani do vrtulniku
deal();
nextWork = 1;
return;
}
if (nextWork == 4) {
Core.log("Vrtulnik id "+ id);
Core.log("Ukol splnen!");
log.add(""+startTime+" "+Core.c.time+ " "+kolik+" "+end.id);
((Settle)start.proces).garage.addLast(this);
return;
}
if (nextWork == 1) { //let tam
shift(start,end);
nextWork = 2;
return;
}
if (nextWork == 2) { //vykladka z vrtulniku
deal();
nextWork = 3;
return;
}
if (nextWork == 3) { //let zpet
((Settle)end.proces).addFood(kolik);
shift(end,start);
nextWork = 4;
return;
}
}
/**
* nakladat/vykladat
*/
public void deal(){
time = (int)((kolik/1000.0)*30.0) + Core.c.time;
Core.log("Vrtulnik id "+ id);
Core.log("Nakladam/vykladam do casu "+time);
Core.c.getQueue().add(this);
}
/**
* posun vrtulniku
* @param from Odkud
* @param to Kam
*/
public void shift(Node from, Node to){
Edge edge = from.firstEdge;
while (edge != null) {
if (edge.node == to) {
time = (int) (edge.cost/2500.0) + Core.c.time;//2500 metru/min
}
edge = edge.next;
}
Core.log("Vrtulnik id "+ id);
Core.log("Letim do uzlu id = "+ to.id);
Core.log("Budu tam v "+time);
Core.c.getQueue().add(this);
}
/**
* prideluje novou praci pro vrtulnik (recyklace vrtulniku)
* @param time Kdy ma vrtulnik vyletet
* @param start Odkud
* @param end Kam
* @param kolik Kolik veze
*/
public void newWork(int time,Node start, Node end, int kolik){
this.time = time;
this.start = start;
this.end = end;
nextWork = 0;
this.kolik = kolik;
this.startTime = time;
}
/**
* statistika k danemu vrtulniku
* @param legend {@code true} vypise legendu
*/
public String toString(boolean legend){
String out = "Id: "+id+"\n";
//out += "Actual place: "+ path[nextWork-1].id;
if (nextWork <= 1 || nextWork == 4 ) {
out += "Actual place: "+ start.id;
}
else {
out += "Actual place: "+ end.id;
}
if (legend) {
out += "Start End Quant Settle\n";
}
for (int i = 0;i<log.size() ;i++ ) {
out += log.get(i)+"\n";
}
return out;
}
/**
* zajistuje aktualni cislovani vrtulniku
*/
private void incrementID()
{
lastID++;
}
}