private void changeEffectsState(Arista a, bool canDeactivate) { Cable spriteToActive = cableToActive.GetComponent <Cable>(); if (spriteToActive.arista._1().Equals(a._1()) && spriteToActive.arista._2().Equals(a._2()) && !canDeactivate) { spriteToActive.changeColliderState(false); for (int i = 0; i < spriteToActive.transform.childCount; i++) { spriteToActive.transform.GetChild(i).gameObject.SetActive(true); } } else { Debug.Log("Desactivamos los efectos"); //Desactivamos todos los efectos porque nos hemos equivocado Vertex[] vert = FindObjectsOfType <Vertex>(); for (int i = 0; i < vert.Length; i++) { vert[i].depush(); } Cable[] allCables = FindObjectsOfType <Cable>(); for (int i = 0; i < allCables.Length; i++) { allCables[i].changeColliderState(true); for (int j = 0; j < allCables[i].transform.childCount; j++) { allCables[i].transform.GetChild(j).gameObject.SetActive(false); } } } }
public Arista this[TAristas idx] { get { Arista arista = !_AristasLock.TryGetValue(idx, out arista) ? _AristasFree.FirstOrDefault(/*arst => arst.Pass*/) : arista; return(arista); } }
void Start() { graphDict = new Dictionary <string, Arista[]>(); ad = new Arista("a", "d", 5); ab = new Arista("a", "b", 7); db = new Arista("d", "b", 9); de = new Arista("d", "e", 15); df = new Arista("d", "f", 6); be = new Arista("b", "e", 7); bc = new Arista("b", "c", 8); ec = new Arista("e", "c", 5); eg = new Arista("e", "g", 9); fe = new Arista("f", "e", 8); fg = new Arista("f", "g", 11); a = new Arista[] { ad, ab }; d = new Arista[] { ad, db, de, df }; b = new Arista[] { ab, db, be, bc }; f = new Arista[] { df, fe, fg }; c = new Arista[] { bc, ec }; e = new Arista[] { be, de, fe, ec, eg }; g = new Arista[] { fg, eg }; aristas = new Arista[][] { a, b, c, d, e, f, g }; vertices = new string[] { "a", "b", "c", "d", "e", "f", "g" }; //Tiene que haber tantos vertices como aristas for (int i = 0; i < vertices.Length; i++) { graphDict.Add(vertices[i], aristas[i]); } }
public BellmanFord() //main { // Ejemplo: Nodo a = new Nodo("1"); Nodo b = new Nodo("2"); Nodo c = new Nodo("3"); Nodo d = new Nodo("4"); Nodo e = new Nodo("5"); Nodo f = new Nodo("6"); Nodo g = new Nodo("7"); List <Nodo> nodos = new List <Nodo>() { a, b, c, d, e, f, g }; Arista ar1 = new Arista(a, b, 6); Arista ar2 = new Arista(a, c, 5); Arista ar3 = new Arista(a, d, 5); Arista ar4 = new Arista(b, e, -1); Arista ar5 = new Arista(c, b, -2); Arista ar6 = new Arista(c, e, -2); Arista ar7 = new Arista(d, c, -2); Arista ar8 = new Arista(d, f, -1); Arista ar9 = new Arista(e, g, 3); Arista ar10 = new Arista(f, g, 3); List <Arista> aristas = new List <Arista>() { ar1, ar2, ar3, ar4, ar5, ar6, ar7, ar8, ar9, ar10 }; Algoritmo(aristas, nodos, nodos[0]); }
public void Enqueue(Arista a) { Node nuevoNodo = new Node(); nuevoNodo.Peso = a.Peso; nuevoNodo.Arista = a; if (this._root == null || a.Peso < this._root.Peso) { nuevoNodo.Next = this._root; this._root = nuevoNodo; } else { Node aux = this._root; while (aux.Next != null && a.Peso >= aux.Peso) { aux = aux.Next; } nuevoNodo.Next = aux.Next; aux.Next = nuevoNodo; } return; }
static List<Arista> CalcPrim(int[,] grafo, int tam) { int[] costemín = Enumerable.Range(0, tam).Select(x => grafo[0, x]).ToArray(); int[] conexión = Enumerable.Range(0, tam).Select(x => 0).ToArray(); List<Arista> arm = new List<Arista>(); Arista aux; int mínimo, elegido = 0; for(int i = 1; i < tam; i++) { mínimo = I; for(int j = 1; j < tam; j++) { if(0 <= costemín[j] && costemín[j] < mínimo) { mínimo = costemín[j]; elegido = j; } } aux = new Arista(); aux.origen = conexión[elegido]; aux.destino = elegido; aux.coste = grafo[conexión[elegido], elegido]; arm.Add(aux); costemín[elegido] = -1; for(int j = 1; j < tam; j++) { if(grafo[elegido, j] < costemín[j]) { costemín[j] = grafo[elegido, j]; conexión[j] = elegido; } } } return arm; }
public void Algoritmo(List <Nodo> nodos, Nodo inicio) { int peso_min = 0; inicio.visitado = true; List <Nodo> nodos_v = new List <Nodo>(); nodos_v.Add(inicio); while (nodos_v.Count < nodos.Count) { Arista arista = new Arista(null, int.MaxValue); foreach (var n in nodos_v) { foreach (var a in n.vecinos) { if (a.distancia < arista.distancia && !a.fin.visitado) { arista = a; } } } if (arista.fin != null) { peso_min += arista.distancia; nodos_v.Add(arista.fin); arista.fin.visitado = true; } } Console.WriteLine(peso_min); }
private void calculateNextCorrectArista(string v) { //Añadimos el vertice que nos ayudara a comprobar si existen ciclos. if (!conjuntoVertices.Contains(v)) { conjuntoVertices.Add(v); } foreach (string s in conjuntoVertices) { Debug.Log("vertice explorado:" + s); } Arista[] aristas = graph.getAristas(v); //Introduciomos nuevas aristas a las no visitadas for (int i = 0; i < aristas.Length; i++) { //Si la arista no esta en visitados ni en no visitados if (!visitedContains(aristas[i]) && !notVisitedContains(aristas[i])) { notVisited.Add(aristas[i]); Debug.Log("Nueva arista: " + aristas[i].toString()); } } //Una vez que disponemos de todas las aristas calculamos la solucion nextCorrectArista = notVisited[0]; foreach (Arista a in notVisited) { if (a._3() <= nextCorrectArista._3() && (!conjuntoVertices.Contains(a._1()) || !conjuntoVertices.Contains(a._2()))) { nextCorrectArista = a; } } Debug.Log("Tienes que elegir la arista: " + nextCorrectArista.toString()); }
public void CopyTo() { Arista lineaArista = linea.GetComponent <Arista>(); lineaArista.source = source; lineaArista.target = target; }
public void visitArista(Arista a) { visited.Add(a); if (notVisitedContains(a)) { removeNotVisited(a); } }
static void Conectar(Arista a, int[] cc, int tam) { int identif = cc[a.origen]; int víctima = cc[a.destino]; for(int i = 0; i < tam; i++) { if(cc[i] == víctima) { cc[i] = identif; } } }
private void PintaArista(State nodoIni, State nodoEnd, Arista arista) { var nix = nodoIni.X; var niy = nodoIni.Y; var nfx = nodoEnd.X; var nfy = nodoEnd.Y; AdjustableArrowCap finfle = new AdjustableArrowCap(5, 5); _plumaFlechaR.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; _plumaFlechaR.CustomEndCap = finfle; if (nix < nfx && niy > nfy) { _graphics.DrawLine(_plumaFlechaR, nix + 20, niy + 20, nfx + 5, nfy + 30); } if (nix > nfx && niy > nfy) { _graphics.DrawLine(_plumaFlechaR, nix + 20, niy + 20, nfx + 30, nfy + 30); } if (nix < nfx && niy < nfy) { _graphics.DrawLine(_plumaFlechaR, nix + 20, niy + 20, nfx + 5, nfy + 5); } if (nix > nfx && niy < nfy) { _graphics.DrawLine(_plumaFlechaR, nix + 20, niy + 20, nfx + 30, nfy + 5); } if (nix == nfx && nix > nfy) { _graphics.DrawLine(_plumaFlechaR, nix + 20, niy + 20, nfx + 15, nfy + 30); } if (nix == nfx && niy < nfy) { _graphics.DrawLine(_plumaFlechaR, nix + 20, niy + 20, nfx + 15, nfy + 30); } if (nix < nfx && niy == nfy) { _graphics.DrawLine(_plumaFlechaR, nix + 20, niy + 20, nfx - 5, nfy + 15); } if (nix > nfx && niy == nfy) { _graphics.DrawLine(_plumaFlechaR, nix + 20, niy + 20, nfx + 35, nfy + 15); } if (nix == nfx && niy == nfy) { creaVuelta(nodoIni, _graphics, 2); } _graphics.DrawRectangle(pincel, 20, 20, 51, 51); _graphics.FillRectangle(colorultipos, 20, 20, 50, 50); _graphics.DrawString(arista.Id.ToString(), fuente3, coloranul, 25, 25); pbDibujo.Refresh(); }
static List<Arista> Transformar(int[,] grafo, int[] conexión) { List<Arista> arm = new List<Arista>(); Arista aux; for(int i = 1; i < conexión.Length; i++) { aux = new Arista(); aux.origen = conexión[i]; aux.destino = i; aux.coste = grafo[conexión[i], i]; arm.Add(aux); } return arm; }
static void Conectar(Arista a, int[] cc, int tam) { int identif = cc[a.origen]; int víctima = cc[a.destino]; for (int i = 0; i < tam; i++) { if (cc[i] == víctima) { cc[i] = identif; } } }
static List <Arista> Transformar(int[,] grafo, int[] conexión) { List <Arista> arm = new List <Arista>(); Arista aux; for (int i = 1; i < conexión.Length; i++) { aux = new Arista(); aux.origen = conexión[i]; aux.destino = i; aux.coste = grafo[conexión[i], i]; arm.Add(aux); } return(arm); }
static Arista Menor(int[,] grafo, bool[] nodos, int tam) { int coste = I; Arista result = new Arista(-1, -1, 0); for(int i = 0; i < tam; i++) { if(nodos[i]) { for(int j = 0; j < tam; j++) { if(!nodos[j] && grafo[i, j] < coste) { coste = grafo[i, j]; result = new Arista(i, j, coste); } } } } return result; }
private bool notVisitedContains(Arista a) { bool contains = false; Arista[] varray = notVisited.ToArray(); int i = 0; while (!contains && (i < varray.Length)) { if (a._1().Equals(varray[i]._1()) && a._2().Equals(varray[i]._2()) && a._3() == varray[i]._3()) { contains = true; } i++; } return(contains); }
public JsonResult Save(Arista arista) { try { var arista2 = new Arista(); arista2.IdDestinoInicial = arista.IdDestinoFinal; arista2.IdDestinoFinal = arista.IdDestinoInicial; arista2.Distancia = arista.Distancia; arista2.Descripcion = arista.Descripcion; _db.Aristas.Add(arista); _db.Aristas.Add(arista2); _db.SaveChanges(); return(this.GetById(arista.Id)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message })); } }
private bool removeNotVisited(Arista a) { bool contains = false; Arista[] varray = notVisited.ToArray(); Arista toRemove = null; int i = 0; while (!contains && (i < varray.Length)) { if (a._1().Equals(varray[i]._1()) && a._2().Equals(varray[i]._2()) && a._3() == varray[i]._3()) { contains = true; toRemove = varray[i]; } i++; } notVisited.Remove(toRemove); return(contains); }
static Arista Menor(int[,] grafo, bool[] nodos, int tam) { int coste = I; Arista result = new Arista(-1, -1, 0); for (int i = 0; i < tam; i++) { if (nodos[i]) { for (int j = 0; j < tam; j++) { if (!nodos[j] && grafo[i, j] < coste) { coste = grafo[i, j]; result = new Arista(i, j, coste); } } } } return(result); }
static List <Arista> CalcPrim(int[,] grafo, int tam) { int[] costemín = Enumerable.Range(0, tam).Select(x => grafo[0, x]).ToArray(); int[] conexión = Enumerable.Range(0, tam).Select(x => 0).ToArray(); List <Arista> arm = new List <Arista>(); Arista aux; int mínimo, elegido = 0; for (int i = 1; i < tam; i++) { mínimo = I; for (int j = 1; j < tam; j++) { if (0 <= costemín[j] && costemín[j] < mínimo) { mínimo = costemín[j]; elegido = j; } } aux = new Arista(); aux.origen = conexión[elegido]; aux.destino = elegido; aux.coste = grafo[conexión[elegido], elegido]; arm.Add(aux); costemín[elegido] = -1; for (int j = 1; j < tam; j++) { if (grafo[elegido, j] < costemín[j]) { costemín[j] = grafo[elegido, j]; conexión[j] = elegido; } } } return(arm); }
public void tryAristaActivation(Arista a) { if (nextCorrectArista != null && a._1().Equals(nextCorrectArista._1()) && a._2().Equals(nextCorrectArista._2()) && a._3() == nextCorrectArista._3() && connectedPorts.Contains(a._1()) && connectedPorts.Contains(a._2())) { Debug.Log("Hemos accedido a la siguiente arista correcta" + a.toString()); changeEffectsState(a, false); visitArista(a); //Debug.Log("Visitados: " + visited.ToString()); //Debug.Log("No Visitados: " + notVisited.ToString()); aristasActivadas += 1; if (checkEnd()) { return; } calculateNextCorrectArista(a._1()); calculateNextCorrectArista(a._2()); } else { Debug.Log("Se reinicia el puzzle"); visited.Clear(); notVisited.Clear(); conjuntoVertices.Clear(); connectedPorts.Clear(); initialVertex = null; aristasActivadas = 0; changeEffectsState(a, true); failed += 1; //Se ha equivocado 3 veces, la mandamos a una zona de enemigos. if (failed == 3) { eventManager.transportToEnemyZone(); failed = 0; } } }
private void TrasarRutaArco(GMapMarker pMarcador) { GMarkerGoogle Marcador; string result = "\n"; Brush ColorFondoInformacion = new SolidBrush(Color.Red); Font f = new Font("Arial", 7, FontStyle.Bold); switch (this.vgContadorIndicadoresDeRuta) { case 0: this.vgContadorIndicadoresDeRuta++; this.vgMarcadorA = pMarcador; Marcador = new GMarkerGoogle(this.vgMarcadorA.Position, GMarkerGoogleType.blue); Marcador.Tag = pMarcador.Tag; Marcador.ToolTipMode = MarkerTooltipMode.Always; Marcador.ToolTip = new GMapRoundedToolTip(Marcador); ColorFondoInformacion.GetType(); Marcador.ToolTip.Stroke.Width = 2; Marcador.ToolTip.Stroke.Color = Color.Black; Marcador.ToolTip.TextPadding = new Size(5, 5); Marcador.ToolTip.Font = f; Marcador.ToolTip.Fill = ColorFondoInformacion; ColorFondoInformacion = new SolidBrush(Color.White); Marcador.ToolTip.Foreground = ColorFondoInformacion; Marcador.ToolTipText = String.Format("\nPunto A"); this.vgCapaMarcadores.Markers.Add(Marcador); this.gMapControl1.Overlays[2] = this.vgCapaMarcadores; break; case 1: this.vgContadorIndicadoresDeRuta++; this.vgMarcadorB = pMarcador; Arista <Lugar> arco = this.Gestor.GetArco(this.vgMarcadorA.Tag.ToString(), this.vgMarcadorB.Tag.ToString()); if (arco != null) { List <Lugar> listaLugares = new List <Lugar> { arco.GetVertA().Info, arco.GetVertB().Info }; MarcarRuta(listaLugares); Marcador = new GMarkerGoogle(this.vgMarcadorB.Position, GMarkerGoogleType.blue); Marcador.Tag = pMarcador.Tag; Marcador.ToolTipMode = MarkerTooltipMode.Always; Marcador.ToolTip = new GMapRoundedToolTip(Marcador); ColorFondoInformacion.GetType(); Marcador.ToolTip.Stroke.Color = Color.Black; Marcador.ToolTip.TextPadding = new Size(5, 5); Marcador.ToolTip.Font = f; Marcador.ToolTip.Fill = ColorFondoInformacion; ColorFondoInformacion = new SolidBrush(Color.White); Marcador.ToolTip.Foreground = ColorFondoInformacion; Marcador.ToolTipText = String.Format("\nPunto B"); this.vgCapaMarcadores.Markers.Add(Marcador); this.gMapControl1.Overlays[2] = this.vgCapaMarcadores; result += "Punto A: " + arco.GetVertA().Info.GetNombre() + "\n"; result += "Punto B: " + arco.GetVertB().Info.GetNombre() + "\n"; result += "Peso: " + arco.GetPeso() + " Metros"; this.textDatosVerticeBuscado.Text = result; } else { if (arco == null) { result = "el punto de inicio y final no son un arco"; } MessageBox.Show("Ocurrio un error " + result); this.gMapControl1.Overlays[2].Clear(); } this.vgContadorIndicadoresDeRuta = 0; this.vgVerArco = false; this.btnVerArco.Enabled = true; this.btnVerArco.BackColor = Color.MediumSeaGreen; break; } RefrecarMapa(); }
static bool NoConectados(Arista a, int[] cc) { return(cc[a.origen] != cc[a.destino]); }
static bool NoConectados(Arista a, int[] cc) { return cc[a.origen] != cc[a.destino]; }