I am trying to use the Microsoft Solver Foundation to optimize a problem with a matrix of binary decision variables. Here is the format of my decision matrix:
X[i,j] =
{
{ x11, x12, ..., x1n },
{ x21, x22, ..., x2n },
...
{ xm1, xm2, ..., xmn },
};
I also have a vector of parameters, which is dependent on Xij matrix (each element of the vector is sum of one column of Xij:
Y[i] =
{
Sum(x11, x21, ..., xm1), Sum(x12, x22, ..., xm2), ..., Sum(x1n, x2n, ..., xmn)
}
I know that i should work with indexed Decision objects, but I have trouble doing that. Could anyone please help me. I understand there is two ways of indexing Decisions:
Decision Xij = new Decision(Domain.Any, "x", Some Set, Some other set);
and also there's:
`Decision[,] = new Decsion [i, j];`
What's the difference?
Yes, you can either use a C#
array to define a non-scalar Decision variable or use indexed Decision objects as explained in Nathan Brixius' blog.
There might be better ways to do it, but I would define one Sum
constraint for every element in your parameter vector Y[i]
. The parameter vector or its elements can be defined as Decision variables, or you could declare them as Term objects, which might be more efficient.
Be aware that Microsoft seems no longer be working on the Solver Foundation. So, it might make sense to look for other solvers. My personal favorite is MiniZinc, but this certainly depends on the problem type to solve. Some people prefer Google OR-Tools.