예제 #1
0
        public void drawTree(Bitmap img, Color vertexColor)
        {
            Graphics g           = Graphics.FromImage(img);
            Font     drawFont    = new Font("Arial", 15);
            Font     weightFont  = new Font("Arial", 10);
            Font     orderFont   = new Font("Arial", 15);
            Pen      plumaArista = new Pen(Color.Pink, 3);

            SolidBrush drawBrush   = new SolidBrush(Color.Purple);
            SolidBrush vertexBrush = new SolidBrush(vertexColor);
            SolidBrush weightBrush = new SolidBrush(Color.Orange);
            SolidBrush orderBrush  = new SolidBrush(Color.Red);



            foreach (Vertice vertice in vertices)
            {
                foreach (Arista arista in vertice.GetAristas())
                {
                    g.DrawLine(plumaArista, vertice.GetCoordenada(), arista.GetSig().GetCoordenada());
                    //g.DrawString(arista.GetPeso().ToString(), weightFont, weightBrush, (vertice.GetCoordenada().X + arista.GetSig().GetCoordenada().X)/2, (vertice.GetCoordenada().Y + arista.GetSig().GetCoordenada().Y) / 2);
                }
            }

            foreach (Vertice vertice in vertices)
            {
                vertice.graficarVertice(vertexBrush, img);

                g.DrawString(contextID + vertice.GetGroup().ToString(), drawFont, drawBrush, vertice.GetCoordenada().X - 15, vertice.GetCoordenada().Y - 10);
            }

            int o = 1;

            foreach (Arista arista in ordenAristas)
            {
                Vertice vertice = this.findvertice(arista.GetVid());
                g.DrawString(o.ToString(), orderFont, orderBrush, (vertice.GetCoordenada().X + arista.GetSig().GetCoordenada().X) / 2, (vertice.GetCoordenada().Y + arista.GetSig().GetCoordenada().Y) / 2);
                g.DrawString(arista.GetPeso().ToString(), weightFont, weightBrush, (vertice.GetCoordenada().X - 30 + arista.GetSig().GetCoordenada().X) / 2, (vertice.GetCoordenada().Y - 30 + arista.GetSig().GetCoordenada().Y) / 2);

                o++;
            }
        }
예제 #2
0
 public Arista(Vertice vertice, int peso, String vid = "")
 {
     sig       = vertice;
     this.peso = peso;
     this.vid  = vid;
 }
예제 #3
0
 public void agregarArista(Vertice vertice, int peso, String vid = "")
 {
     this.aristas.Add(new Arista(vertice, peso, vid));
 }
예제 #4
0
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            if (grafodetectado)
            {
                Color pixel = imageCopy.GetPixel(e.X, e.Y);

                if (pixel.R == pixel.G && pixel.G == pixel.B && pixel.R != 255)
                {
                    List <Arista> prometodor  = new List <Arista>();
                    List <string> visited     = new List <string>();
                    List <Arista> aristaQueue = new List <Arista>();
                    //List<Tuple<String, Arista>> tuplaArista = new List<Tuple<string, Arista>>();
                    Vertice vertice_click = Utilities.BelongsTo(e.X, e.Y, grafo, imageCopy);
                    Tree    newPrim       = new Tree("P");
                    if (vertice_click != null && !Utilities.isInsideTree(ARMPrim, vertice_click))
                    {
                        foreach (Vertice ver in grafo.GetSubgraphs()[vertice_click.GetGroup() - 1])
                        {
                            var nuevoVertice = new Vertice(ver.GetCoordenada(), ver.GetRadius(), ver.GetArea(), ver.GetId());
                            nuevoVertice.SetGroup(ver.GetGroup());
                            newPrim.addVertice(nuevoVertice);
                        }

                        foreach (Arista arista in vertice_click.GetAristas())
                        {
                            //tuplaArista.Add(new Tuple<String, Arista>(vertice_click.GetId(),arista));
                            aristaQueue.Add(arista);
                        }

                        Arista minArista;
                        visited.Add(vertice_click.GetId());
                        while (aristaQueue.Count > 0)
                        {
                            minArista = Utilities.getMinArtista(aristaQueue);

                            if (!visited.Contains(minArista.GetSig().GetId()))
                            {
                                newPrim.findvertice(minArista.GetVid()).agregarArista(minArista.GetSig(), minArista.GetPeso());
                                prometodor.Add(minArista);
                                visited.Add(minArista.GetSig().GetId());
                                foreach (Arista arista in minArista.GetSig().GetAristas())
                                {
                                    if (!visited.Contains(arista.GetSig().GetId()))
                                    {
                                        aristaQueue.Add(arista);
                                    }
                                }
                            }
                            aristaQueue.Remove(minArista);
                        }
                        newPrim.SetOrdenAristas(prometodor);
                        newPrim.calcularPesoTotal();
                        ARMPrim.Add(newPrim);
                        PrimG.Text          = ARMPrim.Count.ToString();
                        PrimList.DataSource = null;
                        PrimList.DataSource = ARMPrim.OrderBy(x => x.GetVertices()[0].GetGroup()).ToList();
                        newPrim.drawTree(Prim, Color.Yellow);
                        pictureBox1.Image  = Prim;
                        verPrim.Enabled    = false;
                        verGrafo.Enabled   = true;
                        verkruskal.Enabled = true;
                    }
                }
            }
        }
예제 #5
0
 public void addVertice(Vertice vertice)
 {
     vertices.Add(vertice);
 }