lib/scs/solver.rb in scs-0.2.3 vs lib/scs/solver.rb in scs-0.3.0
- old
+ new
@@ -4,17 +4,17 @@
@ffi = indirect ? FFI::Indirect : FFI::Direct
end
def solve(data, cone, **settings)
cdata = create_data(data)
- set_settings(cdata, settings)
+ settings = create_settings(settings)
ccone = create_cone(cone)
solution = calloc(ffi::Solution.size) # alloc clear memory
info = ffi::Info.malloc
- ffi.scs(cdata, ccone, solution, info)
+ 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)
@@ -24,19 +24,28 @@
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: info.res_unbdd,
- rel_gap: info.rel_gap,
+ res_unbdd_a: info.res_unbdd_a,
+ res_unbdd_p: info.res_unbdd_p,
setup_time: info.setup_time,
- solve_time: info.solve_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
private
@@ -112,19 +121,34 @@
m, n = shape(data[:a])
cdata = ffi::Data.malloc
cdata.m = m
cdata.n = n
cdata.a = csc_matrix(data[:a])
+
+ if data[:p]
+ raise ArgumentError, "Bad p shape" if shape(data[:p]) != [n, n]
+ cdata.p = csc_matrix(data[:p])
+ end
+
+ raise ArgumentError, "Bad b size" if data[:b].to_a.size != m
cdata.b = float_array(data[:b])
+
+ raise ArgumentError, "Bad c size" if data[:c].to_a.size != n
cdata.c = float_array(data[:c])
cdata
end
def create_cone(cone)
ccone = ffi::Cone.malloc
- ccone.f = cone[:f].to_i
+ ccone.z = cone[:z].to_i
ccone.l = cone[:l].to_i
+ ccone.bu = float_array(cone[:bu])
+ ccone.bl = float_array(cone[:bl])
+ if cone[:bu].to_a.size != cone[:bl].to_a.size
+ raise ArgumentError, "Expected bu and bl size to match"
+ end
+ ccone.bsize = cone[:bu].to_a.size
ccone.q = int_array(cone[:q])
ccone.qsize = cone[:q].to_a.size
ccone.s = int_array(cone[:s])
ccone.ssize = cone[:s].to_a.size
ccone.ep = cone[:ep].to_i
@@ -132,13 +156,12 @@
ccone.p = float_array(cone[:p])
ccone.psize = cone[:p].to_a.size
ccone
end
- def set_settings(data, settings)
+ def create_settings(settings)
set = ffi::Settings.malloc
- data.stgs = set
- ffi.scs_set_default_settings(data)
+ ffi.scs_set_default_settings(set)
# hack for setting members with []=
# safer than send("#{k}=", v)
entity = set.to_ptr
settings.each do |k, v|