ix.iplan
Class PlanCheckingSimulator

java.lang.Object
  extended by ix.iplan.PlanCheckingSimulator

public class PlanCheckingSimulator
extends java.lang.Object

A simple plan-execution simulator that complains if any condition is not satisfied when a node-end is executed after obeying all ordering constraints. To ensure that it's an independent check, it doesn't share any interesting code with the planner. It doesn't even use a status-change propagation algorithm to determine the execution order; it just does a topological sort of the node-ends. However, it independently maintains a set of ready-to-execute node-ends in order to check that they wouldn't delete any of the executing node-end's conditions if they'd been chosen to execute instead.

This class is partly based on parts of O-Plan.

See Also:
AutoTester, PlanTest

Nested Class Summary
protected  class PlanCheckingSimulator.CheckingInterpreter
           
protected  class PlanCheckingSimulator.ConstraintChecker
           
protected  class PlanCheckingSimulator.ExecOrderSorter
          Topological sort for node-ends to provide a total order that can be used to simulate execution.
protected  class PlanCheckingSimulator.UseChecker
           
 
Field Summary
protected  TwoKeyHashMap<Symbol,Symbol,PlanCheckingSimulator.ConstraintChecker> checkerTable
           
protected  ComputeInterpreter computeInterpreter
           
protected  java.util.List<PNodeEnd> executionOrder
           
protected static Symbol FALSE
           
protected  Ip2ModelManager modelManager
           
protected  java.util.List<java.lang.String> problems
           
protected  java.util.Random random
           
protected  boolean randomized
           
protected  long randomSeed
           
protected  SanityChecker sanityChecker
           
protected  boolean shuffle
           
protected  boolean trace
           
protected  java.io.PrintStream traceOut
           
protected static Symbol TRUE
           
protected  java.util.Map worldState
           
 
Constructor Summary
PlanCheckingSimulator(Ip2 ip2)
          Creates a simulator for the specified agent's current plan.
PlanCheckingSimulator(Plan plan, Domain domain)
          Creates a simulator for the specified plan and domain.
 
Method Summary
protected  void checkComputeCondition(Constraint c)
           
protected  void checkComputeResult(LList p, java.lang.Object expected, java.lang.Object actual)
           
protected  void checkConditions(PNodeEnd ne, java.util.Set ready)
           
protected  void checkConstraint(Constraint c, PNodeEnd at)
           
protected  void checkForDeleters(PNodeEnd ne, LList p, java.lang.Object v, java.util.Set ready)
           
protected  void checkNodeEndStatusValue(PNodeEnd end)
           
protected  void checkNodeEndStatusValues()
           
protected  void checkNodeStatusValues()
           
protected  void checkOtherConstraints(PNodeEnd ne)
           
 void describeChangedWorldState()
           
 void describeChangedWorldState(java.io.PrintStream out)
           
 void describeFinalWorldState()
           
 void describeFinalWorldState(java.io.PrintStream out)
           
protected  void describeState(java.io.PrintStream out, java.lang.String label, java.util.Map state)
           
protected  void doEffects(PNodeEnd ne)
           
 java.util.Map getChangedWorldStateMap()
           
protected  java.util.List getConditions(PNodeEnd ne)
           
protected  java.util.List getEffects(PNodeEnd ne)
           
 java.util.List<PNodeEnd> getExecutionOrder()
           
 java.util.Map getInitialWorldStateMap()
           
 Ip2ModelManager getModelManagerBeingChecked()
          Returns the model-manager that contains the model that this simulator is checking.
 java.util.List<java.lang.String> getProblems()
           
 java.util.Map getWorldStateMap()
           
protected  java.util.List<PNodeEnd> keepIf(Status status, java.util.List<PNodeEnd> nodeEnds)
           
static void main(java.lang.String[] argv)
          Standalone main program for testing.
protected  boolean matchComputeResult(java.lang.Object expected, java.lang.Object actual)
           
protected  java.util.List<PNodeEnd> maybeShuffle(java.util.List<PNodeEnd> list)
           
protected  void nextExecFringe(java.util.Set ready, java.util.Set waiting, java.util.Set complete)
          Moves node-ends from waiting to ready.
protected  void problem(java.lang.String description)
           
 void processCommandLineArguments()
           
 void randomize()
          Changes this simulator's random number generator to one set up with a seed based on the current time.
protected  void register(java.lang.String type, java.lang.String relation, PlanCheckingSimulator.ConstraintChecker c)
           
protected  void registerConstraintCheckers()
           
protected  java.util.List<PNodeEnd> removeIf(Status status, java.util.List<PNodeEnd> nodeEnds)
           
 void report()
           
 void report(java.io.PrintStream out)
           
protected  void resetConstraintCheckers()
           
 void run()
          Simulates execution.
 void setShuffle(boolean shuffle)
          Controls whether the node-ends are permuted when putting them in order for execution.
 void setTrace(boolean trace)
          Tells this simulator whether or not it should produce trace output.
 void setTraceOutput(java.io.PrintStream ps)
          Sets the stream on which trace output appears.
 void traceln(java.lang.String message)
           
 void traceln(java.lang.String message, java.lang.Object obj)
           
protected  void wrongStatusProblem(HasStatus h, Status correct)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRUE

protected static final Symbol TRUE

FALSE

protected static final Symbol FALSE

modelManager

protected Ip2ModelManager modelManager

computeInterpreter

protected ComputeInterpreter computeInterpreter

sanityChecker

protected SanityChecker sanityChecker

checkerTable

protected TwoKeyHashMap<Symbol,Symbol,PlanCheckingSimulator.ConstraintChecker> checkerTable

worldState

protected java.util.Map worldState

problems

protected java.util.List<java.lang.String> problems

executionOrder

protected java.util.List<PNodeEnd> executionOrder

random

protected java.util.Random random

shuffle

protected boolean shuffle

trace

protected boolean trace

randomSeed

protected long randomSeed

randomized

protected boolean randomized

traceOut

protected java.io.PrintStream traceOut
Constructor Detail

PlanCheckingSimulator

public PlanCheckingSimulator(Ip2 ip2)
Creates a simulator for the specified agent's current plan.


PlanCheckingSimulator

public PlanCheckingSimulator(Plan plan,
                             Domain domain)
Creates a simulator for the specified plan and domain.

Method Detail

getModelManagerBeingChecked

public Ip2ModelManager getModelManagerBeingChecked()
Returns the model-manager that contains the model that this simulator is checking.


setShuffle

public void setShuffle(boolean shuffle)
Controls whether the node-ends are permuted when putting them in order for execution. If the argument is true, a random number generator is created using this simulator's current random seed, and the simulator will use that generator when making lists of node-ends while determining the execution order. All of the ordering constraints will still be obeyed, but this can change the relative order of node-ends that aren't constrained against each other.

If the argument is false, any current random number generator is discarded, and the simulator will not permute the node-ends.

There is no way to explicitly set the random seed (though that might change in a subclass). There is a fixed default seed to allow repeatable simulations; or else a seed based on the current time can be set by calling randomize().


randomize

public void randomize()
Changes this simulator's random number generator to one set up with a seed based on the current time. It is not necessary to separately call setShuffle(boolean), because this method calls setShuffle(true).


setTrace

public void setTrace(boolean trace)
Tells this simulator whether or not it should produce trace output. Trace output shows which node-end is being executed and when conditions and effects are eveluated.

See Also:
setTraceOutput(PrintStream)

setTraceOutput

public void setTraceOutput(java.io.PrintStream ps)
Sets the stream on which trace output appears. If this method is not called, the stream Debug.out will be used.

See Also:
setTrace(boolean)

run

public void run()
Simulates execution.


getProblems

public java.util.List<java.lang.String> getProblems()

getInitialWorldStateMap

public java.util.Map getInitialWorldStateMap()

getWorldStateMap

public java.util.Map getWorldStateMap()

getChangedWorldStateMap

public java.util.Map getChangedWorldStateMap()

getExecutionOrder

public java.util.List<PNodeEnd> getExecutionOrder()

report

public void report()

report

public void report(java.io.PrintStream out)

describeFinalWorldState

public void describeFinalWorldState()

describeFinalWorldState

public void describeFinalWorldState(java.io.PrintStream out)

describeChangedWorldState

public void describeChangedWorldState()

describeChangedWorldState

public void describeChangedWorldState(java.io.PrintStream out)

describeState

protected void describeState(java.io.PrintStream out,
                             java.lang.String label,
                             java.util.Map state)

maybeShuffle

protected java.util.List<PNodeEnd> maybeShuffle(java.util.List<PNodeEnd> list)

removeIf

protected java.util.List<PNodeEnd> removeIf(Status status,
                                            java.util.List<PNodeEnd> nodeEnds)

keepIf

protected java.util.List<PNodeEnd> keepIf(Status status,
                                          java.util.List<PNodeEnd> nodeEnds)

checkNodeStatusValues

protected void checkNodeStatusValues()

checkNodeEndStatusValues

protected void checkNodeEndStatusValues()

checkNodeEndStatusValue

protected void checkNodeEndStatusValue(PNodeEnd end)

wrongStatusProblem

protected void wrongStatusProblem(HasStatus h,
                                  Status correct)

nextExecFringe

protected void nextExecFringe(java.util.Set ready,
                              java.util.Set waiting,
                              java.util.Set complete)
Moves node-ends from waiting to ready.


traceln

public void traceln(java.lang.String message)

traceln

public void traceln(java.lang.String message,
                    java.lang.Object obj)

problem

protected void problem(java.lang.String description)

checkConditions

protected void checkConditions(PNodeEnd ne,
                               java.util.Set ready)

checkForDeleters

protected void checkForDeleters(PNodeEnd ne,
                                LList p,
                                java.lang.Object v,
                                java.util.Set ready)

checkComputeCondition

protected void checkComputeCondition(Constraint c)

checkComputeResult

protected void checkComputeResult(LList p,
                                  java.lang.Object expected,
                                  java.lang.Object actual)

matchComputeResult

protected boolean matchComputeResult(java.lang.Object expected,
                                     java.lang.Object actual)

doEffects

protected void doEffects(PNodeEnd ne)

getConditions

protected java.util.List getConditions(PNodeEnd ne)

getEffects

protected java.util.List getEffects(PNodeEnd ne)

checkOtherConstraints

protected void checkOtherConstraints(PNodeEnd ne)

checkConstraint

protected void checkConstraint(Constraint c,
                               PNodeEnd at)

register

protected void register(java.lang.String type,
                        java.lang.String relation,
                        PlanCheckingSimulator.ConstraintChecker c)

registerConstraintCheckers

protected void registerConstraintCheckers()

resetConstraintCheckers

protected void resetConstraintCheckers()

main

public static void main(java.lang.String[] argv)
Standalone main program for testing. The most useful command-line arguments are:
   -plan=resource name
   -trace=true or false, default true
   -shuffle=true or false, default false
   -randomize=true or false, default false
 

See Also:
setTrace(boolean), setShuffle(boolean), randomize()

processCommandLineArguments

public void processCommandLineArguments()