public void HyperGraph_must_work() { string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "TestFiles", "tEdgePieces.txt"); //string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "TestFiles", "tEdgePieces.txt"); HyperGraph hyperGraph = GraphGenerator.LoadHyperGraphFromFile(path); //Tuple<string, int>[] degrees = hyperGraph.GetVertexDegrees(); Tuple <string, int>[] degrees = hyperGraph.GetVertexEulerDegrees(); int greenEdgeDegree = 0; int redEdgeDegree = 0; int redEdgeCount = 0; int greenEdgeCount = 0; int evenEdgeDegree = 0; int evenEdgeCount = 0; int maxDegree = degrees.Select(d => d.Item2).Max(); Tuple <string, int>[] maxDegrees = degrees.Where(d => d.Item2 == 6).ToArray(); foreach (Tuple <string, int> tuple in degrees) { int i = Convert.ToInt32(tuple.Item1[0]); int j = Convert.ToInt32(tuple.Item1[1]); if (i < j) { greenEdgeDegree += tuple.Item2; greenEdgeCount++; } else if (i > j) { redEdgeDegree += tuple.Item2; redEdgeCount++; } else { evenEdgeDegree += tuple.Item2; evenEdgeCount++; } } Tuple <string, int>[] orderedDegrees = degrees.OrderBy(t => t.Item2).ThenBy(t => t.Item1).ToArray(); string outputPath = @"C:\Users\Moritz\Dropbox\Studium\Fulda\5_SS19\Project\Triominos\Graphsuite\GraphSuite\Files"; string outputFile = "tEdgePiecesEulerDegrees.txt"; if (File.Exists(Path.Combine(outputPath, outputFile))) { File.Delete(Path.Combine(outputPath, outputFile)); } File.WriteAllLines(Path.Combine(outputPath, outputFile), degrees.OrderBy(x => x.Item1).Select(d => d.Item1 + " => " + d.Item2)); //Tuple<int, Stack<Tuple<string, HyperEdge<string>>>>[] cycles = hyperGraph.GetAllSimpleCycles(); }
public void HyperGraph_has_to_work() { string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "TestFiles", "tEdgeGraph.txt"); //string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "TestFiles", "tEdgePieces.txt"); HyperGraph hyperGraph = GraphGenerator.LoadHyperGraphFromFile(path); //Tuple<string, int>[] degrees = hyperGraph.GetVertexDegrees(); Tuple <string, int>[] degrees = hyperGraph.GetVertexEulerDegrees(); string outputPath = @"C:\Users\Moritz\source\repos\GraphSuite\Files"; string outputFile = "tEdgeEulerDegrees.txt"; if (File.Exists(Path.Combine(outputPath, outputFile))) { File.Delete(Path.Combine(outputPath, outputFile)); } File.WriteAllLines(Path.Combine(outputPath, outputFile), degrees.OrderBy(x => x.Item1).Select(d => d.Item1 + " => " + d.Item2)); //Tuple<int, Stack<Tuple<string, HyperEdge<string>>>>[] cycles = hyperGraph.GetAllSimpleCycles(); }
public void GetTileProbabilities() { string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "TestFiles", "tEdgePieces.txt"); //string path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "TestFiles", "tEdgePieces.txt"); HyperGraph hyperGraph = GraphGenerator.LoadHyperGraphFromFile(path); //Tuple<string, int>[] degrees = hyperGraph.GetVertexDegrees(); Tuple <string, int>[] degrees = hyperGraph.GetVertexEulerDegrees(); Dictionary <HyperEdge, float> probabilities = new Dictionary <HyperEdge, float>(); int blueBlueBlueValues, greenGreenRedValues, greenBlueRedValues; blueBlueBlueValues = greenGreenRedValues = greenBlueRedValues = 0; foreach (HyperEdge edge in hyperGraph.Edges) { int tileSideWs = 0; foreach (Vertex vertex in edge.Vertices) { string reverse = vertex.Value.ReverseString(); int sideWS = degrees.Where(t => t.Item1.Equals(reverse)).Single().Item2; if (edge.Vertices.Select(v => v.Value).Contains(reverse)) { sideWS--; } tileSideWs += sideWS; } string[] vertexCounterParts = edge.Vertices.Select(v => v.Value.ReverseString()).ToArray(); List <HyperEdge> duplicate = hyperGraph.Edges.Where(e => !e.Equals(edge) && e.Vertices.Select(v => v.Value).Intersect(vertexCounterParts).Count() == 2).ToList(); // The number for tileSideWs has to be corrected about the number of those tiles, // which hold more than one 'counterparts' (max counterparts on one tile is 2) // of the actual tile sides. tileSideWs = tileSideWs - duplicate.Count; //float ws = (float)tileSideWs/168.0f; float ws = (float)tileSideWs / 56.0f; probabilities.Add(edge, ws); switch (edge.Vertices.Select(v => v.Value.GetVertexColor()).Distinct().Count()) { case 1: blueBlueBlueValues += edge.Vertices.Select(v => Int32.Parse(v.Value[0].ToString())).Sum(); break; case 2: greenGreenRedValues += edge.Vertices.Select(v => Int32.Parse(v.Value[0].ToString())).Sum(); break; case 3: greenBlueRedValues += edge.Vertices.Select(v => Int32.Parse(v.Value[0].ToString())).Sum(); break; default: throw new InvalidOperationException($"Cannot determine SideType for Tile: {edge.Vertices.Select(v => v.Value[0].ToString()).Aggregate((a, b) => a + " - " + b)}"); } //45 / 6 => 7.5 //150 / 20 => 7.5 //225 / 30 => 7.5 } string outputPath = @"C:\Users\Moritz\Dropbox\Studium\Fulda\5_SS19\Project\Triominos\Graphsuite\GraphSuite\Files"; string outputFile = "tileProbabilitiesAndValues.txt"; if (File.Exists(Path.Combine(outputPath, outputFile))) { File.Delete(Path.Combine(outputPath, outputFile)); } File.WriteAllLines( Path.Combine(outputPath, outputFile), probabilities.OrderBy(kv => kv.Key.GreenSideCount()).Select( kv => kv.Key.Vertices.Select(v => v.Value[0].ToString()).Aggregate((a, b) => a + "-" + b) + " | " + kv.Key.Vertices.Select(v => Int32.Parse(v.Value[0].ToString())).Sum() + " | " + kv.Key.Vertices.Select(v => v.Value.GetVertexColor().ToString()).Aggregate((a, b) => a + "-" + b) + " | " + kv.Value)); }