Displaying differences for changeset
 
display as  

src/main/java/ficus_transims/AggregatedFacilityStatusOutput.java

@@ -12,11 +12,10 @@ import java.util.HashMap;
  * @author Liqun
  */
 public class AggregatedFacilityStatusOutput extends HashMap<String,int[]>{
-//    public String ResourceType;
-//
-//    public AggregatedFacilityStatusOutput(String resource_type){
-//        this.ResourceType = resource_type;
-//    }
+    public String ResourceType;
+
+    public AggregatedFacilityStatusOutput(String resource_type){
+        this.ResourceType = resource_type;
+    }
 
-    public AggregatedFacilityStatusOutput(){}
 }

src/main/java/ficus_transims/Facility.java

@@ -65,13 +65,13 @@ public class Facility implements Serializable {
         this.FunctionalSupportHousehold = new ArrayList<>(); // downstream direction -- to determine which facilities may visit this object
         this.ServiceActivityLocations = new ArrayList<>();
         for (int i = 0; i<functional_support.length;i++){
-            if ( functional_support[i] / 1000000 != 99){
+            if ( functional_support[i] != 0 && functional_support[i] / 1000000 != 99){
                 flag = 1;
                 this.FunctionalSupportFacility.add(functional_support[i]);
             }
-            if (flag == 0 & functional_support[0] != 0) {
-                this.FunctionalSupportFacility.add(0);
-            }
+        }
+        if (flag == 0) {
+            this.FunctionalSupportFacility.add(0);
         }
         
         this.ResourceSupply = resource_support.clone(); // resource support upstream direction -- to determine which facilities may be visited by this object to obtain resource support

src/main/java/ficus_transims/InfrastructureSystem.java

@@ -65,7 +65,6 @@ public class InfrastructureSystem extends ArrayList<Facility> {
             
             //functional support
             String tempLongString = splitline[2];
-//            ArrayList<Integer> down = new ArrayList<>();
             int[] functional_support;
             if (!tempLongString.isEmpty()){
                 this.upFunctionalSupporting.add(id);
@@ -184,7 +183,6 @@ public class InfrastructureSystem extends ArrayList<Facility> {
         Iterator<Integer> I = this.upFunctionalSupporting.iterator();
         int id_code;
         while(I.hasNext()) {
-            int facility_id = I.next();
             Facility f = this.get(I.next());
             Iterator<Integer> II = f.FunctionalSupportFacility.iterator();
             while(II.hasNext()) {

src/main/java/ficus_transims/Population.java

@@ -510,7 +510,7 @@ public class Population extends ArrayList<Household> {
                 continue;
             }else {
                 if (wt_has_rs - hh_water_infor[2] == 1) {
-                    hh_water_infor[4] = hh_water_infor[4] + time - hh_water_infor[3];
+                    hh_water_infor[4] = hh_water_infor[4] + (int) ((time - hh_water_infor[3])/3.6*h.ConsumptionRate[1]);
                 }
                 hh_water_infor[2] = wt_has_rs;
                 hh_water_infor[3] = time;
@@ -522,7 +522,7 @@ public class Population extends ArrayList<Household> {
                 continue;
             }else {
                 if (fl_has_rs - hh_fuel_infor[2] == 1) {
-                    hh_fuel_infor[4] = hh_fuel_infor[4] + time - hh_fuel_infor[3];
+                    hh_fuel_infor[4] = hh_fuel_infor[4] + (int)((time - hh_fuel_infor[3])/3.6*h.ConsumptionRate[2]);
                 }
                 hh_fuel_infor[2] = fl_has_rs;
                 hh_fuel_infor[3] = time;

src/main/java/ficus_transims/PostTRANSIMSproc.java

@@ -15,6 +15,7 @@ import oms3.annotations.In;
 import oms3.annotations.InNode;
 import oms3.annotations.Out;
 import oms3.annotations.OutNode;
+import org.bouncycastle.jce.exception.ExtIOException;
 
 /**
  *
@@ -52,15 +53,24 @@ public class PostTRANSIMSproc {
     
     @OutNode
     public AggregatedResourceSecurityOutput Aggregated_Fuel;
+
+    @OutNode
+    public AggregatedResourceSecurityOutput Aggregated_Elec;
     
-//    @OutNode
-//    public AggregatedFacilityStatusOutput Aggregated_Water_FacilityStat;
-//
-//    @OutNode
-//    public AggregatedFacilityStatusOutput Aggregated_Fuel_FacilityStat;
+    @OutNode
+    public AggregatedFacilityStatusOutput Aggregated_Water_FacilityStat;
+
+    @OutNode
+    public AggregatedFacilityStatusOutput Aggregated_Fuel_FacilityStat;
 
     @OutNode
-    public AggregatedFacilityStatusOutput Aggregated_FacilityStat;
+    public AggregatedFacilityStatusOutput Aggregated_Water_Function;
+
+    @OutNode
+    public AggregatedFacilityStatusOutput Aggregated_Elec_Function;
+
+//    @OutNode
+//    public AggregatedFacilityStatusOutput Aggregated_FacilityStat;
     
     @Execute
     public void exec() throws IOException {
@@ -81,12 +91,14 @@ public class PostTRANSIMSproc {
         RP.BuildTimeLineEvents(U, U.AnalysisPeriod, U.SystemTime, remaining_walk_loc, Urban_loc);
         U.PostTransimsSimulation(RP, U.AL, loc);
         
-        
-//        Aggregated_Water_FacilityStat = U.AggWaterFacilityStatus;
-//        Aggregated_Fuel_FacilityStat = U.AggFuelFacilityStatus;
-        Aggregated_FacilityStat = U.AggFacilityStatus;
+        Aggregated_Elec_Function = U.Agg_ELEC_Initial;
+        Aggregated_Water_Function = U.Agg_WATER_Initial;
+        Aggregated_Water_FacilityStat = U.AggWaterFacilityStatus;
+        Aggregated_Fuel_FacilityStat = U.AggFuelFacilityStatus;
+//        Aggregated_FacilityStat = U.AggFacilityStatus;
         Aggregated_Water = U.AggWaterOutput;
         Aggregated_Fuel = U.AggFuelOutput;
+        Aggregated_Elec = U.AggElecOutput;
 
         // Write population status
         U.Population.write_All_Households(Urban_loc);
@@ -103,16 +115,14 @@ public class PostTRANSIMSproc {
         U.RoadNetwork.WriteNodeLinkConnection(Urban_loc);
 
         U.WriteUrbanStates(Urban_loc);
-        U.WriteResultFiles(Urban_loc, U.SystemTime);
-
-
+        U.WriteFUnctionalFailure(Urban_loc, "Output_Water_Function.txt", U.Agg_WATER_Initial);
+        U.WriteFUnctionalFailure(Urban_loc, "Output_Elec_Function.txt", U.Agg_ELEC_Initial);
+        U.WriteFUnctionalFailure(Urban_loc, "Output_Water_Resource.txt", U.AggWaterFacilityStatus);
+        U.WriteFUnctionalFailure(Urban_loc, "Output_Fuel_Resource.txt", U.AggFuelFacilityStatus);
+        U.WriteHHShortage(Urban_loc, "Output_Fuel.txt", U.AggFuelOutput);
+        U.WriteHHShortage(Urban_loc, "Output_Water.txt", U.AggWaterOutput);
+        U.WriteHHShortage(Urban_loc, "Output_Elec.txt", U.AggElecOutput);
 
-        U.Infrastructure = null;
-        U.RoadNetwork = null;
-        U.Population = null;
-        U.AL = null;
-        U = null;
-        System.gc();
     }
     
     private void checkTravelPlansIndex() {

src/main/java/ficus_transims/PreTRANSIMSproc.java

@@ -74,10 +74,10 @@ public class PreTRANSIMSproc {
     public void exec() {
        
         try {
-            U.systemDisruption(disruption_filename);
+            U.systemDisruption(disruption_filename, U.Agg_ELEC_Initial, U.Agg_WATER_Initial);
             System.out.println("System Failure Propagation is finished");
             String recovery_filename = recovery_loc + startDate + recovery_name;
-            U.systemRecover(recovery_filename);
+            U.systemRecover(recovery_filename, U.Agg_ELEC_Initial, U.Agg_WATER_Initial);
             System.out.println("System Recovery Propagation is finished");
 
             U.update_Aggreagted_Results();

src/main/java/ficus_transims/RoutingPlan.java

@@ -340,9 +340,6 @@ public class RoutingPlan {
             traveler = this.Traveler[count];
 
             int hh_id = traveler / 100;
-            if (hh_id == 0) {
-                System.out.println(count);
-            }
             
             int resrc_id = traveler - hh_id * 100 - 1;
 
@@ -350,7 +347,7 @@ public class RoutingPlan {
                 ls = this.TimeLineEvents.get(t1);
                 ls.add(new int[]{trip, o, d, outward_return, hh_id, resrc_id});
                 if (hh_id == 0){
-                    System.out.println(Arrays.toString(new int[]{trip, o, d, outward_return, hh_id, resrc_id}));
+                    //System.out.println(Arrays.toString(new int[]{trip, o, d, outward_return, hh_id, resrc_id}));
                 }
                 if (outward_return == 1) {
                     trip++;

src/main/java/ficus_transims/UrbanSysInit.java

@@ -84,13 +84,22 @@ public class UrbanSysInit {
     public String Urban_Fuel;
 
     @In
-    public String Urban_Facility;
+    public String Urban_Elec;
 
 //    @In
-//    public String Urban_Water_Facility;
-//
-//    @In
-//    public String Urban_Fuel_Facility;
+//    public String Urban_Facility;
+
+    @In
+    public String Urban_Water_Facility;
+
+    @In
+    public String Urban_Fuel_Facility;
+
+    @In
+    public String Urban_Elec_Function;
+
+    @In
+    public String Urban_Water_Function;
 
     @Out
     public UrbanSystem U;
@@ -136,9 +145,12 @@ public class UrbanSysInit {
             U.Initialize_UrbanStates(Urban_hhid_reference, Urban_vehicle_owner);
             U.Initialize_ResourceOutput(Urban_Water, U.AggWaterOutput);
             U.Initialize_ResourceOutput(Urban_Fuel, U.AggFuelOutput);
-            U.Initialize_FacilityResourceOutput(Urban_Facility, U.AggFacilityStatus);
-//            U.Initialize_FacilityResourceOutput(Urban_Water_Facility, U.AggWaterFacilityStatus);
-//            U.Initialize_FacilityResourceOutput(Urban_Fuel_Facility, U.AggFuelFacilityStatus);
+            U.Initialize_ResourceOutput(Urban_Elec, U.AggElecOutput);
+//            U.Initialize_FacilityResourceOutput(Urban_Facility, U.AggFacilityStatus);
+            U.Initialize_FacilityResourceOutput(Urban_Water_Facility, U.AggWaterFacilityStatus);
+            U.Initialize_FacilityResourceOutput(Urban_Fuel_Facility, U.AggFuelFacilityStatus);
+            U.Initialize_FacilityResourceOutput(Urban_Elec_Function, U.Agg_ELEC_Initial);
+            U.Initialize_FacilityResourceOutput(Urban_Water_Function, U.Agg_WATER_Initial);
             System.out.println("Urban system initilization finished ");
         }
 

src/main/java/ficus_transims/UrbanSystem.java

@@ -51,21 +51,27 @@ public class UrbanSystem implements Serializable {
     ResourceSecurityOutput FuelRsrOutput;
     AggregatedResourceSecurityOutput AggWaterOutput;
     AggregatedResourceSecurityOutput AggFuelOutput;
+    AggregatedResourceSecurityOutput AggElecOutput;
     FacilityStatusOutput FacilityStatus;
-    AggregatedFacilityStatusOutput AggFacilityStatus;
-//    AggregatedFacilityStatusOutput AggWaterFacilityStatus;
-//    AggregatedFacilityStatusOutput AggFuelFacilityStatus;
+//    AggregatedFacilityStatusOutput AggFacilityStatus;
+    AggregatedFacilityStatusOutput AggWaterFacilityStatus;
+    AggregatedFacilityStatusOutput AggFuelFacilityStatus;
+    AggregatedFacilityStatusOutput Agg_ELEC_Initial;
+    AggregatedFacilityStatusOutput Agg_WATER_Initial;
 
     public UrbanSystem(InfrastructureSystem I, Population P, RoadNetwork N, ActivityLocation AL, int time, int period) {
-        WaterRsrOutput = new ResourceSecurityOutput("Water");
-        FuelRsrOutput = new ResourceSecurityOutput("Fuel");
+//        WaterRsrOutput = new ResourceSecurityOutput("Water");
+//        FuelRsrOutput = new ResourceSecurityOutput("Fuel");
         AggWaterOutput = new AggregatedResourceSecurityOutput("Water");
         AggFuelOutput = new AggregatedResourceSecurityOutput("Fuel");
-        FacilityStatus = new FacilityStatusOutput();
-        AggFacilityStatus = new AggregatedFacilityStatusOutput();
+        AggElecOutput = new AggregatedResourceSecurityOutput("Elec");
+//        FacilityStatus = new FacilityStatusOutput();
+//        AggFacilityStatus = new AggregatedFacilityStatusOutput();
         SupplementaryTrips = new ArrayList<>();
-//        AggWaterFacilityStatus = new AggregatedFacilityStatusOutput("Water");
-//        AggFuelFacilityStatus = new AggregatedFacilityStatusOutput("Fuel");
+        AggWaterFacilityStatus = new AggregatedFacilityStatusOutput("Water");
+        AggFuelFacilityStatus = new AggregatedFacilityStatusOutput("Fuel");
+        Agg_ELEC_Initial = new AggregatedFacilityStatusOutput("Elec_Function");
+        Agg_WATER_Initial = new AggregatedFacilityStatusOutput("Water_Function");
         this.RoadNetwork = N;
         this.Infrastructure = I;
         this.Population = P;
@@ -80,21 +86,24 @@ public class UrbanSystem implements Serializable {
         assignHHIDandVHID();
         estimateInfrastructureServiceCapacity();
         buildFunctionalSupportToHousehold();
-        initHouseholdState(AggWaterOutput, AggFuelOutput);
-        initFacilityState(AggFacilityStatus);
-//        initFacilityState(AggWaterFacilityStatus, AggFuelFacilityStatus);
+        initHouseholdState(AggWaterOutput, AggFuelOutput, AggElecOutput);
+//        initFacilityState(AggFacilityStatus);
+        initFacilityState(AggWaterFacilityStatus, AggFuelFacilityStatus);
     }
 
     public UrbanSystem(InfrastructureSystem I, Population P, RoadNetwork N, ActivityLocation AL, int time, int period, int i) {
-        WaterRsrOutput = new ResourceSecurityOutput("Water");
-        FuelRsrOutput = new ResourceSecurityOutput("Fuel");
+//        WaterRsrOutput = new ResourceSecurityOutput("Water");
+//        FuelRsrOutput = new ResourceSecurityOutput("Fuel");
         AggWaterOutput = new AggregatedResourceSecurityOutput("Water");
         AggFuelOutput = new AggregatedResourceSecurityOutput("Fuel");
-        FacilityStatus = new FacilityStatusOutput();
-        AggFacilityStatus = new AggregatedFacilityStatusOutput();
+        AggElecOutput = new AggregatedResourceSecurityOutput("Elec");
+//        FacilityStatus = new FacilityStatusOutput();
+//        AggFacilityStatus = new AggregatedFacilityStatusOutput();
         this.SupplementaryTrips = new ArrayList<>();
-//        AggWaterFacilityStatus = new AggregatedFacilityStatusOutput("Water");
-//        AggFuelFacilityStatus = new AggregatedFacilityStatusOutput("Fuel");
+        AggWaterFacilityStatus = new AggregatedFacilityStatusOutput("Water");
+        AggFuelFacilityStatus = new AggregatedFacilityStatusOutput("Fuel");
+        Agg_ELEC_Initial = new AggregatedFacilityStatusOutput("Elec_Function");
+        Agg_WATER_Initial = new AggregatedFacilityStatusOutput("Water_Function");
         this.RoadNetwork = N;
         this.Infrastructure = I;
         this.Population = P;
@@ -402,7 +411,6 @@ public class UrbanSystem implements Serializable {
 //                this.Infrastructure.recordAggregatedFacilityStatus(this.SystemTime, this.AggFacilityStatus);
 //                this.Infrastructure.recordFacilityStatus(this.SystemTime, this.FacilityStatus);
 //                new_failed = new ArrayList<Integer>();
-//                System.out.println(TF.Seconds2HMS(this.SystemTime));
             }
 
             // For events within each time step, update the product inventory according to the refill
@@ -472,54 +480,198 @@ public class UrbanSystem implements Serializable {
                 }
             }
         }
-        for (String s : this.AggFacilityStatus.keySet()){
-            int id = Integer.parseInt(s);
-            int[] temp = this.AggFacilityStatus.get(s);
-            int amount = 0;
-            if (unfulfilled_demand.containsKey(id)){
-                amount = (int) (1000*unfulfilled_demand.get(id));
-            }
-            temp[3] = this.SystemTime;
-            temp[4] = temp[4] + amount;
-            this.AggFacilityStatus.put(s, temp);
-        }
-//        for (String s : this.AggFuelFacilityStatus.keySet()){
+//        for (String s : this.AggFacilityStatus.keySet()){
 //            int id = Integer.parseInt(s);
-//            int[] temp = this.AggFuelFacilityStatus.get(s);
+//            int[] temp = this.AggFacilityStatus.get(s);
 //            int amount = 0;
 //            if (unfulfilled_demand.containsKey(id)){
 //                amount = (int) (1000*unfulfilled_demand.get(id));
 //            }
 //            temp[3] = this.SystemTime;
 //            temp[4] = temp[4] + amount;
-//            this.AggFuelFacilityStatus.put(s, temp);
-//        }
-//        for (String s : this.AggWaterFacilityStatus.keySet()){
-//            int id = Integer.parseInt(s);
-//            int[] temp = this.AggWaterFacilityStatus.get(s);
-//            int amount = 0;
-//            if (unfulfilled_demand.containsKey(id)){
-//                amount = (int) (1000*unfulfilled_demand.get(id));
-//            }
-//            temp[3] = this.SystemTime;
-//            temp[4] = temp[4] + amount;
-//            this.AggWaterFacilityStatus.put(s, temp);
+//            this.AggFacilityStatus.put(s, temp);
 //        }
+        for (String s : this.AggFuelFacilityStatus.keySet()){
+            int id = Integer.parseInt(s);
+            int[] temp = this.AggFuelFacilityStatus.get(s);
+            int amount = 0;
+            if (unfulfilled_demand.containsKey(id)){
+                amount = (int) (1000*unfulfilled_demand.get(id));
+            }
+            temp[3] = this.SystemTime;
+            temp[4] = temp[4] + amount;
+            this.AggFuelFacilityStatus.put(s, temp);
+        }
+        for (String s : this.AggWaterFacilityStatus.keySet()){
+            int id = Integer.parseInt(s);
+            int[] temp = this.AggWaterFacilityStatus.get(s);
+            int amount = 0;
+            if (unfulfilled_demand.containsKey(id)){
+                amount = (int) (1000*unfulfilled_demand.get(id));
+            }
+            temp[3] = this.SystemTime;
+            temp[4] = temp[4] + amount;
+            this.AggWaterFacilityStatus.put(s, temp);
+        }
+
+        // Household level output
         for (String s : this.AggWaterOutput.keySet()){
+            Household h = this.Population.get(Integer.parseInt(s));
             int[] infor_water = this.AggWaterOutput.get(s);
             int[] infor_fuel = this.AggFuelOutput.get(s);
+
             if (infor_water[2] == 0){
-                infor_water[4] += this.SystemTime - infor_water[3];
+                infor_water[4] += (int)((this.SystemTime - infor_water[3])/3.6*h.ConsumptionRate[1]);
             }
             infor_water[3] = this.SystemTime;
             this.AggWaterOutput.put(s, infor_water);
 
             if (infor_fuel[2] == 0){
-                infor_fuel[4] += this.SystemTime - infor_fuel[3];
+                infor_fuel[4] += (int)((this.SystemTime - infor_fuel[3])/3.6*h.ConsumptionRate[2]);
             }
             infor_fuel[3] = this.SystemTime;
             this.AggFuelOutput.put(s, infor_fuel);
         }
+
+        // Aggregate the effect of three levels of water output
+        if (! this.Agg_WATER_Initial.isEmpty()){
+            for (String s : this.Agg_WATER_Initial.keySet()){
+                int id = Integer.parseInt(s);
+                int type = id/10000;
+                if (type == GE.WATER_TANK){
+                    Facility f = this.Infrastructure.get(id);
+                    int[] temp_in = this.Agg_WATER_Initial.get(s);
+                    int amount = 0;
+                    for (Integer i : f.FunctionalSupportHousehold){
+                        int[] infor = this.AggWaterOutput.get(Integer.toString(i));
+                        amount = amount + infor[4];
+                    }
+                    temp_in[3] = this.SystemTime;
+                    temp_in[4] = temp_in[4] + amount;
+                    this.Agg_WATER_Initial.put(s, temp_in);
+                }
+            }
+            for (String s : this.Agg_WATER_Initial.keySet()){
+                int id = Integer.parseInt(s);
+                int type = id/10000;
+                if (type == GE.WATER_TOWER){
+                    Facility f = this.Infrastructure.get(id);
+                    int[] temp_in = this.Agg_WATER_Initial.get(s);
+                    int amount = 0;
+                    for (Integer i : f.FunctionalSupportHousehold){
+                        int[] infor = this.AggWaterOutput.get(Integer.toString(i));
+                        amount = amount + infor[4];
+                    }
+                    for (Integer i : f.FunctionalSupportFacility){
+                        if (i != 0){
+                            int[] infor = this.Agg_WATER_Initial.get(Integer.toString(i));
+                            amount = amount + infor[4];
+                        }
+                    }
+                    temp_in[3] = this.SystemTime;
+                    temp_in[4] = temp_in[4] + amount;
+                    this.Agg_WATER_Initial.put(s, temp_in);
+                }
+            }
+            for (String s : this.Agg_WATER_Initial.keySet()){
+                int id = Integer.parseInt(s);
+                int type = id/10000;
+                if (type == GE.WATER_PLANT){
+                    Facility f = this.Infrastructure.get(id);
+                    int[] temp_in = this.Agg_WATER_Initial.get(s);
+                    int amount = 0;
+                    for (Integer i : f.FunctionalSupportHousehold){
+                        int[] infor = this.AggWaterOutput.get(Integer.toString(i));
+                        amount = amount + infor[4];
+                    }
+                    for (Integer i : f.FunctionalSupportFacility){
+                        if (i != 0){
+                            int[] infor = this.Agg_WATER_Initial.get(Integer.toString(i));
+                            amount = amount + infor[4];
+                        }
+                    }
+                    temp_in[3] = this.SystemTime;
+                    temp_in[4] = temp_in[4] + amount;
+                    this.Agg_WATER_Initial.put(s, temp_in);
+                }
+            }
+        }
+
+        // Aggregate the effect of three levels of electricity output
+        if (! this.Agg_ELEC_Initial.isEmpty()){
+            for (String s : this.Agg_ELEC_Initial.keySet()){
+                int id = Integer.parseInt(s);
+                int type = id/10000;
+                if (type == GE.POWER_TRANSFORMER){
+                    Facility f = this.Infrastructure.get(id);
+                    int[] temp_in = this.Agg_ELEC_Initial.get(s);
+                    int amount = 0;
+                    for (Integer i : f.FunctionalSupportFacility){
+                        if (this.Agg_WATER_Initial.containsKey(Integer.toString(i))){
+                            amount = amount + this.Agg_WATER_Initial.get(Integer.toString(i))[4];
+                        }else{
+                            amount = amount + this.AggWaterFacilityStatus.get(Integer.toString(i))[4];
+                        }
+                    }
+                    temp_in[3] = this.SystemTime;
+                    temp_in[4] = temp_in[4] + amount;
+                    this.Agg_ELEC_Initial.put(s, temp_in);
+                    for (Integer j : f.FunctionalSupportHousehold){
+                        int[] hh = this.AggElecOutput.get(Integer.toString(j));
+                        hh[4] += this.AnalysisPeriod;
+                        this.AggElecOutput.put(Integer.toString(j), hh);
+                    }
+                }
+            }
+            for (String s : this.Agg_ELEC_Initial.keySet()){
+                int id = Integer.parseInt(s);
+                int type = id/10000;
+                if (type == GE.POWER_SUBSTATION){
+                    Facility f = this.Infrastructure.get(id);
+                    int[] temp_in = this.Agg_ELEC_Initial.get(s);
+                    int amount = 0;
+                    for (Integer i : f.FunctionalSupportFacility){
+                        if (i/1000000 == GE.WATERCODE){
+                            if (this.Agg_WATER_Initial.containsKey(Integer.toString(i))){
+                                amount = amount + this.Agg_WATER_Initial.get(Integer.toString(i))[4];
+                            }else{
+                                amount = amount + this.AggWaterFacilityStatus.get(Integer.toString(i))[4];
+                            }
+                        }else{
+                            amount = amount + this.Agg_ELEC_Initial.get(Integer.toString(i))[4];
+                        }
+                    }
+                    temp_in[3] = this.SystemTime;
+                    temp_in[4] = temp_in[4] + amount;
+                    this.Agg_ELEC_Initial.put(s, temp_in);
+                }
+            }
+            for (String s : this.Agg_ELEC_Initial.keySet()){
+                int id = Integer.parseInt(s);
+                int type = id/10000;
+                if (type == GE.POWER_PYLON){
+                    Facility f = this.Infrastructure.get(id);
+                    int[] temp_in = this.Agg_ELEC_Initial.get(s);
+                    int amount = 0;
+                    for (Integer i : f.FunctionalSupportFacility){
+                        if (i/1000000 == GE.WATERCODE){
+                            if (this.Agg_WATER_Initial.containsKey(Integer.toString(i))){
+                                amount = amount + this.Agg_WATER_Initial.get(Integer.toString(i))[4];
+                            }else{
+                                amount = amount + this.AggWaterFacilityStatus.get(Integer.toString(i))[4];
+                            }
+                        }else{
+                            amount = amount + this.Agg_ELEC_Initial.get(Integer.toString(i))[4];
+                        }
+                    }
+                    temp_in[3] = this.SystemTime;
+                    temp_in[4] = temp_in[4] + amount;
+                    this.Agg_ELEC_Initial.put(s, temp_in);
+                }
+            }
+        }
+        
+
         System.out.println("Post TRANSIMS simulation complete.");
     }
 
@@ -1010,7 +1162,7 @@ public class UrbanSystem implements Serializable {
 
     }
 
-    public void systemDisruption(String file_name) throws FileNotFoundException, IOException {
+    public void systemDisruption(String file_name, AggregatedFacilityStatusOutput A, AggregatedFacilityStatusOutput B) throws FileNotFoundException, IOException {
 
         GeneralParameterNEncoding GE = new GeneralParameterNEncoding();
         int id;
@@ -1057,8 +1209,6 @@ public class UrbanSystem implements Serializable {
                     if (f.Status != 0){
                         failed_list.add(X);
                     }
-                } else {
-                    System.out.println(X + " is not a valid facility ID.");
                 }
             }
             if (! failed_list.isEmpty()){
@@ -1069,18 +1219,37 @@ public class UrbanSystem implements Serializable {
                     temp = this.DisruptedFacilities.get(id / 1000000);
                     tempx = this.DisruptedFacilitiesX.get(id / 1000000);
                     tempy = this.DisruptedFacilitiesY.get(id / 1000000);
-                    temp.add(id);
-                    tempx.add(this.Infrastructure.getFacility(id).Location[0]);
-                    tempy.add(this.Infrastructure.getFacility(id).Location[1]);
+                    Facility f = this.Infrastructure.getFacility(id);
+                    tempx.add(f.Location[0]);
+                    tempy.add(f.Location[1]);
                     this.DisruptedFacilities.put(id / 1000000, temp);
                     this.DisruptedFacilitiesX.put(id / 1000000, tempx);
                     this.DisruptedFacilitiesY.put(id / 1000000, tempy);
+                    if (f.Type/100 == GE.ELECCODE){
+                        int[] fac_statues = new int[5];
+                        fac_statues[0] = f.Location[0];
+                        fac_statues[1] = f.Location[1];
+                        fac_statues[2] = f.Status;
+                        fac_statues[3] = 0;
+                        fac_statues[4] = 0;
+                        A.put(Integer.toString(f.ID), fac_statues);
+                    }else if (f.Type/100 == GE.WATERCODE){
+                        int[] fac_statues = new int[5];
+                        fac_statues[0] = f.Location[0];
+                        fac_statues[1] = f.Location[1];
+                        fac_statues[2] = f.Status;
+                        fac_statues[3] = 0;
+                        fac_statues[4] = 0;
+                        B.put(Integer.toString(f.ID), fac_statues);
+                    }
                     temp = new ArrayList<Integer>();
                 }
                 for (Integer m : this.DisruptedFacilities.keySet()){
                     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)
             }
         }
@@ -1097,7 +1266,7 @@ public class UrbanSystem implements Serializable {
         return output;
     }
 
-    public void systemRecover(String file_name) throws FileNotFoundException, IOException{
+    public void systemRecover(String file_name, AggregatedFacilityStatusOutput A, AggregatedFacilityStatusOutput B) throws FileNotFoundException, IOException{
         GeneralParameterNEncoding GE = new GeneralParameterNEncoding();
         this.RecoveryOutputX = new HashMap<>();
         this.RecoveryOutputX.put(GE.WATERCODE, new int[]{});
@@ -1135,8 +1304,6 @@ public class UrbanSystem implements Serializable {
                 Integer X = Integer.parseInt(splitline[0]);
                 if (this.isFacility(X)) {
                     recovery_list.add(X);
-                } else {
-                    System.out.println(X + " is not a valid facility ID.");
                 }
             }
             if (! recovery_list.isEmpty()){
@@ -1148,12 +1315,18 @@ public class UrbanSystem implements Serializable {
                     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]);
+                    Facility f = this.Infrastructure.getFacility(id);
+                    tempx.add(f.Location[0]);
+                    tempy.add(f.Location[1]);
                     this.RecoveryFacilities.put(id / 1000000, temp);
                     this.RecoveryFacilitiesX.put(id / 1000000, tempx);
                     this.RecoveryFacilitiesY.put(id / 1000000, tempy);
                     temp = new ArrayList<Integer>();
+                    if (f.Type/100 == GE.ELECCODE){
+                        A.remove(Integer.toString(f.ID));
+                    }else if (f.Type/100 == GE.WATERCODE){
+                        B.remove(Integer.toString(f.ID));
+                    }
                 }
                 for (Integer m : this.RecoveryFacilities.keySet()){
                     this.RecoveryOutputX.put(m, arraylist_toArray(this.RecoveryFacilitiesX.get(m)));
@@ -1163,38 +1336,38 @@ public class UrbanSystem implements Serializable {
         }
     }
 
-    private void initFacilityState(AggregatedFacilityStatusOutput fac_output) {
-//      GeneralParameterNEncoding GE = new GeneralParameterNEncoding();
+    private void initFacilityState(AggregatedFacilityStatusOutput fac_output, AggregatedFacilityStatusOutput fac_output_2) {
+        GeneralParameterNEncoding GE = new GeneralParameterNEncoding();
         int[] fac_statues;
-//        int type_1, type_2;
-//      if (fac_output.ResourceType == "Water"){
-//          type_1 = GE.WATERCODE;
-//          type_2 = GE.FUELCODE;
-//        }else{
-//          type_1 = GE.FUELCODE;
-//          type_2 = GE.WATERCODE;
-//        }
+        int type_1, type_2;
+        if (fac_output.ResourceType == "Water"){
+            type_1 = GE.WATERCODE;
+            type_2 = GE.FUELCODE;
+        }else{
+            type_1 = GE.FUELCODE;
+            type_2 = GE.WATERCODE;
+        }
 
         Iterator<Facility> I = this.Infrastructure.iterator();
         while(I.hasNext()) {
             Facility f = I.next();
-//          if (f.Type/100 == type_1){
-            fac_statues = new int[5];
-            fac_statues[0] = f.Location[0];
-            fac_statues[1] = f.Location[1];
-            fac_statues[2] = f.Status;
-            fac_statues[3] = 0;
-            fac_statues[4] = 0;
-            fac_output.put(Integer.toString(f.ID), fac_statues);
-//            }else if (f.Type/100 == type_2){
-//                fac_statues = new int[5];
-//                fac_statues[0] = f.Location[0];
-//                fac_statues[1] = f.Location[1];
-//                fac_statues[2] = f.Status;
-//                fac_statues[3] = 0;
-//                fac_statues[4] = 0;
-//                fac_output_2.put(Integer.toString(f.ID), fac_statues);
-//            }
+            if (f.Type/100 == type_1){
+                fac_statues = new int[5];
+                fac_statues[0] = f.Location[0];
+                fac_statues[1] = f.Location[1];
+                fac_statues[2] = f.Status;
+                fac_statues[3] = 0;
+                fac_statues[4] = 0;
+                fac_output.put(Integer.toString(f.ID), fac_statues);
+            }else if (f.Type/100 == type_2){
+                fac_statues = new int[5];
+                fac_statues[0] = f.Location[0];
+                fac_statues[1] = f.Location[1];
+                fac_statues[2] = f.Status;
+                fac_statues[3] = 0;
+                fac_statues[4] = 0;
+                fac_output_2.put(Integer.toString(f.ID), fac_statues);
+            }
         }
     }
     
@@ -1202,9 +1375,8 @@ public class UrbanSystem implements Serializable {
         this.Infrastructure.writeFacilityStatus(file_name);
     }
 
-    private void initHouseholdState(AggregatedResourceSecurityOutput water_rs_output, AggregatedResourceSecurityOutput fuel_rs_output) {
+    private void initHouseholdState(AggregatedResourceSecurityOutput water_rs_output, AggregatedResourceSecurityOutput fuel_rs_output, AggregatedResourceSecurityOutput elec) {
         int[] hh_water_infor;
-        int[] hh_fuel_infor;
         
         ArrayList<Integer> HHconsumesWater = this.Population.recordHouseholdIDs;
         
@@ -1218,21 +1390,8 @@ public class UrbanSystem implements Serializable {
             hh_water_infor[3] = 0; // This is the current time
             hh_water_infor[4] = 0; // This is the total delay to wait for that material
             water_rs_output.put(Integer.toString(h.ID), hh_water_infor);
-            
-        }
-        
-        ArrayList<Integer> HHconsumesFuel = this.Population.recordHouseholdIDs;
-        
-        Iterator<Integer> IF = HHconsumesFuel.iterator();
-        while (IF.hasNext()) {
-            Household h = this.Population.get(IF.next());
-            hh_fuel_infor = new int[5];
-            hh_fuel_infor[0] = h.Location[0];
-            hh_fuel_infor[1] = h.Location[1];
-            hh_fuel_infor[2] = 1;
-            hh_fuel_infor[3] = 0;
-            hh_fuel_infor[4] = 0;
-            fuel_rs_output.put(Integer.toString(h.ID), hh_fuel_infor);
+            fuel_rs_output.put(Integer.toString(h.ID), hh_water_infor);
+            elec.put(Integer.toString(h.ID), hh_water_infor);
         }
     }
 
@@ -1293,10 +1452,6 @@ public class UrbanSystem implements Serializable {
         InputStream inputFS = new FileInputStream(inputF);
         BufferedReader br = new BufferedReader(new InputStreamReader(inputFS));
         String line = br.readLine();
-//        this.maxHHID = Integer.parseInt(line.split(",")[0]);
-//        this.maxVHID = Integer.parseInt(line.split(",")[1]);
-//        System.out.println("Max_HHID: " + Integer.toString(maxHHID));
-//        System.out.println("Max_VHID: " + Integer.toString(maxVHID));
         int max_hhid = 0;
         while((line = br.readLine()) != null){
             String[] splitline = line.split(":");
@@ -1393,100 +1548,40 @@ public class UrbanSystem implements Serializable {
         }
     }
 
-    public void WriteResultFiles(String loc, int t) throws IOException{
-        System.out.println("Writing resoutce security output to file.");
-        String casename = "Output_Water.txt";
+    public void WriteFUnctionalFailure(String loc, String casename, AggregatedFacilityStatusOutput A) throws IOException {
         String results_file_loc = loc + casename;
         File vehicle_file = new File(results_file_loc);
         FileWriter vf_writer = new FileWriter(vehicle_file);
         List<String> vh_file_records = new ArrayList<String>();
-
-        String casename1 = "Output_Fuel.txt";
-        String results_file_loc1 = loc + casename1;
-        File vehicle_file1 = new File(results_file_loc1);
-        FileWriter vf_writer1 = new FileWriter(vehicle_file1);
-        List<String> vh_file_records1 = new ArrayList<String>();
-
-        String casename2 = "Output_Facility.txt";
-        String results_file_loc2 = loc + casename2;
-        File vehicle_file2 = new File(results_file_loc2);
-        FileWriter vf_writer2 = new FileWriter(vehicle_file2);
-        List<String> vh_file_records2 = new ArrayList<String>();
-
-//        String casename2 = "Output_Water_Facility.txt";
-//        String results_file_loc2 = loc + casename2;
-//        File vehicle_file2 = new File(results_file_loc2);
-//        FileWriter vf_writer2 = new FileWriter(vehicle_file2);
-//        List<String> vh_file_records2 = new ArrayList<String>();
-
-//        String casename3 = "Output_Fuel_Facility.txt";
-//        String results_file_loc3 = loc + casename3;
-//        File vehicle_file3 = new File(results_file_loc3);
-//        FileWriter vf_writer3 = new FileWriter(vehicle_file3);
-//        List<String> vh_file_records3 = new ArrayList<String>();
-
-        vh_file_records.add("ID\tLocation_X\tLocation_Y\tCurrentState\tResourceLostTime\tCurrentTime\n");
-        Iterator<String> I = this.AggWaterOutput.keySet().iterator();
-        while(I.hasNext()){
+        vh_file_records.add("ID\tLocation_X\tLocation_Y\tCurrentState\tCurrentTime\tResourceLostTime\n");
+        Iterator<String> I = A.keySet().iterator();
+        while (I.hasNext()) {
             String id = I.next();
-            int[] infor = this.AggWaterOutput.get(id);
+            int[] infor = A.get(id);
             vh_file_records.add(id + "\t" + infor[0] + "\t" + infor[1] + "\t" + infor[2] + "\t" + infor[3] + "\t" + infor[4] + "\n");
         }
-        for (String record: vh_file_records) {
+        for (String record : vh_file_records) {
             vf_writer.write(record);
         }
         vf_writer.close();
+    }
 
-        vh_file_records1.add("ID\tLocation_X\tLocation_Y\tCurrentState\tResourceLostTime\tCurrentTime\n");
-        Iterator<String> II = this.AggFuelOutput.keySet().iterator();
-        while(II.hasNext()){
-            String id = II.next();
-            int[] infor = this.AggFuelOutput.get(id);
-            vh_file_records1.add(id + "\t" + infor[0] + "\t" + infor[1] + "\t" + infor[2] + "\t" + infor[3] + "\t" + infor[4] + "\n");
-        }
-        for (String record: vh_file_records1) {
-            vf_writer1.write(record);
-        }
-        vf_writer1.close();
-
-        vh_file_records2.add("ID\tLocation_X\tLocation_Y\tCurrentState\tResourceLostTime\tCurrentTime\n");
-        Iterator<String> III = this.AggFacilityStatus.keySet().iterator();
-        while(III.hasNext()){
-            String id = III.next();
-            int[] infor = this.AggFacilityStatus.get(id);
-            vh_file_records2.add(id + "\t" + infor[0] + "\t" + infor[1] + "\t" + infor[2] + "\t" + infor[3] + "\t" + infor[4] + "\n");
+    public void WriteHHShortage(String loc, String casename, AggregatedResourceSecurityOutput A) throws IOException {
+        String results_file_loc = loc + casename;
+        File vehicle_file = new File(results_file_loc);
+        FileWriter vf_writer = new FileWriter(vehicle_file);
+        List<String> vh_file_records = new ArrayList<String>();
+        vh_file_records.add("ID\tLocation_X\tLocation_Y\tCurrentState\tCurrentTime\tResourceLostTime\n");
+        Iterator<String> I = A.keySet().iterator();
+        while (I.hasNext()) {
+            String id = I.next();
+            int[] infor = A.get(id);
+            vh_file_records.add(id + "\t" + infor[0] + "\t" + infor[1] + "\t" + infor[2] + "\t" + infor[3] + "\t" + infor[4] + "\n");
         }
-        for (String record: vh_file_records2) {
-            vf_writer2.write(record);
+        for (String record : vh_file_records) {
+            vf_writer.write(record);
         }
-        vf_writer2.close();
-
-//        vh_file_records2.add("ID\tLocation_X\tLocation_Y\tCurrentState\tResourceLostTime\tCurrentTime\n");
-//        Iterator<String> III = this.AggWaterFacilityStatus.keySet().iterator();
-//        while(III.hasNext()){
-//            String id = III.next();
-//            int[] infor = this.AggWaterFacilityStatus.get(id);
-//            vh_file_records2.add(id + "\t" + infor[0] + "\t" + infor[1] + "\t" + infor[2] + "\t" + infor[3] + "\t" + infor[4] + "\n");
-//        }
-//        for (String record: vh_file_records2) {
-//            vf_writer2.write(record);
-//        }
-//        vf_writer2.close();
-//
-//        vh_file_records3.add("ID\tLocation_X\tLocation_Y\tCurrentState\tResourceLostTime\tCurrentTime\n");
-//        Iterator<String> IV = this.AggFuelFacilityStatus.keySet().iterator();
-//        while(IV.hasNext()){
-//            String id = IV.next();
-//            int[] infor = this.AggFuelFacilityStatus.get(id);
-//            vh_file_records3.add(id + "\t" + infor[0] + "\t" + infor[1] + "\t" + infor[2] + "\t" + infor[3] + "\t" + infor[4] + "\n");
-//        }
-//        for (String record: vh_file_records3) {
-//            vf_writer3.write(record);
-//        }
-//        vf_writer3.close();
-
-        System.out.println("Write resource security output files FINISHED.");
+        vf_writer.close();
     }
-
 }