简体   繁体   English

具有下限和上限的Apache Commons Math SimplexSolver?

[英]Apache Commons Math SimplexSolver with lower and upper bounds?

I intend to solve the following linear programming problem using the Simplex method provided in the Apache Commons Math library. 我打算使用Apache Commons Math库中提供的Simplex方法解决以下线性编程问题。 I do not get it to work and I find the API documentation limited. 我没有使其正常工作,并且我发现API文档受到限制。

Problem 问题

Starting from the vector s0 , determine s , the solution of: 从向量s0 ,确定s ,则以下项的解:

| min   f' * s
|  s
|
| s.t.  s_l <= s <= s_u

where f is a vector, s_l and s_u are the lower and upper bounds of s , respectively. 其中f是向量, s_ls_u分别是s的下限和上限。

I can solve this problem easily in Matlab using the command linprog(f, [], [], [], [], s_l, s_u, s0, options) and wish to do the same in Java, preferably using Apache Commons Math. 我可以使用linprog(f, [], [], [], [], s_l, s_u, s0, options)命令在Matlab中轻松解决此问题linprog(f, [], [], [], [], s_l, s_u, s0, options)并希望在Java中做到这一点,最好使用Apache Commons Math。

SimplexSolver 单面求解器

I have tried to use the Apache Commons Math SimplexSolver similar the explanation here: http://google-opensource.blogspot.se/2009/06/introducing-apache-commons-math.html 我尝试使用类似此处的Apache Commons Math SimplexSolver解释: http : //google-opensource.blogspot.se/2009/06/introducing-apache-commons-math.html

But I can't seam to define my bounds s_l and s_u and I have to provide LinearConstraint (which I do not have any) using this method. 但是我无法通过接缝来定义边界s_ls_u ,因此必须使用此方法提供LinearConstraint (我没有)。

Are you supposed to be able to to that? 你应该能够做到吗?

I am not sure whether there is a shortcut, but actually a lower and upper bound are just 2 linear constraints. 我不确定是否有捷径,但实际上上下限只是2个线性约束。

Make sure that your first variable is larger than the first element of the lower bound (constraint 1) and smaller than the first element of the upper bound (constraint 2). 确保您的第一个变量大于下界的第一个元素(约束1)并且小于上界的第一个元素(约束2)。

Then make sure that your second variable .... and so on. 然后确保您的第二个变量....依此类推。

This may be laborious to write but it should not be too hard to get it right. 编写此代码可能很麻烦,但要正确地编写它并不难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM