Class: SCS::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/scs/solver.rb

Instance Method Summary collapse

Constructor Details

#initialize(indirect: false) ⇒ Solver

Returns a new instance of Solver.



3
4
5
# File 'lib/scs/solver.rb', line 3

def initialize(indirect: false)
  @ffi = indirect ? FFI::Indirect : FFI::Direct
end

Instance Method Details

#solve(data, cone, **settings) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/scs/solver.rb', line 7

def solve(data, cone, **settings)
  cdata = create_data(data)
  settings = create_settings(settings)
  ccone = create_cone(cone)

  solution = calloc(ffi::Solution.size) # alloc clear memory
  info = ffi::Info.malloc

  ffi.scs(cdata, ccone, settings, solution, info)

  solution = ffi::Solution.new(solution)
  x = read_float_array(solution.x, cdata.n)
  y = read_float_array(solution.y, cdata.m)
  s = read_float_array(solution.s, cdata.m)

  {
    x: x,
    y: y,
    s: s,
    iter: info.iter,
    status: read_string(info.status),
    status_val: info.status_val,
    scale_updates: info.scale_updates,
    pobj: info.pobj,
    dobj: info.dobj,
    res_pri: info.res_pri,
    res_dual: info.res_dual,
    gap: info.gap,
    res_infeas: info.res_infeas,
    res_unbdd_a: info.res_unbdd_a,
    res_unbdd_p: info.res_unbdd_p,
    setup_time: info.setup_time,
    solve_time: info.solve_time,
    scale: info.scale,
    comp_slack: info.comp_slack,
    rejected_accel_steps: info.rejected_accel_steps,
    accepted_accel_steps: info.accepted_accel_steps,
    lin_sys_time: info.lin_sys_time,
    cone_time: info.cone_time,
    accel_time: info.accel_time
  }
end