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

The “spec” package implements the mechanisms for specifying vehicle agent’s propoerties at creation time. To implement this package:

  1. Inside the package “edu.utdallas.mavs.traffic.simulation.sim.spec” create a class named “TrafficAgentLoader” that extends the abstract class “AgentLoader” defined in the package “edu.utdallas.mavs.divas.core.sim.common.state”. A traffic agent loader is responsible for creating a vehicle agent’s state and initializing its properties (e.g., scale, visible distance, field of view, 3D model name, task names).
  2. The “TrafficAgentLoader” provides a concrete implementation for the abstract method “createAgent”. This method creates an instance of “VehicleAgentState” and initializes its attributes. In the example we provide in this tutorial, we use the following setter methods to assign the state propoerties:
    1. “setFOV” sets the agents field of view.
    2. “setModelName” assigns a 3D model that is used to represent the vehicle agent in the 3D visualizer.
    3. “setScale” sets the “X”, “Y”, and “Z” dimensions.
    4. “setVisibleDistance” sets the visible distance range at which a vehicle agent can percieve environmental objects using the vision sensor.
    5. “setTaskNames” sets the list of tasks a vehicle agent can perform.

The following code provides an implementation for the class “TrafficAgentLoader”:

package edu.utdallas.mavs.traffic.simulation.sim.spec;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

import com.jme3.math.Vector3f;

import edu.utdallas.mavs.divas.core.sim.common.state.AgentState;
import edu.utdallas.mavs.divas.core.spec.agent.AgentLoader;
import edu.utdallas.mavs.traffic.simulation.sim.agent.tasks.MoveForwardTask;
import edu.utdallas.mavs.traffic.simulation.sim.agent.tasks.TurnLeftTask;
import edu.utdallas.mavs.traffic.simulation.sim.agent.tasks.TurnRightTask;
import edu.utdallas.mavs.traffic.simulation.sim.common.state.VehicleAgentState;

public class TrafficAgentLoader extends AgentLoader

    public AgentState createAgent(String modelName)
        AgentState agentState = createVehicleAgentState(modelName);
        return agentState;

    private VehicleAgentState createVehicleAgentState(String modelName)
        VehicleAgentState state = new VehicleAgentState();

        int modelNumber = getModelNumber(modelName);
		state.setModelName((modelName == null || modelName.isEmpty()) ? getRandomCarModel() : modelName + (modelNumber==0? "" : modelNumber));

        state.setScale(new Vector3f(5f, 5f, 5f));

        Set<String> taskNames = new HashSet<String>();

        return state;

    private int getModelNumber(String modelName)
        Random r = new Random();
        int modelNumber = 0;

            modelNumber = r.nextInt(7);
        else if(modelName.equals("car_bmw_"))
            modelNumber = 1;
        else if(modelName.equals("car_fjsuv_"))
            modelNumber = r.nextInt(7);
        else if(modelName.equals("car_rsc_"))
            modelNumber = r.nextInt(8);
        else if(modelName.equals("car_sport_"))
            modelNumber = r.nextInt(10);
        return modelNumber;

    private String getRandomCarModel()
        Random r = new Random();

        List<String> models = new ArrayList<>();

        String model = models.get(r.nextInt(models.size()));
        int modelNumber = getModelNumber(model);
        return model + modelNumber;