0

The org.apache.commons.math3.optim.linear package in Apache Commons Math Library allows Linear Optimization but the returned values are double. Is there any way to perform Integer Linear Programming using this library? I tried googling but there seems to be no mention of ILP anywhere.

Alternatively, is there any other Java library that can do ILP? please not that I need to run this on android so SCPSolver, GLPK, Or-tools. etc. are not possible.

Thanks in advance.

ShahiM
  • 3,179
  • 1
  • 33
  • 58
  • one more thing, this is a very pressing matter so I'll part with 100 of my hard earned Rep as bounty if you can solve this. – ShahiM Apr 29 '17 at 17:03
  • That Apache solver is LP only. [ojalgo](http://ojalgo.org/generated/org/ojalgo/optimisation/integer/IntegerSolver.html) has an integer programming solver. Also there are a lot of java based CP solvers e.g. [Choco](http://www.choco-solver.org/) – Erwin Kalvelagen Apr 29 '17 at 17:30
  • I am trying out Ojalgo right now. I let you know. – ShahiM Apr 29 '17 at 17:37
  • @ErwinKalvelagen. Ojalgo is throwing a `java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;`. Suppose it cannot run on android?? – ShahiM Apr 29 '17 at 18:59
  • I believe the source is available, so you should be able to fix that. – Erwin Kalvelagen May 01 '17 at 12:39

2 Answers2

2

As this question and 'Linear Programming in Android' in general is a rarely discussed topic, I figured I would post my findings here for anyone searching in the future.

BTW, I ended up using a port of Ojalgo, given below.

These are the LP Libs that I found can be readily imported into an android project :

Apache Commons Math

Perhaps the most well maintained library, this one supports Linear Optimization but does not have "Integer" LP.

The next two libraries do support Integer LP and/or Mixed Integer LP.

Choco Solver

Even though the Latest version of Choco (4.0) is based on Java 8, there is a Java 7 variant of version 3.3.3 . You can find it here. This imports into Android Studio without any issues.

Another issue you might run into is that even though there are guides and tutorials on their website for version 4, you wont be able to find any guides for Choco 3 except for the Javadocs. But fortunately someone had made a PDF of the older guides which you can get by Googling "Choco3 User Manual".

Also note that Choco is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. So if you want to use LP in a commercial project, consider the next option.

Oj! Algorithms

Ojalgo is another great library which has an MIT Licence and supports Java 7. But as I found out, it uses a couple of Java calls that is not available in Android.

Luckily, an MVP has ported the library to work in Android : KIC/ojAlgoAndroid

This port ran with no issues. I have forked and created a release on Jitpack : shahimclt/ojAlgoAndroid.

Community
  • 1
  • 1
ShahiM
  • 3,179
  • 1
  • 33
  • 58
  • 1
    The use of java.lang.management has been removed from recent builds of ojAlgo - it only depends on the compact1 profile. Further it seems support for Java 8 language features is coming to Android. https://developer.android.com/studio/preview/features/java8-support.html – apete May 04 '17 at 10:12
  • @apete. Thanks for the info. I will try that. – ShahiM May 04 '17 at 20:35
2

Just to fix ShahiM's answer:

  • Note that this is BSD-4, so you will have to credit the publisher if you advertise any component that uses the library. – Jay Nov 10 '17 at 23:10
  • You have to credit the publisher if you advertise the use of the software (e.g. "Choco Solver inside", or "global cardinality constraint inside"). You do not HAVE TO credit the publisher (but you can do it :-)) if you advertise your software, even if that software uses Choco Solver, as long as your add is referring to your software and not Choco Solver features BSD clause:"All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by the the organization ." – Jean-Guillaume Fages Nov 13 '17 at 18:32