Uploading progress statistics to a website automatically
I've seen a few questions related to storing & accessing simulation results on the mailing list, so I thought I would share how I implemented this on my own simulations.
This may be useful for anyone who wants to run simulations for long periods (days) on remote computers, and have statistics reported and stored in an online database for easy access. This method can also work behind most firewalls.
I've successfully used curl to have my (heavily) modified version of the breve Walker demo send average fitness, max fitness & variance results per generation to a website, where it is stored in a database using a few PHP lines. I can then check the progress at any time just by visiting another PHP page that lists all the results stored so far.
Here is what I use in breve to send the data to my website (this is just one line of code):
(self execute command "curl -F \"currentGenerationIndex=$currentGenerationIndex\" -F \"bestFitness=$bestFitness\" -F \"avgFitness=$avgFitness\" -F \"varFitness=$varFitness\" http://www.somewebsite.com.ar/simbug.php").
simbug.php is the webpage that receives the data (it can be named anything you want, I named it to match my simulation's name). It looks like this:
<?php
function connectDB() {
$con = pg_connect("dbname=yourdatabasename user=yourusername password=yourpassword host=yourhost");
if (!$con) {
print "this isn't working :(";
exit;
}
return $con;
}
$connection = connectDB();
$currentGenerationIndex = $_POST['currentGenerationIndex'];
$bestFitness = $_POST['bestFitness'];
$avgFitness = $_POST['avgFitness'];
$varFitness = $_POST['varFitness'];
if ($myresult = pg_exec($connection, "insert into bugsim (currentGenerationIndex, bestFitness, avgFitness, varFitness) values ('$currentGenerationIndex', '$bestFitness', '$avgFitness', '$varFitness')"))
print "OK";
else
print "ERROR";
?>Then, I have another php page that just lists the contents of the table using a select * and a for loop (very similar to the code above)
Note: this code assumes you are using PostgreSQL and that you have a table called bugsim with four columns:
- currentGenerationIndex
- bestFitness
- avgFitness
- varFitness
Ignacio -

Uploading progress statistics to a website automatically
Could this be used to write a 'distributed' breveCreatures secreensaver?
In which you run, say 10 generations and upload the best results/genomes to a central server, which then sorts the results/genomes it gets from you with the stored results/genomes from x other people, and uploads another set to you?
this would open the scope to a lot of variety... Bigger pools, for starters... Let the server send out alternate 'beginners' genomes sets, 'advanced' genomes sets, 'very highly evolved' genome sets etc...
Uploading progress statistics to a website automatically
Sure, you can archive and de-archive genome classes and use curl to upload & download files (look at the docs for the -F option to upload files, the link is on my first post).
Another way is using breve's own methods, but those run on special port ranges so it would most likely be useful for LANs. There were a few bugs the first time I tried it a while ago, so you should double check that everything is getting transfered correctly with breve's standard methods.
I haven't tested this recently, but there may still be some troubles on some platforms, check this thread: http://www.spiderland.org/forums/viewtopic.php?t=13
Uploading progress statistics to a website automatically
Yes, I had a look at the breve classes in the screensaver, and they pointed to that possibility... Internal networking.
I had a look at the documentation quite a while ago, maybe I forgot about it being there or it is a new feature?
Will look again, thank you