Messages from list : cormas@cirad.fr

Choose a topic among the following archives :

Re: Use of .txt files as init file ?

New Message Reply Date view Thread view Subject view Author view

Subject: Re: Use of .txt files as init file ?
From: Bruno Locatelli (blocatel@catie.ac.cr)
Date: Wed Jul 21 2004 - 16:47:52 CEST

Dear Pierre Marcel,
Following Nicolas' advice, I recommend you to store all your initialisation parameters in a dictionnary (e.g. called "parameters"), which shall be a variable of your model. All your agents' characteristics should be initialized using data from this dictionary.
Then you can save this object using a non-binary storage with "StoreOn:". Non-binary is useful for what you look for: it stores simple information (it is not adequate for storing objects containing objects...) and stored files may be opened and modified with an Ascii text editor.

Example to be tested in a workspace:

| parameters outputFile |
" DEFINING YOUR PARAMETERS "
parameters := Dictionary new.
parameters at: #numberOfConsumers put: 100.
parameters at: #maxCapitalForConsumer put: 2000.
parameters at: #minCapitalForConsumer put: 1500.

" STORING FILE
outputFile := 'C:\Documents and Settings\Bruno\Mis documentos\temp\parameterfile.txt' asFilename writeStream.
parameters storeOn: outputFile.
outputFile close.

If you open the "parameterfile.txt" in any text editor, you will find this:

((Core.Dictionary new) add: (#minCapitalForConsumer -> 1500); add: (#numberOfConsumers -> 100); add: (#maxCapitalForConsumer -> 2000); yourself)

You can change the parameters in the text editor and save them. For instance, you can change the number of consumers.

((Core.Dictionary new) add: (#minCapitalForConsumer -> 1500); add: (#numberOfConsumers -> 999); add: (#maxCapitalForConsumer -> 2000); yourself)

Then, in the initialization procedure of your model, your should write the following lines in order to retrieve your dictionary of parameters:

inputFile := 'C:\Documents and Settings\Bruno\Mis documentos\temp\parameterfile.txt' asFilename readStream contents asString.
parameters := Object readFromString: inputFile.

You can test it in a Workspace:

| parameters inputFile |
inputFile := 'C:\Documents and Settings\Bruno\Mis documentos\temp\parameterfile.txt' asFilename readStream contents asString.
parameters := Object readFromString: inputFile.
parameters inspect

An inspector window will show :
Dictionary (#minCapitalForConsumer->1500 #numberOfConsumers->999 #maxCapitalForConsumer->2000 )

So the new information (numberOfConsumers=999) was retrieved from the file and imported as an object.

Regards
_____________________________
 
Bruno Locatelli
Global Change Group / Grupo Cambio Global
CIRAD Forêt (www.cirad.fr) - CATIE (www.catie.ac.cr/cambioglobal)
Apdo 2, Turrialba 7170
Costa Rica
 
Tel: 506.558.22.16
Fax: 506.556.62.55
Web perso: http://www.locatelli1.net
________________________________

  ----- Original Message -----
  From: Nicolas Becu
  To: cormas@cirad.fr
  Sent: Wednesday, July 21, 2004 4:46 AM
  Subject: RE: Use of .txt files as init file ?

  Dear Pierre-Marcel

  What I usually do in my models is that I import the initialisation parameters of the model from a csv file during init (you should find csv file import method in the Cormas utils).
  Then I create one csv file for each scenario that I run (each one having different values of initialisation parameters) and I import the csv file that I need for each scenario.

  To structure a bit the model I created a Parameter class in my model which stores all those parameters (I store them in dictionaries at the class level). Then I call the parameter requiered by using a method like : Parameter readValueOf: aParameterName.

  Hope this helps

  Cheers

  Nicolas

    -----Original Message-----
    From: owner-cormas@cirad.cirad.fr [mailto:owner-cormas@cirad.cirad.fr]On Behalf Of Pierre-Marcel GORAL
    Sent: mercredi 21 juillet 2004 09:59
    To: cormas@cirad.fr
    Subject: Use of .txt files as init file ?

        Hello everybody,

    I've got a problem initialising a model. This model has numerous things to settle before launch, and all these variables can take many values in order to make many differrent simulations. So I have to settle each variable one at a time, and it's ... well, boring, at least.
    So I've got one question: is it possible to use a ".txt" like file in order to prepare the inits of all these, and if that's the case, how to call it from the Cormas model, and how to read it?
    (I don't have any knowledge on the Input routines of Cormas).

    I am waitinig your advice.

    Best regards, Pierre-Marcel.

    Pierre-Marcel GORAL

----------------------------------------------------------------------------
    Trouvez l'âme soeur sur MSN Rencontres. Cliquez-ici

New Message Reply Date view Thread view Subject view Author view
 

Back to home