如何用 clp-java 解决一个简单的线性问题

How to solve a simple linear problem with clp-java

我想用clp-java

解决这个问题
Maximize 2 * x + 5 where x <= 10

我用这个代码

CLP clp = new CLP();
CLPVariable x = clp.addVariable().free();
clp.createExpression().add(2, x).add(5).asObjective();
clp.createExpression().add(x).leq(10);
clp.maximize();

System.out.println("obj=" + clp.getObjectiveValue());
System.out.println("x=" + x.getSolution());

产生此输出

obj=15.0
x=10.0

我的问题是为什么 objective 值是 15 而不是应该的 25?

该错误已在最新版本 v1.16.11 中修复。
要使用 Maven 包含此版本,您需要将以下依赖项添加到您的 pom 文件

<dependency>
    <groupId>com.github.quantego</groupId>
    <artifactId>clp-java</artifactId>
    <version>1.16.11</version>
</dependency>

他们更改了版本之间的 groupID。

根据 MVNRepository the artifact should be included in the Mulesoft 存储库,但我在那里找不到它。 如果您在其他地方找不到它,您可能就不走运了。