EldritchText
EldritchText

Reputation: 121

Code example for Scpsolver jar

Im trying to use the scpsolver and gplk jar files for a class project, but the example given gives me a null pointer error.

LinearProgram lp = new LinearProgram(new double[]{5.0,10.0}); 
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[]{3.0,1.0}, 8.0, "c1")); 
lp.addConstraint(new LinearBiggerThanEqualsConstraint(new double[]{0.0,4.0}, 4.0, "c2")); 
lp.addConstraint(new LinearSmallerThanEqualsConstraint(new double[]{2.0,0.0}, 2.0, "c3")); 
lp.setMinProblem(true); 
LinearProgramSolver solver  = SolverFactory.newDefault(); 
double[] sol = solver.solve(lp);

I have tried to google examples for scpsolver but have been unable to find any. Can anyone post a working example for scpsolver?

Upvotes: 1

Views: 1068

Answers (2)

Karthik Suresh
Karthik Suresh

Reputation: 31

If your exception is for the LinearProgramSolver (i had the same issue), its probably newDefault() is unable to automatically find the underlying GLPKSolverPack.jar. Check the following

  1. Make sure you have the GLPKSolverPack.jar is listed in the classpath. I am guessing you have already checked for this.

  2. Make sure you are using the 32 bit JDK version for your project. There is a known issue with 64bit JDK where SCP solver is unable to detect the underlying libraries as per their webpage.

SCPSolver WebSource: If you get an error under Windows "DEBUG: Could not find required library: xxxxxxxx_x64": We currently do not have access to a 64-bit Windows machine, so we are not able to provide 64-bit libraries in the solver packs. Solution: you can still use SCPSolver under Windows if you install a 32-bit x86 JDK!

This was my issue, as soon as I pointed my project to the 32 bit JDK it worked

Upvotes: 2

lunaks
lunaks

Reputation: 136

Null pointer exception means that you have a variable which its value assigned as null and program is trying to use its value. For example :

Integer myInteger = null;
int n = myInteger.intValue();

So check your code if you're trying to get a null value.

Upvotes: -1

Related Questions