Rename
This commit is contained in:
parent
2189ba86c4
commit
5868aa977d
4 changed files with 40 additions and 22 deletions
|
@ -1,7 +1,16 @@
|
|||
package simulation;
|
||||
|
||||
class Event {
|
||||
// Constructor, creates an event of a certain type that should be put in the event list at a certain time.
|
||||
Event(int type, double timeOfEvent) {
|
||||
eventType = type;
|
||||
eventTime = timeOfEvent;
|
||||
}
|
||||
|
||||
// Empty constructor (used by the event list constructor)
|
||||
Event() { }
|
||||
|
||||
public double eventTime;
|
||||
public int eventType;
|
||||
public Event next;
|
||||
public Event next = null;
|
||||
}
|
||||
|
|
|
@ -1,37 +1,43 @@
|
|||
package simulation;
|
||||
|
||||
public class EventList {
|
||||
|
||||
private Event list, last;
|
||||
private Event head, tail;
|
||||
|
||||
EventList() {
|
||||
list = new Event();
|
||||
last = new Event();
|
||||
list.next = last;
|
||||
head = new Event();
|
||||
tail = new Event();
|
||||
head.next = tail;
|
||||
}
|
||||
|
||||
public void InsertEvent(int type, double TimeOfEvent) {
|
||||
Event dummy, predummy;
|
||||
predummy = this.list;
|
||||
dummy = this.list.next;
|
||||
Event temp, pretemp;
|
||||
|
||||
Event newEvent = new Event();
|
||||
newEvent.eventType = type;
|
||||
newEvent.eventTime = TimeOfEvent;
|
||||
pretemp = this.head;
|
||||
temp = this.head.next;
|
||||
|
||||
while ((dummy.eventTime < newEvent.eventTime) && (dummy != last)) {
|
||||
predummy = dummy;
|
||||
dummy = dummy.next;
|
||||
Event newEvent = new Event(type, TimeOfEvent);
|
||||
|
||||
// Find the right place in the list using a sliding window
|
||||
while ((temp.eventTime < newEvent.eventTime) && (temp != tail)) {
|
||||
pretemp = temp;
|
||||
temp = temp.next;
|
||||
}
|
||||
|
||||
predummy.next = newEvent;
|
||||
newEvent.next = dummy;
|
||||
pretemp.next = newEvent;
|
||||
newEvent.next = temp;
|
||||
}
|
||||
|
||||
public Event FetchEvent() {
|
||||
Event dummy = list.next;
|
||||
list.next = dummy.next;
|
||||
dummy.next = null;
|
||||
return dummy;
|
||||
Event temp = head.next;
|
||||
head.next = temp.next;
|
||||
temp.next = null;
|
||||
return temp;
|
||||
}
|
||||
|
||||
public Event popFront() {
|
||||
Event temp = head.next;
|
||||
head.next = temp.next;
|
||||
temp.next = null;
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package simulation;
|
||||
|
||||
// This class is only created to be able to store the global time.
|
||||
public class GlobalSimulation{
|
||||
public static final int ARRIVAL = 1, READY = 2, MEASURE = 3;
|
||||
public static double time = 0;
|
||||
|
|
|
@ -12,11 +12,13 @@ public class MainSimulation extends GlobalSimulation {
|
|||
|
||||
myEventList.InsertEvent(ARRIVAL, 0);
|
||||
myEventList.InsertEvent(MEASURE, 5);
|
||||
|
||||
while (MainSimulation.time < 50000) {
|
||||
actEvent = myEventList.FetchEvent();
|
||||
MainSimulation.time = actEvent.eventTime;
|
||||
actState.TreatEvent(actEvent);
|
||||
}
|
||||
|
||||
System.out.println("Mean number of customers: " + (double) actState.accumulated / actState.noMeasurements);
|
||||
System.out.println("Number of measurements done: " + actState.noMeasurements);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue