void WriteAlgorithmBenchmark(iTextSharp.text.Document doc, ISearchAlgorithm <string> algorithm, SearchReport <string> report)
        {
            iTextSharp.text.pdf.draw.LineSeparator line = new iTextSharp.text.pdf.draw.LineSeparator(1f, 100f, iTextSharp.text.BaseColor.BLACK, iTextSharp.text.Element.ALIGN_CENTER, -1);
            iTextSharp.text.Chunk linebreak             = new iTextSharp.text.Chunk(line);
            Chunk c = new Chunk(algorithm.Name, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 24, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE));

            c.SetGenericTag(algorithm.Name);
            doc.Add(new Paragraph(c));
            // algorithm description
            Chunk desc = new Chunk(algorithm.Description, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.ITALIC, iTextSharp.text.BaseColor.BLACK));

            doc.Add(new Paragraph(desc));
            // algorithm benchmark
            Chunk time = new Chunk("The algorithm took " + report.ElapsedTime + " to find the goal.", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLACK));

            doc.Add(new Paragraph(time));

            // path
            time = new Chunk("The result path costs " + algorithm.CalculateCost(report.Result), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLACK));
            doc.Add(new Paragraph(time));
            // write steps
            foreach (var step in report.Steps)
            {
                WriteAlgorithmStep(doc, step.StepInformation, step.GraphCapture);
            }

            doc.NewPage();
        }
Beispiel #2
0
        public void RunSimulation()
        {
            try
            {
                this.Invoke(new Action(delegate
                {
                    _gArea.ResetNodesColor();
                    tracetxt.Text = "";
                }));
                selected_algorithm = (algorithms.SelectedItem as ComboBoxItem).Tag as ISearchAlgorithm <string>;
                Node <string> initial = (start_node.SelectedItem as ComboBoxItem).Tag as Node <string>;
                Node <string> final   = (goal_node.SelectedItem as ComboBoxItem).Tag as Node <string>;
                this.Invoke(new Action(delegate
                {
                    _gArea.ResetInitialGoal();
                    _gArea.SetInitialGoal(initial, final);
                    selected_algorithm.Logged = checkBoxX1.Checked;
                }));
                selected_algorithm.OnResultFound   += Selected_algorithm_OnResultFound;
                selected_algorithm.OnResetRequired += Selected_algorithm_OnResetRequired;

                // set event handlers
                simulation_thread = new Thread(new ThreadStart(delegate
                {
                    sw.Start();
                    try
                    {
                        selected_algorithm.Initialize();
                        var sr = selected_algorithm.Search(initial, final.Key);
                        this.Invoke(new Action(delegate
                        {
                            selected_algorithm.OnResultFound   -= Selected_algorithm_OnResultFound;
                            selected_algorithm.OnResetRequired -= Selected_algorithm_OnResetRequired;
                            buttonX1.Text     = "Run";
                            simulation_thread = null;
                            if (sr.Found)
                            {
                                _gArea.ColorizePath(sr, Brushes.Red);
                                TracePath(sr);
                            }
                            this.Invoke(new Action(delegate
                            {
                                tracetxt.AppendText("The path cost is " + selected_algorithm.CalculateCost(sr) + Environment.NewLine);
                            }));
                            MessageBoxEx.Show(this, "Simulation complete", "Simulation",
                                              MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }));
                    }
                    catch (Exception ex)
                    {
                        this.Invoke(new Action(delegate
                        {
                            MessageBoxEx.Show(this, ex.Message, "Simulation Process", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        }));
                    }
                    sw.Stop();
                    this.Invoke(new Action(delegate
                    {
                        tracetxt.AppendText("Elapsed time: " + sw.Elapsed);
                    }));
                }));
                simulation_thread.Start();
            }catch (Exception ex)
            {
                MessageBoxEx.Show(this, ex.Message, "Simulation Execution", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }