Data Structures

The data structures: SolverTrait, SolverOp, SolverData.

Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won’t usually won’t usually need your flowcharts; they’ll be obvious.

  • Fred Brooks

Traits

Strings representing particular parts of the state. Wrapped in the class SolverTrait.

  • name: String

Operations

Holds the name of the action, preconditions required to apply it, and sets of traits that are added or removed when the action is performed.

Wrapped in SolverOp class.

  • name: String
  • precond: Set of SolverTrait
  • add: Set of SolverTrait
  • remove: Set of SolverTrait

SolverData

All of the data given in a problem. Used to drive the solver.

  • title: String
  • traits: Set of SolverTrait.
  • initial_state: Set of SolverTrait.
  • goal_state: Set of SolverTrait.
  • ops: List of SolverOp

Also available:

  • trait_set: list of string -> list of SolverTrait. Error if it encounters a string that is not listed in the traits.
  • operation_lookup: a dictionary with key being a the name of an operation and value being the corresponding SolverOp. This is not a function, so you use it with brackets. Example: lookup["put on shirt"].
  • dump(): Return a string representation in TOML format.

Check for Understanding

  • Create your own file shirtdemo.toml. It should include traits for shirt colors red, orange, yellow, green, blue, as well as operations for putting on each shirt. Add one extra trait called “seaswim” which you can get by wearing a blue shirt and using the “get wet” operation. Your initial state is [“pants on”]. Your goal state is [“pants on”,“blue shirt”, “seaswim”].

  • Read in the file and make a SolverDemo object called shirtdemo.

  • Begin with y = SolverTrait('yellow') and do a linear search the set of traits of shirtdemo to find y. Print how many comparisons you make before you find y.

  • Find the operation that adds a blue shirt.

  • Apply the operation to your initial state.

  • Find the “get wet” operation and apply it to your current state.

  • Print out the name of every trait in the current state.