Compare commits

...

1 Commits

Author SHA1 Message Date
82efe228d3
Ugly implementation. Looks slower?! 2020-11-27 21:11:21 +03:00

View File

@ -1,4 +1,5 @@
import java.util.*; import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
public class MakkahCity { public class MakkahCity {
@ -66,6 +67,7 @@ public class MakkahCity {
} }
clearDoneCivilVehicles(); clearDoneCivilVehicles();
ArrayList<Thread> threadPool = new ArrayList<>();
for (Vehicle vehicle : listOfVehicles) { for (Vehicle vehicle : listOfVehicles) {
Route route = vehicle.getRoute(); Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation(); double currentLocation = vehicle.getCurrentLocation();
@ -81,15 +83,32 @@ public class MakkahCity {
vehicle.moveToNextStreet(); vehicle.moveToNextStreet();
} }
if (!vehicle.isArrivedToDest()) { if (!vehicle.isArrivedToDest()) {
double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(), Thread t = new Thread(() -> {
try {
double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
vehicle.getCurrentLocation()+1000,vehicle)) ; vehicle.getCurrentLocation()+1000,vehicle)) ;
if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor ); 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 Sedan) vehicle.move(Sedan.MAX_FORWARD * factor );
else if (vehicle instanceof SUV) vehicle.move(SUV.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 ); else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD * factor );
}
catch (Exception e) {
//e.printStackTrace();
}
});
threadPool.add(t);
t.start();
} }
} }
} }
for (Thread t : threadPool) {
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//noise based on time of day (From PDate) //noise based on time of day (From PDate)
firstDayTimeMan.step(Calendar.MINUTE, 1); firstDayTimeMan.step(Calendar.MINUTE, 1);
//for (int i = 0; i < 46; i++) System.out.print("\b"); //for (int i = 0; i < 46; i++) System.out.print("\b");