/// <summary> /// Makes node by using the specified parent node and the child index (column in the cost matrix). /// </summary> /// <param name="costs">Cost matrix.</param> /// <param name="parent">Parent node.</param> /// <param name="column">Child index (column in cost matrix).</param> /// <returns>Node.</returns> static BranchingNode makeNode(double[,] costs, BranchingNode parent, int column) { var node = new BranchingNode { Row = parent.Row + 1, Column = column, Bound = parent.GetPathCost(costs), Parent = parent }; var isColumnTaken = parent.GetTakenColumns(costs.ColumnCount()); if (node.Row == costs.RowCount() || isColumnTaken[column]) { return(null); //invalid node } node.Bound += costs[node.Row, node.Column]; isColumnTaken[column] = true; for (int r = node.Row + 1; r < costs.RowCount(); r++) { var min = findMinInRowOmmitingTaken(costs, r, isColumnTaken); node.Bound += min; } return(node); }
/// <summary> /// Makes node by using the specified parent node and the child index (column in the cost matrix). /// </summary> /// <param name="costs">Cost matrix.</param> /// <param name="parent">Parent node.</param> /// <param name="column">Child index (column in cost matrix).</param> /// <returns>Node.</returns> static BranchingNode makeNode(double[,] costs, BranchingNode parent, int column) { var node = new BranchingNode { Row = parent.Row + 1, Column = column, Bound = parent.GetPathCost(costs), Parent = parent }; var isColumnTaken = parent.GetTakenColumns(costs.ColumnCount()); if (node.Row == costs.RowCount() || isColumnTaken[column]) return null; //invalid node node.Bound += costs[node.Row, node.Column]; isColumnTaken[column] = true; for (int r = node.Row + 1; r < costs.RowCount(); r++) { var min = findMinInRowOmmitingTaken(costs, r, isColumnTaken); node.Bound += min; } return node; }