@@ -158,42 +158,120 @@ public class Population extends ArrayList<Household> { |
|
// Below are operation function |
|
- |
- public void assignTripOD(InfrastructureSystem S, ActivityLocation AL) { |
- System.out.println("Assigning population trip OD."); |
+ public void assignResourceDest(InfrastructureSystem S, ActivityLocation AL, int period){ |
+ System.out.println("Assign resource destination begins"); |
+ GeneralParameterNEncoding GE = new GeneralParameterNEncoding(); |
+ Progress pr = new Progress(this.TotalHouseholds); |
Iterator<Household> I = this.iterator(); |
- Progress pr = new Progress(this.size()); |
+ double estimated_time; |
+ int r; |
while (I.hasNext()) { |
Household h = I.next(); |
- pr.makeProgress(); |
- for (int r = 0; r < h.ResourceInventory.length; r++) { |
+ r = 1; |
+ if ((! h.waterFunction) && (! this.HouseholdResouceAccess.get("HHWithNoAccess2Water").contains(h.ID))){ |
+ // find resource destination |
+ int dest = S.nearestResourceFacility(h.Location, h.ResourceSupplyFacilityTypes[r]); |
+ h.ResourceDestination[r] = dest; |
+ Facility f = S.get(dest); |
+ double dist = S.computeDistance(h.Location, f.Location); |
+ |
+ // estimate resource replenishment time |
+ if (h.WithVehicle){ |
+ estimated_time = 2 * dist / GE.AverageTravelSpeed + GE.StartReturnOffset; |
+ }else{ |
+ estimated_time = 2 * dist / GE.AverageWalkSpeed + GE.StartReturnOffset; |
+ } |
+ h.ReplenishThreshold[r] = Math.min(h.MaterialStorageCapacity[r], h.ConsumptionRate[r] * estimated_time / 3600); |
+ |
+ // determine demand and dispatch time |
+ int dispatch_time = h.determineWaterDemand(period); |
+ if (this.HouseholdResouceAccess.get("HHWithWalkingAccess2Water").contains(h.ID)){ |
+ h.WalkDispatchTime[r] = dispatch_time; |
+ h.VehicleDispatchTime[r] = -1; |
+ } else if (this.HouseholdResouceAccess.get("HHWithDrivingAccess2Water").contains(h.ID)) { |
+ h.WalkDispatchTime[r] = -1; |
+ h.VehicleDispatchTime[r] = dispatch_time; |
+ } |
+ |
+ // if positive demand, assign trip od |
if (h.Demand[r] > 0) { |
h.ODAL[r] = new int[2]; |
h.ODAL[r][0] = h.ActivityLocation; |
- int dest = S.nearestResourceFacility(h.Location, h.ResourceSupplyFacilityTypes[r]); |
- if (dest != -1) { |
- h.ResourceDestination[r] = dest; |
- int dest_al = S.get(dest).NearestAL; |
- if (AL.LinkNumber[dest_al] != AL.LinkNumber[h.ActivityLocation]) { |
- h.ODAL[r][1] = dest_al; |
- } else { |
- for (Integer i : S.get(dest).ServiceActivityLocations) { |
- if (AL.LinkNumber[i] != AL.LinkNumber[h.ActivityLocation]) { |
- h.ODAL[r][1] = i; |
- break; |
- } |
+ int dest_al = f.NearestAL; |
+ if (AL.LinkNumber[dest_al] != AL.LinkNumber[h.ActivityLocation]) { |
+ h.ODAL[r][1] = dest_al; |
+ } else { |
+ for (Integer i : f.ServiceActivityLocations) { |
+ if (AL.LinkNumber[i] != AL.LinkNumber[h.ActivityLocation]) { |
+ h.ODAL[r][1] = i; |
+ break; |
} |
} |
+ } |
+ } |
+ }else{ |
+ h.Demand[r] = 0; |
+ h.VehicleDispatchTime[r] = -1; |
+ h.WalkDispatchTime[r] = -1; |
+ } |
+ r = 2; |
+ if ((! h.fuelNecessity) || this.HouseholdResouceAccess.get("HHWithNoAccess2Fuel").contains(h.ID)){ |
+ h.Demand[r] = 0; |
+ h.VehicleDispatchTime[r] = -1; |
+ h.WalkDispatchTime[r] = -1; |
+ }else{ |
+ int dest = S.nearestResourceFacility(h.Location, h.ResourceSupplyFacilityTypes[r]); |
+ h.ResourceDestination[r] = dest; |
+ Facility f = S.get(dest); |
+ double dist = S.computeDistance(h.Location, f.Location); |
+ if (h.WithVehicle){ |
+ estimated_time = 2 * dist / GE.AverageTravelSpeed + GE.StartReturnOffset; |
+ }else{ |
+ estimated_time = 2 * dist / GE.AverageWalkSpeed + GE.StartReturnOffset; |
+ } |
+ h.ReplenishThreshold[r] = Math.min(h.MaterialStorageCapacity[r], h.ConsumptionRate[r] * estimated_time / 3600); |
+ int dispatch_time = h.determineFuelDemand(period); |
+ if (this.HouseholdResouceAccess.get("HHWithWalkingAccess2Fuel").contains(h.ID)){ |
+ h.WalkDispatchTime[r] = dispatch_time; |
+ h.VehicleDispatchTime[r] = -1; |
+ } else if (this.HouseholdResouceAccess.get("HHWithDrivingAccess2Fuel").contains(h.ID)) { |
+ h.WalkDispatchTime[r] = -1; |
+ h.VehicleDispatchTime[r] = dispatch_time; |
+ } |
+ if (h.Demand[r] > 0) { |
+ h.ODAL[r] = new int[2]; |
+ h.ODAL[r][0] = h.ActivityLocation; |
+ int dest_al = f.NearestAL; |
+ if (AL.LinkNumber[dest_al] != AL.LinkNumber[h.ActivityLocation]) { |
+ h.ODAL[r][1] = dest_al; |
} else { |
- System.out.println("There is no available resource destination " |
- + "for community " + h.ID + " for demand type " + r); |
+ for (Integer i : f.ServiceActivityLocations) { |
+ if (AL.LinkNumber[i] != AL.LinkNumber[h.ActivityLocation]) { |
+ h.ODAL[r][1] = i; |
+ break; |
+ } |
+ } |
} |
} |
} |
+ pr.makeProgress(); |
} |
- System.out.println("Population trip OD assignment complete."); |
} |
|
+// public void assignTripOD(InfrastructureSystem S, ActivityLocation AL) { |
+// System.out.println("Assigning population trip OD."); |
+// Iterator<Household> I = this.iterator(); |
+// Progress pr = new Progress(this.size()); |
+// while (I.hasNext()) { |
+// Household h = I.next(); |
+// pr.makeProgress(); |
+// for (int r = 0; r < h.ResourceInventory.length; r++) { |
+// |
+// } |
+// } |
+// System.out.println("Population trip OD assignment complete."); |
+// } |
+ |
@Override |
public Household get(int household_ID) { |
return this.getHousehold(household_ID); |
@@ -299,41 +377,41 @@ public class Population extends ArrayList<Household> { |
GE.WalkDistance + " meters, and without vehicles."); |
} |
|
- public void updateDemand(int analysis_period) { |
- GeneralParameterNEncoding GE = new GeneralParameterNEncoding(); |
- Iterator<Household> I = this.iterator(); |
- while(I.hasNext()){ |
- Household h = I.next(); |
- int[] dispatch_time = h.determineResourceDemand(analysis_period); |
- if (h.waterFunction || this.HouseholdResouceAccess.get("HHWithNoAccess2Water").contains(h.ID)){ |
- h.Demand[1] = 0; |
- h.VehicleDispatchTime[1] = -1; |
- h.WalkDispatchTime[1] = -1; |
- }else{ |
- if (this.HouseholdResouceAccess.get("HHWithWalkingAccess2Water").contains(h.ID)){ |
- h.WalkDispatchTime[1] = dispatch_time[0]; |
- h.VehicleDispatchTime[1] = -1; |
- } else if (this.HouseholdResouceAccess.get("HHWithDrivingAccess2Water").contains(h.ID)) { |
- h.WalkDispatchTime[1] = -1; |
- h.VehicleDispatchTime[1] = dispatch_time[0]; |
- } |
- } |
- |
- if ((! h.fuelNecessity) || this.HouseholdResouceAccess.get("HHWithNoAccess2Fuel").contains(h.ID)){ |
- h.Demand[2] = 0; |
- h.VehicleDispatchTime[2] = -1; |
- h.WalkDispatchTime[2] = -1; |
- }else{ |
- if (this.HouseholdResouceAccess.get("HHWithWalkingAccess2Fuel").contains(h.ID)){ |
- h.WalkDispatchTime[2] = dispatch_time[1]; |
- h.VehicleDispatchTime[2] = -1; |
- } else if (this.HouseholdResouceAccess.get("HHWithDrivingAccess2Fuel").contains(h.ID)) { |
- h.WalkDispatchTime[2] = -1; |
- h.VehicleDispatchTime[2] = dispatch_time[1]; |
- } |
- } |
- } |
- } |
+// public void updateDemand(int analysis_period) { |
+// GeneralParameterNEncoding GE = new GeneralParameterNEncoding(); |
+// Iterator<Household> I = this.iterator(); |
+// while(I.hasNext()){ |
+// Household h = I.next(); |
+// int[] dispatch_time = h.determineResourceDemand(analysis_period); |
+// if (h.waterFunction || this.HouseholdResouceAccess.get("HHWithNoAccess2Water").contains(h.ID)){ |
+// h.Demand[1] = 0; |
+// h.VehicleDispatchTime[1] = -1; |
+// h.WalkDispatchTime[1] = -1; |
+// }else{ |
+// if (this.HouseholdResouceAccess.get("HHWithWalkingAccess2Water").contains(h.ID)){ |
+// h.WalkDispatchTime[1] = dispatch_time[0]; |
+// h.VehicleDispatchTime[1] = -1; |
+// } else if (this.HouseholdResouceAccess.get("HHWithDrivingAccess2Water").contains(h.ID)) { |
+// h.WalkDispatchTime[1] = -1; |
+// h.VehicleDispatchTime[1] = dispatch_time[0]; |
+// } |
+// } |
+// |
+// if ((! h.fuelNecessity) || this.HouseholdResouceAccess.get("HHWithNoAccess2Fuel").contains(h.ID)){ |
+// h.Demand[2] = 0; |
+// h.VehicleDispatchTime[2] = -1; |
+// h.WalkDispatchTime[2] = -1; |
+// }else{ |
+// if (this.HouseholdResouceAccess.get("HHWithWalkingAccess2Fuel").contains(h.ID)){ |
+// h.WalkDispatchTime[2] = dispatch_time[1]; |
+// h.VehicleDispatchTime[2] = -1; |
+// } else if (this.HouseholdResouceAccess.get("HHWithDrivingAccess2Fuel").contains(h.ID)) { |
+// h.WalkDispatchTime[2] = -1; |
+// h.VehicleDispatchTime[2] = dispatch_time[1]; |
+// } |
+// } |
+// } |
+// } |
|
// public void resourceDepletion(int seconds, String water_file_name, String fuel_file_name, String time_stamp) { |
// ArrayList<Integer> HHconsumesWater = new ArrayList<>(this.HouseholdResouceAccess.get("HHWithWalkingAccess2Water")); |
@@ -200,6 +200,26 @@ public class RoutingPlan { |
this.TimeLineEvents.put(t, new ArrayList()); |
} |
|
+ while (count < this.TripNumber) { |
+ o = this.Origin[count]; |
+ d = this.Destination[count]; |
+ t1 = this.EndTime[count]; |
+ outward_return = this.OutwardOrReturn[count]; |
+ traveler = this.Traveler[count]; |
+ |
+ int hh_id = traveler / 100; |
+ int resrc_id = traveler - hh_id * 100 - 1; |
+ |
+ if (resrc_id < 3 && t1 < time_line_length) { |
+ ls = this.TimeLineEvents.get(t1); |
+ ls.add(new int[]{trip, o, d, outward_return, hh_id, resrc_id}); |
+ this.TimeLineEvents.put(t1, ls); |
+ if (outward_return == 1) { |
+ trip++; |
+ } |
+ } |
+ } |
+ |
// add the walking accesses |
ArrayList<Integer> HHwalk2Water = U.Population.HouseholdResouceAccess.get("HHWithWalkingAccess2Water"); |
ArrayList<Integer> HHwalk2Fuel = U.Population.HouseholdResouceAccess.get("HHWithWalkingAccess2Fuel"); |
@@ -213,9 +233,8 @@ public class RoutingPlan { |
while (I.hasNext()) { |
Household h = I.next(); |
if (HHwalk2Water.contains(h.ID) && h.Demand[1] > 0) { |
- Facility f = U.Infrastructure.get(h.ResourceDestination[1]); |
- o = h.ActivityLocation; |
- d = f.NearestAL; |
+ o = h.ODAL[1][0]; |
+ d = h.ODAL[1][1]; |
origin_loc = U.AL.Location[o]; |
dest_loc = U.AL.Location[d]; |
walking_time = (int) (U.Infrastructure.computeDistance(origin_loc, dest_loc)/GE.AverageWalkSpeed); |
@@ -223,7 +242,6 @@ public class RoutingPlan { |
t2 = t1 + GE.StartReturnOffset + walking_time; |
if (t1 < time_line_length){ |
ls = this.TimeLineEvents.get(t1); |
-// System.out.println("Line 291. If ls is empty: " + Boolean.toString(ls.isEmpty()) + "Trip : " + Integer.toString(trip) + " TRANSIMS_HHID : " + Integer.toString(h.TransimsHHID) + " Origin: " + Integer.toString(o) + " Destination: " + Integer.toString(d)); |
ls.add(new int[]{trip, o, d, 1, h.TransimsHHID, 1}); |
this.TimeLineEvents.put(t1, ls); |
} |
@@ -233,23 +251,11 @@ public class RoutingPlan { |
ls.add(new int[]{trip, o, d, 2, h.TransimsHHID, 1}); |
this.TimeLineEvents.put(t1, ls); |
} |
-// else{ |
-// if (RemainWalkTrips.containsKey(t1)){ |
-// ArrayList temp = RemainWalkTrips.get(t1); |
-// temp.add(new int[]{trip, o, d, 2, h.TransimsHHID, 1}); |
-// RemainWalkTrips.put(t1, temp); |
-// }else{ |
-// ArrayList temp = new ArrayList(); |
-// temp.add(new int[]{trip, o, d, 2, h.TransimsHHID, 1}); |
-// RemainWalkTrips.put(t1, temp); |
-// } |
-// } |
trip++; |
} |
if (HHwalk2Fuel.contains(h.ID) && h.Demand[2] > 0) { |
- Facility f = U.Infrastructure.get(h.ResourceDestination[2]); |
- o = h.ActivityLocation; |
- d = f.NearestAL; |
+ o = h.ODAL[2][0]; |
+ d = h.ODAL[2][1]; |
origin_loc = U.AL.Location[o]; |
dest_loc = U.AL.Location[d]; |
walking_time = (int) (U.Infrastructure.computeDistance(origin_loc, dest_loc)/GE.AverageWalkSpeed); |
@@ -260,104 +266,22 @@ public class RoutingPlan { |
ls.add(new int[]{trip, o, d, 1, h.TransimsHHID, 2}); |
this.TimeLineEvents.put(t1, ls); |
} |
-// else{ |
-// if (RemainWalkTrips.containsKey(t1)){ |
-// ArrayList temp = RemainWalkTrips.get(t1); |
-// temp.add(new int[]{trip, o, d, 1, h.TransimsHHID, 2}); |
-// RemainWalkTrips.put(t1, temp); |
-// }else{ |
-// ArrayList temp = new ArrayList(); |
-// temp.add(new int[]{trip, o, d, 1, h.TransimsHHID, 2}); |
-// RemainWalkTrips.put(t1, temp); |
-// } |
-// } |
t1 = t2; |
if (t1 < time_line_length){ |
ls = this.TimeLineEvents.get(t1); |
ls.add(new int[]{trip, o, d, 2, h.TransimsHHID, 2}); |
this.TimeLineEvents.put(t1, ls); |
} |
-// else{ |
-// if (RemainWalkTrips.containsKey(t1)){ |
-// ArrayList temp = RemainWalkTrips.get(t1); |
-// temp.add(new int[]{trip, o, d, 2, h.TransimsHHID, 2}); |
-// RemainWalkTrips.put(t1, temp); |
-// }else{ |
-// ArrayList temp = new ArrayList(); |
-// temp.add(new int[]{trip, o, d, 2, h.TransimsHHID, 2}); |
-// RemainWalkTrips.put(t1, temp); |
-// } |
-// } |
trip++; |
} |
} |
|
- if (this.TripNumber == 0){ |
- System.out.println("No vehicle trips in the routing plan."); |
- return; |
- }else{ |
- |
-// File input = new File(loc); |
-// if (input.exists()){ |
-// InputStream inputFS = new FileInputStream(input); |
-// BufferedReader br = new BufferedReader(new InputStreamReader(inputFS)); |
-// String line; |
-// int count; |
-// while((line = br.readLine()) != null){ |
-// String[] splitline = line.split(";"); |
-// int length = splitline.length - 1; |
-// Integer key = Integer.parseInt(splitline[0]); |
-// int[] temp = new int[5]; |
-// for (int j = 0; j < length; j++){ |
-// count = 0; |
-// for (String s : splitline[j].split(",")){ |
-// temp[count] = Integer.parseInt(s); |
-// count++; |
-// } |
-// if (key < time_line_length){ |
-// ArrayList list = this.TimeLineEvents.get(key); |
-// list.add(temp); |
-// this.TimeLineEvents.put(key, list); |
-// }else{ |
-// if (this.RemainWalkTrips.containsKey(key)){ |
-// ArrayList list = this.RemainWalkTrips.get(key); |
-// list.add(temp); |
-// this.RemainWalkTrips.put(key, list); |
-// }else{ |
-// ArrayList list = new ArrayList(); |
-// list.add(temp); |
-// this.RemainWalkTrips.put(key, list); |
-// } |
-// } |
-// } |
-// } |
-// } |
|
// build timeline events based on the traffic |
|
- while (count < this.TripNumber) { |
- o = this.Origin[count]; |
- d = this.Destination[count]; |
- t1 = this.EndTime[count]; |
- outward_return = this.OutwardOrReturn[count]; |
- traveler = this.Traveler[count]; |
- |
- int hh_id = traveler / 100; |
- int resrc_id = traveler - hh_id * 100 - 1; |
|
- if (resrc_id < 3 && t1 < time_line_length) { |
- ls = this.TimeLineEvents.get(t1); |
- ls.add(new int[]{trip, o, d, outward_return, hh_id, resrc_id}); |
- this.TimeLineEvents.put(t1, ls); |
- if (outward_return == 1) { |
- trip++; |
- } |
- } |
- count++; |
- } |
- this.TripNumber = trip; |
-// writeRemainWalk(write_loc); |
- } |
+ this.TripNumber = trip; |
+ System.out.println("Total number of trips: " + trip); |
|
} |
|