I'm trying to figure how I should use the Ford Fulkerson algorithm in this situation The situation is kinda sudoku-like. We have a matrix a
which contains integer values. The last column of each row and last row of each column, contains the sum of the entire row / column.
Example:
int[][] a = {{1, 3, 5, 9},
{4, 2, 1, 7},
{5, 5, 6, *}} // * Is not determined since the sums
// * do not count as summable values.
This thing is, that the values within the matrix are not always correct. The values for the sum are not always correct, for example:
int[][] a = {{1, 3, 3, 9},
{2, 3, 1, 7},
{5, 5, 6, *}} // * Is not determined since the sums do
// * not count as summable values.
There is a matrix b
which contains the max difference a cell can have to meet the given sum. For example
int[][] b = {{1, 0, 3},
{2, 1, 2}}
For example for the value of a[0][0]
, which is 1, the max differences is the value at b[0][0]
, which is 1, so the value at a[0][0]
can be changed to 0 or 2 maximum (and all the numbers in between, but for this example we only have 2 options).
My question is: Given a matrix a
(with invalid values for a given sum) and a matrix b
with the max differences which can be used to meet the required sum, how can I determine wether it's even possible with the given maximum differences and how do I get a valid result of such a matrix (if thus exists).
My current approach (which not works):
- Make a bipartite graph of the rows and columns, so you have a source, a sink and a node for each row and column.
- Then connect each row to each column.
- Then connect the source to each row.
- Then connect each column to the sink.
- Set capacities for the edges from the source to each row-node to the Math.Abs(current sum of numbers in
a
- given sum of numbers ina
(for that row)). - Same for the edges from each column-node to the sink (but for the column sums this time).
- Set the capacities between nodes for the rows to the columns to the given max differences in
b
for each cell accordingly. - Use Ford Fulkerson to determine the max flow.
I don't know how I should use my results of the algorithm to determine the correct values for matrix a
to meet the given sum for each row and column.