void IFitnessFunction.update(SimulatorExperiment engine, Environment environment, instance_pack ip) { if (!(ip.timeSteps % (int)(1 / engine.timestep) == 0)) { //grid.decay_viewed(0); return; } double[] gl = new double[3]; double[] el = new double[3]; double[] sense = new double[3]; int r_ind = 0; if (!first && (ip.timeSteps * engine.timestep) > engine.evaluationTime / 2.0) { allCorrected = true; bool[] close = new bool[3]; // Schrum: Brains don't get switched with preference neurons ... all need to be evaluated if (!ip.agentBrain.preferenceNeurons) { ip.agentBrain.switchBrains(); } foreach (Robot r in ip.robots) { //Schrum: Debugging //Console.WriteLine("Robot id: " + r.id + ", " + r.name); //Console.WriteLine("r.sensors.Count=" + r.sensors.Count); //Console.WriteLine("Last sensor type: " + r.sensors[r.sensors.Count - 1].GetType()); if (!ip.agentBrain.multipleBrains || // Schrum: Original condition (r.sensors[r.sensors.Count - 1] is SignalSensor)) // Schrum: Broader condition that also works with pref neurons { //Schrum: Debugging //Console.WriteLine("Switched signal at " + (ip.timeSteps * engine.timestep)); SignalSensor s = (SignalSensor)r.sensors[r.sensors.Count - 1]; s.setSignal(1.0); } origDist[r_ind] = r.location.distance(environment.goal_point); origHeadings[r_ind] = r.heading; //checks to see if all points have an agent close to them when the signal fires for (int p = 0; p < environment.POIPosition.Count; p++) { if (r.location.manhattenDistance(new Point2D(environment.POIPosition[p].X, environment.POIPosition[p].Y)) < 15) { close[p] = true; } } //checks to see if agents are being corrected (stopped) when the signal fires if (!r.corrected) { allCorrected = false; } r_ind++; } r_ind = 0; first = true; allClose = close[0] && close[1] && close[2]; } foreach (Robot r in ip.robots) { int p_ind = 0; double d2 = r.location.manhattenDistance(environment.goal_point); if (first) { if (!turned[r_ind]) { if (origHeadings[r_ind] != r.heading) { turned[r_ind] = true; } } //if(point.distance(environment.goal_point) <25.0) { // endList[i]=1.5; //} //else { if (d2 <= 20) { el[r_ind] = 1; reachGoal[r_ind] = true; } el[r_ind] = Math.Max(0.0, (origDist[r_ind] - d2) / 167.0); //} } /* * else { * System.Drawing.Point * p=environment.POIPosition[r_ind]; * Point2D point= new * Point2D((double)p.X,(double)p.Y); * double d1=point.distance(r.location); * gl[r_ind]=Math.Max(0.0,(200.0-d1)/200.0); * } */ foreach (System.Drawing.Point p in environment.POIPosition) { Point2D point = new Point2D((double)p.X, (double)p.Y); int i = p_ind; double d1 = point.manhattenDistance(r.location); if (!first) { // Schrum: Magic numbers everywhere! I think robot has reached the POI if within 10 units if (d1 <= 10) { gl[i] = 1; } else { // Otherwise, add (D - d)/D where D = 110 and d = d1 = distance from POI gl[i] = Math.Max(gl[i], (110.0 - d1) / 110.0); } } p_ind += 1; } sense[r_ind] = 1; foreach (ISensor s in r.sensors) { if (s is RangeFinder) { if (s.get_value() < sense[r_ind]) { sense[r_ind] = s.get_value(); } } } r_ind += 1; } for (int i = 0; i < 3; i++) { gotoList[i] += gl[i]; endList[i] += el[i]; sensorList[i] += sense[i]; } return; }
void IFitnessFunction.update(SimulatorExperiment engine, Environment environment, instance_pack ip) { if (!(ip.timeSteps % (int)(1 / engine.timestep) == 0)) { //grid.decay_viewed(0); return; } double[] gl = new double[3]; double[] el = new double[3]; double[] sense = new double[3]; int r_ind = 0; if (!first && (ip.timeSteps * engine.timestep) > engine.evaluationTime / 2.0) { allCorrected = true; bool[] close = new bool[3]; ip.agentBrain.switchBrains(); foreach (Robot r in ip.robots) { if (!ip.agentBrain.multipleBrains) { SignalSensor s = (SignalSensor)r.sensors[r.sensors.Count - 1]; s.setSignal(1.0); } origDist[r_ind] = r.location.distance(environment.goal_point); origHeadings[r_ind] = r.heading; //checks to see if all points have an agent close to them when the signal fires for (int p = 0; p < environment.POIPosition.Count; p++) if (r.location.manhattenDistance(new Point2D(environment.POIPosition[p].X, environment.POIPosition[p].Y)) < 15) close[p] = true; //checks to see if agents are being corrected (stopped) when the signal fires if (!r.corrected) allCorrected = false; r_ind++; } r_ind = 0; first = true; allClose = close[0] && close[1] && close[2]; } foreach (Robot r in ip.robots) { int p_ind = 0; double d2 = r.location.manhattenDistance(environment.goal_point); if (first) { if (!turned[r_ind]) if (origHeadings[r_ind] != r.heading) turned[r_ind] = true; //if(point.distance(environment.goal_point) <25.0) { // endList[i]=1.5; //} //else { if (d2 <= 20) { el[r_ind] = 1; reachGoal[r_ind]=true; } el[r_ind] = Math.Max(0.0, (origDist[r_ind] - d2) / 167.0); //} } /* else { System.Drawing.Point p=environment.POIPosition[r_ind]; Point2D point= new Point2D((double)p.X,(double)p.Y); double d1=point.distance(r.location); gl[r_ind]=Math.Max(0.0,(200.0-d1)/200.0); } */ foreach (System.Drawing.Point p in environment.POIPosition) { Point2D point = new Point2D((double)p.X, (double)p.Y); int i = p_ind; double d1 = point.manhattenDistance(r.location); if (!first) { if (d1 <= 10) gl[i] = 1; else gl[i] = Math.Max(gl[i], (110.0 - d1) / 110.0); } p_ind += 1; } sense[r_ind] = 1; foreach (ISensor s in r.sensors) { if (s is RangeFinder) if (s.get_value() < sense[r_ind]) sense[r_ind] = s.get_value(); } r_ind += 1; } for (int i = 0; i < 3; i++) { gotoList[i] += gl[i]; endList[i] += el[i]; sensorList[i] += sense[i]; } return; }
void IFitnessFunction.update(SimulatorExperiment engine, Environment environment, instance_pack ip) { if (!(ip.timeSteps % (int)(1 / engine.timestep) == 0)) { //grid.decay_viewed(0); return; } double[] gl = new double[3]; double[] el = new double[3]; double[] sense = new double[3]; int r_ind = 0; if (!first && (ip.timeSteps * engine.timestep) > engine.evaluationTime / 2.0) { allCorrected = true; bool[] close = new bool[3]; // Schrum: Brains don't get switched with preference neurons ... all need to be evaluated // Schrum: Checking that numBrains == 2 assures that this mode of switching does not occur in FourTask experiments with 5 brains if (!ip.agentBrain.preferenceNeurons && engine.numBrains == 2) ip.agentBrain.switchBrains(); foreach (Robot r in ip.robots) { //Schrum: Debugging //Console.WriteLine("Robot id: " + r.id + ", " + r.name); //Console.WriteLine("r.sensors.Count=" + r.sensors.Count); //Console.WriteLine("Last sensor type: " + r.sensors[r.sensors.Count - 1].GetType()); if (!ip.agentBrain.multipleBrains || // Schrum: Original condition (r.sensors[r.sensors.Count - 1] is SignalSensor)) // Schrum: Broader condition that also works with pref neurons { //Schrum: Debugging //Console.WriteLine("Switched signal at " + (ip.timeSteps * engine.timestep)); SignalSensor s = (SignalSensor)r.sensors[r.sensors.Count - 1]; s.setSignal(1.0); } origDist[r_ind] = r.location.distance(environment.goal_point); origHeadings[r_ind] = r.heading; //checks to see if all points have an agent close to them when the signal fires for (int p = 0; p < environment.POIPosition.Count; p++) if (r.location.manhattenDistance(new Point2D(environment.POIPosition[p].X, environment.POIPosition[p].Y)) < 15) close[p] = true; //checks to see if agents are being corrected (stopped) when the signal fires if (!r.corrected) allCorrected = false; r_ind++; } r_ind = 0; first = true; allClose = close[0] && close[1] && close[2]; } foreach (Robot r in ip.robots) { int p_ind = 0; double d2 = r.location.manhattenDistance(environment.goal_point); if (first) { if (!turned[r_ind]) if (origHeadings[r_ind] != r.heading) turned[r_ind] = true; //if(point.distance(environment.goal_point) <25.0) { // endList[i]=1.5; //} //else { if (d2 <= 20) { el[r_ind] = 1; reachGoal[r_ind]=true; } el[r_ind] = Math.Max(0.0, (origDist[r_ind] - d2) / 167.0); //} } /* else { System.Drawing.Point p=environment.POIPosition[r_ind]; Point2D point= new Point2D((double)p.X,(double)p.Y); double d1=point.distance(r.location); gl[r_ind]=Math.Max(0.0,(200.0-d1)/200.0); } */ foreach (System.Drawing.Point p in environment.POIPosition) { Point2D point = new Point2D((double)p.X, (double)p.Y); int i = p_ind; double d1 = point.manhattenDistance(r.location); if (!first) { // Schrum: Magic numbers everywhere! I think robot has reached the POI if within 10 units if (d1 <= 10) gl[i] = 1; else // Otherwise, add (D - d)/D where D = 110 and d = d1 = distance from POI gl[i] = Math.Max(gl[i], (110.0 - d1) / 110.0); } p_ind += 1; } sense[r_ind] = 1; foreach (ISensor s in r.sensors) { if (s is RangeFinder) if (s.get_value() < sense[r_ind]) sense[r_ind] = s.get_value(); } r_ind += 1; } for (int i = 0; i < 3; i++) { gotoList[i] += gl[i]; endList[i] += el[i]; sensorList[i] += sense[i]; } return; }
void IFitnessFunction.update(SimulatorExperiment engine, Environment environment, instance_pack ip) { if (!(ip.timeSteps % (int)(1 / engine.timestep) == 0)) { //grid.decay_viewed(0); return; } double[] gl = new double[3]; double[] el = new double[3]; double[] sense = new double[3]; int r_ind = 0; if (!first && (ip.timeSteps * engine.timestep) > engine.evaluationTime / 2.0) { allCorrected = true; bool[] close = new bool[3]; ip.agentBrain.switchBrains(); foreach (Robot r in ip.robots) { if (!ip.agentBrain.multipleBrains) { SignalSensor s = (SignalSensor)r.sensors[r.sensors.Count - 1]; s.setSignal(1.0); } origDist[r_ind] = r.location.distance(environment.goal_point); origHeadings[r_ind] = r.heading; //checks to see if all points have an agent close to them when the signal fires for (int p = 0; p < environment.POIPosition.Count; p++) { if (r.location.manhattenDistance(new Point2D(environment.POIPosition[p].X, environment.POIPosition[p].Y)) < 15) { close[p] = true; } } //checks to see if agents are being corrected (stopped) when the signal fires if (!r.corrected) { allCorrected = false; } r_ind++; } r_ind = 0; first = true; allClose = close[0] && close[1] && close[2]; } foreach (Robot r in ip.robots) { int p_ind = 0; double d2 = r.location.manhattenDistance(environment.goal_point); if (first) { if (!turned[r_ind]) { if (origHeadings[r_ind] != r.heading) { turned[r_ind] = true; } } //if(point.distance(environment.goal_point) <25.0) { // endList[i]=1.5; //} //else { if (d2 <= 20) { el[r_ind] = 1; reachGoal[r_ind] = true; } el[r_ind] = Math.Max(0.0, (origDist[r_ind] - d2) / 167.0); //} } /* * else { * System.Drawing.Point * p=environment.POIPosition[r_ind]; * Point2D point= new * Point2D((double)p.X,(double)p.Y); * double d1=point.distance(r.location); * gl[r_ind]=Math.Max(0.0,(200.0-d1)/200.0); * } */ foreach (System.Drawing.Point p in environment.POIPosition) { Point2D point = new Point2D((double)p.X, (double)p.Y); int i = p_ind; double d1 = point.manhattenDistance(r.location); if (!first) { if (d1 <= 10) { gl[i] = 1; } else { gl[i] = Math.Max(gl[i], (110.0 - d1) / 110.0); } } p_ind += 1; } sense[r_ind] = 1; foreach (ISensor s in r.sensors) { if (s is RangeFinder) { if (s.get_value() < sense[r_ind]) { sense[r_ind] = s.get_value(); } } } r_ind += 1; } for (int i = 0; i < 3; i++) { gotoList[i] += gl[i]; endList[i] += el[i]; sensorList[i] += sense[i]; } return; }