Messages from list : cormas@cirad.fr

Choose a topic among the following archives :

Re: long simulation times

New Message Reply Date view Thread view Subject view Author view

Subject: Re: long simulation times
From: Christophe Le Page (lepage@cirad.fr)
Date: mer avr 18 2001 - 15:56:37 CEST

> Cormas becomes increasingly slower as more and more timesteps have been
> simulated to the point that nothing seems to work at all. In my model (at
my
> PC) this happens around timestep 8000. I presume this has something to do
> with cormas storing all it's chart data in a dictionary variable/attribute
of
> the model which slowly uses all the internal memory as the number of
timesteps
> increases.
>
> Can this be the reason and if so is there a bypass, e.g writing the data
to
> file each timestep?
>
You're right, this is a possible reason. Cormas charts are extreamly memory-
consumer, so for long runs, it is safe to comment the #initCharts and
#updateCharts:
methods. If you need to export some data, #exportGlobalCharts:inFile: is
then of
no use (it is based on the charts data). Writing the data to the file each
time-step
is then a good bypass ! Below are two new methods that you can copy and
paste
somewhere in your model class. They will be added to the release of Cormas
2001
that will be officially delivered and set online very soon...

updateFile: aString dataCollection: aCollec separator: aChar
 "aCollec is made of numbers"
| stream |
 stream := ((Cormas dataPath: self class name), aString) asFilename
appendStream.
 1 to: aCollec size - 1
  do: [:i | stream nextPutAll: (aCollec at: i) printString , aChar asSymbol
asString].
 stream nextPutAll: aCollec last printString.
 stream nextPutAll: '\' withCRs.
 stream close

initFile: aString dataCollection: aCollec separator: aChar
"aCollec is made of numbers"
| aFilename |
 aFilename := ((Cormas dataPath: self class name), aString) asFilename.
 aFilename exists ifTrue: [aFilename delete].
 self updateFile: aString
  dataCollection: aCollec
  separator: aChar

Then you can modify the #init and #step: methods of your model this way
(example given for the Pursuit model)

init
 | data |
 self initCells.
 self initAgents.
 "self initCharts."
 data := OrderedCollection new.
 data add: 0; add: self thePursuit_Preys size; add: self
thePursuit_Predators size.
 self initFile: 'res.txt'
    dataCollection: data
    separator: Character tab.

 step: t
|data|
...
 "self updateCharts: t."
 data := OrderedCollection new.
 data add: t; add: self thePursuit_Preys size; add: self
thePursuit_Predators size.
 self updateFile: 'res.txt'
    dataCollection: data
    separator: Character tab

New Message Reply Date view Thread view Subject view Author view
 

Back to home