osqp 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/LICENSE.txt +202 -22
- data/NOTICE.txt +27 -0
- data/README.md +11 -8
- data/lib/osqp/ffi.rb +134 -130
- data/lib/osqp/solver.rb +61 -46
- data/lib/osqp/version.rb +1 -1
- data/lib/osqp.rb +21 -1
- data/vendor/libosqp.arm64.dylib +0 -0
- data/vendor/libosqp.dll +0 -0
- data/vendor/libosqp.dylib +0 -0
- data/vendor/libosqp.so +0 -0
- metadata +13 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9808787d2680d0620a0d332fd4d42fbc95474d313bfa6ffa4b65f7d42c27d08
|
4
|
+
data.tar.gz: a49f6357ef19809d5b33a9463b0b2c2af573822cf82867445b15548bf4a6035a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e0ae4959e05063d439ecf0897eb4d406dbf84c1601629d845c7ee2b2b2ed88cf83a60ad90a7c1d6b572681e38d148ae05bb3a3fb7504eb7ad8e1f2cb5a94526
|
7
|
+
data.tar.gz: 62bf72c42951365a0e9ad548e20849a949dd4058d9198f02fffd63373fc137facf07afe857c9fdecc41e15ddfb1241eef9aa177acdfb85531accfe54f8218e33
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 0.1.3 (2022-04-08)
|
2
|
+
|
3
|
+
- Improved ARM detection
|
4
|
+
- Fixed `x` and `y` in solution
|
5
|
+
- Fixed memory issue
|
6
|
+
|
7
|
+
## 0.1.2 (2021-01-05)
|
8
|
+
|
9
|
+
- Added ARM shared library for Mac
|
10
|
+
- Updated OSQP to 0.6.2
|
11
|
+
|
12
|
+
## 0.1.1 (2020-04-10)
|
13
|
+
|
14
|
+
- Changed to Apache 2.0 license to match OSQP
|
15
|
+
- Convert P to upper triangle when needed
|
16
|
+
|
1
17
|
## 0.1.0 (2019-11-16)
|
2
18
|
|
3
19
|
- First release
|
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,27 @@
|
|
1
|
+
Copyright (c) 2019-2020 Andrew Kane
|
2
|
+
|
3
|
+
OSQP
|
4
|
+
Copyright (c) 2019 Bartolomeo Stellato, Goran Banjac, Paul Goulart, Stephen Boyd
|
5
|
+
|
6
|
+
This product includes software developed at Stanford University and at the University of Oxford.
|
7
|
+
|
8
|
+
|
9
|
+
The following external modules are included in this software library
|
10
|
+
|
11
|
+
QDLDL
|
12
|
+
Copyright (c) 2018, Paul Goulart, Bartolomeo Stellato, Goran Banjac.
|
13
|
+
|
14
|
+
AMD
|
15
|
+
Copyright (c) 1996-2015, Timothy A. Davis, Patrick R. Amestoy, and Iain S. Duff.
|
16
|
+
|
17
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
18
|
+
you may not use this file except in compliance with the License.
|
19
|
+
You may obtain a copy of the License at
|
20
|
+
|
21
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
22
|
+
|
23
|
+
Unless required by applicable law or agreed to in writing, software
|
24
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
25
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
26
|
+
See the License for the specific language governing permissions and
|
27
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
# OSQP
|
1
|
+
# OSQP Ruby
|
2
2
|
|
3
3
|
The [OSQP](https://osqp.org/) (Operator Splitting Quadratic Program) solver for Ruby
|
4
4
|
|
5
|
+
[![Build Status](https://github.com/ankane/osqp-ruby/workflows/build/badge.svg?branch=master)](https://github.com/ankane/osqp-ruby/actions)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application’s Gemfile:
|
8
10
|
|
9
11
|
```ruby
|
10
|
-
gem
|
12
|
+
gem "osqp"
|
11
13
|
```
|
12
14
|
|
13
15
|
## Getting Started
|
@@ -63,22 +65,23 @@ This library is modeled after the OSQP [Python API](https://osqp.org/docs/interf
|
|
63
65
|
|
64
66
|
## History
|
65
67
|
|
66
|
-
View the [changelog](https://github.com/ankane/osqp/blob/master/CHANGELOG.md)
|
68
|
+
View the [changelog](https://github.com/ankane/osqp-ruby/blob/master/CHANGELOG.md)
|
67
69
|
|
68
70
|
## Contributing
|
69
71
|
|
70
72
|
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
71
73
|
|
72
|
-
- [Report bugs](https://github.com/ankane/osqp/issues)
|
73
|
-
- Fix bugs and [submit pull requests](https://github.com/ankane/osqp/pulls)
|
74
|
+
- [Report bugs](https://github.com/ankane/osqp-ruby/issues)
|
75
|
+
- Fix bugs and [submit pull requests](https://github.com/ankane/osqp-ruby/pulls)
|
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
|
-
git clone https://github.com/ankane/osqp.git
|
81
|
-
cd osqp
|
82
|
+
git clone https://github.com/ankane/osqp-ruby.git
|
83
|
+
cd osqp-ruby
|
82
84
|
bundle install
|
85
|
+
bundle exec rake vendor:all
|
83
86
|
bundle exec rake test
|
84
87
|
```
|
data/lib/osqp/ffi.rb
CHANGED
@@ -1,142 +1,146 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module OSQP
|
2
|
+
module FFI
|
3
|
+
extend Fiddle::Importer
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
"libosqp.so"
|
5
|
+
libs = Array(OSQP.ffi_lib).dup
|
6
|
+
begin
|
7
|
+
dlload Fiddle.dlopen(libs.shift)
|
8
|
+
rescue Fiddle::DLError => e
|
9
|
+
retry if libs.any?
|
10
|
+
raise e
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
typealias "c_float", "double"
|
14
|
+
typealias "c_int", "long long"
|
15
|
+
typealias "enum", "int"
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
Data = struct [
|
18
|
+
"c_int n",
|
19
|
+
"c_int m",
|
20
|
+
"csc *p",
|
21
|
+
"csc *a",
|
22
|
+
"c_float *q",
|
23
|
+
"c_float *l",
|
24
|
+
"c_float *u"
|
25
|
+
]
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
Settings = struct [
|
28
|
+
"c_float rho",
|
29
|
+
"c_float sigma",
|
30
|
+
"c_int scaling",
|
31
|
+
"c_int adaptive_rho",
|
32
|
+
"c_int adaptive_rho_interval",
|
33
|
+
"c_float adaptive_rho_tolerance",
|
34
|
+
"c_float adaptive_rho_fraction",
|
35
|
+
"c_int max_iter",
|
36
|
+
"c_float eps_abs",
|
37
|
+
"c_float eps_rel",
|
38
|
+
"c_float eps_prim_inf",
|
39
|
+
"c_float eps_dual_inf",
|
40
|
+
"c_float alpha",
|
41
|
+
"enum linsys_solver_type linsys_solver",
|
42
|
+
"c_float delta",
|
43
|
+
"c_int polish",
|
44
|
+
"c_int polish_refine_iter",
|
45
|
+
"c_int verbose",
|
46
|
+
"c_int scaled_termination",
|
47
|
+
"c_int check_termination",
|
48
|
+
"c_int warm_start",
|
49
|
+
"c_float time_limit"
|
50
|
+
]
|
28
51
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
"c_int polish",
|
46
|
-
"c_int polish_refine_iter",
|
47
|
-
"c_int verbose",
|
48
|
-
"c_int scaled_termination",
|
49
|
-
"c_int check_termination",
|
50
|
-
"c_int warm_start",
|
51
|
-
"c_float time_limit"
|
52
|
-
]
|
52
|
+
Info = struct [
|
53
|
+
"c_int iter",
|
54
|
+
"char status[32]",
|
55
|
+
"c_int status_val",
|
56
|
+
"c_int status_polish",
|
57
|
+
"c_float obj_val",
|
58
|
+
"c_float pri_res",
|
59
|
+
"c_float dua_res",
|
60
|
+
"c_float setup_time",
|
61
|
+
"c_float solve_time",
|
62
|
+
"c_float update_time",
|
63
|
+
"c_float polish_time",
|
64
|
+
"c_float run_time",
|
65
|
+
"c_int rho_updates",
|
66
|
+
"c_float rho_estimate"
|
67
|
+
]
|
53
68
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
"c_int status_polish",
|
59
|
-
"c_float obj_val",
|
60
|
-
"c_float pri_res",
|
61
|
-
"c_float dua_res",
|
62
|
-
"c_float setup_time",
|
63
|
-
"c_float solve_time",
|
64
|
-
"c_float update_time",
|
65
|
-
"c_float polish_time",
|
66
|
-
"c_float run_time",
|
67
|
-
"c_int rho_updates",
|
68
|
-
"c_float rho_estimate"
|
69
|
-
]
|
69
|
+
Solution = struct [
|
70
|
+
"c_float *x",
|
71
|
+
"c_float *y"
|
72
|
+
]
|
70
73
|
|
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
|
-
|
74
|
+
Workspace = struct [
|
75
|
+
"OSQPData *data",
|
76
|
+
"LinSysSolver *linsys_solver",
|
77
|
+
"OSQPPolish *pol",
|
78
|
+
"c_float *rho_vec",
|
79
|
+
"c_float *rho_inv_vec",
|
80
|
+
"c_int *constr_type",
|
81
|
+
"c_float *x",
|
82
|
+
"c_float *y",
|
83
|
+
"c_float *z",
|
84
|
+
"c_float *xz_tilde",
|
85
|
+
"c_float *x_prev",
|
86
|
+
"c_float *z_prev",
|
87
|
+
"c_float *Ax",
|
88
|
+
"c_float *Px",
|
89
|
+
"c_float *Aty",
|
90
|
+
"c_float *delta_y",
|
91
|
+
"c_float *Atdelta_y",
|
92
|
+
"c_float *delta_x",
|
93
|
+
"c_float *Pdelta_x",
|
94
|
+
"c_float *Adelta_x",
|
95
|
+
"c_float *D_temp",
|
96
|
+
"c_float *D_temp_A",
|
97
|
+
"c_float *E_temp",
|
98
|
+
"OSQPSettings *settings",
|
99
|
+
"OSQPScaling *scaling",
|
100
|
+
"OSQPSolution *solution",
|
101
|
+
"OSQPInfo *info",
|
102
|
+
"OSQPTimer *timer",
|
103
|
+
"c_int first_run",
|
104
|
+
"c_int clear_update_time",
|
105
|
+
"c_int rho_update_from_solve",
|
106
|
+
"c_int summary_printed"
|
107
|
+
]
|
105
108
|
|
106
|
-
|
107
|
-
|
109
|
+
# cs.h
|
110
|
+
extern "csc* csc_matrix(c_int m, c_int n, c_int nzmax, c_float *x, c_int *i, c_int *p)"
|
108
111
|
|
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
|
-
|
112
|
+
# osqp.h
|
113
|
+
extern "void osqp_set_default_settings(OSQPSettings *settings)"
|
114
|
+
extern "c_int osqp_setup(OSQPWorkspace** workp, OSQPData* data, OSQPSettings* settings)"
|
115
|
+
extern "c_int osqp_solve(OSQPWorkspace *work)"
|
116
|
+
extern "c_int osqp_cleanup(OSQPWorkspace *work)"
|
117
|
+
extern "c_int osqp_update_lin_cost(OSQPWorkspace *work, c_float *q_new)"
|
118
|
+
extern "c_int osqp_update_bounds(OSQPWorkspace *work, c_float *l_new, c_float *u_new)"
|
119
|
+
extern "c_int osqp_update_lower_bound(OSQPWorkspace *work, c_float *l_new)"
|
120
|
+
extern "c_int osqp_update_upper_bound(OSQPWorkspace *work, c_float *u_new)"
|
121
|
+
extern "c_int osqp_warm_start(OSQPWorkspace *work, c_float *x, c_float *y)"
|
122
|
+
extern "c_int osqp_warm_start_x(OSQPWorkspace *work, c_float *x)"
|
123
|
+
extern "c_int osqp_warm_start_y(OSQPWorkspace *work, c_float *y)"
|
124
|
+
extern "c_int osqp_update_P(OSQPWorkspace *work, c_float *Px_new, c_int *Px_new_idx, c_int P_new_n)"
|
125
|
+
extern "c_int osqp_update_A(OSQPWorkspace *work, c_float *Ax_new, c_int *Ax_new_idx, c_int A_new_n)"
|
126
|
+
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)"
|
127
|
+
extern "c_int osqp_update_rho(OSQPWorkspace *work, c_float rho_new)"
|
128
|
+
extern "c_int osqp_update_max_iter(OSQPWorkspace *work, c_int max_iter_new)"
|
129
|
+
extern "c_int osqp_update_eps_abs(OSQPWorkspace *work, c_float eps_abs_new)"
|
130
|
+
extern "c_int osqp_update_eps_rel(OSQPWorkspace *work, c_float eps_rel_new)"
|
131
|
+
extern "c_int osqp_update_eps_prim_inf(OSQPWorkspace *work, c_float eps_prim_inf_new)"
|
132
|
+
extern "c_int osqp_update_eps_dual_inf(OSQPWorkspace *work, c_float eps_dual_inf_new)"
|
133
|
+
extern "c_int osqp_update_alpha(OSQPWorkspace *work, c_float alpha_new)"
|
134
|
+
extern "c_int osqp_update_warm_start(OSQPWorkspace *work, c_int warm_start_new)"
|
135
|
+
extern "c_int osqp_update_scaled_termination(OSQPWorkspace *work, c_int scaled_termination_new)"
|
136
|
+
extern "c_int osqp_update_check_termination(OSQPWorkspace *work, c_int check_termination_new)"
|
137
|
+
extern "c_int osqp_update_delta(OSQPWorkspace *work, c_float delta_new)"
|
138
|
+
extern "c_int osqp_update_polish(OSQPWorkspace *work, c_int polish_new)"
|
139
|
+
extern "c_int osqp_update_polish_refine_iter(OSQPWorkspace *work, c_int polish_refine_iter_new)"
|
140
|
+
extern "c_int osqp_update_verbose(OSQPWorkspace *work, c_int verbose_new)"
|
141
|
+
extern "c_int osqp_update_time_limit(OSQPWorkspace *work, c_float time_limit_new)"
|
139
142
|
|
140
|
-
|
141
|
-
|
143
|
+
# util.h
|
144
|
+
extern "const char* osqp_version(void)"
|
145
|
+
end
|
142
146
|
end
|
data/lib/osqp/solver.rb
CHANGED
@@ -2,32 +2,23 @@ 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
|
+
refs = []
|
9
|
+
m, n = shape(a)
|
18
10
|
data = FFI::Data.malloc
|
19
11
|
data.n = n
|
20
12
|
data.m = m
|
21
|
-
data.p = csc_matrix(p)
|
22
|
-
data.q = float_array(q)
|
23
|
-
data.a = csc_matrix(a)
|
24
|
-
data.l = float_array(l)
|
25
|
-
data.u = float_array(u)
|
13
|
+
data.p = csc_matrix(p, refs, upper: true)
|
14
|
+
data.q = float_array(q, refs)
|
15
|
+
data.a = csc_matrix(a, refs)
|
16
|
+
data.l = float_array(l, refs)
|
17
|
+
data.u = float_array(u, refs)
|
26
18
|
|
27
19
|
# work
|
28
|
-
work =
|
29
|
-
check_result FFI.osqp_setup(work.ref, data, set)
|
30
|
-
|
20
|
+
work = FFI::Workspace.malloc
|
21
|
+
check_result FFI.osqp_setup(work.to_ptr.ref, data, set)
|
31
22
|
@work = work
|
32
23
|
end
|
33
24
|
|
@@ -35,24 +26,22 @@ module OSQP
|
|
35
26
|
setup(*args, **settings) if args.any? || settings.any?
|
36
27
|
|
37
28
|
check_result FFI.osqp_solve(@work)
|
38
|
-
workspace = FFI::Workspace.new(@work)
|
39
29
|
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
|
30
|
+
# solution
|
31
|
+
solution = FFI::Solution.new(@work.solution)
|
32
|
+
data = FFI::Data.new(@work.data)
|
33
|
+
x = read_float_array(solution.x, data.n)
|
34
|
+
y = read_float_array(solution.y, data.m)
|
44
35
|
|
45
36
|
# info
|
46
|
-
info = FFI::Info.new(
|
47
|
-
status = info.status
|
48
|
-
idx = status.index { |v| v == 0 }
|
37
|
+
info = FFI::Info.new(@work.info)
|
49
38
|
|
50
39
|
# TODO prim_inf_cert and dual_inf_cert
|
51
40
|
{
|
52
41
|
x: x,
|
53
42
|
y: y,
|
54
43
|
iter: info.iter,
|
55
|
-
status: status
|
44
|
+
status: read_string(info.status),
|
56
45
|
status_val: info.status_val,
|
57
46
|
status_polish: info.status_polish,
|
58
47
|
obj_val: info.obj_val,
|
@@ -70,10 +59,9 @@ module OSQP
|
|
70
59
|
|
71
60
|
def warm_start(x, y)
|
72
61
|
# 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
|
62
|
+
m, n = dimensions
|
63
|
+
raise Error, "Expected x to be size #{n}, got #{x.size}" if x && x.size != n
|
64
|
+
raise Error, "Expected y to be size #{m}, got #{y.size}" if y && y.size != m
|
77
65
|
|
78
66
|
if x && y
|
79
67
|
check_result FFI.osqp_warm_start(@work, float_array(x), float_array(y))
|
@@ -116,14 +104,18 @@ module OSQP
|
|
116
104
|
end
|
117
105
|
end
|
118
106
|
|
119
|
-
def float_array(arr)
|
107
|
+
def float_array(arr, refs = nil)
|
120
108
|
# OSQP float = double
|
121
|
-
Fiddle::Pointer[arr.to_a.pack("d*")]
|
109
|
+
ptr = Fiddle::Pointer[arr.to_a.pack("d*")]
|
110
|
+
refs << ptr if refs
|
111
|
+
ptr
|
122
112
|
end
|
123
113
|
|
124
|
-
def int_array(arr)
|
114
|
+
def int_array(arr, refs = nil)
|
125
115
|
# OSQP int = long long
|
126
|
-
Fiddle::Pointer[arr.to_a.pack("q*")]
|
116
|
+
ptr = Fiddle::Pointer[arr.to_a.pack("q*")]
|
117
|
+
refs << ptr if refs
|
118
|
+
ptr
|
127
119
|
end
|
128
120
|
|
129
121
|
def read_float_array(ptr, size)
|
@@ -131,9 +123,13 @@ module OSQP
|
|
131
123
|
ptr[0, size * Fiddle::SIZEOF_DOUBLE].unpack("d*")
|
132
124
|
end
|
133
125
|
|
126
|
+
def read_string(char_ptr)
|
127
|
+
idx = char_ptr.index { |v| v == 0 }
|
128
|
+
char_ptr[0, idx].map(&:chr).join
|
129
|
+
end
|
130
|
+
|
134
131
|
# TODO add support sparse matrices
|
135
|
-
|
136
|
-
def csc_matrix(mtx)
|
132
|
+
def csc_matrix(mtx, refs, upper: false)
|
137
133
|
mtx = mtx.to_a
|
138
134
|
|
139
135
|
m, n = shape(mtx)
|
@@ -145,11 +141,11 @@ module OSQP
|
|
145
141
|
# CSC format
|
146
142
|
# https://www.gormanalysis.com/blog/sparse-matrix-storage-formats/
|
147
143
|
cp << 0
|
148
|
-
n.times do |
|
149
|
-
mtx.each_with_index do |row,
|
150
|
-
if row[
|
151
|
-
cx << row[
|
152
|
-
ci <<
|
144
|
+
n.times do |j|
|
145
|
+
mtx.each_with_index do |row, i|
|
146
|
+
if row[j] != 0 && (!upper || i <= j)
|
147
|
+
cx << row[j]
|
148
|
+
ci << i
|
153
149
|
end
|
154
150
|
end
|
155
151
|
# cumulative column values
|
@@ -157,13 +153,18 @@ module OSQP
|
|
157
153
|
end
|
158
154
|
|
159
155
|
nnz = cx.size
|
160
|
-
cx = float_array(cx)
|
161
|
-
ci = int_array(ci)
|
162
|
-
cp = int_array(cp)
|
156
|
+
cx = float_array(cx, refs)
|
157
|
+
ci = int_array(ci, refs)
|
158
|
+
cp = int_array(cp, refs)
|
163
159
|
|
164
160
|
FFI.csc_matrix(m, n, nnz, cx, ci, cp)
|
165
161
|
end
|
166
162
|
|
163
|
+
def dimensions
|
164
|
+
data = FFI::Data.new(@work.data)
|
165
|
+
[data.m, data.n]
|
166
|
+
end
|
167
|
+
|
167
168
|
def shape(a)
|
168
169
|
if defined?(Matrix) && a.is_a?(Matrix)
|
169
170
|
[a.row_count, a.column_count]
|
@@ -174,6 +175,20 @@ module OSQP
|
|
174
175
|
end
|
175
176
|
end
|
176
177
|
|
178
|
+
def create_settings(settings)
|
179
|
+
set = FFI::Settings.malloc
|
180
|
+
FFI.osqp_set_default_settings(set)
|
181
|
+
|
182
|
+
# hack for setting members with []=
|
183
|
+
# safer than send("#{k}=", v)
|
184
|
+
entity = set.to_ptr
|
185
|
+
settings.each do |k, v|
|
186
|
+
entity[k.to_s] = settings_value(v)
|
187
|
+
end
|
188
|
+
|
189
|
+
set
|
190
|
+
end
|
191
|
+
|
177
192
|
# handle booleans
|
178
193
|
def settings_value(v)
|
179
194
|
case v
|
data/lib/osqp/version.rb
CHANGED
data/lib/osqp.rb
CHANGED
@@ -2,13 +2,33 @@
|
|
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
|
|
9
8
|
module OSQP
|
10
9
|
class Error < StandardError; end
|
11
10
|
|
11
|
+
class << self
|
12
|
+
attr_accessor :ffi_lib
|
13
|
+
end
|
14
|
+
lib_name =
|
15
|
+
if Gem.win_platform?
|
16
|
+
"libosqp.dll"
|
17
|
+
elsif RbConfig::CONFIG["host_os"] =~ /darwin/i
|
18
|
+
if RbConfig::CONFIG["host_cpu"] =~ /arm|aarch64/i
|
19
|
+
"libosqp.arm64.dylib"
|
20
|
+
else
|
21
|
+
"libosqp.dylib"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
"libosqp.so"
|
25
|
+
end
|
26
|
+
vendor_lib = File.expand_path("../vendor/#{lib_name}", __dir__)
|
27
|
+
self.ffi_lib = [vendor_lib]
|
28
|
+
|
29
|
+
# friendlier error message
|
30
|
+
autoload :FFI, "osqp/ffi"
|
31
|
+
|
12
32
|
def self.lib_version
|
13
33
|
FFI.osqp_version.to_s
|
14
34
|
end
|
Binary file
|
data/vendor/libosqp.dll
CHANGED
Binary file
|
data/vendor/libosqp.dylib
CHANGED
Binary file
|
data/vendor/libosqp.so
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,79 +1,24 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '5'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: numo-narray
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
description:
|
70
|
-
email: andrew@chartkick.com
|
11
|
+
date: 2022-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: andrew@ankane.org
|
71
15
|
executables: []
|
72
16
|
extensions: []
|
73
17
|
extra_rdoc_files: []
|
74
18
|
files:
|
75
19
|
- CHANGELOG.md
|
76
20
|
- LICENSE.txt
|
21
|
+
- NOTICE.txt
|
77
22
|
- README.md
|
78
23
|
- lib/osqp.rb
|
79
24
|
- lib/osqp/ffi.rb
|
@@ -81,14 +26,15 @@ files:
|
|
81
26
|
- lib/osqp/version.rb
|
82
27
|
- vendor/LICENSE
|
83
28
|
- vendor/NOTICE
|
29
|
+
- vendor/libosqp.arm64.dylib
|
84
30
|
- vendor/libosqp.dll
|
85
31
|
- vendor/libosqp.dylib
|
86
32
|
- vendor/libosqp.so
|
87
|
-
homepage: https://github.com/ankane/osqp
|
33
|
+
homepage: https://github.com/ankane/osqp-ruby
|
88
34
|
licenses:
|
89
|
-
-
|
35
|
+
- Apache-2.0
|
90
36
|
metadata: {}
|
91
|
-
post_install_message:
|
37
|
+
post_install_message:
|
92
38
|
rdoc_options: []
|
93
39
|
require_paths:
|
94
40
|
- lib
|
@@ -103,8 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
49
|
- !ruby/object:Gem::Version
|
104
50
|
version: '0'
|
105
51
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
107
|
-
signing_key:
|
52
|
+
rubygems_version: 3.3.7
|
53
|
+
signing_key:
|
108
54
|
specification_version: 4
|
109
55
|
summary: OSQP (Operator Splitting Quadratic Program) solver for Ruby
|
110
56
|
test_files: []
|