Daniel
Daniel

Reputation: 437

How to solve a simple linear problem with clp-java

I want to solve this problem using clp-java

Maximize 2 * x + 5 where x <= 10

I use this code

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());

that produces this output

obj=15.0
x=10.0

My question is why the objective value is 15 and not 25 as it should be?

Upvotes: 0

Views: 282

Answers (1)

Turamarth
Turamarth

Reputation: 2282

The error is fixed in the newest version v1.16.11.
To include this version using maven you need to add the following dependency to your pom file

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

They changed the groupID between the versions.

According to MVNRepository the artifact should be included in the Mulesoft repository but I can't find it there. You might be out of luck if you can't find it somewhere else.

Upvotes: 2

Related Questions