@@ -27,11 +27,12 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
ArrayList<Integer> upResourceSupporting; // record facilities which support other facilities |
ArrayList<Integer> downResourceSupported; |
ArrayList<Integer> totalFacilities; // record the id of all facilities |
- |
+ ArrayList<Integer> Fuel_Facilities; |
|
public InfrastructureSystem(String facility_data_file) throws Exception { |
|
// read in facility data |
+ GeneralParameterNEncoding GE = new GeneralParameterNEncoding(); |
int total_entities = 0; |
// this.functioinalTree = new HashMap<>(); |
this.totalFacilities = new ArrayList<Integer>(); |
@@ -40,6 +41,7 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
this.upFunctionalSupporting = new ArrayList<Integer>(); |
this.upResourceSupporting = new ArrayList<Integer>(); |
this.downResourceSupported = new ArrayList<Integer>(); |
+ this.Fuel_Facilities = new ArrayList<>(); |
|
File inputF = new File(facility_data_file); |
InputStream inputFS = new FileInputStream(inputF); |
@@ -166,6 +168,9 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
Facility f = new Facility(id, type, functional_support, resource_supply, |
location_UTM, production, material, access_resource, up_functional_sup, res_rate); |
this.add(f); |
+ if (type == GE.FUEL_DEPOT){ |
+ this.Fuel_Facilities.add(id); |
+ } |
total_entities ++; |
} |
System.out.println("Facility data read in complete."); |
@@ -227,7 +232,6 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
} |
} |
} |
- System.out.println(this.resource_sup_upward_relationship); |
Iterator<Integer> II = this.resource_sup_upward_relationship.keySet().iterator(); |
while(II.hasNext()) { |
int cur = II.next(); |
@@ -668,7 +672,7 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
for (Integer j : f.ServiceActivityLocations){ |
temp_service = temp_service + Integer.toString(j) + ","; |
} |
- temp_service.substring(0, temp_service.length()-1); |
+ temp_service = temp_service.substring(0, temp_service.length()-1); |
temp_service += System.lineSeparator(); |
writer1.write(temp_service); |
String temp_Resource = Integer.toString(i); |
@@ -677,7 +681,7 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
for (int k : f.ResourceSupply[j]){ |
temp_Resource = temp_Resource + Integer.toString(k) + ","; |
} |
- temp_Resource.substring(0, temp_Resource.length()-1); |
+ temp_Resource = temp_Resource.substring(0, temp_Resource.length()-1); |
} |
temp_Resource += System.lineSeparator(); |
writer2.write(temp_Resource); |
@@ -686,11 +690,11 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
for (int m : f.FunctionalSupportFacility){ |
sup_fac = sup_fac + Integer.toString(m) + ","; |
} |
- sup_fac.substring(0, sup_fac.length()-1); |
+ sup_fac = sup_fac.substring(0, sup_fac.length()-1); |
for (int n : f.FunctionalSupportHousehold){ |
sup_HH = sup_HH + Integer.toString(n) + ","; |
} |
- sup_HH.substring(0, sup_HH.length()-1); |
+ sup_HH = sup_HH.substring(0, sup_HH.length()-1); |
sup_fac += System.lineSeparator(); |
sup_HH += System.lineSeparator(); |
writer3.write(sup_fac); |
@@ -714,6 +718,7 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
} |
|
public InfrastructureSystem(String function_fac, String function_hh, String resource_sup, String fac_id, String nearby_al, String details) throws IOException { |
+ GeneralParameterNEncoding GE = new GeneralParameterNEncoding(); |
this.FacilityNumber = 0; |
this.totalFacilities = new ArrayList<Integer>(); |
this.resource_sup_downward_relationship = new HashMap(); |
@@ -721,6 +726,7 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
this.upFunctionalSupporting = new ArrayList<Integer>(); |
this.upResourceSupporting = new ArrayList<Integer>(); |
this.downResourceSupported = new ArrayList<Integer>(); |
+ this.Fuel_Facilities = new ArrayList<>(); |
|
File inputF_f = new File(details); |
InputStream inputFS_f = new FileInputStream(inputF_f); |
@@ -730,6 +736,9 @@ public class InfrastructureSystem extends ArrayList<Facility> { |
String[] split_f = line_f.split(","); |
Facility f = new Facility(split_f, this.FacilityLayers); |
this.add(f); |
+ if (f.Type == GE.FUEL_DEPOT){ |
+ this.Fuel_Facilities.add(f.ID); |
+ } |
} |
|
File inputF_id = new File(fac_id); |
@@ -5,16 +5,19 @@ |
*/ |
package ficus_transims; |
|
-import java.io.IOException; |
-import java.io.File; |
-import java.io.FileReader; |
-import java.io.BufferedReader; |
+import org.graalvm.compiler.lir.sparc.SPARCArithmetic; |
+import scala.Int; |
+ |
+import java.io.*; |
import java.util.ArrayList; |
import java.util.Arrays; |
import java.util.Collections; |
import java.util.HashMap; |
import java.util.Iterator; |
|
+import static jdk.nashorn.internal.objects.Global.__LINE__; |
+import static jdk.nashorn.internal.runtime.Scope.getScopeCount; |
+ |
/** |
* |
* @author Liqun |
@@ -39,13 +42,14 @@ public class RoutingPlan { |
HashMap<Integer, ArrayList> TimeLineEvents; |
HashMap<Integer, Integer> CheckRoundTrips; // Record the final direction of each traveler so that we could determine the direction of unfinished trips |
HashMap<Integer, int[]> UnfinishedTrips; // Record the unfinished trips, key -- traveler, value -- direction |
+ HashMap<Integer, ArrayList> RemainWalkTrips; |
|
- @SuppressWarnings("empty-statement") |
public RoutingPlan(File file_name, int max_hhid) { |
|
this.badTraveler = new ArrayList(); |
this.UnfinishedTrips = new HashMap<Integer, int[]>(); |
this.CheckRoundTrips = new HashMap<Integer, Integer>(); |
+ this.RemainWalkTrips = new HashMap<>(); |
|
System.out.println("Reading in travel plan."); |
try (BufferedReader br = new BufferedReader(new FileReader(file_name))) { |
@@ -182,7 +186,7 @@ public class RoutingPlan { |
return flag; |
} |
|
- public void BuildTimeLineEvents(UrbanSystem U, int analysis_period) { |
+ public void BuildTimeLineEvents(UrbanSystem U, int analysis_period, int start_time, String loc, String write_loc) throws IOException { |
// TimeLineEvents is a hash map, each key is a time instant, and the |
// item is an array list of events that happened at this time instant, |
// the events are represented as int[] |
@@ -192,12 +196,51 @@ public class RoutingPlan { |
|
int time_line_length; |
time_line_length = getMax(this.EndTime); |
- time_line_length = Math.max(time_line_length, U.AnalysisPeriod) + 1; |
+ System.out.println("Max End Time: " + Integer.toString(time_line_length)); |
+ time_line_length = Math.min(time_line_length, start_time + analysis_period) + 1; |
+ System.out.println("Update Duration: " + Integer.toString(time_line_length)); |
|
- for (int t = 0; t < time_line_length; t++) { // Assume the trips are completed all within 2 hrs |
+ |
+ for (int t = start_time; t < time_line_length; t++) { // Assume the trips are completed all within 2 hrs |
this.TimeLineEvents.put(t, new ArrayList()); |
} |
|
+ 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 |
int o, d, t1, t2, traveler, outward_return, trip = 0, count = 0; |
ArrayList ls; |
@@ -211,7 +254,7 @@ public class RoutingPlan { |
int hh_id = traveler / 100; |
int resrc_id = traveler - hh_id * 100 - 1; |
|
- if (resrc_id < 3) { |
+ 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); |
@@ -227,15 +270,6 @@ public class RoutingPlan { |
ArrayList<Integer> HHwalk2Fuel = U.Population.HouseholdResouceAccess.get("HHWithWalkingAccess2Fuel"); |
Iterator<Household> I = U.Population.iterator(); |
trip++; |
- |
-// if (HHwalk2Fuel == null){ |
-// String msg = "Object HHwalk2Fuel is NULL"; |
-// throw new NullPointerException(msg); |
-// } |
-// if (HHwalk2Water == null){ |
-// String msg = "Object HHwalk2Water is NULL"; |
-// throw new NullPointerException(msg); |
-// } |
|
int[] origin_loc = new int[2]; |
int[] dest_loc = new int[2]; |
@@ -250,15 +284,39 @@ public class RoutingPlan { |
origin_loc = U.AL.Location[o]; |
dest_loc = U.AL.Location[d]; |
walking_time = (int) (U.Infrastructure.computeDistance(origin_loc, dest_loc)/GE.AverageTravelSpeed); |
- t1 = h.WalkDispatchTime[1] + walking_time; |
- t2 = t1 + GE.StartReturnOffset + walking_time; |
-// System.out.println(Integer.toString(h.ID) + " Dispatch Time:" + Integer.toString(h.WalkDispatchTime[1]) + " Distance: " + Double.toString(U.Infrastructure.computeDistance(origin_loc, dest_loc)) + " T1 Time: " + Integer.toString(t1) + " T2 Time: " + Integer.toString(t2)); |
- ls = this.TimeLineEvents.get(t1); |
- ls.add(new int[]{trip, o, d, 1, h.TransimsHHID, 1}); |
- this.TimeLineEvents.put(t1, ls); |
- ls = this.TimeLineEvents.get(t2); |
- ls.add(new int[]{trip, o, d, 2, h.TransimsHHID, 1}); |
- this.TimeLineEvents.put(t2, ls); |
+ t1 = (int) h.WalkDispatchTime[1] + walking_time; |
+ t2 = (int) t1 + GE.StartReturnOffset + walking_time; |
+ if (t1 < time_line_length){ |
+ ls = this.TimeLineEvents.get(t1); |
+ ls.add(new int[]{trip, o, d, 1, 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, 1, h.TransimsHHID, 1}); |
+ RemainWalkTrips.put(t1, temp); |
+ }else{ |
+ ArrayList temp = new ArrayList(); |
+ temp.add(new int[]{trip, o, d, 1, h.TransimsHHID, 1}); |
+ 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, 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) { |
@@ -270,24 +328,60 @@ public class RoutingPlan { |
walking_time = (int) (U.Infrastructure.computeDistance(origin_loc, dest_loc)/GE.AverageTravelSpeed); |
t1 = h.WalkDispatchTime[2] + walking_time; |
t2 = t1 + GE.StartReturnOffset + walking_time; |
- ls = this.TimeLineEvents.get(t1); |
- ls.add(new int[]{trip, o, d, 1, h.TransimsHHID, 2}); |
- this.TimeLineEvents.put(t1, ls); |
- ls = this.TimeLineEvents.get(t2); |
- ls.add(new int[]{trip, o, d, 2, h.TransimsHHID, 2}); |
- this.TimeLineEvents.put(t2, ls); |
+ if (t1 < time_line_length){ |
+ ls = this.TimeLineEvents.get(t1); |
+ 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++; |
} |
} |
// System.out.println("**********************TIMELINE EVENT***************************"); |
this.TripNumber = trip; |
-// clear up some memory |
-// this.Destination = null; |
-// this.Origin = null; |
-// this.StartTime = null; |
-// this.EndTime = null; |
-// this.OutwardOrReturn = null; |
-// this.Traveler = null; |
+ writeRemainWalk(write_loc); |
+ } |
+ |
+ public void writeRemainWalk(String loc) throws IOException { |
+ FileWriter writer = new FileWriter(loc + "RoutingPlan_WalkTrip.txt"); |
+ for (Integer i : RemainWalkTrips.keySet()){ |
+ String s = Integer.toString(i); |
+ for (int j = 0 ; j < RemainWalkTrips.get(i).size(); j++){ |
+ s += ";"; |
+ ArrayList list = RemainWalkTrips.get(i); |
+ for ( int k : (int[]) list.get(j)){ |
+ s = s + k +","; |
+ } |
+ s = s.substring(0, s.length() - 1); |
+ } |
+ } |
+ writer.close(); |
+ System.out.println("The remaining walking trips are written successfully "); |
} |
|
private static int getMax(int[] inputArray) { |