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

Section 1 - Clauses, Types and Rules

1.7 Lists and choices


Evaluate (separately) the clauses below in the Experiment page to see the effects of different primitives. You can either type them separately in the pane and delete the last one or type them all in the pane and use the mouse to select each one before you evaluate it.

sortedList ?list ?prod

(fixedCost ?prod ?cost)

then this one

sortedList ?list ?cost

(fixedCost ?prod ?cost)

then this

and

sortedList ?list ?cost

(fixedCost ?prod ?cost)\

subList ?cheapest ?list 1 3

subList takes the list in the second argument and chops it between the positions given at the end to give the first argument's binding.

and

sortedList ?list ?cost

(fixedCost ?prod ?cost)\

subList ?bestList ?list 1 3\

mappedList ?bestProducers ?bestList fixedCost

mappedList applies a certain clause to every element in a list in turn and unifies with a list of the results. The syntax of the clause used by mappedList must be such that the results of such an application gives the first argument of the clause from the second.

Next try this (evaluate it several times):

randomChoice ?producer ?prod 1

(fixedCost ?prod ?cost)

This clause gives you a random choice of the variable out of all the bindings possible for the subclause fixedCost ?prod ?cost (to find out what these are, select the subclause inside the bracket and evaluate it). The "1" in the above clause needs some demonstration and explanation.

Try the following (separately):

and

randomChoice ?firstProducer ?prod 1

(fixedCost ?prod ?cost)\

randomChoice ?anotherProducer ?prod 2

(fixedCost ?prod ?cost)\

and

randomChoice ?firstProducer ?prod 1

(fixedCost ?prod ?cost)\

randomChoice ?anotherProducer ?prod 1

(fixedCost ?prod ?cost)\

In the first example it (probably) gives different choices for ?firstProducer and ?anotherProducer, in the second it gives the same choice. This is because in the second example the third argument (the "1") is the same in each case. This argument determines a unique reference for the random choice made. During a evaluation (or a whole simulation) the same reference basically gives the same choice each time. This allows control of the choices made and for much easier debugging, since if you rewind a simulation you will get the same choice the next time. If you completely restart the simulation (or re-evaluate a clause in the experiment page) you get a different randomisation. This term is called a uniquifying term and is used with several SDML primitives including: randomNumber, randomList, generatedInstance and arbitaryChoice.

Try the following (separately):

and

randomNumber ?number 1\

randomNumber ?another 2

and

randomNumber ?number 1\

randomNumber ?another 1

The uniquifying term can be any SDML term (without uninstantiated variables).

Try the following (separately):

and

producer ?prod\

randomNumber ?number ?prod

and

producer ?prod\

inInterval ?year 1990 1996\

randomNumber ?number [?prod ?year]\

= ?interestRate ?number

In the second case we have ensured that we will get a different interest rate for each producer and year between 1990 and 1996 since we have a pair of the producer and date for the uniquifying term. randomNumber always gives a non-negative number less than one.


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

Generated with CERN WebMaker