注意, 必要条件:
- ;J:\IBM\ILOG\CPLEX_Studio1271\cplex\bin\x64_win64;J:\IBM\ILOG\CPLEX_Studio1271\cplex\lib\cplex.jar 添加到环境变量path中;
- 将cplex.jar放到工程中并添加进路径;
- 将;J:\IBM\ILOG\CPLEX_Studio1271\cplex\bin\x64_win64添加到native library中。
下面是个小例子:
package javaTest.java;
import ilog.concert.*;
import ilog.cplex.*;
public class TestCplex {
/**
* obj = x1 + 5x2 + 1X3
* -x1 + x2 + x3 <=56;
* x1 - 3x2 + x3 <= 39;
* 0 <= x1 <= 40;
* 0 <= x2, x3
* @param args
*/
public static void main(String[] args) {
double[] lb = { 0.0, 0.0, 0.0};
double[] ub = { 40.0, Double.MAX_VALUE, Double.MAX_VALUE};
try {
IloCplex cplex = new IloCplex();
IloNumVar[] x = cplex.numVarArray(3, lb, ub);
double[] objvals = { 1.0, 5.0, 1.0 };
cplex.addMaximize(cplex.scalP