lp_solve在windows中的配置

2017-11-28  本文已影响0人  QiangZeng
  1. Windows
    第一步: 在Windows中把这两个文件(lpsolve55.dll , lpsolve55j.dll)加到windows/system32目录下
    第二步: 把jar包(lpsolve55j.jar)加到当前的项目

官方的例子


import lpsolve.*;

public class Main {

  public static void main(String[] args) {
    try {
      // Create a problem with 4 variables and 0 constraints
      LpSolve solver = LpSolve.makeLp(0, 4);

      // add constraints
      solver.strAddConstraint("3 2 2 1", LpSolve.LE, 4);
      solver.strAddConstraint("0 4 3 1", LpSolve.GE, 3);

      // set objective function
      solver.strSetObjFn("2 3 -2 3");

      // solve the problem
      solver.solve();

      // print solution
      System.out.println("Value of objective function: " + solver.getObjective());
      double[] var = solver.getPtrVariables();
      for (int i = 0; i < var.length; i++) {
          System.out.println("Value of var[" + i + "] = " + var[i]);
      }

      // delete the problem and free memory
      solver.deleteLp();
    }
    catch (LpSolveException e) {
      e.printStackTrace();
    }
  }

}

其余linux配置见下文
https://zhuanlan.zhihu.com/p/31461518

下载地址
win64的lp_solve dll文件

上一篇下一篇

猜你喜欢

热点阅读