public async Task BuildingFlowGraph_ShouldBuild() { EndpointConvention.Map <EFoo>(new Uri("queue:input-queue")); var harness = new InMemoryTestHarness() { TestTimeout = TimeSpan.FromSeconds(1) }; harness.Consumer(() => new AFooConsumer()); harness.Consumer(() => new BFooConsumer()); harness.Consumer(() => new CFooConsumer()); harness.Consumer(() => new DFooConsumer()); harness.Consumer(() => new EFooConsumer()); await harness.Start(); await harness.Bus.Publish <AFoo>(new { CorrelationId = Guid.NewGuid() }); await harness.Bus.Publish <BFoo>(new { CorrelationId = Guid.NewGuid() }); var graph = await GraphGenerator.Generate(harness); var converstationGraphs = string.Join(Environment.NewLine, graph.Select(StringGraphRenderer.Render)); await harness.Stop(); this.Assent(converstationGraphs); }
public void Test() { var columns = new string[5] { "Algorithm", "Vertices Count", "Edges Percent", "Calls Limit", "Time" }; var separator = ","; var filePath = "./times.csv"; File.WriteAllText(filePath, string.Join(separator, columns) + Environment.NewLine); Stopwatch stopwatch; UndirectedGraph graph, result; for (int i = 3; i < 8; i++) { for (double j = 0.2d; j < 0.8d; j += 0.2d) { graph = GraphGenerator.Generate(i, j); for (int k = 1; k <= 4; k++) { stopwatch = Stopwatch.StartNew(); result = new EdgeAlgorithm(k).ColorGraph(graph); stopwatch.Stop(); File.AppendAllText(filePath, string.Join(separator, "Edge", i, j.ToString(CultureInfo.InvariantCulture), k, stopwatch.ElapsedMilliseconds) + Environment.NewLine); stopwatch = Stopwatch.StartNew(); result = new MatchingAlgorithm(k).ColorGraph(graph); stopwatch.Stop(); File.AppendAllText(filePath, string.Join(separator, "Matching", i, j.ToString(CultureInfo.InvariantCulture), k, stopwatch.ElapsedMilliseconds) + Environment.NewLine); } } } }
void Start() { if (mc != null) { DestroyImmediate(gameObject); return; } mc = this; gg = Instantiate(generatorPrefab) as GraphGenerator; currentNode = gg.Generate(); if (storedNodeIndex != -1) { currentNode = gg.GetNode(storedNodeIndex); } currentNode.SetActive(true); Camera.main.transform.position = new Vector3(currentNode.transform.position.x, currentNode.transform.position.y, -20); mship = Instantiate(mshipprefab, currentNode.transform.position, Quaternion.identity) as MapMothership; mship.SetState(MshipState.ORBIT, currentNode); }
//Add node based on the indexing of the typeOfNode, will determine what kind of node spawn at each index. //Insert the appropriate list of integers to spawn the appropriate node types for each node. protected void GenerateInitPlanet(GraphGenerator generator, List <int> nodeTypes, int numberOfNodes, float scale) { listOfNodes = new List <PlanetNode>(); listOfLinks = new List <PlanetLink>(); GraphGenerator.GraphData graphData = generator.Generate(numberOfNodes, scale, containerForBoth.transform.position); for (int i = 0; i < graphData.nodes.Count; i++) { if (i > nodeTypes.Count - 1) { break; } GameObject obj = Instantiate(typeOfNode[nodeTypes[i]], graphData.nodes[i], graphData.nodes_rot[i], containerForNodes.transform); PlanetNode node = obj.GetComponent <PlanetNode>(); node.index = i; listOfNodes.Add(node); } for (int i = 0; i < graphData.links.Count; i += 2) { //Will definetly have no direction links because i said so. if (!graphData.isLinksDirectional) { GameObject obj = Instantiate(typeOfLink, Vector3.zero, Quaternion.identity, containerForLinks.transform); PlanetLink link = obj.GetComponent <PlanetLink>(); int index1 = graphData.links[i]; int index2 = graphData.links[i + 1]; link.nodePrev = listOfNodes[index1]; link.nodeNext = listOfNodes[index2]; link.PlaceLinkAtNodes(); listOfLinks.Add(link); } } }
public void SevenVerticesTwentyFivePercentEdgesTest() { int verticesCount = 7; double edgePercent = 0.25; var graph = GraphGenerator.Generate(verticesCount, edgePercent); int expectedEdgesCount = (int)(edgePercent * verticesCount * (verticesCount - 1) / 2); Assert.AreEqual(verticesCount, graph.VerticeCount()); Assert.AreEqual(expectedEdgesCount, graph.EdgeCount()); }
void Start() { if (mc != null) { DestroyImmediate (gameObject); return; } mc = this; gg = Instantiate (generatorPrefab) as GraphGenerator; currentNode = gg.Generate (); if (storedNodeIndex != -1) { currentNode = gg.GetNode(storedNodeIndex); } currentNode.SetActive (true); Camera.main.transform.position = new Vector3 (currentNode.transform.position.x, currentNode.transform.position.y, -20); mship = Instantiate(mshipprefab, currentNode.transform.position, Quaternion.identity) as MapMothership; mship.SetState(MshipState.ORBIT, currentNode); }
private void GraphGenerate() { erText.Text = ""; GraphGenerator graphGenerator = new GraphGenerator(); int nodeCount = 5; int percent = 70; int width = 5; try { nodeCount = Int32.Parse(nodeCountTextBox.Text); percent = Int32.Parse(percentTextBox.Text); width = Int32.Parse(difficult.SelectedItem.ToString()); } catch { erText.Text = "Только целые числа"; } graphGenerator.Width = width; graph = graphGenerator.Generate(nodeCount); graph.Percent = percent; graph.RefactorGraph(); nodeGrid.ItemsSource = graph.Nodes; edgeGrid.ItemsSource = graph.Edges; painter = new Painter(canvas1, graph); painter.Draw(); canvas1.IsEnabled = true; }
private static void Main() { #region Initialize var random = new Random(); var generator = new GraphGenerator(random); var algorithm = new Algorithm <Chromosome>(random); #endregion var results = new List <List <List <AlgorithmResult <Chromosome> > > >(); for (int verticesNumber = VerticesNumberFrom; verticesNumber <= VerticesNumberTo; verticesNumber++) { Console.WriteLine($"{verticesNumber} vertices"); results.Add(new List <List <AlgorithmResult <Chromosome> > >()); for (int degree = DegreeFrom; degree <= verticesNumber; degree++) { results[verticesNumber - VerticesNumberFrom].Add(new List <AlgorithmResult <Chromosome> >()); for (int chromosomesNumber = ChromosomesNumberFrom; chromosomesNumber <= ChromosomesNumberTo; chromosomesNumber++) { var averageIterationsOrder = 0; var averagePathOrder = 0; var averageIterationsCycle = 0; var averagePathCycle = 0; var averageIterationsRandom = 0; var averagePathRandom = 0; var averageIterations = 0; var averagePath = 0; for (var graphCase = 0; graphCase < GraphsNumber; graphCase++) { Graph graph = generator.Generate(verticesNumber, degree); graph.Randomize(random); #region Chromosomes var chromosomes = new List <Chromosome>(); for (var i = 0; i < chromosomesNumber; i++) { var chromosome = new Chromosome(); foreach (List <int> _ in graph.Edges) { int vertex; do { vertex = random.Next(graph.Edges.Count); } while (chromosome.Vertices.Contains(vertex)); chromosome.Vertices.Add(vertex); } chromosomes.Add(chromosome); } #endregion #region Functions var fitnessFunction = new Func <Chromosome, double>(c => { var sum = 0; for (var i = 0; i < c.Vertices.Count - 1; i++) { sum += graph.Edges[c.Vertices[i]][c.Vertices[i + 1]]; } return(sum + graph.Edges[c.Vertices[^ 1]][0]);
void SetupGraph() { GraphGenerator graphGenerator = new GraphGenerator(startingPoint, endingPoint); G = graphGenerator.Generate(); }