[Next] [Previous] [Up] [Top] [Contents]

Section 2 - Modules, Time Levels and Lists

2.10 More examples using time


Up to this point the simulation is very similar to the one we made yesterday, but now we will have new producers entering the market each week (who will have to be allocated a cost structure, and some capital) and some producers who have survived from the last week. We will start with the new producers.

Add a producers category to the Initial iteration rulebase and write a rule called create new producers based on the parameter set by the clause noProducers ?no and with the consequent:

all week (producer ?producer)

We will frequently want to distinguish between new and existing producers. So we will write a backward clause to save us time. This is done in the same manner as the randomProducerChoice and bestOF predicates defined in the previous lesson.

Create a backward chaining predicate called newProducer, just taking one argument of type Producer, in the producer - transient category of the Definitions, with the antecedent:

and

producer ?producer\

notInferred

last week (producer ?producer)

The subclause last week (producer ?producer) would bind with any clauses of the form producer ?producer only in the previous week (if there was one). In fact it will check in the last iteration of the previous week (after the Final iteration rule base has finished). If there was no previous week (i.e. it was the first week) this would fail.

Similarly create another backward chaining clause oldProducer.

The new producer will need to be allocated some capital. Create a rule called initial capital under the producers category with antecedent:

and

newProducer ?producer\

capitalRange ?minCap ?maxCap\

randomNumber ?rn ?producer\

is ?capital (truncated ?rn * (?maxCap - ?minCap) + ?minCap)

and consequent:

all week (capital ?producer ?capital)

Thus the first clause of this rule will bind with all producers recorded that were not so recorded last week. In other words all the new producers.

In the Categories: pane use the command button to select the load rules command to load the file parnewpr.rb. This loads a rule called parameters for new producers to set the fixedCost, marginalCost and profitTarget clauses for the new producers.

Although the existence of the producer will have to be reaffirmed each week, its cost structure will be fixed. That is why the antecedent of the parameters for new producers rule asserts the facts for all eternity. It reads:

all eternity (and

fixedCost ?producer ?fixedCost\

marginalCost ?producer ?marginalCost\

profitTarget ?producer ?pt)

Notice also the use of and in a consequent to assert several consequences at once. Now we can create the queue of customers.

Add a consumers category to the Initial iteration rulebase. Under this create a rule called form queue with antecedent:

and

time week ?weekNo\

randomList ?consumerQueue ?cons ?weekNo

consumer ?cons

and consequent:

queue ?consumerQueue

This rule creates a list of consumers in a random order. The time clause is a way of finding out the present simulation time. We then use the resulting week number as the uniquifying term in randomList to ensure a differently shuffled list each time.

Also create a new category called prices, and create a rule to set the initial price for new producers for the week.


An introduction to SDML - Bruce Edmonds - 13 JUL 99
[Next] [Previous] [Up] [Top] [Contents]

Generated with CERN WebMaker