Ejemplo n.º 1
0
        private void LoadBtn_Click(object sender, RoutedEventArgs e)
        {
            string filePath = $"../../../Simulations/{ConfigTextBox.Text}.json";

            if (!File.Exists(filePath))
            {
                DisableButtons();
                return;
            }

            var simulationReader = new SimulationReader();

            simulationReader.ReadConfigsFile(filePath);

            simulations = simulationReader.Configs.ConvertAll(x => x.CreateSimulation());

            if (simulations?[currentSimulationNumber]?.Config.Network != "SOMNetwork")
            {
                imageParser = new ImageParser(simulationReader.ImagesPath);
                imageParser.Parse();
                imageParser.GenerateDataSets(simulations[0].ValidationData, simulations[0].ImagesDisturbanceProbability, simulations[0].ImageDisturbanceMaxDifference);
            }

            EnableButtons();
        }
    public static void ReadVissim()
    {
        var trafficDB = FindObjectOfType <TrafficIntegrationData>();

        if (trafficDB != null)
        {
            var path = EditorUtility.OpenFilePanel("Open .fzp", "", "fzp");
            if (path.Length > 0)
            {
                // Clear the trafficDB
                trafficDB.ResetTrafficDB();

                // Instantiate the simulation reader.
                var reader = SimulationReader.FindSimulationReader();
                reader.SetFileName(path);
                reader.SetUseNetworkStream(false);
                reader.SetIO(new VissimIO());
                reader.SetTrafficDB(trafficDB);

                // Start a threaded read.
                reader.ThreadUpdate();
                reader.TryShowWindow();

                //Debug.Log("ReadFZP: DoPasing thread started...");
            }
        }
    }
    public static void ReadPws()
    {
        var trafficDB = FindObjectOfType <TrafficIntegrationData>();

        if (trafficDB != null)
        {
            var path = EditorUtility.OpenFilePanel("Open .meta", "", "meta");
            if (path.Length > 0)
            {
                // Clear the trafficDB
                trafficDB.ResetTrafficDB();

                // Instantiate the simulation reader.
                var reader = SimulationReader.FindSimulationReader();
                reader.SetFileName(path);
                reader.SetUseNetworkStream(false);
                reader.SetIO(new ProtoMetaIO());
                reader.SetTrafficDB(trafficDB);

                // Start a threaded read.
                reader.ThreadUpdate();
                reader.TryShowWindow();
            }
        }
    }
Ejemplo n.º 4
0
    public void LoadScenario(int index)
    {
        Debug.Log("Loading scenario " + index);
        log.Info("Loading scenario " + index);

        if (decisionTree == null)
        {
            return;
        }
        if (trafficDB == null)
        {
            return;
        }

        var sc = decisionTree.GetScenario(index);

        if (sc == null)
        {
            return;
        }

        // Round up game time to avoid loops when going back
        timeController.gameTime += 0.1f;

        if (currentScenario != null && currentScenario.id == sc.id)
        {
            Debug.Log("Scenario already in memory, no need to load it again");
            return;
        }

        trafficDB.ResetTrafficDB();

        var reader = SimulationReader.FindSimulationReader();

        if (sc.simulation != null)
        {
            //reader.SetFileName(sc.FindSimulationPath());
            reader.SetFileName(sc.simulation.path);
            reader.SetUseNetworkStream(false);
            reader.SetIO(new ProtoMetaIO());
            reader.SetTrafficDB(trafficDB);

            // Start a threaded read.
            reader.ThreadUpdate();
        }

        // Set the current scenario with a delay to allow threading start
        StartCoroutine("SetCurrentScenario", sc);
    }
    public static void ReadMatSim()
    {
        var trafficDB = FindObjectOfType <TrafficIntegrationData>();

        if (trafficDB != null)
        {
            var aramGis          = FindObjectOfType <MapBoundaries>();
            var connectionString = aramGis.GetOverridenConnectionString();

            // Instantiate the simulation reader.
            var reader = SimulationReader.FindSimulationReader();
            if (!reader.IsConnectionOpen(connectionString))
            {
                return;
            }

            trafficDB.ResetTrafficDB();

            reader.SetConnectionString(connectionString);
            reader.SetIO(new MatsimIO());
            reader.SetTrafficDB(trafficDB);
            reader.ThreadUpdate();

            //Debug.Log("ReadMatsim: DoPasing thread started...");

            //var path = EditorUtility.OpenFilePanel("Open .xml", "", "xml");
            //if (path.Length > 0)
            //{
            //    // Clear the trafficDB
            //    trafficDB.ResetTrafficDB();

            //    // Instantiate the simulation reader.
            //    var reader = SimulationReader.FindSimulationReader();
            //    reader.SetFileName(path);
            //    reader.SetUseNetworkStream(false);
            //    reader.SetIO(new MatsimIO());
            //    reader.SetTrafficDB(trafficDB);

            //    // Start a threaded read.
            //    reader.ThreadUpdate();
            //    reader.TryShowWindow();

            //    //Debug.Log("ReadFZP: DoPasing thread started...");

            //}
        }
    }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator    = ".";
            System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

            var simulationReader = new SimulationReader();

            Console.Write("Simulation config file name (Simulations/XXX.json): ");
            string fileName = Console.ReadLine();

            simulationReader.ReadConfigsFile($"../Simulations/{fileName}.json");
            var file = new StreamWriter($"../Simulations/{fileName}-results.csv");

            Console.WriteLine("Loaded configs");

            var headers = $"{Config.GetCsvHeaders()};LoopsMean;";

            file.WriteLine(headers);
            Console.WriteLine(headers);
            var simulations = new List <Simulation>();

            foreach (var config in simulationReader.Configs)
            {
                var simulation = config.CreateSimulation();
                simulations.Add(simulation);
                var          loopsResults = new List <int>();
                List <float> errors       = null;

                for (int j = 0; j < config.Repeat; j++)
                {
                    simulation.Reset();
                    errors = simulation.TrainByThreshold(config.TrainData, config.TrainThreshold);

                    if (errors == null)
                    {
                        break;
                    }

                    loopsResults.Add(errors.Count);
                }

                string data = $"{config.GetCsvData()};";

                if (errors == null)
                {
                    data += "timeout";
                }
                else
                {
                    data += loopsResults.Sum() / (float)loopsResults.Count;

                    foreach (float error in errors)
                    {
                        data += $";{error}";
                    }
                }

                file.WriteLine(data);
                Console.WriteLine($"{simulations.Count}: {data}");
            }

            file.Close();
            Console.WriteLine("Ended");

            ConsoleMenu(simulations);
        }