I have an n x m
matrix consisting of non-negative integers. For example:
2 3 4 7 1
1 5 2 6 2
4 3 4 2 1
2 1 2 4 1
3 1 3 4 1
2 1 4 3 2
6 9 1 6 4
It seems that a linear programming approach can be very helpful here.
Let Pm x n be the matrix with the values of the positions:
Now let define a bomb matrix B(x, y)m x n,with 1 ≤ x ≤ m, 1 ≤ y ≤ n as below
in such a way that
For example:
So we are looking to a matrix Bm x n = [bij] that
Can be defined as a sum of bomb matrices:
(qij would be then the quantity of bombs we would drop in position pij)
pij - bij ≤ 0 (to be more succint, let us say it as P - B ≤ 0)
Also, B should minimize the sum .
We can also write B as the ugly matrix ahead:
and since P - B ≤ 0 (which means P ≤ B) we have the following pretty linear inequality system below:
Being qmn x 1 defined as
pmn x 1 defined as
We can say we have a system The system below represented as product of matrices http://latex.codecogs.com/gif.download?S%5Cmathbf%7Bq%7D&space;%5Cge&space;%5Cmathbf%7Bp%7D being Smn x mn the matrix to be reversed to solve the system. I did not expand it myself but I believe it should be easy to do it in code.
Now, we have a minimum problem which can be stated as
I believe it is something easy, almost trivial to be solved with something like the simplex algorithm (there is this rather cool doc about it). However, I do know almost no linear programming (I will take a course about it on Coursera but it is just in the future...), I had some headaches trying to understand it and I have a huge freelance job to finish so I just give up here. It can be that I did something wrong at some point, or that it can't go any further, but I believe this path can eventually lead to the solution. Anyway, I am anxious for your feedback.
(Special thanks for this amazing site to create pictures from LaTeX expressions)