/// <summary> /// Feeds the layout thread /// </summary> public override void StartLayout() { if (nodes.Count <= 1) { return; //nothing to do } //if there are cycles in the graph we have infinite loops, make sure the layout is finite //by checking this list for (int k = 0; k < nodes.Count; k++) { visited[nodes[k].UID.ToString()] = false; positioned[nodes[k].UID.ToString()] = false; nodes[k].Tag = k; //makes sure we can get the index in the collection } //the structure depends on a spanning tree (Prim's algorithm here) if (extract == null) { throw new Exception("The layout algorithm doesn't have a GraphAbstract to work with."); } GraphAnalyzer analyzer = new GraphAnalyzer(extract, true); IGraph g = Algorithms.PrimsAlgorithm(analyzer, 0);//TODO: allow to modify the starting vertex //IGraph g = Algorithms.KruskalsAlgorithm(analyzer); mSite.OutputInfo("Prim's:" + Environment.NewLine); mSite.OutputInfo(g.ToString()); if (g == null) { return; //TODO: notify the failure to find a spanning tree } VerticalDrawTree(g, nodes[0], true, 30, 30); //VerticalDrawTree(g,nodes[rnd.Next(0,nodes.Count-1)],true,30,30); }
public void TestMissingProjectFile() { var mockLogger = new Mock <ILogger>(); var mockProjectAnalyzer = new Mock <IProjectAnalyzer>(); var mockResultsReporter = new Mock <IResultsReporter>(); var analyzer = new GraphAnalyzer(mockLogger.Object, mockProjectAnalyzer.Object, mockResultsReporter.Object, true); string doesNotExistPath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}"); analyzer.AnalyzeGraph(doesNotExistPath); }
public void TestExistingProjectFile() { string testProject = TestUtilities.CreateTestProject(); var mockLogger = new Mock <ILogger>(); var mockProjectAnalyzer = new Mock <IProjectAnalyzer>(); var mockResultsReporter = new Mock <IResultsReporter>(); mockProjectAnalyzer.Setup(a => a.IsBuildUpToDate(It.IsAny <string>())).Returns((true, string.Empty)); var analyzer = new GraphAnalyzer(mockLogger.Object, mockProjectAnalyzer.Object, mockResultsReporter.Object, true); bool isUpToDate = analyzer.AnalyzeGraph(testProject); Assert.IsTrue(isUpToDate); TestUtilities.CleanUpTestProject(testProject); }
internal static void Process(Graph graph) { int iteration = 1; bool foundPatterns; PatternMap patterns = null; if (File.Exists(PATH)) { File.Delete(PATH); } do { Console.WriteLine("\nИтерация №" + iteration); if (graph.VertexCount < 3) { Console.WriteLine("Граф имеет слишком мало вершин для поиска паттернов."); break; } Console.WriteLine("Ищем паттерны..."); var analyzer = new GraphAnalyzer(graph, patterns); foundPatterns = analyzer.FindPatterns(out patterns); if (foundPatterns) { Console.WriteLine("Найдено экземпляров паттернов: " + patterns.TotalInstances); Console.WriteLine("Делаем подстановку..."); graph.ReplacePatterns(patterns); Export(patterns, iteration); iteration++; } else { Console.WriteLine("Паттернов не обнаружено."); } } while (foundPatterns); Console.WriteLine("Поиск завершён."); }
public Transformation calculateTransformation(List <Contour <Point> > contours_image1, List <Contour <Point> > contours_image2) { List <Feature> image1_features = new List <Feature>(); List <Feature> image2_features = new List <Feature>(); //Get the points of the FIRST (=0) contour Point[] points1 = contours_image1[0].ToArray(); //Calculate the angle at every pixel for picture 1 for (int i = 0; i < points1.Length; i++) { AngleCalculator angleCalculator = new AngleCalculator(); double angle = angleCalculator.calculateAngle(points1, i); Feature f = new Feature(); f.point = points1[i]; f.angle_at_pixel = angle; image1_features.Add(f); } //Get the points of the FIRST (=0) contour Point[] points2 = contours_image2[0].ToArray(); //Calculate the angle at every pixel for picture 2 for (int i = 0; i < points2.Length; i++) { AngleCalculator angleCalculator = new AngleCalculator(); double angle = angleCalculator.calculateAngle(points2, i); Feature f = new Feature(); f.point = points2[i]; f.angle_at_pixel = angle; image2_features.Add(f); } GraphAnalyzer graphanalyzer = new GraphAnalyzer(); //Normalize the shorter contour to longer one List <Feature> image1_features_normalized; List <Feature> image2_features_normalized; if (image1_features.Count < image2_features.Count) { image1_features_normalized = graphanalyzer.normalize(image2_features, image1_features); image2_features_normalized = image2_features; } else { image2_features_normalized = graphanalyzer.normalize(image1_features, image2_features); image1_features_normalized = image1_features; } //Moves the contour(graph) of image1 to best matching image1_features_normalized = graphanalyzer.matchGraphs(image1_features_normalized, image2_features_normalized); //Get the best Features by using extrema [0] image1 --> [1] image2, .... List <Feature> bestFeatures = graphanalyzer.findBestFeaturesWithExtrema(image1_features_normalized, image2_features_normalized); bestFeatureStorage1.Add(bestFeatures[0]); bestFeatureStorage1.Add(bestFeatures[2]); bestFeatureStorage2.Add(bestFeatures[1]); bestFeatureStorage2.Add(bestFeatures[3]); //Calculating the transformation for the best features Transformation transformation = calculateTransformationValues(bestFeatures); //Exporting the graph Exporter exporter = new Exporter(); exporter.exportFeatures(image1_features_normalized, image2_features_normalized); return(transformation); }
public Transformation calculateTransformation(List<Contour<Point>> contours_image1, List<Contour<Point>> contours_image2) { List<Feature> image1_features = new List<Feature>(); List<Feature> image2_features = new List<Feature>(); //Get the points of the FIRST (=0) contour Point[] points1 = contours_image1[0].ToArray(); //Calculate the angle at every pixel for picture 1 for (int i = 0; i < points1.Length; i++) { AngleCalculator angleCalculator = new AngleCalculator(); double angle = angleCalculator.calculateAngle (points1, i); Feature f = new Feature(); f.point = points1[i]; f.angle_at_pixel = angle; image1_features.Add(f); } //Get the points of the FIRST (=0) contour Point[] points2 = contours_image2[0].ToArray(); //Calculate the angle at every pixel for picture 2 for (int i = 0; i < points2.Length; i++) { AngleCalculator angleCalculator = new AngleCalculator(); double angle = angleCalculator.calculateAngle(points2, i); Feature f = new Feature(); f.point = points2[i]; f.angle_at_pixel = angle; image2_features.Add(f); } GraphAnalyzer graphanalyzer = new GraphAnalyzer(); //Normalize the shorter contour to longer one List<Feature> image1_features_normalized; List<Feature> image2_features_normalized; if (image1_features.Count < image2_features.Count) { image1_features_normalized = graphanalyzer.normalize(image2_features, image1_features); image2_features_normalized = image2_features; } else { image2_features_normalized = graphanalyzer.normalize(image1_features, image2_features); image1_features_normalized = image1_features; } //Moves the contour(graph) of image1 to best matching image1_features_normalized = graphanalyzer.matchGraphs(image1_features_normalized, image2_features_normalized); //Get the best Features by using extrema [0] image1 --> [1] image2, .... List<Feature> bestFeatures = graphanalyzer.findBestFeaturesWithExtrema(image1_features_normalized, image2_features_normalized); bestFeatureStorage1.Add(bestFeatures[0]); bestFeatureStorage1.Add(bestFeatures[2]); bestFeatureStorage2.Add(bestFeatures[1]); bestFeatureStorage2.Add(bestFeatures[3]); //Calculating the transformation for the best features Transformation transformation = calculateTransformationValues(bestFeatures); //Exporting the graph Exporter exporter = new Exporter(); exporter.exportFeatures(image1_features_normalized, image2_features_normalized); return transformation; }