Skip to content

Commit 31de5c3

Browse files
committed
Merge pull request #3 from karanveerm/master
Use ECOS 1.0.3 + Add setup function that takes keyword arguments
2 parents 519d602 + 64dcfc7 commit 31de5c3

File tree

2 files changed

+99
-13
lines changed

2 files changed

+99
-13
lines changed

deps/build.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ using BinDeps
66
ecos = library_dependency("ecos",aliases=["libecos"])
77
end
88

9-
provides(Sources, URI("https://github.com/ifa-ethz/ecos/archive/master.zip"),
10-
[ecos], os = :Unix, unpacked_dir="ecos-master")
9+
# The last stable version of ECOS seems to be v1.0.3 as of 05/29/2014
10+
# This is safer than unpacking from master which may cause ECOS.jl to
11+
# not work properly
12+
provides(Sources, URI("https://github.com/ifa-ethz/ecos/archive/v1.0.3.zip"),
13+
[ecos], os = :Unix, unpacked_dir="ecos-1.0.3")
1114

1215
prefix = joinpath(BinDeps.depsdir(ecos),"usr")
13-
srcdir = joinpath(BinDeps.depsdir(ecos),"src","ecos-master/")
16+
srcdir = joinpath(BinDeps.depsdir(ecos),"src","ecos-1.0.3/")
1417

1518
provides(SimpleBuild,
1619
(@build_steps begin

src/ECOS.jl

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ immutable Cstats
104104
nitref3::Clong
105105
tsetup::Cdouble
106106
tsolve::Cdouble
107-
tfactor::Cdouble
108-
tkktsolve::Cdouble
107+
tfactor::Cdouble
108+
tkktsolve::Cdouble
109109
torder::Cdouble
110110
tkktcreate::Cdouble
111111
ttranspose::Cdouble
@@ -121,6 +121,9 @@ immutable Csettings
121121
feastol::Cdouble
122122
abstol::Cdouble
123123
reltol::Cdouble
124+
feastol_inacc::Cdouble
125+
abstol_inacc::Cdouble
126+
reltol_inacc::Cdouble
124127
nitref::Clong
125128
maxit::Clong
126129
verbose::Clong
@@ -132,6 +135,7 @@ immutable Cpwork
132135
m::Clong
133136
p::Clong
134137
D::Clong
138+
135139
# Variables
136140
x::Ptr{Cdouble}
137141
y::Ptr{Cdouble}
@@ -140,23 +144,45 @@ immutable Cpwork
140144
lambda::Ptr{Cdouble}
141145
kap::Cdouble
142146
tau::Cdouble
147+
148+
# Best iterates seen so far
149+
best_x::Ptr{Cdouble}
150+
best_y::Ptr{Cdouble}
151+
best_z::Ptr{Cdouble}
152+
best_s::Ptr{Cdouble}
153+
best_kap::Cdouble
154+
best_tau::Cdouble
155+
best_cx::Cdouble
156+
best_by::Cdouble
157+
best_hz::Cdouble
158+
best_info::Ptr{Cstats}
159+
143160
# Temporary variables
144161
dsaff::Ptr{Cdouble}
145162
dzaff::Ptr{Cdouble}
146163
W_times_dzaff::Ptr{Cdouble}
164+
dsaff_by_W::Ptr{Cdouble}
147165
saff::Ptr{Cdouble}
148166
zaff::Ptr{Cdouble}
167+
149168
# Cone
150169
C::Ptr{Ccone}
151170
A::Ptr{Cspmat}
152171
G::Ptr{Cspmat}
153172
c::Ptr{Cdouble}
154173
b::Ptr{Cdouble}
155174
h::Ptr{Cdouble}
175+
176+
# equilibration vector
177+
xequil::Ptr{Cdouble}
178+
Aequil::Ptr{Cdouble}
179+
Gequil::Ptr{Cdouble}
180+
156181
# scalings of problem data
157182
resx0::Cdouble
158183
resy0::Cdouble
159184
resz0::Cdouble
185+
160186
# residuals
161187
rx::Ptr{Cdouble}
162188
ry::Ptr{Cdouble}
@@ -165,21 +191,25 @@ immutable Cpwork
165191
hresx::Cdouble
166192
hresy::Cdouble
167193
hresz::Cdouble
168-
# temporary storage
194+
195+
# temporary storage
169196
cx::Cdouble
170197
by::Cdouble
171198
hz::Cdouble
172199
sz::Cdouble
200+
173201
# KKT System
174202
KKT::Ptr{Ckkt}
203+
175204
# info struct
176205
info::Ptr{Cstats}
206+
177207
# settings struct
178208
stgs::Ptr{Csettings}
179209
end
180210

181211

182-
# ECOS types:
212+
# ECOS types:
183213
# pfloat -> Cdouble
184214
# idxint -> SuiteSparse_long -> Clong
185215

@@ -190,18 +220,71 @@ end
190220
# l is the dimension of the positive orthant, i.e. in Gx+s=h, s in K, the first l elements of s are >=0
191221
# ncones is the number of second-order cones present in K
192222
# q is an array of integers of length ncones, where each element defines the dimension of the cone
193-
# Gpr, Gjc, Gir are the the data, the column index, and the row index arrays, respectively, for the matrix G represented in column compressed storage (CCS) format (Google it if you need more information on this format, it is one of the standard sparse matrix representations)
223+
# Gpr, Gjc, Gir are the the data, the column index, and the row index arrays, respectively,
224+
# for the matrix G represented in column compressed storage (CCS) format (Google it if you need more
225+
# information on this format, it is one of the standard sparse matrix representations)
194226
# Apr, Ajc, Air is the CCS representation of the matrix A (can be all NULL if no equalities are present)
195227
# c is an array of type pfloat of size n
196228
# h is an array of type pfloat of size m
229+
# b is an array of type pfloat of size p (can be NULL if no equalities are present)
230+
# The setup function returns a struct of type pwork, which you need to define first
231+
# This is the straightforward translation from the C API.
232+
function setup(n::Int64, m::Int64, p::Int64, l::Int64, ncones::Int64, q::Array{Int64},
233+
Gpr::Array{Float64}, Gjc::Array{Int64}, Gir::Array{Int64}, Apr::Array{Float64},
234+
Ajc::Array{Int64}, Air::Array{Int64}, c::Array{Float64}, h::Array{Float64},
235+
b::Array{Float64})
236+
problem = ccall((:ECOS_setup, ECOS.ecos), Ptr{Cpwork}, (Clong, Clong, Clong, Clong, Clong, Ptr{Clong}, Ptr{Cdouble}, Ptr{Clong}, Ptr{Clong}, Ptr{Cdouble}, Ptr{Clong}, Ptr{Clong}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), n, m, p, l, ncones, q, Gpr, Gjc, Gir, Apr, Ajc, Air, c, h, b)
237+
end
197238

198-
# b is an array of type pfloat of size p (can be NULL if no equalities are present) The setup function returns a struct of type pwork, which you need to define first
239+
VecOrMatOrSparseOrNothing = Union(Vector, Matrix, SparseMatrixCSC, Nothing)
240+
ArrayFloat64OrNothing = Union(Array{Float64, }, Nothing)
199241

242+
function setup(;n::Int64=nothing, m::Int64=nothing, p::Int64=0, l::Int64=0,
243+
ncones::Int64=0, q::Array{Int64, }=[], G::VecOrMatOrSparseOrNothing=nothing,
244+
A::VecOrMatOrSparseOrNothing=nothing, c::Array{Float64, }=nothing,
245+
h::ArrayFloat64OrNothing=nothing, b::ArrayFloat64OrNothing=nothing)
246+
if q == []
247+
q = convert(Ptr{Int64}, C_NULL)
248+
end
200249

201-
# This is the straightforward translation from the C API.
202-
# TODO: allow the matrix to be a Julia SparseMatrixCSC instead
203-
function setup(n::Int64, m::Int64, p::Int64, l::Int64, ncones::Int64, q::Array{Int64}, Gpr::Array{Float64}, Gjc::Array{Int64}, Gir::Array{Int64}, Apr::Array{Float64}, Ajc::Array{Int64}, Air::Array{Int64}, c::Array{Float64}, h::Array{Float64}, b::Array{Float64})
204-
problem = ccall((:ECOS_setup, ECOS.ecos), Ptr{Cpwork}, (Clong, Clong, Clong, Clong, Clong, Ptr{Clong}, Ptr{Cdouble}, Ptr{Clong}, Ptr{Clong}, Ptr{Cdouble}, Ptr{Clong}, Ptr{Clong}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), n, m, p, l, ncones, q, Gpr, Gjc, Gir, Apr, Ajc, Air, c, h, b)
250+
if A == nothing
251+
Apr = convert(Ptr{Float64}, C_NULL)
252+
Ajc = convert(Ptr{Int64}, C_NULL)
253+
Air = convert(Ptr{Int64}, C_NULL)
254+
else
255+
sparseA = sparse(A)
256+
# Hack to make it a float, find a better way
257+
Apr = sparseA.nzval * 1.0
258+
# -1 since the C language is 0 indexed
259+
Ajc = sparseA.colptr - 1
260+
Air = sparseA.rowval - 1
261+
end
262+
263+
if G == nothing
264+
Gpr = convert(Ptr{Float64}, C_NULL)
265+
Gjc = convert(Ptr{Int64}, C_NULL)
266+
Gir = convert(Ptr{Int64}, C_NULL)
267+
else
268+
sparseG = sparse(G)
269+
# Hack to make it a float, find a better way
270+
Gpr = sparseG.nzval * 1.0
271+
# -1 since the C language is 0 indexed
272+
Gjc = sparseG.colptr - 1
273+
Gir = sparseG.rowval - 1
274+
end
275+
276+
if b == nothing
277+
b = convert(Ptr{Float64}, C_NULL)
278+
end
279+
280+
if h == nothing
281+
h = convert(Ptr{Float64}, C_NULL)
282+
end
283+
284+
ccall((:ECOS_setup, ECOS.ecos), Ptr{Cpwork}, (Clong, Clong, Clong, Clong, Clong,
285+
Ptr{Clong}, Ptr{Cdouble}, Ptr{Clong}, Ptr{Clong}, Ptr{Cdouble}, Ptr{Clong},
286+
Ptr{Clong}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), n, m, p, l, ncones,
287+
q, Gpr, Gjc, Gir, Apr, Ajc, Air, c, h, b)
205288
end
206289

207290
function solve(problem::Ptr{Cpwork})

0 commit comments

Comments
 (0)