Map states = new Hashtable(); //Maps (Actions => states (which the actions are applied in))
Iterator ait = top.getActions().iterator();
TemporalMetricState state = problem.getTemporalMetricInitialState();
while (ait.hasNext())
{
Action a = (Action) ait.next();
if (a instanceof StartInstantAction)
{
StartInstantAction sia = (StartInstantAction) a;
List l = TemporalConstraint.getBounds(sia, sia.getSibling(), sia.parent.getMaxDuration(state), sia.parent.getMinDuration(state));
stn.addConstraints(new HashSet(l));
}
states.put(a, state);
state = (TemporalMetricState) state.apply(a);
}
stn.consistent();
// sort out the resources
Map graphs = new Hashtable(); //Maps (NamedResources => PrecedenceGraphs)
ait = top.getActions().iterator();
while (ait.hasNext())
{
Action a = (Action) ait.next();
Iterator bcit = a.getComparators().iterator();
while (bcit.hasNext())
{
//WARNING WARNING WARNING - assumes comparators are of the form (NamedFunction </>/<=/>= StaticFunction)
BinaryComparator bc = (BinaryComparator) bcit.next();
NamedFunction res = (NamedFunction) bc.first;
PrecedenceResourceGraph prg = (PrecedenceResourceGraph) graphs.get(res);
if (prg == null)
{
prg = new PrecedenceResourceGraph(stn);
graphs.put(res,prg);
}
state = (TemporalMetricState) states.get(a);
BigDecimal d = bc.second.getValue(state);
prg.addCondition(new BinaryComparator( bc.type, res, new NumberFunction(d)), a);
}
Iterator roit = a.getOperators().iterator();
while (roit.hasNext())
{
ResourceOperator ro = (ResourceOperator) roit.next();
NamedFunction res = (NamedFunction) ro.resource;
PrecedenceResourceGraph prg = (PrecedenceResourceGraph) graphs.get(res);