Advertisement
Guest User

Person.groovy

a guest
Aug 11th, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. /**
  2.  *
  3.  */
  4. package at.ac.wu.mzuba.ltcmicro2
  5.  
  6. import repast.simphony.context.Context;
  7. import repast.simphony.engine.schedule.ScheduledMethod;
  8. import repast.simphony.random.RandomHelper;
  9. import repast.simphony.util.ContextUtils;
  10.  
  11. /**
  12.  * This class represents individuals in the microsimulation.
  13.  *
  14.  * @author Martin Zuba
  15.  */
  16. public class Person {
  17.  
  18.     // <-- Basic data -->
  19.     double age;
  20.     Sex sex;
  21.     /** Federal state of residence. */
  22.     Bundesland wohnort;
  23.     /** Number of Instrumental Activities of Daily Living the Person needs help with */
  24.     int nrIADL;
  25.     /** Number of Activities of Daily Living the Person needs help with */
  26.     int nrADL;
  27.     /** Number of chronic conditions the person suffers from */
  28.     int nrCond;
  29.     /** Level of care allowance granted to the Person <code>[0:7]</code> */
  30.     int pfSt;
  31.    
  32.     // <-- Methods --> 
  33.    
  34.     /**
  35.      * Ages the person one year. This method is scheduled for every iteration of the simulation.
  36.      *
  37.      * @return <code>true&nbsp</code> if the person survived, <br> <code>false</code> otherwise.  
  38.      */
  39.     @ScheduledMethod(start = 1d, interval = 1d)
  40.     public boolean age() {
  41.         // age one year
  42.         this.age++;
  43.  
  44.         // die with 20% probability after age 70 – will be replaced
  45.         if (age > 70 && RandomHelper.nextDouble() < 0.1) {
  46.             die();
  47.             return false;
  48.         }
  49.         return true;
  50.     }
  51.    
  52.     /**
  53.      * Removes the Person from the context it inhabited.
  54.      *
  55.      * @return <code>true</code> if the person was found in a context, <br> <code>false</code> otherwise.  
  56.      */
  57.     public boolean die() {
  58.         Context<Object> context = ContextUtils.getContext(this);
  59.         if (context != null) {
  60.             context.remove(this);
  61.             return true;
  62.         } else {
  63.             return true;
  64.         }
  65.     }
  66.    
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement