protected void setupVariables()
        {
            robots = new List <Robot>();
            substrateDescription           = new SubstrateDescription(substrateDescriptionFilename);
            GenomeVisualizerForm.substrate = substrateDescription;

            agentBrain = new AgentBrain(homogeneousTeam, numberRobots, substrateDescription, genome != null ? genome.Decode(null) : null, normalizeWeights, adaptableANN, modulatoryANN, multibrain, evolveSubstrate);

            //if(homogeneousTeam)
            //Console.WriteLine("inc:"+agentBrain.getBrain(0).InputNeuronCount);

            loadEnvironments(this);

            //agentsCollide=environment.agentsCollide;
            //agentsVisible=environment.agentsVisible;

            //Substrate sensor density
            initializeRobots(agentBrain, environment, headingNoise, sensorNoise, effectorNoise, null);

            setFitnessFunction(fitnessFunctionName);
            setBehavioralCharacterization(behaviorCharacterizationName);


            if (gridCollision)
            {
                collisionManager = new GridCollision();
            }
            else
            {
                collisionManager = new StandardCollision();
            }
            collisionManager.Initialize(environment, this, this.robots);
            timeSteps = 0;
            elapsed   = 0;
        }
예제 #2
0
        public void init(int id, double nx, double ny, double dir,
                         AgentBrain agentBrain, Environment environment,
                         float sensorNoise, float effectorNoise, float headingNoise, float timeStep)
        {
            steps = 0;

            this.id      = id;
            radius       = defaultRobotSize();
            location     = new Point2D(nx, ny);
            circle       = new Circle2D(location, radius);
            old_location = new Point2D(location);

            heading            = dir;
            velocity           = 0.0;
            collide_last       = false;
            this.timeStep      = timeStep;
            this.environment   = environment;
            this.agentBrain    = agentBrain;
            this.sensorNoise   = sensorNoise;
            this.effectorNoise = effectorNoise;
            this.headingNoise  = headingNoise;
            populateSensors();
            if (environment.seed != -1)
            {
                rng = environment.rng; //new SharpNeatLib.Maths.FastRandom(environment.seed); //Utilities.random;
            }
            else
            {
                rng = environment.rng;               //new SharpNeatLib.Maths.FastRandom();
            }
        }
예제 #3
0
          public void init(int id, double nx, double ny, double dir, 
            AgentBrain agentBrain, Environment environment,
            float sensorNoise, float effectorNoise, float headingNoise, float timeStep)
        {
            steps = 0;

            this.id = id;
    	    radius = defaultRobotSize();
            location = new Point2D(nx, ny);
            circle = new Circle2D(location, radius);
            old_location = new Point2D(location);
           
            heading = dir;
            velocity = 0.0;
            collide_last = false;
            this.timeStep = timeStep;
            this.environment = environment;
            this.agentBrain = agentBrain;
            this.sensorNoise = sensorNoise;
            this.effectorNoise = effectorNoise;
            this.headingNoise = headingNoise;
            populateSensors();
			if(environment.seed != -1) 
            	rng=environment.rng; //new SharpNeatLib.Maths.FastRandom(environment.seed); //Utilities.random;
        	else
				rng=environment.rng; //new SharpNeatLib.Maths.FastRandom();
		}
        protected void setupVariables()
        {
            //Console.WriteLine("setupVariables");
            robots = new List <Robot>();
            // Schrum: more special handling: Don't want to overwrite substrate in visual mode
            if (!(fitnessFunction is FourTasksFitness))
            {
                substrateDescription = new SubstrateDescription(substrateDescriptionFilename);
            }

            agentBrain = new AgentBrain(homogeneousTeam, numberRobots, substrateDescription, genome != null ? genome.Decode(null) : null, normalizeWeights, adaptableANN, modulatoryANN, multibrain, numBrains, evolveSubstrate, preferenceNeurons, forcedSituationalPolicyGeometry);

            //if(homogeneousTeam)
            //Console.WriteLine("inc:"+agentBrain.getBrain(0).InputNeuronCount);

            loadEnvironments(this);

            //agentsCollide=environment.agentsCollide;
            //agentsVisible=environment.agentsVisible;

            //Substrate sensor density
            initializeRobots(agentBrain, environment, headingNoise, sensorNoise, effectorNoise, null);

            // Schrum: more special handling: Don't want to overwrite fitness function in visual mode
            if (!(fitnessFunction is FourTasksFitness))
            {
                setFitnessFunction(fitnessFunctionName);
            }
            else // sufficient if FourTasks is already loaded
            {
                //Console.WriteLine("setupVariables: environmentName = " + environmentName);
                ((FourTasksFitness)fitnessFunction).setExperiment(this);
                fitnessFunction.reset();
                ((FourTasksFitness)fitnessFunction).setupFitness(FourTasksFitness.environmentID(environmentName));
            }
            setBehavioralCharacterization(behaviorCharacterizationName);


            if (gridCollision)
            {
                collisionManager = new GridCollision();
            }
            else
            {
                collisionManager = new StandardCollision();
            }
            collisionManager.Initialize(environment, this, this.robots);
            timeSteps = 0;
            elapsed   = 0;
        }
 public virtual void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack x) { }
 public virtual void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack x)
 {
 }
        //TODO this could be put into a Formation class or something that takes an environment as input
        public override void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack ip)
        {
            int num_bots;
            //Set up robots.
            //set up deltas for spacing the robots
            double dx, dy;

            if (overrideTeamFormation)
            {
                dx = Math.Cos(group_orientation / 180.0 * 3.14) * group_spacing;
                dy = Math.Sin(group_orientation / 180.0 * 3.14) * group_spacing;
            }
            else
            {
                dx = Math.Cos(e.group_orientation / 180.0 * 3.14) * e.robot_spacing;
                dy = Math.Sin(e.group_orientation / 180.0 * 3.14) * e.robot_spacing;
            }


            //record z-stack coordinates
            //float zstack = -1.0f;
            //float zdelta = 2.0f / (numberRobots - 1);
            AgentBrain   ab;
            List <Robot> rbts;
            double       _timestep = 0.0;

            if (ip == null)
            {
                ab        = agentBrain;
                rbts      = robots;
                num_bots  = numberRobots;
                _timestep = this.timestep;
            }
            else
            {
                ab        = ip.agentBrain;
                rbts      = new List <Robot>();
                ip.robots = rbts;
                num_bots  = ip.num_rbts;
                _timestep = ip.timestep;
            }

            rbts.Clear();

            int heading = overrideTeamFormation ? robot_heading : e.robot_heading;

            //add robots in their formation according to environment
            double nx, ny;

            for (int num = 0; num < num_bots; num++)
            {
                Robot r = RobotModelFactory.getRobotModel(robotModelName);
                r.rangefinderDensity = this.rangefinderSensorDensity;

                //TODO: Make a variable that controls this

                /*if (e.POIPosition.Count >= numberRobots)
                 * {
                 *  nx = e.POIPosition[num].X;
                 *  ny = e.POIPosition[num].Y;
                 * }
                 * else*/
                {
                    nx = e.start_point.x + num * dx;
                    ny = e.start_point.y + num * dy;
                }
                r.init(num, nx, ny,
                       heading / 180.0 * 3.14, ab, e, sensorNoise, effectorNoise, headingNoise, (float)_timestep);

                r.collisionPenalty = collisionPenalty;
                ab.registerRobot(r);

                //if (overrideDefaultSensorDensity)
                //    r.populateSensors(rangefinderSensorDensity);
                //else
                r.populateSensors();  //TODO populate sensors gets called multiple times. also in robot contructor

                if (agentBrain.zcoordinates == null)
                {
                    r.zstack = 0;
                }
                else
                {
                    r.zstack = ab.zcoordinates[num];
                }
                //zstack;
                rbts.Add(r);

                //zstack += zdelta;
            }

            uint count = 0;

            foreach (ISensor sensor in robots[0].sensors)
            {
                if (sensor is RangeFinder)
                {
                    count++;
                }
            }

            //Console.WriteLine("Range finder count : " + count);
            //By convention the rangefinders are in layer zero so scale that layer
            // Schrum: HOWEVER, if there are no rangefinders, then we do not want to do this.
            // Schrum: Also disabled this when in the FourTasks domain, since it seems to cause problems.
            if (count != 0 && !(this.fitnessFunction is FourTasksFitness))
            { // don't rescale rangefinders if there are none.
                substrateDescription.setNeuronDensity(0, count, 1);
            }
            ab.updateInputDensity();
        }
        protected void setupVariables()
        {
            robots = new List<Robot>();
            substrateDescription = new SubstrateDescription(substrateDescriptionFilename);

            agentBrain = new AgentBrain(homogeneousTeam, numberRobots, substrateDescription, genome != null ? genome.Decode(null) : null, normalizeWeights, adaptableANN, modulatoryANN, multibrain, evolveSubstrate, dirComm);

            //if(homogeneousTeam)
            //Console.WriteLine("inc:"+agentBrain.getBrain(0).InputNeuronCount);

            loadEnvironments(this);

            //agentsCollide=environment.agentsCollide;
            //agentsVisible=environment.agentsVisible;

            //Substrate sensor density
            initializeRobots(agentBrain, environment, headingNoise, sensorNoise, effectorNoise, null);

            setFitnessFunction(fitnessFunctionName);
            setBehavioralCharacterization(behaviorCharacterizationName);

            if (gridCollision)
                collisionManager = new GridCollision();
            else
                collisionManager = new StandardCollision();
            collisionManager.Initialize(environment, this, this.robots);
            timeSteps = 0;
            elapsed = 0;

            if (initialized)
                foreach (Prey p in environment.preys)
                {
                    p.reset();
                }
            preyCaught = 0;
        }
        //TODO this could be put into a Formation class or something that takes an environment as input
        public override void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack ip)
        {
            int num_bots;
            //Set up robots.
            //set up deltas for spacing the robots
            double dx, dy;
            if (overrideTeamFormation)
            {
                dx = Math.Cos(group_orientation / 180.0 * 3.14) * group_spacing;
                dy = Math.Sin(group_orientation / 180.0 * 3.14) * group_spacing;
            }
            else
            {
                dx = Math.Cos(e.group_orientation / 180.0 * 3.14) * e.robot_spacing;
                dy = Math.Sin(e.group_orientation / 180.0 * 3.14) * e.robot_spacing;
            }

            //record z-stack coordinates
            //float zstack = -1.0f;
            //float zdelta = 2.0f / (numberRobots - 1);
            AgentBrain ab;
            List<Robot> rbts;
            double _timestep=0.0;
            if (ip == null)
            {
                ab = agentBrain;
                rbts = robots;
                num_bots = numberRobots;
                _timestep = this.timestep;
            }
            else
            {
                ab = ip.agentBrain;
                rbts = new List<Robot>();
                ip.robots = rbts;
                num_bots = ip.num_rbts;
                _timestep=ip.timestep;
            }

            rbts.Clear();

            int heading = overrideTeamFormation ? robot_heading : e.robot_heading;

            //add robots in their formation according to environment
            double nx, ny;
            for (int num = 0; num < num_bots; num++)
            {
                Robot r = RobotModelFactory.getRobotModel(robotModelName);
                r.rangefinderDensity = this.rangefinderSensorDensity;

                //TODO: Make a variable that controls this
                /*if (e.POIPosition.Count >= numberRobots)
                {
                    nx = e.POIPosition[num].X;
                    ny = e.POIPosition[num].Y;
                }
                else*/
                {
                    nx = e.start_point.x + num * dx;
                    ny = e.start_point.y + num * dy;
                }
                r.init(num, nx, ny,
                    heading / 180.0 * 3.14, ab, e, sensorNoise, effectorNoise, headingNoise, (float)_timestep);

                r.collisionPenalty = collisionPenalty;
                ab.registerRobot(r);

                //if (overrideDefaultSensorDensity)
                //    r.populateSensors(rangefinderSensorDensity);
                //else
                    r.populateSensors();  //TODO populate sensors gets called times. also in robot contructor

                if (agentBrain.zcoordinates == null) r.zstack = 0;
                else
                    r.zstack = ab.zcoordinates[num];
                //zstack;

                if (r is ModularRobot)
                {
                    if (num == 1)
                    {
                        ModularRobot firstBot = (ModularRobot)rbts[0];
                        firstBot.initFirstBot((ModularRobot)r, e.robot_spacing);
                        rbts[0] = firstBot;
                    }
                    if (num != 0)
                    {
                        ModularRobot bot = (ModularRobot)r;
                        bot.initBot((ModularRobot)rbts[num - 1], e.robot_spacing);
                        r = bot;
                    }
                }

                rbts.Add(r);

                //zstack += zdelta;
            }

            uint count = 0;
            foreach (ISensor sensor in robots[0].sensors)
            {
                if (sensor is RangeFinder || sensor is PreySensor || sensor is TimeSensor)
                {
                    count++;
                }
            }

            //By convention the rangefinders are in layer zero so scale that layer
            substrateDescription.setNeuronDensity(0, count, 1);

            ab.updateInputDensity();
        }
        // Schrum2: Add extra enemy robot after deault robots
        public override void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack ip)
        {
            // Debug:schrum2
            //Console.WriteLine("Init Robots");
            base.initializeRobots(agentBrain, e, headingNoise, sensorNoise, effectorNoise, ip);
            enemies = new List <EnemyRobot>();
            for (int i = 0; i < numEnemies; i++)
            {
                // schrum2: here is where the enemy robot is added
                // Location of evolved robot is needed to track it
                // Assumes that robot is in position 0 (problem?)
                EnemyRobot r = new EnemyRobot(robots[0], flee);
                enemies.Add(r);

                double _timestep = 0.0;
                if (ip == null)
                {
                    _timestep = this.timestep;
                }
                else
                {
                    _timestep = ip.timestep;
                }

                double nx = enemyX - i * enemyDeltaX;
                double ny = enemyY - i * enemyDeltaY;
                double h  = 0;

                // Alternative starting positions for enemies
                if (enemiesSurround)
                {
                    double evolvedX = robots[0].location.x;
                    double evolvedY = robots[0].location.y;

                    double radius = 200.0;

                    nx = evolvedX + radius * Math.Cos((i * 2.0 * Math.PI) / numEnemies);
                    ny = evolvedY + radius * Math.Sin((i * 2.0 * Math.PI) / numEnemies);
                    h  = Math.PI + i * (2 * Math.PI / numEnemies);
                }

                r.init(robots.Count, // id is last position in list of robots
                       nx, ny, h,    // starting position and heading
                       agentBrain,   // Has evolved brain (to avoid NullPointers, etc), but should never actually use it (problem?)
                       e, sensorNoise, effectorNoise, headingNoise, (float)_timestep);

                r.collisionPenalty = collisionPenalty;
                // Only add enemy if it is not already present
                if (robots.Count <= numEnemies) // Makes limiting assumption that this experiment will always be used with only one evolved bot and one enemy
                {
                    robots.Add(r);
                    //Console.WriteLine("Added enemy to list: " + robots.Count);
                }

                // Required so that experiment works properly in both visual and non-visual mode
                // (The non-visual mode takes the robots from the instance_pack instead of the experiment)
                if (ip != null && ip.robots.Count <= numEnemies)
                {
                    ip.robots.Add(r);
                    //Console.WriteLine("Added enemy to ip");
                }
            }
        }
        // Schrum2: Add extra enemy robot after deault robots
        public override void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack ip)
        {
            // Debug:schrum2
            //Console.WriteLine("Init Robots");
            base.initializeRobots(agentBrain, e, headingNoise, sensorNoise, effectorNoise, ip);
            enemies = new List<EnemyRobot>();
            for (int i = 0; i < numEnemies; i++)
            {

                // schrum2: here is where the enemy robot is added
                // Location of evolved robot is needed to track it
                // Assumes that robot is in position 0 (problem?)
                EnemyRobot r = new EnemyRobot(robots[0], flee);
                enemies.Add(r);

                double _timestep = 0.0;
                if (ip == null)
                {
                    _timestep = this.timestep;
                }
                else
                {
                    _timestep = ip.timestep;
                }

                double nx = enemyX - i * enemyDeltaX;
                double ny = enemyY - i * enemyDeltaY;
                double h = 0;

                // Alternative starting positions for enemies
                if (enemiesSurround)
                {
                    double evolvedX = robots[0].location.x;
                    double evolvedY = robots[0].location.y;

                    double radius = 200.0;

                    nx = evolvedX + radius*Math.Cos((i * 2.0 * Math.PI) / numEnemies);
                    ny = evolvedY + radius*Math.Sin((i * 2.0 * Math.PI) / numEnemies);
                    h = Math.PI + i * (2 * Math.PI / numEnemies);
                }

                r.init(robots.Count, // id is last position in list of robots
                    nx, ny, h, // starting position and heading
                    agentBrain, // Has evolved brain (to avoid NullPointers, etc), but should never actually use it (problem?) 
                    e, sensorNoise, effectorNoise, headingNoise, (float)_timestep);

                r.collisionPenalty = collisionPenalty;
                // Only add enemy if it is not already present
                if (robots.Count <= numEnemies) // Makes limiting assumption that this experiment will always be used with only one evolved bot and one enemy
                {
                    robots.Add(r);
                    //Console.WriteLine("Added enemy to list: " + robots.Count);
                }

                // Required so that experiment works properly in both visual and non-visual mode
                // (The non-visual mode takes the robots from the instance_pack instead of the experiment)
                if (ip != null && ip.robots.Count <= numEnemies)
                {
                    ip.robots.Add(r);
                    //Console.WriteLine("Added enemy to ip");
                }
            }
        }