public bool CheckAdjecentSameDigitsMax2(int[] resultArray) { var valid = false; int prev = 0; var list = new List<Adjacent>(); var item = new Adjacent(); foreach (var n in resultArray) { if (prev == n) { item.Count++; valid = true; } else { if (item.Count > 1) list.Add(item); item = new Adjacent(); } prev = n; } if (item.Count > 1) list.Add(item); return valid && list.Count() > 0 && list.Any(c => c.Count == 2); }
internal Room(Point Position, int Width, int Height, RoomPartGenerator[] RoomPartGenerator, Adjacent <List <int> > Exits) { position = Position; width = Width; height = Height; roomPartGenerators = RoomPartGenerator; exits = Exits; }
// Calculates the smallest path among all vertices public void floydWarshall() { this.allDistances = new PathVertexInfo[this.vertices.Length, this.vertices.Length]; // initializing distances for (int i = 0; i < this.vertices.Length; i++) { this.allDistances [i, i] = new PathVertexInfo(this.vertices [i], 0); for (int j = 0; j < this.vertices.Length; j++) { if (i != j) { Adjacent adj = this.isAdjacent(i, j); if (adj != null) { this.allDistances [i, j] = new PathVertexInfo(this.vertices [j], this.vertices [j].VertexCost + adj.edgeWeight + this.allDistances[i, i].DistanceToVertex); this.allDistances [i, j].PreviousVertex = this.allDistances[i, i]; } else { this.allDistances [i, j] = new PathVertexInfo(this.vertices [j], float.MaxValue); } } } } for (int k = 0; k < this.vertices.Length; k++) { for (int i = 0; i < this.vertices.Length; i++) { for (int j = 0; j < this.vertices.Length; j++) { if (allDistances [i, j].DistanceToVertex > allDistances [i, k].DistanceToVertex + allDistances [k, j].DistanceToVertex && allDistances [i, k].DistanceToVertex + allDistances [k, j].DistanceToVertex >= 0) // Check overflow { allDistances [i, j].DistanceToVertex = allDistances [i, k].DistanceToVertex + allDistances [k, j].DistanceToVertex; allDistances [i, j].PreviousVertex = allDistances [k, j].PreviousVertex; } } } } // add the cost of start vertex to the path for (int i = 0; i < this.vertices.Length; i++) { for (int j = 0; j < this.vertices.Length; j++) { float distanceWithStart = allDistances [i, j].DistanceToVertex + this.vertices [i].VertexCost; // not overflow if (distanceWithStart > 0) { allDistances [i, j].DistanceToVertex = distanceWithStart;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3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, - }; var adjacent = new Adjacent(matriz); var retorno = adjacent.MaxAdjacentDistance(); Assert.True(retorno.Equals(Constant.DefaultErrorValue)); } }
public void Adjacent_MaxDistanciaEntreAdjacentes_RetornoComSucesso() { int[] matriz = new int[] { 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 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 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, 5, 6, 9, 8, 9, 0, 3, 3, 12, 5, 3, 7, 1, }; var adjacent = new Adjacent(matriz); var retorno = adjacent.MaxAdjacentDistance(); Assert.True(retorno.Equals(Constant.Nothing)); }
public void Adjacent_MaxDistanciaEntreAdjacentesPorIndice_RetornoComSucesso() { int indiceA = 3; int indiceB = 6; int[] matriz = new int[] { 0, 3, 3, 12, 5, 3, 7, 1 }; var adjacent = new Adjacent(matriz, indiceA, indiceB); adjacent.MaxAdjacentDistance(); Assert.True(adjacent.ShortestDistance() == 5); }
public string RemoveDuplicates(string s, int k) { Stack <Adjacent> stack = new Stack <Adjacent>(); foreach (char c in s) { if (stack.Count > 0 && stack.Peek().c == c) { stack.Peek().count++; } else { stack.Push(new Adjacent(c, 1)); } if (stack.Count > 0 && stack.Peek().count >= k) { stack.Pop(); } } StringBuilder sb = new StringBuilder(); while (stack.Count != 0) { Adjacent adj = stack.Pop(); for (int i = 0; i < adj.count; i++) { sb.Append(adj.c); } } string result = sb.ToString(); char[] res = result.ToCharArray(); Array.Reverse(res); return(new string(res)); }
private bool HasFlips(Adjacent adjacent) { return(adjacent.Flips.Contains(txtFlips.Text)); }
/// <summary> /// A* pathfinder. /// </summary> /// <param name="start">The node to begin the search at.</param> /// <param name="end">The node to find from the start.</param> /// <param name="adj">A function which returns nodes adjacent to the passed in node.</param> /// <param name="dist">A function that gives the distance and estimated distance between nodes.</param> /// <param name="maxnodes">The maximum number of nodes to keep on the open list. 0 for unlimited.</param> /// <param name="maxnodedepth">The maximum path length that can be made. 0 for unlimited.</param> /// <param name="mintargetdist">The minimum acceptable distance to the target before ending the search.</param> /// <param name="minnodedist">A function that returns the minimum number of node transitions between 2 nodes. Pass in null if no such function is availible. Optimizes search time in conjunction with a passed in minnodedepth.</param> /// <returns>A list of nodes going from start to end or null in the event no path could be found.</returns> public static List <T> AStar(T start, T end, Adjacent adj, Distance dist, int maxnodes, int maxnodedepth, int mintargetdist, NodeDist minnodedist) { Comparison <PathNode <T> > pwc = new Comparison <PathNode <T> >(PathWeightCompare); PriorityQueue <PathNode <T> > open = new PriorityQueue <PathNode <T> >(pwc); Dictionary <T, double> bestF = new Dictionary <T, double>(); List <T> path = null; open.Enqueue(new PathNode <T>(start, null, 0, dist(start, end), 0, bestF)); while (!open.Empty) { PathNode <T> cur = open.Dequeue(); bool closeenough = false; if (mintargetdist > 0) { closeenough = dist(cur.source, end) <= mintargetdist; } if (cur.source.Equals(end) || closeenough) { Stack <T> s = new Stack <T>(); path = new List <T>(); s.Push(cur.source); while (cur.prevNode != null) { cur = cur.prevNode; s.Push(cur.source); } while (s.Count > 0) { path.Add(s.Pop()); } break; } List <T> L = adj(cur.source); if (minnodedist != null && maxnodedepth != 0) { if (minnodedist(cur.source, end) + cur.nt >= maxnodedepth) { continue; } } else if (maxnodedepth != 0) { if (cur.nt >= maxnodedepth) { continue; } } foreach (T d in L) { double ng = cur.g + dist(cur.source, d); if (bestF.ContainsKey(d)) { if (ng + dist(d, end) < bestF[d]) { for (int i = 0; i < open.Count; i++) { if (open[i].source.Equals(d)) { open.Remove(i); break; } } } else { continue; } } open.Enqueue(new PathNode <T>(d, cur, ng, dist(d, end), cur.nt + 1, bestF)); } if (maxnodes != 0 && open.Count > maxnodes) { open.Cut(maxnodes); } } return(path); }
public void Save() { if (title == null) { return; } if (Title == null) { return; } if (!TitleManager.instance.Titles.Contains(Title)) { int gfdgfd = 0; } string dir = Globals.ModDir + "history\\provinces\\"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } String provincesDir = Globals.MapDir + "history\\provinces\\" + id.ToString() + " - " + Title.Name.Replace("c_", "") + ".txt"; Script s = new Script(); s.Root = new ScriptScope(); s.Name = provincesDir; s.Root.Add(new ScriptCommand("title", Title.Name, s.Root)); s.Root.Add(new ScriptCommand("max_settlements", max_settlements, s.Root)); if (Culture != null) { s.Root.Add(new ScriptCommand("culture", initialCulture, s.Root)); s.Root.Add(new ScriptCommand("religion", initialReligion, s.Root)); } if (MapManager.instance.LoadedTerrain.ContainsKey(id)) { s.Root.Add(new ScriptCommand("terrain", MapManager.instance.LoadedTerrain[id], s.Root)); } int cc = 0; foreach (var barony in baronies) { if (baronies[0].type == "tribal" && barony.type != "temple" && cc > 0) { continue; } if (barony.enabled && cc == 0) { s.Root.Add(new ScriptCommand(barony.title, barony.type, s.Root)); } cc++; } var cities = baronies.Where(c => c.type == "city" && c.enabled); if (cities.Any()) { if (Adjacent.Where(o => !o.land).Count() > 0) { s.Root.Do(@"1.1.1 = { " + cities.First().title + @" = ct_port_1 }"); } } if (terrain != null) { s.Root.Add(new ScriptCommand("terrain", terrain, s.Root)); } foreach (var scriptScope in dateScripts) { s.Root.SetChild(scriptScope); } s.Save(); }
private bool IsTarget(Adjacent adjacent) { var timeAndDelay = (TimeAndDelay)dataGridViewValues.SelectedRows[0].DataBoundItem; return(adjacent.Date == timeAndDelay.Date && adjacent.Delay == timeAndDelay.Delay); }
private void buttonGenerateAdjacents_Click(object sender, EventArgs e) { if (radioBtnDPPt.Checked) { ColumnFlipSequence.Visible = true; ColumnElmResponse.Visible = false; ColumnRoamers.Visible = false; ColumnGen5IVs.Visible = false; } else if (radioBtnHgSs.Checked) { ColumnFlipSequence.Visible = false; ColumnElmResponse.Visible = true; ColumnRoamers.Visible = true; ColumnGen5IVs.Visible = false; } else { ColumnFlipSequence.Visible = false; ColumnElmResponse.Visible = false; ColumnRoamers.Visible = false; ColumnGen5IVs.Visible = true; ColumnCGearAdjust.Visible = sekrit; } if (maskedTextBoxMDelay.Text == "") { maskedTextBoxMDelay.Focus(); return; } if (maskedTextBoxPDelay.Text == "") { maskedTextBoxPDelay.Focus(); return; } if (maskedTextBoxMSecond.Text == "") { maskedTextBoxMSecond.Focus(); return; } if (maskedTextBoxPSecond.Text == "") { maskedTextBoxPSecond.Focus(); return; } // Make sure that something is selected in the main // times grid and then go ahead and get that item if (dataGridViewValues.SelectedRows.Count == 0) { return; } // Load all of our +/- so we can use them to generate // or list of adjacent frames. int mDelay = int.Parse(maskedTextBoxMDelay.Text); int pDelay = int.Parse(maskedTextBoxPDelay.Text); int mSecond = int.Parse(maskedTextBoxMSecond.Text); int pSecond = int.Parse(maskedTextBoxPSecond.Text); var timeAndDelay = (TimeAndDelay)dataGridViewValues.SelectedRows[0].DataBoundItem; // From the actual time we need to build a start // time and an end time so that we can iterate DateTime startTime = timeAndDelay.Date - new TimeSpan(0, 0, mSecond); DateTime endTime = timeAndDelay.Date + new TimeSpan(0, 0, pSecond); // Figure out how many seconds there are between the times // as this is going to be the number of times that we are // going to loop, plus 1. TimeSpan span = endTime - startTime; int startDelay = timeAndDelay.Delay - mDelay; int endDelay = timeAndDelay.Delay + pDelay; // Grab our roamer information so we only have to do it one // time and can just run the code and pass the results into // the adjacents. uint rRoute = 0; uint eRoute = 0; uint lRoute = 0; // need to tryparse out all of the route values if (maskedTextBoxRRoute.Text != "") { rRoute = uint.Parse(maskedTextBoxRRoute.Text); } if (maskedTextBoxERoute.Text != "") { eRoute = uint.Parse(maskedTextBoxERoute.Text); } if (maskedTextBoxLRoute.Text != "") { lRoute = uint.Parse(maskedTextBoxLRoute.Text); } var adjacents = new List <Adjacent>(); int oddEven = timeAndDelay.Delay & 1; int minFrame; int maxFrame; int.TryParse(maskedTextBoxMinFrame.Text, out minFrame); int.TryParse(maskedTextBoxMaxFrame.Text, out maxFrame); if (minFrame == 0) { minFrame = 1; } if (maxFrame == 0) { maxFrame = 10; } if (checkBoxRoamer.Checked) { minFrame++; maxFrame++; } for (int cnt = 0; cnt <= (int)span.TotalSeconds; cnt++) { DateTime seedTime = startTime + new TimeSpan(0, 0, cnt); // Now we need to loop through all of our delay range // so that we have all of the information to create // a seed. for (int delayCnt = startDelay; delayCnt <= endDelay; delayCnt++) { if (!checkBoxOddEven.Checked || (delayCnt & 1) == oddEven) { // Create the seed an add to the collection var adjacent = new Adjacent { Delay = delayCnt, Date = seedTime, MinFrame = minFrame, MaxFrame = maxFrame + 6, Seed = ((((uint)seedTime.Month * (uint)seedTime.Day + (uint)seedTime.Minute + (uint)seedTime.Second) % 0x100) * 0x1000000) + ((uint)seedTime.Hour * 0x10000) + ((uint)seedTime.Year - 2000 + (uint)delayCnt) + // only part of the MAC Address is used ((uint)MAC_Address & 0xFFFFFF) }; adjacent.RoamerInformtion = HgSsRoamers.GetHgSsRoamerInformation( adjacent.Seed, checkBoxRPresent.Checked, checkBoxEPresent.Checked, checkBoxLPresent.Checked, rRoute, eRoute, lRoute); adjacents.Add(adjacent); } } } // Bind to the collection dataGridViewAdjacents.DataSource = adjacents; //highlight the target int target = adjacents.FindIndex(IsTarget); dataGridViewAdjacents.FirstDisplayedScrollingRowIndex = target; }
private bool HasElms(Adjacent adjacent) { return(adjacent.ElmResponses.Contains(textBoxResponses.Text) && (RoamerText == "" || RoamerText == adjacent.RoamerLocations)); }
public void AddAdjacent(Node Node) { Adjacent.Add(Node); }
public void Terrain_Initialise(int iSeed, int iNumPieces) { Terrain_ShutDown(); m_fTimeUntilNextFalloff = m_fTimeBetweenFalloff; GameObject templateTerrainPiece = (GameObject)Resources.Load("Prefabs/GroundBlock", typeof(GameObject)); float fOuterRadius = templateTerrainPiece.transform.localScale.x; float fInnerRadius = fOuterRadius * 0.86602540378443864676372317075294f; // (cos(30°) Vector2 translateX = new Vector2(fInnerRadius * 2, 0); Vector2 translateY = new Vector2(fInnerRadius, fInnerRadius * 1.7320508075688772935274463415059f); // fInnerRadius*1.7320508075688772935274463415059 == √((fInnerRadius+fInnerRadius)² - fInnerRadius²) Vector2 translateZ = new Vector2(fInnerRadius, fInnerRadius * -1.7320508075688772935274463415059f); // fInnerRadius*1.7320508075688772935274463415059 == √((fInnerRadius+fInnerRadius)² - fInnerRadius²) Random.seed = iSeed; // Seed the random number generator, so all clients (including the host) generate the same terrain. uint uiTotalRecommendation = 0; System.Collections.Generic.Dictionary <long, Adjacent> builder = new System.Collections.Generic.Dictionary <long, Adjacent>(); // Create all terrain pieces. for (uint uiLoop = 0; uiLoop < iNumPieces; ++uiLoop) { // Find where the new piece will be placed. Adjacent.Index newPos = new Adjacent.Index(0, 0, 0); if (uiLoop != 0) // If this is not the first piece... { // Spawn from one of the recommended locations, using the Roulette Wheel genetic algorithm. uint uiSelection = (uint)Random.Range(0, (int)uiTotalRecommendation); foreach (System.Collections.Generic.KeyValuePair <long, Adjacent> pair in builder) { // Ignore pieces that have already been populated. if (pair.Value.m_TerrainPiece != null) { continue; } // Before using Roulette Wheel selection, ensure the pieces of terrain that are part of the initial solid arena are created. newPos.SetAs(pair.Key); if (pair.Value.m_uiRecommendation >= 5 && new Vector3(translateX.x * newPos.x + translateY.x * newPos.y + translateZ.x * newPos.z, templateTerrainPiece.transform.position.y, translateX.y * newPos.x + translateY.y * newPos.y + translateZ.y * newPos.z).magnitude - fOuterRadius <= m_fRadiusOfInitialSolidArena) { break; // Create this piece by using 'newPos'. } // Check if this is the winner of Roulette Wheel selection. if (uiSelection < pair.Value.m_uiRecommendation) { break; // Create this piece by using 'newPos'. } else // Not winner. { uiSelection -= pair.Value.m_uiRecommendation; } } } // Create new terrain piece. GameObject terrainPiece = (GameObject)GameObject.Instantiate ( templateTerrainPiece, new Vector3 ( translateX.x * newPos.x + translateY.x * newPos.y + translateZ.x * newPos.z, templateTerrainPiece.transform.position.y, translateX.y * newPos.x + translateY.y * newPos.y + translateZ.y * newPos.z ), templateTerrainPiece.transform.localRotation ); terrainPiece.name = "Terrain " + uiLoop + " (" + newPos.x + "x " + newPos.y + "y " + newPos.z + "z)"; Adjacent adjacent = null; if (builder.TryGetValue(newPos, out adjacent)) { // If the terrain piece in 'adjacent' is already set, then the terrain has been generated far too large - no more pieces can be created. if (adjacent.m_TerrainPiece != null) { break; // Stop creating terrain. } adjacent.m_TerrainPiece = terrainPiece; } else { adjacent = new Adjacent(terrainPiece); builder.Add(newPos, adjacent); } if (terrainPiece.transform.position.magnitude - fOuterRadius <= m_fRadiusOfSmallestArena) // If this piece of terrain is within the radius of the final arena, then preserve this piece... { m_TerrainPieces_Preserved.Add(terrainPiece); // Add this piece to the list of terrain pieces that will not crumble. } else // Outside the radius of the smallest arena... { m_TerrainPieces.Insert(0, terrainPiece); // Add this piece to the list of terrain pieces that can crumble. } uiTotalRecommendation -= adjacent.m_uiRecommendation; // Increment recommendation of all surrounding pieces (plus create them if they do not exist yet). Adjacent.Index relativePos; relativePos = newPos.Relative(-1, -0, -0); if (relativePos.x >= -1048576) // Only bother if the value is within range of the bits allocated (20 bits). { if (!builder.TryGetValue(relativePos, out adjacent)) { adjacent = new Adjacent(); builder.Add(relativePos, adjacent); } if (adjacent.m_TerrainPiece == null) { ++adjacent.m_uiRecommendation; ++uiTotalRecommendation; } } relativePos = newPos.Relative(+1, +0, +0); if (relativePos.x < 1048576) // Only bother if the value is within range of the bits allocated (20 bits). { if (!builder.TryGetValue(relativePos, out adjacent)) { adjacent = new Adjacent(); builder.Add(relativePos, adjacent); } if (adjacent.m_TerrainPiece == null) { ++adjacent.m_uiRecommendation; ++uiTotalRecommendation; } } relativePos = newPos.Relative(-0, -1, -0); if (relativePos.y >= -1048576) // Only bother if the value is within range of the bits allocated (20 bits). { if (!builder.TryGetValue(relativePos, out adjacent)) { adjacent = new Adjacent(); builder.Add(relativePos, adjacent); } if (adjacent.m_TerrainPiece == null) { ++adjacent.m_uiRecommendation; ++uiTotalRecommendation; } } relativePos = newPos.Relative(+0, +1, +0); if (relativePos.y < 1048576) // Only bother if the value is within range of the bits allocated (20 bits). { if (!builder.TryGetValue(relativePos, out adjacent)) { adjacent = new Adjacent(); builder.Add(relativePos, adjacent); } if (adjacent.m_TerrainPiece == null) { ++adjacent.m_uiRecommendation; ++uiTotalRecommendation; } } relativePos = newPos.Relative(-0, -0, -1); if (relativePos.z >= -1048576) // Only bother if the value is within range of the bits allocated (20 bits). { if (!builder.TryGetValue(relativePos, out adjacent)) { adjacent = new Adjacent(); builder.Add(relativePos, adjacent); } if (adjacent.m_TerrainPiece == null) { ++adjacent.m_uiRecommendation; ++uiTotalRecommendation; } } relativePos = newPos.Relative(+0, +0, +1); if (relativePos.z < 1048576) // Only bother if the value is within range of the bits allocated (20 bits). { if (!builder.TryGetValue(relativePos, out adjacent)) { adjacent = new Adjacent(); builder.Add(relativePos, adjacent); } if (adjacent.m_TerrainPiece == null) { ++adjacent.m_uiRecommendation; ++uiTotalRecommendation; } } } }
/// <summary> /// Retrieves a field of nodes that were on the way to or the finish nodes themselves. /// </summary> /// <param name="start">The node to begin the search on.</param> /// <param name="adj">A function which returns nodes adjacent to the passed in node.</param> /// <param name="dist">A function that gives the distance between nodes.</param> /// <param name="fin">A function that returns whether or not the node passed in is an end point.</param> /// <param name="include">A set of flags for what to return. INTERIOR are the nodes that lead to the FINISHED nodes. BOTH returns botht he INTERIOR and FINISHED nodes.</param> /// <param name="maxnodedepth">The maximum length path.</param> /// <returns>A field of nodes that lead to the finishing nodes.</returns> public static List <T> DijkstraNodeInRange(T start, Adjacent adj, Distance dist, Finished fin, DijkstraIncludeFlags include, int maxnodedepth) { Comparison <PathNode <T> > pwc = new Comparison <PathNode <T> >(PathWeightCompare); PriorityQueue <PathNode <T> > open = new PriorityQueue <PathNode <T> >(pwc); Dictionary <T, double> bestF = new Dictionary <T, double>(); List <T> closed = new List <T>(); List <T> finishedL = new List <T>(); open.Enqueue(new PathNode <T>(start, null, 0, 0, 0, bestF)); while (!open.Empty) { PathNode <T> cur = open.Dequeue(); closed.Add(cur.source); if (fin(cur.source, cur.g) != 0) { finishedL.Add(cur.source); continue; } List <T> L = adj(cur.source); if (maxnodedepth != 0 && cur.nt >= maxnodedepth) { continue; } foreach (T d in L) { double ng = cur.g + dist(cur.source, d); if (bestF.ContainsKey(d)) { if (ng < bestF[d]) { for (int i = 0; i < open.Count; i++) { if (open[i].source.Equals(d)) { open.Remove(i); break; } } } else { continue; } } open.Enqueue(new PathNode <T>(d, cur, ng, 0, cur.nt + 1, bestF)); } } switch (include) { case DijkstraIncludeFlags.INTERIOR: return(closed); case DijkstraIncludeFlags.FINISHED: return(finishedL); case DijkstraIncludeFlags.BOTH: foreach (T t in finishedL) { closed.Add(t); } return(closed); } return(null); }
/// <summary> /// Dijkstra pathfinder. /// </summary> /// <param name="start">The node to begin the search at.</param> /// <param name="adj">A function which returns nodes adjacent to the passed in node.</param> /// <param name="dist">A function that gives the distance between nodes.</param> /// <param name="fin">A function that returns whether or not the node passed in is the end of the search.</param> /// <param name="maxnodedepth">The maximum path length.</param> /// <returns>A list of paths to the different finishing nodes found.</returns> public static List <List <T> > Dijkstra(T start, Adjacent adj, Distance dist, Finished fin, int maxnodedepth) { Comparison <PathNode <T> > pwc = new Comparison <PathNode <T> >(PathWeightCompare); PriorityQueue <PathNode <T> > open = new PriorityQueue <PathNode <T> >(pwc); Dictionary <T, double> bestF = new Dictionary <T, double>(); List <List <T> > path = new List <List <T> >(); open.Enqueue(new PathNode <T>(start, null, 0, 0, 0, bestF)); while (!open.Empty) { PathNode <T> cur = open.Dequeue(); FinishedFlags isDone = fin(cur.source, cur.g); if (isDone != 0) { Stack <T> s = new Stack <T>(); s.Push(cur.source); while (cur.prevNode != null) { cur = cur.prevNode; s.Push(cur.source); } path.Add(new List <T>()); while (s.Count > 0) { path[path.Count - 1].Add(s.Pop()); } } if ((isDone & FinishedFlags.FINISHED) != 0) { break; } List <T> L = adj(cur.source); if (maxnodedepth != 0 && cur.nt >= maxnodedepth) { continue; } foreach (T d in L) { double ng = cur.g + dist(cur.source, d); if (bestF.ContainsKey(d)) { if (ng < bestF[d]) { for (int i = 0; i < open.Count; i++) { if (open[i].source.Equals(d)) { open.Remove(i); break; } } } else { continue; } } open.Enqueue(new PathNode <T>(d, cur, ng, 0, cur.nt + 1, bestF)); } } return(path); }