package uk.ac.leeds.sog.moses.agent; import java.util.ArrayList; import java.util.List; import java.util.Random; import org.apache.log4j.Logger; /** * @author Belinda * This class models the changes of the household and its members during * the lifecycle of the household. It also outputs the information * about the households that have been created. */ public class Household implements Comparable { //Household attributes private int i_id; private int i_size; private HRP i_hrp; private Spouse i_spouse; private List i_child; private List i_elderly; private List i_adult; private String i_wLocation;//ward private String i_oLocation;//OA private String i_location;//currently use OA // Household status: 0(occupied household), 1(vacant household) private int i_householdStatus; private static Logger s_logger = Logger.getLogger(Household.class); private static String s_lineSeparator = System.getProperty("line.separator"); //the constructor public Household(HRP a_hrp) { i_id = a_hrp.getHouseID(); i_size = a_hrp.getHouseholdSize(); i_hrp = a_hrp; i_spouse = null; i_child = new ArrayList(); i_elderly = new ArrayList(); i_adult = new ArrayList(); i_wLocation = a_hrp.getWLocation(); i_oLocation = a_hrp.getOLocation(); i_location = a_hrp.getLocation(); i_householdStatus = 0; } //Method to update changes in the household members after each step/year public void step() { // HRP if(i_hrp.getDeathStatus() == 0 && i_hrp.getFormalCare() == 0) { i_hrp.step(); if(i_hrp.getAge() >= 65 && ProbabilityModel.formalcare(i_hrp)) { i_hrp.setFormalCare(1); } if(i_hrp.getAge() >= 65 && ProbabilityModel.death(i_hrp)) { // HRP is dead and household will be vacant i_hrp.setDeathStatus(1); } } if(i_hrp.getDeathStatus() == 0 && i_hrp.getFormalCare() == 1) { i_hrp.step(); } // spouse if(i_spouse != null && i_spouse.getDeathStatus() == 0 && i_spouse.getFormalCare() == 0) { i_spouse.step(); if(i_spouse.getAge() >= 65 && ProbabilityModel.formalcare(i_spouse)) { i_spouse.setFormalCare(1); } if(i_spouse.getAge() >= 65 && ProbabilityModel.death(i_spouse)) { i_spouse.setDeathStatus(1); } } if(i_spouse != null && i_spouse.getDeathStatus() == 0 && i_spouse.getFormalCare() == 1) { i_spouse.step(); } // children for(int i=0; i= 16) { child.setLeftHouse(1); } } // elderly dependents: elderly dependents, HRP(over 65) and spouse(over 65); for(int i=0; i= 65) { // over 65 if(adult.getFormalCare() == 0 && ProbabilityModel.formalcare(adult)) { adult.setFormalCare(1); } if(ProbabilityModel.death(adult)) { adult.setDeathStatus(1); } } else { adult.step(); } } //call the method to get the updated household size updateHouseholdSize(); //call the method to find out whether the household is vacant or not updateHouseholdStatus(); } //method to get household ID public int getId() { return i_id; } //set household ID public void setId(int an_id) { i_id = an_id; } //add children in the current list public void addChildDependent(Child child) { i_child.add(child); } //remove children from the cureent list if they left house public void removeChildDependent(Child child) { i_child.remove(child); } //get the updated list of child dependents public List getListOfChildren() { return i_child; } //add an elderly to the list public void addElderlyDependent(ElderlyDependent elderly) { i_elderly.add(elderly); } //remove an elderly if he/she is not in the household any more public void removeElderlyDependent(ElderlyDependent elderly) { i_elderly.remove(elderly); } //get the list of elderlys public List getListOfElderlyDependents() { return i_elderly; } //add an adult public void addAdultDependent(AdultDependent adult) { i_adult.add(adult); } //remove an adult public void removeAdultDependent(AdultDependent adult) { i_adult.remove(adult); } //get the list of adults public List getListOfAdultDependents() { return i_adult; } //get the HRP of the household public HRP getHrp() { return i_hrp; } //set the HRP public void setHrp(HRP a_hrp) { i_hrp = a_hrp; } // get the ward name public String getWLocation() { return i_wLocation; } //set the ward name public void setWLocation(String a_wLocation) { i_wLocation = a_wLocation; } //get the OA name public String getOLocation() { return i_oLocation; } //set the OA name public void setOLocation(String a_oLocation) { i_oLocation = a_oLocation; } //get the location(currently using OA) public String getLocation() { return i_location; } //set location public void setLocation(String a_location) { i_location = a_location; } //get spouse public Spouse getSpouse() { return i_spouse; } //set spouse public void setSpouse(Spouse a_spouse) { i_spouse = a_spouse; } //get household size public int getSize() { return i_size; } //set household size public void setSize(int a_size) { i_size = a_size; } //get household status: if it is vacant public int getHouseholdStatus() { return i_householdStatus; } //set the household status value public void setHouseholdStatus(int a_status) { i_householdStatus = a_status; } //decide the position to put the household by household ID order public int compareTo(Object object) { Household another = (Household) object; if(i_id < another.getId()) { return -1; } else if( i_id == another.getId()) { return 0; } else { return 1; } } //method to get a String with all the variables of the household public String toString() { StringBuffer buff = new StringBuffer(); buff.append(i_id); buff.append(", "); buff.append(i_householdStatus); buff.append(", "); buff.append(i_size); buff.append(", "); buff.append(i_hrp.getPid()); buff.append(", "); buff.append(i_hrp.getAge()); buff.append(", "); if(i_spouse != null) { buff.append(i_spouse.getPid()); } else { buff.append(""); } buff.append(", "); if(i_spouse != null) { buff.append(i_spouse.getAge()); } else { buff.append(""); } buff.append(", "); if(i_child.size() >0) { for(int i=0; i"); } buff.append(", "); if(i_elderly.size() > 0) { for(int i=0; i"); } buff.append(", "); if(i_adult.size() > 0) { for(int i=0; i"); } buff.append(", "); buff.append(i_location); buff.append(", "); buff.append(i_wLocation); buff.append(", "); buff.append(i_oLocation); return buff.toString(); } //method to update the household status: whether it's vacant private void updateHouseholdStatus() { // count number of elderly people in the household int numOfElderly = 0; // over 65 int numOfNonElderly = 0; // under 65 if(i_hrp.getDeathStatus() == 0 && i_hrp.getFormalCare() == 0 && i_hrp.getAge() >= 65) { numOfElderly++; } else if(i_hrp.getDeathStatus() == 0 && i_hrp.getAge() < 65) { numOfNonElderly++; } if(i_spouse != null) { if(i_spouse.getDeathStatus() == 0 && i_spouse.getFormalCare() == 0 && i_spouse.getAge() >= 65) { numOfElderly++; } else if(i_spouse.getDeathStatus() == 0 && i_spouse.getAge() < 65) { numOfNonElderly++; } } // child for(int i=0; i= 65) { numOfElderly++; } else if(adult.getDeathStatus() == 0 && adult.getAge() < 65) { numOfNonElderly++; } } // finally set household status if(numOfNonElderly == 0 && numOfElderly == 0) { // vacant household i_householdStatus = 1; } else if(numOfNonElderly == 0 && numOfElderly == 1) { // vacant household i_householdStatus = 1; } else { // occupied household i_householdStatus = 0; } } //method to get the updated household size private void updateHouseholdSize() { int size = 0; // hrp is alive if(i_hrp.getDeathStatus() == 0 && i_hrp.getFormalCare() == 0) { size += 1; } if(i_spouse != null && i_spouse.getDeathStatus() == 0 && i_spouse.getFormalCare() == 0) { size += 1; } // chidren for(int i=0; i