We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › saving the position of thouthands of agents
Page Index Toggle Pages: 1
saving the position of thouthands of agents (Read 1556 times)
saving the position of thouthands of agents
Apr 30th, 2010, 9:11pm
 
hello, which do you think is the better way of saving the position of thouthands of agents or points in 2d ?
Ive made a program based in thouthands of agents that generate different kind of spatial distribution patterns, which do you think would be the best way of saving the position of those agents?

thanks

Seb

Re: saving the position of thouthands of agents
Reply #1 - May 1st, 2010, 1:32am
 
That depends on what operations that you're trying to do with them. Try reading about basic data structure (LinkedList, Trees/Heaps, HashMap, Set) to get some idea what data structure are best in what situations.
Re: saving the position of thouthands of agents
Reply #2 - May 1st, 2010, 1:42am
 
As said above for the container/collection.

To store the coordinates themselves, if only the coordinates interest you, just use a PVector. If you need to store more information (life length, speed, whatever), you must do your own class.
Re: saving the position of thouthands of agents
Reply #3 - May 1st, 2010, 5:20am
 
You can always store their x,y,z to a reference file and then refer to it on the fly.

It has so many applications.

The possibilities are endless with Processing!

So much things to do so little time!
Re: saving the position of thouthands of agents
Reply #4 - May 1st, 2010, 10:40am
 
hello, what i need to do is to make something like a preset or save/load mechanism ,
each agent has 4 values,  the x, y and  2 more values.
for example :
agent 1 : 244, 223 , 44, 44
agent 2 :133, 44 , 35, 14 and so on...

the first 2 values are the x and y , and the 2 last are the state of the agents.

The program i made create spatial distribution patterns based on some selforganizing behaivors,  and i need to wait to much time until those patterns emerge, what i need is to save the possitions of all the agents with their values in a external file, maybe txt file, and then load them  on the fly , when the program is running,  would do you recommend me would be the best way of achieving such a task?

thanks in advance

Seb.
Re: saving the position of thouthands of agents
Reply #5 - May 1st, 2010, 1:31pm
 
Ahh.. I see, you're trying to save your program's state to a file. Processing comes with a builtin XML parser (XMLElement), you might want to take a loot at that.

Before jumping on file formats though, you need to decide what data you need to store to be able to recreate the program's state. From there, it's just merely figuring out a way to dump the info to a (XML or otherwise) file and parse them back.
Re: saving the position of thouthands of agents
Reply #6 - May 1st, 2010, 4:42pm
 
is there any benefit in using xml instead a simple .txt file?
what about if i just use saveString to save to a .txt file and loadStrings to load? which are the advantages of using xmlElement?

thanks
Re: saving the position of thouthands of agents
Reply #7 - May 2nd, 2010, 12:54am
 
Personally, I avoid to use XML unless I really need to... Smiley
For data as simple as the one you show, not hierarchic nor with optional elements, etc., a simple CSV format is more than enough.

As you guessed, make an array of strings holding the textual data to save, separated by semi-colon or tabs, using toString() if you have a class, or "manually" if you use separate arrays, then use saveStrings() (plural, here...).

Note that if you have really lot of data, this isn't very efficient (convert data to a big array of strings) so if you are concerned by that (memory limitation), you can use the method used by saveStrings(), generating the lines on the fly:
Code:
    File file = saveFile("dataToSave.csv");
   OutputStream output = createOutput(file)
   PrintWriter writer = createWriter(output);
   for (int i = 0; i < dataLlength; i++) {
String line = x[i] + ";" + y[i] + ";" + stat1[i] + ";" + stat2[i];
// or String line = agent[i].toString();
writer.println(line);
   }
   writer.flush();
   writer.close();

Likewise, you might want to split the reading of data to generate it line per line.
Processing just hides this complexity because most data is small enough to fit in memory anyway.
Page Index Toggle Pages: 1