@@ -35,7 +35,7 @@ public class Facility implements Serializable { |
int[] upFunctionalSupFacilities; // record the upstream functional support facilities for each facilities |
// int[] supportStatus; // [How to access the resources]record the statues of upstream functional support facilities |
// int[] requiredResource; // determine the actual raw material is required by this facility. 0 is not, (10, 11, 13) is required |
- int[] access2Resources; // [How to access the resources]record the statues of upstream functional support facilities, 3 is functional support, 2 is the resource support, 1 is consuming current resource, 0 is not required |
+ int[] access2Resources; // [How to access the resources]record the statues of upstream functional support facilities, 4 is not necessary, 3 is functional support, 2 is the resource support, 1 is consuming current resource, 0 is no access to necessary resources |
|
double ProductionInventory; // |
double[] ResourceInventory; // current resource inventory level |
@@ -102,25 +102,46 @@ public class Facility implements Serializable { |
|
// Determine supply |
double supply; |
- if (this.ProductionInventory - demand > 0) { |
+ int limited = 0; |
+ int[] flag = new int[]{-1, -1, -1}; |
+ for (int k = 0; k < MaterialStorageCapacity.length; k++){ |
+ if (access2Resources[k] == 2 || access2Resources[k] == 1){ |
+ // Limited resources |
+ flag[k] = 1; // position of limited resources |
+ limited = 1; |
+ } |
+ } |
+ |
+ if (limited == 0){ |
supply = demand; |
- } else { |
- supply = this.ProductionInventory; |
- |
- // After consumption, need to check if this facility is still has production |
- for (int i = 0; i < this.MaterialStorageCapacity.length; i++) { |
- if (this.access2Resources[i] == 1) { |
- this.Status = 0; |
- this.access2Resources[i] = 0; |
- } |
+ }else{ |
+ if (this.ProductionInventory - demand > 0) { |
+ supply = demand; |
+ } else { |
+ supply = this.ProductionInventory; |
+ |
+ // After consumption, need to check if this facility is still has production |
+ for (int i = 0; i < this.MaterialStorageCapacity.length; i++) { |
+ if (this.access2Resources[i] == 1) { |
+ this.Status = 0; |
+ this.access2Resources[i] = 0; |
+ } |
+ } |
+ if (this.Status == 2) { |
+ this.Status = 1; |
+ } |
} |
- if (this.Status == 2) { |
- this.Status = 1; |
+ |
+ // Update the production inventory according to the consumption -- assume the product is processed simultaneously with the consumption of the resource |
+ this.ProductionInventory = this.ProductionInventory - supply; |
+ for (int a = 0; a < MaterialStorageCapacity.length; a++){ |
+ if (flag[a] == 1){ |
+ this.ResourceInventory[a] = this.ResourceInventory[a] - supply * ResourceConsumptionRate[a]; |
+ } |
} |
} |
- |
- // Update the production inventory according to the consumption -- assume the product is processed simultaneously with the consumption of the resource |
- this.ProductionInventory = this.ProductionInventory - supply; |
+ |
+ |
|
return supply; |
} |
@@ -174,7 +195,7 @@ public class Facility implements Serializable { |
production = Math.min(production, this.ResourceInventory[i]/this.ResourceConsumptionRate[i]); |
} |
} |
- this.ProductionInventory = Math.max(production, this.ProductionInventory); |
+ this.ProductionInventory = Math.max(production, this.ProductionCapacity); |
|
// According to the new product inventory, update the facility status |
if (this.ProductionInventory > 0 & this.Status == 1) { |
@@ -266,10 +287,10 @@ public class Facility implements Serializable { |
this.upFunctionalSupFacilities = new int[resource_layer]; |
this.access2Resources = new int[resource_layer]; |
this.ResourceSupply = new int[resource_layer][]; // resource support upstream direction -- to determine which facilities may be visited by this object to obtain resource support |
- this.Demand = new double[this.MaterialStorageCapacity.length]; |
- this.ODAL = new int[this.MaterialStorageCapacity.length][]; |
- this.VehicleDispatchTime = new int[this.MaterialStorageCapacity.length]; |
- this.ResourceDestination = new int[this.MaterialStorageCapacity.length]; |
+ this.Demand = new double[resource_layer]; |
+ this.ODAL = new int[resource_layer][2]; |
+ this.VehicleDispatchTime = new int[resource_layer]; |
+ this.ResourceDestination = new int[resource_layer]; |
this.FunctionalSupportFacility = new ArrayList<>(); // downstream direction -- to determine which facilities may obtain functional support from this object |
this.FunctionalSupportHousehold = new ArrayList<>(); // downstream direction -- to determine which facilities may visit this object |
this.ServiceActivityLocations = new ArrayList<>(); |
@@ -48,16 +48,28 @@ public class PostTRANSIMSproc { |
public String Urban_loc; |
|
@Out |
- public int[] elecXCOORD; |
+ public int[] elecXCOORD_disrupted; |
|
@Out |
- public int[] elecYCOORD; |
+ public int[] elecYCOORD_disrupted; |
|
@Out |
- public int[] waterXCOORD; |
+ public int[] waterXCOORD_disrupted; |
|
@Out |
- public int[] waterYCOORD; |
+ public int[] waterYCOORD_disrupted; |
+ |
+ @Out |
+ public int[] elecXCOORD_Recovery; |
+ |
+ @Out |
+ public int[] elecYCOORD_Recovery; |
+ |
+ @Out |
+ public int[] waterXCOORD_Recovery; |
+ |
+ @Out |
+ public int[] waterYCOORD_Recovery; |
|
@OutNode |
public AggregatedResourceSecurityOutput Aggregated_Water; |
@@ -110,10 +122,40 @@ public class PostTRANSIMSproc { |
U.WriteResultFiles(Urban_loc, U.SystemTime); |
|
GeneralParameterNEncoding GE = new GeneralParameterNEncoding(); |
- elecXCOORD = U.OutputX.get(GE.ELECCODE); |
- elecYCOORD = U.OutputY.get(GE.ELECCODE); |
- waterXCOORD = U.OutputX.get(GE.WATERCODE); |
- waterYCOORD = U.OutputY.get(GE.WATERCODE); |
+// if (U.DisruptedOutputX.get(GE.ELECCODE).length != 0){ |
+ elecXCOORD_disrupted = U.DisruptedOutputX.get(GE.ELECCODE); |
+ elecYCOORD_disrupted = U.DisruptedOutputY.get(GE.ELECCODE); |
+// }else{ |
+// elecXCOORD_disrupted = new int[]{}; |
+// elecYCOORD_disrupted = new int[]{}; |
+// } |
+ |
+// if (U.DisruptedOutputX.get(GE.WATERCODE).length != 0){ |
+ waterXCOORD_disrupted = U.DisruptedOutputX.get(GE.WATERCODE); |
+ waterYCOORD_disrupted = U.DisruptedOutputY.get(GE.WATERCODE); |
+// }else{ |
+// waterXCOORD_disrupted = new int[]{}; |
+// waterYCOORD_disrupted = new int[]{}; |
+// } |
+ |
+// if (U.RecoveryOutputX.get(GE.ELECCODE).length != 0){ |
+ elecXCOORD_Recovery = U.RecoveryOutputX.get(GE.ELECCODE); |
+ elecYCOORD_Recovery = U.RecoveryOutputY.get(GE.ELECCODE); |
+ System.out.println("Electricity recovery: " + Integer.toString(elecXCOORD_Recovery.length)); |
+// }else{ |
+// elecXCOORD_Recovery = new int[]{}; |
+// elecYCOORD_Recovery = new int[]{}; |
+// } |
+ |
+// if (U.RecoveryOutputX.get(GE.WATERCODE).length != 0){ |
+ waterXCOORD_Recovery = U.RecoveryOutputX.get(GE.WATERCODE); |
+ waterYCOORD_Recovery = U.RecoveryOutputY.get(GE.WATERCODE); |
+ System.out.println("Water recovery: " + Integer.toString(waterXCOORD_Recovery.length)); |
+// }else{ |
+// waterXCOORD_Recovery = new int[]{}; |
+// waterYCOORD_Recovery = new int[]{}; |
+// } |
+ |
|
U.Infrastructure = null; |
U.RoadNetwork = null; |
@@ -31,9 +31,14 @@ public class UrbanSystem implements Serializable { |
HashMap<Integer, Integer> HHIDReference; |
HashMap<Integer, ArrayList<Integer>> DisruptedFacilities; |
HashMap<Integer, ArrayList<Integer>> DisruptedFacilitiesX; |
- HashMap<Integer, int[]> OutputX; |
- HashMap<Integer, int[]> OutputY; |
HashMap<Integer, ArrayList<Integer>> DisruptedFacilitiesY; |
+ HashMap<Integer, int[]> DisruptedOutputX; |
+ HashMap<Integer, int[]> DisruptedOutputY; |
+ HashMap<Integer, int[]> RecoveryOutputX; |
+ HashMap<Integer, int[]> RecoveryOutputY; |
+ HashMap<Integer, ArrayList<Integer>> RecoveryFacilities; |
+ HashMap<Integer, ArrayList<Integer>> RecoveryFacilitiesX; |
+ HashMap<Integer, ArrayList<Integer>> RecoveryFacilitiesY; |
HashMap<Integer, int[]> FakeHouseholdInfor; |
HashMap<Integer, int[]> FinishedReroutingTrips; |
ArrayList<Integer> DisruptionsHappenTime; // newly added |
@@ -840,6 +845,14 @@ public class UrbanSystem implements Serializable { |
|
GeneralParameterNEncoding GE = new GeneralParameterNEncoding(); |
int id; |
+ this.DisruptedOutputX = new HashMap<>(); |
+ this.DisruptedOutputX.put(GE.WATERCODE, new int[]{}); |
+ this.DisruptedOutputX.put(GE.ELECCODE, new int[]{}); |
+ this.DisruptedOutputX.put(GE.FUELCODE, new int[]{}); |
+ this.DisruptedOutputY = new HashMap<>(); |
+ this.DisruptedOutputY.put(GE.WATERCODE, new int[]{}); |
+ this.DisruptedOutputY.put(GE.ELECCODE, new int[]{}); |
+ this.DisruptedOutputY.put(GE.FUELCODE, new int[]{}); |
this.DisruptedFacilities = new HashMap<>(); |
this.DisruptedFacilities.put(GE.ELECCODE, new ArrayList<Integer>()); |
this.DisruptedFacilities.put(GE.WATERCODE, new ArrayList<Integer>()); |
@@ -879,8 +892,6 @@ public class UrbanSystem implements Serializable { |
System.out.println(X + " is not a valid facility ID."); |
} |
} |
- this.OutputX = new HashMap<>(); |
- this.OutputY = new HashMap<>(); |
if (! failed_list.isEmpty()){ |
propogated_list = this.Infrastructure.systemDisruption(failed_list); |
Iterator<Integer> I = propogated_list.iterator(); |
@@ -898,8 +909,8 @@ public class UrbanSystem implements Serializable { |
temp = new ArrayList<Integer>(); |
} |
for (Integer m : this.DisruptedFacilities.keySet()){ |
- this.OutputX.put(m, arraylist_toArray(this.DisruptedFacilitiesX.get(m))); |
- this.OutputY.put(m, arraylist_toArray(this.DisruptedFacilitiesY.get(m))); |
+ this.DisruptedOutputX.put(m, arraylist_toArray(this.DisruptedFacilitiesX.get(m))); |
+ this.DisruptedOutputY.put(m, arraylist_toArray(this.DisruptedFacilitiesY.get(m))); |
} |
// this.determineHouseholdLostElec(this.SystemTime, this.ElecRsrOutput, this.Infrastructure, this.Population, this.DisruptedFacilities) |
} |
@@ -918,6 +929,30 @@ public class UrbanSystem implements Serializable { |
} |
|
public void systemRecover(String file_name) throws FileNotFoundException, IOException{ |
+ GeneralParameterNEncoding GE = new GeneralParameterNEncoding(); |
+ this.RecoveryOutputX = new HashMap<>(); |
+ this.RecoveryOutputX.put(GE.WATERCODE, new int[]{}); |
+ this.RecoveryOutputX.put(GE.ELECCODE, new int[]{}); |
+ this.RecoveryOutputX.put(GE.FUELCODE, new int[]{}); |
+ this.RecoveryOutputY = new HashMap<>(); |
+ this.RecoveryOutputY.put(GE.WATERCODE, new int[]{}); |
+ this.RecoveryOutputY.put(GE.ELECCODE, new int[]{}); |
+ this.RecoveryOutputY.put(GE.FUELCODE, new int[]{}); |
+ this.RecoveryFacilities = new HashMap<>(); |
+ this.RecoveryFacilities.put(GE.ELECCODE, new ArrayList<Integer>()); |
+ this.RecoveryFacilities.put(GE.WATERCODE, new ArrayList<Integer>()); |
+ this.RecoveryFacilities.put(GE.FUELCODE, new ArrayList<Integer>()); |
+ this.RecoveryFacilitiesX = new HashMap<>(); |
+ this.RecoveryFacilitiesX.put(GE.ELECCODE, new ArrayList<Integer>()); |
+ this.RecoveryFacilitiesX.put(GE.WATERCODE, new ArrayList<Integer>()); |
+ this.RecoveryFacilitiesX.put(GE.FUELCODE, new ArrayList<Integer>()); |
+ this.RecoveryFacilitiesY = new HashMap<>(); |
+ this.RecoveryFacilitiesY.put(GE.ELECCODE, new ArrayList<Integer>()); |
+ this.RecoveryFacilitiesY.put(GE.WATERCODE, new ArrayList<Integer>()); |
+ this.RecoveryFacilitiesY.put(GE.FUELCODE, new ArrayList<Integer>()); |
+ ArrayList<Integer> temp = new ArrayList<Integer>(); |
+ ArrayList<Integer> tempx = new ArrayList<Integer>(); |
+ ArrayList<Integer> tempy = new ArrayList<Integer>(); |
File inputF = new File(file_name); |
if (inputF.exists()){ |
InputStream inputFS = new FileInputStream(inputF); |
@@ -935,7 +970,27 @@ public class UrbanSystem implements Serializable { |
System.out.println(X + " is not a valid facility ID."); |
} |
} |
- this.Infrastructure.repairedFacility(recovery_list); |
+ if (! recovery_list.isEmpty()){ |
+ ArrayList propagation_list = this.Infrastructure.repairedFacility(recovery_list); |
+ Iterator<Integer> I = propagation_list.iterator(); |
+ while(I.hasNext()) { |
+ int id = I.next(); |
+ temp = this.RecoveryFacilities.get(id / 1000000); |
+ tempx = this.RecoveryFacilitiesX.get(id / 1000000); |
+ tempy = this.RecoveryFacilitiesY.get(id / 1000000); |
+ temp.add(id); |
+ tempx.add(this.Infrastructure.getFacility(id).Location[0]); |
+ tempy.add(this.Infrastructure.getFacility(id).Location[1]); |
+ this.RecoveryFacilities.put(id / 1000000, temp); |
+ this.RecoveryFacilitiesX.put(id / 1000000, tempx); |
+ this.RecoveryFacilitiesY.put(id / 1000000, tempy); |
+ temp = new ArrayList<Integer>(); |
+ } |
+ for (Integer m : this.RecoveryFacilities.keySet()){ |
+ this.RecoveryOutputX.put(m, arraylist_toArray(this.RecoveryFacilitiesX.get(m))); |
+ this.RecoveryOutputY.put(m, arraylist_toArray(this.RecoveryFacilitiesY.get(m))); |
+ } |
+ } |
} |
} |
|