commons-user mailing list archives

Site index · List index
Message view
Top
From Alexander SehlstrĂ¶m <alexan...@sehlstrom.se>
Subject Re: [Math] Limitations of the SimplexSolver class?
Date Tue, 09 Apr 2013 06:23:11 GMT
```Thomas,

After writing the pice of code you were asking for I found the error; The max iteration exception
was thrown, but swallowed by some part of my code, hence not showing up. So by increasing
from maximum 100 to 1000 iterations the SimplexSolver returns a result.

It is quite slow however and do not come near the computation time I need solving the same
problem in Matlab with linprog. Suggestions of other Apache Commons Math classes that are
solving the same type of problems as the SimplexSolver do are gratefully accepted.

Thanks,

Alexander

8 apr 2013 kl. 17:43 skrev Thomas Neidhart <thomas.neidhart@gmail.com>:

> Hi Alexander,
>
> could you create an issue (https://issues.apache.org/jira/browse/MATH) and
> attach a minimal runnable test case?
> The attached code can not be compiled and needs other libraries as jblas I
> suppose.
>
> Thanks,
>
> Thomas
>
>
>
> On Mon, Apr 8, 2013 at 5:29 PM, Alexander SehlstrĂ¶m
> <alexander@sehlstrom.se>wrote:
>
>> Hello,
>>
>> I am trying to solve a linear programming problem using the SimplexSolver
>> (org.apache.commons.math3.optim.linear.SimplexSolver).
>>
>> It dose start to compute, however it never returns any result. Is there
>> any limit on the number of variables it is possible to solve for?
>>
>>
>> Determine s_c, the solution of:
>>
>>    | min   g(x)' * s
>>    | s.t.  s_l <= s <= s_u
>>
>> where g(x) is the vector of first order derivatives of f(x) with
>> respect to xi, s is the step length to use for update of x and
>> the lower and upper bounds of s are defined as:
>>
>>    s_l = max( -delta, xmin - x )
>>    s_u = min(  delta, xmax - x )
>>
>> The number of variables are 640 since g(x) is a vector of length 640.
>>
>> My code runs fine until SimplexSolver.optimize() is called; the method
>> never returns a result and the code is stuck without any error thrown.
>>
>> Thanks
>> Alexander
>>
>> My code is appended below.
>>
>> // Gradient of objective function at x
>> LinearObjectiveFunction g = new
>> LinearObjectiveFunction(evaluation.derivatives.toArray(), 0);
>>
>> // Boundaries s_l and s_u
>> // - Treat the boundaries as linear constraints.
>> DoubleMatrix tempMatrix = new DoubleMatrix(x.length, 2);
>>
>> // s_l = max( -delta, xmin - x ),
>> tempMatrix.putColumn(0, DoubleMatrix.ones(x.length).mul(-1*delta));
>> tempMatrix.putColumn(1, xmin.sub(x));
>> s_l = tempMatrix.rowMaxs();
>>
>> // s_u = min(  delta, xmax - x ),
>> tempMatrix.putColumn(0, DoubleMatrix.ones(x.length).mul(delta));
>> tempMatrix.putColumn(1, xmax.sub(x));
>> s_u = tempMatrix.rowMins();
>>
>> Collection<LinearConstraint> constraints = new ArrayList();
>>
>> for (int i = 0; i < s_l.length; i++) {
>>    double[] coef = eye.getRow(i).toArray();
>> s_l.get(i)));
>> s_u.get(i)));
>> }
>>
>> // Solve
>> LinearConstraintSet lcs = new LinearConstraintSet(constraints);
>> NonNegativeConstraint nnc = new NonNegativeConstraint(false);
>>
>> simplexresult = new SimplexSolver().optimize(new MaxIter(100), g, lcs,
>> nnc);
>>
>> s_c = new DoubleMatrix(simplexresult.getPoint());
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org