Esempio n. 1
0
        /// <summary>
        /// Initialize the robot.
        /// </summary>
        public void init(int id, double locationX, double locationY, double heading, AgentBrain agentBrain, Environment environment, float sensorNoise, float effectorNoise, float headingNoise, float timeStep)
        {
            this.ID      = id;
            Radius       = defaultRobotSize();
            Location     = new Point2D(locationX, locationY);
            AreaOfImpact = new Circle2D(Location, Radius);
            OldLocation  = new Point2D(Location);

            Heading                 = heading;
            Velocity                = 0.0;
            HasCollided             = false;
            this.Timestep           = timeStep;
            this.CurrentEnvironment = environment;
            this.Brain              = agentBrain;
            this.SensorNoise        = sensorNoise;
            this.EffectorNoise      = effectorNoise;
            this.HeadingNoise       = headingNoise;
            populateSensors();
            if (environment.seed != -1)
            {
                rng = environment.rng;
            }
            else
            {
                rng = environment.rng;
            }
            this.Trajectory = new List <int>();
        }
        /// <summary>
        /// Performs the actual initialization logic.
        /// </summary>
        protected void setupVariables()
        {
            substrateDescription = new SubstrateDescription(substrateDescriptionFilename);
            agentBrain           = new AgentBrain(homogeneousTeam, numberRobots, substrateDescription, genome != null ? genome.Decode(null) : null, normalizeWeights, adaptableANN, modulatoryANN, multibrain, evolveSubstrate, neatBrain, useCTRNNS);

            loadEnvironments(this);

            initializeRobots(agentBrain, environment, headingNoise, sensorNoise, effectorNoise, null);

            setFitnessFunction(fitnessFunctionName);
            setBehavioralCharacterization(behaviorCharacterizationName);

            collisionManager = new StandardCollision();

            collisionManager.initialize(environment, this, this.robots);
            timeSteps   = 0;
            elapsedTime = 0;
        }
 public virtual void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack x) { }
        /// <summary>
        /// Initializes robot brains and positions them in the CurrentEnvironment.
        /// </summary>
        public override void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack ip)
        {
            double spacing = 0;
            int    num_bots;
            double dx, dy; // Deltas for spacing the robots

            if (overrideTeamFormation)
            {
                dx      = Math.Cos(group_orientation / 180.0 * 3.14) * group_spacing;
                dy      = Math.Sin(group_orientation / 180.0 * 3.14) * group_spacing;
                spacing = 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;
                spacing = e.robot_spacing;
            }

            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();

            bool circle    = false;
            bool staggered = true;

            double radius     = (spacing) / (2.0 * Math.PI * (1.0 / num_bots));
            double angleDelta = (2 * Math.PI) / num_bots;

            // Add robots in their formation according to CurrentEnvironment
            double nx, ny;

            for (int num = 0; num < num_bots; num++)
            {
                double heading = overrideTeamFormation ? robot_heading : e.robot_heading;
                Robot  r;
                if (robotValues != null && robotValues.Count > 0 && robotValues.Count >= num)
                {
                    r = RobotModelFactory.getRobotModel(robotValues[num]);
                }
                else
                {
                    r = RobotModelFactory.getRobotModel(robotModelName);
                }

                if (circle)
                {
                    nx      = e.start_point.X + radius * Math.Cos(num * angleDelta);
                    ny      = e.start_point.Y + radius * Math.Sin(num * angleDelta);
                    heading = num * angleDelta - Math.PI;
                }
                else
                {
                    if (staggered && num % 2 == 1 && e.stagger != 0)
                    {
                        nx = e.start_point.X + num * dx + (staggered ? e.stagger * num : 0);
                    }
                    else
                    {
                        nx = e.start_point.X + num * dx - (staggered ? e.stagger * num : 0);
                    }
                    ny      = e.start_point.Y + num * dy;
                    heading = (heading / 180.0) * 3.14;
                }

                r.init(num, nx, ny,
                       heading, ab, e, sensorNoise, effectorNoise, headingNoise, (float)_timestep);
                r.CollisionPenalty = collisionPenalty;
                ab.registerRobot(r);

                if (overrideDefaultSensorDensity)
                {
                    r.populateSensors(sensorDensity);
                }
                else
                {
                    r.populateSensors();
                }
                if (agentBrain.ZCoordinates == null)
                {
                    r.ZStack = 0;
                }
                else
                {
                    r.ZStack = ab.ZCoordinates[num];
                }
                rbts.Add(r);
            }

            ab.updateInputDensity();
        }
Esempio n. 5
0
        /// <summary>
        /// Initialize the robot.
        /// </summary>
        public void init(int id, double locationX, double locationY, double heading, AgentBrain agentBrain, Environment environment, float sensorNoise, float effectorNoise, float headingNoise, float timeStep)
        {
            this.ID = id;
            Radius = defaultRobotSize();
            Location = new Point2D(locationX, locationY);
            AreaOfImpact = new Circle2D(Location, Radius);
            OldLocation = new Point2D(Location);

            Heading = heading;
            Velocity = 0.0;
            HasCollided = false;
            this.Timestep = timeStep;
            this.CurrentEnvironment = environment;
            this.Brain = agentBrain;
            this.SensorNoise = sensorNoise;
            this.EffectorNoise = effectorNoise;
            this.HeadingNoise = headingNoise;
            populateSensors();
            if (environment.seed != -1)
                rng = environment.rng;
            else
                rng = environment.rng;
            this.Trajectory = new List<int>();
        }
        /// <summary>
        /// Initializes robot brains and positions them in the CurrentEnvironment.
        /// </summary>
        public override void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack ip)
        {
            double spacing = 0;
            int num_bots;
            double dx, dy; // Deltas for spacing the robots
            if (overrideTeamFormation)
            {
                dx = Math.Cos(group_orientation / 180.0 * 3.14) * group_spacing;
                dy = Math.Sin(group_orientation / 180.0 * 3.14) * group_spacing;
                spacing = 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;
                spacing = e.robot_spacing;
            }

            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();

            bool circle = false;
            bool staggered = true;

            double radius = (spacing) / (2.0 * Math.PI * (1.0 / num_bots));
            double angleDelta = (2 * Math.PI) / num_bots;

            // Add robots in their formation according to CurrentEnvironment
            double nx, ny;
            for (int num = 0; num < num_bots; num++)
            {

                double heading = overrideTeamFormation ? robot_heading : e.robot_heading;
                Robot r;
                if (robotValues != null && robotValues.Count > 0 && robotValues.Count >= num)
                {
                    r = RobotModelFactory.getRobotModel(robotValues[num]);
                }
                else
                    r = RobotModelFactory.getRobotModel(robotModelName);

                if (circle)
                {
                    nx = e.start_point.X + radius * Math.Cos(num * angleDelta);
                    ny = e.start_point.Y + radius * Math.Sin(num * angleDelta);
                    heading = num * angleDelta - Math.PI;
                }
                else
                {
                    if (staggered && num % 2 == 1 && e.stagger != 0)
                        nx = e.start_point.X + num * dx + (staggered ? e.stagger * num : 0);
                    else
                        nx = e.start_point.X + num * dx - (staggered ? e.stagger * num : 0);
                    ny = e.start_point.Y + num * dy;
                    heading = (heading / 180.0) * 3.14;
                }

                r.init(num, nx, ny,
                    heading, ab, e, sensorNoise, effectorNoise, headingNoise, (float)_timestep);
                r.CollisionPenalty = collisionPenalty;
                ab.registerRobot(r);

                if (overrideDefaultSensorDensity)
                    r.populateSensors(sensorDensity);
                else
                    r.populateSensors();
                if (agentBrain.ZCoordinates == null) r.ZStack = 0;
                else
                    r.ZStack = ab.ZCoordinates[num];
                rbts.Add(r);
            }

            ab.updateInputDensity();
        }
        /// <summary>
        /// Performs the actual initialization logic. 
        /// </summary>
        protected void setupVariables()
        {
            substrateDescription = new SubstrateDescription(substrateDescriptionFilename);
            agentBrain = new AgentBrain(homogeneousTeam, numberRobots, substrateDescription, genome != null ? genome.Decode(null) : null, normalizeWeights, adaptableANN, modulatoryANN, multibrain, evolveSubstrate, neatBrain, useCTRNNS);

            loadEnvironments(this);

            initializeRobots(agentBrain, environment, headingNoise, sensorNoise, effectorNoise, null);

            setFitnessFunction(fitnessFunctionName);
            setBehavioralCharacterization(behaviorCharacterizationName);

            collisionManager = new StandardCollision();

            collisionManager.initialize(environment, this, this.robots);
            timeSteps = 0;
            elapsedTime = 0;
        }
 public virtual void initializeRobots(AgentBrain agentBrain, Environment e, float headingNoise, float sensorNoise, float effectorNoise, instance_pack x)
 {
 }