LinkedList allActorList = new LinkedList();
// Populate it.
for (Iterator entities = container.deepEntityList().iterator(); entities
.hasNext();) {
ComponentEntity entity = (ComponentEntity) entities.next();
// Fill allActorList with the list of things that we can schedule
// FIXME: What if other things can be scheduled than actors?
if (entity instanceof Actor) {
allActorList.addLast(entity);
}
}
// externalRates maps from external
// ports to the number of tokens that that port
// will produce or consume in each firing.
// It gets populated with the fractional production ratios
// and is used in the end to set final rates on external ports.
// This map is initialized to zero.
Map externalRates = new TreeMap(new DFUtilities.NamedObjComparator());
// Initialize externalRates to zero.
for (Iterator ports = container.portList().iterator(); ports.hasNext();) {
IOPort port = (IOPort) ports.next();
externalRates.put(port, Fraction.ZERO);
}
// An association between all the relations in a simulation and
// and array of the maximum number of tokens that are ever
// waiting on that relation.
Map minimumBufferSize = new TreeMap(
new DFUtilities.NamedObjComparator());
// Initialize the buffer size of each relation to zero.
for (Iterator relations = container.relationList().iterator(); relations
.hasNext();) {
Relation relation = (Relation) relations.next();
minimumBufferSize.put(relation, Integer.valueOf(0));
}
// First solve the balance equations
Map entityToFiringsPerIteration = _solveBalanceEquations(container,
allActorList, externalRates);
if (_debugging && VERBOSE) {
_debug("Firing Ratios: " + entityToFiringsPerIteration.toString());
}
// A list that contains actors that do not fire.
LinkedList deadActorList = new LinkedList();
LinkedList liveActorList = new LinkedList();
// Populate deadActorList.
for (Iterator actors = allActorList.iterator(); actors.hasNext();) {
ComponentEntity actor = (ComponentEntity) actors.next();
// Remove this actor from the firing sequence if it will
// not be fired.
Fraction firing = (Fraction) entityToFiringsPerIteration.get(actor);
if (_debugging && VERBOSE) {
_debug("Actor " + actor.getName() + "fires "
+ firing.getNumerator() + " times.");
}
if (firing.getNumerator() == 0) {
if (_debugging && VERBOSE) {