Consider setting up the following system for a linear programming optimization
sz = 50;
d = Table[Abs[i - j], {i, 1, sz}, {j, 1, sz}];
vd = (d // Flatten)[[2 ;;]] // N;
fs = Table[f[i, j], {i, 1, sz}, {j, 1, sz}];
vfs = (fs // Flatten)[[2 ;;]];
uv = Table[1, sz];
ClearAll[o]; ClearAll[t];
on = Table[o[i], {i, sz}];
tw = Table[t[i], {i, sz}];
eqs = {fs[[1, 1]], -on - fs.uv, -tw - uv.fs} /. Solve[-1. == fs /. List -> Plus, f[1, 1]][[1]] // Flatten;
{b, m} = CoefficientArrays[eqs, vfs];
so that, e.g., generating some random input
one = Table[RandomReal[], {i, 1, sz}];
one = one/Total[one];
two = Table[RandomReal[], {i, 1, sz}];
two = two/Total[two];
we can evaluate the optimization
AbsoluteTiming[
Do[o[i] = one[[i]]; t[i] = two[[i]];, {i, sz}];
out = LinearProgramming[vd, m, b, Method -> "InteriorPoint"];
vd.out
]
{0.0143417, 2.13037}
As we can see, for systems of size sz = 50
one optimization takes about 0.015
seconds. My question is:
Is
0.015
seconds in this case a good performance, or may there be ways to speed up the optimization?
I need to evaluate 10^12 such optimization steps, which at that rate would take 475.647
years to complete. I wonder if I should be looking into performance improvements, or rather change my approach if no significant speedup can be expected to be achieved.
Do[o[i] = one[[i]]; t[i] = two[[i]];, {i, sz}]
when you could just do this:o = one; t = two;
and it seems like you don't appear to useo
ort
in theLinearProgramming
? $\endgroup$o
andt
are not lists. The function valueso[i]
,t[i]
enter theLinearProgramming
through the predefined vectorb
and matrixm
. Their values change dynamically when the components are assigned. $\endgroup$Array
,ConstantArray
, andNormalize
to put it in a more functional and lessTable
-like / loop style. Nevertheless, I don't think you can improve on 0.015 seconds. If you use a less strictTolerance->.1
then it gets a 2x times faster at best. LP is $\mathcal{O}(n^{2})$ or $\mathcal{O}(n^{3})$ and I think Mathematica is already using a decent optimizer (COIN?) so there's not much you can do. $\endgroup$