4.5. Using Java¶
This topic describes how to use the Java API of MindOpt.
Install Java Maven Dependency:
<dependency>
<groupId>com.alibaba.damo</groupId>
<artifactId>mindoptj</artifactId>
<version>[0.20.0,)</version>
</dependency>
Java call example
// load the dll, for example: c:\mindopt\0.19.0\win64_x86\lib\mindopt_0_23_1.dll
Mdo.load("c:\mindopt\0.20.0\win64_x86\lib\mindopt_0_23_1.dll");
// Method 1: A new method for creating model is introduced from version 0.19.0.
//Set up environment. Please put this in the initialization of the program, such as the setup stage in MapReduce.
MdoEnv env = new MdoEnv();
//create a model
MdoModel model = env.createModel();
model.readProb(filename)
model.solveProb();
model.displayResult();
model.free();
//JAVA SDK need to free the env object. Please put this in the end of the program, such as the cleanup stage in MapReduce.
env.free();
// Method 2: The old method for creating model is still supported. It will be removed in future version.
/*
MdoModel model = new MdoModel();
model.readProb(filename)
model.solveProb();
model.displayResult();
*/
For the complete sample code, see /example/MdoLoDiet1.java and other codes in the .java package.