public void Neighbors() { var edgeListLines = this.GetSimpleEdgeListLines(); var graph = GraphLoader.FromEdgeListLines(edgeListLines); var outgoingNeighbors = graph.GetNeighbors(EdgeDirection.Outgoing); Assert.Equal( expected: "{\"1\":[2,3,4],\"2\":[3,4],\"3\":[4],\"4\":[]}", actual: Json.Encode(outgoingNeighbors)); var incomingNeighbors = graph.GetNeighbors(EdgeDirection.Incoming); Assert.Equal( expected: "{\"1\":[],\"2\":[1],\"3\":[1,2],\"4\":[1,2,3]}", actual: Json.Encode(incomingNeighbors)); var eitherNeighbors = graph.GetNeighbors(EdgeDirection.Either); Assert.Equal( expected: "{\"1\":[2,3,4],\"2\":[1,3,4],\"3\":[1,2,4],\"4\":[1,2,3]}", actual: Json.Encode(eitherNeighbors)); var bothNeighbors = graph.GetNeighbors(EdgeDirection.Both); Assert.Equal( expected: "{\"1\":[],\"2\":[],\"3\":[],\"4\":[]}", actual: Json.Encode(bothNeighbors)); }
public MainForm() { InitializeComponent(); if (!Settings.Default.LastSize.IsEmpty) { StartPosition = FormStartPosition.Manual; Location = Settings.Default.LastLocation; Size = Settings.Default.LastSize; splitContainer1.SplitterDistance = Settings.Default.SplitterPosition; } this.treeView1.AllowDrop = true; this.graphControl1.AllowDrop = true; this.treeView1.MouseDown += new MouseEventHandler(listBox1_MouseDown); this.treeView1.DragOver += new DragEventHandler(listBox1_DragOver); this.graphControl1.DragEnter += new DragEventHandler(treeView1_DragEnter); this.graphControl1.DragDrop += new DragEventHandler(treeView1_DragDrop); IDictionary <Guid, Type> filterTypes = FiltersHelper.GetFilterTypes(); UpdateTreeView(filterTypes); if (File.Exists(PathToXml)) { GraphBundle graphBundle = GraphLoader.Load(PathToXml); graphControl1.LoadGraph(graphBundle); } else { graphControl1.LoadGraph(new GraphBundle()); } }
static void Main(string[] args) { bool isGraphsChecker = IsValidGraphsChecker(args); bool isComplexityChecker = IsValidComplexityChecker(args); if (!(isGraphsChecker ^ isComplexityChecker)) { ShowHelp(args); return; } bool exact = args[0] == "exact"; if (isGraphsChecker) { var G = GraphLoader.FromCSV(args[1]); var H = GraphLoader.FromCSV(args[2]); var modularGraph = ModularGraph.Create(G, H); if (exact) { var exactResult = new Exact(G, H, modularGraph).Run(); GraphLoader.ToCSV(exactResult, "Examples/exact.csv"); } else { var approximateResult = new Approximate(G, H, modularGraph).Run(); GraphLoader.ToCSV(approximateResult, "Examples/approximate.csv"); } } else { new ComplexityChecker(args[2], exact).Run(); } }
static void Main(string[] args) { DateTime dt = DateTime.Now; int option = 0; if (args.Length != 2) { throw new ArgumentException( "Wrong number of arguments!Please specify two paths for the first and second input graphs"); } var G1 = GraphLoader.LoadGraph(args[0]); var G2 = GraphLoader.LoadGraph(args[1]); State s = new State(G1.AdjacencyMatrix, G2.AdjacencyMatrix); if (option == 0) { Console.Write("V Solution\n"); SolutionV.McGregor(new State(G1.AdjacencyMatrix, G2.AdjacencyMatrix), ref s); } else { Console.Write("V+E Solution\n"); SolutionV.McGregor(new State(G1.AdjacencyMatrix, G2.AdjacencyMatrix), ref s, 1); } //List<Edge> edges = s.correspondingEdges.Select(x => x.Item1).ToList(); GraphLoader.WriteSummary(G1, G2, s.correspondingEdges, s.correspondingVerticles.Count(x => x.v1 != -1 && x.v2 != -1)); }
public void Degrees() { var edgeListLines = this.GetSimpleEdgeListLines(); var graph = GraphLoader.FromEdgeListLines(edgeListLines); var outgoingDegrees = graph.GetOutgoingDegrees(); var incomingDegrees = graph.GetIncomingDegrees(); var degrees = graph.GetDegrees(); Assert.Equal(expected: 4, actual: outgoingDegrees.Count); Assert.Equal(expected: 4, actual: incomingDegrees.Count); Assert.Equal(expected: 4, actual: degrees.Count); Assert.Equal(expected: 3, actual: outgoingDegrees[1]); Assert.Equal(expected: 2, actual: outgoingDegrees[2]); Assert.Equal(expected: 1, actual: outgoingDegrees[3]); Assert.Equal(expected: 0, actual: outgoingDegrees[4]); Assert.Equal(expected: 0, actual: incomingDegrees[1]); Assert.Equal(expected: 1, actual: incomingDegrees[2]); Assert.Equal(expected: 2, actual: incomingDegrees[3]); Assert.Equal(expected: 3, actual: incomingDegrees[4]); Assert.Equal(expected: 3, actual: degrees[1]); Assert.Equal(expected: 3, actual: degrees[2]); Assert.Equal(expected: 3, actual: degrees[3]); Assert.Equal(expected: 3, actual: degrees[4]); }
public void Indexing() { var edgeListLines = this.GetSimpleEdgeListLines(); var graph = GraphLoader.FromEdgeListLines(edgeListLines); Assert.Equal( expected: "{\"Vertices\":{\"1\":0,\"2\":0,\"3\":0,\"4\":0},\"OutgoingEdges\":{\"1\":{\"2\":0,\"3\":0,\"4\":0},\"2\":{\"3\":0,\"4\":0},\"3\":{\"4\":0}},\"IncomingEdges\":{\"2\":{\"1\":0},\"3\":{\"1\":0,\"2\":0},\"4\":{\"1\":0,\"2\":0,\"3\":0}}}", actual: graph.ToDebugString()); }
static void Main(string[] args) { var gl = new GraphLoader(); var graph = gl.LoadFromCsvFile("../../../Datasets/KarateClub/KarateClub.csv"); var kl = new KernighanLin(); var clusteredGraph = kl.Cluster(graph); var exporter = new GraphExporter(); exporter.ExportToCsv(clusteredGraph, "../../../Datasets/KarateClub/KarateClubClustered.csv"); }
public void Loading() { var edgeListLines = this.GetSimpleEdgeListLines(); var graph = GraphLoader.FromEdgeListLines(edgeListLines); var vertices = graph.GetVertices(); var edges = graph.GetEdges(); Assert.Equal(expected: 4, actual: vertices.Count); Assert.Equal(expected: 6, actual: edges.Count); }
static void Main(string[] args) { var gl = new GraphLoader(); var florentine = gl.LoadMultilayerGraph("../../../Datasets/Florentine/florentine.mpx"); florentine.ActorNames.ForEach(e => florentine.PrintInfoAboutActor(e)); var gc = new GraphConverter(); var acmTemporal = gl.LoadTemporalGraph("../../../Datasets/ACM Hypertex 2009/ht09_contact_list.tsv"); var acmMultilayer = gc.ConvertTemporalToMultilayerGraph(acmTemporal, 5); acmMultilayer.ActorNames.ForEach(e => acmMultilayer.PrintInfoAboutActor(e)); }
//List<GraphNode> path; //bool x = false; // Use this for initialization IEnumerator Start() { loader = GetComponent <GraphLoader>(); while (!loader.IsReady) { //Debug.Log("not ready"); yield return(null); } int totalPoints = loader.wayPoints.Count; // Number of cars cannot exceed number of waypoints if (carPopulation >= totalPoints) { carPopulation = totalPoints - (carPopulation / 10); } Dictionary <Vector3, bool> selectedNodes = new Dictionary <Vector3, bool>(); //Debug.Log("total cars is: " + carPopulation); for (int i = 0; i < carPopulation; i++) { // Debug.Log("i is: " + i); Vector3 start = loader.wayPoints[random.Next(loader.wayPoints.Count - 1)]; if (selectedNodes.ContainsKey(start)) { while (selectedNodes.ContainsKey(start)) { start = loader.wayPoints[random.Next(loader.wayPoints.Count - 1)]; } } Vector3 end = loader.wayPoints[random.Next(loader.wayPoints.Count - 1)]; if (start == end) { while (start == end) { end = loader.wayPoints[random.Next(loader.wayPoints.Count - 1)]; } } selectedNodes.Add(start, true); //selectedNodes.Add(end, true); GameObject Car = Instantiate(carPrefab, start, Quaternion.identity); path = loader.graph.ShortestPath(loader.graph.nodes[start], loader.graph.nodes[end]); Car.GetComponent <CarMove>().wayPoints = path; // Car.GetComponent<CarMove>().destination = loader.wayPoints[random.Next(loader.wayPoints.Count - 1)]; } }
public string Transpile(string source) { var scope = new Scope(_compiler.Scope); scope.AddUniqueId("v"); var jobject = JObject.Parse(source); var doc = GraphLoader.FromWebNodes(jobject, scope, serializers: GraphModel.Serializers); var text = string.Empty; _compiler.CompileInstance(doc, out text); return(text); }
static void Main(string[] args) { var gl = new GraphLoader(); var graph = gl.LoadFromCsvFile("../../../Datasets/KarateClub/KarateClub.csv"); graph.NormalizeIds(); var clusterer = new KCoreClusterer(); clusterer.Cluster(graph, 1); clusterer.Cluster(graph, 2); clusterer.Cluster(graph, 3); clusterer.Cluster(graph, 4); }
static void Main(string[] args) { string pathToFile1, pathToFile2; int generationSize, generationCount; var breakWhenScoreDrops = false; if (args.Length < 4) { throw new ArgumentException("Too few arguments"); } if (!string.IsNullOrEmpty(args[0]) && !string.IsNullOrEmpty(args[1])) { pathToFile1 = args[0]; pathToFile2 = args[1]; } else { throw new ArgumentException("Empty path arguments"); } if (int.TryParse(args[2], out var value1) && int.TryParse(args[3], out var value2)) { generationSize = value1; generationCount = value2; } else { throw new ArgumentException("Could not parse generation size or generation count"); } if (args.Length == 5 && bool.TryParse(args[4], out var value)) { breakWhenScoreDrops = value; } var g1 = GraphLoader.LoadGraph(pathToFile1); var g2 = GraphLoader.LoadGraph(pathToFile2); var watch = Stopwatch.StartNew(); var algorithm = new GeneticAlgorithm(generationSize, generationCount, breakWhenScoreDrops); var solution = algorithm.FindMaximalCommonSubgraph(g1, g2); Console.WriteLine(solution.ToString()); #if DEBUG Console.WriteLine($"{watch.ElapsedMilliseconds}ms, score={solution.Score}"); #endif }
static void Main(string[] args) { var gl = new GraphLoader(); var graph = gl.LoadFromCsvFile("../../../Datasets/KarateClub/KarateClub.csv"); graph.NormalizeIds(); //var adjacencyMatrix = graph.GetAdjacencyMatrix(); //var cosineSimilarityMatrix = adjacencyMatrix.GetCosineSimilarityMatrix(); var clusterer = new HierarchicalAgglomerativeClusterer(); clusterer.Cluster(graph); var exporter = new GraphExporter(); //exporter.ExportToCsv(basic, "../../../Datasets/basicGraph.csv"); //exporter.ExportToCsv(holmeKim, "../../../Datasets/holmeKim.csv"); }
public void Reverse_RandomGraph() { var edgeList = this.GetRandomEdgeList(100, 100); var graph = GraphLoader.FromEdgeList(edgeList); var graphPrime = graph.Reverse(); TestHelpers.DictionaryEqual(graph.GetOutgoingDegrees(), graphPrime.GetIncomingDegrees()); TestHelpers.DictionaryEqual(graph.GetIncomingDegrees(), graphPrime.GetOutgoingDegrees()); Assert.Equal( Json.Encode(graph.GetNeighbors(EdgeDirection.Outgoing)), Json.Encode(graphPrime.GetNeighbors(EdgeDirection.Incoming))); Assert.Equal( Json.Encode(graph.GetNeighbors(EdgeDirection.Incoming)), Json.Encode(graphPrime.GetNeighbors(EdgeDirection.Outgoing))); }
public void Load() { GraphLoader graphLoader = new GraphLoader(); Graph graph = graphLoader.Load("AB200, BC100 "); Assert.IsNotNull(graph); var nodes = graph.GetNodes(); CollectionAssert.AreEquivalent(new[] { "A", "B", "C" }.ToList(), nodes.ToList()); var neighbors = graph.GetNeighbors("A").ToList(); Assert.AreEqual(1, neighbors.Count); Assert.AreEqual("A", neighbors[0].FromNode); Assert.AreEqual("B", neighbors[0].ToNode); Assert.AreEqual(200, neighbors[0].Weight); }
public void Degrees_RandomGraph() { var edgeList = this.GetRandomEdgeList(100, 100); var graph = GraphLoader.FromEdgeList(edgeList); var outgoingDegrees = graph.GetOutgoingDegrees(); var incomingDegrees = graph.GetIncomingDegrees(); var degrees = graph.GetDegrees(); Assert.Equal( expected: degrees.Sum(vertex => vertex.Value), actual: outgoingDegrees.Sum(vertex => vertex.Value) + incomingDegrees.Sum(vertex => vertex.Value)); Assert.Equal( expected: 2 * graph.GetEdges().Count, actual: degrees.Sum(vertex => vertex.Value)); }
private void LoadFile() { try { gr = GraphLoader.Load(fileName.Text); begSelector.Maximum = gr.GetLength(0); endSelector.Maximum = gr.GetLength(0); begSelector.Enabled = true; endSelector.Enabled = true; btnStart.Enabled = true; } catch (Exception e) { begSelector.Enabled = false; endSelector.Enabled = false; btnStart.Enabled = false; } }
private static bool Init(string[] args) { try { _graph = GraphLoader.LoadGraph(args[0]); int tmp; if (!int.TryParse(args[1], out tmp) || !_graph.Nodes.Contains(tmp)) { _error = "Given node value isn't an integer or doesn't exist in given graph"; return(false); } _startNode = tmp; _costs = new List <float>(_graph.Count); for (int i = 0; i < _graph.Count; i++) { _costs.Add(MAX_WEIGHT); } _costs[_startNode] = 0; _edges = new List <Tuple <int, int, float> >(); List <float?> nodeEdges; for (int i = 0; i < _graph.Count; i++) { nodeEdges = _graph.Edges[i]; for (int j = 0; j < nodeEdges.Count; j++) { if (nodeEdges[j].HasValue) { _edges.Add(new Tuple <int, int, float>(i, j, nodeEdges[j].Value)); } } } return(true); } catch (Exception ex) { _error = ex.Message + '\n'; _error += ex.StackTrace; return(false); } }
static void Main(string[] args) { if (args.Length != 3 || (args[2] != "V" && args[2] != "E")) { throw new ArgumentException("Invalid arguments!"); } var graphA = GraphLoader.LoadGraph(args[0]); var graphB = GraphLoader.LoadGraph(args[1]); Console.WriteLine(); var modularGraph = new ModularGraph(graphA, graphB); var result = modularGraph.LargestCliqueHeuristic(args[2] == "1"); var edgesA = graphA.Subgraph(result.Item1).Edges; var edgesB = graphB.Subgraph(result.Item2).Edges; GraphLoader.WriteSummary(graphA, graphB, edgesA, edgesB, result.Item1.Count); }
protected override void Run() { var graphs = GraphLoader.GetRandomGraphsVariety(10); var options = new BenchmarkOptions() { EarlyStopTime = 5000, }; var scenarios = new List <BenchmarkScenario <int> >() { // GetNonCorridorScenario(graphs), GetCorridorScenario(graphs), }; var scenarioGroup = new MinimumDistanceScenario().GetScenario(graphs, new MinimumDistanceScenario.Options()); var generators = new List <ILevelGeneratorFactory <int> >() { GetNewGenerator <int>(options), GetOldGenerator <int>(options), GetNewGenerator <int>(options), GetOldGenerator <int>(options), //GetNewGenerator<int>(options, true), //GetOldGenerator<int>(options, true), //GetNewGenerator<int>(options), //GetNewGenerator<int>(options, optimizeCorridorConstraints: true, name: "CorCons"), //GetNewGenerator<int>(options), //GetNewGenerator<int>(options, optimizeCorridorConstraints: true, name: "CorCons"), // GetNewGenerator<int>(options), // GetBeforeMasterThesisGenerator<int>(options), // GetOldGenerator<int>(options), // GetOldGenerator<int>(options, true), // GetNewGenerator<int>(options), }; // LoadFromFolder<int>(); RunBenchmark(scenarios, generators); // RunBenchmark(scenarioGroup, generators); }
protected override void Run() { var graphs = GraphLoader.GetRandomGraphsVariety(20); var options = new BenchmarkOptions() { EarlyStopTime = 5000, }; var scenarios = new List <BenchmarkScenario <int> >() { GetDeformedScenario(graphs), GetNormalScenario(graphs), }; var generators = new List <ILevelGeneratorFactory <int> >() { GetOldGenerator <int>(options), GetNewGenerator <int>(options), }; RunBenchmark(scenarios, generators); }
static void Main(string[] args) { var gl = new GraphLoader(); var karate = gl.LoadFromCsvFile("../../../Datasets/KarateClub/KarateClub.csv"); var erdos = gl.LoadFromEdgeListFile("../../../Datasets/Lesson07B/erdos_export"); var barabasi = gl.LoadFromEdgeListFile("../../../Datasets/Lesson07B/barabasi_export"); var airports = gl.LoadFromEdgeListFile("../../../Datasets/Lesson07B/airports_export"); var sm = new SirModel(); double beta = 0.3; int mu = 5; int iterations = 30; var karateSirDistribution = sm.Simulate(karate, beta, mu, iterations); var erdosSirDistribution = sm.Simulate(erdos, beta, mu, iterations); var barabasiSirDistribution = sm.Simulate(barabasi, beta, mu, iterations); var airportsSirDistribution = sm.Simulate(airports, beta, mu, iterations); ExportDistributionToCsv(karateSirDistribution, "../../../Exports/KarateClubSirDistribution.csv"); ExportDistributionToCsv(erdosSirDistribution, "../../../Exports/ErdosSirDistribution.csv"); ExportDistributionToCsv(barabasiSirDistribution, "../../../Exports/BarabasiSirDistribution.csv"); ExportDistributionToCsv(airportsSirDistribution, "../../../Exports/AirportsSirDistribution.csv"); }
void GetSampleGraph() { var loader = new GraphLoader(); _testgraph = loader.LoadInputData(new SimpleExampleDataSet()); }
static int Main(string[] args) { const string usageMessage = "Usage:\nepoxy <configuration json file>"; if (args.Length != 1 || args[0] == "-h" || args[0] == "--help") { Console.Error.WriteLine(usageMessage); return(-1); } string configurationJsonFilePath = args[0]; if (!File.Exists(configurationJsonFilePath)) { Console.Error.WriteLine($"Configuration file '{configurationJsonFilePath}' does not exist."); if (!Path.IsPathRooted(configurationJsonFilePath)) { Console.Error.WriteLine($"Path appears to be relative and the current working directory is '{Directory.GetCurrentDirectory()}'."); } return(-2); } Configuration config = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText(configurationJsonFilePath)); (bool configIsValid, string message) = config.Validate(); if (!configIsValid) { if (!message.IsNullOrEmpty()) { Console.Error.WriteLine($"Invalid configuration: {message}"); } return(-3); } Graph graph = GraphLoader.LoadGraph(Directory.EnumerateFiles(config.DoxygenXmlDirectory).Where(file => Path.GetExtension(file) == ".xml")); if (graph == null) { Console.Error.WriteLine("Failed to load C++ library definitions successfully."); return(-4); } foreach (BinderConfiguration binderConfig in config.Binders) { IBinder binder = BinderFactory.GetBinder(binderConfig); if (binder == null) { Console.WriteLine($"Warning: language '{binderConfig.Language}' currently does not have a binder implemented-skipping."); continue; } binder.GenerateNativeBindings(graph); binder.GenerateLanguageBindings(graph); } Console.WriteLine("SUCCESS"); return(0); }
public static void Setup(TestContext context) { Graph map = new GraphLoader().Load("AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7"); m_mapQuery = new MapQuery(map); }
public static void Main(string[] args) { var buildConfig = BuildConfiguration(); var config = buildConfig.GetSection(nameof(AppConfiguration)); var dataPath = config["data"]; var resultPath = config["results"]; var graphEdges = System.IO.Path.Combine(dataPath, config["graphEdges"]); var graphCoordinates = System.IO.Path.Combine(dataPath, config["graphCoordinates"]); var dataLoader = new GraphLoader(graphEdges, 100); var graph = dataLoader.Load(); var calculationStrategies = new ISimilarityCalculationStrategy[] { new EdgeSimillarityStrategy(), new NodeSimilarityStrategy() }; var simpleSolver = new TspSolver(graph); var localSearchSolver = new TspLocalSearchSolver(graph); var edgeFinder = new GraspEdgeFinder(3); var evolutinarySolver = new EvolutionarySolver(graph, new Recombinator(new SimilarityFinder(calculationStrategies), Steps, graph), new Selector(), 41000); var localSearch = new LocalSearchAlgorithm(Steps, edgeFinder); var stats = new BasicSolverStatistics(); var bestCost = int.MaxValue; ISolverStatistics bestStatistics = new BasicSolverStatistics(); for (var i = 0; i < 10; i++) { var generatedPaths = simpleSolver.Solve(new RandomPathAlgorithm(Steps, edgeFinder)); generatedPaths = localSearchSolver.Solve(localSearch, generatedPaths); evolutinarySolver.Solve(localSearch, generatedPaths); if (evolutinarySolver.SolvingStatistics.BestPath.Cost < bestCost) { bestCost = evolutinarySolver.SolvingStatistics.BestPath.Cost; bestStatistics = evolutinarySolver.SolvingStatistics; } stats.UpdateSolvingResults(evolutinarySolver.SolvingStatistics.BestPath, evolutinarySolver.SolvingStatistics.MeanSolvingTime); } var statsPrinter = new FilePrinter(resultPath, "evo_stats.res"); statsPrinter.Print(stats.ToString()); var output = new StringBuilder(); output.AppendLine($"{"Id".PadRight(4)}\tCost\tTime"); for (var i = 0; i < bestStatistics.Costs.Count; i++) { output.AppendLine($"{i.ToString().PadRight(4)}\t{bestStatistics.Costs[i].ToString().PadRight(4)}\t{bestStatistics.SolvingTimes[i].Milliseconds:D}"); } var evoResultsPrinter = new FilePrinter(resultPath, "evolutionary_results.res"); evoResultsPrinter.Print(output.ToString()); Console.WriteLine("Evolutionary solver ended his work!"); //SimilaritySolver(resultPath, graph, calculationStrategies, edgeFinder); }