コード例 #1
0
        void Start()
        {
            var env = GameObject.FindGameObjectWithTag("AgentEnvironment");

            if (!env)
            {
                return;
            }

            var agentEnvironment = env.GetComponent <AgentEnvironment>();

            if (agentEnvironment)
            {
                m_environment = agentEnvironment;
            }

            m_simulationData         = ScriptableObject.FindObjectOfType <SimulationData>();
            simulationDataText.text += "\n" +
                                       $"Density : {m_simulationData.populationDensity.ToString()} \n " +
                                       $"Infectivity : {m_simulationData.infectivity.ToString()} \n " +
                                       $"Launch Sick nb : {m_simulationData.launchSickNumber.ToString()} \n " +
                                       $"Launch Immuned nb :  {m_simulationData.launchImmunedNumber.ToString()} \n " +
                                       $"Disease duration :  {m_simulationData.diseaseDuration.ToString()} \n " +
                                       $"Death statistic :  {m_simulationData.deathStatistic.ToString()} \n " +
                                       $"Disease transmission distance :  {m_simulationData.diseaseTransmissionDistance.ToString()} \n ";

            m_bastCitizensStatText = currentCitizensStatText.text;
            m_bastMayorStatText    = currentMayorStatText.text;
        }
コード例 #2
0
        //Constructor
        public FlockSystem(int agentCount, bool i3D, AgentEnvironment iAgentEnvironment)
        {
            Agents = new List <FlockAgent>();

            //TO DO check here if you have an environment or not
            if (iAgentEnvironment == null)
            {
                if (i3D)
                {
                    defaultEnv = new AgentEnvironment(Plane.WorldXY, defaultEnvSize, defaultEnvSize, defaultEnvSize);
                    AgentEnvX  = defaultEnv.EnvWidth;
                    AgentEnvY  = defaultEnv.EnvHeight;
                    AgentEnvZ  = defaultEnv.EnvDepth;
                    for (int i = 0; i < agentCount; i++)
                    {
                        FlockAgent agent = new FlockAgent(
                            Util.GetRandomPoint(0.0, AgentEnvX, 0.0, AgentEnvY, 0.0, AgentEnvZ),
                            Util.GetRandomUnitVector() * 4.0,
                            defaultEnv);
                        agent.FlockSystem = this;
                        Agents.Add(agent);
                    }
                }
                else
                {
                    defaultEnv = new AgentEnvironment(Plane.WorldXY, defaultEnvSize, defaultEnvSize, 0);
                    AgentEnvX  = defaultEnv.EnvWidth;
                    AgentEnvY  = defaultEnv.EnvHeight;
                    AgentEnvZ  = defaultEnv.EnvDepth;
                    for (int i = 0; i < agentCount; i++)
                    {
                        FlockAgent agent = new FlockAgent(
                            Util.GetRandomPoint(0.0, AgentEnvX, 0.0, AgentEnvY, 0.0, AgentEnvZ),
                            Util.GetRandomUnitVector() * 4.0,
                            defaultEnv);
                        agent.FlockSystem = this;
                        Agents.Add(agent);
                    }
                }
            }
            else
            {
                defaultEnv = iAgentEnvironment;
                AgentEnvX  = defaultEnv.EnvWidth;
                AgentEnvY  = defaultEnv.EnvHeight;
                AgentEnvZ  = defaultEnv.EnvDepth;
                for (int i = 0; i < agentCount; i++)
                {
                    FlockAgent agent = new FlockAgent(
                        Util.GetRandomPoint(0.0, AgentEnvX, 0.0, AgentEnvY, 0.0, AgentEnvZ),
                        Util.GetRandomUnitVectorXY() * 4.0,
                        defaultEnv);

                    agent.FlockSystem = this;
                    Agents.Add(agent);
                }
            }
        }
コード例 #3
0
 public FlockAgent(Point3d position, Vector3d velocity, AgentEnvironment agentEnvironment)
 {
     GenericAgentEnvironment = agentEnvironment;
     Position         = position;
     Velocity         = velocity;
     boundingBoxSizeX = agentEnvironment.EnvWidth;
     boundingBoxSizeY = agentEnvironment.EnvHeight;
     boundingBoxSizeZ = agentEnvironment.EnvDepth;
 }
コード例 #4
0
 public Idle(AgentEnvironment environment, Agents.Mayor mayor) : base(environment, mayor)
 {
 }
コード例 #5
0
        private void Start()
        {
            var env = GameObject.FindGameObjectWithTag("AgentEnvironment");

            if (!env)
            {
                return;
            }

            var agentEnvironment = env.GetComponent <AgentEnvironment>();

            if (agentEnvironment)
            {
                m_environment = agentEnvironment;
            }

            m_simulationData = ScriptableObject.FindObjectOfType <SimulationData>();

            var  map = GameObject.FindGameObjectWithTag("Map");
            uint height = 0, width = 0;

            if (map.GetComponent <Renderer>() != null)
            {
                var size = map.GetComponent <Renderer>().bounds.size;
                width  = (uint)size.x;
                height = (uint)size.z;
            }
            var mapPosition = map.transform.position;

            m_environment.Coordinates = new AgentEnvironment.MapCoordinates(mapPosition, width, height);

            // Instantiate House prefab
            for (uint i = 0; i < m_simulationData.populationDensity; i++)
            {
                var position = new Vector3(mapPosition.x + Random.Range(-(float)width / 2, (float)width / 2),
                                           mapPosition.y,
                                           mapPosition.z + Random.Range(-(float)height / 2, (float)height / 2));
                var house = Instantiate(housePrefab,
                                        position,
                                        Quaternion.identity);
                house.transform.parent = map.transform;

                var citizen = Instantiate(citizenPrefab,
                                          new Vector3(position.x,
                                                      position.y + 0.5f,
                                                      position.z),
                                          Quaternion.identity);
                citizen.transform.parent = map.transform;
                if (citizen.TryGetComponent <CitizenBody>(out var citizenBody))
                {
                    citizenBody.InitProximityColliderSize(new Vector3(
                                                              m_simulationData.diseaseTransmissionDistance,
                                                              1,
                                                              m_simulationData.diseaseTransmissionDistance));
                }
            }

            m_environment.UpdateAgentList();

            var mayor = Instantiate(mayorPrefab);
        }
コード例 #6
0
 protected MayorState(AgentEnvironment environment, Agents.Mayor mayor)
 {
     m_environment = environment;
     m_mayor       = mayor;
 }
コード例 #7
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // code for reading input parameters
            //declare input parameters
            bool iReset = false;
            bool iPlay  = false;

            AgentEnvironment iAgentEnvironment = new AgentEnvironment(Plane.WorldXY, 50.0, 50.0, 0);
            bool             i3D               = false;
            int           iCount               = 10;
            double        iTimeStep            = 0.01;
            double        iNeighbourhoodRadius = 1;
            double        iAlignment           = 0.0;
            double        iCohesion            = 0.0;
            double        iSeparation          = 0.0;
            double        iSeparationDistance  = 1.0;
            List <Circle> iRepellers           = new List <Circle>();
            bool          iUseParallel         = false;
            bool          iUseRTree            = false;

            //read in input parameters
            DA.GetData("Reset", ref iReset);                             //0
            DA.GetData("Play", ref iPlay);                               //1
            DA.GetData("Environment", ref iAgentEnvironment);            //2
            DA.GetData("isSimulation3D", ref i3D);                       //3
            DA.GetData("Count", ref iCount);                             //4
            DA.GetData("Timestep", ref iTimeStep);                       //5
            DA.GetData("NeighbourhoodRadius", ref iNeighbourhoodRadius); //6
            DA.GetData("Alignment", ref iAlignment);                     //7
            DA.GetData("Cohesion", ref iCohesion);                       //8
            DA.GetData("Separation", ref iSeparation);                   //9
            DA.GetData("SeparationDistance", ref iSeparationDistance);   //10
            DA.GetDataList("Repellers", iRepellers);                     //11
            DA.GetData("UseCoresInParallel", ref iUseParallel);          //12
            DA.GetData("UseR-TreeSearch", ref iUseRTree);                //13


            if (iReset || flockSystem == null)
            {
                flockSystem = new FlockSystem(iCount, i3D, iAgentEnvironment);
            }
            else
            {
                flockSystem.Timestep            = iTimeStep;
                flockSystem.NeighbourhoodRadius = iNeighbourhoodRadius;
                flockSystem.AlignmentStrength   = iAlignment;
                flockSystem.CohesionStrength    = iCohesion;
                flockSystem.SeparationStrength  = iSeparation;
                flockSystem.SeparationDistance  = iSeparationDistance;
                flockSystem.Repellers           = iRepellers;
                flockSystem.UseParallel         = iUseParallel;

                if (iUseRTree)
                {
                    flockSystem.updateUsingRTree();
                }
                else
                {
                    flockSystem.Update();
                }
                if (iPlay)
                {
                    ExpireSolution(true);
                }
            }

            List <GH_Point>  positions  = new List <GH_Point>();
            List <GH_Vector> velocities = new List <GH_Vector>();

            foreach (FlockAgent agent in flockSystem.Agents)
            {
                positions.Add(new GH_Point(agent.Position));
                velocities.Add(new GH_Vector(agent.Velocity));
            }

            DA.SetDataList("Positions", positions);
            DA.SetDataList("Velocities", velocities);
        }
コード例 #8
0
 public SocialDistancing(AgentEnvironment environment, Agents.Mayor mayor, float growthRate) : base(environment, mayor)
 {
     m_growthRate = growthRate;
 }
コード例 #9
0
 public TimeOutside(AgentEnvironment environment, Agents.Mayor mayor, float growthRate) : base(environment, mayor)
 {
     m_growthRate = growthRate;
 }
コード例 #10
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // code for reading input parameters
            //declare input parameters
            bool     iReset  = false;
            bool     iPlay   = false;
            Point3d  initPos = new Point3d(0, 0, 0);
            Vector3d initVel = new Vector3d(0.5, 0.5, 1);

            AgentEnvironment iAgentEnvironment = new AgentEnvironment(Plane.WorldXY, 50.0, 50.0, 0);
            BristlebotAgent  iBristlebot       = new BristlebotAgent(initPos, initVel);
            int    iCount    = 10;
            double iTimeStep = 0.01;

            double        iNeighbourhoodRadius = 1;
            double        iSeparationDistance  = 1.0;
            List <Circle> iRepellers           = new List <Circle>();

            bool iUseParallel = false;
            bool iUseRTree    = false;

            //read in input parameters
            DA.GetData("Reset", ref iReset);                             //0
            DA.GetData("Play", ref iPlay);                               //1
            DA.GetData("Environment", ref iAgentEnvironment);            //2
            DA.GetData("BristlebotAgent", ref iAgentEnvironment);        //2
            DA.GetData("Count", ref iCount);                             //4
            DA.GetData("Timestep", ref iTimeStep);                       //5
            DA.GetData("NeighbourhoodRadius", ref iNeighbourhoodRadius); //6

            DA.GetData("SeparationDistance", ref iSeparationDistance);   //10
            DA.GetDataList("Repellers", iRepellers);                     //11
            DA.GetData("UseCoresInParallel", ref iUseParallel);          //12
            DA.GetData("UseR-TreeSearch", ref iUseRTree);                //13


            if (iReset || bristlebotSystem == null)
            {
                bristlebotSystem = new BristlebotSystem(iCount, iAgentEnvironment);
            }
            else
            {
                bristlebotSystem.NeighbourhoodRadius = iNeighbourhoodRadius;

                bristlebotSystem.Repellers   = iRepellers;
                bristlebotSystem.UseParallel = iUseParallel;

                if (iUseRTree)
                {
                    bristlebotSystem.updateUsingRTree();
                }
                else
                {
                    bristlebotSystem.Update();
                }
                if (iPlay)
                {
                    ExpireSolution(true);
                }
            }

            List <GH_Point>  positions  = new List <GH_Point>();
            List <GH_Vector> velocities = new List <GH_Vector>();

            foreach (BristlebotAgent agent in bristlebotSystem.Agents)
            {
                positions.Add(new GH_Point(agent.Position));
                velocities.Add(new GH_Vector(agent.Velocity));
            }

            DA.SetDataList("Positions", positions);
            DA.SetDataList("Velocities", velocities);
        }