예제 #1
0
        } // end start

        // Update is called once per frame
        void Update()
        {
            if (GenerationManager.generationChange)
            {
                if (is3D)
                {
                    bool exportArrayPointCloud        = false;
                    bool exportOrganizationPointcloud = false;
                    bool exportMobileAgentData        = true;
                    bool exportClusterAgentData       = false;

                    string filePath = SimulationManager.Get().PixelDataMobileAgentsPath;

                    string fileName = "PixelDataModibleAgents" + GenerationManager.generationCount.ToString() + ".txt";

                    ExportData.ExportPointCloudToTxtFile(filePath, pixel3DArray, pixel2DArray, AgentPopulation.populationList, fileName, columns, rows, height, is3D, is2D, exportArrayPointCloud, exportOrganizationPointcloud,
                                                         exportMobileAgentData, exportClusterAgentData);



                    string filePath1 = SimulationManager.Get().PixelDataClusterAgentsPath;
                    string fileName1 = "ClusterAgents" + GenerationManager.generationCount.ToString() + ".txt";
                    string fullPath1 = System.IO.Path.Combine(filePath1, fileName1);

                    StreamWriter writer1 = new StreamWriter(fullPath1);


                    //StreamWriter writer2 = new StreamWriter(@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\PixelData\ClusterAgents\" +
                    //    "ClusterAgents" + GenerationManager.generationCount.ToString() + ".txt");

                    for (int i = 0; i < columns; i++)
                    {
                        for (int j = 0; j < rows; j++)
                        {
                            for (int k = 0; k < height; k++)
                            {
                                string outPut = pixel3DArray[i, k, j].CountClusterAgents.ToString();


                                writer1.WriteLine(outPut);
                            }
                        }
                    }

                    writer1.Close();
                }
            }
        } // end update
예제 #2
0
        private AgentPopulation AP; // store script to reference in variable

        // Use this for initialization
        void Start()
        {
            agentPopulation = GameObject.Find("AgentPopulation");     // create variable to store game object that holds script top reference
            AP = agentPopulation.GetComponent <AgentPopulation>();    // store script to reference in variable

            if (is2D)
            {
                pixel2DArray = new Pixel[columns, rows];
                // DensityValues2D = new float [columns, rows];
                NextDensityValues2D = new Pixel[columns, rows];
            }

            if (is3D)
            {
                pixel3DArray = new Pixel[columns, height, rows];
                //DensityValues3D = new float [columns, height, rows];
                NextDensityValues3D = new Pixel[columns, height, rows];
            }

            Init();
            Name();



            if (is3D)
            {
                bool exportArrayPointCloud        = true;
                bool exportOrganizationPointcloud = false;
                bool exportMobileAgentData        = false;
                bool exportClusterAgentData       = false;

                string filePath = SimulationManager.Get().PixelArrayFilePath;
                string fileName = "PixelArray" + ".txt";



                ExportData.ExportPointCloudToTxtFile(filePath, pixel3DArray, pixel2DArray, AgentPopulation.populationList, fileName, columns, rows, height, is3D, is2D, exportArrayPointCloud, exportOrganizationPointcloud,
                                                     exportMobileAgentData, exportClusterAgentData);
            }
        } // end start
예제 #3
0
        } // END START

        // Update is called once per frame


        void Update()
        {
            if (getPixelArrayCntrMass == false)
            {
                //print(pixelPop.GetCntrMassPixelArray());

                pixelPop.GetCntrMassPixelArray();


                getPixelArrayCntrMass = true;
            }



            //Only run method once

            time += (int)Time.time;

            //time == timeToInitFirstAgent &&
            if (time == timeToInitFirstAgent && runCoroutine == false && PeoplePopulation.peopleList.Count != 0)
            {
                //MovePopTowardsPixelArrayCntrMass();



                // ActivateAgentsBasedOnInitClusterPositionFromRhino(1);

                // ActivateAgentBasedOnCntOfPplMassB();
                ActivateMiddleAgentOfBottomLayer();
                // PickRandomAgentstoActivateFromBottomLayer(2);

                runCoroutine = true;
            }



            // cancelledAgentList = FindObjectsWithTag("Cancelled");
            deActivatedAgentList           = FindObjectsWithTag("De-Activated");
            signalReceiverAgentList        = FindObjectsWithTag("SignalReceiver");
            signalReceiverPassiveAgentList = FindObjectsWithTag("SignalReceiverPassive");
            freezedAgentList = FindObjectsWithTag("Freezed");

            //if (GenerationManager.generationCount != 0)
            //{
            //    //deActivatedPassiveAgentList = FindObjectsWithTag("De-ActivatedPassive");
            //    wondererAgentList = FindObjectsWithTag("Wanderer");
            //}



            #region EXPORT DATA



            if (GM.windEffectCounter > GM.WindEffectMaxDuration)
            {
                /// DISPLACEMENT
                string filePath = SimulationManager.Get().WindAnalysisFilePath;    //@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\WindAnalysis\";
                string fileName = "TotalWindDisplacement" + GenerationManager.generationCount.ToString() + ".txt";

                StreamWriter writer = new StreamWriter(filePath + fileName);

                for (int i = 0; i < populationList.Count; i++)
                {
                    if (populationList[i].gameObject.tag != "Cancelled")
                    {
                        string OutPut = populationList[i].GetComponent <OrganizationalModel.Behaviors.OrganizationBehavior>().totalDisplacement.ToString();
                        writer.WriteLine(OutPut);
                    }
                }

                writer.Close();
            }

            if (GenerationManager.playWindEffect && exportBodyPlanBeforeWindForce == false)
            {
                /// DISPLACEMENT
                string filePath = SimulationManager.Get().ClusterOrganizationFilePath;     //@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\ClusterOrganization\";
                string fileName = "ClusterOrganization" + "BeforeWindForce" + ".txt";

                StreamWriter writer = new StreamWriter(filePath + fileName);

                for (int i = 0; i < populationList.Count; i++)
                {
                    if (populationList[i].gameObject.tag != "Cancelled")
                    {
                        string OutPut = populationList[i].GetComponent <OrganizationalModel.Behaviors.OrganizationBehavior>().totalDisplacement.ToString();
                        writer.WriteLine(OutPut);
                    }
                }

                writer.Close();
            }


            if (GenerationManager.playWindEffect)
            {
                bool   exportOrganizationPointcloud = true;
                string filePath1 = SimulationManager.Get().ClusterOrganizationFilePath;    //@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\ClusterOrganization\";
                string fileName1 = "ClusterOrganization" + "AfterWindForce" + ".txt";

                ExportData.ExportPointCloudToTxtFile(filePath1, fileName1, AgentPopulation.populationList, SimulationManager.Get().is3D, SimulationManager.Get().is2D, exportOrganizationPointcloud);
            }


            if (AgentPopulation.freezedAgentList.Count == AgentPopulation.populationList.Count - totalCancelledAgents && exportDataTemp == false)    // ONLY USED WHEN ONLY 1 ORGANIZATION IS WANTED. --> ONLY ONE ITERATION

            // if (GenerationManager.generationChange)
            {
                /// DISPLACEMENT
                string filePathZ = SimulationManager.Get().WindAnalysisFilePath;    //@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\WindAnalysis\";
                string fileNameZ = "TotalWindDisplacement" + GenerationManager.generationCount.ToString() + ".txt";

                StreamWriter writerZ = new StreamWriter(filePathZ + fileNameZ);

                for (int i = 0; i < populationList.Count; i++)
                {
                    if (populationList[i].gameObject.tag != "Cancelled")
                    {
                        string OutPut = populationList[i].GetComponent <OrganizationalModel.Behaviors.OrganizationBehavior>().totalDisplacement.ToString();
                        writerZ.WriteLine(OutPut);
                    }
                }

                writerZ.Close();



                bool   exportOrganizationPointcloud = true;
                string filePath = SimulationManager.Get().ClusterOrganizationFilePath;
                string fileName = "ClusterOrganization" + GenerationManager.generationCount.ToString() + ".txt";

                ExportData.ExportPointCloudToTxtFile(filePath, fileName, AgentPopulation.populationList, SimulationManager.Get().is3D, SimulationManager.Get().is2D, exportOrganizationPointcloud);

                string filePathMultiple = SimulationManager.Get().individualOrganizationFilePath;
                ExportData.ExportPointCloudToMultipleTxtFiled(filePathMultiple, populationList, SimulationManager.Get().is3D, SimulationManager.Get().is2D, exportOrganizationPointcloud);

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                ///DICTIONARY
                //for (int i = 0; i < populationList.Count; i++)
                //{
                //    if (populationList[i].gameObject.tag != "Cancelled")
                //    {
                //        dictionary.Add(i, populationList[i].GetComponent<OrganizationalModel.Behaviors.OrganizationBehavior>().neighbours);
                //    }
                //}

                //using (var writer = new StreamWriter(@"C:\Users\nicol\OneDrive\Desktop\New folder\test.txt"))
                //{
                //    foreach (var pair in dictionary)
                //    {
                //        writer.WriteLine("{0},{1};", pair.Key, String.Join(",", pair.Value.Select(x => x.ToString()).ToArray()));
                //    }
                //}
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                ///// ENERGY DATA
                string       filePath2 = SimulationManager.Get().EnergyLevelsFilePath;//@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\EnergyLevels\";
                string       fileName2 = "EnergyLevels" + GenerationManager.generationCount.ToString() + ".txt";
                string       fullPath2 = System.IO.Path.Combine(filePath2, fileName2);
                StreamWriter writer2   = new StreamWriter(fullPath2);

                for (int i = 0; i < populationList.Count; i++)
                {
                    if (populationList[i].gameObject.tag != "Cancelled")
                    {
                        string OutPut = populationList[i].GetComponent <OrganizationalModel.Behaviors.OrganizationBehavior>().energyLevel.ToString();
                        writer2.WriteLine(OutPut);
                    }
                }

                writer2.Close();

                ///// ENERGY DATA

                ///// NEIGHBOUR DATA
                string filePath3 = SimulationManager.Get().NeighbourCountFilePath;    //@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\NeighbourCount\";
                string fileName3 = "NeighbourCount" + GenerationManager.generationCount.ToString() + ".txt";
                string fullPath3 = System.IO.Path.Combine(filePath3, fileName3);

                StreamWriter writer3 = new StreamWriter(fullPath3);

                for (int i = 0; i < populationList.Count; i++)
                {
                    if (populationList[i].gameObject.tag != "Cancelled")
                    {
                        string OutPut = populationList[i].GetComponent <OrganizationalModel.Behaviors.OrganizationBehavior>().neighbours.Count.ToString();


                        writer3.WriteLine(OutPut);
                    }
                }

                writer3.Close();


                string filePath4 = SimulationManager.Get().CommunicationTypeFilePath;    //@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\CommunicationType\";
                string fileName4 = "CommunicationType" + GenerationManager.generationCount.ToString() + ".txt";
                string fullPath4 = System.IO.Path.Combine(filePath4, fileName4);

                StreamWriter writer4 = new StreamWriter(fullPath4);

                for (int i = 0; i < populationList.Count; i++)
                {
                    if (populationList[i].gameObject.tag != "Cancelled")
                    {
                        string OutPut = populationList[i].GetComponent <OrganizationalModel.Behaviors.OrganizationBehavior>().communicationType.ToString();


                        writer4.WriteLine(OutPut);
                    }
                }

                writer4.Close();



                string filePath5 = SimulationManager.Get().DirectionalityRuleFilePath;    //@"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\DirectionalityRule\";
                string fileName5 = "DirectionalityRule" + GenerationManager.generationCount.ToString() + ".txt";
                string fullPath5 = System.IO.Path.Combine(filePath5, fileName5);

                StreamWriter writer5 = new StreamWriter(fullPath5);

                for (int i = 0; i < populationList.Count; i++)
                {
                    if (populationList[i].gameObject.tag != "Cancelled")
                    {
                        string OutPut = populationList[i].GetComponent <OrganizationalModel.Behaviors.OrganizationBehavior>().directionalityRule.ToString();


                        writer5.WriteLine(OutPut);
                    }
                }

                writer5.Close();



                string filePath6 = SimulationManager.Get().DensityThresholdFilePath;
                string fileName6 = "DensityThreshold" + GenerationManager.generationCount.ToString() + ".txt";
                string fullPath6 = System.IO.Path.Combine(filePath6, fileName6);

                StreamWriter writer6 = new StreamWriter(fullPath6);

                for (int i = 0; i < populationList.Count; i++)
                {
                    if (populationList[i].gameObject.tag != "Cancelled")
                    {
                        string OutPut = populationList[i].GetComponent <OrganizationalModel.Behaviors.OrganizationBehavior>().currentScalarValueDensityCheck.ToString();


                        writer6.WriteLine(OutPut);
                    }
                }

                writer6.Close();



                ///// NEIGHBOUR DATA



                ///// STATE HISTORY DATA FREEZED
                string filePath1 = @"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\AgentHistory\AgentStateHistory\Freezed\";
                string fileName1 = "FreezedStateHistory" + GenerationManager.generationCount.ToString() + ".txt";
                bool   freezed   = true;
                ExportData.ExportStateHistoryData(filePath1, fileName1, populationList, freezed, false, false, false);

                /////  STATE HISTORY DATA  FREEZED



                ///// STATE HISTORY DATA DEACTIVATED
                string filePathA = @"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\AgentHistory\AgentStateHistory\DeActivated\";
                string fileNameA = "DeActivatedStateHistory" + GenerationManager.generationCount.ToString() + ".txt";

                ExportData.ExportStateHistoryData(filePathA, fileNameA, populationList, false, true, false, false);

                /////  STATE HISTORY DATA  DEACTIVATED



                ///// STATE HISTORY DATA EMMITER
                string filePathB = @"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\AgentHistory\AgentStateHistory\Emmiter\";
                string fileNameB = "EmmiterStateHistory" + GenerationManager.generationCount.ToString() + ".txt";

                ExportData.ExportStateHistoryData(filePathB, fileNameB, populationList, false, false, true, false);

                /////  STATE HISTORY DATA  EMMITER


                ///// STATE HISTORY DATA RECEIVER
                string filePathC = @"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\AgentHistory\AgentStateHistory\Receiver\";
                string fileNameC = "ReceiverStateHistory" + GenerationManager.generationCount.ToString() + ".txt";

                ExportData.ExportStateHistoryData(filePathC, fileNameC, populationList, false, false, false, true);

                /////  STATE HISTORY DATA  RECEIVER



                //StringBuilder tsvData = new StringBuilder();
                //// tsvData.AppendLine("Agent , Neighbour History, Inactive history State, De Activated History state, Emitter History state, Receiver History state");

                //tsvData.AppendLine("Agent\tNeighbour History");

                //for (int i = 0; i < populationList.Count; i++)
                //{
                //    if (populationList[i] != null)
                //    {
                //        string agentName = populationList[i].name;


                //        for (int j = 0; j < populationList[i].neighbourHistory.Count; j++)
                //        {
                //            string agentHistory = populationList[i].neighbourHistory[j].name.ToString();
                //            string inactiveHistoryState = populationList[i].freezedHistoryCount.ToString();
                //            string deActivatedHistoryState = populationList[i].deActivatedHistoryCount.ToString();
                //            string emmiterHistoryState = populationList[i].emmiterHistoryCount.ToString();
                //            string receiverHistoryState = populationList[i].receiverHistoryCount.ToString();

                //            string data = agentName + "\t" + agentHistory;//+ "," + inactiveHistoryState + "," + deActivatedHistoryState + "," + emmiterHistoryState + "," + receiverHistoryState;
                //            tsvData.AppendLine(data);

                //        }
                //    }



                //}

                //string Path = @"C:\Users\nicol\Documents\Architecture\1.AADRL\Term 4\Data\SimulationData\3D\Cluster\AgentHistory\HistoryData" + GenerationManager.generationCount.ToString() + ".tsv";

                //File.AppendAllText(Path, tsvData.ToString());



                exportDataTemp = true;
                #endregion
            }
        } // END UPDATE