Code Monkey home page Code Monkey logo

lpsolve-android's Introduction

lpsolve-android

Migrate the lp_solve code from C, Java to Android.

Version of lp_solve: 5.5.2.5

Background

Few days ago, I was developing some tools for Princess Connect Re:Dive and met the problem of linear programming.

However, when I try the org.apache.commons:commons-math3 library, it shows the BAD performance as the constraints and variable increase. That's the reason why I migrate the lp_solve library from C to Android.

It's believed that lp_solve libraries give the correct answer at least **10 TIMES FASTER THAN ** org.apache.commons:commons-math3. And the accuracy has increased dramatically, compared to the former.

How to Use

Before we go on, we shall check some prerequisites:

  1. Android Studio
  2. CMake

After that, download the latest lpsolve_android_release.zip in release page and unzip it. The directory structure is listed below

app
  - build.gradle
  - src
    - main
      - cpp
        - CMakeLists.txt
        - ...More
      - java
        - lpsolve
        - ...More
lpsolve_bin
  - lib
    - arm64-v8a
    - armeabi-v7a
    - x86
    - x86_64

The directories inside lpsolve_bin/lib contain the .so libraries for each platforms.

There are 2 different ways to lay out the lp_solve libraries.

Way 1: Build A New NDK Project

First, build a NDK project in AS.

The file structure in directory app correspond to the real structure in ndk project of Android Studio. Then:

  1. Put the files in directory app/src in the corresponding location of the ndk project. Make sure the lpsolve package is the subdirectory of app/src/main/java and the cpp dir is the subdirectory of app/src/main, or it may cause errors.
  2. Modify the build.gradle in app as below:
android{
	...
	defaultConfig{
		...
		# Here define the parameters which control the cmake
        	externalNativeBuild {
            		cmake {
                		cFlags ""
                		cppFlags ""
            		}
        	}
	}
	...
	# Here is the relative path of the CMakeList.txt
    	externalNativeBuild {
        	cmake  {
			path "src/main/cpp/CMakeLists.txt"
       		}
    	}
}

Way 2: Add the lp_solve libraries to an existing project

  1. Start an existing android project with AS.

  2. Put the files in directory app/src in the corresponding location of the NDK project. Make sure the lpsolve package is the subdirectory of app/src/main/java and the cpp directory is the subdirectory of app/src/main, or it may cause errors.

  3. Open the Project pane from the left side of the IDE and select the Android view.

  4. Right-click on the module you would like to link to your native library, such as the app module, and select Link C++ Project with Gradle from the menu.

  5. From the drop-down menu, select CMake. Then, use the field next to Project Path to specify the src/main/cpp/CMakeLists.txt script file for your external CMake project.

  6. Click OK.

Above steps could be referred to Link Gradle to your native library on the website of Android Developers.

When everything is done, you could import the lpsolve package the same as what we do with Java.

And every time the .apk file is compiled and built, the lpsolve would be packed in it.

API Reference

lp_solve reference guide

License

The MIT License

Credits

The project relies on:

lpsolve-android's People

Contributors

leonardodalinky avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.