【发布时间】:2018-05-17 07:51:13
【问题描述】:
感谢您的宝贵时间。
解决后我找不到如何获取变量值。
Make a three row five column equation
@lp = LPSolve::make_lp(3, 5)
Set some column names
LPSolve::set_col_name(@lp, 1, "fred")
LPSolve::set_col_name(@lp, 2, "bob")
Add a constraint and a row name, the API expects a 1 indexed array
constraint_vars = [0, 0, 1]
FFI::MemoryPointer.new(:double, constraint_vars.size) do |p|
p.write_array_of_double(constraint_vars)
LPSolve::add_constraint(@lp, p, LPSelect::EQ, 1.0.to_f)
end
LPSolve::set_row_name(@lp, 1, "onlyBob")
Set the objective function and minimize it
constraint_vars = [0, 1.0, 3.0]
FFI::MemoryPointer.new(:double, constraint_vars.size) do |p|
p.write_array_of_double(constraint_vars)
LPSolve::set_obj_fn(@lp, p)
end
LPSolve::set_minim(@lp)
Solve it and retreive the result
LPSolve::solve(@lp)
@objective = LPSolve::get_objective(@lp)
输出
Model name: '' - run #1
Objective: Minimize(R0)
SUBMITTED
Model size: 4 constraints, 5 variables, 1 non-zeros.
Sets: 0 GUB, 0 SOS.
对phase 1 使用DUAL 单工,对phase 2 使用PRIMAL 单工。
原始和双重单纯形定价策略设置为“Devex”。
Optimal solution 3 after 1 iter.
Excellent numeric accuracy ||*|| = 0
备忘录:lp_solve 版本 5.5.0.15 用于 64 位操作系统,具有 64 位 REAL 变量。 在总迭代计数 1 中,0 (0.0%) 是绑定翻转。 有 0 次重构,0 次由时间触发,0 次由密度触发。 ...每次重构平均有 1.0 个主要支点。 最大的 [LUSOL v2.2.1.0] fact(B) 有 5 个 NZ 条目,是最大基数的 1.0 倍。 约束矩阵 inf-norm 为 1,动态范围为 1。 加载数据的时间为 0.031 秒,使用预求解 0.000 秒, ... 单纯形求解器中的 0.000 秒,总共 0.031 秒。 => 3.0
【问题讨论】:
标签: ruby-on-rails rubygems lpsolve