示例#1
0
        void IFitnessFunction.update(SimulatorExperiment Experiment, Environment environment, instance_pack ip)
        {
            if (!(ip.timeSteps % (int)(1 / ip.timestep) == 0))
            {
                //grid.decay_viewed(0);
                return;
            }
            bool   all_in   = true;
            double a_accum  = 0.00000001;
            double a_saccum = 0.00000001;

            foreach (Robot r in ip.robots)
            {
                if (!r.autopilot)
                {
                    foreach (ISensor s in r.sensors)
                    {
                        if (s is SignalSensor)
                        {
                            SignalSensor ss  = (SignalSensor)s;
                            double       val = ss.get_value();
                            val += 0.05;
                            if (val > 1.0)
                            {
                                val = 1.0;
                            }
                            ss.setSignal(val);
                        }
                    }
                }

                if ((environment.AOIRectangle.Contains((int)r.location.x, (int)r.location.y)))
                {
                    a_accum += 1.0 / (nearest(ip, r, environment));
                    if (r.corrected)
                    {
                        a_saccum += nearest(ip, r, environment);
                    }
                    //else
                    //	a_saccum+=1.0;
                }
                else
                {
                    all_in = false;
                }
            }

            if (all_in)
            {
                accum     += ((double)ip.robots.Count) / (a_accum);
                stopaccum += a_saccum / ((double)ip.robots.Count);
            }
        }
示例#2
0
        void IFitnessFunction.update(SimulatorExperiment Experiment, Environment environment, instance_pack ip)
        {
            grid = ((GridCollision)(ip.collisionManager)).grid;

            if (!(ip.timeSteps % (int)(1 / Experiment.timestep) == 0))
            {
                return;
            }

            int dim = grid.coarseness;

            for (int x = 0; x < dim; x++)
            {
                for (int y = 0; y < dim; y++)
                {
                    int gx = (int)((double)x * grid.gridx) + (int)(grid.gridx / 2.0);
                    int gy = (int)((double)y * grid.gridy) + (int)(grid.gridy / 2.0);
                    if ((environment.AOIRectangle.Contains(gx, gy)))
                    {
                        accum      += grid.grid[x, y].viewed;
                        stop_accum += grid.grid[x, y].viewed2;
                    }
                }
            }

            foreach (Robot r in ip.robots)
            {
                if (!r.autopilot)
                {
                    foreach (ISensor s in r.sensors)
                    {
                        if (s is SignalSensor)
                        {
                            SignalSensor ss  = (SignalSensor)s;
                            double       val = ss.get_value();
                            val += 0.05;
                            if (val > 1.0)
                            {
                                val = 1.0;
                            }
                            ss.setSignal(val);
                        }
                    }
                }
            }


            grid.decay_viewed(0);
            //grid.decay_viewed(.95);
        }
        void IFitnessFunction.update(SimulatorExperiment Experiment, Environment environment, instance_pack ip)
        {
            if (!(Experiment.timeSteps % (int)(1 / Experiment.timestep) == 0))
            {
                //grid.decay_viewed(0);
                return;
            }

            foreach (Robot r in ip.robots)
            {
                if (!r.autopilot)
                {
                    foreach (ISensor s in r.sensors)
                    {
                        if (s is SignalSensor)
                        {
                            SignalSensor ss  = (SignalSensor)s;
                            double       val = ss.get_value();
                            val += 0.05;
                            if (val > 1.0)
                            {
                                val = 1.0;
                            }
                            ss.setSignal(val);
                        }
                    }
                }
            }



            double x1    = (double)environment.AOIRectangle.Left;
            double y1    = (double)environment.AOIRectangle.Top;
            double x2    = (double)environment.AOIRectangle.Right;
            double y2    = (double)environment.AOIRectangle.Bottom;
            int    steps = 10;

            accum += test_interpolation(ip, x1, y1, x2, y1, steps);
            accum += test_interpolation(ip, x2, y1, x2, y2, steps);
            accum += test_interpolation(ip, x2, y2, x2, y1, steps);
            accum += test_interpolation(ip, x2, y1, x1, y1, steps);
        }