void inicializaCC(Grafo g) { for (int i = 0; i < g.getListaNodos().Count; i++) { cc.Add(g.getListaNodos()[i].getCiudad().ToString()); } }
private void panel1_MouseClick(object sender, MouseEventArgs e) { bool pos = true; foreach (Nodo n in g.getListaNodos()) { if (!((n.getX() <= e.X - 50 || n.getX() >= e.X + 25) || (n.getY() <= e.Y - 50 || n.getY() >= e.Y + 25))) { pos = false; } } if (pintar && pos) { Pen p1 = new Pen(Color.Red, 4); n.setX(e.X - 25); n.setY(e.Y - 25); pintar = false; } Pen p3 = new Pen(Color.Green, 2); imprimirCiudades(g, p3); }
void ActualizaPesos(List <ElementoDijkstra> VD, Nodo n, Grafo g, int p, char opc) { ElementoDijkstra ed; if (g.getListaNodos().Contains(n)) { foreach (Ady a in n.getListaAdy()) { ed = BuscaElementoDijkstra(VD, a); if (opc == 'c') { if (p + a.getcosto() < ed.getPeso()) { ed.setPeso(p + a.getcosto()); ed.setProv(n); } } else { if (p + a.getTiempo() < ed.getPeso()) { ed.setPeso(p + a.getTiempo()); ed.setProv(n); } } } } }
void Inicializa(Grafo g, Nodo inicial, Nodo final) { foreach (Nodo n in g.getListaNodos()) { if (n == final) { VD.Add(new ElementoDijkstra(n, 10000, false)); } } foreach (Nodo n in g.getListaNodos()) { if (n == inicial) { VD.Add(new ElementoDijkstra(n, 0, true)); } else if (n != final) { VD.Add(new ElementoDijkstra(n, 10000, false)); } } }
private void imprimirCiudades(Grafo gf, Pen p3) { int x1, x2, y1, y2; foreach (Nodo n in gf.getListaNodos()) { if (n.getX() >= 0 && n.getY() >= 0) { Pen p2 = new Pen(Color.Blue, 4); panel1.CreateGraphics().DrawEllipse(p2, n.getX(), n.getY(), 50, 50); panel1.CreateGraphics().DrawString(Char.ToString(n.getCiudad()), new Font("Arial", 20), new SolidBrush(Color.Blue), new RectangleF(n.getX() + 10, n.getY() + 10, 50, 50), new StringFormat()); foreach (Ady a in n.getListaAdy()) { if (a.getNodo().getX() >= 0 && a.getNodo().getY() >= 0) { if (n.getY() < a.getNodo().getY()) { y1 = n.getY() + 40; y2 = a.getNodo().getY() + 10; } else { y1 = n.getY() + 10; y2 = a.getNodo().getY() + 40; } if (n.getX() < a.getNodo().getX()) { x1 = n.getX() + 40; x2 = a.getNodo().getX() + 10; panel1.CreateGraphics().DrawString(Convert.ToString("$" + a.getcosto() + "\n" + a.getTiempo() + "min."), new Font("ArialBlack", 10), new SolidBrush(Color.Black), new RectangleF(x1, y1, 50, 50), new StringFormat()); } else { x1 = n.getX() + 10; x2 = a.getNodo().getX() + 40; panel1.CreateGraphics().DrawString(Convert.ToString("$" + a.getcosto() + "\n" + a.getTiempo() + "min."), new Font("ArialBlack", 10), new SolidBrush(Color.Black), new RectangleF(x1 - 50, y1, 50, 50), new StringFormat()); } AdjustableArrowCap bigArrow = new AdjustableArrowCap(7, 7); p3.CustomEndCap = bigArrow; //panel1.CreateGraphics().DrawLine(p3,n.getX() + 25, n.getY() + 25, a.getNodo().getX() + 25, a.getNodo().getY() + 25); panel1.CreateGraphics().DrawLine(p3, x1, y1, x2, y2); } } } } foreach (Nodo n in gf.getListaNodos()) { if (n.getX() <= 1 || n.getY() <= 1) { establecerPosicion(n); break; } } }
private void listBoxRuta_SelectedIndexChanged(object sender, EventArgs e) { ListaVuelos vd = new ListaVuelos(); ElementoDijkstra ed2; foreach (ElementoDijkstra ed in d.getVD()) { if (ed == d.getVD()[listBoxRuta.SelectedIndex]) { ed2 = ed; if (ed.getPeso() != 10000) { if (radioButtonC.Checked == true) { textBoxPond2.Text = "$ " + ed.getPeso().ToString(); } else { textBoxPond2.Text = ed.getPeso().ToString() + " min."; } } else { textBoxPond2.Text = "No disponible"; } while (ed2.GetProv() != null) { foreach (Vuelo v in lv) { if (v.getOrigen() == ed2.GetProv().getCiudad() && v.getDestino() == ed2.GetDes().getCiudad()) { vd.Add(v); break; } } foreach (ElementoDijkstra aux in d.getVD()) { if (aux.GetDes().getCiudad() == ed2.GetProv().getCiudad()) { ed2 = aux; break; } } } break; } } Grafo gd = new Grafo(vd); foreach (Nodo n in g.getListaNodos()) { foreach (Nodo n2 in gd.getListaNodos()) { if (n.getCiudad() == n2.getCiudad()) { n2.setX(n.getX()); n2.setY(n.getY()); } } } panel1.Refresh(); Pen p1 = new Pen(Color.Red, 2); imprimirCiudades(gd, p1); }