Using this vocabulary

Solve these (separate) problems

  1. Given an arbitrary number of collections of cars, find the set of cars that is common to all collections (based on make and model).This is effectively intersection of sets.
  2. Identify cars that do not exist in any other collection (Disjunction)
  3. For each collection of cars eliminate all but the most expensive instance of each make and model
  4. Assign a unique id to every car

 

Intersection of collections

The intersection rule sheet can operate on an arbitrary number of collections and will find the set of cars that is common to all of the collections. It does this by eliminating any car not found in a different collection.

Test Case

      

Result

  

This has the advantage that it’s nice and simple, but suffers from the disadvantage that we are deleting the cars that are not in all the groups. Suppose we want to make a collection of the cars in all groups while leaving the other cars alone. How can we do this?

Here’s one way:

 

Condition b is a little odd looking. If rule 1 fails to find the car in any other group then the attribute existsInAnotherGroup is set to F (just one is enough). When we get to rule 2 we are looking for just those cars that DID NOT get flagged with F (they will still be null). Those are the ones that must be in every group.

Results

   

The cars in the Intersection object are references to the original cars that still remain in the initial groups.

Also note that even though Ford T is repeated in different groups its physically a different car (just with the same make and model)

If we want the original groups to reference single instances of each make and model we’d do it like this:

   

Each make and model is now only defined once and each group makes a reference to it.

Note: In order to create this test data where more than one group references the SAME car you need to drag an associated car from the vocabulary to a Group but then hold down the SHIFT key before releasing the mouse button. This will then present a menu of cars that you can select to be associated with that group.

Only cars not already associated with that group will be available to select.

Also, since a physical car can now belong to one or more groups, it’s necessary to modify the vocabulary to allow a many-to-many association between Groups and Cars.

Test Case

We don’t need to change the rule sheet.

 

 

Disjunction (Difference)

This disjunction rule sheet operates on TWO collections

It won’t work if you have more than two collections. Can you see why? Can you create a rule sheet that WILL work with more than two collections?

Test Case

  

  

 

Dealing with More than 2 Collections

Here’s one way to do it

Remember that Corticon will apply rule 1 to all cars in all groups before moving on to rule 2

Applied to the original four groups we get this output:

 

Identify Most Expensive Cars

Assign Unique Indexes

Action A sets all the index values to zero.

Action B sets every index 1 more than the max value (so far).

So each time  Thing has its index value set, there is a new max value for the next Thing.

Alternative (procedural)

Download

Download PDF version.