// Copyright 1999 Regents of The University of Michigan
// This makes all public classes defined for the simulator package available
import umich.coabs.simulator.*;
/**
This class is a decision maker that controls the group of evacuees
in its entities list. When the evacuee is not at a destination,
this decision maker boards the evacuee on a transport. When the
transport arrives at a destination for the evacuee, it disembarks
the evacuee.
@author Brad Clement, bradc@umich.edu
*/
public class DecisionMakerForEvacuees extends DecisionMaker {
int state = 0;
/**
Just passes basics up to the costructor of the parent class, DecisionMaker
*/
public DecisionMakerForEvacuees(String i, LinkedList e, Control c) {
super(i, e, c);
}
/**
This is the method that is called on each decision cycle by the Control
object of the simulator. It controls the behavior of all evacuees in
its entities list. Sometimes the evacuees will not successfully
embark or disembark a transport because the transport starts to move
out of a location. The results of these action failures are defined in
the Evacuee class. The default is nothing changes, and a message is printed.
*/
public void TakeStep() {
ListElement elem;
int i, n;
Transport t;
Location l;
Evacuee e;
boolean done = true; // The decision maker is done when all evacuees in its entity list are in safety locations
// Cycle through the list of entities
for (elem = entities.head; elem != null; elem = elem.next) {
e = (Evacuee) elem.data;
// if the evacuee, e, is currently not in a transport
if (e.getCurTransport() == null) {
// if e is not at one of its safety destinations
if (e.getDestinations().Find(e.getCurLocation()) == null) {
// If there is at least one transport here, embark the first one in the list (head.data)
if (e.getCurLocation().getTransports().size > 0) {
// Calls to an entity's actions are made directly, but the result is spread
// out over the duration of the actions' executions
e.Embark((Transport) e.getCurLocation().getTransports().head.data);
}
// Cannot be done, yet, since this evacuee hasn't reached a safety location
done = false;
}
// e is in a transport
} else {
// Not done, yet, since's an evacuee travelling in a transport
done = false;
// If the transport is at a safety destination, e disembarks
if (e.getCurLocation() != null)
if (e.getDestinations().Find(e.getCurLocation()) != null) {
e.Disembark();
}
}
}
// Stop the control loop of the simulator when all evacuees are at destinations
if (done) {
System.out.println("Mission accomplished!");
ctrl.StopSimulator();
}
}
}