## The Use Case

We want a decision model that can allocate tasks to resources based on matching the task requirement to the resource capability. As part of this process we’ll want to calculate the total cost of each possible assignment of resource to task.

The total cost of an assignment will be the task duration * the resource cost.

The problem is complicated by the fact that our resources can be:

1. Humans (costPerHour=baseCostPerHour + additionalCostPerHour)
2. Equipment (costPerHour=fuelCostPerHour + maintenanceCostPerHour)
3. Robots (costPerHour=baseCostPerHour+ fuelCostPerHour + maintenanceCostPerHour)

And since these different kinds of resource have different attributes associated with them how do we model the vocabulary and write appropriate rules?

## Classical Approach

The classical approach would be to have a vocabulary like this for Resource which has all the attributes required plus a type attribute to indicate what type of resource it is:

But as you can see not all of the attributes apply to all of the resource types. Humans don’t have a date of manufacture or a fuel cost per hour, whereas equipment does.

If we combine all the attributes into a single object then in order to calculate the resource costs we’ll need a rule sheet something like this:

Action E represents additional cost for Equipment and Robots

Action F represents additional cost for workers (Humans and Robots)

This is how we might do it in the absence of the Inheritance feature of Corticon

Then we could use a very simple rule sheet like this to perform the allocation of resources to tasks:

## Using Inheritance

### The Vocabulary

Resource now is greatly simplified to just the attributes needed for the resource allocation rule sheet.

The different types of resources are now defined as separate entities that INHERIT from the Resource entity. The grey indicates inherited attributes

Humans are a type of worker and so inherit their characteristics

Corticon supports multiple inheritance so we can show that Robots inherit from both Worker and Equipment entities.

But now that we have all these different entities for different kinds of resource doesn’t this make the resource allocation rule sheet more complex?

No. It does not change at all:

The reference to Resource will automatically include ALL entities that inherit from Resource.

This means you can add new types of Resource without needing to change the allocation rule sheet.

The only requirement is that rules exist for each entity to calculate the resource cost per hour since that is required in the allocation rule sheet.

In some ways this is similar to the concept of Interfaces in programming languages with the exception that there is no concept of a method that must be implemented – instead you must ensure rules calculate any required data elements.

### The Rule Sheets

In order to calculate the cost per hour you could write a single rule sheet like this:

Note that it is very similar to the first rule sheet except that we can now refer explicitly to the various types of resource (such as Human or Robot).

An alternative approach might be to have a separate rule sheet for each kind of Resource (this would be closer in concept to the idea of methods for interfaces). So that whenever you add a brand new type of resource you also add the rule sheet that calculates its cost per hour.  Any extra costs that might apply (by virtue of your new entity being a type of Equipment) would be handled automatically by the Equipment rule sheet.

Note that since Robots are also Workers and Equipment, three rule sheets will apply to Robots each one supplying the relevant costs.