+1 (972) 883-2091
ECSS 4.220, 800 W Campbell Rd, Richardson, TX 75083–0688, US

Implementing the “stimulus” package

1. Package Description

This package contains the definitions of an agent’s stimuli. In case of the traffic simulation, the vehicle agent generates two types of stimuli: move and change heading. To this effect, we create two classes inside the “stimulus” package that correspond to these stimuli. We name these classes “MoveStimulus” and “ChangeHeadingStimulus” (see the figure below). These classes extend the class “AgentStimulus” defined inside the package “edu.utdallas.mvs.divas.core.sim.comon.stimulus”.

After creating the stimuli classes, the project explorer should look like the following:

2. Implementing the “MoveStimulus” class

The “MoveStimulus” class describes the movement stimulus generated by a vehicle agent to indicate its desire to move to a new location. It stores information about the vehicle’s intended new location. To implement this class:

  1. Create a new class inside the package “edu.utdallas.mvs.divas.core.sim.comon.stimulus” and name it “MoveStimulus”
  2. Write the following code to implement the “MoveStimulus” class:
   
package edu.utdallas.mavs.traffic.simulation.sim.common.stimulus;

import com.jme3.math.Vector3f;
import edu.utdallas.mavs.divas.core.sim.common.stimulus.AgentStimulus;

public class MoveStimulus extends AgentStimulus implements Comparable<MoveStimulus>
{
    private float             x;
    private float             y;
    private float             z;

    public MoveStimulus(int id, Vector3f position)
    {
        this(id, position.x, position.y, position.z);
    }

    public MoveStimulus(int id, float x, float y, float z)
    {
        super(id);

        this.x = x;
        this.y = y;
        this.z = z;
    }

    /**
     * Get the position where the agent wishes to move.
     * 
     * @return the position where the agent wishes to move
     */
    public Vector3f getPosition()
    {
        return new Vector3f(x, y, z);
    }

    @Override
    public int compareTo(MoveStimulus o)
    {
        if(this.id > o.id)
            return 1;
        else if(this.id < o.id)
            return -1;
        else
            return 0;
    }
}

 

3. Implementing the “ChangeHeadingStimulus” class

The “ChangeHeadingStimulus” class describes the stimulus generated by a vehicle agent to indicate its desire to change its heading. This class stores information about the new intended vehicle agent’s heading. To create this class:

  1. Create a new class inside the package “edu.utdallas.mvs.divas.core.sim.comon.stimulus” and name it “ChangeHeadingStimulus”
  2. Write the following code to implement the “ChangeHeadingStimulus” class:
package edu.utdallas.mavs.traffic.simulation.sim.common.stimulus;

import com.jme3.math.Vector3f;
import edu.utdallas.mavs.divas.core.sim.common.stimulus.AgentStimulus;

public class ChangeHeadingStimulus extends AgentStimulus
{
    private float             x;
    private float             y;
    private float             z;
    public ChangeHeadingStimulus(int id, Vector3f heading)
    {
        this(id, heading.x, heading.y, heading.z);
    }

    
    public ChangeHeadingStimulus(int id, float x, float y, float z)
    {
        super(id);
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public float getX()
    {
        return x;
    }

    public void setX(float x)
    {
        this.x = x;
    }

    public float getY()
    {
        return y;
    }

    public void setY(float y)
    {
        this.y = y;
    }

    public float getZ()
    {
        return z;
    }

    public void setZ(float z)
    {
        this.z = z;
    }

    public Vector3f getHeading()
    {
        return new Vector3f(x, y, z);
    }
}