-1

Thank you for your time.

I couldn't find how to get variables values after the solution.

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)

Output

Model name:  '' - run #1    
Objective:   Minimize(R0)


SUBMITTED
Model size:        4 constraints,       5 variables,            1 non-zeros.
Sets:                                   0 GUB,                  0 SOS.

Using DUAL simplex for phase 1 and PRIMAL simplex for phase 2.

The primal and dual simplex pricing strategy set to 'Devex'.

Optimal solution                   3 after          1 iter.

Excellent numeric accuracy ||*|| = 0

MEMO: lp_solve version 5.5.0.15 for 64 bit OS, with 64 bit REAL variables. In the total iteration count 1, 0 (0.0%) were bound flips. There were 0 refactorizations, 0 triggered by time and 0 by density. ... on average 1.0 major pivots per refactorization. The largest [LUSOL v2.2.1.0] fact(B) had 5 NZ entries, 1.0x largest basis. The constraint matrix inf-norm is 1, with a dynamic range of 1. Time to load data was 0.031 seconds, presolve used 0.000 seconds, ... 0.000 seconds in simplex solver, in total 0.031 seconds. => 3.0

1 Answers1

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]

gives the solution.