Statestep Tutorial

Creating Rules

This first section of the tutorial introduces the interface through which Statestep gives you the power to manage millions of possibilities. Of course, the example used here is a good deal smaller, with only a few dozen possible combinations.

Setting up the model

First, we need to set up the variables and other data we'll be using - that is, the model. To keep things simple, the model we'll use is a decision table. This recommends an appropriate activity depending on the outdoor conditions.

Rule Temperature Weather Wind Activity
A hot
warm
fine
rain
breeze windsurf
B cold
warm
fine
rain
calm go hillwalking
C hot fine calm lie in sun
D * * gale read a book
E * snow breeze
calm
ski

The rules correspond to the rows of the table, for example, rule A recommends windsurfing if it's either warm or hot and either fine or raining, provided there's also a breeze. An asterisk ('*') means "don't care": rule D tells us to read a book if there's a gale blowing, regardless of Temperature and Weather.

In Statestep, any set of rules like this is associated with an event. For an ordinary decision table like this, we just need to define a single event as a formality. To do this, go to the Model menu in the main window and select Events. In the window that appears, click the button to create a new event. You can call it "decide".

The next thing we need to do is define the variables, for example Temperature, which has the values cold, hot, and warm. To do this, open the variables window (also reached from the Model menu), click the button to create a new variable and enter the name "Temperature". Then, while Temperature is selected on the left of the window, use the right-hand side of the window to create its three values.

Now that you've seen these windows, let's skip along. Instead of defining the other variables, just go to the File menu of the main window and select Open. A warning will appear that your work will be lost. Ignore it and open the file "activities.s2" that came with the program - it's in a subdirectory called "samples".

If anything below is different from what you see when running the program then it may be that someone has changed the "activities.s2" model. If you suspect this has happened, re-extract the sample models from the original program package.

Working with the rule window

As well as definitions of the variables, the file you've just loaded also contains the rules in the decision table above. Go to the Model menu and select Rules to open the rules window. Click on the event (decide) shown on the left and you'll see the list of rules. Here's what you should see if you double-click on rule A:

Rule A screenshot

This picture assumes the default display options and colour scheme are in use.

This is the same as rule A in the decision table above: that's because only the values on the white background are part of the rule; the values on a green background are not selected. We'll learn more about the colours shortly. Later, we'll also find out what the second row of cells is for; we won't be using it in this example.

Tip: To view the next rule without opening another window, press Alt and the cursor down key. (You can read about other keyboard shortcuts later in the help page for the rule window.)

Looking at the rules window, you may have noticed a 'U' beside the event decide. This indicates that the rules for this event are Unfinished, that is, that there are some combinations of Temperature, Weather and Wind for which there is no rule to tell us what to do. To cover some of these other combinations, click on the button to create a new rule - you can give it the name "new1". A window then appears showing the new rule.

New rule initial

Empty cells are green - and all of the top row of cells are indeed "empty": remember, values appearing on a green background are not selected. However, an empty cell is treated as being equivalent to a cell that contains "don't care", that is, a cell in which all of the values have been selected. Because of this convention, our new rule effectively covers all possible combinations of Temperature, Weather and Wind. Consequently, it overlaps all of the existing rules. Click on Overlaps on the menu bar to see them.

So what about the colours? Every possible combination with the value gale for Wind is already covered (by rule D) and so gale is coloured blue. Similarly, rules D and E already tell us what to do in every case in which Weather is snow. The values gale and snow are redundant.

All the other values are purple: each of them appears in at least one combination that is covered by one of the other rules but also appears in at least one combination that is not covered. For example, consider the value fine: rule B tells us what to do if it's warm, fine and calm - however, no rule exists for the combination cold, fine and breeze. The values coloured purple are common.

Now right-click in the Temperature cell and select the value hot.

New rule step 1

Notice how the value fine for Weather has changed: it's now redundant. That's because all the combinations in which Weather is fine and Temperature is hot are already covered (by rules A, C and D).

Let's imagine that, seeing these colours, we decide to create a new rule suggesting windsurfing for when it's hot, raining and breezy. Actually, the combination hot, rain and breeze is already covered by rule A - but let's pretend that there are many rules and we've forgotten about rule A. Select the value rain for Weather.

Tip: Usually, the quickest way to select/unselect a value is to double-click it; if you have a three-button mouse then you can use a single click of the middle mouse button instead.

New rule step 2

The number of overlapping rules has decreased. Notice also that the Wind values have changed colour: since the combination hot, rain and breeze that we had in mind is already covered, breeze is now redundant.

On the other hand, calm is now a unique value, coloured black: this means that there is no rule to tell us what to do when Wind is calm and the other two variables have the values we've already selected. So we'll create a rule for that instead, and specify the outcome "Read a book": for Wind select calm. This causes the display to change again:

New rule step 3

Now, all the selected values are unique and we have a rule with no overlaps. Further, we can see from the colours of the values that we can also select fog for the variable Weather to cover some more uncovered combinations. We didn't select fog earlier because we originally meant to create a rule for going windsurfing (not a good idea in fog). However, reading a book seems like a good choice not only for the combination we're already covering but also for the combination hot, fog, and calm. We therefore also select fog.

New rule step 4

As you can see, some of the remaining unselected values are now common (coloured purple). We could select one or more of these to get the rule to cover more combinations which are not covered by any other rule - though at the expense of also covering some combinations that are already covered by other rules and so causing overlaps. (In fact, as we'll see later, it can be quite useful to allow rules to overlap).

To finish the rule, we just need to specify the outcome. To do this, increase the height of the rule window - you can do this by clicking on the top or bottom border and dragging the mouse while holding down the mouse button. An empty text area, which is normally displayed only if it's not empty, appears at the bottom of the window. Double-click in this box to edit it and enter the text "# read a book". The "#" signals that what follows on that line is merely a comment which should be ignored by the program: without it, Statestep would try to interpret the text as a formula and you'd get an error message (more about formulas later).

Using File->Save As in the main window, save this model, including the new rule you've just defined, to a file in your home directory - call it "activitiesNew.s2". We'll be using it again later.

What we've seen here is how the changing colours help you to quickly find the cases you want to cover. Again, the power of this approach really becomes apparent only when you're addressing many more possibilities than in this example.

Next: Using the Constraint Table