osqp 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +202 -22
- data/NOTICE.txt +13 -0
- data/README.md +3 -1
- data/lib/osqp.rb +3 -1
- data/lib/osqp/ffi.rb +133 -131
- data/lib/osqp/solver.rb +43 -34
- data/lib/osqp/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81100b0a27916edf758ca568e9213b8ea451c1efa664f00ddb84155c1c50f650
|
4
|
+
data.tar.gz: af59920235f7c6c4c1f13ab61861fbbb4f27bf2aebbbab59cb9a3beaef6c2099
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b480edb450da31e0ef2714452db49caa36e0089b61fbcd8b89e0a92bba0cd2a81c3442cca7fa84e0f1947dfc7f36e50fe3b1dd773f42fe80203584be2ce6fb12
|
7
|
+
data.tar.gz: ac74d1ec489c286618ebe8d10f1f1bf4ca4408966972e8ecbfbf8f80c918a42abdb9eb780dfbcac8dbc8016a8909727e82c53dc68c9b3c9da31564d16bd19405
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
@@ -1,22 +1,202 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/NOTICE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2019-2020 Andrew Kane
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
The [OSQP](https://osqp.org/) (Operator Splitting Quadratic Program) solver for Ruby
|
4
4
|
|
5
|
+
[![Build Status](https://travis-ci.org/ankane/osqp.svg?branch=master)](https://travis-ci.org/ankane/osqp) [![Build status](https://ci.appveyor.com/api/projects/status/o93q4b56anxmnvwn/branch/master?svg=true)](https://ci.appveyor.com/project/ankane/osqp/branch/master)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application’s Gemfile:
|
@@ -74,7 +76,7 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
|
|
74
76
|
- Write, clarify, or fix documentation
|
75
77
|
- Suggest or add new features
|
76
78
|
|
77
|
-
To get started with development
|
79
|
+
To get started with development:
|
78
80
|
|
79
81
|
```sh
|
80
82
|
git clone https://github.com/ankane/osqp.git
|
data/lib/osqp.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
require "fiddle/import"
|
3
3
|
|
4
4
|
# modules
|
5
|
-
require "osqp/ffi"
|
6
5
|
require "osqp/solver"
|
7
6
|
require "osqp/version"
|
8
7
|
|
@@ -12,4 +11,7 @@ module OSQP
|
|
12
11
|
def self.lib_version
|
13
12
|
FFI.osqp_version.to_s
|
14
13
|
end
|
14
|
+
|
15
|
+
# friendlier error message
|
16
|
+
autoload :FFI, "osqp/ffi"
|
15
17
|
end
|
data/lib/osqp/ffi.rb
CHANGED
@@ -1,142 +1,144 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module OSQP
|
2
|
+
module FFI
|
3
|
+
extend Fiddle::Importer
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
lib =
|
6
|
+
if Gem.win_platform?
|
7
|
+
"libosqp.dll"
|
8
|
+
elsif RbConfig::CONFIG["host_os"] =~ /darwin/i
|
9
|
+
"libosqp.dylib"
|
10
|
+
else
|
11
|
+
"libosqp.so"
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
+
dlload File.expand_path("../../vendor/#{lib}", __dir__)
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
typealias "c_float", "double"
|
17
|
+
typealias "c_int", "long long"
|
18
|
+
typealias "enum", "int"
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
Data = struct [
|
21
|
+
"c_int n",
|
22
|
+
"c_int m",
|
23
|
+
"csc *p",
|
24
|
+
"csc *a",
|
25
|
+
"c_float *q",
|
26
|
+
"c_float *l",
|
27
|
+
"c_float *u"
|
28
|
+
]
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
30
|
+
Settings = struct [
|
31
|
+
"c_float rho",
|
32
|
+
"c_float sigma",
|
33
|
+
"c_int scaling",
|
34
|
+
"c_int adaptive_rho",
|
35
|
+
"c_int adaptive_rho_interval",
|
36
|
+
"c_float adaptive_rho_tolerance",
|
37
|
+
"c_float adaptive_rho_fraction",
|
38
|
+
"c_int max_iter",
|
39
|
+
"c_float eps_abs",
|
40
|
+
"c_float eps_rel",
|
41
|
+
"c_float eps_prim_inf",
|
42
|
+
"c_float eps_dual_inf",
|
43
|
+
"c_float alpha",
|
44
|
+
"enum linsys_solver_type linsys_solver",
|
45
|
+
"c_float delta",
|
46
|
+
"c_int polish",
|
47
|
+
"c_int polish_refine_iter",
|
48
|
+
"c_int verbose",
|
49
|
+
"c_int scaled_termination",
|
50
|
+
"c_int check_termination",
|
51
|
+
"c_int warm_start",
|
52
|
+
"c_float time_limit"
|
53
|
+
]
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
55
|
+
Info = struct [
|
56
|
+
"c_int iter",
|
57
|
+
"char status[32]",
|
58
|
+
"c_int status_val",
|
59
|
+
"c_int status_polish",
|
60
|
+
"c_float obj_val",
|
61
|
+
"c_float pri_res",
|
62
|
+
"c_float dua_res",
|
63
|
+
"c_float setup_time",
|
64
|
+
"c_float solve_time",
|
65
|
+
"c_float update_time",
|
66
|
+
"c_float polish_time",
|
67
|
+
"c_float run_time",
|
68
|
+
"c_int rho_updates",
|
69
|
+
"c_float rho_estimate"
|
70
|
+
]
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
72
|
+
Workspace = struct [
|
73
|
+
"OSQPData *data",
|
74
|
+
"LinSysSolver *linsys_solver",
|
75
|
+
"OSQPPolish *pol",
|
76
|
+
"c_float *rho_vec",
|
77
|
+
"c_float *rho_inv_vec",
|
78
|
+
"c_int *constr_type",
|
79
|
+
"c_float *x",
|
80
|
+
"c_float *y",
|
81
|
+
"c_float *z",
|
82
|
+
"c_float *xz_tilde",
|
83
|
+
"c_float *x_prev",
|
84
|
+
"c_float *z_prev",
|
85
|
+
"c_float *Ax",
|
86
|
+
"c_float *Px",
|
87
|
+
"c_float *Aty",
|
88
|
+
"c_float *delta_y",
|
89
|
+
"c_float *Atdelta_y",
|
90
|
+
"c_float *delta_x",
|
91
|
+
"c_float *Pdelta_x",
|
92
|
+
"c_float *Adelta_x",
|
93
|
+
"c_float *D_temp",
|
94
|
+
"c_float *D_temp_A",
|
95
|
+
"c_float *E_temp",
|
96
|
+
"OSQPSettings *settings",
|
97
|
+
"OSQPScaling *scaling",
|
98
|
+
"OSQPSolution *solution",
|
99
|
+
"OSQPInfo *info",
|
100
|
+
"OSQPTimer *timer",
|
101
|
+
"c_int first_run",
|
102
|
+
"c_int clear_update_time",
|
103
|
+
"c_int rho_update_from_solve",
|
104
|
+
"c_int summary_printed"
|
105
|
+
]
|
105
106
|
|
106
|
-
|
107
|
-
|
107
|
+
# cs.h
|
108
|
+
extern "csc* csc_matrix(c_int m, c_int n, c_int nzmax, c_float *x, c_int *i, c_int *p)"
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
110
|
+
# osqp.h
|
111
|
+
extern "void osqp_set_default_settings(OSQPSettings *settings)"
|
112
|
+
extern "c_int osqp_setup(OSQPWorkspace** workp, OSQPData* data, OSQPSettings* settings)"
|
113
|
+
extern "c_int osqp_solve(OSQPWorkspace *work)"
|
114
|
+
extern "c_int osqp_cleanup(OSQPWorkspace *work)"
|
115
|
+
extern "c_int osqp_update_lin_cost(OSQPWorkspace *work, c_float *q_new)"
|
116
|
+
extern "c_int osqp_update_bounds(OSQPWorkspace *work, c_float *l_new, c_float *u_new)"
|
117
|
+
extern "c_int osqp_update_lower_bound(OSQPWorkspace *work, c_float *l_new)"
|
118
|
+
extern "c_int osqp_update_upper_bound(OSQPWorkspace *work, c_float *u_new)"
|
119
|
+
extern "c_int osqp_warm_start(OSQPWorkspace *work, c_float *x, c_float *y)"
|
120
|
+
extern "c_int osqp_warm_start_x(OSQPWorkspace *work, c_float *x)"
|
121
|
+
extern "c_int osqp_warm_start_y(OSQPWorkspace *work, c_float *y)"
|
122
|
+
extern "c_int osqp_update_P(OSQPWorkspace *work, c_float *Px_new, c_int *Px_new_idx, c_int P_new_n)"
|
123
|
+
extern "c_int osqp_update_A(OSQPWorkspace *work, c_float *Ax_new, c_int *Ax_new_idx, c_int A_new_n)"
|
124
|
+
extern "c_int osqp_update_P_A(OSQPWorkspace *work, c_float *Px_new, c_int *Px_new_idx, c_int P_new_n, c_float *Ax_new, c_int *Ax_new_idx, c_int A_new_n)"
|
125
|
+
extern "c_int osqp_update_rho(OSQPWorkspace *work, c_float rho_new)"
|
126
|
+
extern "c_int osqp_update_max_iter(OSQPWorkspace *work, c_int max_iter_new)"
|
127
|
+
extern "c_int osqp_update_eps_abs(OSQPWorkspace *work, c_float eps_abs_new)"
|
128
|
+
extern "c_int osqp_update_eps_rel(OSQPWorkspace *work, c_float eps_rel_new)"
|
129
|
+
extern "c_int osqp_update_eps_prim_inf(OSQPWorkspace *work, c_float eps_prim_inf_new)"
|
130
|
+
extern "c_int osqp_update_eps_dual_inf(OSQPWorkspace *work, c_float eps_dual_inf_new)"
|
131
|
+
extern "c_int osqp_update_alpha(OSQPWorkspace *work, c_float alpha_new)"
|
132
|
+
extern "c_int osqp_update_warm_start(OSQPWorkspace *work, c_int warm_start_new)"
|
133
|
+
extern "c_int osqp_update_scaled_termination(OSQPWorkspace *work, c_int scaled_termination_new)"
|
134
|
+
extern "c_int osqp_update_check_termination(OSQPWorkspace *work, c_int check_termination_new)"
|
135
|
+
extern "c_int osqp_update_delta(OSQPWorkspace *work, c_float delta_new)"
|
136
|
+
extern "c_int osqp_update_polish(OSQPWorkspace *work, c_int polish_new)"
|
137
|
+
extern "c_int osqp_update_polish_refine_iter(OSQPWorkspace *work, c_int polish_refine_iter_new)"
|
138
|
+
extern "c_int osqp_update_verbose(OSQPWorkspace *work, c_int verbose_new)"
|
139
|
+
extern "c_int osqp_update_time_limit(OSQPWorkspace *work, c_float time_limit_new)"
|
139
140
|
|
140
|
-
|
141
|
-
|
141
|
+
# util.h
|
142
|
+
extern "const char* osqp_version(void)"
|
143
|
+
end
|
142
144
|
end
|
data/lib/osqp/solver.rb
CHANGED
@@ -2,32 +2,22 @@ module OSQP
|
|
2
2
|
class Solver
|
3
3
|
def setup(p, q, a, l, u, **settings)
|
4
4
|
# settings
|
5
|
-
set =
|
6
|
-
FFI.osqp_set_default_settings(set)
|
7
|
-
|
8
|
-
# hack for setting members with []=
|
9
|
-
# safer than send("#{k}=", v)
|
10
|
-
entity = set.to_ptr
|
11
|
-
settings.each do |k, v|
|
12
|
-
entity[k.to_s] = settings_value(v)
|
13
|
-
end
|
14
|
-
|
15
|
-
m, n = shape(a)
|
5
|
+
set = create_settings(settings)
|
16
6
|
|
17
7
|
# data
|
8
|
+
m, n = shape(a)
|
18
9
|
data = FFI::Data.malloc
|
19
10
|
data.n = n
|
20
11
|
data.m = m
|
21
|
-
data.p = csc_matrix(p)
|
12
|
+
data.p = csc_matrix(p, upper: true)
|
22
13
|
data.q = float_array(q)
|
23
14
|
data.a = csc_matrix(a)
|
24
15
|
data.l = float_array(l)
|
25
16
|
data.u = float_array(u)
|
26
17
|
|
27
18
|
# work
|
28
|
-
work =
|
29
|
-
check_result FFI.osqp_setup(work.ref, data, set)
|
30
|
-
|
19
|
+
work = FFI::Workspace.malloc
|
20
|
+
check_result FFI.osqp_setup(work.to_ptr.ref, data, set)
|
31
21
|
@work = work
|
32
22
|
end
|
33
23
|
|
@@ -35,24 +25,21 @@ module OSQP
|
|
35
25
|
setup(*args, **settings) if args.any? || settings.any?
|
36
26
|
|
37
27
|
check_result FFI.osqp_solve(@work)
|
38
|
-
workspace = FFI::Workspace.new(@work)
|
39
28
|
|
40
29
|
# data
|
41
|
-
data = FFI::Data.new(
|
42
|
-
x = read_float_array(
|
43
|
-
y = read_float_array(
|
30
|
+
data = FFI::Data.new(@work.data)
|
31
|
+
x = read_float_array(@work.x, data.n)
|
32
|
+
y = read_float_array(@work.y, data.m)
|
44
33
|
|
45
34
|
# info
|
46
|
-
info = FFI::Info.new(
|
47
|
-
status = info.status
|
48
|
-
idx = status.index { |v| v == 0 }
|
35
|
+
info = FFI::Info.new(@work.info)
|
49
36
|
|
50
37
|
# TODO prim_inf_cert and dual_inf_cert
|
51
38
|
{
|
52
39
|
x: x,
|
53
40
|
y: y,
|
54
41
|
iter: info.iter,
|
55
|
-
status: status
|
42
|
+
status: read_string(info.status),
|
56
43
|
status_val: info.status_val,
|
57
44
|
status_polish: info.status_polish,
|
58
45
|
obj_val: info.obj_val,
|
@@ -70,10 +57,9 @@ module OSQP
|
|
70
57
|
|
71
58
|
def warm_start(x, y)
|
72
59
|
# check dimensions
|
73
|
-
|
74
|
-
|
75
|
-
raise Error, "Expected
|
76
|
-
raise Error, "Expected y to be size #{data.m}, got #{y.size}" if y && y.size != data.m
|
60
|
+
m, n = dimensions
|
61
|
+
raise Error, "Expected x to be size #{n}, got #{x.size}" if x && x.size != n
|
62
|
+
raise Error, "Expected y to be size #{m}, got #{y.size}" if y && y.size != m
|
77
63
|
|
78
64
|
if x && y
|
79
65
|
check_result FFI.osqp_warm_start(@work, float_array(x), float_array(y))
|
@@ -131,9 +117,13 @@ module OSQP
|
|
131
117
|
ptr[0, size * Fiddle::SIZEOF_DOUBLE].unpack("d*")
|
132
118
|
end
|
133
119
|
|
120
|
+
def read_string(char_ptr)
|
121
|
+
idx = char_ptr.index { |v| v == 0 }
|
122
|
+
char_ptr[0, idx].map(&:chr).join
|
123
|
+
end
|
124
|
+
|
134
125
|
# TODO add support sparse matrices
|
135
|
-
|
136
|
-
def csc_matrix(mtx)
|
126
|
+
def csc_matrix(mtx, upper: false)
|
137
127
|
mtx = mtx.to_a
|
138
128
|
|
139
129
|
m, n = shape(mtx)
|
@@ -145,11 +135,11 @@ module OSQP
|
|
145
135
|
# CSC format
|
146
136
|
# https://www.gormanalysis.com/blog/sparse-matrix-storage-formats/
|
147
137
|
cp << 0
|
148
|
-
n.times do |
|
149
|
-
mtx.each_with_index do |row,
|
150
|
-
if row[
|
151
|
-
cx << row[
|
152
|
-
ci <<
|
138
|
+
n.times do |j|
|
139
|
+
mtx.each_with_index do |row, i|
|
140
|
+
if row[j] != 0 && (!upper || i <= j)
|
141
|
+
cx << row[j]
|
142
|
+
ci << i
|
153
143
|
end
|
154
144
|
end
|
155
145
|
# cumulative column values
|
@@ -164,6 +154,11 @@ module OSQP
|
|
164
154
|
FFI.csc_matrix(m, n, nnz, cx, ci, cp)
|
165
155
|
end
|
166
156
|
|
157
|
+
def dimensions
|
158
|
+
data = FFI::Data.new(@work.data)
|
159
|
+
[data.m, data.n]
|
160
|
+
end
|
161
|
+
|
167
162
|
def shape(a)
|
168
163
|
if defined?(Matrix) && a.is_a?(Matrix)
|
169
164
|
[a.row_count, a.column_count]
|
@@ -174,6 +169,20 @@ module OSQP
|
|
174
169
|
end
|
175
170
|
end
|
176
171
|
|
172
|
+
def create_settings(settings)
|
173
|
+
set = FFI::Settings.malloc
|
174
|
+
FFI.osqp_set_default_settings(set)
|
175
|
+
|
176
|
+
# hack for setting members with []=
|
177
|
+
# safer than send("#{k}=", v)
|
178
|
+
entity = set.to_ptr
|
179
|
+
settings.each do |k, v|
|
180
|
+
entity[k.to_s] = settings_value(v)
|
181
|
+
end
|
182
|
+
|
183
|
+
set
|
184
|
+
end
|
185
|
+
|
177
186
|
# handle booleans
|
178
187
|
def settings_value(v)
|
179
188
|
case v
|
data/lib/osqp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,6 +74,7 @@ extra_rdoc_files: []
|
|
74
74
|
files:
|
75
75
|
- CHANGELOG.md
|
76
76
|
- LICENSE.txt
|
77
|
+
- NOTICE.txt
|
77
78
|
- README.md
|
78
79
|
- lib/osqp.rb
|
79
80
|
- lib/osqp/ffi.rb
|
@@ -86,7 +87,7 @@ files:
|
|
86
87
|
- vendor/libosqp.so
|
87
88
|
homepage: https://github.com/ankane/osqp
|
88
89
|
licenses:
|
89
|
-
-
|
90
|
+
- Apache-2.0
|
90
91
|
metadata: {}
|
91
92
|
post_install_message:
|
92
93
|
rdoc_options: []
|
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
- !ruby/object:Gem::Version
|
104
105
|
version: '0'
|
105
106
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
107
|
+
rubygems_version: 3.1.2
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
110
|
summary: OSQP (Operator Splitting Quadratic Program) solver for Ruby
|