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; | package simulation; | ||||||
| 
 | 
 | ||||||
| class Event { | 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 double eventTime; | ||||||
| 	public int eventType; | 	public int eventType; | ||||||
| 	public Event next; | 	public Event next = null; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,37 +1,43 @@ | ||||||
| package simulation; | package simulation; | ||||||
| 
 | 
 | ||||||
| public class EventList { | public class EventList { | ||||||
| 
 | 	private Event head, tail; | ||||||
| 	private Event list, last; |  | ||||||
| 
 | 
 | ||||||
| 	EventList() { | 	EventList() { | ||||||
| 		list = new Event(); | 		head = new Event(); | ||||||
| 		last = new Event(); | 		tail = new Event(); | ||||||
| 		list.next = last; | 		head.next = tail; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public void InsertEvent(int type, double TimeOfEvent) { | 	public void InsertEvent(int type, double TimeOfEvent) { | ||||||
| 		Event dummy, predummy; | 		Event temp, pretemp; | ||||||
| 		predummy = this.list; |  | ||||||
| 		dummy = this.list.next; |  | ||||||
| 
 | 
 | ||||||
| 		Event newEvent = new Event(); | 		pretemp = this.head; | ||||||
| 		newEvent.eventType = type; | 		temp = this.head.next; | ||||||
| 		newEvent.eventTime = TimeOfEvent; |  | ||||||
| 
 | 
 | ||||||
| 		while ((dummy.eventTime < newEvent.eventTime) && (dummy != last)) { | 		Event newEvent = new Event(type, TimeOfEvent); | ||||||
| 			predummy = dummy; | 
 | ||||||
| 			dummy = dummy.next; | 		// 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; | 		pretemp.next = newEvent; | ||||||
| 		newEvent.next = dummy; | 		newEvent.next = temp; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	public Event FetchEvent() { | 	public Event FetchEvent() { | ||||||
| 		Event dummy = list.next; | 		Event temp = head.next; | ||||||
| 		list.next = dummy.next; | 		head.next = temp.next; | ||||||
| 		dummy.next = null; | 		temp.next = null; | ||||||
| 		return dummy; | 		return temp; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	public Event popFront() { | ||||||
|  | 		Event temp = head.next; | ||||||
|  | 		head.next = temp.next; | ||||||
|  | 		temp.next = null; | ||||||
|  | 		return temp; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| package simulation; | package simulation; | ||||||
| 
 | 
 | ||||||
|  | // This class is only created to be able to store the global time. | ||||||
| public class GlobalSimulation{ | public class GlobalSimulation{ | ||||||
| 	public static final int ARRIVAL = 1, READY = 2, MEASURE = 3; | 	public static final int ARRIVAL = 1, READY = 2, MEASURE = 3; | ||||||
| 	public static double time = 0; | 	public static double time = 0; | ||||||
| } | } | ||||||
|  | @ -12,11 +12,13 @@ public class MainSimulation extends GlobalSimulation { | ||||||
| 
 | 
 | ||||||
| 		myEventList.InsertEvent(ARRIVAL, 0); | 		myEventList.InsertEvent(ARRIVAL, 0); | ||||||
| 		myEventList.InsertEvent(MEASURE, 5); | 		myEventList.InsertEvent(MEASURE, 5); | ||||||
|  | 
 | ||||||
| 		while (MainSimulation.time < 50000) { | 		while (MainSimulation.time < 50000) { | ||||||
| 			actEvent = myEventList.FetchEvent(); | 			actEvent = myEventList.FetchEvent(); | ||||||
| 			MainSimulation.time = actEvent.eventTime; | 			MainSimulation.time = actEvent.eventTime; | ||||||
| 			actState.TreatEvent(actEvent); | 			actState.TreatEvent(actEvent); | ||||||
| 		} | 		} | ||||||
|  | 
 | ||||||
| 		System.out.println("Mean number of customers: " + (double) actState.accumulated / actState.noMeasurements); | 		System.out.println("Mean number of customers: " + (double) actState.accumulated / actState.noMeasurements); | ||||||
| 		System.out.println("Number of measurements done: " + actState.noMeasurements); | 		System.out.println("Number of measurements done: " + actState.noMeasurements); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Imbus
						Imbus