All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.powertac.householdcustomer.persons.Person Maven / Gradle / Ivy

/*
 * Copyright 2009-2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an
 * "AS IS" BASIS,  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package org.powertac.householdcustomer.persons;

import java.util.ListIterator;
import java.util.Properties;
import java.util.Random;
import java.util.Vector;

import org.apache.log4j.Logger;
import org.powertac.common.configurations.HouseholdConstants;
import org.powertac.common.enumerations.Status;
import org.powertac.householdcustomer.customers.Household;

/**
 * A person domain instance represents a single person in its real life activities The person is
 * living in a house, it may work, it goes to the movies, it is sick, it goes on a vacation trip. In
 * order to make the models as realistic as possible we have them to live their lives as part of a
 * bigger community.
 * @author Antonios Chrysopoulos
 * @version 1, 13/02/2011
 */

public class Person
{

  /**
   * logger for trace logging -- use log.info(), log.warn(), and log.error() appropriately. Use
   * log.debug() for output you want to see in testing or debugging.
   */
  static protected Logger log = Logger.getLogger(Person.class.getName());

  /**
   * the person's name in the community. Usually it includes the household he is living in or its
   * type of person
   */
  String name;

  /** the person's name at anytime. He may be sleeping, working, having fun etc. **/
  Status status;

  /** the household that the person lives in. **/
  Household memberOf;

  /** A vector the contains the working days of the week **/
  Vector workingDays = new Vector();

  /** This is a vector of the working vacation days of the year for this person **/
  Vector vacationVector = new Vector();

  /**
   * Vector of the public vacation days of the person's community, such as Christmas, Easter and so
   * on.
   **/
  Vector publicVacationVector = new Vector();

  /** This is a vector of the days that the person is sick and will stay in the house **/
  Vector sicknessVector = new Vector();

  /** The duration each of the person's leisure activity takes **/
  int leisureDuration = 0;

  /** This is a vector of the day's quarter's and the status of the person in each one of them **/
  Vector dailyRoutine = new Vector();

  /** This is a vector containing the days of the week that the person has leisure time **/
  Vector leisureVector = new Vector();

  /** The weekly schedule and status of the person **/
  Vector> weeklyRoutine = new Vector>();

  /**
   * This function checks if the person is sleeping.
   * @return
   */
  boolean isSleeping ()
  {
    if (status == Status.Sleeping)
      return true;
    else
      return false;
  }

  /**
   * This function checks if the person is at work.
   * @return
   */
  boolean isAtWork ()
  {
    if (status == Status.Working)
      return true;
    else
      return false;
  }

  /**
   * This function checks if the person is doing a leisure activity.
   * @return
   */
  boolean isLeisure ()
  {
    if (status == Status.Leisure)
      return true;
    else
      return false;
  }

  /**
   * This function checks if the person is on vacation.
   * @return
   */
  boolean isVacation ()
  {
    if (status == Status.Vacation)
      return true;
    else
      return false;
  }

  /**
   * This function checks if the person is sick.
   * @return
   */
  boolean isSick ()
  {
    if (status == Status.Sick)
      return true;
    else
      return false;
  }

  /** This function returns the weekly routine of a person */
  public Vector> getWeeklyRoutine ()
  {
    return weeklyRoutine;
  }

  /** This function returns the daily routine of a person */
  public Vector getDailyRoutine ()
  {
    return dailyRoutine;
  }

  /**
   * This function fills out the leisure days' vector of the person by choosing randomly days of the
   * week, while the amount of days is different for each person type.
   * @param counter
   * @param gen
   * @return
   */
  Vector createLeisureVector (int counter, Random gen)
  {
    // Create auxiliary variable
    Vector v = new Vector();

    // Loop for the amount of days
    for (int i = 0; i < counter; i++) {
      int day = gen.nextInt(HouseholdConstants.DAYS_OF_WEEK);
      v.add(day);
    }
    java.util.Collections.sort(v);
    return v;
  }

  /**
   * This function fills out the daily routine of the person, taking into account the different
   * variables and occupations, if he is sick or working etc.
   * @param mean
   * @param dev
   * @param gen
   * @return
   */
  Vector createSicknessVector (double mean, double dev, Random gen)
  {
    // Create auxiliary variables

    int days = (int) (dev * gen.nextGaussian() + mean);
    Vector v = new Vector(days);

    for (int i = 0; i < days; i++) {
      int x = gen.nextInt(HouseholdConstants.DAYS_OF_COMPETITION) + 1;
      ListIterator iter = v.listIterator();
      while (iter.hasNext()) {
        int temp = (int) iter.next();
        if (x == temp) {
          x = x + 1;
          iter = v.listIterator();
        }
      }
      v.add(x);
    }
    java.util.Collections.sort(v);
    return v;
  }

  /** This function sets the household in which the person is living in */
  public void setMemberOf (Household house)
  {
    memberOf = house;
  }

  /**
   * This function fills out the daily routine of the person, taking into account the different
   * variables and occupations, if he is sick or working etc
   * @param day
   * @param vacationAbsence
   * @param gen
   * @return
   */
  public void fillDailyRoutine (int day, double vacationAbsence, Random gen)
  {
    // Create auxiliary variable
    Status st;

    int weekday = day % HouseholdConstants.DAYS_OF_WEEK;
    dailyRoutine = new Vector();
    if (sicknessVector.contains(day)) {
      fillSick();
    } else {
      if (publicVacationVector.contains(day) || (this instanceof WorkingPerson && vacationVector.contains(day))) {
        if (gen.nextDouble() < vacationAbsence) {
          for (int i = 0; i < HouseholdConstants.QUARTERS_OF_DAY; i++) {
            st = Status.Vacation;
            dailyRoutine.add(st);
          }
        } else {
          normalFill();
          addLeisure(weekday, gen);
        }
      } else {
        normalFill();
        if (this instanceof WorkingPerson) {
          int index = workingDays.indexOf(weekday);
          if (index > -1) {
            fillWork();
            addLeisureWorking(weekday, gen);
          } else {
            addLeisure(weekday, gen);
          }
        } else {
          addLeisure(weekday, gen);
        }
      }
    }
  }

  /**
   * This function fills out the daily routine with the leisure activity of the day, if there is one
   * for the person in question.
   * @param weekday
   * @param gen
   * @return
   */
  void addLeisure (int weekday, Random gen)
  {
    // Create auxiliary variables
    ListIterator iter = leisureVector.listIterator();
    Status st;

    while (iter.hasNext()) {
      if (iter.next() == weekday) {
        int start = HouseholdConstants.START_OF_LEISURE + gen.nextInt(HouseholdConstants.LEISURE_WINDOW);
        for (int i = start; i < start + leisureDuration; i++) {
          st = Status.Leisure;
          dailyRoutine.set(i, st);
          if (i == HouseholdConstants.QUARTERS_OF_DAY - 1)
            break;
        }
      }
    }
  }

  /**
   * This function fills out the leisure activities in the daily schedule of the person in question.
   * @param weekday
   * @param gen
   * @return
   */
  void addLeisureWorking (int weekday, Random gen)
  {

  }

  /**
   * This function fills out the daily routine of the person as if he stays in the house all day
   * long.
   * @return
   */
  void normalFill ()
  {
    Status st;
    for (int i = HouseholdConstants.START_OF_SLEEPING_1; i < HouseholdConstants.END_OF_SLEEPING_1; i++) {
      st = Status.Sleeping;
      dailyRoutine.add(st);
    }
    for (int i = HouseholdConstants.END_OF_SLEEPING_1; i < HouseholdConstants.START_OF_SLEEPING_2; i++) {
      st = Status.Normal;
      dailyRoutine.add(st);
    }
    for (int i = HouseholdConstants.START_OF_SLEEPING_2; i < HouseholdConstants.END_OF_SLEEPING_2; i++) {
      st = Status.Sleeping;
      dailyRoutine.add(st);
    }
  }

  /**
   * This function fills out the daily routine of the person that is sick for the day.
   * @return
   */
  void fillSick ()
  {
    Status st;
    for (int i = HouseholdConstants.START_OF_SLEEPING_1; i < HouseholdConstants.END_OF_SLEEPING_1; i++) {
      st = Status.Sleeping;
      dailyRoutine.add(st);
    }
    for (int i = HouseholdConstants.END_OF_SLEEPING_1; i < HouseholdConstants.START_OF_SLEEPING_2; i++) {
      st = Status.Sick;
      dailyRoutine.add(st);
    }
    for (int i = HouseholdConstants.START_OF_SLEEPING_2; i < HouseholdConstants.END_OF_SLEEPING_2; i++) {
      st = Status.Sleeping;
      dailyRoutine.add(st);
    }
  }

  /**
   * This function fill the daily program of the person with the suitable working activities taking
   * in consideration the working habits, duration and shifts.
   * @return
   */
  void fillWork ()
  {

  }

  /**
   * This is the function utilized to show the information regarding the person in question, its
   * variables values etc.
   * @return
   */
  public void showInfo ()
  {

  }

  /**
   * At the end of each week the person models refresh their schedule. This way we have a realistic
   * and dynamic model, changing working hours, leisure activities and so on.
   * @param conf
   * @param gen
   * @return
   */
  public void refresh (Properties config, Random gen)
  {

  }

  public String toString ()
  {
    return name;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy