uk.ac.ucl.casa.andrew.phd.segregationModelDensity
Class Resident

java.lang.Object
  extended byuk.ac.ucl.casa.andrew.phd.segregationModelDensity.Resident
All Implemented Interfaces:
anl.repast.gis.GisAgent, anl.repast.gis.OpenMapAgent

public class Resident
extends java.lang.Object
implements anl.repast.gis.OpenMapAgent

This is the same basic class as with other residents however density has been added to the agents preferences.

Version:
1 02-Aug-07
Author:
Andrew Crooks
Centre for Advanced Spatial Analysis, University College London., Andrew

Field Summary
(package private)  double currentNeigbourhoodPopulationDenstiy
           
(package private)  int gisResidentAgentIndex
           
(package private)  boolean happy
           
(package private) static int idCounter
           
(package private)  float movementOfResident
           
(package private)  float movetoWithin
           
(package private)  int noTimesMoved
           
(package private)  com.bbn.openmap.omGraphics.OMCircle omCircle
          Instance fields *
(package private) static java.util.ArrayList removedResidentList
           
(package private)  int residentAge
           
(package private)  java.lang.String socclass
           
 
Constructor Summary
Resident(java.util.ArrayList urbanAgentList)
           
Resident(float lat, float lon, float radius, java.lang.String socclass, int resAge, boolean happy)
           
 
Method Summary
 void agePopulation()
           
 void bigMovementForResident()
           
 void calculateDistanceToAgentsOfSameType(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentsList, float movetoWithin)
          If the Agent is unhappy it moves.
 void calculateNeigbours(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentsList)
          Caluculates the types of nighbousrs based on Social classs and uses the hashmap from the neighboursWithin method to do this.
static java.util.HashMap countNeibourhingAgents(java.util.ArrayList residents)
          Takes the parameter residents and caluclates The method returns a hashMap and is used in percentageOfNeibourhingAgents
 void evaluateAndSetHappiness(java.util.ArrayList residentsList, java.util.ArrayList environmentAgentList)
          Evaluates and sets the agents happyness based on its surrounding neighbourhood and the agents indervidial prefferences for differnet types of agents.
 ResidentArrayList findNearestNeighbourOfSameType(java.util.ArrayList residentsList)
          If the Agent is unhappy it moves.
 int getAge()
           
 java.awt.Paint getFillPaint()
           
 com.vividsolutions.jts.geom.Geometry getGeometryResdient()
          This method gets the lat & longeting of the omCircle (agents) goeometry and creates a new point for the agent which is then passed to the isInUnionGeometry method to check that the can move, see if each omCircle agent is within UrbanAgent bounding box.
 int getGisAgentIndex()
           
 boolean getHappyness()
          Gets the current agents Happyness (either true or false)
 float getLat()
           
 com.bbn.openmap.LatLonPoint getLatLon()
           
 float getLon()
           
 int[] getNeighbors()
           
 int getNumberOfTimesAgentMoved()
           
 com.bbn.openmap.omGraphics.OMGraphic getOMGraphic()
           
 float getRadius()
           
 java.lang.String getsoc()
           
 java.lang.String[] gisPropertyList()
           
 boolean isInUnionGeometry(java.util.ArrayList urbanAgentsList)
          Tests to see if resdient agent is within an urban agent which is used in stepRestrictTo method, the mthod takes the ArrayList from Urban Agent (therefore inherits all the properties from Urban agent (especially the union geoemtry)and uses it to see if the agent can move.
 void moveAgentUntilHappy(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentsList, anl.repast.gis.display.OpenMapDisplay omDisplay, float movetoWithin, float movementOfResident)
          This method will only move the agents that are unhappy, each agent is moved until it finds an area where it is happy to live.
 void movement(float movementOfResident)
          Governs how far an agent can move in any time step, takes the SegGISModel.movement movement paremater as the distance for random movement in both X and Y Directions.
 void movementForNewResdient()
           
 java.util.ArrayList neighboursWithin(java.util.ArrayList residentsList, java.util.ArrayList environmentAgentList)
          finds which resident agents are within a specified radius of a specific agent using a buffering mechansim from JTS.
 com.vividsolutions.jts.geom.Point newAgentAtCentrePoint(java.util.ArrayList urbanAgents)
          This method creates a new point based on the centroid of the centroid of the area of interest.
static int numberOfTimesAgentMoved()
           
static java.util.HashMap percentageOfNeibourhingAgents(java.util.ArrayList residentsList)
          Takes the parameter residents and uses the method countNeibourhingAgents and is called in the calculateNeigbours method after summaryOfNeibourhingAgents has been called and caluclates the percentage of neighbours at a specific distance (buffer).
 void postStep(java.util.ArrayList residents, java.util.ArrayList urbanAgentsList)
           
 void preStep(java.util.ArrayList residents)
           
static int randomAge()
          A simple method sets the resdinet agents age randomly between a min and max value
static com.vividsolutions.jts.geom.Point randomPointforNewAgent(java.util.ArrayList urbanAgentList)
          This method creates a new point for the agent to be placed randomly within the urban area using JTS CoordinateArrays class http://vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/CoordinateArrays.html The method first finds the max and min x and y values and creates a random new point between these values, and then checks to see if the agent is within the urban layer extent if not, a new random point is chosen until it returns true.
 void reallyBigBigMovementForResident()
           
 void reallyBigMovementForResident()
           
static void reset()
           
 void setAge(int residentAge)
           
 void setGisAgentIndex(int index)
           
 void setHappyness(boolean residentHappy)
          Sets the current agents Happyness(either true or false)
 void setLat(float lat)
           
 void setLatLon(float lat, float lon)
           
 void setLon(float lon)
           
 void setNeighbors(int[] neighbours)
           
 void setNumberOfTimesAgentMoved(int noTimesMoved)
           
 void setOMGraphic(com.bbn.openmap.omGraphics.OMGraphic omg)
           
 void setRadius(float newrad)
           
static java.lang.String setRandomSocialClass()
           
 void setsoc(java.lang.String socialclass)
           
 void smallMovementForNewResdient()
           
 void step(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentsList, anl.repast.gis.display.OpenMapDisplay omDisplay, float movetoWithin, float movementOfResident)
          What the urban agents do in each time step, I have tried to to keep this simple, but it calls on a number of other methods Parameters taken include residents,ArrayList urbanAgents, OpenMapDisplay omDisplay, which are passed on from SegGISModel
 void stepRestrictTo(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentsList, anl.repast.gis.display.OpenMapDisplay omDisplay)
          Used to restrict movement of the agents within a shapefile.
 void stepRestrictToForNewResident(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentsList, anl.repast.gis.display.OpenMapDisplay omDisplay, float movetoWithin, float movementOfResident)
          To ensure that the current resedient is actually created the area of interest, once the resident agent has been created stepRestrictToForNewResident mehod is called.
 java.util.ArrayList summaryOfNeibourhingAgents(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentList)
          Takes the parameter residents and caluclates the number of of neighbours at a specific distance (buffer) and is used in calculateNeigbours method.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

omCircle

com.bbn.openmap.omGraphics.OMCircle omCircle
Instance fields *


idCounter

static int idCounter

removedResidentList

static java.util.ArrayList removedResidentList

gisResidentAgentIndex

int gisResidentAgentIndex

noTimesMoved

int noTimesMoved

currentNeigbourhoodPopulationDenstiy

double currentNeigbourhoodPopulationDenstiy

socclass

java.lang.String socclass

movementOfResident

float movementOfResident

residentAge

int residentAge

happy

boolean happy

movetoWithin

float movetoWithin
Constructor Detail

Resident

public Resident(float lat,
                float lon,
                float radius,
                java.lang.String socclass,
                int resAge,
                boolean happy)

Resident

public Resident(java.util.ArrayList urbanAgentList)
Method Detail

reset

public static void reset()

preStep

public void preStep(java.util.ArrayList residents)

step

public void step(java.util.ArrayList residentsList,
                 java.util.ArrayList urbanAgentsList,
                 anl.repast.gis.display.OpenMapDisplay omDisplay,
                 float movetoWithin,
                 float movementOfResident)
What the urban agents do in each time step, I have tried to to keep this simple, but it calls on a number of other methods Parameters taken include residents,ArrayList urbanAgents, OpenMapDisplay omDisplay, which are passed on from SegGISModel

Parameters:
residentsList -
urbanAgentsList -
omDisplay -
movetoWithin -
movementOfResident -

postStep

public void postStep(java.util.ArrayList residents,
                     java.util.ArrayList urbanAgentsList)
Parameters:
residents -
urbanAgentsList -

getNumberOfTimesAgentMoved

public int getNumberOfTimesAgentMoved()

setNumberOfTimesAgentMoved

public void setNumberOfTimesAgentMoved(int noTimesMoved)

numberOfTimesAgentMoved

public static int numberOfTimesAgentMoved()

evaluateAndSetHappiness

public void evaluateAndSetHappiness(java.util.ArrayList residentsList,
                                    java.util.ArrayList environmentAgentList)
Evaluates and sets the agents happyness based on its surrounding neighbourhood and the agents indervidial prefferences for differnet types of agents. Not how density has been introduced

Parameters:
residentsList -
environmentAgentList -

newAgentAtCentrePoint

public com.vividsolutions.jts.geom.Point newAgentAtCentrePoint(java.util.ArrayList urbanAgents)
This method creates a new point based on the centroid of the centroid of the area of interest. Its based on the union- geometry of the entire shapefile. Its ok if only adding one agent each time step but not more as only one agent can one space. (the method is not called but does work) This method could be used if you wanted to add an agent at a specific point (portal)


randomPointforNewAgent

public static com.vividsolutions.jts.geom.Point randomPointforNewAgent(java.util.ArrayList urbanAgentList)
This method creates a new point for the agent to be placed randomly within the urban area using JTS CoordinateArrays class http://vividsolutions.com/jts/javadoc/com/vividsolutions/jts/geom/CoordinateArrays.html The method first finds the max and min x and y values and creates a random new point between these values, and then checks to see if the agent is within the urban layer extent if not, a new random point is chosen until it returns true.


stepRestrictToForNewResident

public void stepRestrictToForNewResident(java.util.ArrayList residentsList,
                                         java.util.ArrayList urbanAgentsList,
                                         anl.repast.gis.display.OpenMapDisplay omDisplay,
                                         float movetoWithin,
                                         float movementOfResident)
To ensure that the current resedient is actually created the area of interest, once the resident agent has been created stepRestrictToForNewResident mehod is called. It works the the same way as stepRestrict but the movement that the agent can make is incremented untill the resident agent is within the area. The reason why it is not allways within the are is due to pression errors when rounding between floats.

Parameters:
residentsList -
urbanAgentsList -
omDisplay -
movetoWithin -
movementOfResident -

stepRestrictTo

public void stepRestrictTo(java.util.ArrayList residentsList,
                           java.util.ArrayList urbanAgentsList,
                           anl.repast.gis.display.OpenMapDisplay omDisplay)
Used to restrict movement of the agents within a shapefile. If movement is not valid return the agent to last position and enter the movement method again. Previously had: public void stepRestrictTo(ArrayList residents,ArrayList urbanAgents,OpenMapDisplay omDisplay) { do{ movement(); } while (this.isInUnionGeometry(urbanAgents)==false); log.info("while (this.isInUnionGeometry(urbanAgents)==false) Resident agent ID: " + gisResidentAgentIndex); } But this sometimes made the agent keep going in a loop and slowing the program down for example repeating the same method 6000 times. The current method stores the the residenet agents last known position and keeps going back to this until the step is true.

Parameters:
residentsList -
urbanAgentsList -
omDisplay -

findNearestNeighbourOfSameType

public ResidentArrayList findNearestNeighbourOfSameType(java.util.ArrayList residentsList)
If the Agent is unhappy it moves. Problem with moveAgentUntilHappy method is it takes a long time. therefroe trying to give the agent global information about the area. And then chose the best location.

Parameters:
residentsList -
Returns:

calculateDistanceToAgentsOfSameType

public void calculateDistanceToAgentsOfSameType(java.util.ArrayList residentsList,
                                                java.util.ArrayList urbanAgentsList,
                                                float movetoWithin)
If the Agent is unhappy it moves. Problem with moveAgentUntilHappy method is it takes a long time. therefroe trying to give the agent global information about the area. And then chose the best location. This method assumes agents will only move to areas where there is a least one agent of the same type in the area. The method uses ResidentArrayList class to store information on the agents nearest neibours makes it faster than calculating a new distance between agents each time.

Parameters:
residentsList -
urbanAgentsList -
movetoWithin -

moveAgentUntilHappy

public void moveAgentUntilHappy(java.util.ArrayList residentsList,
                                java.util.ArrayList urbanAgentsList,
                                anl.repast.gis.display.OpenMapDisplay omDisplay,
                                float movetoWithin,
                                float movementOfResident)
This method will only move the agents that are unhappy, each agent is moved until it finds an area where it is happy to live. First the agent moves to a random location ,checks to see if its within the polygon's extent, if it is, it the looks at its surrounding nieghbours to see if it satisisfies it critea. After 25 attempted moveements, if the agent is not happy will call the calculateDistanceToAgentsOfSameType method. If after this method the agent remains upset it will be removed from the are else the agent moves and becomes happy. Either way the program moves to the next agent. the use of the counter is used first to move in the nearest area then the search for agents of the same type Therefore more chance to find an area the agent is happy

Parameters:
residentsList -
urbanAgentsList -
omDisplay -
movetoWithin -
movementOfResident -

getGeometryResdient

public com.vividsolutions.jts.geom.Geometry getGeometryResdient()
This method gets the lat & longeting of the omCircle (agents) goeometry and creates a new point for the agent which is then passed to the isInUnionGeometry method to check that the can move, see if each omCircle agent is within UrbanAgent bounding box.


isInUnionGeometry

public boolean isInUnionGeometry(java.util.ArrayList urbanAgentsList)
Tests to see if resdient agent is within an urban agent which is used in stepRestrictTo method, the mthod takes the ArrayList from Urban Agent (therefore inherits all the properties from Urban agent (especially the union geoemtry)and uses it to see if the agent can move.

Parameters:
urbanAgentsList -
Returns:

movement

public void movement(float movementOfResident)
Governs how far an agent can move in any time step, takes the SegGISModel.movement movement paremater as the distance for random movement in both X and Y Directions.

Parameters:
movementOfResident -

smallMovementForNewResdient

public void smallMovementForNewResdient()

movementForNewResdient

public void movementForNewResdient()

bigMovementForResident

public void bigMovementForResident()

reallyBigMovementForResident

public void reallyBigMovementForResident()

reallyBigBigMovementForResident

public void reallyBigBigMovementForResident()

calculateNeigbours

public void calculateNeigbours(java.util.ArrayList residentsList,
                               java.util.ArrayList urbanAgentsList)
Caluculates the types of nighbousrs based on Social classs and uses the hashmap from the neighboursWithin method to do this. The method returns an Arraylist with the highest percentage but also the percentage of the differnet types. of social class in a specific area.

Parameters:
residentsList -
urbanAgentsList -

neighboursWithin

public java.util.ArrayList neighboursWithin(java.util.ArrayList residentsList,
                                            java.util.ArrayList environmentAgentList)
finds which resident agents are within a specified radius of a specific agent using a buffering mechansim from JTS. Buffer returns a geometry

Parameters:
residentsList -
environmentAgentList -
Returns:

summaryOfNeibourhingAgents

public java.util.ArrayList summaryOfNeibourhingAgents(java.util.ArrayList residentsList,
                                                      java.util.ArrayList urbanAgentList)
Takes the parameter residents and caluclates the number of of neighbours at a specific distance (buffer) and is used in calculateNeigbours method. The method returns an arraylist

Parameters:
residentsList -
urbanAgentList -
Returns:

countNeibourhingAgents

public static java.util.HashMap countNeibourhingAgents(java.util.ArrayList residents)
Takes the parameter residents and caluclates The method returns a hashMap and is used in percentageOfNeibourhingAgents

Parameters:
residents -
Returns:

percentageOfNeibourhingAgents

public static java.util.HashMap percentageOfNeibourhingAgents(java.util.ArrayList residentsList)
Takes the parameter residents and uses the method countNeibourhingAgents and is called in the calculateNeigbours method after summaryOfNeibourhingAgents has been called and caluclates the percentage of neighbours at a specific distance (buffer). The method returns a hashMap

Parameters:
residentsList -
Returns:

getHappyness

public boolean getHappyness()
Gets the current agents Happyness (either true or false)

Returns:

setHappyness

public void setHappyness(boolean residentHappy)
Sets the current agents Happyness(either true or false)


randomAge

public static int randomAge()
A simple method sets the resdinet agents age randomly between a min and max value

Returns:

getAge

public int getAge()

setAge

public void setAge(int residentAge)

agePopulation

public void agePopulation()

setRandomSocialClass

public static java.lang.String setRandomSocialClass()

getLat

public float getLat()

getLon

public float getLon()

getLatLon

public com.bbn.openmap.LatLonPoint getLatLon()

setLatLon

public void setLatLon(float lat,
                      float lon)

getRadius

public float getRadius()

setRadius

public void setRadius(float newrad)

setLat

public void setLat(float lat)

setLon

public void setLon(float lon)

setsoc

public void setsoc(java.lang.String socialclass)

getsoc

public java.lang.String getsoc()

getFillPaint

public java.awt.Paint getFillPaint()
Specified by:
getFillPaint in interface anl.repast.gis.OpenMapAgent

getOMGraphic

public com.bbn.openmap.omGraphics.OMGraphic getOMGraphic()
Specified by:
getOMGraphic in interface anl.repast.gis.OpenMapAgent

setOMGraphic

public void setOMGraphic(com.bbn.openmap.omGraphics.OMGraphic omg)
Specified by:
setOMGraphic in interface anl.repast.gis.OpenMapAgent

getGisAgentIndex

public int getGisAgentIndex()
Specified by:
getGisAgentIndex in interface anl.repast.gis.GisAgent

setGisAgentIndex

public void setGisAgentIndex(int index)
Specified by:
setGisAgentIndex in interface anl.repast.gis.GisAgent

gisPropertyList

public java.lang.String[] gisPropertyList()
Specified by:
gisPropertyList in interface anl.repast.gis.GisAgent

setNeighbors

public void setNeighbors(int[] neighbours)
Specified by:
setNeighbors in interface anl.repast.gis.GisAgent

getNeighbors

public int[] getNeighbors()
Specified by:
getNeighbors in interface anl.repast.gis.GisAgent

toString

public java.lang.String toString()