Section 1 - Clauses, Types and Rules
We can now write a rule to record a consumer buying some good.
Create the rule buying in the buying category with the following antecedent and consequent:
and
consumer ?cons\
chosenProducer ?cons ?bestProd ?minPrice\
requires ?cons ?req\
getsMoney ?cons ?money\
is ?volBought (min ?req (truncated ?money / ?minPrice))
bought ?cons ?volBought ?bestProd
Notice how you can use any of the arithmetic primitives as a function inside the is primitive, this simplifies rule writing.
Go to the Final rulebase in the UniversalAgent type, create a category called producers and enter the rule called sold with antecedent:
and
producer ?prod\
total ?totalSold ?vol
bought ?cons ?vol ?prod
and consequent:
and
sold ?prod ?totalSold\
report "Total sales for " ?prod " were " ?totalSold
This rule totals the sales made by each producer and records it. It also prints a message on the text report transcript to report some of the results to the modeller. If you open a text report transcript before you restart a simulation you will see the messages here. There is also a numeric report transcript to report purely numeric data - this is suitable for importing into spreadsheet and statistic programs for analysis. If you click the yes button on the save data? dialogue as you restart a simulation, you will be prompted for filenames and the contents of each transcript will be saved in the appropriate file.
Try this now.
As an exercise write rules in the Final rulebase to calculate and assert the profit made by each producer, the amount spent by each consumer and to report the average profit over all the producers on a transcript (see the comment on the primitive average in the Definitions section for guidance on this).
Generated with CERN WebMaker