public void Prims_AdjacencyMatrixGraph_Smoke_Test() { var graph = new Advanced.Algorithms.DataStructures.Graph.AdjacencyMatrix.WeightedGraph <char, int>(); graph.AddVertex('S'); graph.AddVertex('A'); graph.AddVertex('B'); graph.AddVertex('C'); graph.AddVertex('D'); graph.AddVertex('T'); graph.AddEdge('S', 'A', 8); graph.AddEdge('S', 'C', 10); graph.AddEdge('A', 'B', 10); graph.AddEdge('A', 'C', 1); graph.AddEdge('A', 'D', 8); graph.AddEdge('B', 'T', 4); graph.AddEdge('C', 'D', 1); graph.AddEdge('D', 'B', 1); graph.AddEdge('D', 'T', 10); var algorithm = new Prims <char, int>(); var result = algorithm.FindMinimumSpanningTree(graph); Assert.AreEqual(graph.VerticesCount - 1, result.Count); }
static void Main(String[] args) { var mn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var g = new Dictionary <int, List <Edge> >(); for (int i = 0; i < mn[1]; ++i) { var xyr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); List <Edge> eds; if (!g.TryGetValue(xyr[0], out eds)) { eds = new List <Edge>(); g.Add(xyr[0], eds); } eds.Add(new Edge(xyr[0], xyr[1], xyr[2])); if (!g.TryGetValue(xyr[1], out eds)) { eds = new List <Edge>(); g.Add(xyr[1], eds); } eds.Add(new Edge(xyr[1], xyr[0], xyr[2])); } var first = int.Parse(Console.ReadLine()); int sum = 0; foreach (var edge in Prims.BuildMinimumSpanningTree(first, new DictionaryGraph(g))) { sum += edge.weight; } Console.WriteLine(sum); }
public Map Generate() { TriangleNet.Mesh mesh = createMesh(); Map map = new Map(); foreach (TriangleNet.Geometry.Vertex triVertex in mesh.Vertices) { Vertex v = map.AddVertex((float)triVertex.x, (float)triVertex.y); vertexIDMap.Add(triVertex.GetHashCode(), v.ID); } foreach (TriangleNet.Geometry.Edge Edge in mesh.Edges) { map.AddEdge(vertexIDMap[Edge.P0], vertexIDMap[Edge.P1]); } Prims prims = new Prims(map); prims.AssignMSTEdges(); Roads roads = new Roads(map, roadDensity); roads.AssignRoadEdges(); return(map); }
/** * \brief Function to generate the maze * * Uses the appropriate algorithm according to * the selected option in the UI and applies it to the 2d * array. Disposes the old maze. * * \return null */ public void GenerateNewMaze(int sizeR, int sizeC) { //Better mazes are produced if number of rows and columns are odd if (sizeR % 2 == 0) { sizeR += 1; } if (sizeC % 2 == 0) { sizeC += 1; } //Destroy the old maze DisposeOldMaze(); if (dropdown.value == 0) { backtracker = new RecursiveBacktracker(); data = backtracker.GenerateMaze(sizeR, sizeC); } else if (dropdown.value == 1) { prims = new Prims(); data = prims.Mazer(sizeR, sizeC); } else if (dropdown.value == 2) { krusk = new Kruskalls(); data = krusk.Mazer(sizeR, sizeC); } DisplayMaze(); }
public void Prims_Smoke_Test() { var graph = new WeightedGraph <char, int>(); graph.AddVertex('S'); graph.AddVertex('A'); graph.AddVertex('B'); graph.AddVertex('C'); graph.AddVertex('D'); graph.AddVertex('T'); graph.AddEdge('S', 'A', 8); graph.AddEdge('S', 'C', 10); graph.AddEdge('A', 'B', 10); graph.AddEdge('A', 'C', 1); graph.AddEdge('A', 'D', 8); graph.AddEdge('B', 'T', 4); graph.AddEdge('C', 'D', 1); graph.AddEdge('D', 'B', 1); graph.AddEdge('D', 'T', 10); var algo = new Prims <char, int>(); var result = algo.FindMinimumSpanningTree(graph); Assert.AreEqual(graph.VerticesCount - 1, result.Count); }
static void Main(string[] args) { GameOfLife.GameOfLifeMain(); ParseHtml.ParseHtmlMain(null); AllTextSuggestions.AllTextSuggestionsMain(null); BSTIteratorDriver.BSTIteratorMain(null); TopologicalSort.TopologicalSortMain(); Prims.PrimsMain(null); Kruskals.KruskalsMain(null); WordSearch.wordSearchMain(); CountSmallerAfterNumber2.CountSmallerAfterNumber2Main(); CountSmallerAfterNumber.countSmallerMain(); BFS.BFSMain(null); StringPermutation.StringPermutationMain(); // Done RemoveKFromList.RemoveKFromListMain(); TripletSum.tripletSumMain(); SubsetSum.subsetSumMain(); RotateImage.rotateImageMain(); // Done StrStr.strStrMain(); // Done - exceeding time SumOfTwo.SumOfTwoMain(); // Not done SortedSquaredArray.sortedSquaredArrayMain(); // Done IsListPalindrome.isListPalindromeMain(); // Done SwapLexOrder.swapLexOrderMain(); TextJustification.textJustificationMain(); // Done GoodStringCount.goodStringsCountMain(); // Not done WordLadder.wordLadderMain(); // Not complete by me SortingAlgos.sortingAlgosMain(); // Done SortByString.sortByStringMain(); // Done StringReformatting.stringReformattingMain(); // Done ReverseInteger.reverseIntegerMain(); // Done ProductExceptSelf.productExceptSelfMain(); // Done }
public void Constructor() { IScanner scanner = Provider.Scanner; StringParser parser = Prims.StringOf(MatchedString); Assert.AreEqual(parser.MatchedString, MatchedString); }
private HashSet <Edge> MST() { Prims mst = new Prims(_roomConnections); HashSet <Edge> edges = mst.Prim(); return(edges); }
static G RandomAlgorithm <G, T>(Grid grid, Algorithm algorithm) where G : Grid where T : Cell { switch (algorithm) { case Algorithm.AldousBroder: return(AldousBroder.CreateMaze <G, T>(grid as G)); case Algorithm.BinaryTree: return(BinaryTree.CreateMaze(grid) as G); case Algorithm.HuntAndKill: return(HuntAndKill.CreateMaze <G, T>(grid as G)); case Algorithm.RecursiveBacktracker: return(RecursiveBacktracker.CreateMaze <G, T>(grid as G)); case Algorithm.Sidewinder: return(Sidewinder.CreateMaze(grid) as G); case Algorithm.Wilsons: return(Wilsons.CreateMaze <G, T>(grid as G)); case Algorithm.Kruskals: return(Kruskals.CreateMaze(grid) as G); case Algorithm.Prims: return(Prims.CreateMaze <G, T>(grid as G)); case Algorithm.TruePrims: return(TruePrims.CreateMaze <G, T>(grid as G)); case Algorithm.GrowingTree: return(GrowingTree.CreateMaze <G, T>(grid as G)); case Algorithm.RecursiveDivision: return(RecursiveDivision.CreateMaze(grid) as G); case Algorithm.Ellers: return(Ellers.CreateMaze(grid) as G); case Algorithm.Houstons: return(Houstons.CreateMaze <G, T>(grid as G)); } return(null); }
public void NegateFailParse() { IScanner scanner = Provider.NewScanner; NegatableParser parser = ~Prims.Ch(MatchedChar); ParserMatch m = parser.Parse(scanner); Assert.IsFalse(m.Success); Assert.AreEqual(scanner.Offset, 0); }
public void FailParse() { IScanner scanner = Provider.NewScanner; CharParser parser = Prims.Ch(NonMatchedChar); ParserMatch m = parser.Parse(scanner); Assert.IsFalse(m.Success); Assert.AreEqual(scanner.Offset, 0); }
public void NegateFailParse() { IScanner scanner = Provider.Scanner; NegatableParser parser = -Prims.CharOf(MatchedChar); ParserMatch m = parser.Parse(scanner); Assert.IsTrue(!m.Success); Assert.AreEqual(scanner.Offset, 0); }
public void FailParse() { IScanner scanner = Provider.NewScanner; StringParser parser = Prims.Str(NonMatchedString); ParserMatch m = parser.Parse(scanner); Assert.IsFalse(m.Success); Assert.AreEqual(0, scanner.Offset); }
public void FailParse() { IScanner scanner = Provider.Scanner; StringParser parser = Prims.StringOf(NonMatchedString); ParserMatch m = parser.Parse(scanner); Assert.IsTrue(!m.Success); Assert.AreEqual(scanner.Offset, 0); }
public void MainTestMethod() { const int SIZE = 500; const int START_FROM = 0; const int THREAD_AMOUNT = 3; Prims prims = new Prims(new Graph(SIZE).Generate()); prims.Run(startVertex: START_FROM, threadAmount: THREAD_AMOUNT); }
// Start is called before the first frame update void createMaze(int oldseed, int newseed) { Random.InitState(newseed); //applies the set seed Prims prims = new Prims(mazeSizeX, mazeSizeY); //Create Prims Object prims.loop(); //Run Prims Algorithm to Completition //prims.draw(); <-- String Based UI var maze = prims.getMaze(); //Retrieve Maze Information Draw(maze); //Graphical UI }
public void SuccessParse() { IScanner scanner = Provider.Scanner; StringParser parser = Prims.StringOf(MatchedString); ParserMatch m = parser.Parse(scanner); Assert.IsTrue(m.Success); Assert.AreEqual(m.Offset, 0); Assert.AreEqual(m.Length, 3); Assert.AreEqual(scanner.Offset, 4); }
public void SuccessParse() { IScanner scanner = Provider.NewScanner; StringParser parser = Prims.Str(MatchedString); ParserMatch m = parser.Parse(scanner); Assert.IsTrue(m.Success); Assert.AreEqual(0, m.Offset); Assert.AreEqual(3, m.Length); Assert.AreEqual(3, scanner.Offset); }
public void SuccessParse() { IScanner scanner = Provider.NewScanner; CharParser parser = Prims.Ch(MatchedChar); ParserMatch m = parser.Parse(scanner); Assert.IsTrue(m.Success); Assert.AreEqual(m.Offset, 0); Assert.AreEqual(m.Length, 1); Assert.AreEqual(scanner.Offset, 1); }
public void NegateSuccessParse() { IScanner scanner = Provider.Scanner; NegatableParser parser = -Prims.CharOf(NonMatchedChar); ParserMatch m = parser.Parse(scanner); Assert.IsTrue(m.Success); Assert.AreEqual(m.Offset, 0); Assert.AreEqual(m.Length, 1); Assert.AreEqual(scanner.Offset, 1); }
private static Parser <Card, Value> ParseNWithRunningComparison(int n, RunningComparison comparison, Card first, Card previous) { if (n == 0) { return(Parser.Return <Card, Value>(first.Value)); } return (from current in Prims.Satisfy <Card>(curr => comparison(previous, curr)) from rest in ParseNWithRunningComparison(n - 1, comparison, first, current) select rest); ; }
TemplateResults selectHallways(TemplateResults formattedRects) { var edges = new List <Edge>(); var coordinates = new List <Coordinate>(); formattedRects.centers.ForEach((p) => { coordinates.Add(new Coordinate(p.min.X, p.min.Y)); }); var triangulator = new DelaunayTriangulationBuilder(); triangulator.SetSites(coordinates.ToArray()); var triangulatedEdges = triangulator.GetEdges(new GeometryFactory(new PrecisionModel(.1))); triangulatedEdges.Geometries.ToList().ForEach((edge) => { var Q = edge.Coordinates[0]; var P = edge.Coordinates[1]; edges.Add(new Edge(new Point((int)Q.X, (int)Q.Y), new Point((int)P.X, (int)P.Y))); }); var edgePoints = new HashSet <Point>(); edges = new Prims().exec(edges); edges.ForEach((edge) => { var p12 = edge.getPoints(); edgePoints.UnionWith(edge.getPoints()); }); var newPaths = new HashSet <Rect>(); var newNonPaths = formattedRects.nonPathIndices; formattedRects.allRects.ForEach((r) => { if (edgePoints.Contains(r.min)) { newPaths.Add(r); } else { newNonPaths.Add(r); } }); formattedRects.nonPathIndices = newNonPaths.ToList(); formattedRects.pathIndices = newPaths.ToList(); return(formattedRects); }
public void EndOfInputTest() { Prims.EndOfInput <Char>() .Run("inputString".AsStream()) .Case( failure: (restStream, errorMessage) => { /* OK */ }, success: (restStream, value) => Assert.Fail()); Prims.EndOfInput <Char>() .Run("".AsStream()) .Case( failure: (restStream, errorMessage) => Assert.Fail(), success: (restStream, value) => { /* OK */ }); }
public void EmptyTest() { Prims.Empty <Char, Char>() .Run("inputString".AsStream()) .Case( failure: (restStream, errorMessage) => Assert.Fail(), success: (restStream, value) => { Assert.True(Enumerable.Equals(value, Enumerable.Empty <Char>())); Assert.True(restStream.Current.HasValue); Assert.AreEqual('i', restStream.Current.Value.Item0); Assert.AreEqual(1, restStream.Current.Value.Item1.Line); Assert.AreEqual(1, restStream.Current.Value.Item1.Column); }); }
public void UnitTest() { Prims.Unit <Char>() .Run("inputString".AsStream()) .Case( failure: (restStream, errorMessage) => Assert.Fail(), success: (restStream, value) => { Assert.AreEqual(Unit.Instance, value); Assert.True(restStream.Current.HasValue); Assert.AreEqual('i', restStream.Current.Value.Item0); Assert.AreEqual(1, restStream.Current.Value.Item1.Line); Assert.AreEqual(1, restStream.Current.Value.Item1.Column); }); }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { TextureThreadContextReady.Close(); Printer.Dispose(); PendingTextures.Close(); Prims.Clear(); Textures.Clear(); glControl.Context.Dispose(); glControl.Dispose(); renderer = null; GLMode = null; components.Dispose(); } base.Dispose(disposing); }
public void KleeneStar() //http://www.codeproject.com/csharp/spart.asp?df=100&forumid=30315&select=797678#xx797678xx { Rule integer = new Rule("integer"); Rule number = new Rule("number"); Rule group = new Rule("group"); Rule term = new Rule("term"); Rule expression = new Rule("expression"); Parser add = Ops.Sequence('+', term); integer.Parser = Ops.Sequence(Prims.Digit, Ops.ZeroOrMore(Prims.Digit)); number.Parser = Ops.Sequence(Ops.Optional(integer), Prims.Ch('.'), integer); group.Parser = Ops.Sequence('(', expression, ')'); term.Parser = group | number | integer; expression.Parser = Ops.Sequence(term, Ops.ZeroOrMore(add)); Assert.IsTrue(expression.Parse(new StringScanner("(.99+100)")).Success); Assert.IsTrue(expression.Parse(new StringScanner("(5.99+100)")).Success); }
public void List() //http://www.codeproject.com/csharp/spart.asp?df=100&forumid=30315&select=797847#xx797847xx { Parser real = Ops.Sequence(Ops.OneOrMore(Prims.Digit), Ops.Optional(Ops.Sequence('.', Ops.OneOrMore(Prims.Digit)))); Rule numList = new Rule(); numList.Parser = Ops.Sequence( real, Ops.ZeroOrMore(Ops.Sequence(Prims.Ch(','), real)), Prims.End); Assert.IsTrue(numList.Parse(new StringScanner("100")).Success); // THROWS INDEX EXCEPTION Assert.IsFalse(numList.Parse(new StringScanner("88,d,88,9.090,")).Success); // PARSES SUCCESSFULLY! Assert.IsFalse(numList.Parse(new StringScanner("88,88,9.090,")).Success); // PARSES SUCCESSFULLY! }
public void AnyTest() { Prims.Any <Char>() .Run("inputString".AsStream()) .Case( failure: (restStream, errorMessage) => Assert.Fail(), success: (restStream, value) => { Assert.AreEqual('i', value); Assert.True(restStream.Current.HasValue); Assert.AreEqual(1, restStream.Current.Value.Item1.Line); Assert.AreEqual(2, restStream.Current.Value.Item1.Column); }); Prims.Any <Char>() .Run("".AsStream()) .Case( failure: (restStream, errorMessage) => { /* OK */ }, success: (restStream, value) => Assert.Fail()); }
// Use this for initialization void Start() { problem = ProblemCamera.Import(problemPath); bois = new List <MotionModelCamera>(); points = new List <GameObject>(); spawnObjects(); prim = new Prims(problem.obstacles, problem.pointsOfInterest, scanningRadius); List <float[]> goodpoints = prim.getNewPointsOfInterest(); som = new SOMCamera(goodpoints, problem.startPositions, problem.goalPositions); List <float[]> interestings = new List <float[]>(); interestings.AddRange(goodpoints); interestings.AddRange(problem.goalPositions); interestings.AddRange(problem.startPositions); cooldown = waitTime; vGraph = new VisibilityGraphCamera(problem.obstacles, interestings); drawRadius(cooldown, goodpoints); Debug.Break(); }