superscs_interface.cpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #include "superscs_interface.hpp"
27 #include "casadi/core/casadi_misc.hpp"
28 
29 #include <linsys/amatrix.h>
30 #include <linsys/common.h>
31 #include <cstring>
32 
33 namespace casadi {
34 
35  extern "C"
36  int CASADI_CONIC_SUPERSCS_EXPORT
37  casadi_register_conic_superscs(Conic::Plugin* plugin) {
38  plugin->creator = SuperscsInterface::creator;
39  plugin->name = "superscs";
40  plugin->doc = SuperscsInterface::meta_doc.c_str();
41  plugin->version = CASADI_VERSION;
42  plugin->options = &SuperscsInterface::options_;
43  plugin->deserialize = &SuperscsInterface::deserialize;
44  return 0;
45  }
46 
47  extern "C"
48  void CASADI_CONIC_SUPERSCS_EXPORT casadi_load_conic_superscs() {
50  }
51 
52  SuperscsInterface::SuperscsInterface(const std::string& name,
53  const std::map<std::string, Sparsity>& st)
54  : Conic(name, st) {
55  }
56 
58  clear_mem();
59  }
60 
62  = {{&Conic::options_},
63  {{"superscs",
64  {OT_DICT,
65  "Options to be passed to superscs."}}
66  }
67  };
68 
69  void SuperscsInterface::init(const Dict& opts) {
70  // Initialize the base classes
71  Conic::init(opts);
72 
73  ScsData dummy;
74  dummy.stgs = &settings_;
75  scs_set_default_settings(&dummy);
76 
77  settings_.eps = 1e-6;
78 
79  // Read options
80  for (auto&& op : opts) {
81  if (op.first=="superscs") {
82  const Dict& opts = op.second;
83  for (auto&& op : opts) {
84  if (op.first=="normalize") {
85  settings_.normalize = op.second;
86  } else if (op.first=="scale") {
87  settings_.scale = op.second;
88  } else if (op.first=="rho_x") {
89  settings_.rho_x = op.second;
90  } else if (op.first=="max_time_milliseconds") {
91  settings_.max_time_milliseconds = op.second;
92  } else if (op.first=="max_iters") {
93  settings_.max_iters = op.second;
94  } else if (op.first=="previous_max_iters") {
95  settings_.previous_max_iters = op.second;
96  } else if (op.first=="eps") {
97  settings_.eps = op.second;
98  } else if (op.first=="alpha") {
99  settings_.alpha = op.second;
100  } else if (op.first=="cg_rate") {
101  settings_.cg_rate = op.second;
102  } else if (op.first=="verbose") {
103  settings_.verbose = op.second;
104  } else if (op.first=="warm_start") {
105  settings_.warm_start = op.second;
106  } else if (op.first=="do_super_scs") {
107  settings_.do_super_scs = op.second;
108  } else if (op.first=="k0") {
109  settings_.k0 = op.second;
110  } else if (op.first=="c_bl") {
111  settings_.c_bl = op.second;
112  } else if (op.first=="k1") {
113  settings_.k1 = op.second;
114  } else if (op.first=="k2") {
115  settings_.k2 = op.second;
116  } else if (op.first=="c1") {
117  settings_.c1 = op.second;
118  } else if (op.first=="sse") {
119  settings_.sse = op.second;
120  } else if (op.first=="ls") {
121  settings_.ls = op.second;
122  } else if (op.first=="beta") {
123  settings_.beta = op.second;
124  } else if (op.first=="sigma") {
125  settings_.sigma = op.second;
126  } else if (op.first=="direction") {
127  if (op.second=="restarted_broyden") {
128  settings_.direction = restarted_broyden;
129  } else if (op.second=="anderson_acceleration") {
130  settings_.direction = anderson_acceleration;
131  } else if (op.second=="fixed_point_residual") {
132  settings_.direction = fixed_point_residual;
133  } else if (op.second=="full_broyden") {
134  settings_.direction = full_broyden;
135  } else {
136  casadi_error("Unknown argument for direction.");
137  }
138  } else if (op.first=="thetabar") {
139  settings_.thetabar = op.second;
140  } else if (op.first=="memory") {
141  settings_.memory = op.second;
142  } else if (op.first=="tRule") {
143  settings_.tRule = op.second;
144  } else if (op.first=="broyden_init_scaling") {
145  settings_.broyden_init_scaling = op.second;
146  } else if (op.first=="do_record_progress") {
147  settings_.do_record_progress = op.second;
148  } else if (op.first=="do_override_streams") {
149  settings_.do_override_streams = op.second;
150  } else {
151  casadi_error("Not recognised");
152  }
153  }
154  }
155  }
156 
157  // Create a helper function that trasforms the Hessian into
158  // a factorised representation
159  //
160  // 1/2 x' H x -> 1/2 || F x ||_2^2
161  HL_sp_ = H_.ldl(Hp_);
162  MX P = DM::eye(nx_)(Slice(), Hp_);
163 
164  // Arguments for F Function are the LDL parameters
165  MX L = MX::sym("L", HL_sp_);
166  MX D = MX::sym("D", Sparsity::diag(nx_));
167  F_ = Function("F", {L, D}, {sqrt(2)*mtimes(mtimes(sqrt(D), DM::eye(nx_)+ L), P.T())});
168 
169  // Note: Quadratic reformulation
170  //
171  // min 1/2 x'Hx + G'x
172  // x st lb <= Ax <= ub
173  //
174  // is transformed to
175  //
176  // min y + G'x
177  // x,y st lb <= Ax <= ub
178  // || F x || <= 1+y (part 1)
179  // y <= -1 (part 2)
180 
181  // Initialize SDP to SOCP memory
183 
184  // Canonical form of superscs:
185  // min <c,x>
186  // x,s
187  //
188  // subject to Ax+s = b
189  // s in K^l x K^q1 x K^q2 ...
190  //
191  // with:
192  // x in K^l <=> x>=0
193  // (t, x) in K^q <=> ||x|| <= t
194 
195  // Note: soc reordering
196  // We will get cones from CasADi
197  // in a form [A1;A2] x <=> || A1 x || <= A2 x
198  // while we need [A2;A1]
199  const SDPToSOCPMem& sm = sdp_to_socp_mem_;
200  for (casadi_int i=1;i<sm.r.size();++i) {
201  perturb_.push_back(sm.r[i]-1);
202  for (casadi_int k=sm.r[i-1];k<sm.r[i]-1;++k) {
203  perturb_.push_back(k);
204  }
205  }
206 
207  casadi_int offset = 0;
208 
209  // A: simple bounds
210  // Index matrix for x <= ubx
211  IM B(Sparsity::diag(nx_), range(nx_), false);
212  offset += nx_;
213  // and lbx <= x
214  B = vertcat(B, IM(Sparsity::diag(nx_), range(offset, offset+nx_), false));
215  offset += nx_;
216 
217  // A: linear constraints
218  // Index matrix for A x <= ubx
219  IM A(A_, range(offset, offset+A_.nnz()), false);
220  offset += A_.nnz();
221  // Index matrix for lbx <= A x
222  A = vertcat(A, IM(A_, range(offset, offset+A_.nnz()), false));
223  offset += A_.nnz();
224 
225  // A: quadratic reformulation (part 2)
226  // Index matrix for y<=-1
227  IM Ae(Sparsity::unit(nx_+1, nx_).T(), offset);
228  offset += 1;
229 
230  // SOCP helper constraints
231  const Sparsity& sp = sm.map_Q.sparsity();
232  const casadi_int* colind = sp.colind();
233  const casadi_int* row = sp.row();
234  const casadi_int* ddata = sm.map_Q.ptr();
235 
236  // A: conic constraints
237  casadi_int n_c = sp.size2();
238 
239  std::vector<casadi_int> c_row, c_col, c_data;
240 
241  for (casadi_int j=0; j<n_c; ++j) {
242  casadi_int i = perturb_[j];
243  for (casadi_int k=colind[i]; k<colind[i+1]-1; ++k) {
244  c_col.push_back(row[k]);
245  c_row.push_back(j);
246  c_data.push_back(offset+ddata[k]);
247  }
248  }
249  offset += Q_.nnz();
250 
251  IM C = IM::triplet(c_row, c_col, c_data, n_c, nx_);
252 
253  // A: conic constraints stemming from quadratic reformulation (part 1)
254  IM F = IM(F_.sparsity_out(0), range(offset, offset+F_.nnz_out(0)));
255  offset+= F_.nnz_out(0);
256 
257  F = blockcat(IM(1, nx_), offset, F, IM(nx_, 1));
258  F = vertcat(F, horzcat(IM(1, nx_), offset+1));
259 
260  // Augment an empty column, because of the iontroduction of 'y'
261  // in the quadratic reformulation
262  A = horzcat(A, IM(A.size1(), 1));
263  B = horzcat(B, IM(B.size1(), 1));
264  C = horzcat(C, IM(C.size1(), 1));
265 
266  At_ = IM::vertcat({B, A, Ae, C, F});
267 
268  lookup_ = lookupvector(At_.nonzeros(), 2*nx_ + 2*A_.nnz() + 1 + Q_.nnz()+F_.nnz_out(0)+2);
269 
270  alloc_w(At_.nnz(), true);
271  alloc_w(At_.size1(), true);
272  }
273 
274  int SuperscsInterface::init_mem(void* mem) const {
275  if (Conic::init_mem(mem)) return 1;
276  auto m = static_cast<SuperscsMemory*>(mem);
277 
278  m->ldl_d.resize(nx_);
279  m->ldl_l.resize(HL_sp_.nnz());
280  m->ldl_w.resize(nx_);
281  m->F_res.resize(F_.sparsity_out(0).nnz());
282  m->g.resize(nx_+1);
283 
284  m->data.n = At_.size2();
285  m->data.m = At_.size1();
286  m->data.stgs = &m->settings;
287 
288  m->A.m = At_.size1();
289  m->A.n = At_.size2();
290  m->at_colind = At_.sparsity().get_colind();
291  m->A.p = get_ptr(m->at_colind);
292  m->at_row = At_.sparsity().get_row();
293  m->A.i = get_ptr(m->at_row);
294  m->A.x = nullptr;
295 
296  m->data.A = &m->A;
297  const SDPToSOCPMem& sm = sdp_to_socp_mem_;
298 
299  m->cone.f = 0;
300  m->cone.qsize = sm.r.size();
301  m->q = diff(sm.r);
302  m->q.push_back(nx_+2);
303  m->cone.q = get_ptr(m->q);
304 
305  m->sol = nullptr;
306  m->info = nullptr;
307 
308  m->fstats["preprocessing"] = FStats();
309  m->fstats["solver"] = FStats();
310  m->fstats["postprocessing"] = FStats();
311  return 0;
312  }
313 
315  solve(const double** arg, double** res, casadi_int* iw, double* w, void* mem) const {
316  auto m = static_cast<SuperscsMemory*>(mem);
317  const SDPToSOCPMem& sm = sdp_to_socp_mem_;
318 
319  // Perform LDL factorization
320  bool H_all_zero = true;
321  for (casadi_int k=0;k<H_.nnz();++k) {
322  H_all_zero = H_all_zero && arg[CONIC_H][k]==0;
323  }
324 
325  // Circumvent bug in ldl?
326  if (H_all_zero) {
327  casadi_clear(get_ptr(m->ldl_l), HL_sp_.nnz());
328  casadi_clear(get_ptr(m->ldl_d), nx_);
329  } else {
330  casadi_ldl(H_, arg[CONIC_H], HL_sp_, get_ptr(m->ldl_l), get_ptr(m->ldl_d),
331  get_ptr(Hp_), get_ptr(m->ldl_w));
332  }
333 
334  F_({get_ptr(m->ldl_l), get_ptr(m->ldl_d)}, {get_ptr(m->F_res)});
335 
336  double* a_ptr = w; w+= At_.nnz();
337  m->A.x = a_ptr;
338 
339  const casadi_int* lookup = get_ptr(lookup_);
340 
341  // A: simple bounds
342  for (casadi_int k=0;k<nx_;++k) {
343  a_ptr[*lookup++] = 1;
344  }
345  for (casadi_int k=0;k<nx_;++k) {
346  a_ptr[*lookup++] = -1;
347  }
348  // A: linear constraints
349  for (casadi_int k=0;k<A_.nnz();++k) {
350  a_ptr[*lookup++] = arg[CONIC_A][k];
351  }
352  for (casadi_int k=0;k<A_.nnz();++k) {
353  a_ptr[*lookup++] = -arg[CONIC_A][k];
354  }
355 
356  // A: quadratic reformulation (part 2)
357  a_ptr[*lookup++] = -1;
358 
359  // A: conic constraints
360  for (casadi_int k=0;k<Q_.nnz();++k) {
361  casadi_int loc = *lookup++;
362  if (loc>=0) {
363  a_ptr[loc] = -arg[CONIC_Q][k];
364  }
365  }
366 
367  // A: conic constraints stemming from quadratic reformulation (part 1)
368  for (casadi_int k=0;k<F_.nnz_out(0);++k) {
369  a_ptr[*lookup++] = -m->F_res[k];
370  }
371  a_ptr[*lookup++] = -1;
372  a_ptr[*lookup++] = 1;
373 
374  // b: simple bounds
375  double* b_ptr = w;
376 
377  m->data.b = b_ptr;
378  casadi_clear(b_ptr, At_.size1());
379 
380  casadi_axpy(nx_, 1.0, arg[CONIC_UBX], b_ptr);
381  b_ptr += nx_;
382  casadi_axpy(nx_, -1.0, arg[CONIC_LBX], b_ptr);
383  b_ptr += nx_;
384 
385  // b: linear constraints
386  casadi_copy(arg[CONIC_UBA], na_, b_ptr);
387  b_ptr += na_;
388  casadi_axpy(na_, -1.0, arg[CONIC_LBA], b_ptr);
389  b_ptr += na_;
390 
391  // b: quadratic reformulation (part 2)
392  *b_ptr = -1;
393  b_ptr += 1;
394 
395  // b: conic constraints
396  for (casadi_int j=0; j<sm.map_Q.size2(); ++j) {
397  casadi_int i = perturb_[j];
398  // Get bound
399  b_ptr[j] = sm.map_P[i]==-1 ? 0 : arg[CONIC_P][sm.map_P[i]];
400  }
401  b_ptr += sm.map_Q.size2();
402 
403  // b: conic constraints stemming from quadratic reformulation (part 1)
404  *b_ptr = 1;
405  b_ptr += 1;
406  b_ptr += nx_;
407  *b_ptr = 1;
408  b_ptr += 1;
409 
410  // SuperSCS cannot dealing with infinities,
411  // and replacing with arbitrarily large bounds
412  // is numerically undesirable for the method
413 
414  // -> detect inactive rows
415  std::vector<casadi_int> s;
416  for (casadi_int k=0;k<At_.size1();++k) {
417  if (!isinf(m->data.b[k])) s.push_back(k);
418  }
419  std::vector<casadi_int> sl = lookupvector(s, At_.size1());
420  std::vector<casadi_int> mapping;
421  Sparsity Anew = At_.sparsity().sub(s, range(At_.size2()), mapping);
422 
423  // Trim A
424  casadi_copy(Anew.colind(), nx_+2, m->A.p);
425  casadi_copy(Anew.row(), Anew.nnz(), m->A.i);
426  m->A.m = Anew.size1();
427  m->data.m = Anew.size1();
428  for (casadi_int k=0;k<Anew.nnz();++k) {
429  m->A.x[k] = m->A.x[mapping[k]];
430  }
431 
432  // Trim b
433  for (casadi_int k=0;k<At_.size1();++k) {
434  casadi_int e = sl[k];
435  if (e>=0) m->data.b[e] = m->data.b[k];
436  }
437 
438  // How many linear constraints we have
439  // depends on the trimming procedure
440  m->cone.l = 2*nx_+2*na_+1-(At_.size1()-Anew.size1());
441 
442  // Set objective
443  casadi_copy(arg[CONIC_G], nx_, get_ptr(m->g));
444  // Part related to quadratic reformulation: y
445  m->g[nx_] = 1;
446 
447  m->data.c = get_ptr(m->g);
448 
449  // No other cones
450  m->cone.ssize = 0;
451  m->cone.ed = 0;
452  m->cone.ep = 0;
453  m->cone.psize = 0;
454  m->cone.p = nullptr;
455  m->cone.s = nullptr;
456 
457  if (m->sol) scs_free_sol(m->sol);
458  if (m->info) scs_free_info(m->info);
459 
460  m->sol = scs_init_sol();
461  m->info = scs_init_info();
462 
463  // Copy settings
464  std::memcpy(m->data.stgs, &settings_, sizeof(ScsSettings));
465 
466  casadi_int status = scs(&m->data, &m->cone, m->sol, m->info);
467 
468  m->d_qp.success = SCS_SOLVED==status;
469 
470  casadi_copy(m->sol->x, nx_, res[CONIC_X]);
471  if (res[CONIC_COST])
472  *res[CONIC_COST] = casadi_dot(nx_, m->sol->x, get_ptr(m->g));
473  if (res[CONIC_COST])
474  *res[CONIC_COST] += 0.5*casadi_bilin(arg[CONIC_H], H_, m->sol->x, m->sol->x);
475 
476  return 0;
477  }
478 
480  Dict stats = Conic::get_stats(mem);
481  //auto m = static_cast<SuperscsMemory*>(mem);
482  //stats["return_status"] = return_status_string(m->return_status);
483  return stats;
484  }
485 
487  }
488 
490  if (sol) scs_free_sol(sol);
491  if (info) scs_free_info(info);
492  }
493 
495  s.version("SuperscsInterface", 1);
496  ScsData dummy;
497  dummy.stgs = &settings_;
498  scs_set_default_settings(&dummy);
499  s.unpack("SuperscsInterface::settings::normalize", settings_.normalize);
500  s.unpack("SuperscsInterface::settings::scale", settings_.scale);
501  s.unpack("SuperscsInterface::settings::rho_x", settings_.rho_x);
502  s.unpack("SuperscsInterface::settings::max_time_milliseconds", settings_.max_time_milliseconds);
503  s.unpack("SuperscsInterface::settings::max_iters", settings_.max_iters);
504  s.unpack("SuperscsInterface::settings::previous_max_iters", settings_.previous_max_iters);
505  s.unpack("SuperscsInterface::settings::eps", settings_.eps);
506  s.unpack("SuperscsInterface::settings::alpha", settings_.alpha);
507  s.unpack("SuperscsInterface::settings::cg_rate", settings_.cg_rate);
508  s.unpack("SuperscsInterface::settings::verbose", settings_.verbose);
509  s.unpack("SuperscsInterface::settings::warm_start", settings_.warm_start);
510  s.unpack("SuperscsInterface::settings::do_super_scs", settings_.do_super_scs);
511  s.unpack("SuperscsInterface::settings::k0", settings_.k0);
512  s.unpack("SuperscsInterface::settings::c_bl", settings_.c_bl);
513  s.unpack("SuperscsInterface::settings::k1", settings_.k1);
514  s.unpack("SuperscsInterface::settings::k2", settings_.k2);
515  s.unpack("SuperscsInterface::settings::c1", settings_.c1);
516  s.unpack("SuperscsInterface::settings::sse", settings_.sse);
517  s.unpack("SuperscsInterface::settings::ls", settings_.ls);
518  s.unpack("SuperscsInterface::settings::beta", settings_.beta);
519  s.unpack("SuperscsInterface::settings::sigma", settings_.sigma);
520  casadi_int dir;
521  s.unpack("SuperscsInterface::settings::direction", dir);
522  settings_.direction = static_cast<direction_enum>(dir);
523  s.unpack("SuperscsInterface::settings::thetabar", settings_.thetabar);
524  s.unpack("SuperscsInterface::settings::memory", settings_.memory);
525  s.unpack("SuperscsInterface::settings::tRule", settings_.tRule);
526  s.unpack("SuperscsInterface::settings::broyden_init_scaling", settings_.broyden_init_scaling);
527  s.unpack("SuperscsInterface::settings::do_record_progress", settings_.do_record_progress);
528  s.unpack("SuperscsInterface::settings::do_override_streams", settings_.do_override_streams);
529  s.unpack("SuperscsInterface::Hp", Hp_);
530  s.unpack("SuperscsInterface::HL_sp", HL_sp_);
531  s.unpack("SuperscsInterface::f", F_);
532  s.unpack("SuperscsInterface::At", At_);
533  s.unpack("SuperscsInterface::lookup", lookup_);
534  s.unpack("SuperscsInterface::perturb", perturb_);
535  s.unpack("SuperscsInterface::opts", opts_);
537  }
538 
541  s.version("SuperscsInterface", 1);
542  s.pack("SuperscsInterface::settings::normalize", settings_.normalize);
543  s.pack("SuperscsInterface::settings::scale", settings_.scale);
544  s.pack("SuperscsInterface::settings::rho_x", settings_.rho_x);
545  s.pack("SuperscsInterface::settings::max_time_milliseconds", settings_.max_time_milliseconds);
546  s.pack("SuperscsInterface::settings::max_iters", settings_.max_iters);
547  s.pack("SuperscsInterface::settings::previous_max_iters", settings_.previous_max_iters);
548  s.pack("SuperscsInterface::settings::eps", settings_.eps);
549  s.pack("SuperscsInterface::settings::alpha", settings_.alpha);
550  s.pack("SuperscsInterface::settings::cg_rate", settings_.cg_rate);
551  s.pack("SuperscsInterface::settings::verbose", settings_.verbose);
552  s.pack("SuperscsInterface::settings::warm_start", settings_.warm_start);
553  s.pack("SuperscsInterface::settings::do_super_scs", settings_.do_super_scs);
554  s.pack("SuperscsInterface::settings::k0", settings_.k0);
555  s.pack("SuperscsInterface::settings::c_bl", settings_.c_bl);
556  s.pack("SuperscsInterface::settings::k1", settings_.k1);
557  s.pack("SuperscsInterface::settings::k2", settings_.k2);
558  s.pack("SuperscsInterface::settings::c1", settings_.c1);
559  s.pack("SuperscsInterface::settings::sse", settings_.sse);
560  s.pack("SuperscsInterface::settings::ls", settings_.ls);
561  s.pack("SuperscsInterface::settings::beta", settings_.beta);
562  s.pack("SuperscsInterface::settings::sigma", settings_.sigma);
563  s.pack("SuperscsInterface::settings::direction", static_cast<casadi_int>(settings_.direction));
564  s.pack("SuperscsInterface::settings::thetabar", settings_.thetabar);
565  s.pack("SuperscsInterface::settings::memory", settings_.memory);
566  s.pack("SuperscsInterface::settings::tRule", settings_.tRule);
567  s.pack("SuperscsInterface::settings::broyden_init_scaling", settings_.broyden_init_scaling);
568  s.pack("SuperscsInterface::settings::do_record_progress", settings_.do_record_progress);
569  s.pack("SuperscsInterface::settings::do_override_streams", settings_.do_override_streams);
570  s.pack("SuperscsInterface::Hp", Hp_);
571  s.pack("SuperscsInterface::HL_sp", HL_sp_);
572  s.pack("SuperscsInterface::f", F_);
573  s.pack("SuperscsInterface::At", At_);
574  s.pack("SuperscsInterface::lookup", lookup_);
575  s.pack("SuperscsInterface::perturb", perturb_);
576  s.pack("SuperscsInterface::opts", opts_);
578  }
579 
580 } // namespace casadi
Internal class.
Definition: conic_impl.hpp:44
static const Options options_
Options.
Definition: conic_impl.hpp:83
casadi_int nx_
Number of decision variables.
Definition: conic_impl.hpp:169
int init_mem(void *mem) const override
Initalize memory block.
Definition: conic.cpp:451
casadi_int na_
The number of constraints (counting both equality and inequality) == A.size1()
Definition: conic_impl.hpp:172
Sparsity H_
Problem structure.
Definition: conic_impl.hpp:166
void init(const Dict &opts) override
Initialize.
Definition: conic.cpp:412
void deserialize(DeserializingStream &s, SDPToSOCPMem &m)
Definition: conic.cpp:729
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Definition: conic.cpp:738
Dict get_stats(void *mem) const override
Get all statistics.
Definition: conic.cpp:711
void sdp_to_socp_init(SDPToSOCPMem &mem) const
SDP to SOCP conversion initialization.
Definition: conic.cpp:580
void serialize(SerializingStream &s, const SDPToSOCPMem &m) const
Definition: conic.cpp:721
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
void version(const std::string &name, int v)
void alloc_w(size_t sz_w, bool persistent=false)
Ensure required length of w field.
casadi_int nnz_out() const
Get number of output nonzeros.
Definition: function.cpp:855
const Sparsity & sparsity_out(casadi_int ind) const
Get sparsity of a given output.
Definition: function.cpp:1031
casadi_int nnz() const
Get the number of (structural) non-zero elements.
casadi_int size2() const
Get the second dimension (i.e. number of columns)
casadi_int size1() const
Get the first dimension (i.e. number of rows)
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
MX - Matrix expression.
Definition: mx.hpp:92
std::vector< Scalar > & nonzeros()
const Sparsity & sparsity() const
Const access the sparsity - reference to data member.
static Matrix< casadi_int > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< casadi_int > &d)
Construct a sparse matrix from triplet form.
Scalar * ptr()
static Matrix< casadi_int > vertcat(const std::vector< Matrix< casadi_int > > &v)
static Matrix< double > eye(casadi_int n)
create an n-by-n identity matrix
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
void clear_mem()
Clear all memory (called from destructor)
Helper class for Serialization.
void version(const std::string &name, int v)
void pack(const Sparsity &e)
Serializes an object to the output stream.
Class representing a Slice.
Definition: slice.hpp:48
General sparsity class.
Definition: sparsity.hpp:106
Sparsity sub(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, std::vector< casadi_int > &mapping, bool ind1=false) const
Get a submatrix.
Definition: sparsity.cpp:334
casadi_int size1() const
Get the number of rows.
Definition: sparsity.cpp:124
static Sparsity diag(casadi_int nrow)
Create diagonal sparsity pattern *.
Definition: sparsity.hpp:190
static Sparsity unit(casadi_int n, casadi_int el)
Create the sparsity pattern for a unit vector of length n and a nonzero on.
Definition: sparsity.cpp:1104
casadi_int nnz() const
Get the number of (structural) non-zeros.
Definition: sparsity.cpp:148
casadi_int size2() const
Get the number of columns.
Definition: sparsity.cpp:128
const casadi_int * row() const
Get a reference to row-vector,.
Definition: sparsity.cpp:164
std::vector< casadi_int > get_colind() const
Get the column index for each column.
Definition: sparsity.cpp:364
Sparsity ldl(std::vector< casadi_int > &p, bool amd=true) const
Symbolic LDL factorization.
Definition: sparsity.cpp:621
std::vector< casadi_int > get_row() const
Get the row for each non-zero entry.
Definition: sparsity.cpp:372
const casadi_int * colind() const
Get a reference to the colindex of all column element (see class description)
Definition: sparsity.cpp:168
std::vector< casadi_int > lookup_
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static const std::string meta_doc
A documentation string.
SuperscsInterface(const std::string &name, const std::map< std::string, Sparsity > &st)
Create a new Solver.
static Conic * creator(const std::string &name, const std::map< std::string, Sparsity > &st)
Create a new QP Solver.
~SuperscsInterface() override
Destructor.
std::vector< casadi_int > perturb_
SDPToSOCPMem sdp_to_socp_mem_
SDP to SOCP conversion memory.
void init(const Dict &opts) override
Initialize.
int init_mem(void *mem) const override
Initalize memory block.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Dict opts_
Superscs options.
Dict get_stats(void *mem) const override
Get all statistics.
static const Options options_
Options.
std::vector< casadi_int > Hp_
int solve(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const override
Solve the QP.
The casadi namespace.
Definition: archiver.cpp:28
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.
@ CONIC_UBA
dense, (nc x 1)
Definition: conic.hpp:181
@ CONIC_A
The matrix A: sparse, (nc x n) - product with x must be dense.
Definition: conic.hpp:177
@ CONIC_G
The vector g: dense, (n x 1)
Definition: conic.hpp:175
@ CONIC_Q
The matrix Q: sparse symmetric, (np^2 x n)
Definition: conic.hpp:193
@ CONIC_LBA
dense, (nc x 1)
Definition: conic.hpp:179
@ CONIC_UBX
dense, (n x 1)
Definition: conic.hpp:185
@ CONIC_H
Definition: conic.hpp:173
@ CONIC_LBX
dense, (n x 1)
Definition: conic.hpp:183
@ CONIC_P
The matrix P: sparse symmetric, (np x np)
Definition: conic.hpp:195
T1 casadi_bilin(const T1 *A, const casadi_int *sp_A, const T1 *x, const T1 *y)
void CASADI_CONIC_SUPERSCS_EXPORT casadi_load_conic_superscs()
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
std::vector< casadi_int > lookupvector(const std::vector< casadi_int > &v, casadi_int size)
Returns a vector for quickly looking up entries of supplied list.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
T1 casadi_dot(casadi_int n, const T1 *x, const T1 *y)
Inner product.
Matrix< casadi_int > IM
Definition: im_fwd.hpp:31
std::vector< T > diff(const std::vector< T > &values)
diff
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.
void casadi_axpy(casadi_int n, T1 alpha, const T1 *x, T1 *y)
AXPY: y <- a*x + y.
int CASADI_CONIC_SUPERSCS_EXPORT casadi_register_conic_superscs(Conic::Plugin *plugin)
void casadi_clear(T1 *x, casadi_int n)
CLEAR: x <- 0.
@ CONIC_X
The primal solution.
Definition: conic.hpp:201
@ CONIC_COST
The optimal cost.
Definition: conic.hpp:203
SDP to SOCP conversion memory.
Definition: conic_impl.hpp:178
std::vector< casadi_int > r
Definition: conic_impl.hpp:180
std::vector< casadi_int > map_P
Definition: conic_impl.hpp:190
Options metadata for a class.
Definition: options.hpp:40
std::vector< double > ldl_d