Beispiel #1
0
        /// <summary>
        /// Runs multiple simulations and count compete cells every countStep. This test is designed for
        /// Septum objects
        /// </summary>
        /// <param name="numberOfRuns">Number of simulation runs</param>
        /// <param name="numberOfSteps">Number of simulation steps within each run</param>
        /// <param name="countStep">Count complete septums every step</param>
        /// <param name="tileName">Name of the tile.</param>
        /// <param name="numberOfKills">Number of object to be hurt.</param>
        /// <param name="probabilityOfTheKill">TODO</param>
        /// <param name="probabilistic">Flag for using random mechanism of choosing step.</param>
        private void RunMultipleSimulationsV2(int numberOfRuns,
                                              int numberOfSteps,
                                              int countStep,
                                              string tileName,
                                              double probabilityOfTheKill,
                                              long numberOfKills = -1,
                                              bool probabilistic = true)
        {
            // ReSharper disable once UnusedVariable
            using (WaitCursor cursor = new WaitCursor())
            {
                VisualizeLogging.LogMessageAndVisualize(string.Format("MSystemStats multiple runs V2 started (numberOfRuns={0}, numberOfSteps={1}, countStep={2}, tileName={3}, probabilityOfTheKill={4}, numberOfKills={5}, probabilistic={6})",
                                                                      numberOfRuns, numberOfSteps, countStep, tileName, probabilityOfTheKill, numberOfKills, probabilistic));

                // write down headline
                string headLine = "STAT>> RunNo,StepNo,Fail";
                for (int i = 0; i < 41; i++)
                {
                    headLine += string.Format(",T_{0}", i);
                }
                VisualizeLogging.LogMessageAndVisualize(headLine);

                ulong runNo = 1;
                for (int i = 0; i < numberOfRuns; i++, runNo++)
                {
                    // create simulator
                    Simulator simulator;
                    try
                    {
                        simulator = new Simulator(v_MSystemObjects, v_SerializeFloatingObjects);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(string.Format("Failed to create simulator object in run no. {0}. ExceptionMessage: {1}", runNo, e.Message));
                        return;
                    }

                    // do one run
                    try
                    {
                        string res = "";
                        // numberOfKills is -1 => we want to choose the kills purely probabilisticly
                        if (numberOfKills == -1)
                        {
                            res = simulator.RunSimulationV2(numberOfSteps, countStep, runNo, tileName, probabilityOfTheKill);
                        }
                        else
                        {
                            res = simulator.RunSimulationV2(numberOfSteps, countStep, runNo, tileName, numberOfKills, probabilistic);
                        }
                        VisualizeLogging.LogMessageAndVisualize(res);
                    }
                    catch (Exception e)
                    {
                        // this particular run has failed but we continue
                        VisualizeLogging.LogMessageAndVisualize(string.Format("MSystemStats run no.{0} failed. Exception:{1}", runNo, e));
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Vizualizes message from notification reciever.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event parameter.</param>
        private void VisualizeNotification(object sender, PropertyChangedEventArgs e)
        {
            NotificationMessage notification = TypeUtil.TryCast <NotificationMessage>(sender);

            if (notification != null)
            {
                VisualizeLogging.LogMessageAndVisualize(notification.Message);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Restarts simulation engine.
        /// </summary>
        private void RestartSimulator()
        {
            VisualizeLogging.LogMessageAndVisualize("Simulator restart.");
            ResetUi();
            Simulator.SimulationCurrentState = Simulator.SimulationControlFlags.Stop;
            v_Simulator = new Simulator(v_MSystemObjects, v_SerializeFloatingObjects);

            if (!v_ReciverInitialized)
            {
                //Reciever initializing and creating binding for method which rises on PropertyChanged event - aka new message arrived.
                NotificationMessage notificationReciever = v_Simulator.GetNotificationReciever();
                notificationReciever.PropertyChanged += VisualizeNotification;
            }
        }
Beispiel #4
0
        /// <summary>
        /// --- Load example -> M System description - Click event ---
        /// Opens OpenFileDialog, M System description file and deserialize input.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event parameter.</param>
        private void mSystemDescriptionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter      = "XML Files (.xml)|*.xml";
                openFileDialog.Multiselect = false;
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Check if selected file is really evolution file.
                    XDocument doc = XDocument.Load(openFileDialog.FileName);
                    if (doc.Element("root") == null)
                    {
                        throw new InvalidOperationException("Selected file is not an M System description file.");
                    }
                    v_MSystemObjectsPath = openFileDialog.FileName;

                    //XSD validation
                    if (v_ValidateUsingXSD)
                    {
                        string errorsAndWarnings;
                        if (!XmlValidator.Validate(v_MSystemObjectsPath, v_XSDPath, out errorsAndWarnings))
                        {
                            throw new ValidationFailed(errorsAndWarnings);
                        }
                    }

                    string errorMessage;
                    IDeserializedObjects deserializedObjects = Xmlizer.Deserialize(v_MSystemObjectsPath, out errorMessage);
                    if (deserializedObjects == null)
                    {
                        richTextBoxMSystem.Text = errorMessage;
                        return;
                    }
                    v_MSystemObjects = TypeUtil.Cast <DeserializedObjects>(deserializedObjects);
                    RestartSimulator();

                    richTextBoxMSystem.Text = v_Simulator.MSystemToString();
                    VisualizeLogging.LogMessageAndVisualize("Deserialization of M System description file was successful.");
                    VisualizeLogging.LogMessageAndVisualize(string.Format("File: {0}", openFileDialog.FileName));
                }
            }
            catch (Exception exception)
            {
                ExceptionWindow.Show(exception);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Saves Snapshot.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event parameter.</param>
 private void saveSnapshotToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (v_Simulator == null)
     {
         ShowLoadSimulationMessage();
         return;
     }
     using (SaveFileDialog saveFileDialog = new SaveFileDialog())
     {
         saveFileDialog.Filter = "XML files (*.xml)|*.xml";
         if (saveFileDialog.ShowDialog() == DialogResult.OK)
         {
             string savePath = saveFileDialog.FileName;
             v_Simulator.SaveSnapshotsWithSpecificLocation(savePath);
             VisualizeLogging.LogMessageAndVisualize(string.Format("Snapshot save to {0}", savePath));
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// Run One Off Damage test. For more information, see test description document.
        /// </summary>
        /// <param name="numberOfRuns">Number of runs (experiments) to perform.</param>
        /// <param name="tileName">Name of the targeted tile, empty string means any randomly chosen tile.</param>
        /// <param name="numberOfTiles">Number of tiles to remove.</param>
        /// <param name="onlyPologon3DTiles">If TRUE then only tiles of type Pologon3D type are being removed</param>
        /// <param name="numberOfRecoverySteps">Number of system iterations given the system to recover.</param>
        private void RunOneOffDamageTest(int numberOfRuns, string tileName, int numberOfTiles, bool onlyPologon3DTiles, int numberOfRecoverySteps)
        {
            // ReSharper disable once UnusedVariable
            using (WaitCursor cursor = new WaitCursor())
            {
                VisualizeLogging.LogMessageAndVisualize(string.Format("RunOneOffDamageTest started (numberOfRuns={0}, tileName={1}, numberOfTiles={2}, numberOfRecoverySteps = {3})",
                                                                      numberOfRuns, tileName, numberOfTiles, numberOfRecoverySteps));

                // write down headline
                string headLine = "STAT>> RunNo,InitialStepNo,FurtherStepNo";
                for (int i = 0; i < 41; i++)
                {
                    headLine += string.Format(",T_{0}", i);
                }
                VisualizeLogging.LogMessageAndVisualize(headLine);

                for (int i = 0; i < numberOfRuns; i++)
                {
                    // create simulator
                    Simulator simulator;
                    try
                    {
                        simulator = new Simulator(v_MSystemObjects, v_SerializeFloatingObjects);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(string.Format("Failed to create simulator object in run no. {0}. ExceptionMessage: {1}", i + 1, e.Message));
                        return;
                    }

                    // do one run
                    try
                    {
                        string res = simulator.RunSimulationOneOffDamage(i + 1, tileName, numberOfTiles, onlyPologon3DTiles, numberOfRecoverySteps);
                        VisualizeLogging.LogMessageAndVisualize(res);
                    }
                    catch (Exception e)
                    {
                        // this particular run has failed but we continue
                        VisualizeLogging.LogMessageAndVisualize(string.Format("MSystemStats run no.{0} failed. Exception:{1}", i + 1, e));
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Runs multiple simulations with specified
        /// </summary>
        /// <param name="numberOfRuns">Number of simulation runs</param>
        /// <param name="numberOfSteps">Number of simulation steps within each run</param>
        /// <param name="tileName">Name of the tile.</param>
        /// <param name="numberOfKills">Number of object to be hurt.</param>
        /// <param name="probabilityOfTheKill">TODO</param>
        /// <param name="probabilistic">Flag for using random mechanism of choosing step.</param>
        private void RunMultipleSimulations(int numberOfRuns, int numberOfSteps, string tileName,
                                            double probabilityOfTheKill, long numberOfKills = -1, bool probabilistic = true)
        {
            // ReSharper disable once UnusedVariable
            using (WaitCursor cursor = new WaitCursor())
            {
                VisualizeLogging.LogSimulationMessageAndVisualize(string.Format("MSystemStats multiple runs started (numberOfRuns={0}, numberOfSteps={1}, " +
                                                                                "tileName={2}, probabilityOfTheKill={3}, numberOfKills={4}, probabilistic={5}",
                                                                                numberOfRuns, numberOfSteps, tileName, probabilityOfTheKill, numberOfKills, probabilistic));

                List <MSystemStats> simulationStats = new List <MSystemStats>();
                ulong runNo = 1;
                for (int i = 0; i < numberOfRuns; i++, runNo++)
                {
                    // create simulator
                    Simulator simulator;
                    try
                    {
                        simulator = new Simulator(v_MSystemObjects, v_SerializeFloatingObjects);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(string.Format("Failed to create simulator object in run no. {0}. ExceptionMessage: {1}", runNo, e.Message));
                        return;
                    }

                    // do one run
                    try
                    {
                        // numberOfKills is -1 => we want to choose the kills purely probabilisticly
                        if (numberOfKills == -1)
                        {
                            simulator.RunSimulation(numberOfSteps, tileName, probabilityOfTheKill);
                        }
                        else
                        {
                            simulator.RunSimulation(numberOfSteps, tileName, numberOfKills, probabilistic);
                        }
                        MSystemStats systemStats = simulator.GetMSystemStats();
                        VisualizeLogging.LogSimulationMessageAndVisualize(systemStats.ToString()); //Log to simulation log as it is a part of simulation.
                        simulationStats.Add(systemStats);
                    }
                    catch (Exception)
                    {
                        // this particular run has failed but we continue
                        VisualizeLogging.LogSimulationMessageAndVisualize(string.Format("MSystemStats run no.{0} failed.", runNo));
                    }
                }
                // process stats - get average
                double sum = 0;
                foreach (MSystemStats element in simulationStats)
                {
                    sum += element.GetFullCellsCount();
                }
                double average = sum / simulationStats.Count;

                // process stats - get standard deviation
                sum = 0;
                foreach (MSystemStats element in simulationStats)
                {
                    sum += Math.Pow(average - element.GetFullCellsCount(), 2);
                }
                double stdDev = Math.Pow(sum / simulationStats.Count, 0.5); // square root
                // Write result to the log
                VisualizeLogging.LogSimulationMessageAndVisualize(string.Format("MSystemStats result: Runs = {0} Average = {1} Std. deviation = {2}", simulationStats.Count, average, stdDev));
            }
        }
Beispiel #8
0
 /// <summary>
 /// Stop simulation.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event parameter.</param>
 private void buttonStop_Click(object sender, EventArgs e)
 {
     VisualizeLogging.LogMessageAndVisualize("Simulation stopping...");
     Simulator.SimulationCurrentState = Simulator.SimulationControlFlags.Stop;
 }