Setup for LPSolve
1.Go to https://sourceforge.net/projects/lpsolve/files/ -> click on LpSolve
You will see different versions of LPSolve.
Download lp_solve_5.5.2.5_dev_win64.zip (according to processor type )
lp_solve_5.5.2.5_java.zip (for java)
2.Extract both the files( lp_solve_5.5.2.5_dev_win64 and lp_solve_5.5.2.5_java folder )
3.Create a maven project using eclipse.( Demo project)
4.Goto lp_solve_5.5.2.5_java folder and copy lib folder and paste it into the root of your project directory.
(lib folder contains supporting files of processor type (win64,win32 etc )and jar file of LPSolve i.e “lpsolve55j.jar”).
5.Right click on Demo Project->Build Path->Configure Build Path->Libraries->Add External jars->navigate to your project directory->lib -> select “lpsolve55j.jar”->open->apply->’apply and close.
6.Goto lp_solve_5.5.2.5_dev_win64 folder copy ”lpsolve55.dll” and paste it into C:\Windows folder.
7.Goto lib->win64->copy “lpsolve55j.dll” and paste it into C:\Windows folder.
8.Create a new class Demo
9.http://lpsolve.sourceforge.net/5.5/ use this as a reference guide.
10.copy and paste simple example and run the application.
import lpsolve.*;
public class Demo {
public static void main(String[] args) {
try {
// Create a problem with 4 variables and 0 constraints
LpSolve solver = LpSolve.makeLp(0, 4);
// add constraints
solver.strAddConstraint("3 2 2 1", LpSolve.LE, 4);
solver.strAddConstraint("0 4 3 1", LpSolve.GE, 3);
// set objective function
solver.strSetObjFn("2 3 -2 3");
// solve the problem
solver.solve();
// print solution
System.out.println("Value of objective function: " + solver.getObjective());
double[] var = solver.getPtrVariables();
for (int i = 0; i < var.length; i++) {
System.out.println("Value of var[" + i + "] = " + var[i]);
}
// delete the problem and free memory
solver.deleteLp();
}
catch (LpSolveException e) {
e.printStackTrace();
}
}
}
if you get this error:java.lang.unsatisfiedlinkerror no lpsolve55j in java.library.path
Setting the java.library path. using Eclipse
1.Select your project in the Package Explorer area and press a right click on it.
2.Select Build Path → Configure Build Path... option.
3.In the appearing window, select the Libraries tab.
4.Then, expand the JRE System library option and select the Native library location.
5.Click on the Edit... button at the right panel.
6.Locate the required library and then click OK.
7.Close the window.