コード例 #1
0
        public Pandemic_Experiment(
            List <PD_Game> allGames,
            bool saveInitialGameStates,
            Dictionary <PD_AI_Agent_Base, string> namePerAgent,
            PD_AI_PathFinder pathFinder,
            int numRepetitionsPerAgent,
            string experimentResults_FolderPath,
            bool keep_GameStats_Report,
            bool keep_Trace
            )
        {
            AllGames = allGames;
            SaveInitialGameStates = saveInitialGameStates;

            NamePerAgent           = namePerAgent;
            NumRepetitionsPerAgent = numRepetitionsPerAgent;

            GameState_Report = new PD_GameState_Report(AllGames[0], pathFinder);
            GameStats_Report = new PD_GameStats_Report(AllGames[0], pathFinder);

            ExperimentResults_FolderPath = experimentResults_FolderPath;
            if (PD_IO_Utilities.FolderExists(ExperimentResults_FolderPath) == false)
            {
                PD_IO_Utilities.CreateFolder(ExperimentResults_FolderPath, true);
            }

            Keep_GameStats_Report = keep_GameStats_Report;
            Keep_Trace            = keep_Trace;

            string thisExperiment_FolderName = DateTime.UtcNow.Ticks.ToString();

            ThisExperiment_FolderPath = Path.Combine(ExperimentResults_FolderPath, thisExperiment_FolderName);
            if (PD_IO_Utilities.FolderExists(ThisExperiment_FolderPath) == false)
            {
                PD_IO_Utilities.CreateFolder(ThisExperiment_FolderPath, true);
            }

            if (SaveInitialGameStates)
            {
                foreach (var game in AllGames)
                {
                    string gameFileName = "game_" + game.unique_id.ToString() + ".json";
                    string gameFilePath = Path.Combine(ThisExperiment_FolderPath, gameFileName);

                    PD_IO_Utilities.SerializeGameToJsonAndSave(
                        game,
                        false,
                        gameFilePath,
                        false,
                        false
                        );
                }
            }

            Report_FilePath_PerAgent = new Dictionary <PD_AI_Agent_Base, string>();

            List <PD_AI_Agent_Base> allAgents = NamePerAgent.Keys.ToList();

            foreach (var agent in allAgents)
            {
                string agentName = NamePerAgent[agent];

                string agent_Report_FileName = agentName + ".csv";
                string agent_Report_FilePath = Path.Combine(ThisExperiment_FolderPath, agent_Report_FileName);
                Report_FilePath_PerAgent.Add(agent, agent_Report_FilePath);

                string agent_Description_FileName = agentName + ".json";
                string agent_Description_FilePath = Path.Combine(ThisExperiment_FolderPath, agent_Description_FileName);
                PD_IO_Utilities.SerializeToJsonAndSave(agent, agent_Description_FilePath, true, false);
            }

            int counter = 0;

            foreach (var agent in allAgents)
            {
                PD_IO_Utilities.CreateFile(Report_FilePath_PerAgent[agent], false, false);

                PD_IO_Utilities.AppendToFile(
                    Report_FilePath_PerAgent[agent],
                    Get_Record_Header(AllGames[0], pathFinder, agent)
                    );

                counter++;
            }
        }
コード例 #2
0
        public PD_Experiment_Tournament(
            List <PD_Game> allGames,
            Dictionary <PD_AI_Agent_Base, string> namePerAgent,
            PD_AI_PathFinder pathFinder,
            int numRepetitionsPerAgent,
            string experimentResults_ParentFolder_Path,
            bool keep_GameStats_Report,
            bool keep_MacroActions_Report,
            bool keep_Trace
            )
        {
            PathFinder = new PD_AI_PathFinder();

            AllGames               = allGames;
            NamePerAgent           = namePerAgent;
            NumRepetitionsPerAgent = numRepetitionsPerAgent;

            GameState_Report           = new PD_GameState_Report(AllGames[0], pathFinder);
            GameStats_Report           = new PD_GameStats_Report(AllGames[0], pathFinder);
            MacroActions_Report        = new PD_MacroActions_Report(AllGames[0], pathFinder);
            RollingHorizonAgent_Report = new PD_RollingHorizon_Agent_Report();

            ExperimentResults_ParentFolder_Path = experimentResults_ParentFolder_Path;
            if (PD_IO_Utilities.FolderExists(ExperimentResults_ParentFolder_Path) == false)
            {
                PD_IO_Utilities.CreateFolder(ExperimentResults_ParentFolder_Path, true);
            }

            Keep_GameStats_Report    = keep_GameStats_Report;
            Keep_MacroActions_Report = keep_MacroActions_Report;
            Keep_Trace = keep_Trace;

            string thisTournament_Folder_Name = DateTime.UtcNow.Ticks.ToString();

            ThisTournament_Folder_Path = Path.Combine(ExperimentResults_ParentFolder_Path, thisTournament_Folder_Name);
            if (PD_IO_Utilities.FolderExists(ThisTournament_Folder_Path) == false)
            {
                PD_IO_Utilities.CreateFolder(ThisTournament_Folder_Path, true);
            }

            FolderPath_Per_Agent     = new Dictionary <PD_AI_Agent_Base, string>();
            Report_FilePath_PerAgent = new Dictionary <PD_AI_Agent_Base, string>();

            List <PD_AI_Agent_Base> allAgents = NamePerAgent.Keys.ToList();

            foreach (var agent in allAgents)
            {
                string agentName = NamePerAgent[agent];

                string agent_FolderName = agentName;
                string agent_FolderPath = Path.Combine(ThisTournament_Folder_Path, agent_FolderName);
                FolderPath_Per_Agent.Add(agent, agent_FolderPath);
                if (PD_IO_Utilities.FolderExists(agent_FolderPath) == false)
                {
                    PD_IO_Utilities.CreateFolder(agent_FolderPath, true);
                }

                string agent_Report_FileName = agentName + ".csv";
                string agent_Report_FilePath = Path.Combine(agent_FolderPath, agent_Report_FileName);
                Report_FilePath_PerAgent.Add(agent, agent_Report_FilePath);

                string agent_Description_FileName = agentName + ".json";
                string agent_Description_FilePath = Path.Combine(agent_FolderPath, agent_Description_FileName);
                PD_IO_Utilities.SerializeToJsonAndSave(agent, agent_Description_FilePath, true, false);
            }

            int counter = 0;

            foreach (var agent in allAgents)
            {
                PD_IO_Utilities.CreateFile(Report_FilePath_PerAgent[agent], false, false);
                //PD_GameStats_Report tempGameReport = new PD_GameStats_Report(AllGames[0], pathFinder);

                PD_IO_Utilities.AppendToFile(
                    Report_FilePath_PerAgent[agent],
                    Get_Record_Header(AllGames[0], pathFinder, agent)
                    );

                counter++;
            }
        }