Exemplo n.º 1
0
    void placeAgents()
    {
        simulationAgentEncapsulator mainAgentScript = null;



        for (int i = 0; i < numberOfAgents; i++)
        {
            //Instantiate(agent, GeneratedPosition(), Quaternion.identity);

            GameObject cloneAgent = Instantiate(prefab, GeneratedPosition(), Quaternion.identity) as GameObject;

            cloneAgent.tag = "agent";

            cloneAgent.name = "agent" + i;

            int quarterNum = (int)numberOfAgents / 4;

            mainAgentScript = cloneAgent.GetComponent <simulationAgentEncapsulator>();
            if (i >= 0 && i < quarterNum)
            {
                mainAgentScript.assignedPersonality       = simulationAgentEncapsulator.personalityType.Introverted;
                mainAgentScript.assignedPersonalitySecond = simulationAgentEncapsulator.personalityTypeSecond.Cooperative;
            }

            if (i >= quarterNum && i < quarterNum * 2)
            {
                mainAgentScript.assignedPersonality       = simulationAgentEncapsulator.personalityType.Introverted;
                mainAgentScript.assignedPersonalitySecond = simulationAgentEncapsulator.personalityTypeSecond.Suspicious;
            }

            if (i >= quarterNum * 2 && i < quarterNum * 3)
            {
                mainAgentScript.assignedPersonality       = simulationAgentEncapsulator.personalityType.Extroverted;
                mainAgentScript.assignedPersonalitySecond = simulationAgentEncapsulator.personalityTypeSecond.Cooperative;
            }

            if (i >= quarterNum * 3 && i < quarterNum * 4)
            {
                mainAgentScript.assignedPersonality       = simulationAgentEncapsulator.personalityType.Extroverted;
                mainAgentScript.assignedPersonalitySecond = simulationAgentEncapsulator.personalityTypeSecond.Suspicious;
            }
        }

        Debug.Log("Agents placed...");
    }
Exemplo n.º 2
0
    void statistics()
    {
        GameObject a = GameObject.FindGameObjectWithTag("agent");

        AgentBehaviourScript = a.GetComponent <AgentBehaviour>();

        numberOfDirections = AgentBehaviourScript.numberOfDirections;

        directionalFeatures = AgentBehaviourScript.stateMatrixFeatures.Length;

        onedimensionalFeatures = AgentBehaviourScript.onedimensionalFeatures.Length;

        GameObject[] agents = GameObject.FindGameObjectsWithTag("agent");

        Debug.Log("agents " + agents.Length + " directional " + numberOfDirections * directionalFeatures + " onedimensional " + onedimensionalFeatures);

        //Time.timeScale = 0;

        //string buffer = "visited_info,unvisited_info,extraverted_agents,introverted_agents,total_agents,total_visited_info,total_unvisited_info,type" + System.Environment.NewLine;

        string buffer = "vi,uvi,ea,ia,ca,sa,tae,tai,tca,tsa,tvi,tuvi,good,bad,score,type" + System.Environment.NewLine;

        foreach (GameObject agent in agents)
        {
            AgentBehaviourScript = agent.GetComponent <AgentBehaviour>();

            AgentEncapsulatorScript = agent.GetComponent <simulationAgentEncapsulator>();

            double[] currentVector = AgentBehaviourScript.weightsVector;

            List <GameObject> infopointsVisited = AgentBehaviourScript.infopointsVisited;


            float totalScore = AgentBehaviourScript.totalScore;

            int goodInfo = 0;

            int badInfo = 0;

            foreach (var infopoint in infopointsVisited)
            {
                infopointScript = infopoint.GetComponent <infopointDynamics> ();

                if (infopointScript.disposition == infopointDynamics.possibleDispositions.Good)
                {
                    goodInfo++;
                }
                else
                {
                    badInfo++;
                }
            }

            string personality = "";

            if (AgentEncapsulatorScript.assignedPersonality == simulationAgentEncapsulator.personalityType.Extroverted)
            {
                personality = "E";
            }
            else
            {
                personality = "I";
            }

            if (AgentEncapsulatorScript.assignedPersonalitySecond == simulationAgentEncapsulator.personalityTypeSecond.Cooperative)
            {
                personality += "C";
            }
            else
            {
                personality += "S";
            }

            printArrayDouble(currentVector);

            double bias = currentVector[currentVector.Length - 1];

            Debug.Log(bias);

            for (int i = 0; i < currentVector.Length; i++)
            {
                currentVector[i] = currentVector[i] - bias;
            }

            printArrayDouble(currentVector);

            List <double> features = new List <double>();

            for (int i = 0; i < directionalFeatures; i++)
            {
                //List<double> f = new List<double>();

                double featureSum = 0f;


                for (int j = 0; j < numberOfDirections; j++)
                {
                    //Debug.Log(currentVector[j * directionalFeatures + i]);

                    featureSum += currentVector[j * directionalFeatures + i];

                    //f.Add(currentVector[j * directionalFeatures + i]);

                    //f.Add(j * directionalFeatures + i);
                }

                features.Add(featureSum / numberOfDirections);
            }


            for (int i = 0; i < onedimensionalFeatures; i++)
            {
                features.Add(currentVector[numberOfDirections * directionalFeatures + i]);
            }


            features.Add(goodInfo);

            features.Add(badInfo);

            features.Add(totalScore);


            //Debug.Log(agent.name);

            string featureBuffer = "";

            int count = 0;

            foreach (var feature in features)
            {
                count++;

                if (count < features.Count)
                {
                    featureBuffer += feature + ",";
                }
                else
                {
                    featureBuffer += feature;
                }
            }

            // if(!featureBuffer.Contains("0,0,0,0,0,0,0"))
            buffer += featureBuffer + "," + personality + System.Environment.NewLine;
        }


        writeData(buffer);
    }
Exemplo n.º 3
0
        private void Awake()
        {
            this.WarnIfMultipleInstances();

            _unit = this.GetUnitFacade();
            if (_unit == null)
            {
                Debug.LogError("WanderBehaviour requires a component that implements IMovable.");
                this.enabled = false;
            }

            agentEncapsulatorScript = GetComponent <simulationAgentEncapsulator>();

            minimumDistance = 60.0f;

            rayAngle = 3;


            fieldOFView = 25f;

            goalFlag = false;



            mainGrid = GridManager.instance.GetGrid(new Vector3(0, 0, 0));


            //state function



            range = 400;

            interactRange = 20;


            consumeReward = 0.5f;

            socialReward = consumeReward;

            visitedReward = (float)-consumeReward / 3;

            refuseReward = (float)-socialReward / 3;


            infopointsVisited = new List <GameObject>();


            numberOfDirections = 8;

            directionsState = new GameObject[numberOfDirections];

            directionsVector = new float[numberOfDirections + 2];

            directionsMatrix = new float[numberOfDirections, 2];

            step = (float)1 / (numberOfDirections / 2);

            //Debug.Log ("step: " + step);



            /* rows of matrix - attributes that are perceived for each direction
             *
             * 0 - distance of the detected object - 0-1
             *
             * 1 - type of the detected object 1 - agent , 0 - info
             *
             * 2 - extraverted agent - 1, infopoint - 0
             *
             * 3 - introverted agent - 1 , infopoint - 0
             *
             *
             * 0 - visited infopoints close  - 0 - 1
             *
             * 1 - unvisited infopoints close - 0 -1
             *
             * 2 - extraverted agents close - 0 - 1
             *
             * 3 - intraverted agents close - 0 - 1
             *
             */

            stateMatrixFeatures = new float[4];



            /* additional features
             *
             * 0 - total number of agents detected
             *
             * 1 - total number of visited infopoints detected
             *
             * 2 - total number of unvisited infopoints detected
             *
             * 3 - detecting agents personality type - 0 - introverted, 1 -extroverted
             *
             * 4 - detecting agent mood, positive 1, neutral 0.5, negative 0
             *
             */


            onedimensionalFeatures = new float[3];


            vectorSize = numberOfDirections * stateMatrixFeatures.Length + onedimensionalFeatures.Length + 1;              // + bias

            previousfeaturesVector = new float[vectorSize];

            weightsVector = new double[vectorSize];

            matrixLength = stateMatrixFeatures.Length;

            matrixSize = numberOfDirections * matrixLength;


            int counter;

            for (counter = 0; counter < weightsVector.Length; counter++)
            {
                weightsVector [counter] = 0f;
            }



            //Debug.Log (TestRange (-0.5f, -0.5f, -0.25f ));


            for (int i = 0; i < numberOfDirections + 2; i++)
            {
                if (i <= numberOfDirections / 2)
                {
                    //Debug.Log ("number " + i * step);

                    directionsVector [i] = i * step;
                }
                else
                {
                    //Debug.Log ("number2 " + (i * step - ( 2 + step )));

                    directionsVector [i] = i * step - (2 + step);
                }


                //Debug.Log (i);
            }



            for (int i = 0; i < directionsMatrix.GetLength(0); i++)
            {
                if (i < numberOfDirections / 2)
                {
                    directionsMatrix [i, 0] = directionsVector [i];

                    directionsMatrix [i, 1] = directionsVector [i + 1];
                }
                else
                {
                    directionsMatrix [i, 0] = directionsVector [i + 1];

                    directionsMatrix [i, 1] = directionsVector [i + 2];
                }


                for (int j = 0; j < directionsMatrix.GetLength(1); j++)
                {
                    float s = directionsMatrix[i, j];

                    //Debug.Log (i + "-"+ j + " " + s);
                }
            }


            foreach (float item in directionsVector)
            {
                //Debug.Log (item);
            }
        }