public static void Print(SpanningTree parent, int level, int chromosomeNum, StreamWriter sw) { sw.WriteLine("------------------- Chromosome : {0} -------------------", chromosomeNum); Print(parent, level, sw); sw.WriteLine("---------Longest----------"); PrintLongest(parent, level, sw); counter = 0; }
public static void PrintLongest(SpanningTree parent, int level, StreamWriter sw) { ////////////////////////////////////////////////////////////////////// sw.WriteLine("{0}Level : '{1}', Row : '{2}', Col : '{3}', Length : '{4}'", new string(' ', 4 * level), level, parent.row, parent.col, parent.length); ////////////////////////////////////////////////////////////////////// if (parent.children != null) { PrintLongest(parent.children[0], level + 1, sw); } }
public static void OrderHighLow(SpanningTree parent, int level) { if (parent.children != null) { parent.children = parent.children.OrderByDescending(x => x.length).ToList(); foreach (SpanningTree child in parent.children) { OrderHighLow(child, level + 1); } } }
static void Main(string[] args) { StreamWriter sw = new StreamWriter(FILENAME); int tt = 0; foreach (int[,] chromosome in PopulationChromosomes) { new SpanningTree(auvChromosomeLocationsIndexesY[tt], auvChromosomeLocationsIndexesX[tt], chromosome); SpanningTree.OrderHighLow(SpanningTree.root, 0); SpanningTree.Print(SpanningTree.root, 0, tt, sw); tt++; } sw.Flush(); sw.Close(); Console.ReadLine(); }
public int RecursiveTree(SpanningTree parent, Cell currentCell) { int length = 0; int maxLength = 0; parent.row = currentCell.row; parent.col = currentCell.col; graph.graph[currentCell.row][currentCell.col].visited = true; EnumCell enumCell = new EnumCell(currentCell.row, currentCell.col, graph.graph); foreach (Cell cell in enumCell) { if (!cell.visited) { SpanningTree newBranch = new SpanningTree(); if (parent.children == null) { parent.children = new List <SpanningTree>(); } length = RecursiveTree(newBranch, SpanningTree.graph.graph[cell.row][cell.col]); if (length > maxLength) { if ((enumCell.numberOfRows > 7) || (enumCell.numberOfCols > 7)) { if (parent.children.Count == 0) { parent.children.Add(newBranch); } else { parent.children[0] = newBranch; } } else { parent.children.Add(newBranch); } maxLength = length; } } } graph.graph[currentCell.row][currentCell.col].visited = false; parent.length = maxLength; return(maxLength + 1); }
private static void Print(SpanningTree parent, int level, StreamWriter sw) { ////////////////////////////////////////////////////////////////////// sw.WriteLine("{0}Level : '{1}', Row : '{2}', Col : '{3}', Length : '{4}'", new string(' ', 4 * level), level, parent.row, parent.col, parent.length); ////////////////////////////////////////////////////////////////////// if (parent.children != null) { foreach (SpanningTree child in parent.children) { Print(child, level + 1, sw); if (child.length == 0) { sw.WriteLine("||,,,,,,Branch {0},,,,,,||", counter); sw.WriteLine("{0}Level : '{1}', Row : '{2}', Col : '{3}', Length : '{4}'", new string(' ', 4 * level), level, root.row, root.col, root.length); counter += 1; } } } }
public int RecursiveTree(SpanningTree parent, Cell currentCell) { int length = 0; int maxLength = 0; parent.row = currentCell.row; parent.col = currentCell.col; graph.graph[currentCell.row][currentCell.col].visited = true; if ((currentCell.col == 1) && (currentCell.row == 3)) { int z = 5; } if ((currentCell.col == 0) && (currentCell.row == 2)) { int zz = 5; } EnumCell enumCell = new EnumCell(currentCell.row, currentCell.col, graph.graph); foreach (Cell cell in enumCell) { if (!cell.visited) { SpanningTree newBranch = new SpanningTree(); if (parent.children == null) { parent.children = new List <SpanningTree>(); } parent.children.Add(newBranch); length = RecursiveTree(newBranch, SpanningTree.graph.graph[cell.row][cell.col]); if (length > maxLength) { maxLength = length; } } } graph.graph[currentCell.row][currentCell.col].visited = false; parent.length = maxLength; return(maxLength + 1); }
public SpanningTree(int startRow, int startCol, int[,] graph) { SpanningTree.graph = new Graph(graph); root = new SpanningTree(); RecursiveTree(root, SpanningTree.graph.graph[startRow][startCol]); }