swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating output files in java


From: Olivier Jauze
Subject: Re: Creating output files in java
Date: Wed, 01 Aug 2001 09:15:11 +0200

At 16:31 31/07/01 +0200, you wrote:
Hi again,
thanks a lot for your answer but I  have a question for you related to
your way of solving this. Where should I create the instance of
FileOutpout class? For each agent I need to save a value and besides I
need to  do it for every simulation step. At the end of the simulations
I should have an enormous file with 3 values for all the agents at every
simulation step. I have tried your solution but don't understand where
to create the new instance, where to write the line (to get what I want)
and where to close the file. This class FileWriter doesn't have the
option of opening an existing file, well at least I haven't dound it.

Many many thanks indeed for your help,
Isis

Hi,
this is what I understand to your problem :
at every time step, you want to save 3 values for every agents.

1 : if you want one file, it would became enormous but is there a problem ?
2 : If you want one file per agent, the size of each fil will be acceptable I think.

If you choose the first solution :
You have to create the file as a static attribute of your agent's class so you will have only one file.
        For instance : protected static FileOutput file;

Then you must have a static method that allow you to instanciate this file.
        For instance :
        protected static void createFile( String nameFile )
        {
                file = new FileOutput( nameFile ) ;
        }

You can use this method at the beginning of the simulation in the buildActions() method of the modelSwarm
        For instance (I name your agent's class : Agent) :
        public void buildActions()
        {
                ...
                Agent.createFile("hello.txt");
        }

        If you choose the first solution :
you don not need a static attribute, so you will have one file per agent.
        I will create th instance in the constructor of the agent's class.

To write the data, I will create a method that at every time step :
        - write the data in the file(s).
        - or save data in a table.

You can compare this method with an event, so you will have to insert this event in the schedule of your Observer or your ModelSwarm at every time step.

To close the file(s), I will create a method that be exexuted at the end of the simulation. If you write at every time you just have to close the file, if you don't you will have to write the table.
This way is better than the first because you just have one series of output.

I hope this email will answer to your question.
Have a good day
Olivier JAUZE
INRA unité URH équipe SP
Centre de Theix

                 ==================================
  Swarm-Support is for discussion of the technical details of the day
  to day usage of Swarm.  For list administration needs (esp.
  [un]subscribing), please send a message to <address@hidden>
  with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]