Tips And Tricks
OvSwValue class fields
General rule: do not store internal data as OvSwValue (or derivative) values: use OvSwValue types only for exchanging data from and to ant agents. For example, do not use:
class MyAlgorithm { OvSwString* somestring; OvSwValue::Ptr myfunction (void* owner, OvSwStack* st) { return OvSwValue::Ptr(somestring); // WARNING! This will likely result in "somestring" to be freed early! // Moreover, problems will arise when serializing data. } }
but this instead:
class MyAlgorithm { string somestring; OvSwValue::Ptr myfunction (void* owner, OvSwStack* st) { return wrap(somestring); } }
Genetic programming
Genome can be implemented using lambdas:
protocol "Cip" { ant "Ciop" { behavior { (virtual $geneA) (virtual $geneB) (define value 0) (define phenotypeA { "1" : (lambda (x) (+ x x)), "2" : (lambda (x) (* x x)), "3" : (lambda (x) (+ x 1)), "4" : (lambda (x) (- x 1))}) (define phenotypeB { "1" : (lambda (x) (+ x x)), "2" : (lambda (x) (* x x)), "3" : (lambda (x) (+ x 1)), "4" : (lambda (x) (- x 1))}) (define (expression fA fB) (set! value (+ ((get phenotypeA fA) value) ((get phenotypeB fB) value)))) (while 1 (begin (set! value (readValueFromNode)) (expression $geneA $geneB) (storeValueOnNode value))) } } }
Compile OverSwarm files
for i in `find . -name *.osw`; do java -cp $HOME/sim/ovswcompiler/src/ org.syscall.overswarm.compiler.module.Make $i; done