You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Alexander Sehlström <al...@sehlstrom.se> on 2013/03/07 17:13:32 UTC

[math] Solving SLP problem

Hi,

I wish to solve the following problem:

/* Problem --------------------------------------------------------
 * Starting from double[] s0, determine double[] s, the solution of:
 * 
 *     | min   f' * s
 *     |
 *     | s.t.  s_l <= s <= s_u
 * 
 * where double[] f has the same length as the double [] s.
 *
 * The double[] s_l and double[] s_u are lower and upper bounds of s,
 * respectively.
 * ----------------------------------------------------------------
 */

I have tried to understand what solution algorithm in Apache Commons Math to use. I have tried the SimplexSolver, but it seams unable to handle SimpleBounds and demands LinearConstraint which I do not have any.

Any suggestions of how to use the library for this problem?

Re: [math] Solving SLP problem

Posted by Alexander Sehlström <al...@sehlstrom.se>.
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 <th...@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
> 


Re: [math] Solving SLP problem

Posted by Thomas Neidhart <th...@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


Re: [math] Solving SLP problem

Posted by Alexander Sehlström <al...@sehlstrom.se>.
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(...)?

/Alexander

7 mar 2013 kl. 17:37 skrev Thomas Neidhart <th...@gmail.com>:

> On Thu, Mar 7, 2013 at 5:13 PM, Alexander Sehlström
> <al...@sehlstrom.se>wrote:
> 
>> Hi,
>> 
>> I wish to solve the following problem:
>> 
>> /* Problem --------------------------------------------------------
>> * Starting from double[] s0, determine double[] s, the solution of:
>> *
>> *     | min   f' * s
>> *     |
>> *     | s.t.  s_l <= s <= s_u
>> *
>> * where double[] f has the same length as the double [] s.
>> *
>> * The double[] s_l and double[] s_u are lower and upper bounds of s,
>> * respectively.
>> * ----------------------------------------------------------------
>> */
>> 
>> I have tried to understand what solution algorithm in Apache Commons Math
>> to use. I have tried the SimplexSolver, but it seams unable to handle
>> SimpleBounds and demands LinearConstraint which I do not have any.
>> 
>> Any suggestions of how to use the library for this problem?
> 
> 
> Hi Alexander,
> 
> you can also see your bounds as linear constraints:
> 
> s_l <= s <= s_u is equivalent to
> 
> linear constraint s_i >= s_l
> linear constraint s_i <= s_u
> 
> where s_i is your respective entry in the s array.
> 
> Hope this helps,
> 
> Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [math] Solving SLP problem

Posted by Thomas Neidhart <th...@gmail.com>.
On Thu, Mar 7, 2013 at 5:13 PM, Alexander Sehlström
<al...@sehlstrom.se>wrote:

> Hi,
>
> I wish to solve the following problem:
>
> /* Problem --------------------------------------------------------
>  * Starting from double[] s0, determine double[] s, the solution of:
>  *
>  *     | min   f' * s
>  *     |
>  *     | s.t.  s_l <= s <= s_u
>  *
>  * where double[] f has the same length as the double [] s.
>  *
>  * The double[] s_l and double[] s_u are lower and upper bounds of s,
>  * respectively.
>  * ----------------------------------------------------------------
>  */
>
> I have tried to understand what solution algorithm in Apache Commons Math
> to use. I have tried the SimplexSolver, but it seams unable to handle
> SimpleBounds and demands LinearConstraint which I do not have any.
>
> Any suggestions of how to use the library for this problem?


Hi Alexander,

you can also see your bounds as linear constraints:

s_l <= s <= s_u is equivalent to

linear constraint s_i >= s_l
linear constraint s_i <= s_u

where s_i is your respective entry in the s array.

Hope this helps,

Thomas