|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfr.lifl.jedi.model.Environment
public class Environment
The class corresponds to the environment were agents evolve. It is a two dimensional continuous space, that can be either bounded, or defined as a torus along the x axis and the y axis.
The position of agents in the environment
is stored in every agent (see Agent.getXPosition()
and Agent.getYPosition()
).
This class also lists :
getAllAgents()
)getActiveAgentsToAdd()
and getPassiveAgentsToRemove()
)
This class provides tools that :
distance(Agent, Agent)
);
contains(double, double)
);
canBePutAt(Agent, double, double)
,
canMoveForward(Agent, double)
and
canMoveTowards(Agent, Agent, double)
);
getNeighborhoodInHalo(Agent, PhysicalHalo, Set)
).
This method is a tool to get the set of agent perceived by an agent.
putAgent(Agent, double, double)
);
removeAgent(Agent)
);
turnLeft(Agent, double)
and
turnRight(Agent, double)
);
moveForward(Agent, double)
);
moveTowards(Agent, Agent, double)
);
getDestination(double, double, double, double, java.awt.geom.Point2D.Double)
);
AgentsPopulation
).
JEDI V 2.2 |
Created the 30th oct. 2008 |
Modified the 4th may 2009 |
Yoann Kubera |
SMAC Team (Systèmes Multi-Agents et Comportement) |
LIFL (Laboratoire d'Informatique Fondamentale de Lille) |
University of Lille, France |
Nested Class Summary | |
---|---|
class |
Environment.EnvironmentCell
This inner class corresponds to an unitary cell of the environment. |
Field Summary | |
---|---|
protected java.util.List<Agent> |
activeAgentsToAdd
The set of all active agents that where added during a simulation step, and passive agent that became active during a simulation step. |
protected AgentsPopulation |
agentsPopulation
Variable that stores the population of all different agent classes that are present in the environment. |
protected java.util.Set<Agent> |
allAgents
The set of all agents contained in the environment. |
protected int |
height
The height of the environment, expressed in unitary cell number; |
protected java.util.List<Agent> |
passiveAgentsToRemove
The set of active agents that became passive during a simulation step. |
protected Environment.EnvironmentCell[][] |
theGrid
A reference on the grid used to represent the environment. |
protected int |
width
The width of the environment, expressed in unitary cell number; |
Constructor Summary | |
---|---|
Environment(int width,
int height)
Constructor of an environment in JEDI. |
Method Summary | |
---|---|
boolean |
canBePutAt(Agent a,
double x,
double y)
Checks that an agent can move or can be put at the given position in the environment. |
boolean |
canMoveForward(Agent a,
double distance)
Checks if an agent can move forward, in order to cover a particular distance in the environment. |
boolean |
canMoveForward(Agent a,
double devAngle,
double distance)
Checks if an agent can turn from a particular angle to the left (defined by devAngle ), and then can move forward, in order to cover a particular
distance in the environment. |
boolean |
canMoveTowards(Agent src,
Agent tgt,
double d)
Checks if the src agent can move
towards tgt . |
void |
clear()
Clears the environment. |
boolean |
contains(double x,
double y)
Tells if the environment contains a particular position. |
double |
distance(Agent a1,
Agent a2)
Gets the distance separating two agents. |
double |
distance(double xa,
double ya,
double la,
double ha,
double xb,
double yb)
Computes the distance between a rectangle A and a point B such that : A is defined by his lower left corner (xa, ya), its width |
protected double |
distance(double xa,
double ya,
double la,
double ha,
double xb,
double yb,
double lb,
double hb)
Computes the distance between two rectangles A and B such that : A is defined by his lower left corner (xa, ya), its width |
java.util.List<Agent> |
getActiveAgentsToAdd()
Gets the set of all active agents that where added during a simulation step, and the set of all passive agents that became active during a simulation step. |
AgentsPopulation |
getAgentsPopulation()
Gets the agents number of every different agent family. |
java.util.Set<Agent> |
getAllAgents()
Gets the set of all agents contained in the environment. |
Environment.EnvironmentCell |
getCellAt(int x,
int y)
Gets the cell of the environment that contains the (x,y) coordinates. |
boolean |
getDestination(double x,
double y,
double direction,
double distance,
java.awt.geom.Point2D.Double destination)
Gets the destination of a move that is made in a particular direction from the (x,y) starting position. |
int |
getHeight()
Retrieves the height of the environment. |
void |
getNeighborhoodInHalo(Agent a,
PhysicalHalo halo,
java.util.Set<Agent> neighborhood)
Gets the set of all the agents which surface intersect a particular surface of the environment -- called the halo of the agent. |
java.util.List<Agent> |
getPassiveAgentsToRemove()
Gets the set of active agents that became passive during a simulation step. |
int |
getWidth()
Retrieves the width of the environment. |
void |
headTowards(Agent a,
double angle)
Makes the agent head towards a particular direction. |
boolean |
isXAxisTorus()
Checks if the environment is a torus along the x axis. |
boolean |
isYAxisTorus()
Checks if the environment is a torus along the x axis. |
void |
moveForward(Agent a,
double distance)
Makes an agent move forward in the environment. |
void |
moveToPosition(Agent a,
double x,
double y)
Moves an agent to the given position in the environment. |
void |
moveTowards(Agent src,
Agent tgt,
double d)
Moves an agent towards another agent. |
double |
noTorusDistance(double xa,
double ya,
double la,
double ha,
double xb,
double yb)
Computes the distance between a rectangle A and a point B such that : A is defined by his lower left corner (xa, ya), its width |
protected double |
noTorusDistance(double xa,
double ya,
double la,
double ha,
double xb,
double yb,
double lb,
double hb)
Computes the distance between two rectangles A and B such that : A is defined by his lower left corner (xa, ya), its width |
void |
putAgent(Agent a,
double x,
double y)
Puts an agent at the given position in the environment. |
void |
removeAgent(Agent a)
Removes an agent from the environment. |
void |
setXAxisTorus(boolean v)
Defines if the environment is a torus along the x axis. |
void |
setYAxisTorus(boolean v)
Defines if the environment is a torus along the x axis. |
void |
timeStepStartClean()
Cleans the list of : all active agents that where added during a simulation step and of all passive agents that became active during the simulation step. |
void |
turnLeft(Agent a,
double angle)
Makes an agent turn left -- i.e. |
void |
turnRight(Agent a,
double angle)
Makes an agent turn right -- i.e. |
void |
update(java.util.Observable o,
java.lang.Object arg)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int width
protected int height
protected Environment.EnvironmentCell[][] theGrid
protected java.util.Set<Agent> allAgents
protected java.util.List<Agent> activeAgentsToAdd
An agent is active if it has the ability to initiate at least one interaction.
An agent is passive if it has not the ability to initiate at least one interaction.
protected java.util.List<Agent> passiveAgentsToRemove
An agent is active if it has the ability to initiate at least one interaction.
An agent is passive if it has not the ability to initiate at least one interaction.
protected AgentsPopulation agentsPopulation
Constructor Detail |
---|
public Environment(int width, int height)
By default, the grid is not a torus.
width
- The width of the environment.
It has to be higher than 1.
If not, it is set to 1.height
- The height of the environment.
It has to be higher than 1.
If not, it is set to 1.Method Detail |
---|
public AgentsPopulation getAgentsPopulation()
public int getWidth()
public int getHeight()
public boolean isXAxisTorus()
true
if the environment is
a torus along the x axis.public void setXAxisTorus(boolean v)
v
- true
if the environment will become
is a torus along the x axis.public boolean isYAxisTorus()
true
if the environment is
a torus along the x axis.public void setYAxisTorus(boolean v)
v
- true
if the environment will become
is a torus along the x axis.public java.util.Set<Agent> getAllAgents()
Do not modify this list.
public java.util.List<Agent> getActiveAgentsToAdd()
An agent is active if it has the ability to initiate at least one interaction.
An agent is passive if it has not the ability to initiate at least one interaction.
public java.util.List<Agent> getPassiveAgentsToRemove()
An agent is active if it has the ability to initiate at least one interaction.
An agent is passive if it has not the ability to initiate at least one interaction.
public void timeStepStartClean()
An agent is active if it has the ability to initiate at least one interaction.
An agent is passive if it has not the ability to initiate at least one interaction.
public boolean contains(double x, double y)
x
- the x coordinate of the position.y
- the y coordinate of the position.
true
if the environment
contains (x,y).public Environment.EnvironmentCell getCellAt(int x, int y)
Gets the cell of the environment that contains the (x,y) coordinates.
This method is only used by the simulation core.
x
- The x coordinate to test.y
- The y coordinate to test.
null
is returned.protected double noTorusDistance(double xa, double ya, double la, double ha, double xb, double yb, double lb, double hb)
xa
- The x coordinate of the lower left corner of A rectangleya
- The y coordinate of the lower left corner of A rectanglela
- The width of A rectangleha
- The height of A rectanglexb
- The x coordinate of the lower left corner of B rectangleyb
- The y coordinate of the lower left corner of B rectanglelb
- The width of B rectanglehb
- The height of B rectangle
protected double distance(double xa, double ya, double la, double ha, double xb, double yb, double lb, double hb)
xa
- The x coordinate of the lower left corner of A rectangleya
- The y coordinate of the lower left corner of A rectanglela
- The width of A rectangleha
- The height of A rectanglexb
- The x coordinate of the lower left corner of B rectangleyb
- The y coordinate of the lower left corner of B rectanglelb
- The width of B rectanglehb
- The height of B rectangle
public double noTorusDistance(double xa, double ya, double la, double ha, double xb, double yb)
This method is public to help computations in other classes, like the ones
defining halo.
For simulation, please use the distance(Agent, Agent)
method.
xa
- The x coordinate of the lower left corner of A rectangleya
- The y coordinate of the lower left corner of A rectanglela
- The width of A rectangleha
- The height of A rectanglexb
- The x coordinate of B pointyb
- The y coordinate of B point
public double distance(double xa, double ya, double la, double ha, double xb, double yb)
xa
- The x coordinate of the lower left corner of A rectangleya
- The y coordinate of the lower left corner of A rectanglela
- The width of A rectangleha
- The height of A rectanglexb
- The x coordinate of B pointyb
- The y coordinate of B point
public double distance(Agent a1, Agent a2)
Gets the distance separating two agents.
If the distance is 0, then the surface representing each agent are intersecting.
a1
- the first agent for which the distance is computeda2
- the second agent for which the distance is computed
public void getNeighborhoodInHalo(Agent a, PhysicalHalo halo, java.util.Set<Agent> neighborhood)
The halo is a geometrical shape that represents the area of
the environment the agent perceives.
This area is relative to the agent's position.
Thus, the coordinate (0,0) in the area corresponds to the
coordinate (Agent.getXPosition()
; Agent.getYPosition()
)
of the environment.
The neighborhood is stored in the list given in parameters.
a
- The agent that perceives its neighborhoodhalo
- The surface of the environment the agent perceives.neighborhood
- The list of all agents that are perceived by the agent.
The agent performing perception is not included.public void putAgent(Agent a, double x, double y) throws java.lang.IllegalArgumentException
Please note that before calling this method, it must made
be sure that the agent can be put at this position, thanks to
the canBePutAt(Agent, double, double)
method.
This method has to be called only if the agent is not in the environment.
If it is already in the environment, please use the moveToPosition(Agent, double, double)
method.
a
- The agent to put in the environment.x
- The x coordinate where to put the agent.y
- The y coordinate where to put the agent.
java.lang.IllegalArgumentException
- if the agent cannot be put at that position, either because :
Agent.getSurface()
,
moveToPosition(Agent, double, double)
public void removeAgent(Agent a)
a
- The agent to remove from the environment.public boolean canBePutAt(Agent a, double x, double y)
a
- The agent to move or put in the environment.x
- The x coordinate where to move or put the agent.y
- The y coordinate where to move or put the agent.
false
if the agent cannot move or be put at
this position.
This can be either because the position (x,y) is out of bounds, or
because a part of agents' surface is out of the environment.
Obviously, in that case the agent is not put in the environment.
Please note that the center of the agents surface is put at the (x,y) position.
Agent.getSurface()
public void turnRight(Agent a, double angle)
The angle has to be expressed in degrees.
a
- The agent to make turn right with a particular angle.public void turnLeft(Agent a, double angle)
The angle has to be expressed in degrees.
a
- The agent to make turn left with a particular angle.public void headTowards(Agent a, double angle)
a
- The agent to turn.angle
- The direction to which the agent has to head towards.public boolean canMoveTowards(Agent src, Agent tgt, double d)
src
agent can move
towards tgt
.
If true
, then sthe src
agent can turn towards tgt
, and can be put at
the position at d units ahead.
src
- The agent that movestgt
- The agent to reachd
- The distance of the move
true
if the src
agent can turn towards tgt
, and can be put at
the position at d units ahead. Returns false
if :
d
units toward its targetsrc
or tgt
are equal to null
src
or tgt
are not in the environmentPlease note that only the destination is checked. This method does not check if the agent goes through obstacles to reach its target.
public void moveTowards(Agent src, Agent tgt, double d) throws java.lang.IllegalArgumentException
src
- The agent to move in the environment.tgt
- The agent to which src
wants to get closer.d
- The distance of the move.
java.lang.IllegalArgumentException
- if :
src
agent cannot turn towards the tgt
agent,
and then move forward in d
units.
src
or tgt
agent are equal to null
.src
or tgt
agent are not in the environment.canMoveTowards(Agent, Agent, double)
public void moveToPosition(Agent a, double x, double y) throws java.lang.IllegalArgumentException
a
- The agent to move in the environment.x
- The x coordinate where to move the agent.y
- The y coordinate where to move the agent.
java.lang.IllegalArgumentException
- if the agent cannot be put at
that position, either because :
If that exception is thrown, the a
agent is removed
from the environment.
canBePutAt(Agent, double, double)
public boolean getDestination(double x, double y, double direction, double distance, java.awt.geom.Point2D.Double destination) throws java.lang.IllegalArgumentException
The direction is a value in [-180;180[.
Please refer to Agent.getDirection()
for more informations.
x
- The x coordinate of the move's origin.y
- The y coordinate of the move's origin.direction
- The direction in which the move is made.distance
- The distance covered by the move. It should be greater or equal to 0.destination
- The object where the destination is stored.
true
if the destination can be reached (in the environment).
It returns false
if :
null
;java.lang.IllegalArgumentException
Agent.getDirection()
public void moveForward(Agent a, double distance) throws java.lang.IllegalArgumentException
The move is made according to the agent's current position and its direction.
This method may fail if the move ends at a position not in the environment, or if the agent cannot be placed at that position.
a
- The agent to move.distance
- The distance that the agent covers by moving
java.lang.IllegalArgumentException
- if a parameter is null, or
if the agent cannot be put at that position, because either :
In such a case, the agent is removed from the environment.
canBePutAt(Agent, double, double)
,
getDestination(double, double, double, double, java.awt.geom.Point2D.Double)
public boolean canMoveForward(Agent a, double distance)
The move is made according to the agent's current position and its direction.
This method may fail if the move ends at a position not in the environment, or if the agent cannot be placed at that position.
a
- The agent to movedistance
- The distance that the agent covers by moving
true
if the move can be made.
It returns false in case where canBePutAt(Agent, double, double)
or getDestination(double, double, double, double, java.awt.geom.Point2D.Double)
return false
.
canBePutAt(Agent, double, double)
,
getDestination(double, double, double, double, java.awt.geom.Point2D.Double)
public boolean canMoveForward(Agent a, double devAngle, double distance)
devAngle
), and then can move forward, in order to cover a particular
distance in the environment.
The move is made according to the agent's current position and its direction.
This method may fail if the move ends at a position not in the environment, or if the agent cannot be placed at that position.
a
- The agent to movedistance
- The distance that the agent covers by movingdevAngle
- The deviation angle from the agents current position.
true
if the move can be made.
It returns false in case where canBePutAt(Agent, double, double)
or getDestination(double, double, double, double, java.awt.geom.Point2D.Double)
return false
.
canBePutAt(Agent, double, double)
,
getDestination(double, double, double, double, java.awt.geom.Point2D.Double)
public void clear()
This method removes all agents from the environment.
public void update(java.util.Observable o, java.lang.Object arg)
update
in interface java.util.Observer
Observer.update(java.util.Observable, java.lang.Object)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |