コード例 #1
0
ファイル: MainForm.cs プロジェクト: retimarcell55/UtazoUgynok
        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);
            }
        }
コード例 #2
0
        public AgentManager readAgentsFromFile(String path)
        {
            AgentManager agentManager = new AgentManager();

            using (StreamReader sr = new StreamReader(path))
            {
                String[] data = sr.ReadLine().Split(' ');
                for (int i = 0; i < data.Length; i++)
                {
                    agentManager.Agents.Add(new Agent(i, int.Parse(data[i])));
                }
            }

            return(agentManager);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: retimarcell55/UtazoUgynok
        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);
        }
コード例 #4
0
 public Configuration(string name, CompleteGraph graph, AgentManager agentManager)
 {
     Name         = name;
     Graph        = graph;
     AgentManager = agentManager;
 }