package uk.ac.leeds.sog.moses.agent; import java.util.Random; import org.apache.log4j.Logger; /** * @author Belinda * This class provides a method for application of probability rates of * formal care/death statue to people by age group. */ public class ProbabilityByAgeGroup { //minimum age and maximum age within the age group int i_minAge,i_maxAge; int i_formalCareProbability, i_deathProbability; Random i_generator; // a random sequence of number used to apply the probability int[] i_formalCareRandomSeq = new int[100]; // a pointer to find the postion of an age corresponding to the random sequence int i_formalCarePosition; //a random sequence of number used to apply the probability int[] i_deathRandomSeq = new int[100]; // a pointer to find the postion of an age corresponding to the random sequence int i_deathPosition; private static Logger s_logger = Logger.getLogger(ProbabilityByAgeGroup.class); //constructor ProbabilityByAgeGroup(int a_minAge, int a_maxAge, int a_formalCareProbability, int a_deathProbability) { i_minAge = a_minAge; i_maxAge = a_maxAge; i_formalCareProbability = a_formalCareProbability; i_deathProbability = a_deathProbability; i_generator = new Random(); //call the methods to create random sequence required for application //of the formal care and death probability createFormalCareRandomSeq(); createDeathRandomSeq(); } //method to create formal care random sequence private void createFormalCareRandomSeq() { for(int i=0; i<=99; i++) { i_formalCareRandomSeq[i] = i_generator.nextInt(100) + 1; // random int value is between 1 and 100 } i_formalCarePosition = 0; } // method to create formal care random sequence private void createDeathRandomSeq() { for(int i=0; i<=99; i++) { i_deathRandomSeq[i] = i_generator.nextInt(100) + 1; // random int value is between 1 and 100 } i_deathPosition = 0; } public int getMinAge() { return i_minAge; } public int getMaxAge() { return i_maxAge; } //method to find out whether there has been a health change //and the person has been put in formal care and output the results public boolean formalcare() { boolean result = false; if(i_formalCarePosition >= 100) { createFormalCareRandomSeq(); } if(i_formalCareRandomSeq[i_formalCarePosition] <= i_formalCareProbability) { result = true; } //move the pointer forward for the next age in the list i_formalCarePosition++; if(s_logger.isDebugEnabled()) { s_logger.debug("i_formalCarePosition: " + i_formalCarePosition); StringBuffer buffer = new StringBuffer(); for(int i=0; i<=99; i++) { buffer.append(i_formalCareRandomSeq[i] + " "); } s_logger.debug("i_formalCareRandomSeq: " + buffer.toString()); } return result; } //method to find out if the person is dead and output the results public boolean death() { boolean result = false; if(i_deathPosition >= 100) { createDeathRandomSeq(); } if(i_deathRandomSeq[i_deathPosition] <= i_deathProbability) { result = true; } i_deathPosition++; if(s_logger.isDebugEnabled()) { s_logger.debug("i_deathPosition: " + i_deathPosition); StringBuffer buffer = new StringBuffer(); for(int i=0; i<=99; i++) { buffer.append(i_deathRandomSeq[i] + " "); } s_logger.debug("i_deathRandomSeq: " + buffer.toString()); } return result; } }