diff --git a/UML_structure.dia b/UML_structure.dia
new file mode 100644
index 0000000..6b3925b
Binary files /dev/null and b/UML_structure.dia differ
diff --git a/runSim.sh b/runSim.sh
old mode 100644
new mode 100755
diff --git a/scenarios/scenario1_active.xml b/scenarios/scenario1_active.xml
index 77c4530..c921f7f 100644
--- a/scenarios/scenario1_active.xml
+++ b/scenarios/scenario1_active.xml
@@ -1,16 +1,16 @@
-
+
-
-
-
-
-
-
+
+
+
-
+
diff --git a/src/epics/ai/AWASSLookAheadNode.java b/src/epics/ai/AWASSLookAheadNode.java
new file mode 100644
index 0000000..2384f92
--- /dev/null
+++ b/src/epics/ai/AWASSLookAheadNode.java
@@ -0,0 +1,122 @@
+package epics.ai;
+
+import static java.lang.Math.cos;
+import static java.lang.Math.sin;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import epics.camsim.core.TraceableObject;
+import epics.common.AbstractAINode;
+import epics.common.Coordinate2D;
+import epics.common.IBanditSolver;
+import epics.common.IRegistration;
+import epics.common.ITrObjectRepresentation;
+import epics.common.RandomNumberGenerator;
+import epics.common.RandomUse.USE;
+
+public class AWASSLookAheadNode extends AbstractAINode { //ActiveAINodeMulti {
+
+ /** The confidence for an object below which we advertise */
+ public static final double CONF_THRESHOLD = 0.1;
+ private static final int LOOK_AHEAD = 2;
+ private static final double AUCT_PROB = 0.2;
+
+ /** Keep track of confidence from last time step to find whether
+ * it has increased or decreased */
+ private Map lastConfidence = new HashMap();
+
+ /**
+ * constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
+ * @param comm the communication policy
+ * @param staticVG if static or dynamic vision graph
+ * @param vg the initial vision graph
+ * @param r the global registration component - can be null
+ * @param rg the random number generator for this instance
+ */
+ public AWASSLookAheadNode(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg){
+ super(staticVG, vg, r, rg);
+ }
+
+ /**
+ * constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
+ * @param comm the communication policy
+ * @param staticVG if static or dynamic vision graph
+ * @param vg the initial vision graph
+ * @param r the global registration component - can be null
+ * @param rg the random number generator for this instance
+ * @param bs the bandit solver to decide the best communication policy and auctioning schedule
+ */
+ public AWASSLookAheadNode(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg, IBanditSolver bs){
+ super(staticVG, vg, r, rg, bs);
+ }
+
+ public AWASSLookAheadNode(boolean staticVG,
+ Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg) {
+ super(staticVG, vg, r, auctionDuration, rg);
+ }
+
+ public AWASSLookAheadNode(boolean staticVG,
+ Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg, IBanditSolver bs) {
+ super(staticVG, vg, r, auctionDuration, rg, bs);
+ }
+
+ /**
+ * creates a passive ai instance from another existing instance
+ * @param ai the given existing AI instance
+ */
+ public AWASSLookAheadNode(AbstractAINode ai){
+ super(ai);
+ if (ai instanceof AWASSLookAheadNode) {
+ AWASSLookAheadNode pass = (AWASSLookAheadNode) ai;
+ lastConfidence = pass.lastConfidence;
+ }
+ }
+
+ private Coordinate2D toCameraSpace(final Coordinate2D pointPos){
+ final Coordinate2D camPos = camController.getPostion();
+ final double camAngle = -camController.getHeading();
+ final double dx = pointPos.getX()-camPos.getX();
+ final double dy = pointPos.getY()-camPos.getY();
+ final double x = dx * cos(camAngle) + dy * sin(camAngle);
+ final double y = -dx * sin(camAngle) + dy * cos(camAngle);
+ return new Coordinate2D(x, y);
+ }
+
+
+ @Override
+ public void advertiseTrackedObjects() {
+ for (ITrObjectRepresentation io : this.getAllTrackedObjects_bb().values()) {
+ double conf = this.getConfidence(io);
+ double lastConf = this.getLastConfidenceFor(io);
+ if (this.camController.objectIsVisible(io) == -1){
+ if (conf < CONF_THRESHOLD && (conf == 0 || conf < lastConf)) {
+ final TraceableObject obj = io.getTraceableObject();
+ //if(camController.isObjectInFOV(obj)){
+ final Coordinate2D expectedNext = toCameraSpace(obj.esteemNext(LOOK_AHEAD));
+ if((conf != 0 && !camController.isCoordinateInFOV(expectedNext)) || randomGen.nextDouble(USE.UNIV) < AUCT_PROB){
+ /*
+ * Start an auction if:
+ * - the object is in FOV and it's expected to exit the FOV in near future
+ * - the object is not in FOV with probability AUCT_PROB
+ */
+ callForHelp(io);
+ }
+ }
+ }
+ this.addLastConfidence(io, conf);
+ }
+ }
+
+ protected void addLastConfidence(ITrObjectRepresentation io, double conf) {
+ this.lastConfidence.put(io, conf);
+ }
+
+ protected double getLastConfidenceFor(ITrObjectRepresentation io) {
+ if (lastConfidence.containsKey(io)) {
+ return lastConfidence.get(io);
+ } else {
+ return 0.0;
+ }
+ }
+}
diff --git a/src/epics/ai/AWASSLookAheadNodeClustering.java b/src/epics/ai/AWASSLookAheadNodeClustering.java
new file mode 100644
index 0000000..4af7e8e
--- /dev/null
+++ b/src/epics/ai/AWASSLookAheadNodeClustering.java
@@ -0,0 +1,111 @@
+package epics.ai;
+
+import static java.lang.Math.cos;
+import static java.lang.Math.sin;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import epics.camsim.core.TraceableObject;
+import epics.common.AbstractAINode;
+import epics.common.Coordinate2D;
+import epics.common.IBanditSolver;
+import epics.common.IRegistration;
+import epics.common.ITrObjectRepresentation;
+import epics.common.RandomNumberGenerator;
+import epics.common.RandomUse.USE;
+
+public class AWASSLookAheadNodeClustering extends AbstractClusterFoVAINode { //ActiveAINodeMulti {
+
+ /** The confidence for an object below which we advertise */
+ public static final double CONF_THRESHOLD = 0.1;
+ private static final int LOOK_AHEAD = 2;
+ private static final double AUCT_PROB = 0.2;
+
+ /** Keep track of confidence from last time step to find whether
+ * it has increased or decreased */
+ private Map lastConfidence = new HashMap();
+
+ /**
+ * constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
+ * @param comm the communication policy
+ * @param staticVG if static or dynamic vision graph
+ * @param vg the initial vision graph
+ * @param r the global registration component - can be null
+ * @param rg the random number generator for this instance
+ */
+ public AWASSLookAheadNodeClustering(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg){
+ super(staticVG, vg, r, rg);
+ }
+
+ /**
+ * constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
+ * @param comm the communication policy
+ * @param staticVG if static or dynamic vision graph
+ * @param vg the initial vision graph
+ * @param r the global registration component - can be null
+ * @param rg the random number generator for this instance
+ * @param bs the bandit solver to decide the best communication policy and auctioning schedule
+ */
+ public AWASSLookAheadNodeClustering(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg, IBanditSolver bs){
+ super(staticVG, vg, r, rg, bs);
+ }
+
+ public AWASSLookAheadNodeClustering(boolean staticVG,
+ Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg) {
+ super(staticVG, vg, r, auctionDuration, rg);
+ }
+
+ public AWASSLookAheadNodeClustering(boolean staticVG,
+ Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg, IBanditSolver bs) {
+ super(staticVG, vg, r, auctionDuration, rg, bs);
+ }
+
+ /**
+ * creates a passive ai instance from another existing instance
+ * @param ai the given existing AI instance
+ */
+ public AWASSLookAheadNodeClustering(AbstractAINode ai){
+ super(ai);
+ if (ai instanceof AWASSLookAheadNodeClustering) {
+ AWASSLookAheadNodeClustering pass = (AWASSLookAheadNodeClustering) ai;
+ lastConfidence = pass.lastConfidence;
+ }
+ }
+
+ @Override
+ public void advertiseTrackedObjects() {
+ for (ITrObjectRepresentation io : this.getAllTrackedObjects_bb().values()) {
+ double conf = this.getConfidence(io);
+ double lastConf = this.getLastConfidenceFor(io);
+ if (this.camController.objectIsVisible(io) == -1){
+ if (conf < CONF_THRESHOLD && (conf == 0 || conf < lastConf)) {
+ final TraceableObject obj = io.getTraceableObject();
+ //if(camController.isObjectInFOV(obj)){
+ final Coordinate2D expectedNext = toCameraSpace(obj.esteemNext(LOOK_AHEAD));
+ if((conf != 0 && !camController.isCoordinateInFOV(expectedNext)) || randomGen.nextDouble(USE.UNIV) < AUCT_PROB){
+ /*
+ * Start an auction if:
+ * - the object is in FOV and it's expected to exit the FOV in near future
+ * - the object is not in FOV with probability AUCT_PROB
+ */
+ callForHelp(io);
+ }
+ }
+ }
+ this.addLastConfidence(io, conf);
+ }
+ }
+
+ protected void addLastConfidence(ITrObjectRepresentation io, double conf) {
+ this.lastConfidence.put(io, conf);
+ }
+
+ protected double getLastConfidenceFor(ITrObjectRepresentation io) {
+ if (lastConfidence.containsKey(io)) {
+ return lastConfidence.get(io);
+ } else {
+ return 0.0;
+ }
+ }
+}
diff --git a/src/epics/ai/AbstractClusterFoVAINode.java b/src/epics/ai/AbstractClusterFoVAINode.java
new file mode 100644
index 0000000..44db192
--- /dev/null
+++ b/src/epics/ai/AbstractClusterFoVAINode.java
@@ -0,0 +1,261 @@
+package epics.ai;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import static java.lang.Math.PI;
+import static java.lang.Math.cos;
+import static java.lang.Math.sin;
+
+import epics.common.Coordinate2D;
+import epics.common.RandomNumberGenerator;
+import epics.common.AbstractAINode;
+import epics.common.IRegistration;
+import epics.common.IBanditSolver;
+import epics.common.ITrObjectRepresentation;
+
+import epics.ai.kmeans.*;
+
+public abstract class AbstractClusterFoVAINode extends AbstractAINode {
+ SequentialKMeans kmeans;
+
+// protected Map visionGraph = new HashMap();
+
+ // the idea: we cluster the FoV based on the hand-over positions.
+ // therefor,
+ // we should get the visionGraph based on the current position of the object
+ // we should update the K-Means when a handover takes place
+
+ // connnnstructor
+ public AbstractClusterFoVAINode(AbstractAINode old){
+ super(old);
+ initKMeans();
+ }
+
+ /**
+ * Creates an AI Node WITHOUT bandit solver
+ * for switching to another node automatically.
+ * This constructor simply calls instantiateAINode(). Overriding classes
+ * should only call super and do real handling in instantiateAINode().
+ * This is painful but is to enforce these arguments in the constructor.
+ *
+ * @param comm communication used
+ * @param staticVG if true, only static vision graph is used
+ * @param vg initial vision graph
+ * @param r global registration component
+ * @param rg random number generator for this node
+ */
+ public AbstractClusterFoVAINode(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg){
+ super(staticVG, vg, r, rg);
+ initKMeans();
+ }
+
+ /**
+ * Creates an AI Node WITHOUT bandit solver for switching to another node automatically
+ * @param comm the used communication policy
+ * @param staticVG if static vision graph or not
+ * @param vg the initial vision graph
+ * @param r the global registration component - can be null
+ * @param auctionDuration the duration of auctions
+ * @param rg the random number generator for this instance
+ */
+ public AbstractClusterFoVAINode(
+ boolean staticVG,
+ Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg) {
+ super(staticVG, vg, r, auctionDuration, rg);
+ initKMeans();
+ }
+
+ /**
+ * Standard constructor including bandit solver
+ * @param comm communication used
+ * @param staticVG if true, only static vision graph is used
+ * @param vg initial vision graph
+ * @param r global registration component
+ * @param rg random number generator for this node
+ * @param bs the bandit solver to find the best strategy
+ */
+ public AbstractClusterFoVAINode(
+ boolean staticVG, Map vg,
+ IRegistration r, RandomNumberGenerator rg, IBanditSolver bs){
+ super(staticVG, vg, r, rg, bs);
+ initKMeans();
+ }
+
+
+ public AbstractClusterFoVAINode(
+ boolean staticVG,
+ Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg, IBanditSolver bs) {
+ super(staticVG, vg, r, auctionDuration, rg, bs);
+ initKMeans();
+ }
+
+ private void initKMeans() {
+ this.kmeans = new SequentialKMeans(2); // 2 features/dimension, -> the position of the object at handover
+ }
+
+ /**
+ * copies the given AbstractClusterFoVAINode
+ * @param ai the given AiNode
+ */
+ public void instantiateAINode(AbstractClusterFoVAINode ai){
+ super.instantiateAINode(ai);
+ this.kmeans = ai.kmeans;
+ }
+
+
+ protected Coordinate2D toCameraSpace(final Coordinate2D pointPos){
+ final Coordinate2D camPos = camController.getPostion();
+ final double camAngle = -camController.getHeading();
+ final double dx = pointPos.getX()-camPos.getX();
+ final double dy = pointPos.getY()-camPos.getY();
+ final double x = dx * cos(camAngle) + dy * sin(camAngle);
+ final double y = -dx * sin(camAngle) + dy * cos(camAngle);
+ return new Coordinate2D(x, y);
+ }
+
+
+ protected Map getVisionGraphForObject(ITrObjectRepresentation rto) {
+ Coordinate2D coords = toCameraSpace(rto.getTraceableObject().getCurrentPosition());
+ double[] co = new double[2];
+ co[0] = coords.getX();
+ co[1] = coords.getY();
+
+ Cluster c = this.kmeans.getClosestCluster( new ClusterPoint(co) );
+ //System.out.println("For obj at "+coords+", got "+c);
+ return c.visionGraph;
+ }
+
+
+ // this should be the moment of handover...
+ @Override
+ protected void removeTrackedObject(ITrObjectRepresentation rto) {
+ super.removeTrackedObject(rto);
+ //System.out.println("THIS IS Hand-overrrrrr");
+
+ Coordinate2D coords = toCameraSpace(rto.getTraceableObject().getCurrentPosition());
+ double[] co = new double[2];
+ co[0] = coords.getX();
+ co[1] = coords.getY();
+
+ this.kmeans.add(new ClusterPoint(co));
+ }
+
+
+
+ /**
+ * updates the vision graph. reduces every link by the evaporationrate
+ */
+ @Override
+ protected void updateVisionGraph() {
+ if(!staticVG){
+ Iterator clusters = this.kmeans.getClusterIterator();
+ while (clusters.hasNext()) {
+ Cluster cluster = clusters.next();
+
+ ArrayList toRemove = new ArrayList();
+ for (Map.Entry e : vgEntrySet(cluster)) {
+ double val = e.getValue();
+ e.setValue( e.getValue() * EVAPORATIONRATE); //0.995);
+ if (val < 0) {
+ toRemove.add(e.getKey());
+ }
+ }
+ for (int i = 0; i < toRemove.size(); i++) {
+ vgRemove(toRemove.get(i), cluster);
+ }
+ } // for each cluster
+ }
+ }
+
+
+
+ /**
+ * returns the vision graph
+ * the graph consists of cameras (key) and the corresponding strength (value) in a map
+ * @return the vision graph
+ */
+ @Override
+ public Map getVisionGraph() {
+ return null;
+ }
+ public Map getVisionGraph(ITrObjectRepresentation itro) {
+ return this.getVisionGraphForObject(itro);
+ }
+
+ /** Whether the key exists for this cam name (ignoring object here) */
+ @Override
+ public boolean vgContainsKey(String camName, ITrObjectRepresentation itro) {
+ return getVisionGraph(itro).containsKey(camName);
+ }
+
+ /** Get all values in the vision graph (ignoring object here) */
+ @Override
+ public Collection vgGetValues(ITrObjectRepresentation itro) {
+ return getVisionGraph(itro).values();
+ }
+
+ /** Get all cameras with values in the vision graph */
+ @Override
+ public Set vgGetCamSet() {
+ return null;
+ }
+
+ public Set vgGetCamSet(ITrObjectRepresentation itro) {
+ return getVisionGraph(itro).keySet();
+ }
+
+
+ /** Get the pheromone value for this camera name (ignoring object here) */
+ @Override
+ public Double vgGet(String camName, ITrObjectRepresentation itro) {
+ return getVisionGraph(itro).get(camName);
+ }
+
+ // TODO
+
+ /** Put a value in the vision graph under this camera name (ignoring
+ * object here) */
+ public Double vgPut(String camName, ITrObjectRepresentation itro, Double value) {
+ return getVisionGraph(itro).put(camName, value);
+ }
+
+ /** Get all entries (key-value pairs) in the vision graph */
+ public Set> vgEntrySet() {
+ return null;
+ }
+ public Set> vgEntrySet(ITrObjectRepresentation itro) {
+ return getVisionGraph(itro).entrySet();
+ }
+
+ public Set> vgEntrySet(Cluster cluster) {
+ return cluster.visionGraph.entrySet();
+ }
+
+ /** Remove from the vision graph the key-value pair for the given key */
+ public Double vgRemove(String name) {
+ return null;
+ }
+ public Double vgRemove(String name, ITrObjectRepresentation itro) {
+ return getVisionGraph(itro).remove(name);
+ }
+ public Double vgRemove(String name, Cluster cluster) {
+ return cluster.visionGraph.remove(name);
+ }
+
+ private void printVisionGraph() {
+ // for all vision graphs print
+// String neighbours = "";
+// for (String neighbour : visionGraph.keySet()) {
+// neighbours += "; " + neighbour;
+// }
+// System.out.println(this.camController.getName() +
+// " has the following neighbours:" + neighbours);
+ }
+
+
+}
+
diff --git a/src/epics/ai/ActiveAINodeMulti.java b/src/epics/ai/ActiveAINodeMulti.java
index b6306f6..7f297d4 100644
--- a/src/epics/ai/ActiveAINodeMulti.java
+++ b/src/epics/ai/ActiveAINodeMulti.java
@@ -9,81 +9,114 @@
import epics.common.RandomNumberGenerator;
/**
- * Implementation of AbstractAINode.
- * defines the behaviour of the camera node regarding communication policies and the auction invitation schedules.
- * this class uses the active auction invitation schedule to send invitations to other cameras in every timestep.
- * @author Marcin Bogdanski & Lukas Esterle, refactored by Horatio Cane
+ * Implementation of AbstractAINode. defines the behaviour of the camera node
+ * regarding communication policies and the auction invitation schedules. this
+ * class uses the active auction invitation schedule to send invitations to
+ * other cameras in every timestep.
+ *
+ * @author Marcin Bogdanski & Lukas Esterle, refactored by Horatio Cane
*/
public class ActiveAINodeMulti extends AbstractAINode {
-
- /**
- * Creates an AI Node with active auction schedule from another, existing ai node
- * @param ai the existing ai node
- */
- public ActiveAINodeMulti(AbstractAINode ai){
- super(ai);
- }
-
- /**
- * Creates an AI Node with active auction schedule WITHOUT bandit solver for switching to another node automatically
- * @param comm the used communication policy
- * @param staticVG if static vision graph or not
- * @param vg the initial vision graph
- * @param r the global registration component - can be null
- * @param auctionDuration the duration of auctions
- * @param rg the random number generator for this instance
- */
- public ActiveAINodeMulti(boolean staticVG,
- Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg) {
- super(staticVG, vg, r, auctionDuration, rg);
- }
-
- /**
- * Creates an AI Node with active auction schedule WITH a bandit solver for switching to another node automatically
- * @param comm the used communication policy
- * @param staticVG if static vision graph or not
- * @param vg the initial vision graph
- * @param r the global registration component - can be null
- * @param auctionDuration the duration of auctions
- * @param rg the random number generator for this instance
- * @param bs the bandit solver
- */
- public ActiveAINodeMulti(boolean staticVG,
- Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg, IBanditSolver bs) {
- super(staticVG, vg, r, auctionDuration, rg, bs);
- }
-
- /**
- * Creates an AI Node with active auction schedule WITHOUT bandit solver for switching to another node automatically
- * @param comm the used communication policy
- * @param staticVG if static vision graph or not
- * @param vg the initial vision graph
- * @param r the global registration component - can be null
- * @param rg the random number generator for this instance
- */
- public ActiveAINodeMulti(boolean staticVG,
- Map vg, IRegistration r, RandomNumberGenerator rg) {
- super(staticVG, vg, r, rg);
- }
-
- /**
- * Creates an AI Node with active auction schedule WITH a bandit solver for switching to another node automatically
- * @param comm the used communication policy
- * @param staticVG if static vision graph or not
- * @param vg the initial vision graph
- * @param r the global registration component - can be null
- * @param rg the random number generator for this instance
- * @param bs the bandit solver
- */
- public ActiveAINodeMulti(boolean staticVG,
- Map vg, IRegistration r, RandomNumberGenerator rg, IBanditSolver bs) {
- super(staticVG, vg, r, rg, bs);
- }
-
- public void advertiseTrackedObjects() {
- // Active strategy means all objects are advertised every time
+
+ /**
+ * Creates an AI Node with active auction schedule from another, existing ai
+ * node
+ *
+ * @param ai
+ * the existing ai node
+ */
+ public ActiveAINodeMulti(AbstractAINode ai) {
+ super(ai);
+ }
+
+ /**
+ * Creates an AI Node with active auction schedule WITHOUT bandit solver for
+ * switching to another node automatically
+ *
+ * @param comm
+ * the used communication policy
+ * @param staticVG
+ * if static vision graph or not
+ * @param vg
+ * the initial vision graph
+ * @param r
+ * the global registration component - can be null
+ * @param auctionDuration
+ * the duration of auctions
+ * @param rg
+ * the random number generator for this instance
+ */
+ public ActiveAINodeMulti(boolean staticVG, Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg) {
+ super(staticVG, vg, r, auctionDuration, rg);
+ }
+
+ /**
+ * Creates an AI Node with active auction schedule WITH a bandit solver for
+ * switching to another node automatically
+ *
+ * @param comm
+ * the used communication policy
+ * @param staticVG
+ * if static vision graph or not
+ * @param vg
+ * the initial vision graph
+ * @param r
+ * the global registration component - can be null
+ * @param auctionDuration
+ * the duration of auctions
+ * @param rg
+ * the random number generator for this instance
+ * @param bs
+ * the bandit solver
+ */
+ public ActiveAINodeMulti(boolean staticVG, Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg, IBanditSolver bs) {
+ super(staticVG, vg, r, auctionDuration, rg, bs);
+ }
+
+ /**
+ * Creates an AI Node with active auction schedule WITHOUT bandit solver for
+ * switching to another node automatically
+ *
+ * @param comm
+ * the used communication policy
+ * @param staticVG
+ * if static vision graph or not
+ * @param vg
+ * the initial vision graph
+ * @param r
+ * the global registration component - can be null
+ * @param rg
+ * the random number generator for this instance
+ */
+ public ActiveAINodeMulti(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg) {
+ super(staticVG, vg, r, rg);
+ }
+
+ /**
+ * Creates an AI Node with active auction schedule WITH a bandit solver for
+ * switching to another node automatically
+ *
+ * @param comm
+ * the used communication policy
+ * @param staticVG
+ * if static vision graph or not
+ * @param vg
+ * the initial vision graph
+ * @param r
+ * the global registration component - can be null
+ * @param rg
+ * the random number generator for this instance
+ * @param bs
+ * the bandit solver
+ */
+ public ActiveAINodeMulti(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg, IBanditSolver bs) {
+ super(staticVG, vg, r, rg, bs);
+ }
+
+ public void advertiseTrackedObjects() {
+ // Active strategy means all objects are advertised every time
for (ITrObjectRepresentation io : this.getAllTrackedObjects_bb().values()) {
- callForHelp(io);
+ callForHelp(io);
}
}
}
diff --git a/src/epics/ai/ActiveAINodeMultiClustering.java b/src/epics/ai/ActiveAINodeMultiClustering.java
new file mode 100644
index 0000000..e10bd40
--- /dev/null
+++ b/src/epics/ai/ActiveAINodeMultiClustering.java
@@ -0,0 +1,122 @@
+package epics.ai;
+
+import java.util.Map;
+
+import epics.common.AbstractAINode;
+import epics.common.IBanditSolver;
+import epics.common.IRegistration;
+import epics.common.ITrObjectRepresentation;
+import epics.common.RandomNumberGenerator;
+
+/**
+ * Implementation of AbstractAINode. defines the behaviour of the camera node
+ * regarding communication policies and the auction invitation schedules. this
+ * class uses the active auction invitation schedule to send invitations to
+ * other cameras in every timestep.
+ *
+ * @author Marcin Bogdanski & Lukas Esterle, refactored by Horatio Cane
+ */
+public class ActiveAINodeMultiClustering extends AbstractClusterFoVAINode {
+
+ /**
+ * Creates an AI Node with active auction schedule from another, existing ai
+ * node
+ *
+ * @param ai
+ * the existing ai node
+ */
+ public ActiveAINodeMultiClustering(AbstractAINode ai) {
+ super(ai);
+ }
+
+ /**
+ * Creates an AI Node with active auction schedule WITHOUT bandit solver for
+ * switching to another node automatically
+ *
+ * @param comm
+ * the used communication policy
+ * @param staticVG
+ * if static vision graph or not
+ * @param vg
+ * the initial vision graph
+ * @param r
+ * the global registration component - can be null
+ * @param auctionDuration
+ * the duration of auctions
+ * @param rg
+ * the random number generator for this instance
+ */
+ public ActiveAINodeMultiClustering(boolean staticVG, Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg) {
+ super(staticVG, vg, r, auctionDuration, rg);
+ }
+
+ /**
+ * Creates an AI Node with active auction schedule WITH a bandit solver for
+ * switching to another node automatically
+ *
+ * @param comm
+ * the used communication policy
+ * @param staticVG
+ * if static vision graph or not
+ * @param vg
+ * the initial vision graph
+ * @param r
+ * the global registration component - can be null
+ * @param auctionDuration
+ * the duration of auctions
+ * @param rg
+ * the random number generator for this instance
+ * @param bs
+ * the bandit solver
+ */
+ public ActiveAINodeMultiClustering(boolean staticVG, Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg, IBanditSolver bs) {
+ super(staticVG, vg, r, auctionDuration, rg, bs);
+ }
+
+ /**
+ * Creates an AI Node with active auction schedule WITHOUT bandit solver for
+ * switching to another node automatically
+ *
+ * @param comm
+ * the used communication policy
+ * @param staticVG
+ * if static vision graph or not
+ * @param vg
+ * the initial vision graph
+ * @param r
+ * the global registration component - can be null
+ * @param rg
+ * the random number generator for this instance
+ */
+ public ActiveAINodeMultiClustering(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg) {
+ super(staticVG, vg, r, rg);
+ }
+
+ /**
+ * Creates an AI Node with active auction schedule WITH a bandit solver for
+ * switching to another node automatically
+ *
+ * @param comm
+ * the used communication policy
+ * @param staticVG
+ * if static vision graph or not
+ * @param vg
+ * the initial vision graph
+ * @param r
+ * the global registration component - can be null
+ * @param rg
+ * the random number generator for this instance
+ * @param bs
+ * the bandit solver
+ */
+ public ActiveAINodeMultiClustering(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg, IBanditSolver bs) {
+ super(staticVG, vg, r, rg, bs);
+ }
+
+ public void advertiseTrackedObjects() {
+ // Active strategy means all objects are advertised every time
+ for (ITrObjectRepresentation io : this.getAllTrackedObjects_bb().values()) {
+ callForHelp(io);
+ }
+ }
+}
diff --git a/src/epics/ai/PassiveAINodeMultiClustering.java b/src/epics/ai/PassiveAINodeMultiClustering.java
new file mode 100644
index 0000000..25af236
--- /dev/null
+++ b/src/epics/ai/PassiveAINodeMultiClustering.java
@@ -0,0 +1,98 @@
+package epics.ai;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import epics.common.AbstractAINode;
+import epics.common.IBanditSolver;
+import epics.common.IRegistration;
+import epics.common.ITrObjectRepresentation;
+import epics.common.RandomNumberGenerator;
+
+public class PassiveAINodeMultiClustering extends AbstractClusterFoVAINode { //ActiveAINodeMulti {
+
+ /** The confidence for an object below which we advertise */
+ public static final double CONF_THRESHOLD = 0.1;
+
+ /** Keep track of confidence from last time step to find whether
+ * it has increased or decreased */
+ private Map lastConfidence = new HashMap();
+
+ /**
+ * constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
+ * @param comm the communication policy
+ * @param staticVG if static or dynamic vision graph
+ * @param vg the initial vision graph
+ * @param r the global registration component - can be null
+ * @param rg the random number generator for this instance
+ */
+ public PassiveAINodeMultiClustering(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg){
+ super(staticVG, vg, r, rg);
+ }
+
+ /**
+ * constructor for this node. calls its super constructor and sets the DEFAULT_AUCTION_DURATION
+ * @param comm the communication policy
+ * @param staticVG if static or dynamic vision graph
+ * @param vg the initial vision graph
+ * @param r the global registration component - can be null
+ * @param rg the random number generator for this instance
+ * @param bs the bandit solver to decide the best communication policy and auctioning schedule
+ */
+ public PassiveAINodeMultiClustering(boolean staticVG, Map vg, IRegistration r, RandomNumberGenerator rg, IBanditSolver bs){
+ super(staticVG, vg, r, rg, bs);
+ }
+
+ public PassiveAINodeMultiClustering(boolean staticVG,
+ Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg) {
+ super(staticVG, vg, r, auctionDuration, rg);
+ }
+
+ public PassiveAINodeMultiClustering(boolean staticVG,
+ Map vg, IRegistration r, int auctionDuration, RandomNumberGenerator rg, IBanditSolver bs) {
+ super(staticVG, vg, r, auctionDuration, rg, bs);
+ }
+
+ /**
+ * creates a passive ai instance from another existing instance
+ * @param ai the given existing AI instance
+ */
+ public PassiveAINodeMultiClustering(AbstractAINode ai){
+ super(ai);
+ if (ai instanceof PassiveAINodeMultiClustering) {
+ PassiveAINodeMultiClustering pass = (PassiveAINodeMultiClustering) ai;
+ lastConfidence = pass.lastConfidence;
+ }
+ }
+
+ @Override
+ public void advertiseTrackedObjects() {
+ for (ITrObjectRepresentation io : this.getAllTrackedObjects_bb().values()) {
+ double conf = this.getConfidence(io);
+ double lastConf = this.getLastConfidenceFor(io);
+
+ if (this.camController.realObjectsUsed()){
+ if(this.camController.objectIsVisible(io) == 1){
+ callForHelp(io);
+ }
+ } else if (this.camController.objectIsVisible(io) == -1){
+ if (conf < CONF_THRESHOLD && (conf == 0 || conf < lastConf)) {
+ callForHelp(io);
+ }
+ }
+ this.addLastConfidence(io, conf);
+ }
+ }
+
+ protected void addLastConfidence(ITrObjectRepresentation io, double conf) {
+ this.lastConfidence.put(io, conf);
+ }
+
+ protected double getLastConfidenceFor(ITrObjectRepresentation io) {
+ if (lastConfidence.containsKey(io)) {
+ return lastConfidence.get(io);
+ } else {
+ return 0.0;
+ }
+ }
+}
diff --git a/src/epics/ai/kmeans/Cluster.java b/src/epics/ai/kmeans/Cluster.java
new file mode 100644
index 0000000..ca8739c
--- /dev/null
+++ b/src/epics/ai/kmeans/Cluster.java
@@ -0,0 +1,91 @@
+/* by Hedde Bosman */
+
+package epics.ai.kmeans;
+
+
+import java.util.Map;
+import java.util.HashMap;
+
+// this class is not 'generic' anymore... due to the vision graph being added here...
+
+public class Cluster {
+ private ClusterPoint center; // the mean/center of the cluster
+ private double count; // the number of cluster points associated to this mean
+ private int relevance;
+
+ // again, public = lazy...
+ public Map visionGraph;
+
+ public Cluster(int numCoordinates) {
+ count = 0.0;
+ center = new ClusterPoint(numCoordinates);
+ visionGraph = new HashMap();
+ this.resetRelevance();
+ }
+ public Cluster(ClusterPoint x) {
+ count = 1.0;
+ center = x;
+ visionGraph = new HashMap();
+ this.resetRelevance();
+ }
+
+ // initiate the cluster center by using random values between [-1,1]
+ public void initRandomCenter() {
+ for (int i = 0; i < center.coordinates.length; i++) {
+ center.coordinates[i] = Math.random()*2.0-1.0; // random() is 0-1
+ }
+ }
+
+ // get the distance from the cluster center to point x
+ public double distanceTo(ClusterPoint x) {
+ return center.distanceTo(x);
+ }
+ public double distanceTo(Cluster x) {
+ return center.distanceTo(x.center);
+ }
+
+ // should get called every time a point has been added to THIS cluster
+ public void resetRelevance() {
+ this.relevance = SequentialKMeans.CLUSTER_LIFETIME;
+ }
+ // should get called every time a point has been added to ANY cluster
+ public boolean decrementRelevance() {
+ return (--relevance < 0);
+ }
+
+ /////////////////////////////////////////////////////////
+ // functions to add a point to this cluster
+ /////////////////////////////////////////////////////////
+
+ // if factor is fixed, we forget
+ public void addForgetfull(ClusterPoint x, double factor) {
+ // for each coordinate (x,y,...)
+ for (int i = 0; i < center.coordinates.length; i++) {
+ // add factor * diff(this,x)^2
+ center.coordinates[i] += factor * (x.coordinates[i] - center.coordinates[i]);
+ }
+ this.resetRelevance();
+ }
+
+ // fixed forgetting factor
+ public void addForgetfull(ClusterPoint x) {
+ this.addForgetfull(x, 0.01);
+ }
+
+ // changing forgetting factor (learning rate is slower when number of data points increases)
+ public void add(ClusterPoint x) {
+ count += 1.0;
+ double factor = 1.0 / count;
+ this.addForgetfull(x, factor);
+ }
+
+ public String toString() {
+ String r = "Cluster, center=[ ";
+ for (int i = 0; i < this.center.coordinates.length; i++) {
+ r += this.center.coordinates[i] + " ";
+ }
+ r += "]; count="+this.count;
+ return r;
+ }
+}
+
diff --git a/src/epics/ai/kmeans/ClusterPoint.java b/src/epics/ai/kmeans/ClusterPoint.java
new file mode 100644
index 0000000..c3a98fe
--- /dev/null
+++ b/src/epics/ai/kmeans/ClusterPoint.java
@@ -0,0 +1,44 @@
+/* by Hedde Bosman */
+
+package epics.ai.kmeans;
+
+public class ClusterPoint {
+ public double[] coordinates; // public = being lazy
+
+ // constructor by number of coordinates (no initalization)
+ public ClusterPoint(int numCoordinates) {
+ this.coordinates = new double[numCoordinates];
+ }
+
+ // constructor by array of doubles that represent coordinates
+ public ClusterPoint(double[] coords) {
+ this.coordinates = coords;
+ }
+
+ // determine euclidian distance from this point to point y
+ // returns NaN when number of coordinates do not match (different spaces)
+ public double distanceTo(ClusterPoint y) {
+ if (y.coordinates.length != this.coordinates.length) {
+ return Double.NaN;
+ }
+
+ double dist = 0.0;
+
+ for (int i = 0; i < this.coordinates.length; i++) {
+ dist += Math.pow((this.coordinates[i]-y.coordinates[i]), 2);
+ }
+ dist = Math.sqrt(dist);
+
+ return dist;
+ }
+
+ public String toString() {
+ String r = "[ ";
+ for (int i = 0; i < this.coordinates.length; i++) {
+ r += this.coordinates[i]+" ";
+ }
+ r += "]";
+ return r;
+ }
+}
+
diff --git a/src/epics/ai/kmeans/SequentialKMeans.java b/src/epics/ai/kmeans/SequentialKMeans.java
new file mode 100644
index 0000000..1bc3e47
--- /dev/null
+++ b/src/epics/ai/kmeans/SequentialKMeans.java
@@ -0,0 +1,138 @@
+/* by Hedde Bosman */
+
+/*
+ implemented follwing the pseudo-code at:
+ http://www.cs.princeton.edu/courses/archive/fall08/cos436/Duda/C/sk_means.htm
+*/
+
+package epics.ai.kmeans;
+
+import java.util.Vector;
+import java.util.Iterator;
+import java.util.HashMap;
+
+// this class is not generic anymore... it clones the vision graph when adding a new cluster
+
+public class SequentialKMeans {
+ private int maxNumClusters;
+ private Vector clusters; // the clusters :P
+
+ // if a cluster has not seen a new point associated with it for CLUSTER_LIFETIME datapoints, we remove it...
+ public final static int CLUSTER_LIFETIME = 100;
+
+ public final static double MINIMUM_INTER_CLUSTER_DISTANCE = 0.05;
+ // CLUSTER_ADD_FACTOR = 0.5 => 0.5*(maxDistance between clusters), so maximum non-overlapping radius
+ // any larger values means that they all overlap
+ public final static double CLUSTER_ADD_FACTOR = 0.5;
+
+
+ public SequentialKMeans(int numCoordinates) {
+ clusters = new Vector();
+ // only add one cluster, the adaptive 'add' should add new ones on demand
+ Cluster c = new Cluster(numCoordinates);
+ c.initRandomCenter();
+ clusters.add(c);
+
+ maxNumClusters = 10;
+ }
+ // constructor, requires #clusters and #coordinates
+ public SequentialKMeans(int numCoordinates, int numClusters) {
+ clusters = new Vector();
+
+ for (int i = 0; i < numClusters; i++) {
+ Cluster c = new Cluster(numCoordinates);
+ c.initRandomCenter();
+ clusters.add(c);
+ }
+
+ maxNumClusters = 10;
+ }
+
+ public double getMaximumInterClusterDistance() {
+ double dist = MINIMUM_INTER_CLUSTER_DISTANCE;
+ for (int i = 0; i < clusters.size(); i++) {
+ for (int j = i+1; j < clusters.size(); j++) {
+ double tmpDist = clusters.get(i).distanceTo(clusters.get(j));
+ if (dist < tmpDist)
+ dist = tmpDist;
+ }
+ }
+ return dist;
+ }
+
+ public int getClosestClusterIndex(ClusterPoint x) {
+ double dist = Double.MAX_VALUE;
+ int idx = -1;
+
+ // for each cluster
+ for (int i = 0; i < clusters.size(); i++) {
+ // determine if the center is closer than other clusters
+ double tmpDist = clusters.get(i).distanceTo(x);
+ if (dist > tmpDist) {
+ // if so, this is the closest clusters
+ dist = tmpDist;
+ idx = i;
+ }
+ }
+ return idx;
+ }
+ public Cluster getClosestCluster(ClusterPoint x) {
+ return clusters.get( getClosestClusterIndex(x) );
+ }
+
+ public Iterator getClusterIterator() {
+ return clusters.iterator();
+ }
+
+ // add a single point to the cluster it is closest to
+ public void add(ClusterPoint x) {
+ int idx = getClosestClusterIndex(x);
+ // yes, less efficient than inlining the getClosestClusterIndex
+ // but, saves some code duplication
+ double dist = clusters.get(idx).distanceTo(x);
+
+
+ if (dist < CLUSTER_ADD_FACTOR*this.getMaximumInterClusterDistance()) {
+ // add it to the closest cluster
+ clusters.get(idx).add(x);
+ } else {
+ // should add a new cluster, because it's outside of the radius of any other, i.e. an outlier
+ if (clusters.size() < maxNumClusters) {
+ // yes, we are not yet at our maximum number of clusters!
+ Cluster c = new Cluster(x);
+ c.visionGraph = (HashMap) ((HashMap)clusters.get(idx).visionGraph).clone(); // clone the vision graph of the closest cluster
+ clusters.add(c);
+// System.out.println("CLUSTER ADD "+c);
+ } else {
+ // we're already at the max number of clusters, so add it to the closest cluster
+ // this is basically where we become a voronoi diagram
+ clusters.get(idx).add(x);
+ }
+ }//*/
+
+ // keep track of cluster 'relevance' and remove irrelevant clusters
+ if (clusters.size() > 1) { // at least have one cluster... :P
+ Iterator it = clusters.iterator();
+ while (it.hasNext()) {
+ Cluster c = it.next();
+ if (c.decrementRelevance()) {
+ //System.out.println("Removing cluster "+c);
+ it.remove();
+// System.out.println("CLUSTER REMOVE "+c);
+ // maybe merge it?
+ }
+ }
+ }
+ }
+
+ public String toString() {
+ String r = "";
+
+ for (int i = 0; i < clusters.size(); i++) {
+ r += clusters.get(i).toString() + "\n";
+ }
+
+ return r;
+ }
+};
+
diff --git a/src/epics/camsim/core/CameraController.java b/src/epics/camsim/core/CameraController.java
index a493d91..e67b6b2 100644
--- a/src/epics/camsim/core/CameraController.java
+++ b/src/epics/camsim/core/CameraController.java
@@ -412,6 +412,8 @@ public IMessage sendMessage(String to, MessageType msgType, Object content){
stats.addCommunication(1.0, this.getName());
} else if (msgType == MessageType.StartTracking) {
stats.addHandover(1.0);
+ } else if(msgType == MessageType.Found){
+ stats.addBid();
}
} catch (Exception e) {
e.printStackTrace();
@@ -645,4 +647,26 @@ public int objectIsVisible(ITrObjectRepresentation tor) {
return 1;
}
}
+
+ @Override
+ public boolean isObjectInFOV(TraceableObject tor){
+ return visible_objects.containsKey(tor);
+ }
+
+ @Override
+ public Coordinate2D getPostion() {
+ return new Coordinate2D(x, y);
+ }
+
+ @Override
+ public boolean isCoordinateInFOV(Coordinate2D pos) {
+ final double dist = Math.hypot(pos.getX(), pos.getY());
+ if(dist < range) {
+ final double angle = Math.atan2(pos.getY(), pos.getX());
+ final double angleS = (Math.PI-viewing_angle)/2;
+ final double angleF = (Math.PI+viewing_angle) /2;
+ return angleS < angle && angle < angleF;
+ }
+ return false;
+ }
}
diff --git a/src/epics/camsim/core/SimCore.java b/src/epics/camsim/core/SimCore.java
index af40e77..f0c6b96 100644
--- a/src/epics/camsim/core/SimCore.java
+++ b/src/epics/camsim/core/SimCore.java
@@ -31,1192 +31,1286 @@
import epics.commpolicy.Step;
/**
- * SimCore represents the main core of the simulation. each object and camera is controlled from here.
- * the SimCore drives the simulation in discrete time steps.
+ * SimCore represents the main core of the simulation. each object and camera is
+ * controlled from here. the SimCore drives the simulation in discrete time
+ * steps.
+ *
* @author Marcin Bogdanski
*/
public class SimCore {
- int CAMERRORRATE = -1; //percent of camera error. -1 = no camera error
- int RESETRATE = 50; //looses knowledge about everything - happens in x percentage of cameraerror (only when error occurs, knowledgeloss can happen)
+ int CAMERRORRATE = -1; // percent of camera error. -1 = no camera error
+ int RESETRATE = 50; // looses knowledge about everything - happens in x
+ // percentage of cameraerror (only when error occurs,
+ // knowledgeloss can happen)
static final boolean BIDIRECTIONAL_VISION = true;
boolean USEGLOBAL = false;
String EPSILONGREEDY = "epics.learning.EpsilonGreedy";
private double epsilon = 0.1;
double alpha = 0.5;
- private int selectInterval = 0; //if < 1, a new strategy is selected every timestep
+ private int selectInterval = 0; // if < 1, a new strategy is selected every
+ // timestep
private int currentSelectInt = 0;
-
+
Statistics stats;
RandomNumberGenerator randomGen;
-
+
int interval = 1;
-
- static int camIDGenerator = 0;
- public static int getNextID(){ return camIDGenerator++; }
-
- /*
- * Simulation area
- */
- private double min_x;
- /**
- * returns the minimum x value for the simulation environment
- * @return minimum x of simulation environment
- */
- public double get_min_x(){return min_x;}
- private double max_x;
- /**
- * returns the maximum x value for the simulation environment
- * @return maximum x of simulation environment
- */
- public double get_max_x(){return max_x;}
- private double min_y;
- /**
- * returns the minimum y value for the simulation environment
- * @return minimum y of simulation environment
- */
- public double get_min_y(){return min_y;}
- private double max_y;
- /**
- * returns the maximum y value for the simulation environment
- * @return maximum y of simulation environment
- */
- public double get_max_y(){return max_y;}
- private long sim_time;
- /**
- * returns the maximum simulation time
- * @return maximum simulation time
- */
- public long get_sim_time(){return sim_time;}
- private String ai_alg; public boolean staticVG = false;
-
- private boolean firstUpdate;
- private ArrayList events;
- private boolean _runReal;
- private int step;
-
- private IRegistration reg = null;
- private SimSettings settings;
- private String paramFile;
-
-
- /**
- * checks if the given coordinates are in range
- * throws a IllegalArgumentException if they are not
- * @param x
- * @param y
- */
- private void checkCoordInRange( double x, double y ){
- if ( x < min_x || x > max_x || y < min_y || y > max_y ){
- throw new IllegalArgumentException("x/y value out of simulation field.");
- }
- }
-
- private ArrayList cameras = new ArrayList();
- private ArrayList objects = new ArrayList();
+
+ static int camIDGenerator = 0;
+
+ public static int getNextID() {
+ return camIDGenerator++;
+ }
+
+ /*
+ * Simulation area
+ */
+ private double min_x;
+
+ /**
+ * returns the minimum x value for the simulation environment
+ *
+ * @return minimum x of simulation environment
+ */
+ public double get_min_x() {
+ return min_x;
+ }
+
+ private double max_x;
+
+ /**
+ * returns the maximum x value for the simulation environment
+ *
+ * @return maximum x of simulation environment
+ */
+ public double get_max_x() {
+ return max_x;
+ }
+
+ private double min_y;
+
+ /**
+ * returns the minimum y value for the simulation environment
+ *
+ * @return minimum y of simulation environment
+ */
+ public double get_min_y() {
+ return min_y;
+ }
+
+ private double max_y;
+
+ /**
+ * returns the maximum y value for the simulation environment
+ *
+ * @return maximum y of simulation environment
+ */
+ public double get_max_y() {
+ return max_y;
+ }
+
+ private long sim_time;
+
+ /**
+ * returns the maximum simulation time
+ *
+ * @return maximum simulation time
+ */
+ public long get_sim_time() {
+ return sim_time;
+ }
+
+ private String ai_alg;
+ public boolean staticVG = false;
+
+ private boolean firstUpdate;
+ private ArrayList events;
+ private boolean _runReal;
+ private int step;
+
+ private IRegistration reg = null;
+ private SimSettings settings;
+ private String paramFile;
+
+ /**
+ * checks if the given coordinates are in range throws a
+ * IllegalArgumentException if they are not
+ *
+ * @param x
+ * @param y
+ */
+ private void checkCoordInRange(double x, double y) {
+ if (x < min_x || x > max_x || y < min_y || y > max_y) {
+ throw new IllegalArgumentException("x/y value out of simulation field.");
+ }
+ }
+
+ private ArrayList cameras = new ArrayList();
+ private ArrayList objects = new ArrayList();
private AbstractCommunication _comm = null;
private String outputFile;
-
/**
* Constructor pure simulation
- * @param seed for the random number generators
- * @param output outputfilename for statistics
- * @param ss settings of simulations - generated from an scenariofile
- * @param global global coordination used
- * @param camError the probability of failing cameras
- * @param camReset probability of a reset after a camera failed
+ *
+ * @param seed
+ * for the random number generators
+ * @param output
+ * outputfilename for statistics
+ * @param ss
+ * settings of simulations - generated from an scenariofile
+ * @param global
+ * global coordination used
+ * @param camError
+ * the probability of failing cameras
+ * @param camReset
+ * probability of a reset after a camera failed
*/
- public SimCore( long seed, String output, SimSettings ss, boolean global){
+ public SimCore(long seed, String output, SimSettings ss, boolean global) {
initSimCore(seed, output, global, -1, 50, alpha, false, false, "", null);
this.interpretFile(ss);
}
-
/**
- * Constructor pure simulation
- * @param seed for the random number generators
- * @param output outputfilename for statistics
- * @param ss settings of simulations - generated from an scenariofile
- * @param global global coordination used
- * @param banditParam the epsilon/temperature value for bandit solvers
- * @param alpha the alpha value for the weighted reward function used in bandit solvers
+ * Constructor pure simulation
+ *
+ * @param seed
+ * for the random number generators
+ * @param output
+ * outputfilename for statistics
+ * @param ss
+ * settings of simulations - generated from an scenariofile
+ * @param global
+ * global coordination used
+ * @param banditParam
+ * the epsilon/temperature value for bandit solvers
+ * @param alpha
+ * the alpha value for the weighted reward function used in
+ * bandit solvers
*/
- public SimCore( long seed, String output, SimSettings ss, boolean global, double banditParam, double alpha){
+ public SimCore(long seed, String output, SimSettings ss, boolean global, double banditParam, double alpha) {
initSimCore(seed, output, global, -1, 50, alpha, false, false, "", null);
this.interpretFile(ss);
}
/**
* Constructor
- * @param seed for the random number generators
- * @param output outputfilename for statistics
- * @param ss settings of simulations - generated from an scenariofile
- * @param global global coordination used
- * @param banditParam the epsilon/temperature value for bandit solvers
- * @param alpha the alpha value for the weighted reward function used in bandit solvers
- * @param realData indicates if real data has been used
- * @param allStatistics indicates if statistics are also taken for each camera seperately
+ *
+ * @param seed
+ * for the random number generators
+ * @param output
+ * outputfilename for statistics
+ * @param ss
+ * settings of simulations - generated from an scenariofile
+ * @param global
+ * global coordination used
+ * @param banditParam
+ * the epsilon/temperature value for bandit solvers
+ * @param alpha
+ * the alpha value for the weighted reward function used in
+ * bandit solvers
+ * @param realData
+ * indicates if real data has been used
+ * @param allStatistics
+ * indicates if statistics are also taken for each camera
+ * seperately
*/
- public SimCore( long seed, String output, SimSettings ss, boolean global, double epsilon, double alpha, boolean realData, boolean allStatistics){
+ public SimCore(long seed, String output, SimSettings ss, boolean global, double epsilon, double alpha, boolean realData, boolean allStatistics) {
initSimCore(seed, output, global, -1, 50, alpha, realData, allStatistics, "", null);
this.epsilon = epsilon;
- this.interpretFile(ss);
+ this.interpretFile(ss);
}
-
+
/**
- * Constructor pure simulation
- * @param seed for the random number generators
- * @param output outputfilename for statistics
- * @param ss settings of simulations - generated from an scenariofile
- * @param global global coordination used
- * @param camError the probability of failing cameras
- * @param camReset probability of a reset after a camera failed
- * @param alpha the alpha value for the weighted reward function used in bandit solvers
- * @param realData indicates if real data has been used
- * @param allStatistics indicates if statistics are also taken for each camera seperately
+ * Constructor pure simulation
+ *
+ * @param seed
+ * for the random number generators
+ * @param output
+ * outputfilename for statistics
+ * @param ss
+ * settings of simulations - generated from an scenariofile
+ * @param global
+ * global coordination used
+ * @param camError
+ * the probability of failing cameras
+ * @param camReset
+ * probability of a reset after a camera failed
+ * @param alpha
+ * the alpha value for the weighted reward function used in
+ * bandit solvers
+ * @param realData
+ * indicates if real data has been used
+ * @param allStatistics
+ * indicates if statistics are also taken for each camera
+ * seperately
*/
- public SimCore( long seed, String output, SimSettings ss,
- boolean global, int camError, int camReset, double alpha, boolean realData, boolean allStatistics) {
- initSimCore(seed, output, global, camError, camReset,
- alpha, realData, allStatistics, "", null);
+ public SimCore(long seed, String output, SimSettings ss, boolean global, int camError, int camReset, double alpha, boolean realData, boolean allStatistics) {
+ initSimCore(seed, output, global, camError, camReset, alpha, realData, allStatistics, "", null);
+ this.interpretFile(ss);
+ }
+
+ /**
+ * Constructor pure simulation
+ *
+ * @param seed
+ * for the random number generators
+ * @param output
+ * outputfilename for statistics
+ * @param summaryFile
+ * File for a summarised statistics file
+ * @param paramFile
+ * parameterfile for simulations
+ * @param ss
+ * settings of simulations - generated from an scenariofile
+ * @param global
+ * global coordination used
+ * @param camError
+ * the probability of failing cameras
+ * @param camReset
+ * probability of a reset after a camera failed
+ * @param realData
+ * indicates if real data has been used
+ * @param allStatistics
+ * indicates if statistics are also taken for each camera
+ * seperately
+ */
+ public SimCore(long seed, String output, String summaryFile, String paramFile, SimSettings ss, boolean global, int camError, int camReset, boolean realData, boolean allStatistics) {
+ initSimCore(seed, output, global, camError, camReset, alpha, realData, allStatistics, summaryFile, paramFile);
this.interpretFile(ss);
}
-
- /**
- * Constructor pure simulation
- * @param seed for the random number generators
- * @param output outputfilename for statistics
- * @param summaryFile File for a summarised statistics file
- * @param paramFile parameterfile for simulations
- * @param ss settings of simulations - generated from an scenariofile
- * @param global global coordination used
- * @param camError the probability of failing cameras
- * @param camReset probability of a reset after a camera failed
- * @param realData indicates if real data has been used
- * @param allStatistics indicates if statistics are also taken for each camera seperately
- */
- public SimCore(long seed, String output, String summaryFile, String paramFile, SimSettings ss,
- boolean global, int camError, int camReset, boolean realData, boolean allStatistics) {
- initSimCore(seed, output, global, camError, camReset,
- alpha, realData, allStatistics, summaryFile, paramFile);
- this.interpretFile(ss);
- }
/**
* Initiation method for the simcore. Sets all the parameters
- * @param seed for the random number generators
- * @param output outputfilename for statistics
- * @param global global coordination used
- * @param camError the probability of failing cameras
- * @param camReset probability of a reset after a camera failed
- * @param alpha the alpha value for the weighted reward function used in bandit solvers
- * @param realData indicates if real data has been used
- * @param allStatistics indicates if statistics are also taken for each camera seperately
- * @param summaryFile File for a summarised statistics file
- * @param paramFile parameterfile for simulations
+ *
+ * @param seed
+ * for the random number generators
+ * @param output
+ * outputfilename for statistics
+ * @param global
+ * global coordination used
+ * @param camError
+ * the probability of failing cameras
+ * @param camReset
+ * probability of a reset after a camera failed
+ * @param alpha
+ * the alpha value for the weighted reward function used in
+ * bandit solvers
+ * @param realData
+ * indicates if real data has been used
+ * @param allStatistics
+ * indicates if statistics are also taken for each camera
+ * seperately
+ * @param summaryFile
+ * File for a summarised statistics file
+ * @param paramFile
+ * parameterfile for simulations
*/
- private void initSimCore(long seed, String output, boolean global,
- int camError, int camReset, double alpha,
- boolean realData, boolean allStatistics, String summary, String paramFile) {
+ private void initSimCore(long seed, String output, boolean global, int camError, int camReset, double alpha, boolean realData, boolean allStatistics, String summary, String paramFile) {
this.RESETRATE = camReset;
- this.CAMERRORRATE = camError;
- this.alpha = alpha;
-
+ this.CAMERRORRATE = camError;
+ this.alpha = alpha;
+
USEGLOBAL = global;
-
+
_runReal = realData;
step = 0;
firstUpdate = true;
-
- if(USEGLOBAL){
- reg = new GlobalRegistration();
- }
-
- randomGen = new RandomNumberGenerator(seed);
- outputFile = output;
- if(summary == ""){
- stats = new Statistics(output, "E://Results//sum_result/" + output.substring(output.indexOf('/')+1), allStatistics, randomGen.getSeed());
+
+ if (USEGLOBAL) {
+ reg = new GlobalRegistration();
}
- else{
+
+ randomGen = new RandomNumberGenerator(seed);
+ outputFile = output;
+ if (summary == "") {
+ stats = new Statistics(output, "E://Results//sum_result/" + output.substring(output.indexOf('/') + 1), allStatistics, randomGen.getSeed());
+ } else {
stats = new Statistics(output, summary, allStatistics, randomGen.getSeed());
}
-
+
}
-
- /**
- * Interprets the SimSettings object and creates cameras, vision graphs
- * and trackable objects with their corresponding behaviour as well as
- * the simulation environment itself
- * @param ss The object containing the settings for this simulation
- */
- public void interpretFile(SimSettings ss){
- settings = ss;
-
- if(ss.min_x != null){
- this.min_x = ss.min_x;
- }
- else{
- this.min_x = -30;
- }
- if(ss.max_x != null){
- this.max_x = ss.max_x;
- }
- else{
- this.max_x = 30;
- }
- if(ss.min_y != null){
- this.min_y = ss.min_y;
- }
- else{
- this.min_y = -30;
- }
- if(ss.max_y != null){
- this.max_y = ss.max_y;
- }
- else{
- this.max_y = 30;
- }
-
- if(ss.visionGraph != null){
- staticVG = ss.visionGraph.isStatic;
- }
-
-
- for (SimSettings.CameraSettings cs : ss.cameras){
- Map vg = null;
-
- if(ss.visionGraph != null){
- vg = new HashMap();
- if(ss.visionGraph.vg.containsKey(cs.name)){
- ArrayList neighs = ss.visionGraph.vg.get(cs.name);
- for(String s : neighs){
- vg.put(s, 1.0);
- }
- }
-
- if(staticVG){
- for(Map.Entry> all : ss.visionGraph.vg.entrySet()){
- if(all.getValue().contains(cs.name))
- vg.put(all.getKey(), 1.0);
- }
- }
- }
-
- this.add_camera(
- cs.name, cs.x, cs.y,
- cs.heading, cs.viewing_angle,
- cs.range, cs.ai_algorithm,
- cs.comm, cs.customComm,
- cs.limit, vg, cs.bandit,
- cs.predefConfidences, cs.predefVisibility);
- }
-
- for (SimSettings.TrObjectSettings tro : ss.objects){
- this.add_object(tro.x, tro.y, tro.heading, tro.speed, tro.features);
- }
-
- for (TrObjectWithWaypoints objWithWP : ss.objectsWithWaypoints) {
- this.add_object(objWithWP.speed, objWithWP.waypoints, objWithWP.features);
- }
-
- events = ss.events;
- }
-
- /** Writes statistics and closes all statistics files */
- public void close_files(){
- try {
+
+ /**
+ * Interprets the SimSettings object and creates cameras, vision graphs and
+ * trackable objects with their corresponding behaviour as well as the
+ * simulation environment itself
+ *
+ * @param ss
+ * The object containing the settings for this simulation
+ */
+ public void interpretFile(SimSettings ss) {
+ settings = ss;
+
+ if (ss.min_x != null) {
+ this.min_x = ss.min_x;
+ } else {
+ this.min_x = -30;
+ }
+ if (ss.max_x != null) {
+ this.max_x = ss.max_x;
+ } else {
+ this.max_x = 30;
+ }
+ if (ss.min_y != null) {
+ this.min_y = ss.min_y;
+ } else {
+ this.min_y = -30;
+ }
+ if (ss.max_y != null) {
+ this.max_y = ss.max_y;
+ } else {
+ this.max_y = 30;
+ }
+
+ if (ss.visionGraph != null) {
+ staticVG = ss.visionGraph.isStatic;
+ }
+
+ for (SimSettings.CameraSettings cs : ss.cameras) {
+ Map vg = null;
+
+ if (ss.visionGraph != null) {
+ vg = new HashMap();
+ if (ss.visionGraph.vg.containsKey(cs.name)) {
+ ArrayList neighs = ss.visionGraph.vg.get(cs.name);
+ for (String s : neighs) {
+ vg.put(s, 1.0);
+ }
+ }
+
+ if (staticVG) {
+ for (Map.Entry> all : ss.visionGraph.vg.entrySet()) {
+ if (all.getValue().contains(cs.name))
+ vg.put(all.getKey(), 1.0);
+ }
+ }
+ }
+
+ this.add_camera(cs.name, cs.x, cs.y, cs.heading, cs.viewing_angle, cs.range, cs.ai_algorithm, cs.comm, cs.customComm, cs.limit, vg, cs.bandit, cs.predefConfidences, cs.predefVisibility);
+ }
+
+ for (SimSettings.TrObjectSettings tro : ss.objects) {
+ this.add_object(tro.x, tro.y, tro.heading, tro.speed, tro.features);
+ }
+
+ for (TrObjectWithWaypoints objWithWP : ss.objectsWithWaypoints) {
+ this.add_object(objWithWP.speed, objWithWP.waypoints, objWithWP.features);
+ }
+
+ events = ss.events;
+ }
+
+ /** Writes statistics and closes all statistics files */
+ public void close_files() {
+ try {
stats.close();
} catch (Exception e) {
e.printStackTrace();
}
- }
-
- /** Outputs all information from all bandit solvers into files */
- private void printAllBanditResults(){
- for(CameraController cc : this.cameras){
+ }
+
+ /** Outputs all information from all bandit solvers into files */
+ private void printAllBanditResults() {
+ for (CameraController cc : this.cameras) {
IBanditSolver bs = cc.getAINode().getBanditSolver();
- if(bs != null){
+ if (bs != null) {
ArrayList> results = bs.getResults();
printResults(results, outputFile + "_" + cc.getName() + ".csv");
}
-
+
}
- }
-
- /**
- * Convenience method to print arrayLists within ArrayLists into
- * specific files
- * @param res results to be stored in file
- * @param filename the filename to store results to
- */
- private void printResults(ArrayList> res, String filename){
+ }
+
+ /**
+ * Convenience method to print arrayLists within ArrayLists into specific
+ * files
+ *
+ * @param res
+ * results to be stored in file
+ * @param filename
+ * the filename to store results to
+ */
+ private void printResults(ArrayList> res, String filename) {
File f = new File(filename);
PrintWriter out;
try {
FileWriter fw = new FileWriter(f);
out = new PrintWriter(fw);
int size = res.get(0).size();
- for(int j = 0; j < size; j++){
- for(int i = 0; i < res.size()-1; i++){
+ for (int j = 0; j < size; j++) {
+ for (int i = 0; i < res.size() - 1; i++) {
out.print(res.get(i).get(j) + ";");
}
- out.println(res.get(res.size()-1).get(j));
+ out.println(res.get(res.size() - 1).get(j));
}
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
-
+
}
- /**
- * Creates a new camera and adds it to the list of cameras WITH an AINODE as parameter
- * @param name defines the name of the camera
- * @param x_pos defines the x position in the internal coordinates
- * @param y_pos defines the y position in the internal coordinates
- * @param heading_degrees defines the direction of the viewing point
- * @param angle_degrees defines the width of the viewing angle
- * @param range defines the range (distance) of the camera's view
- * @param ai_algorithm defines the initial algorithm approach used
- * @param comm defines the initial/predefined communication strategy
- * @param limit sets limit for amount of objects being tracked (0 = unlimited)
- * @param vg contains the predefined vision graph
- * @param bandit defines the used bandit solver algorithm
- * @param predefConfidences defines a list of objects represented by an ArrayList of
- * their confidences where each element is for one frame/timestep
- * @param predefVisibility defines a list of objects represented by an ArrayList of
- * their visibility (0 = visible, 1 = not visible or at touching border) where each
- * element is for one frame/timestep
+ /**
+ * Creates a new camera and adds it to the list of cameras WITH an AINODE as
+ * parameter
+ *
+ * @param name
+ * defines the name of the camera
+ * @param x_pos
+ * defines the x position in the internal coordinates
+ * @param y_pos
+ * defines the y position in the internal coordinates
+ * @param heading_degrees
+ * defines the direction of the viewing point
+ * @param angle_degrees
+ * defines the width of the viewing angle
+ * @param range
+ * defines the range (distance) of the camera's view
+ * @param ai_algorithm
+ * defines the initial algorithm approach used
+ * @param comm
+ * defines the initial/predefined communication strategy
+ * @param limit
+ * sets limit for amount of objects being tracked (0 = unlimited)
+ * @param vg
+ * contains the predefined vision graph
+ * @param bandit
+ * defines the used bandit solver algorithm
+ * @param predefConfidences
+ * defines a list of objects represented by an ArrayList of their
+ * confidences where each element is for one frame/timestep
+ * @param predefVisibility
+ * defines a list of objects represented by an ArrayList of their
+ * visibility (0 = visible, 1 = not visible or at touching
+ * border) where each element is for one frame/timestep
*/
- public void add_camera(
- String name,
- double x_pos, double y_pos,
- double heading_degrees,
- double angle_degrees,
- double range,
- String ai_algorithm,
- int commValue,
- String customComm,
- int limit,
- Map vg,
- String bandit,
- ArrayList> predefConfidences,
- ArrayList> predefVisibility){
-
- ai_alg = ai_algorithm;
- add_camera(
- name, x_pos, y_pos, heading_degrees, angle_degrees,
- range, commValue, customComm, limit, vg, bandit,
- predefConfidences, predefVisibility);
- }
-
- /**
- * Creates a new camera and adds it to the list of cameras all having the same predefined aiNode
- * @param name defines the name of the camera
- * @param x_pos defines the x position in the internal coordinates
- * @param y_pos defines the y position in the internal coordinates
- * @param heading_degrees defines the direction of the viewing point
- * @param angle_degrees defines the width of the viewing angle
- * @param range defines the range (distance) of the camera's view
- * @param comm defines the initial/predefined communication strategy
- * @param limit sets limit for amount of objects being tracked (0 = unlimited)
- * @param vg contains the predefined vision graph
- * @param bandit defines the used bandit solver algorithm
- * @param predefConfidences defines a list of objects represented by an ArrayList of
- * their confidences where each element is for one frame/timestep
- * @param predefVisibility defines a list of objects represented by an ArrayList of
- * their visibility (0 = visible, 1 = not visible or at touching border) where each
- * element is for one frame/timestep
- */
- public void add_camera(
- String name,
- double x_pos, double y_pos,
- double heading_degrees,
- double angle_degrees,
- double range,
- int commValue,
- String customComm,
- int limit,
- Map vg,
- String bandit,
- ArrayList> predefConfidences,
- ArrayList> predefVisibility){
-
- checkCoordInRange(x_pos, y_pos);
-
- AbstractAINode aiNode = null;
- try {
- aiNode = newAINodeFromName(ai_alg, staticVG, vg, reg, bandit);
- } catch (Exception e) {
- System.out.println("Couldn't initialise AI Node from name given in scenario file: "+ai_alg);
- System.out.println("Is it a fully qualified class name? e.g. 'epics.ai.ActiveAINodeMulti'");
- e.printStackTrace();
- System.exit(1);
- }
-
- CameraController cc = new CameraController(
- name,
- x_pos, y_pos,
- Math.toRadians(heading_degrees),
- Math.toRadians(angle_degrees),
- range, aiNode, limit, stats, randomGen, predefConfidences, predefVisibility);
-
-
- try {
- Class>[] commConstructorTypes = {AbstractAINode.class, ICameraController.class};
- Class> commClass = getCommClass(commValue, customComm);
- Constructor> cons = commClass.getConstructor(commConstructorTypes);
- _comm = (AbstractCommunication) cons.newInstance(aiNode, cc);
- aiNode.setComm(_comm);
- } catch (Exception e) {
- System.err.println("Failed to create a communication class");
+ public void add_camera(String name, double x_pos, double y_pos, double heading_degrees, double angle_degrees, double range, String ai_algorithm, int commValue, String customComm, int limit, Map vg, String bandit, ArrayList> predefConfidences, ArrayList> predefVisibility) {
+
+ ai_alg = ai_algorithm;
+ add_camera(name, x_pos, y_pos, heading_degrees, angle_degrees, range, commValue, customComm, limit, vg, bandit, predefConfidences, predefVisibility);
+ }
+
+ /**
+ * Creates a new camera and adds it to the list of cameras all having the
+ * same predefined aiNode
+ *
+ * @param name
+ * defines the name of the camera
+ * @param x_pos
+ * defines the x position in the internal coordinates
+ * @param y_pos
+ * defines the y position in the internal coordinates
+ * @param heading_degrees
+ * defines the direction of the viewing point
+ * @param angle_degrees
+ * defines the width of the viewing angle
+ * @param range
+ * defines the range (distance) of the camera's view
+ * @param comm
+ * defines the initial/predefined communication strategy
+ * @param limit
+ * sets limit for amount of objects being tracked (0 = unlimited)
+ * @param vg
+ * contains the predefined vision graph
+ * @param bandit
+ * defines the used bandit solver algorithm
+ * @param predefConfidences
+ * defines a list of objects represented by an ArrayList of their
+ * confidences where each element is for one frame/timestep
+ * @param predefVisibility
+ * defines a list of objects represented by an ArrayList of their
+ * visibility (0 = visible, 1 = not visible or at touching
+ * border) where each element is for one frame/timestep
+ */
+ public void add_camera(String name, double x_pos, double y_pos, double heading_degrees, double angle_degrees, double range, int commValue, String customComm, int limit, Map vg, String bandit, ArrayList> predefConfidences, ArrayList> predefVisibility) {
+
+ checkCoordInRange(x_pos, y_pos);
+
+ AbstractAINode aiNode = null;
+ try {
+ aiNode = newAINodeFromName(ai_alg, staticVG, vg, reg, bandit);
+ } catch (Exception e) {
+ System.out.println("Couldn't initialise AI Node from name given in scenario file: " + ai_alg);
+ System.out.println("Is it a fully qualified class name? e.g. 'epics.ai.ActiveAINodeMulti'");
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ CameraController cc = new CameraController(name, x_pos, y_pos, Math.toRadians(heading_degrees), Math.toRadians(angle_degrees), range, aiNode, limit, stats, randomGen, predefConfidences, predefVisibility);
+
+ try {
+ Class>[] commConstructorTypes = { AbstractAINode.class, ICameraController.class };
+ Class> commClass = getCommClass(commValue, customComm);
+ Constructor> cons = commClass.getConstructor(commConstructorTypes);
+ _comm = (AbstractCommunication) cons.newInstance(aiNode, cc);
+ aiNode.setComm(_comm);
+ } catch (Exception e) {
+ System.err.println("Failed to create a communication class");
e.printStackTrace();
System.exit(1);
}
-
- try {
- if (paramFile != null) {
- this.applyParamsToAINode(aiNode, paramFile);
- }
- } catch (IOException e) {
- System.out.println("Couldn't read ParamFile: " + paramFile);
- e.printStackTrace();
- System.exit(1);
- }
-
- if(USEGLOBAL){
- reg.addCamera(cc);
- }
-
- this.getCameras().add(cc);
- for (CameraController c1 : this.cameras){
- c1.addCamera(cc);
- cc.addCamera(c1);
- }
+
+ try {
+ if (paramFile != null) {
+ this.applyParamsToAINode(aiNode, paramFile);
+ }
+ } catch (IOException e) {
+ System.out.println("Couldn't read ParamFile: " + paramFile);
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ if (USEGLOBAL) {
+ reg.addCamera(cc);
+ }
+
+ this.getCameras().add(cc);
+ for (CameraController c1 : this.cameras) {
+ c1.addCamera(cc);
+ cc.addCamera(c1);
+ }
}
-
- public Class> getCommClass(int commValue, String customComm) throws ClassNotFoundException {
- switch(commValue){
- case 0: return Broadcast.class;
- case 1: return Smooth.class;
- case 2: return Step.class;
- case 4:
- if (customComm == null || customComm.equals("")) {
- throw new IllegalArgumentException("No CustomComm value provided");
- }
- Class> nodeType = Class.forName(customComm);
- return (Class>) nodeType;
- default:
- throw new IllegalArgumentException("Comm value provided is invalid: "+commValue);
-
+
+ public Class> getCommClass(int commValue, String customComm) throws ClassNotFoundException {
+ switch (commValue) {
+ case 0:
+ return Broadcast.class;
+ case 1:
+ return Smooth.class;
+ case 2:
+ return Step.class;
+ case 4:
+ if (customComm == null || customComm.equals("")) {
+ throw new IllegalArgumentException("No CustomComm value provided");
+ }
+ Class> nodeType = Class.forName(customComm);
+ return (Class>) nodeType;
+ default:
+ throw new IllegalArgumentException("Comm value provided is invalid: " + commValue);
+
}
- }
-
- /** Given a node's class name, dynamically loads the class and
- * instantiates a new node of that type using reflection
- * @param fullyQualifiedClassName the class name - has to include package
- * name if not in the same package. eg.: epics.ai.ActiveAINodeMulti
- * @param comm the communication policy: 0 = Broadcast, 1 = Smooth, 2 = step
- * @param staticVG defines if VG is static as predefined or can change dynamically
- * @param vg a predefined VG - may or may not change over time
- * @param r a global registration
- * @param banditS the class name of a bandit solver
- * @return AbstractAINode the created AINode
- * @throws ClassNotFoundException if the class for the AINode or the BanditSolver wasn't found
- */
- public AbstractAINode newAINodeFromName(String fullyQualifiedClassName,
- boolean staticVG, Map vg, IRegistration r, String banditS)
- throws ClassNotFoundException, SecurityException, NoSuchMethodException,
- IllegalArgumentException, InstantiationException, IllegalAccessException,
- InvocationTargetException {
- IBanditSolver bs = null;
- try {
- if(banditS != null){
- if(!banditS.equals("")){
+ }
+
+ /**
+ * Given a node's class name, dynamically loads the class and instantiates a
+ * new node of that type using reflection
+ *
+ * @param fullyQualifiedClassName
+ * the class name - has to include package name if not in the
+ * same package. eg.: epics.ai.ActiveAINodeMulti
+ * @param comm
+ * the communication policy: 0 = Broadcast, 1 = Smooth, 2 = step
+ * @param staticVG
+ * defines if VG is static as predefined or can change
+ * dynamically
+ * @param vg
+ * a predefined VG - may or may not change over time
+ * @param r
+ * a global registration
+ * @param banditS
+ * the class name of a bandit solver
+ * @return AbstractAINode the created AINode
+ * @throws ClassNotFoundException
+ * if the class for the AINode or the BanditSolver wasn't found
+ */
+ public AbstractAINode newAINodeFromName(String fullyQualifiedClassName, boolean staticVG, Map vg, IRegistration r, String banditS) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ IBanditSolver bs = null;
+ try {
+ if (banditS != null) {
+ if (!banditS.equals("")) {
Class> banditType = Class.forName(banditS);
- Class>[] banditConstructorTypes = {int.class, double.class, double.class, int.class, RandomNumberGenerator.class};
+ Class>[] banditConstructorTypes = { int.class, double.class, double.class, int.class, RandomNumberGenerator.class };
Constructor> banditCons = banditType.getConstructor(banditConstructorTypes);
- bs = (IBanditSolver) banditCons.newInstance(6, epsilon, alpha, interval, randomGen);
- }
- }
+ bs = (IBanditSolver) banditCons.newInstance(6, epsilon, alpha, interval, randomGen);
+ }
+ }
} catch (ClassNotFoundException e) {
- if(!banditS.equals(""))
- System.out.println("AAAHHH " + banditS + " not found...");
+ if (!banditS.equals(""))
+ System.out.println("AAAHHH " + banditS + " not found...");
}
-
- Class> nodeType = Class.forName(fullyQualifiedClassName);
- Class>[] constructorTypes = {boolean.class, Map.class, IRegistration.class, RandomNumberGenerator.class, IBanditSolver.class};
- Constructor> cons = nodeType.getConstructor(constructorTypes);
- AbstractAINode node = (AbstractAINode) cons.newInstance(staticVG, vg, r, randomGen, bs);
- return node;
- }
-
- /**
- * Creates an AINode from an existing one using reflection. Clones the contents of the existing node into the new one.
- * @param fullyQualifiedClassName the class name - has to include package name if not in the same package. eg.: epics.ai.ActiveAINodeMulti
- * @param comm the communication policy: 0 = Broadcast, 1 = Smooth, 2 = step
- * @param ai the pre-existing AINode
- * @return a specific implementation of an abstract AINode
- */
- public AbstractAINode newAINodeFromName(String fullyQualifiedClassName,
- AbstractCommunication comm, AbstractAINode ai)
- throws ClassNotFoundException, SecurityException, NoSuchMethodException,
- IllegalArgumentException, InstantiationException, IllegalAccessException,
- InvocationTargetException {
- Class> nodeType = Class.forName(fullyQualifiedClassName);
- Class>[] constructorTypes = {AbstractAINode.class};
- Constructor>[] allCons = nodeType.getDeclaredConstructors();
-
- Constructor> cons = nodeType.getConstructor(constructorTypes);
- AbstractAINode node = (AbstractAINode) cons.newInstance(ai);
- node.setComm(comm);
- return node;
- }
-
- /**
- * Given a file which contains parameters for our run, we run through
- * the params and apply each one to the AI node. This is mainly to aid
- * running of experiments, where the necessary parameters can be applied
- * to the node for a particular run, then the params file is changed for
- * the next run
- * @param node to apply parameters to
- * @param paramsFilepath contains the filepath for the parameterfile
- * @throws IOException in case opening of file fails
- */
- public void applyParamsToAINode(AbstractAINode node, String paramsFilepath) throws IOException {
- RunParams.loadIfNotLoaded(paramsFilepath);
- System.out.println("Setting params for " + node.getName() + "...");
- Set> props = RunParams.getAllProperties();
- for (Entry