private Node getPartialRoute(Node node, int rowNum, int colNum) { double[,] updated = new double[Cities.Length, Cities.Length]; for (int i = 0; i < Cities.Length; i++) { for (int k = 0; k < Cities.Length; k++) { updated[i, k] = node.getMatrix()[i, k]; } } ArrayList partialRoute = new ArrayList(); for (int i = 0; i < node.getRoute().Count; i++) { partialRoute.Add(node.getRoute()[i]); } double newbssf = node.getbssf() + node.getMatrix()[rowNum, colNum]; for (int i = 0; i < Cities.Length; i++) { updated[rowNum, i] = double.PositiveInfinity; updated[i, colNum] = double.PositiveInfinity; } updated[rowNum, colNum] = double.PositiveInfinity; updated[colNum, rowNum] = double.PositiveInfinity; partialRoute.Add(Cities[colNum]); Node newNode = new Node(newbssf, updated, partialRoute); newNode.setNum(colNum); return(reduceMatrix(newNode)); }
private Node reduceMatrix(Node node) { double[,] updated = new double[Cities.Length, Cities.Length]; double updatedbssf = node.getbssf(); for (int i = 0; i < Cities.Length; i++) { for (int k = 0; k < Cities.Length; k++) { updated[i, k] = node.getMatrix()[i, k]; } } for (int i = 0; i < Cities.Length; i++) //for each row { double min = double.PositiveInfinity; for (int k = 0; k < Cities.Length; k++) //get minimum for each row { if (updated[i, k] < min) { min = updated[i, k]; } } if (min != 0 && min != double.PositiveInfinity) { for (int k = 0; k < Cities.Length; k++) //subtract minimum from each value { updated[i, k] -= min; } updatedbssf += min; } } for (int i = 0; i < Cities.Length; i++) //for each column { double min = double.PositiveInfinity; for (int k = 0; k < Cities.Length; k++) //get minimum for each column { if (updated[k, i] < min) { min = updated[k, i]; } } if (min != 0 && min != double.PositiveInfinity) { for (int k = 0; k < Cities.Length; k++) //subtract minimum from each value { updated[k, i] -= min; } updatedbssf += min; } } Node newNode = new Node(updatedbssf, updated, node.getRoute()); newNode.setNum(node.getNum()); return(newNode); }