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 <[email protected]>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? > > My problem reads: > > 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(); > constraints.add(new LinearConstraint(coef, Relationship.GEQ, > s_l.get(i))); > constraints.add(new LinearConstraint(coef, Relationship.LEQ, > 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()); > >
