Messages from list : cormas@cirad.fr

Choose a topic among the following archives :

Re: changing variables over time

New Message Reply Date view Thread view Subject view Author view

Subject: Re: changing variables over time
From: Christophe Le Page (christophe.le_page@cirad.fr)
Date: Tue Sep 23 2003 - 08:56:14 CEST

Hi all,

It is a often needed to access the current simulation time from any
method of your model.
Cormas do not provide any generic mechanism to do that.
A first solution is to use as method's argument "t" from the general
scheduling method
MyModel>>step:t
    ...
    self theCells do: [:c | c stepTime: t].
    self theAgents do: [:a | a stepTime: t].
    ...

It may become laborious. Let's take an example of a simulation running
on a monthly basis for
100 time-steps. You may need to access the absolute time-step value, but
also the corresponding
month and year values (for instance, time-step = 25 ==> month = 1 and
 year = 3).

A good solution is to create specific temporal
classInstanceVariableNames to your model's class.
    CormasNS.Models.MyModel defineClass: #MyModel
        superclass: #{CormasNS.Kernel.CormasModel}
        indexedType: #none
        private: false
        instanceVariableNames: 'theCells theAgents '
        classInstanceVariableNames: 'timeStep month year '
        imports: ''
        category: 'Cormas-MyModel'

On the top of the protocol list, switch from "Instance" to "Class" to be
able to add one by one the
accessors methods for these 3 class attributes.

Then you have to write a method to update these attributes
MyModel>>updateTime:t
        self class timeStep: t.
        self class month: ((t \\ 12) = 0) ifTrue: [12] ifFalse: [t \\ 12].
        self class year: (t / 12) ceiling

You need to call it at the very beginning of the general
MyModel>>step:t simulation method:
MyModel>>step:t
        self updateTime: t
        self theCells do: [:c | c step].
        self theAgents do: [:a | a step].
        ...

Now you can have a class (PassiveEntity) Climate, where you may have a
single class method
rainfallMonthlyAverages
   ^#(100 200 200 300 300 400 400 400 300 300 250 150)

And from any method of any entity class of your model, to get the
current month average rainfall,
just write this instruction:
    Climate rainfallMonthlyAverages at: (MyModel month)

clp

Erasmus L a écrit:

>Hello Jakin
>
>That's very easy. There are 2 ways of doing this.
>Firstly you need to add an attribute to the environment called rainfall
>or something. Set your time step to one month.
>
>Then you change the monthly values by
>1. Use an equation to simulate rainfall. Since rainfall is usually
>periodic of nature you can use a periodic equation (using sine, cosine
>or pi) that describes the real rainfall pattern to calculate the monthly
>rainfall values. Your equation must have a period of 12 months and your
>x-value will be one month. Y value is of course the rainfall for that
>month. You can also add a random variability to it.
>
>2. You can use real data and read the monthly rainfall from a file.
>
>Let me know if you need help with the equations.
>
>Best wishes,
>
>Louise Erasmus
>
>Residential address:
>Biocomplexity Research Group
>Department of Zoology
>University of Stellenbosch
>Stellenbosch
>7602
>South Africa
>
>Tel. + 27 - 21 - 808 2604
>
>Affiliation address:
>Conservation Planning Unit
>Department of Zoology and Entomology
>University of Pretoria
>Pretoria
>0002
>South Africa
>
>Tel. +27 - 12 - 420 4048
>e-mail: lerasmus@zoology.up.ac.za
>
>Please use the residential address
>
>
>-----Original Message-----
>From: Jakin Ravalico [mailto:jakin.ravalico@adelaide.edu.au]
>Sent: 21 September 2003 11:21 AM
>To: cormas@cirad.fr
>Subject: changing variables over time
>
>I am having trouble changing variables in Cormas over a time period, for
>
>example using different monthly averages to simulate rainfall within the
>model.
>Could anyone help with how to do this?
>
>Jakin Ravalico
>
>

New Message Reply Date view Thread view Subject view Author view
 

Back to home