Unstable test (multiple exceptions)
This commit is contained in:
		
							parent
							
								
									b214b279db
								
							
						
					
					
						commit
						d1061221e8
					
				@ -21,7 +21,7 @@ public class MakkahCity {
 | 
				
			|||||||
	private static PDate currenttimeManager = firstDayTimeMan;
 | 
						private static PDate currenttimeManager = firstDayTimeMan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static void main(String[] args) {
 | 
						public static void main(String[] args) {
 | 
				
			||||||
 | 
							ArrayList<Thread> threads = new ArrayList<>();
 | 
				
			||||||
		//Gen Camp
 | 
							//Gen Camp
 | 
				
			||||||
		campPerDistrict[District.ALMANSOOR.ordinal()] = new ArrayList<>();
 | 
							campPerDistrict[District.ALMANSOOR.ordinal()] = new ArrayList<>();
 | 
				
			||||||
		campPerDistrict[District.ALAZIZIYA.ordinal()] = new ArrayList<>();
 | 
							campPerDistrict[District.ALAZIZIYA.ordinal()] = new ArrayList<>();
 | 
				
			||||||
@ -62,27 +62,21 @@ public class MakkahCity {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			clearDoneCivilVehicles();
 | 
								clearDoneCivilVehicles();
 | 
				
			||||||
			for (Vehicle vehicle : listOfVehicles) {
 | 
								for (Vehicle vehicle : listOfVehicles) {
 | 
				
			||||||
				Route route = vehicle.getRoute();
 | 
									VMover m = new VMover(vehicle);
 | 
				
			||||||
				double currentLocation = vehicle.getCurrentLocation();
 | 
									threads.add(new Thread(m));
 | 
				
			||||||
				if (vehicle.getCurrentStreet() == null &&
 | 
					 | 
				
			||||||
				route.getStreets()[0].capcityPoint(0,1000) < 1) {
 | 
					 | 
				
			||||||
					vehicle.setCurrentStreet(route.getStreets()[0]);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				 if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation,
 | 
					 | 
				
			||||||
						currentLocation+1000) < 1 ) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					if (currentLocation >= vehicle.getCurrentStreet().getLength()) {
 | 
					 | 
				
			||||||
						//Move to next street
 | 
					 | 
				
			||||||
						vehicle.moveToNextStreet();
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					if (!vehicle.isArrivedToDest()) {
 | 
					 | 
				
			||||||
						double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
 | 
					 | 
				
			||||||
										vehicle.getCurrentLocation()+1000,vehicle)) ;
 | 
					 | 
				
			||||||
						if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor );
 | 
					 | 
				
			||||||
						else if (vehicle instanceof Sedan) vehicle.move(Sedan.MAX_FORWARD * factor );
 | 
					 | 
				
			||||||
						else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor );
 | 
					 | 
				
			||||||
						else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD * factor );
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								for (int i = 0; i < threads.size(); i += 4){
 | 
				
			||||||
 | 
									threads.get(i).start();
 | 
				
			||||||
 | 
									threads.get(i+1).start();
 | 
				
			||||||
 | 
									threads.get(i+2).start();
 | 
				
			||||||
 | 
									threads.get(i+3).start();
 | 
				
			||||||
 | 
									try {
 | 
				
			||||||
 | 
										threads.get(i).join();
 | 
				
			||||||
 | 
										threads.get(i+1).join();
 | 
				
			||||||
 | 
										threads.get(i+2).join();
 | 
				
			||||||
 | 
										threads.get(i+3).join();
 | 
				
			||||||
 | 
									} catch (InterruptedException e) {
 | 
				
			||||||
 | 
										e.printStackTrace();
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			//noise based on time of day (From PDate)
 | 
								//noise based on time of day (From PDate)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										34
									
								
								src/VMover.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/VMover.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					public class VMover implements Runnable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Vehicle vehicle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public VMover(Vehicle vehicle) {
 | 
				
			||||||
 | 
					        this.vehicle = vehicle;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void run() {
 | 
				
			||||||
 | 
					        Route route = vehicle.getRoute();
 | 
				
			||||||
 | 
					        double currentLocation = vehicle.getCurrentLocation();
 | 
				
			||||||
 | 
					        if (vehicle.getCurrentStreet() == null &&
 | 
				
			||||||
 | 
					                route.getStreets()[0].capcityPoint(0,1000) < 1) {
 | 
				
			||||||
 | 
					            vehicle.setCurrentStreet(route.getStreets()[0]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (vehicle.getCurrentStreet() != null && vehicle.getCurrentStreet().capcityPoint(currentLocation,
 | 
				
			||||||
 | 
					                currentLocation+1000) < 1 ) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (currentLocation >= vehicle.getCurrentStreet().getLength()) {
 | 
				
			||||||
 | 
					                //Move to next street
 | 
				
			||||||
 | 
					                vehicle.moveToNextStreet();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (!vehicle.isArrivedToDest()) {
 | 
				
			||||||
 | 
					                double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
 | 
				
			||||||
 | 
					                        vehicle.getCurrentLocation()+1000,vehicle)) ;
 | 
				
			||||||
 | 
					                if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor );
 | 
				
			||||||
 | 
					                else if (vehicle instanceof Sedan) vehicle.move(Sedan.MAX_FORWARD * factor );
 | 
				
			||||||
 | 
					                else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor );
 | 
				
			||||||
 | 
					                else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD * factor );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user