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

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

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

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

Field Summary
(package private) static java.util.ArrayList agentCouldNotGetHappyInOriginalArea
           
(package private)  int gisResidentAgentIndex
           
(package private)  boolean happy
           
(package private) static int idCounter
           
(package private)  float movementOfResident
           
(package private)  int noTimesMoved
           
(package private)  com.bbn.openmap.omGraphics.OMCircle omCircle
           
(package private) static java.util.ArrayList removedResidentList
           
(package private)  java.lang.String socclass
           
 
Constructor Summary
Resident(float lat, float lon, float radius, java.lang.String socclass, boolean happy)
           
 
Method Summary
 java.util.ArrayList agentsInSameArea(java.util.ArrayList urbanAgents, java.util.ArrayList residentAgents)
          Designed to stop the agents from moving outside thier original area, finds all the residents that are within the urban area.
 void bigMovementForResident()
           
 void calculateDistanceToAgentsOfSameType(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentsList, float movetoWithin)
          If the Agent is unhappy it moves.
 void calculateDistanceToAgentsOfSameTypeRestricited(java.util.ArrayList newReturnResList, java.util.ArrayList geoemtryofLocalPoygon, java.util.ArrayList urbanAgentList, java.util.ArrayList residentsList, float movetoWithin)
          Same as calculateDistanceToAgentsOfSameType but uses a restricted geoemtry of the urban agent
 void calculateNeigbours(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentList)
          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 urbanAgentList)
          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.
 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()
           
 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 moveAgentUntilHappyRestricted(java.util.ArrayList residentsList, java.util.ArrayList urbanAgentsList, float movetoWithin, float movementOfResident)
          This is the same as moveAgentUntilHappy however a local geoemerty is used based on the urban agent
 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 urbanAgentList)
          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)
           
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).
 java.util.ArrayList polygonOfAgent(java.util.ArrayList urbanAgents, java.util.ArrayList residentAgents)
          Designed to stop the agents from moving outside thier original area
 void postStep(java.util.ArrayList residents, java.util.ArrayList urbanAgentList)
           
 void preStep(java.util.ArrayList residents, java.util.ArrayList urbanAgentsList)
           
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()
           
 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)
           
 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 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

idCounter

static int idCounter

removedResidentList

static java.util.ArrayList removedResidentList

agentCouldNotGetHappyInOriginalArea

static java.util.ArrayList agentCouldNotGetHappyInOriginalArea

gisResidentAgentIndex

int gisResidentAgentIndex

noTimesMoved

int noTimesMoved

socclass

java.lang.String socclass

movementOfResident

float movementOfResident

happy

boolean happy
Constructor Detail

Resident

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

preStep

public void preStep(java.util.ArrayList residents,
                    java.util.ArrayList urbanAgentsList)

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 urbanAgentList)
Parameters:
residents -
urbanAgentList -

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 urbanAgentList)
Evaluates and sets the agents happyness based on its surrounding neighbourhood and the agents indervidial prefferences for differnet types of agents. Agents are satisfied if there preferences are met ie no agents or more agents of their group over any other group

Parameters:
residentsList -
urbanAgentList -

newAgentAtCentrePoint

public com.vividsolutions.jts.geom.Point newAgentAtCentrePoint(java.util.ArrayList urbanAgents)

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.

Parameters:
urbanAgentList -
Returns:

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 OMCircle requires.

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 -

calculateDistanceToAgentsOfSameTypeRestricited

public void calculateDistanceToAgentsOfSameTypeRestricited(java.util.ArrayList newReturnResList,
                                                           java.util.ArrayList geoemtryofLocalPoygon,
                                                           java.util.ArrayList urbanAgentList,
                                                           java.util.ArrayList residentsList,
                                                           float movetoWithin)
Same as calculateDistanceToAgentsOfSameType but uses a restricted geoemtry of the urban agent

Parameters:
newReturnResList -
geoemtryofLocalPoygon -
urbanAgentList -
residentsList -
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 ifit 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 with.

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

moveAgentUntilHappyRestricted

public void moveAgentUntilHappyRestricted(java.util.ArrayList residentsList,
                                          java.util.ArrayList urbanAgentsList,
                                          float movetoWithin,
                                          float movementOfResident)
This is the same as moveAgentUntilHappy however a local geoemerty is used based on the urban agent

Parameters:
residentsList -
urbanAgentsList -
movetoWithin -
movementOfResident -

polygonOfAgent

public java.util.ArrayList polygonOfAgent(java.util.ArrayList urbanAgents,
                                          java.util.ArrayList residentAgents)
Designed to stop the agents from moving outside thier original area

Parameters:
urbanAgents -
residentAgents -
Returns:
the current geomerty of the area the agent is residning within.

agentsInSameArea

public java.util.ArrayList agentsInSameArea(java.util.ArrayList urbanAgents,
                                            java.util.ArrayList residentAgents)
Designed to stop the agents from moving outside thier original area, finds all the residents that are within the urban area.

Parameters:
urbanAgents -
residentAgents -
Returns:
List of residents that are within the same area as the agent in question

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.

Returns:

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 urbanAgentList)
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 -
urbanAgentList -

neighboursWithin

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


summaryOfNeibourhingAgents

public java.util.ArrayList summaryOfNeibourhingAgents(java.util.ArrayList residentsList,
                                                      java.util.ArrayList urbanAgentList)
Takes the parameter residents and caluclates the number 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()

setHappyness

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


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()