コード例 #1
0
ファイル: Experimenter.cs プロジェクト: slowmickey/VISLAB
        /// <summary>
        /// Creates a new experiment folder,
        /// copy files to it from model dir.
        /// and marks it as loaded and selected in the project file
        /// </summary>
        public void CreateExperiment(Experiment.ExperimentData expData)
        {
            // get max experiment number
            int max = SysAdmin.GetMaxDirNumber(manager.GetRootExperimentPath(modelName));

            ++max;
            // create new experiment folder
            string s = manager.GetLoadedExperimentAbsolutePath(modelName);

            string experimentPath = string.Format("{0}#{1}", s, max);

            if (max == 0)
            {
                experimentPath = string.Format("{0}{1}#{2}", s, modelName, max);
            }

            var di = Directory.CreateDirectory(string.Format("{0}\\{1}{2}", experimentPath, modelName, Model.MODEL_DIR_POSTFIX));

            // copy main model folder to the new model folder
            s = manager.GetModelDir(modelName);
            SysAdmin.CopyDirectory(s, di.FullName);

            // create experiment data file in the experiment folder
            s = string.Format("{0}\\{1}{2}", experimentPath, modelName, Experiment.ExperimentData.EXPERIMENT_DATA_POSTFIX);
            expData.Save(s);
            // mark experiment as loaded
            manager.MarkExperimentAsLoaded(modelName, experimentPath);
            manager.MarkExperimentAsSelected(modelName, experimentPath);
        }
コード例 #2
0
ファイル: Experimenter.cs プロジェクト: slowmickey/VISLAB
        public void CreateRootExperiment()
        {
            // create new experiment folder
            var di = Directory.CreateDirectory(manager.GetLoadedExperimentModelDir(modelName));

            // copy main model folder to new model folder
            string s = manager.GetModelDir(modelName);

            SysAdmin.CopyDirectory(s, di.FullName);

            // create experiment data file in the experiment folder
            var expData = new Experiment.ExperimentData()
            {
                //Alanyze = false,
                CreatedOn   = DateTime.Now,
                Description = "Zero Experiment (created automatically)",
                //Duration = new TimeSpan(0),
                //DurationTicks = 0
            };

            expData.Save(manager.GetLoadedExperimentDataFileName(modelName));
        }
コード例 #3
0
        private CreateExperimentControl CreateCreateExperimentControl(Experiment.ExperimentData expData)
        {
            var ctrl = new CreateExperimentControl();

            ctrl.DataContext = expData;

            //ctrl.tbkDuration.Text = duration.ToString();
            ctrl.btnCreateExperimenet.Click += (sender_, e_) =>
            {
                experimenter.CreateExperiment(expData);

                // refresh the model experiments tree
                Refresh();
                ShadowMaker.ShadowDown();
            };

            ctrl.btnCancel.Click += (sender_, e_) =>
            {
                Refresh();
                ShadowMaker.ShadowDown();
            };

            return(ctrl);
        }
コード例 #4
0
ファイル: Experimenter.cs プロジェクト: slowmickey/VISLAB
        public void RunSimulationAsync(Dispatcher context, Func <bool> startAction, Action <Experiment.ExperimentData> endAction)
        {
            ThreadPool.QueueUserWorkItem(o =>
            {
                aex.Protect(() =>
                {
                    // load model if VISSIM is not instanciated or save model otherwise
                    if (!vissim.IsInstanciated)
                    {
                        LoadModelToVissim(true);
                    }
                    else
                    {
                        SaveModelToVissim();
                    }

                    // perform prep. actions (ask user for DataCollections, Evaluations and etc.)
                    bool canContinue = true;
                    context.Invoke(DispatcherPriority.Background, new ThreadStart(delegate()
                    {
                        canContinue = startAction();
                    }));
                    if (!canContinue)
                    {
                        return;
                    }

                    var sim = vissim.Instance.Simulation;

                    long startTicks = DateTime.Now.Ticks;
                    simulationState.IsSimulationRunning = true;

                    try
                    {
                        aex.Protect(() => sim.RunContinuous());
                    }
                    finally
                    {
                        simulationState.IsSimulationRunning = false;
                        if (simulationState.SimulationWasStopped)
                        {
                            simulationState.SimulationWasStopped = false;
                        }
                    }

                    var data = new Experiment.ExperimentData()
                    {
                        CreatedOn = DateTime.Now,
                        Duration  = new TimeSpan(DateTime.Now.Ticks - startTicks),
                        //Period = new TimeSpan(0, 0, (int)sim.Period),
                        IsCountersEvaluationEnabled    = vissim.Instance.Evaluation.Wrap().IsDataCollectionsEnabled,
                        IsTravelTimesEvaluationEnabled = vissim.Instance.Evaluation.Wrap().IsTravelTimeEnabled,
                        NumberOfRuns = 1
                    };

                    context.Invoke(DispatcherPriority.Background, new ThreadStart(delegate()
                    {
                        endAction(data);
                    }));
                });
            });
        }
コード例 #5
0
ファイル: Experimenter.cs プロジェクト: slowmickey/VISLAB
        public void RunMultiAsync(StartMultirunBindingSource parameters, Dispatcher context, Func <bool> startAction, Action <Experiment.ExperimentData> endAction, Action <string> stateChangedAction)
        {
            ThreadPool.QueueUserWorkItem(o =>
            {
                aex.Protect(() =>
                {
                    // load model if VISSIM is not instanciated or save model otherwise
                    if (!vissim.IsInstanciated)
                    {
                        LoadModelToVissim(true);
                    }
                    else
                    {
                        SaveModelToVissim();
                    }

                    // perform prep. actions (ask user for DataCollections, Evaluations and etc.)
                    bool canContinue = true;
                    context.Invoke(DispatcherPriority.Background, new ThreadStart(delegate()
                    {
                        canContinue = startAction();
                    }));
                    if (!canContinue)
                    {
                        return;
                    }

                    var gr = vissim.Instance.Graphics.Wrap();
                    bool wasVisualizationEnabled = gr.IsVisualizationEnabled;
                    if (!gr.IsVisualizationEnabled ^ parameters.DisableAnimation)
                    {
                        gr.IsVisualizationEnabled = !parameters.DisableAnimation;
                    }

                    var sim = vissim.Instance.Simulation;

                    long startTicks = DateTime.Now.Ticks;

                    //sim.RunMulti();

                    int i = 0;

                    simulationState.IsSimulationRunning = true;
                    try
                    {
                        while (parameters.NumberOfRuns > i && !simulationState.SimulationWasStopped)
                        {
                            sim.RunIndex   = i++;
                            sim.RandomSeed = (int)DateTime.Now.Ticks;
                            sim.Comment    = string.Format("Simulation random seed = {0}", sim.RandomSeed);

                            context.Invoke(DispatcherPriority.Normal, new ThreadStart(delegate()
                            {
                                stateChangedAction(string.Format("Simulation ...\nRun {0} of {1}", i, parameters.NumberOfRuns));
                            }));

                            aex.Protect(() => sim.RunContinuous());

                            aex.Protect(() => vissim.Instance.DoEvents());
                        }
                    }
                    finally
                    {
                        if (wasVisualizationEnabled != gr.IsVisualizationEnabled)
                        {
                            gr.IsVisualizationEnabled = wasVisualizationEnabled;
                        }
                        simulationState.IsSimulationRunning = false;
                        if (simulationState.SimulationWasStopped)
                        {
                            simulationState.SimulationWasStopped = false;
                        }
                    }

                    var data = new Experiment.ExperimentData()
                    {
                        CreatedOn = DateTime.Now,
                        Duration  = new TimeSpan(DateTime.Now.Ticks - startTicks),
                        //Period = new TimeSpan(0, 0, (int)sim.Period * i),
                        IsCountersEvaluationEnabled    = vissim.Instance.Evaluation.Wrap().IsDataCollectionsEnabled,
                        IsTravelTimesEvaluationEnabled = vissim.Instance.Evaluation.Wrap().IsTravelTimeEnabled,
                        NumberOfRuns = i
                    };

                    context.Invoke(DispatcherPriority.Background,
                                   new ThreadStart(delegate()
                    {
                        endAction(data);
                    }));
                });
            });
        }