crowdmodel.utils
Class Misc

java.lang.Object
  extended by crowdmodel.utils.Misc

public class Misc
extends java.lang.Object

Class that describes static method functions = functions that do not need a class instantiation to be used = functions that are convenient for my model, however are not part of the model These involve functions that describe perception functions like the agents that can be perceived by an individual, or to check whether a position is walkable or not, functions to initialise the social structure etc.

Author:
Nanda Wijermans

Constructor Summary
Misc()
           
 
Method Summary
static java.util.Vector<CrowdAgent> agentsInCone(repast.simphony.context.Context context, CrowdAgent me, double angle, double distance)
          Returns the agents that are situated in a cone given a position, angle, width and depth.
static java.lang.String bName2fName(java.lang.String behaviourName)
          Given a behaviourName the corresponding factName is returned.
static boolean close2friend(repast.simphony.context.Context<CObject> context, java.util.Iterator<CrowdAgent> friends, CrowdAgent me)
          This function returns whether an agent is standing close to one of its friends This is done by checking the distance between the agent and all of its friends.
static int[][] createGroup(int[][] matrix, int groupsize, int numgroups, int crowdsize)
          Function creates a matrix that represents a social structure.
static boolean crowded(repast.simphony.space.continuous.ContinuousSpace space, repast.simphony.space.continuous.NdPoint point, double dist)
           
static java.lang.Integer crowdedness(repast.simphony.space.continuous.ContinuousSpace space, repast.simphony.space.continuous.NdPoint point, double dist)
           
static boolean crowdedOld(repast.simphony.space.continuous.ContinuousSpace space, repast.simphony.space.continuous.NdPoint point)
          Indicated whether a point is crowded based on the occupancy of the 8 surrounding patches (Moore's neighbourhood).
static java.util.ArrayList<java.lang.String> fill(java.lang.String[] list)
          Converts an String array into an ArrayList Used by the behaviourRules classes
static repast.simphony.space.grid.GridPoint findWalkableNeighborPatch(repast.simphony.context.Context<CObject> context, repast.simphony.space.grid.GridPoint pos)
           
static java.lang.String fName2bName(java.lang.String factName)
          Given a factName the corresponding behaviourtName is returned.
static int getDensityCondition(int crowdsize)
           
static int getLeadershipCondition(int leaderRatio)
           
static java.util.Vector<repast.simphony.space.grid.GridPoint> getMooresPatches(repast.simphony.space.grid.GridPoint gp)
           
static int getSafetyCondition(java.lang.String distribution)
          Relates the safety condition with a number. 1 = friends (crowd composition) = low preference safety goal = B(3,7) 2 = mixed (crowd composition) = average preference safety goal = B(5,5) 3 = family (crowd composition) = high preference safety goal = B(7,3)
static double heading2point(repast.simphony.space.continuous.NdPoint pos, repast.simphony.space.continuous.NdPoint poi)
          Calculates what the new heading should be, given a point it should be directed to In repast the coordinate system goes from 0 (top), 90 (right), 180/-180 (bottom), -90 (left).
static java.util.ArrayList iterator2array(java.util.Iterator iterator, int size)
           
static int[][] makeFriends(int crowdsize, int duoPerc, int trioPerc, int quartetPerc)
          The function makeFriends defines the initial social structure.
static void matrixPrint(double[][] matrix)
          Prints a matrix on the console - overloading function depending on the type of matrix here a matrix filled with Double values
static void matrixPrint(int[][] matrix)
          Prints a matrix on the console, specificly a matrix for friends with the first row being printed outside the matrix...
static repast.simphony.space.grid.GridPoint nd2gridpoint(repast.simphony.space.continuous.NdPoint target)
          Returns the corresponding patch that a NdPoint belongs to (this is of course a approximation, as we use a rounding function for the double coordinate values to return an integer coordinate value)
static CrowdAgent nearestAgent(repast.simphony.context.Context context, CrowdAgent me, java.util.Iterator<CrowdAgent> agents)
          Returns the agent that is physically the nearest
static int nrAgentsInCone(repast.simphony.context.Context context, CrowdAgent me, double angle, double distance)
          Calculates the number of agents that are situated in a cone given a position, angle, depth and width.
static repast.simphony.space.continuous.NdPoint posClose2pos(repast.simphony.context.Context<CObject> context, repast.simphony.space.continuous.NdPoint posFriend, CrowdAgent me)
          Function returns a position close a given position (here the position of a friend is used) It searches for a position in the Moore's neighbourhood (the eight surrounding patches) When no position can be found in the neighbourhood that is available for an agent to stand on (depending on walkablility: occupiedness (other objects/agents) and positioned within the world) the function returns null.
static repast.simphony.space.continuous.NdPoint posNearestAgent(repast.simphony.context.Context context, repast.simphony.space.continuous.NdPoint myPos, java.util.Iterator<CrowdAgent> agents, CrowdAgent me)
          Returns the location of the nearest positioned agent given a set of agents and my own position.
static void setSocialNetwork(repast.simphony.context.Context agentContext, int[][] links)
          Sets the initial social structure in the repast context in terms of a Network projection.
static boolean walkablePatch(repast.simphony.context.Context context, CrowdAgent thisAgent, repast.simphony.space.continuous.NdPoint target)
          Given a (x,y) coordinate this function returns whether this gridcell is walkable or not based on the position being located within the world and whether the cell is walkable (not a building (stage,bar,toilet)) Note overloaded function!
static boolean walkablePatch(repast.simphony.context.Context context, repast.simphony.space.grid.GridPoint target)
          Given a GridPoint (x,y) coordinate this function returns whether this gridcell is walkable or not (so if CellObjects are on it) Note verloaded function!
static boolean withinWorld(repast.simphony.space.grid.GridPoint target)
          Indicates whether a GridPoint lies within the world
static boolean withinWorld(repast.simphony.space.continuous.NdPoint target)
          Indicates whether a NdPoint lies within the world or not
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Misc

public Misc()
Method Detail

fill

public static java.util.ArrayList<java.lang.String> fill(java.lang.String[] list)
Converts an String array into an ArrayList Used by the behaviourRules classes


nrAgentsInCone

public static int nrAgentsInCone(repast.simphony.context.Context context,
                                 CrowdAgent me,
                                 double angle,
                                 double distance)
Calculates the number of agents that are situated in a cone given a position, angle, depth and width. Used to calculate the density of number of agents observed by an agent For future development: - incorporate the vertical dimension/restrictions in perceiving to define whether an agent is observable or not. - refine this for the type of sensor (hearing has a different range then viewing)


crowdedOld

public static boolean crowdedOld(repast.simphony.space.continuous.ContinuousSpace space,
                                 repast.simphony.space.continuous.NdPoint point)
Indicated whether a point is crowded based on the occupancy of the 8 surrounding patches (Moore's neighbourhood). When the amount of people exceed 4, than is is considered crowded This is used for the toilet and bar to indicate whether they are crowded or not.

Parameters:
space -
point -
Returns:

crowded

public static boolean crowded(repast.simphony.space.continuous.ContinuousSpace space,
                              repast.simphony.space.continuous.NdPoint point,
                              double dist)

crowdedness

public static java.lang.Integer crowdedness(repast.simphony.space.continuous.ContinuousSpace space,
                                            repast.simphony.space.continuous.NdPoint point,
                                            double dist)

agentsInCone

public static java.util.Vector<CrowdAgent> agentsInCone(repast.simphony.context.Context context,
                                                        CrowdAgent me,
                                                        double angle,
                                                        double distance)
Returns the agents that are situated in a cone given a position, angle, width and depth. Other then that is is identical to the nrAgentsIncone function. It is used to scan the observable agents for friends, or direction to walk to. But also to discern between the people (i.e. observable behaviours) that affect an agent. For future development: - incorporate the vertical dimension/restrictions in perceiving to define whether an agent is observable or not. - refine this for the type of sensor (hearing has a different range then viewing)


posNearestAgent

public static repast.simphony.space.continuous.NdPoint posNearestAgent(repast.simphony.context.Context context,
                                                                       repast.simphony.space.continuous.NdPoint myPos,
                                                                       java.util.Iterator<CrowdAgent> agents,
                                                                       CrowdAgent me)
Returns the location of the nearest positioned agent given a set of agents and my own position.

Parameters:
myPos - - the position of the agent who is concerned with the distance of other agents
agents - - set of agents that I want to extract the position of the nearest person
Returns:
position of the nearest agents

nearestAgent

public static CrowdAgent nearestAgent(repast.simphony.context.Context context,
                                      CrowdAgent me,
                                      java.util.Iterator<CrowdAgent> agents)
Returns the agent that is physically the nearest

Parameters:
myPos - - the position of the agent who is concerned with the distance of other agents
agents - - set of agents that I want to extract the position of the nearest person
Returns:
the agent that is most nearby

withinWorld

public static boolean withinWorld(repast.simphony.space.grid.GridPoint target)
Indicates whether a GridPoint lies within the world

Parameters:
target -
Returns:
a boolean value indicating whether a GridPoint lies within the word

withinWorld

public static boolean withinWorld(repast.simphony.space.continuous.NdPoint target)
Indicates whether a NdPoint lies within the world or not

Parameters:
target -
Returns:
a boolean value indicating whether a NdPoint lies within the word

walkablePatch

public static boolean walkablePatch(repast.simphony.context.Context context,
                                    CrowdAgent thisAgent,
                                    repast.simphony.space.continuous.NdPoint target)
Given a (x,y) coordinate this function returns whether this gridcell is walkable or not based on the position being located within the world and whether the cell is walkable (not a building (stage,bar,toilet)) Note overloaded function!

Parameters:
px -
py -
sspace -
Returns:
whether a patch is walkable or not

getMooresPatches

public static java.util.Vector<repast.simphony.space.grid.GridPoint> getMooresPatches(repast.simphony.space.grid.GridPoint gp)

walkablePatch

public static boolean walkablePatch(repast.simphony.context.Context context,
                                    repast.simphony.space.grid.GridPoint target)
Given a GridPoint (x,y) coordinate this function returns whether this gridcell is walkable or not (so if CellObjects are on it) Note verloaded function!

Parameters:
px -
py -
sspace -
Returns:
whether a patch is walkable or not

heading2point

public static double heading2point(repast.simphony.space.continuous.NdPoint pos,
                                   repast.simphony.space.continuous.NdPoint poi)
Calculates what the new heading should be, given a point it should be directed to In repast the coordinate system goes from 0 (top), 90 (right), 180/-180 (bottom), -90 (left). We calculate a Repast heading as follows:

Based on the relative position from one point A (me) to another point B(other) there are either positioned: I) on the same axe (either: left, right, top or bottom position)
II) in one of the Quadrants (1,2,3,4)

Given the distances (height and width of a vector between the points) and the quadrants the other point can lie in relative from point A (me)
deltaX = xpos (me) - xpoi (other)
deltaY = ypos (me) - ypoi (other)

Quadrant 1 (Q1): top-right, (deltaX < 0 && deltaY < 0)
Quadrant 2 (Q2): top-left, (deltaX > 0 && deltaY < 0)
Quadrant 3 (Q3): bottom-left, deltaX > 0 && deltaY < 0)
Quadrant 4 (Q4): bottom-right, deltaX < 0 && deltaY < 0)

In condition I :
If deltaX == 0 : point B is on the same vertical height.
    • if deltaY > 0 : heading = 180 or -180, B is above A
      if deltaY < 0 : heading = 0, B is below A
  • else if deltaY == 0 : point be is on the same horizontal height
    • if deltaX > 0 : heading = -90, B is left from A
      if deltaX < 0 : heading = 90, B is right from A
  • The angle is calculated in the same way for each B, independent from the quadrant B is situated in. To calculate the heading is based on the the quadrant the other point is lying in.

    alpha = shift tan(deltaX / deltaY) Q1: heading = alpha Q2: heading = -alpha Q3: heading = -180 + alpha Q4: heading = 180 - alpha

    Parameters:
    pos - - my posistion (A)
    poi - - position I want to set my heading towards (B)

    nd2gridpoint

    public static repast.simphony.space.grid.GridPoint nd2gridpoint(repast.simphony.space.continuous.NdPoint target)
    Returns the corresponding patch that a NdPoint belongs to (this is of course a approximation, as we use a rounding function for the double coordinate values to return an integer coordinate value)

    Parameters:
    target -
    Returns:
    gridPoint given a NdPoint

    makeFriends

    public static int[][] makeFriends(int crowdsize,
                                      int duoPerc,
                                      int trioPerc,
                                      int quartetPerc)
    The function makeFriends defines the initial social structure. It describes the smallest unit of connection between individuals in terms of with whom am I coming to this event Such a group is defined as a closed and full connected group. The size and amount of groups is distinctive between the scenarios. We assume the following social structure settings given the a scenario: festival: mostly duo's, trio's and quartets (couples, sets of couples, friends, family) soccer: a group of (20-30) of more hard core supporters (given an in-group) and the rest of the crowd consists again out of duo's, trio's and quartets. (mental note: makes me think, as within this hardcore setting one also has the duos, trios and quartets in friends, however have an extra group they feel verbonden with) demonstration: They arrive in big groups, one can define department level so like 20, 30 people. However here one has also bigger clusters like 5, 6 . Sight, haven't made up my mind about this. (mental note: can I avoid the multiple layers of groups one belong to in this setting? I mean in a festival it is so easy as they there is no link between the subgroups, there is no overall group or multiple overall groups, and is this not exactly what I define as an important indicator for the difference between more probable settings for a riot (focussed group))

    Parameters:
    crowdsize -
    duoPerc -
    trioPerc -
    quartetPerc -
    Returns:
    matrix that represents connections between agents

    createGroup

    public static int[][] createGroup(int[][] matrix,
                                      int groupsize,
                                      int numgroups,
                                      int crowdsize)
    Function creates a matrix that represents a social structure. The matrix is filled by defining a (set of) group(s), based on the number of groups with a certain group size. An element in the matrix indicates whether an agent is connect (1) to another agent or not (0) Where the last column represents the number of ties/friends an individual has. | a1 | a2 | a3 | #ties \n -------------------------- \n a1 | 0 | 0 | 1 | 2 \n a2 | 0 | 0 | 1 | 2 \n a3 | 1 | 1 | 0 | 2 \n Example shows that agent 1 and 2 have 1 connection and agent 3 has to as this one is connected to both agent 1 and 2.

    Parameters:
    matrix -
    groupsize -
    numgroups -
    crowdsize -
    Returns:
    matrix that represents connections between agents

    matrixPrint

    public static void matrixPrint(int[][] matrix)
    Prints a matrix on the console, specificly a matrix for friends with the first row being printed outside the matrix... TODO update the name and explanation of this function * - overloading function depending on the type of matrix here a matrix filled with Integer values

    Parameters:
    matrix -

    matrixPrint

    public static void matrixPrint(double[][] matrix)
    Prints a matrix on the console - overloading function depending on the type of matrix here a matrix filled with Double values

    Parameters:
    matrix -

    setSocialNetwork

    public static void setSocialNetwork(repast.simphony.context.Context agentContext,
                                        int[][] links)
    Sets the initial social structure in the repast context in terms of a Network projection. The agents (nodes) that are connected (given a matrix) are set by adding an Edge to the network projection.

    Parameters:
    agentContext -
    links -

    close2friend

    public static boolean close2friend(repast.simphony.context.Context<CObject> context,
                                       java.util.Iterator<CrowdAgent> friends,
                                       CrowdAgent me)
    This function returns whether an agent is standing close to one of its friends This is done by checking the distance between the agent and all of its friends. When the distance is closer than 0.5 meter a friend is being considered as physically close. This function can be made in a computational cheaper way by checking whether the people that are close to you (within a radius of 0.5 meter) are your friends. However, I need to have some sort of collection to make this friend-check (friends.contains(closeAgent)) and this is not possible using the Network information (as this returns an Iterable, which forces me to go through all my friends which makes the whole attempt obsolete given my current method) and I can use it by accessing memory, however I need to make this available and usable in terms of retrieving a subset of memory elements. this is not that important now. Furthermore the size of the groups are currently max. 4 people so not that expensive.

    Parameters:
    context -
    friends -
    myPos -
    Returns:
    boolean whether an agent is physically close to one of its friends

    posClose2pos

    public static repast.simphony.space.continuous.NdPoint posClose2pos(repast.simphony.context.Context<CObject> context,
                                                                        repast.simphony.space.continuous.NdPoint posFriend,
                                                                        CrowdAgent me)
    Function returns a position close a given position (here the position of a friend is used) It searches for a position in the Moore's neighbourhood (the eight surrounding patches) When no position can be found in the neighbourhood that is available for an agent to stand on (depending on walkablility: occupiedness (other objects/agents) and positioned within the world) the function returns null.

    Parameters:
    context -
    posFriend -
    me -
    Returns:
    a NdPoint near to a given position. Null is returned when no (available) position is found.

    findWalkableNeighborPatch

    public static repast.simphony.space.grid.GridPoint findWalkableNeighborPatch(repast.simphony.context.Context<CObject> context,
                                                                                 repast.simphony.space.grid.GridPoint pos)
    Parameters:
    context -
    pos -
    Returns:

    bName2fName

    public static java.lang.String bName2fName(java.lang.String behaviourName)
    Given a behaviourName the corresponding factName is returned. Currently this is done a bit expensive, needs to be changed into a global variable

    Parameters:
    behaviourName -
    Returns:

    fName2bName

    public static java.lang.String fName2bName(java.lang.String factName)
    Given a factName the corresponding behaviourtName is returned. Currently this is done a bit expensive, needs to be changed into a global variable

    Parameters:
    factName -
    Returns:

    iterator2array

    public static java.util.ArrayList iterator2array(java.util.Iterator iterator,
                                                     int size)

    getDensityCondition

    public static int getDensityCondition(int crowdsize)

    getSafetyCondition

    public static int getSafetyCondition(java.lang.String distribution)
    Relates the safety condition with a number. 1 = friends (crowd composition) = low preference safety goal = B(3,7) 2 = mixed (crowd composition) = average preference safety goal = B(5,5) 3 = family (crowd composition) = high preference safety goal = B(7,3)

    Parameters:
    distribution -
    Returns:
    numerical safety condition

    getLeadershipCondition

    public static int getLeadershipCondition(int leaderRatio)