Skip to content

Commit

Permalink
optionally log swarm activity to network
Browse files Browse the repository at this point in the history
  • Loading branch information
howthebodyworks committed Aug 17, 2012
1 parent b1d10f4 commit 65cbf55
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion optimisation/swarm/swarm.sc
Expand Up @@ -42,7 +42,10 @@ PSOptimisingSwarm {

//flag to stop iterator gracefuly.
var playing = false;


var <>swarmName = "swarm";
var netSender = nil;
var <netAddr = nil;
/*
Here are the variables that hold the operator functions.
Paths are coerced to functions at instantiation time to avoid problems with
Expand Down Expand Up @@ -268,6 +271,7 @@ PSOptimisingSwarm {
bestKnownFitnessTable[phenotype] = myBestFitness;
});
this.updateStatistics;
netSender.value;
iterations = iterations + 1;
}
setParam {|statekey, stateval|
Expand Down Expand Up @@ -333,6 +337,22 @@ PSOptimisingSwarm {
super.free;
controller.free;
}
net_ {|addr|
netAddr = addr;
netAddr.isNil.if({
netSender = nil;
}, {
netSender = {
var path = "/swarm/%".format(swarmName);
var i = 0;
cookedFitnessMap.keysValuesDo({|agent,fitness|
netAddr.sendMsg(path, i, fitness, *(agent.chromosome));
i = i+1;
});
};
});

}
}

PSLocalOptimisingSwarm : PSOptimisingSwarm {
Expand Down
2 changes: 2 additions & 0 deletions psosynth.scd
Expand Up @@ -117,6 +117,8 @@ s.waitForBoot({
//~swarm.scoreCooker = #[phenosynth, score_cookers, scale_distance_to_similarity];
~swarm.scoreCooker = #[phenosynth, score_cookers, invert_distance_to_similarity];
//~swarm.scoreCooker = [\phenosynth, \score_cookers, \reverse_ranked];
~net = NetAddr("127.0.0.1", 57130);
~swarm.net_(~net);
~swarm.play(~control);
{
~plotState = SwarmGraph.new(~swarm);
Expand Down

0 comments on commit 65cbf55

Please sign in to comment.