Example #1
0
        void tc_Multi()
        {
            RaiseEvent(new RoutedEventArgs(TreeControl.MultiEvent));

            ShadowMaker.ShadowUp();
            modelControlGrid.IsEnabled = false;

            var x = new StartMultirunBindingSource()
            {
                DisableAnimation = true,
                NumberOfRuns     = 3
            };

            var startCtrl = new StartMultirunControl();

            startCtrl.DataContext      = x;
            startCtrl.btnCancel.Click += (sender_, e_) =>
            {
                ShadowMaker.ShadowDown();
                modelControlGrid.IsEnabled = true;
            };
            startCtrl.btnOk.Click += (sender_, e_) =>
            {
                ShadowMaker.ShadowDown();

                if (x.NumberOfRuns > 0)
                {
                    var lc = new LoadingControl();
                    if (!vissim.IsInstanciated)
                    {
                        lc.Message = "Starting VISSIM ...";
                    }
                    else
                    {
                        lc.Message = "Simulation ...";
                    }
                    ShadowMaker.ShowThis(lc);

                    experimenter.RunMultiAsync(x, this.Dispatcher
                                               , StartAction
                                               , (expData) =>
                    {
                        var ctrl = CreateCreateExperimentControl(expData);
                        ShadowMaker.ShowThis(ctrl);
                    }
                                               , (message) =>
                    {
                        lc.Message = message;
                    }
                                               );
                }
                else
                {
                    ShadowMaker.ShowThis(startCtrl);
                }

                ShadowMaker.ShadowUp();
            };

            ShadowMaker.ShowThis(startCtrl);
        }
Example #2
0
        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);
                    }));
                });
            });
        }