Implementing the “task” package
1. Package Description
The role of an agent’s Task Module is to define the set of concrete tasks an agent can perform. In addition, it specifies the translation of agent’s tasks into a set of stimuli that are sent later to the environment to combine and decide their effects.
This package contains the classes as listed below:
- CloseDoorTask
- FaceTask
- HumanTaskModule
- IdleTask
- MoveTask
- OpenDoorTask
2. Package implementation
Next, we describe the detailed implementation of those classes.
To implement the “CloseDoorTask” class:
-
- Create a new class inside the “task” package and name it “CloseDoorTask”.
- Copy the code given below that describes the full implementation of a “CloseDoorTask” class.
package edu.utdallas.mavs.evacuation.simulation.sim.agent.task; import edu.utdallas.mavs.divas.core.sim.agent.task.AbstractTask; import edu.utdallas.mavs.divas.core.sim.agent.task.Task; import edu.utdallas.mavs.divas.core.sim.common.stimulus.Stimuli; import edu.utdallas.mavs.evacuation.simulation.sim.common.stimulus.CloseDoorStimulus; /** * This class describes a close door task. */ public class CloseDoorTask extends AbstractTask { private static final long serialVersionUID = 1L; /** * The name of this task */ public static final String NAME = "CloseDoor"; /** * The type of this task */ public static final String TYPE = "CloseDoor"; /** * The door ID */ protected int id; /** * Creates a new close door task * * @param enabled * the enabled status of the task */ public CloseDoorTask(boolean enabled) { this(-1, enabled); } /** * Creates a new close door task * * @param executionCycle * the schedule execution cycle of the task * @param enabled * the enabled status of the task */ public CloseDoorTask(long executionCycle, boolean enabled) { super(NAME, TYPE, executionCycle, enabled); } @Override public Stimuli execute(int agentId) { Stimuli stimuli = new Stimuli(); stimuli.add(new CloseDoorStimulus(agentId, id)); return stimuli; } @Override public Task createTask(long executionCycle) { return new CloseDoorTask(executionCycle, enabled); } @Override public String toString() { return "DoorID: " + id; } public int getId() { return id; } public void setId(int id) { this.id = id; } }
To implement the “FaceTask” class:
-
- Create a new class inside the “task” package and name it “FaceTask”.
- Copy the code given below that describes the full implementation of a “FaceTask” class.
package edu.utdallas.mavs.evacuation.simulation.sim.agent.task; import com.jme3.math.Vector3f; import edu.utdallas.mavs.divas.core.sim.agent.task.AbstractTask; import edu.utdallas.mavs.divas.core.sim.agent.task.Task; import edu.utdallas.mavs.divas.core.sim.common.stimulus.Stimuli; import edu.utdallas.mavs.evacuation.simulation.sim.common.stimulus.ChangeHeadingStimulus; /** * This class describes a face task. * <p> * A face task allows an agent to look into a specific direction. */ public class FaceTask extends AbstractTask { private static final long serialVersionUID = 1L; /** * The name of this task */ public static final String NAME = "Face"; /** * The type of this task */ public static final String TYPE = "Heading"; /** * The heading direction of the agent after this task is executed */ protected Vector3f heading; /** * Creates a new face task * * @param enabled * the enabled status of the task */ public FaceTask(boolean enabled) { this(-1, enabled); } /** * Creates a new face task * * @param executionCycle * the schedule execution cycle of the task * @param enabled * the enabled status of the task */ public FaceTask(long executionCycle, boolean enabled) { super(NAME, TYPE, executionCycle, enabled); } @Override public Stimuli execute(int agentId) { Stimuli stimuli = new Stimuli(); stimuli.add(new ChangeHeadingStimulus(agentId, heading)); return stimuli; } @Override public Task createTask(long executionCycle) { return new FaceTask(executionCycle, enabled); } /** * Updates the direction to which the agent should be headed * * @param heading * the new heading direction */ public void setHeading(Vector3f heading) { this.heading = heading; } @Override public String toString() { return String.format("%s[%.1f,%.1f,%.1f]", getName(), heading.x, heading.y, heading.z); } }
To implement the “HumanTaskModule” class:
-
- Create a new class inside the “task” package and name it “HumanTaskModule”.
- Copy the code given below that describes the full implementation of a “HumanTaskModule” class.
package edu.utdallas.mavs.evacuation.simulation.sim.agent.task; import java.io.Serializable; import java.util.Set; import edu.utdallas.mavs.divas.core.sim.agent.task.AbstractTaskModule; import edu.utdallas.mavs.evacuation.simulation.sim.agent.knowledge.EvacuationHumanKnowledgeModule; public class HumanTaskModule extends AbstractTaskModule<EvacuationHumanKnowledgeModule> implements Serializable { private static final long serialVersionUID = 1L; public HumanTaskModule(EvacuationHumanKnowledgeModule knowledgeModule) { super(knowledgeModule); } @Override protected void loadTasks() { Set<String> availableTasks = knowledgeModule.getSelf().getTaskNames(); tasks.put(MoveTask.NAME, new MoveTask(availableTasks.contains(MoveTask.NAME))); tasks.put(FaceTask.NAME, new FaceTask(availableTasks.contains(FaceTask.NAME))); tasks.put(OpenDoorTask.NAME, new OpenDoorTask(availableTasks.contains(OpenDoorTask.NAME))); tasks.put(CloseDoorTask.NAME, new CloseDoorTask(availableTasks.contains(CloseDoorTask.NAME))); tasks.put(IdleTask.NAME, new IdleTask(availableTasks.contains(IdleTask.NAME))); } }
To implement the “IdleTask” class:
-
- Create a new class inside the “task” package and name it “IdleTask”.
- Copy the code given below that describes the full implementation of a “IdleTask” class.
package edu.utdallas.mavs.evacuation.simulation.sim.agent.task; import edu.utdallas.mavs.divas.core.sim.agent.task.AbstractTask; import edu.utdallas.mavs.divas.core.sim.agent.task.Task; import edu.utdallas.mavs.divas.core.sim.common.stimulus.Stimuli; import edu.utdallas.mavs.evacuation.simulation.sim.common.stimulus.IdleStimulus; /** * This class describes a open door task. */ public class IdleTask extends AbstractTask { private static final long serialVersionUID = 1L; /** * The name of this task */ public static final String NAME = "Idle"; /** * The type of this task */ public static final String TYPE = "Idle"; /** * Creates a new open door task * * @param enabled * the enabled status of the task */ public IdleTask(boolean enabled) { this(-1, enabled); } /** * Creates a new open door task * * @param executionCycle * the schedule execution cycle of the task * @param enabled * the enabled status of the task */ public IdleTask(long executionCycle, boolean enabled) { super(NAME, TYPE, executionCycle, enabled); } @Override public Stimuli execute(int agentId) { Stimuli stimuli = new Stimuli(); stimuli.add(new IdleStimulus(agentId)); return stimuli; } @Override public Task createTask(long executionCycle) { return new IdleTask(executionCycle, enabled); } @Override public String toString() { return "IDLEING"; } }
To implement the “MoveTask” class:
-
- Create a new class inside the “task” package and name it “MoveTask”.
- Copy the code given below that describes the full implementation of a “MoveTask” class.
package edu.utdallas.mavs.evacuation.simulation.sim.agent.task; import com.jme3.math.Vector3f; import edu.utdallas.mavs.divas.core.sim.agent.task.AbstractTask; import edu.utdallas.mavs.divas.core.sim.agent.task.Task; import edu.utdallas.mavs.divas.core.sim.common.stimulus.Stimuli; import edu.utdallas.mavs.evacuation.simulation.sim.common.stimulus.MoveStimulus; /** * This class describes a move task. * <p> * A move task allows an agent to move to a specific location in the environment. */ public class MoveTask extends AbstractTask { private static final long serialVersionUID = 1L; /** * The name of this task */ public static final String NAME = "Move"; /** * The type of this task */ public static final String TYPE = "Position"; /** * The position of the agent after this task is executed */ private Vector3f position; /** * Creates a new move task * * @param enabled * the enabled status of the task */ public MoveTask(boolean enabled) { this(-1, enabled); } /** * Creates a new move task * * @param executionCycle * the schedule execution cycle of the task * @param enabled * the enabled status of the task */ public MoveTask(long executionCycle, boolean enabled) { super(NAME, TYPE, executionCycle, enabled); } @Override public Stimuli execute(int agentId) { Stimuli stimuli = new Stimuli(); stimuli.add(new MoveStimulus(agentId, position)); return stimuli; } @Override public Task createTask(long executionCycle) { return new MoveTask(executionCycle, enabled); } /** * Updates the position to which the agent should be moved * * @param position * the new position */ public void setPosition(Vector3f position) { this.position = position; } @Override public String toString() { return String.format("%s[%.1f,%.1f,%.1f]", getName(), position.x, position.y, position.z); } }
To implement the “OpenDoorTask” class:
-
- Create a new class inside the “task” package and name it “OpenDoorTask”.
- Copy the code given below that describes the full implementation of a “OpenDoorTask” class.
package edu.utdallas.mavs.evacuation.simulation.sim.agent.task; import edu.utdallas.mavs.divas.core.sim.agent.task.AbstractTask; import edu.utdallas.mavs.divas.core.sim.agent.task.Task; import edu.utdallas.mavs.divas.core.sim.common.stimulus.Stimuli; import edu.utdallas.mavs.evacuation.simulation.sim.common.stimulus.OpenDoorStimulus; /** * This class describes a open door task. */ public class OpenDoorTask extends AbstractTask { private static final long serialVersionUID = 1L; /** * The name of this task */ public static final String NAME = "OpenDoor"; /** * The type of this task */ public static final String TYPE = "OpenDoor"; /** * The door ID */ protected int id; /** * Creates a new open door task * * @param enabled * the enabled status of the task */ public OpenDoorTask(boolean enabled) { this(-1, enabled); } /** * Creates a new open door task * * @param executionCycle * the schedule execution cycle of the task * @param enabled * the enabled status of the task */ public OpenDoorTask(long executionCycle, boolean enabled) { super(NAME, TYPE, executionCycle, enabled); } @Override public Stimuli execute(int agentId) { Stimuli stimuli = new Stimuli(); stimuli.add(new OpenDoorStimulus(agentId, id)); return stimuli; } @Override public Task createTask(long executionCycle) { return new OpenDoorTask(executionCycle, enabled); } @Override public String toString() { return "DoorID: " + id; } public int getId() { return id; } public void setId(int id) { this.id = id; } }