线性约束规划问题java求解

Linear programming.

brewer's linear program

Linear programming solvers.

  • Simplex.java is a bare-bones versionof the simplex algorithm.
  • QSoptis a Java linear program solver created by David Applegate, William Cook,Sanjeeb Dash, and Monika Mevenkamp.It can be used at no cost for research or education purposes.QSoptSolver.java solves a linear programin LP format, such as beer.lp.
  • Matlabcontains a linear programming solver in the optimization toolbox.
    [wayne:tombstone] ~> matlab
                                          < M A T L A B (R) >
                                Copyright 1984-2009 The MathWorks, Inc.
                              Version 7.9.0.529 (R2009b) 64-bit (glnxa64)
                                            August 12, 2009
    >> A = [5 15; 4 4; 35 20];
    >> b = [480; 160; 1190];
    >> c = [13; 23];
    
    >> lb = [0; 0];
    >> ub = [inf; inf];
    >> x = linprog(-c, A, b, [], [], lb, ub)
    x =
        12.0000
        28.0000
    
  • CPLEXis a high-performance mathematical programming solverfor linear programming, mixed integer programming, and quadratic programming.It supports interfaces to C, C++, Java, Python, Matlab, and Microsoft Excel.It is also accessible via the modeling systems includingAIMMS, AMPL, GAMS, and MPL.
  • AMPL is a modeling language for mathematical programming.The files beer.mod and beer.datspecify the model and data for the brewery problem.
    [wayne:tombstone] ~> ampl
    ILOG AMPL 9.100
    AMPL Version 20021038 (SunOS 5.8)
    
    ampl: model beer.mod;
    
    ampl: data beer.dat;
    
    ampl: solve;
    ILOG CPLEX 9.100 
    CPLEX 9.1.0: optimal solution; objective 800
    2 dual simplex iterations (1 in phase I)
    
    ampl: display x;
    x [*] :=
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
以下是使用Lingo求解线性规划问题的示例代码: ```java import lingo.*; import java.util.*; public class LingoTest { public static void main(String[] args) { try { // 创建Lingo对象 Lingo lingo = new Lingo(); // 创建模型 lingo.CreateModel(); // 定义决策变量 LingoVariable x1 = lingo.AddVariable("x1", 0, LingoInfinity, LingoInteger); LingoVariable x2 = lingo.AddVariable("x2", 0, LingoInfinity, LingoInteger); // 定义目标函数 LingoObjective obj = lingo.SetObjective("maximize", 5 * x1 + 4 * x2); // 添加约束条件 lingo.AddConstraint(2 * x1 + x2 <= 100); lingo.AddConstraint(x1 + 2 * x2 <= 50); // 求解线性规划问题 lingo.Solve(); // 获取解 Map<String, Object> solution = new HashMap<>(); solution.put("x1", x1.GetLevel()); solution.put("x2", x2.GetLevel()); solution.put("Objective", obj.GetValue()); // 输出解 System.out.println("Solution: " + solution); } catch (LingoException e) { System.err.println(e.getMessage()); } } // 定义正无穷 private static final double LingoInfinity = 1e30; } ``` 在上面的代码中,我们使用了Lingo Java API来求解线性规划问题。首先,我们创建了一个Lingo对象,并创建了一个模型。接着,我们定义了两个决策变量x1和x2,以及一个目标函数obj。然后,我们添加了两个约束条件,并设置了目标函数的优化方向为最大化。最后,我们调用了Solve方法求解线性规划问题,并获取了解的值。在这个例子中,我们使用了整数线性规划,因此将决策变量的类型设置为整数。如果需要使用浮点数线性规划,可以将决策变量的类型设置为LingoContinuous。 需要注意的是,Lingo Java API需要在Lingo的安装目录下添加lingo.jar文件,并将该文件添加到Java的classpath中。同时,还需要添加Lingo的动态链接库文件到操作系统的库路径中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值