• No results found

Continuous 2D and 3D spaceContinuous 2D and 3D space

boolean jumpToRandomEmptyCell()boolean jumpToRandomEmptyCell()– finds a random empty cell and places the– finds a random empty cell and places the agent there.

agent there.

moveToNextCell( int dir )moveToNextCell( int dir ) – moves the agent to an adjacent cell  – moves the agent to an adjacent cell in a given direction.in a given direction.

swapWithAgent( AgentDiscrete2D anotherAgent )swapWithAgent( AgentDiscrete2D anotherAgent ) – swaps the cell location of this – swaps the cell location of this agent with another agent. Swap is the only way for an agent to move in a fully agent with another agent. Swap is the only way for an agent to move in a fully occupied space.

occupied space.

swapWithCell( int r, int c )swapWithCell( int r, int c ) – swaps this agent with an agent at the c – swaps this agent with an agent at the cell with theell with the given row and column.

given row and column.

swapWithNextCell( int dir )swapWithNextCell( int dir ) – swaps the agent with an agent at the adjacent cell in a – swaps the agent with an agent at the adjacent cell in a given direction.

given direction.

int[] findRandomEmptyCell()int[] findRandomEmptyCell()–tries to find a randomly located empty cell and–tries to find a randomly located empty cell and returns its row and column in the array with two elements.

returns its row and column in the array with two elements.

Agent getAgentAtCell( int r, int c )Agent getAgentAtCell( int r, int c ) – returns the agent located in the cell with a  – returns the agent located in the cell with a givengiven row and column, or null.

row and column, or null.

Agent getAgentNextToMe( int dir )Agent getAgentNextToMe( int dir ) – returns the agent next to this agent in a given – returns the agent next to this agent in a given direction, if any.

direction, if any.

AgentDiscrete2D[] getNeighbors()AgentDiscrete2D[] getNeighbors()– returns the array of neighbor agents, subject to– returns the array of neighbor agents, subject to the current neighborhood type (Euclidean {N, S, E, W},

the current neighborhood type (Euclidean {N, S, E, W}, Moore - also {..,NW, NW,Moore - also {..,NW, NW, SE, SW}). The elements in the returned array are of the base class

SE, SW}). The elements in the returned array are of the base class AgentDiscrete2D

AgentDiscrete2D, and not of the same class as this agent because, in general, there, and not of the same class as this agent because, in general, there can be more than one type of agent in the same space.

can be more than one type of agent in the same space.

In addition, the environment object supporting 2D continuous space (base class In addition, the environment object supporting 2D continuous space (base class EnvironmentDiscrete2D

EnvironmentDiscrete2D) offers these functions:) offers these functions:

int[] findRandomEmptyCell()int[] findRandomEmptyCell() – tries to find a randomly located empty cell  – tries to find a randomly located empty cell andand return its row and column in the array with two elements.

return its row and column in the array with two elements.

AgentDiscrete2D getAgentAtCell(int r, int c)AgentDiscrete2D getAgentAtCell(int r, int c) – returns the agent located in the cell – returns the agent located in the cell with a given row and column, or null.

with a given row and column, or null.

int getColumns()int getColumns() – Returns the number of columns in the space. – Returns the number of columns in the space.

int getRows()int getRows() – Returns the number of rows in the space. – Returns the number of rows in the space.

Continuous 2D and 3D space Continuous 2D and 3D space

Continuous space

Continuous space (two- or three-dimensional) in AnyLogic is infinite space with real (two- or three-dimensional) in AnyLogic is infinite space with real number coordinates (Java type for coordinate is

number coordinates (Java type for coordinate is doubledouble). Continuous 2D space is). Continuous 2D space is assumed by default when a new agent class is created. If you want to apply standard assumed by default when a new agent class is created. If you want to apply standard layouts or networks to the agents, you should

layouts or networks to the agents, you should use theuse theEnvironmentEnvironment object. Otherwise, object. Otherwise, the

theEnvironmentEnvironment object can be omitted in the model. object can be omitted in the model.

To create an agent population living in continuous 2D or 3D space:

To create an agent population living in continuous 2D or 3D space:

25.

25. Drag theDrag theAgent populationAgent population object from the object from theGeneralGeneral palette to the graphical palette to the graphical editor.

editor.

26.

26. In theIn theConfigure new environmentConfigure new environment page of the wizard choose page of the wizard chooseSpace typeSpace type::

Continuous 2D

Continuous 2D or orContinuous 3DContinuous 3D and choose the width and height, and the initial and choose the width and height, and the initial layout.

layout.

The options of the

The options of the EnvironmentEnvironment object related to the continuous space are shown in the object related to the continuous space are shown in the Figure. The

Figure. TheWidthWidth and andHeightHeight are are not the bounds of the entire spacenot the bounds of the entire space ; the space is always; the space is always infinite and unbounded. These are the bounds of the layout, and they apply each time infinite and unbounded. These are the bounds of the layout, and they apply each time the layout is applied (in most cases, the layout is applied once, when the model

the layout is applied (in most cases, the layout is applied once, when the model initializes). The agents can freely cross

initializes). The agents can freely cross these bounds when they move.these bounds when they move.

Continuous 2D space options (Advanced page of the Environment properties) Continuous 2D space options (Advanced page of the Environment properties) When you create an agent p

When you create an agent population, or when you drop an individual agent on opulation, or when you drop an individual agent on thethe canvas of the container object, its animation is also placed there. The design-time canvas of the container object, its animation is also placed there. The design-time position of the animation defines the point where the agent with coordinates (0,0) will position of the animation defines the point where the agent with coordinates (0,0) will be displayed at runtime (see the Figure), but

be displayed at runtime (see the Figure), but does not affect the actual coordinates ofdoes not affect the actual coordinates of the agent 

the agent ..

If there is more than one

If there is more than one agent population or individual agent and, agent population or individual agent and, correspondingly,correspondingly, more than one embedded agent animation, it makes sense to place all the animations more than one embedded agent animation, it makes sense to place all the animations into the same point to make sure that at runtime the positions of the agent animations into the same point to make sure that at runtime the positions of the agent animations are consistent with their coordinates.

are consistent with their coordinates.

Continuus 2D space is chosen Continuus 2D space is chosen

The bounding rectangle of the layout The bounding rectangle of the layout

Random, arranged, ring, Random, arranged, ring, spring mass, or custom spring mass, or custom

Also: random, ring Also: random, ring lattice, small world, lattice, small world, and scale free and scale free

To see the agent animation in the 3D scene, make sure its

To see the agent animation in the 3D scene, make sure its Show in 3D sceneShow in 3D scene checkbox is checkbox is selected.

selected.

The meaning of the width, height, and the layout properties The meaning of the width, height, and the layout properties

Space

Space type: Continuous 2D type: Continuous 2D Width: 200

Width: 200 Height: 200 Height: 200

Layout type: Random Layout type: Random Editor’s

Editor’s coordinate coordinate origin origin The The animation animation of of agents agents from from the the population population houses.houses.

The agent with coordinates (0,0) will be displayed here The agent with coordinates (0,0) will be displayed here

The rectangle 200 x 200.

The rectangle 200 x 200.

When the layout is When the layout is applied, these bounds applied, these bounds are assumed

are assumed

Movement in continuous space Movement in continuous space

The agent movement is always

The agent movement is always piecewise linear  piecewise linear : the agent moves along straight line: the agent moves along straight line segments at constant velocity. To initiate

segments at constant velocity. To initiate a straight-line movement from the currenta straight-line movement from the current position to the point with coordinates (

position to the point with coordinates (Xb,Yb), you should call the functionXb,Yb), you should call the function moveTo( Xb,moveTo( Xb, Yb )

Yb ), in 3D space this is, in 3D space this is moveTo( Xb, Yb, Zb )moveTo( Xb, Yb, Zb ). Optionally, you can suggest a polyline-based. Optionally, you can suggest a polyline-based trajectory for the agent movement by providing the polyl

trajectory for the agent movement by providing the polyline as the last ine as the last parameter ofparameter of the

themoveTo()moveTo() function, e.g. function, e.g.moveTo( x, y, z, polyline )moveTo( x, y, z, polyline ), see the Figure. The agent will first, see the Figure. The agent will first move from its current location to the closest point on the polyline along the shortest move from its current location to the closest point on the polyline along the shortest straight line, then move along the polyline to the point on the polyline closest to the straight line, then move along the polyline to the point on the polyline closest to the destination, and then straight to the destination point. You can model movement along destination, and then straight to the destination point. You can model movement along curved trajectories by approximating them by polylines.

curved trajectories by approximating them by polylines.

The agent stops when it reaches the destination point, or when

The agent stops when it reaches the destination point, or when stop()stop() or or jumpTo() jumpTo() is is called. You can also call

called. You can also callmoveTo()moveTo()another time while the agent is moving, and it willanother time while the agent is moving, and it will then change its direction.

then change its direction.

The velocity of the agent is set at the bottom of its

The velocity of the agent is set at the bottom of its AgentAgent property page and can be property page and can be changed at runtime by calling the function

changed at runtime by calling the functionsetVelocity()setVelocity(). If this function is called when. If this function is called when the agent is moving, it continues to

the agent is moving, it continues to move with the new velocity. To move with the new velocity. To modelmodel acceleration/deceleration you can break down the movement into

acceleration/deceleration you can break down the movement into small segments andsmall segments and increase or decrease the agent velocity at the beginning of a segment.

increase or decrease the agent velocity at the beginning of a segment.

Movement in continuous 2D space Movement in continuous 2D space

(Xa,Ya) (Xa,Ya)

(Xb,Yb) (Xb,Yb)

moveTo( Xb, Yb, polyline ) moveTo( Xb, Yb, polyline )

(Xa,Ya) (Xa,Ya)

(Xb,Yb) (Xb,Yb) moveTo( Xb, Yb )

moveTo( Xb, Yb )

On arrival is called here On arrival is called here

This is the front side of This is the front side of the agent animation the agent animation

When an agent moves, the right-hand side of its animation is the front side. To change When an agent moves, the right-hand side of its animation is the front side. To change the front side, you need to rotate the animation.

the front side, you need to rotate the animation.

When the agent successfully reaches the destination point, its

When the agent successfully reaches the destination point, itsOn arrivalOn arrival code (specified code (specified in the

in theAgentAgent property page) is executed, and  property page) is executed, and active statecharts transitions waiting onactive statecharts transitions waiting on arrival are triggered, if there are any. The call of

arrival are triggered, if there are any. The call of moveTo()moveTo() followed by an arrival- followed by an arrival-triggered transition is a frequently used patt

triggered transition is a frequently used pattern.ern.

To calculate the distance to another agent or to a point you can use the functions To calculate the distance to another agent or to a point you can use the functions distanceTo( x, y )

distanceTo( x, y ),,distanceTo( x, y, z )distanceTo( x, y, z ), and, anddistanceTo( agent )distanceTo( agent )..

To detect the moment when

To detect the moment when a geometric condition over the moving agents becomesa geometric condition over the moving agents becomes true (for example, when two agents get close to each other), you can use two

true (for example, when two agents get close to each other), you can use two approaches:

approaches:

Analytical. You can obtain the Analytical. You can obtain the time analytically using your high schooltime analytically using your high school knowledge of physics and geometry, and then schedule

knowledge of physics and geometry, and then schedule the required action atthe required action at the exact moment of time with the help of event or transition. The solution will the exact moment of time with the help of event or transition. The solution will be 100% accurate and very efficient computationally.

be 100% accurate and very efficient computationally.

Test the condition periodically (polling). You can introduce time steps ("ticks")Test the condition periodically (polling). You can introduce time steps ("ticks") and test the condition on each tick. Such a model will consume a lot more CPU and test the condition on each tick. Such a model will consume a lot more CPU power, and the detection will occur with an error (the larger the time step, the power, and the detection will occur with an error (the larger the time step, the larger the error), or can be

larger the error), or can be even missed. However, this approach is simpler andeven missed. However, this approach is simpler and also more general.

also more general.

The example Air defense system presented

The example Air defense system presented below demonstrates most of continuousbelow demonstrates most of continuous space modeling techniques.

space modeling techniques.

Example: Air defense system Example: Air defense system

We will build a simple model of a radar-based air defense system. All types of agents We will build a simple model of a radar-based air defense system. All types of agents in this model (bomber aircrafts, radars, missiles,

in this model (bomber aircrafts, radars, missiles, bombs, and buildings) live andbombs, and buildings) live and interact in continuous 3D space. We will use various kinds of movement and space interact in continuous 3D space. We will use various kinds of movement and space sensing techniques.

sensing techniques.

Bombers are sent to destroy ground assets

Bombers are sent to destroy ground assets (buildings) compactly located in a c(buildings) compactly located in a c ertainertain area. One aircraft is la

area. One aircraft is launched per building. Aircrafts carry bombs. To complete unched per building. Aircrafts carry bombs. To complete itsits mission successfully, an aircraft needs to

mission successfully, an aircraft needs to drop a bomb within 500 meters drop a bomb within 500 meters groundground distance from the target building while flying, at most, at 2 km altitude. Having distance from the target building while flying, at most, at 2 km altitude. Having completed the mission, the bomber returns to

completed the mission, the bomber returns to the base using a the base using a higher altitude route.higher altitude route.

The bomber speed is 600 km/h.

The bomber speed is 600 km/h.

The buildings are protected by the air

The buildings are protected by the air defense system, which consists of two defense system, which consists of two radarsradars equipped with guided surface-to-air missiles. A radar can

equipped with guided surface-to-air missiles. A radar can simultaneously guide up tosimultaneously guide up to

two missiles. A missile is

two missiles. A missile is launched once the bomber enters the launched once the bomber enters the radar’s coverage area,radar’s coverage area, which is a hemisphere of 6.5 k

which is a hemisphere of 6.5 kilometer radius around the radar. The missile ilometer radius around the radar. The missile speed isspeed is 900 km/h. The missile explodes once it gets as close as 300 meters to the aircraft. If 900 km/h. The missile explodes once it gets as close as 300 meters to the aircraft. If the missile exits the radar coverage area before it hits the aircraft, it destroys itself.

the missile exits the radar coverage area before it hits the aircraft, it destroys itself.

Create the scene:

Create the scene:

1.

1. Create a new model. Drag aCreate a new model. Drag aRectangleRectangle shape into the editor of shape into the editor ofMainMain, place its, place its top left corner at (0,0), and set its size to 800 x 600. We will

top left corner at (0,0), and set its size to 800 x 600. We will assume 10 pixelsassume 10 pixels per kilometer scale.

per kilometer scale.

2.

2. Set theSet theLine colorLine color of the rectangle to of the rectangle toNo colorNo color and use and useEarth textureEarth texture for the for theFillFill color

color..

3.

3. Check theCheck theShow in 3D sceneShow in 3D scene checkbox on the checkbox on theGeneralGeneral page of the rectangle page of the rectangle properties. On the

properties. On the AdvancedAdvanced property page set the rectangle’s Z to -1 and Z- property page set the rectangle’s Z to -1 and Z-height to 1.

height to 1.

4.

4. Finally, on theFinally, on theGeneralGeneral page check the page check theLockLock checkbox. This prevents the checkbox. This prevents the rectangle from being selected and we will be able to

rectangle from being selected and we will be able to freely draw on top of it.freely draw on top of it.

5.

5. Open theOpen the3D3D palette and drag the palette and drag the3D window3D window to the editor of to the editor of MainMain. Place the. Place the window below the ground rectangle, for example, at

window below the ground rectangle, for example, at (0,850) and extend it to(0,850) and extend it to the size of 800 by 550 pixels.

the size of 800 by 550 pixels.

6.

6. From theFrom thePresentationPresentation palette drag the palette drag theView areaView areaand place it at (0,800). Set itsand place it at (0,800). Set its Name

Name to toview3Dview3D and andTitleTitle to to3D3D..

7.

7. Create another view area at Create another view area at (0,0) with the name(0,0) with the name view2Dview2D and title and title2D2D..

8.

8. Run the model. Switch between the 2D and 3D views.Run the model. Switch between the 2D and 3D views.

Create the buildings:

Create the buildings:

9.

9. Draw a closed polyline on top of the ground rectangle, as shown in the Figure.Draw a closed polyline on top of the ground rectangle, as shown in the Figure.

Name it

Name itprotectedAreaprotectedArea. Our buildings will be located within its bounds.. Our buildings will be located within its bounds.

10.

10. Drag theDrag theAgent populationAgent population object from the object from theGeneralGeneral palette to palette toMainMain (it makes (it makes sense to place it to the left of

sense to place it to the left of the ground rectangle so it does not interferethe ground rectangle so it does not interfere with the animation).

with the animation).

11.

11. On the first page of the wizard, type:On the first page of the wizard, type:

Agent class name

Agent class name::BuildingBuilding

Agent class name::BuildingBuilding

Related documents