Beispiel #1
0
        public void SetAlgorithmTest()
        {
            ISimulationHandler handler = new SimulationHandler();

            handler.SetAlgorithm(Algorithm);
            Assert.AreEqual(Algorithm, handler.Algorithm);
        }
Beispiel #2
0
    public static void handleDayChange(string action)
    {
        //Run SimulationHandler.handleSimulation() here
        if (action == "sleep")
        {
            EnergyHandler.handleEnergy(action);
        }
        else if (action == "nap")
        {
            EnergyHandler.handleEnergy(action);
        }
        else if (action == "training")
        {
            EnergyHandler.handleEnergy(action);
        }
        GlobalData.globalData.days    += 1;
        GlobalData.globalData.weekDay += 1;
        GlobalData.globalData.dayCycle = "Morning";

        if (GlobalData.globalData.weekDay == 7)
        {
            GlobalData.globalData.weekDay = 0;
        }
        handleWeek();

        days      = (double)GlobalData.globalData.days / 28;
        isInteger = unchecked (days == (int)days);
        if (isInteger)
        {
            handleMonthChange();
        }
        SimulationHandler.handleSimulation();
        SceneManager.LoadScene("The City", LoadSceneMode.Single);
    }
Beispiel #3
0
        public void SetSimulationTypeTest()
        {
            ISimulationHandler handler = new SimulationHandler();

            handler.SetSimulationType(SimulationType);
            Assert.AreEqual(SimulationType, handler.SimulationType);
        }
Beispiel #4
0
        public void ConstructorTest_IAlgorithmAndSimulationType_AsParameter()
        {
            ISimulationHandler handler = new SimulationHandler(Algorithm, SimulationType);

            Assert.AreEqual(Algorithm, handler.Algorithm);
            Assert.AreEqual(SimulationType, handler.SimulationType);
        }
Beispiel #5
0
        public void ConstructorTest_NoParameter()
        {
            ISimulationHandler handler = new SimulationHandler();

            Assert.IsNull(handler.Algorithm);
            Assert.IsNull(handler.SimulationType);
        }
Beispiel #6
0
 /// <summary>
 /// Stops the paused simulation and flushes memory
 /// </summary>
 public void Reset()
 {
     SimulationHandler.StopSimulation();
     SimulationHandler.Simulation.ResetSimulationStep();  // reset simulation step back to 0
     m_monitors.Clear();
     m_results.Clear();
     m_resultIdCounter = 0;
 }
Beispiel #7
0
        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            StoreViewsLayout(UserLayoutFileName);

            Properties.Settings.Default.RecentFilesList = new StringCollection();
            Properties.Settings.Default.RecentFilesList.AddRange(m_recentMenu.GetFiles());

            Properties.Settings.Default.Save();

            SimulationHandler.Finish();
        }
Beispiel #8
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (m_isClosing)
            {
                return;
            }

            // Cancel the event - the window will close when the simulation is finished.
            e.Cancel = true;

            if (SimulationHandler.State != MySimulationHandler.SimulationState.STOPPED)
            {
                DialogResult dialogResult = DialogResult.None;

                PauseSimulationForAction(() =>
                {
                    dialogResult =
                        MessageBox.Show(
                            "Do you want to quit while the simulation is running?",
                            "Quit?",
                            MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    return(dialogResult == DialogResult.No);
                });

                if (dialogResult == DialogResult.No)
                {
                    return;
                }
            }

            if (!Project.HasBeenNamed || !IsProjectSaved())
            {
                var dialogResult = MessageBox.Show("Save project changes?",
                                                   "Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                // Do not close.
                if (dialogResult == DialogResult.Cancel)
                {
                    return;
                }

                if (dialogResult == DialogResult.Yes)
                {
                    SaveProjectOrSaveAs();
                }
            }

            // When this is true, the event will just return next time it's called.
            m_isClosing = true;
            SimulationHandler.Finish(Close);
        }
Beispiel #9
0
        private void StartSimulation(bool oneStepOnly)
        {
            if (SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED)
            {
                MyLog.INFO.WriteLine("--------------");
                bool anyOutputChanged = UpdateMemoryModel();

                MyValidator validator = ValidationView.Validator;
                validator.Simulation = SimulationHandler.Simulation;

                validator.ClearValidation();

                Project.World.ValidateWorld(validator);
                Project.Network.Validate(validator);

                validator.AssertError(!anyOutputChanged, Project.Network, "Possible infinite loop in memory block sizes.");

                ValidationView.UpdateListView();
                validator.Simulation = null;

                ResetObservers();

                if (validator.ValidationSucessfull)
                {
                    try
                    {
                        SimulationHandler.StartSimulation(oneStepOnly);
                    }
                    catch (Exception e)
                    {
                        MyLog.ERROR.WriteLine("Simulation cannot be started! Exception occured: " + e.Message);
                    }
                }
                else
                {
                    MyLog.ERROR.WriteLine("Simulation cannot be started! Validation failed.");
                    OpenFloatingOrActivate(ValidationView);
                }
            }
            else
            {
                try
                {
                    SimulationHandler.StartSimulation(oneStepOnly);
                }
                catch (Exception e)
                {
                    MyLog.ERROR.WriteLine("Simulation cannot be started! Exception occured: " + e.Message);
                }
            }
        }
Beispiel #10
0
 private void updateMemoryBlocksToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         SimulationHandler.UpdateMemoryModel();
     }
     finally
     {
         foreach (GraphLayoutForm graphView in GraphViews.Values)
         {
             graphView.Desktop.Invalidate();
         }
     }
 }
Beispiel #11
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (m_isClosing)
            {
                return;
            }

            // Cancel the event - the window will close when the simulation is finished.
            e.Cancel = true;

            if (SimulationHandler.State != MySimulationHandler.SimulationState.STOPPED)
            {
                DialogResult dialogResult = DialogResult.None;

                PauseSimulationForAction(() =>
                {
                    dialogResult =
                        MessageBox.Show(
                            "Do you want to quit while the simulation is running?",
                            "Quit?",
                            MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    return(dialogResult == DialogResult.No);
                });

                if (dialogResult == DialogResult.No)
                {
                    return;
                }
            }

            if (AskToSaveProjectAndForwardDialogResult() == DialogResult.Cancel)
            {
                return;
            }

            SaveWindowPlacement();

            // When this is true, the event will just return next time it's called.
            m_isClosing = true;

            SimulationHandler.Finish(Close);
        }
Beispiel #12
0
        /// <summary>
        /// Runs simulation for a given number of steps. Simulation will be left in PAUSED state after
        /// this function returns, allowing to inspect content of memory blocks and then perhaps
        /// resume the simulation by calling this function again.
        /// </summary>
        /// <param name="stepCount">Number of steps to perform</param>
        /// <param name="reportInterval">Step count between printing out simulation info (e.g. speed)</param>
        public void RunAndPause(uint stepCount, uint reportInterval = 100)
        {
            if (stepCount == 0)
            {
                throw new ArgumentException("Zero step count not allowed.", "stepCount");  // would run forever
            }
            // TODO(Premek): Add a check that that simulation is not finished

            if (SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED)
            {
                if (SimulationHandler.UpdateMemoryModel())
                {
                    MyLog.ERROR.WriteLine("Simulation cannot be started! Memory model did not converge.");
                    return;
                }

                SimulationHandler.Simulation.Validate(Project);

                MyValidator validator = SimulationHandler.Simulation.Validator;

                if (!validator.ValidationSucessfull)
                {
                    MyLog.ERROR.WriteLine("Simulation cannot be started! Validation failed.");
                    return;
                }
            }

            try
            {
                SimulationHandler.ReportIntervalSteps = reportInterval;
                SimulationHandler.StartSimulation(stepCount);
                SimulationHandler.WaitUntilStepsPerformed();
            }
            catch (Exception e)
            {
                MyLog.ERROR.WriteLine("Simulation cannot be started! Exception occured: " + e.Message);
                throw;
            }
        }
Beispiel #13
0
 private void stopToolButton_Click(object sender, EventArgs e)
 {
     SimulationHandler.StopSimulation();
     SimulationHandler.Simulation.InDebugMode = false;
 }
Beispiel #14
0
 /// <summary>
 /// Shutdown the runner and the underlaying simulation infrastructure
 /// </summary>
 public void Shutdown()
 {
     SimulationHandler.Finish();
 }
Beispiel #15
0
 public void stopToolButton_Click(object sender, EventArgs e)
 {
     ShowHideAllObservers(forceShow: true);
     SimulationHandler.StopSimulation();
     SimulationHandler.Simulation.InDebugMode = false;
 }
Beispiel #16
0
 public void pauseToolButton_Click(object sender, EventArgs e)
 {
     ShowHideAllObservers(forceShow: true);
     SimulationHandler.PauseSimulation();
 }
Beispiel #17
0
 private void pauseToolButton_Click(object sender, EventArgs e)
 {
     SimulationHandler.PauseSimulation();
 }