Beispiel #1
0
        public void DrawGraph(CompleteGraph graph, AgentManager agentManager)
        {
            Graphics graphics = visualizer.CreateGraphics();

            graphics.Clear(Color.YellowGreen);

            Font         drawFont   = new Font("Arial", 12);
            SolidBrush   drawBrush  = new SolidBrush(Color.Black);
            StringFormat drawFormat = new StringFormat();

            foreach (var vertex in graph.Vertices)
            {
                Rectangle rectangle = new Rectangle(
                    vertex.Position.X - (VERTEX_RADIUS / 2), vertex.Position.Y - (VERTEX_RADIUS / 2), VERTEX_RADIUS, VERTEX_RADIUS);
                if (agentManager.Agents.Exists(agent => agent.ActualPosition == vertex.Id))
                {
                    graphics.FillEllipse(new SolidBrush(Color.Red), rectangle);
                }
                else if (vertex.Used)
                {
                    graphics.FillEllipse(new SolidBrush(Color.Yellow), rectangle);
                }
                else
                {
                    graphics.FillEllipse(new SolidBrush(Color.Black), rectangle);
                }
                string drawString = ((char)(vertex.Id + 65)).ToString();
                graphics.DrawString(drawString, drawFont, drawBrush, vertex.Position.X, vertex.Position.Y, drawFormat);
            }

            Pen pen = null;

            foreach (var edge in graph.Edges)
            {
                if (edge.Used)
                {
                    drawBrush = new SolidBrush(Color.Yellow);
                    pen       = Pens.Yellow;
                }
                else
                {
                    drawBrush = new SolidBrush(Color.Black);
                    pen       = Pens.Black;
                }
                graphics.DrawLine(pen, new Point(edge.StartVertex.Position.X, edge.StartVertex.Position.Y), new Point(edge.EndVertex.Position.X, edge.EndVertex.Position.Y));
                string drawString = edge.Weight.ToString();

                graphics.DrawString(drawString, drawFont, drawBrush, (edge.StartVertex.Position.X + edge.EndVertex.Position.X) / 2, (edge.StartVertex.Position.Y + edge.EndVertex.Position.Y) / 2, drawFormat);
            }
        }
Beispiel #2
0
        private void SaveConfigurationButton_Click(object sender, EventArgs e)
        {
            if (ConfigurationName.Text == null)
            {
                MessageBox.Show("Please name your configuration!");
            }

            FileManager fm = new FileManager();

            CompleteGraph graph        = fm.readGraphFromFile(VertexCoordPath.Text);
            AgentManager  agentManager = fm.readAgentsFromFile(AgentPath.Text);

            Configuration conf = new Configuration(ConfigurationName.Text, graph, agentManager);

            if (conf != null)
            {
                MessageBox.Show("Configuration " + conf.Name + " saved!");
            }

            fm.saveConfiguration(conf);
        }
 public Configuration(string name, CompleteGraph graph, AgentManager agentManager)
 {
     Name         = name;
     Graph        = graph;
     AgentManager = agentManager;
 }