Ruby on rails 如何从lp_select gem(lpsolve)获取解决方案报告

Ruby on rails 如何从lp_select gem(lpsolve)获取解决方案报告,ruby-on-rails,rubygems,lpsolve,Ruby On Rails,Rubygems,Lpsolve,谢谢你抽出时间 我找不到解决方案之后如何获取变量值 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 ind

谢谢你抽出时间

我找不到解决方案之后如何获取变量值

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)
输出 对
阶段1使用
单工,对
阶段2使用
单工

原始和双重单工定价策略设置为“
Devex

Optimal solution                   3 after          1 iter.

Excellent numeric accuracy ||*|| = 0
备注:lp_解决版本5.5.0.15,适用于64位操作系统,带有64位实数 变量。 在总迭代次数1中,0(0.0%)为绑定翻转。 共有0次重构,0次由时间触发,0次由密度触发。 ... 平均每个重构1.0个主枢轴。 最大的[LUSOL v2.2.1.0]事实(B)有5个新西兰条目,最大基数为1.0x。 约束矩阵inf范数为1,动态范围为1。 加载数据的时间为0.031秒,预解算时间为0.000秒, ... 单纯形解算器中为0.000秒,总计为0.031秒。=>3.0

给出了解决方案

Optimal solution                   3 after          1 iter.

Excellent numeric accuracy ||*|| = 0
retvals = []
FFI::MemoryPointer.new(:double, 2) do |p|

    err = LPSolve::get_variables(@lp, p)

  retvals = p.get_array_of_double(0,2)
end

retvals[0]
retvals[1]