1

Can someone help me how to use lpsolve55j.jar on Android device. I tried importing it like every other library (putting it in libs folder and adding it in JavaBuildPath -> Libraries) but I got this error:

03-07 15:28:52.910: W/dalvikvm(3421): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Llpsolve/LpSolve;
03-07 15:28:52.910: D/AndroidRuntime(3421): Shutting down VM
03-07 15:28:52.910: W/dalvikvm(3421): threadid=1: thread exiting with uncaught exception (group=0x9e495930)
03-07 15:28:52.910: E/AndroidRuntime(3421): FATAL EXCEPTION: main
03-07 15:28:52.910: E/AndroidRuntime(3421): java.lang.UnsatisfiedLinkError: Couldn't load lpsolve55j from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.app.cutstockan-2.apk,libraryPath=/data/app-lib/com.app.cutstockan-2]: findLibrary returned null
03-07 15:28:52.910: E/AndroidRuntime(3421):     at java.lang.Runtime.loadLibrary(Runtime.java:365)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at java.lang.System.loadLibrary(System.java:535)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at lpsolve.LpSolve.<clinit>(LpSolve.java:275)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at com.app.cutstockan.Calculate.generateEquations(Calculate.java:123)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at com.app.cutstockan.Calculate.<init>(Calculate.java:52)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at com.app.cutstockan.Main$1.onClick(Main.java:37)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at android.view.View.performClick(View.java:4204)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at android.view.View$PerformClick.run(View.java:17355)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at android.os.Handler.handleCallback(Handler.java:725)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at android.os.Looper.loop(Looper.java:137)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at android.app.ActivityThread.main(ActivityThread.java:5202)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at java.lang.reflect.Method.invokeNative(Native Method)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at java.lang.reflect.Method.invoke(Method.java:511)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
03-07 15:28:52.910: E/AndroidRuntime(3421):     at dalvik.system.NativeStart.main(Native Method)
03-07 15:28:54.650: I/Process(3421): Sending signal. PID: 3421 SIG: 9

EDIT

OK, so what I need this for is for solving a system of inequalities. Can someone help me to find alternative for this library that can solve this?

nikmin
  • 1,803
  • 3
  • 28
  • 46
  • this jar contains native library ... so it will not work on Android if you do not compile native library for Android ... – Selvin Mar 07 '13 at 14:37
  • @Selvin I found the source for the library, any suggestions how can I compile the library for Android? – nikmin Mar 07 '13 at 14:49
  • A little offtopic maybe, but you might one to re-think solving LP on Android devices (use a server instead?). – adrianp Mar 07 '13 at 15:10
  • Granted, I have not tried it myself, but maybe you should be able to build and use the Simplex solver from [Apache Commons Math](http://commons.apache.org/proper/commons-math/userguide/optimization.html) in your Android application? – Anders Gustafsson Mar 07 '13 at 20:10
  • @adrianp I can't use server because I need to make everything to work without internet connection (locally). It's not so heavy mathematics, if that is what you thought – nikmin Mar 08 '13 at 07:21
  • @AndersGustafsson As I could see, this library solves only `A*X=B`. I need to solve system of inequalities – nikmin Mar 08 '13 at 07:40
  • 1
    @nikmin But you *do have* an objective function? You can formulate the [LinearConstraint](http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/optimization/linear/LinearConstraint.html)s of the LP problem as inequalities by specifying the lhs-rhs `Relationship`. Hmmm, I notice now that the [SimplexSolver](http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/optimization/linear/SimplexSolver.html) is deprecated in Commons Math 3.1, but I do not know the reason why? – Anders Gustafsson Mar 08 '13 at 08:37
  • @AndersGustafsson I doesn't matter if it's deprecated. Can you please write an usage example as answer? This is used for minimization, right? Thanks – nikmin Mar 08 '13 at 08:47
  • @AndersGustafsson I figured out how to make the constraints and objective function but how to use `solver.optimize(OptimizationData)` – nikmin Mar 08 '13 at 09:49
  • @nikmin Please see my answer for further guidance. I hope the referenced examples should give you sufficient help. – Anders Gustafsson Mar 08 '13 at 09:52

1 Answers1

2

Apache Commons Math is a pure Java library that contains for example the Simplex algorithm for solving linear programs. Binaries of this library should probably be possible to use as-is in an Android application, alternatively it should be straightforward to build the library specifically for Android.

The associated unit test cases sufficiently illustrates the usage of the Apache Commons Math SimplexSolver for solving different kinds of smaller LP problems.

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • I solved it. But there is one problem. Is there a way the call to `solver.optimize` to return results with integers, not doubles? I want to get the best integers result – nikmin Mar 08 '13 at 12:02
  • The LP optimizer in *Apache Commons Math* is only capable of handling floating-point variables, integer variables (Mixed Integer Linear Programming) are not supported. I looked around, and right out-of-the-box I cannot find any usable pure Java MILP libraries, unfortunately. There is an ambitious project porting GLPK (which supports integer variables) to *Javascript*, [glpk.js](https://github.com/hgourvest/glpk.js), could this be of use? – Anders Gustafsson Mar 08 '13 at 12:37
  • I think this is of no use :( If you find something else I will be very grateful. Thanks for helping – nikmin Mar 08 '13 at 13:27