# commons-user mailing list archives

##### Site index · List index
Message view
Top
From Alexander SehlstrĂ¶m <alexan...@sehlstrom.se>
Subject Re: [math] Solving SLP problem
Date Thu, 07 Mar 2013 18:12:07 GMT
Thanks again Thomas!

/Alexander

PS. For those interested, the resulting code looks like:

// Objective function
LinearObjectiveFunction g = new LinearObjectiveFunction(gArray, 0);  // gArray computed elsewhere

// Boundaries: s_l <= s <= s_u
// - Treat the boundaries as linear constraints.
Collection<LinearConstraint> constraints = new ArrayList();
DoubleMatrix eye = DoubleMatrix.eye(x.length);		// I use the JBlas matrix library

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
PointValuePair result = new SimplexSolver().optimize(g, new LinearConstraintSet(constraints),
GoalType.MINIMIZE, new MaxIter(100));

double[] s = result.getPoint();

7 mar 2013 kl. 19:05 skrev Thomas Neidhart <thomas.neidhart@gmail.com>:

> On 03/07/2013 06:31 PM, Alexander SehlstrĂ¶m wrote:
>> Thomas,
>>
>> Thanks for the suggested solution. Seams to do the job as it no longer throws errors.
>>
>> How do I retrieve my resulting double[] s from the PointValuePair r = new SimplexSolver().optimize(...)?
>
> r.getPoint() returns the found solution for s in your case (if I
> understand your setup correctly).
>
> If you have more problems please also attach your example.
>
> Thomas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

Mime
• Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message