DuQuad  v1.0
Quadratic Programming Optimizations
 All Data Structures Files Functions Variables Typedefs Macros
main.c
Go to the documentation of this file.
1 /** \file
2  * Main file which takes input from matlab and construct data in c-code format.
3  * This mainfile is called from the matlab function duquad.m.
4  * After converting the input, it runs the spesified algorithm, i.e one
5  * of the following: DGM, DFGM, ALM or FALM.
6  * When getting the result from the algorithm, the data is converted back
7  * to matlab format.
8  */
9 #include "head.h"
10 #include "gdm.h"
11 #include "fgm.h"
12 #include "dgm.h"
13 #include "dfgm.h"
14 #include "alm.h"
15 #include "falm.h"
16 #include "print.h"
17 
18 // Inputs
19 #define H_IN prhs[0]
20 #define C_IN prhs[1]
21 #define A_IN prhs[2]
22 #define B_IN prhs[3]
23 #define LB_HAT_IN prhs[4]
24 #define UB_HAT_IN prhs[5]
25 #define LB_IN prhs[6]
26 #define UB_IN prhs[7]
27 #define Z0_IN prhs[8]
28 #define OPT_IN prhs[9]
29 #define INFO_IN prhs[10]
30 
31 // Used in augmented cases
32 #define H_HAT_IN prhs[11]
33 #define A2_IN prhs[12]
34 #define RHO_AT_B_IN prhs[13]
35 
36 // Outputs
37 #define ZOPT_OUT plhs[0]
38 #define FOPT_OUT plhs[1]
39 #define EXITFLAG_OUT plhs[2]
40 #define OUTPUT_STRUCT_OUT plhs[3]
41 #define LAMBDA1_OUT plhs[4]
42 #define LAMBDA2_OUT plhs[5]
43 
44 /* static functions declaration */
45 
46 static void init_Info();
47 static void init_Options();
48 static void init_Problem();
49 
50 static void make_output();
51 static void make_output_fail_safe();
52 static void make_Output_struct();
53 
54 static void clean_up_Output_M();
55 static void clean_up_Result();
56 
57 static void init_DGM();
58 static void allocate_DGM();
59 static void clean_up_DGM_matlab();
60 
61 static void init_DFGM();
62 static void allocate_DFGM();
63 static void clean_up_DFGM_matlab();
64 
65 static void init_ALM();
66 static void allocate_ALM();
67 static void clean_up_ALM_matlab();
68 
69 static void init_FALM();
70 static void allocate_FALM();
71 static void clean_up_FALM_matlab();
72 
73 /* public functions definition */
74 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
75 {
76  _SDEBUG("*** Main start**\n");
77 
78 
79  int algorithm = mxGetScalar(mxGetField(OPT_IN, 0, "algorithm"));
80  ALGORITHM = algorithm;
81 
82  if (algorithm == 1 || algorithm == 2)
83  {
84  struct Struct_DGM s;
85  init_DGM(nrhs, prhs, &s);
86 
87  if (DGM(&s) == -1){
88  ERROR("Error in DGM()\n");
89  make_output_fail_safe(nlhs, plhs);
90  clean_up_DGM_matlab(&s);
91  return;
92  }
93  make_output(nlhs, plhs, s.res);
94  clean_up_DGM_matlab(&s);
95  }
96  else if (algorithm == 3 || algorithm == 4)
97  {
98  struct Struct_DFGM s;
99  init_DFGM(nrhs, prhs, &s);
100  if (DFGM(&s) == -1){
101  ERROR("Error in DFGM()\n");
102  make_output_fail_safe(nlhs, plhs);
103  clean_up_DFGM_matlab(&s);
104  return;
105  }
106  make_output(nlhs, plhs, s.res);
107  clean_up_DFGM_matlab(&s);
108  }
109  else if (algorithm == 5 || algorithm == 6)
110  {
111  struct Struct_ALM s;
112  init_ALM(nrhs, prhs, &s);
113  if (ALM(&s) == -1){
114  ERROR("Error in ALM()\n");
115  make_output_fail_safe(nlhs, plhs);
116  clean_up_ALM_matlab(&s);
117  return;
118  }
119  make_output(nlhs, plhs, s.res);
120  clean_up_ALM_matlab(&s);
121  }
122 
123  else if (algorithm == 7 || algorithm == 8)
124  {
125  struct Struct_FALM s;
126  init_FALM(nrhs, prhs, &s);
127  if (FALM(&s) == -1){
128  ERROR("Error in FALM()\n");
129  make_output_fail_safe(nlhs, plhs);
130  clean_up_FALM_matlab(&s);
131  return;
132  }
133  make_output(nlhs, plhs, s.res);
134  clean_up_FALM_matlab(&s);
135  }
136 
137 
138  _SDEBUG("*** Main finish**\n");
139  return;
140 }
141 
142 
143 
144 /* Definition of static functions */
145 
146 static void init_Info(int nrhs, const mxArray *prhs[], struct Info *p)
147 {
148  p->lb_is_inf = mxGetScalar(mxGetField(INFO_IN, 0, "lb_is_inf"));
149  p->ub_is_inf = mxGetScalar(mxGetField(INFO_IN, 0, "ub_is_inf"));
150  p->problem_case = mxGetScalar(mxGetField(INFO_IN, 0, "problem_case"));
151  p->eigH_min = mxGetScalar(mxGetField(INFO_IN, 0, "eigH_min"));
152  p->eigH_max = mxGetScalar(mxGetField(INFO_IN, 0, "eigH_max"));
153  p->Ld = mxGetScalar(mxGetField(INFO_IN, 0, "Ld"));
154 
155  switch (p->problem_case) {
156  case 1:
157  p->lb_hat_is_inf = FALSE;
158  p->ub_hat_is_inf = FALSE;
159  p->pf_vec_length = 2*M;
160  break;
161  case 2:
162  p->lb_hat_is_inf = FALSE;
163  p->ub_hat_is_inf = FALSE;
164  p->pf_vec_length = M;
165  break;
166  case 3:
167  p->lb_hat_is_inf = TRUE;
168  p->ub_hat_is_inf = FALSE;
169  p->pf_vec_length = M;
170  break;
171  case 4:
172  p->lb_hat_is_inf = FALSE;
173  p->ub_hat_is_inf = TRUE;
174  p->pf_vec_length = M;
175  break;
176  default:
177  printf("Could not resolve problem case\n");
178  break;
179  }
180 }
181 
182 static void init_Options(int nrhs, const mxArray *prhs[], struct Options *opt)
183 {
184  // Get parameters from the struct opt
185  opt->maxiter_outer = mxGetScalar(mxGetField(OPT_IN, 0, "maxiter_outer"));
186  opt->maxiter_inner = mxGetScalar(mxGetField(OPT_IN, 0, "maxiter_inner"));
187  opt->eps_ds = mxGetScalar(mxGetField(OPT_IN, 0, "eps_ds"));
188  opt->eps_pf = mxGetScalar(mxGetField(OPT_IN, 0, "eps_pf"));
189  opt->eps_inner = mxGetScalar(mxGetField(OPT_IN, 0, "eps_inner"));
190  opt->algorithm = mxGetScalar(mxGetField(OPT_IN, 0, "algorithm"));
191 }
192 
193 static void init_Problem(int nrhs, const mxArray *prhs[], struct Problem *p)
194 {
195 
196  mxArray *b1,*b2;
197  b1 = mxDuplicateArray(H_IN);
198  b2 = mxDuplicateArray(A_IN);
199  p->H = mxGetPr(b1);
200  p->A = mxGetPr(b2);
201 
202  p->A_t = vector_alloc(N*M);
203  mtx_transpose(p->A,p->A_t,M,N);
204 
205  // Other vectors
206  mxArray *a1,*a2,*a3,*a4,*a5,*a6,*a7;
207  a1 = mxDuplicateArray(C_IN);
208  a2 = mxDuplicateArray(B_IN);
209  a3 = mxDuplicateArray(LB_HAT_IN);
210  a4 = mxDuplicateArray(UB_HAT_IN);
211  a5 = mxDuplicateArray(LB_IN);
212  a6 = mxDuplicateArray(UB_IN);
213  a7 = mxDuplicateArray(Z0_IN);
214  p->c = mxGetPr(a1);
215  p->b = mxGetPr(a2);
216  p->lb_hat = mxGetPr(a3);
217  p->ub_hat = mxGetPr(a4);
218  p->lb = mxGetPr(a5);
219  p->ub = mxGetPr(a6);
220  p->z0 = mxGetPr(a7);
221 }
222 
223 static void allocate_DGM(struct Struct_DGM *s)
224 {
225  s->z = vector_alloc(N);
226  s->lambda1 = vector_alloc(M);
227  s->lambda2 = vector_alloc(M);
228  s->temp1_dim_N = vector_alloc(N);
229  s->temp2_dim_M = vector_alloc(M);
230  s->temp3_dim_M = vector_alloc(M);
231  s->b_ub_hat = vector_alloc(M);
232  s->b_lb_hat = vector_alloc(M);
233  s->z_avg = vector_alloc(N);
234  s->summ = vector_alloc(N);
236  s->A_z = vector_alloc(M);
237  s->res->out->ds_vector = vector_alloc(2);
238  s->res->out->pf_vector = vector_alloc(2);
239 }
240 
241 static void allocate_DFGM(struct Struct_DFGM *s)
242 {
243  s->z = vector_alloc(N);
244  s->lambda1 = vector_alloc(M);
245  s->lambda2 = vector_alloc(M);
246  s->temp1_dim_N = vector_alloc(N);
247  s->temp2_dim_M = vector_alloc(M);
248  s->temp3_dim_M = vector_alloc(M);
249  s->b_ub_hat = vector_alloc(M);
250  s->b_lb_hat = vector_alloc(M);
251  s->z_avg = vector_alloc(N);
252  s->summ = vector_alloc(N);
254  s->A_z = vector_alloc(M);
255  s->res->out->ds_vector = vector_alloc(2);
256  s->res->out->pf_vector = vector_alloc(2);
257 
258  // Different form DGM()
259  s->lambda1_old = vector_alloc(M);
260  s->lambda2_old = vector_alloc(M);
261  s->y1 = vector_alloc(M);
262  s->y2 = vector_alloc(M);
263  s->z_ds = vector_alloc(N);
264  s->A_z_ds = vector_alloc(M);
265 }
266 
267 static void allocate_ALM(struct Struct_ALM *s)
268 {
269  s->z = vector_alloc(N);
270  s->lambda = vector_alloc(M);
271  s->temp1_dim_N = vector_alloc(N);
272  s->temp2_dim_M = vector_alloc(M);
273  s->temp3_dim_M = vector_alloc(M);
274  s->z_avg = vector_alloc(N);
275  s->summ = vector_alloc(N);
277  s->A_z = vector_alloc(M);
278  s->res->out->ds_vector = vector_alloc(2);
279  s->res->out->pf_vector = vector_alloc(2);
280 }
281 
282 static void allocate_FALM(struct Struct_FALM *s)
283 {
284  s->z = vector_alloc(N);
285  s->lambda = vector_alloc(M);
286  s->temp1_dim_N = vector_alloc(N);
287  s->temp2_dim_M = vector_alloc(M);
288  s->temp3_dim_M = vector_alloc(M);
289  s->z_avg = vector_alloc(N);
290  s->summ = vector_alloc(N);
292  s->A_z = vector_alloc(M);
293  s->res->out->ds_vector = vector_alloc(2);
294  s->res->out->pf_vector = vector_alloc(2);
295 
296  // Different form DGM()
297  s->lambda_old = vector_alloc(M);
298  s->y1 = vector_alloc(M);
299  s->z_ds = vector_alloc(N);
300  s->A_z_ds = vector_alloc(M);
301 }
302 
303 static void init_DGM(int nrhs, const mxArray *prhs[], struct Struct_DGM *s)
304 {
305  // Get parameters from the struct INFO
306  N = mxGetScalar(mxGetField(INFO_IN, 0, "N"));
307  M = mxGetScalar(mxGetField(INFO_IN, 0, "M"));
308 
309  s->info = malloc(sizeof * s->info);
310  init_Info(nrhs, prhs, s->info);
311 
312  s->opt = malloc(sizeof * s->opt);
313  init_Options(nrhs, prhs, s->opt);
314 
315  s->prob = malloc(sizeof * s->prob);
316  init_Problem(nrhs, prhs, s->prob);
317 
318  s->res = malloc(sizeof * s->res);
319  s->res->fopt = 0.0;
320  s->res->out = malloc(sizeof * s->res->out);
321 
322  allocate_DGM(s);
323 }
324 
325 static void init_DFGM(int nrhs, const mxArray *prhs[], struct Struct_DFGM *s)
326 {
327 
328  // Get parameters from the struct INFO
329  N = mxGetScalar(mxGetField(INFO_IN, 0, "N"));
330  M = mxGetScalar(mxGetField(INFO_IN, 0, "M"));
331 
332  s->info = malloc(sizeof * s->info);
333  init_Info(nrhs, prhs, s->info);
334 
335  s->opt = malloc(sizeof * s->opt);
336  init_Options(nrhs, prhs, s->opt);
337 
338  s->prob = malloc(sizeof * s->prob);
339  init_Problem(nrhs, prhs, s->prob);
340 
341  s->res = malloc(sizeof * s->res);
342  s->res->fopt = 0.0;
343  s->res->out = malloc(sizeof * s->res->out);
344 
345  allocate_DFGM(s);
346  }
347 
348 static void init_ALM(int nrhs, const mxArray *prhs[], struct Struct_ALM *s)
349 {
350  // Get parameters from the struct INFO
351  N = mxGetScalar(mxGetField(INFO_IN, 0, "N"));
352  M = mxGetScalar(mxGetField(INFO_IN, 0, "M"));
353 
354  s->info = malloc(sizeof * s->info);
355  init_Info(nrhs, prhs, s->info);
356 
357  s->opt = malloc(sizeof * s->opt);
358  init_Options(nrhs, prhs, s->opt);
359  s->opt->rho = mxGetScalar(mxGetField(OPT_IN, 0, "rho"));
360 
361  s->prob = malloc(sizeof * s->prob);
362  init_Problem(nrhs, prhs, s->prob);
363 
364  s->res = malloc(sizeof * s->res);
365  s->res->fopt = 0.0;
366  s->res->out = malloc(sizeof * s->res->out);
367 
368  allocate_ALM(s);
369 
370  // Take in some other vectors spesial for augmented case
371  mxArray *a1,*a2,*a3;
372  a1 = mxDuplicateArray(H_HAT_IN);
373  a2 = mxDuplicateArray(A2_IN);
374  a3 = mxDuplicateArray(RHO_AT_B_IN);
375 
376  s->H_hat = mxGetPr(a1);
377  s->A2 = mxGetPr(a2);
378  s->rho_At_b = mxGetPr(a3);
379 }
380 
381 static void init_FALM(int nrhs, const mxArray *prhs[], struct Struct_FALM *s)
382 {
383  // Get parameters from the struct INFO
384  N = mxGetScalar(mxGetField(INFO_IN, 0, "N"));
385  M = mxGetScalar(mxGetField(INFO_IN, 0, "M"));
386 
387  s->info = malloc(sizeof * s->info);
388  init_Info(nrhs, prhs, s->info);
389 
390  s->opt = malloc(sizeof * s->opt);
391  init_Options(nrhs, prhs, s->opt);
392  s->opt->rho = mxGetScalar(mxGetField(OPT_IN, 0, "rho"));
393 
394  s->prob = malloc(sizeof * s->prob);
395  init_Problem(nrhs, prhs, s->prob);
396 
397  s->res = malloc(sizeof * s->res);
398  s->res->fopt = 0.0;
399  s->res->out = malloc(sizeof * s->res->out);
400 
401  allocate_FALM(s);
402 
403  // Take in some other vectors spesial for augmented case
404  mxArray *a1,*a2,*a3;
405  a1 = mxDuplicateArray(H_HAT_IN);
406  a2 = mxDuplicateArray(A2_IN);
407  a3 = mxDuplicateArray(RHO_AT_B_IN);
408 
409  s->H_hat = mxGetPr(a1);
410  s->A2 = mxGetPr(a2);
411  s->rho_At_b = mxGetPr(a3);
412 }
413 
414 static void clean_up_Output_M(struct Output *s)
415 {
418  free(s);
419  s = NULL;
420 }
421 
422 static void clean_up_Result(struct Result *res)
423 {
424  clean_up_Output_M(res->out);
425  res->zopt = NULL; // Just a pointer (newer allocated space)
426  res->lambda1 = NULL; // Just a pointer
427  res->lambda2 = NULL; // Just a pointer
428  free(res);
429  res = NULL;
430 }
431 
432 static void clean_up_DGM_matlab (struct Struct_DGM *s)
433 {
434  free_pointer(s->prob->A_t);
435  free(s->opt); s->opt = NULL;
436  free(s->info); s->info = NULL;
437  free_pointer(s->z);
438  free_pointer(s->lambda1);
439  free_pointer(s->lambda2);
445  free_pointer(s->z_avg);
446  free_pointer(s->summ);
447  free_pointer(s->pf_vec);
448  free_pointer(s->A_z);
449  clean_up_Result(s->res);
450 }
451 
452 static void clean_up_DFGM_matlab (struct Struct_DFGM *s)
453 {
454  free_pointer(s->prob->A_t);
455  free(s->opt); s->opt = NULL;
456  free(s->info); s->info = NULL;
457  free_pointer(s->z);
458  free_pointer(s->lambda1);
459  free_pointer(s->lambda2);
465  free_pointer(s->z_avg);
466  free_pointer(s->summ);
467  free_pointer(s->pf_vec);
468  free_pointer(s->A_z);
469  clean_up_Result(s->res);
470 
471  // Different from DGM()
474  free_pointer(s->y1);
475  free_pointer(s->y2);
476  free_pointer(s->z_ds);
477  free_pointer(s->A_z_ds);
478 }
479 
480 static void clean_up_ALM_matlab (struct Struct_ALM *s)
481 {
482  free_pointer(s->prob->A_t);
483  free(s->opt); s->opt = NULL;
484  free(s->info); s->info = NULL;
485  free_pointer(s->z);
486  free_pointer(s->lambda);
490  free_pointer(s->z_avg);
491  free_pointer(s->summ);
492  free_pointer(s->pf_vec);
493  free_pointer(s->A_z);
494  clean_up_Result(s->res);
495 }
496 
497 static void clean_up_FALM_matlab (struct Struct_FALM *s)
498 {
499  free_pointer(s->prob->A_t);
500  free(s->opt); s->opt = NULL;
501  free(s->info); s->info = NULL;
502  free_pointer(s->z);
503  free_pointer(s->lambda);
507  free_pointer(s->z_avg);
508  free_pointer(s->summ);
509  free_pointer(s->pf_vec);
510  free_pointer(s->A_z);
511  clean_up_Result(s->res);
512 
513  // Different from DGM()
515  free_pointer(s->y1);
516  free_pointer(s->z_ds);
517  free_pointer(s->A_z_ds);
518 }
519 
520 static void make_output(int nlhs, mxArray *plhs[], const struct Result * res)
521 {
522  uint32_t i;
523 
524  // zopt
525  mxArray *MEX_zopt;
526  MEX_zopt = ZOPT_OUT = mxCreateDoubleMatrix(N,1,mxREAL);
527  real_t *ZOPT = mxGetPr(MEX_zopt);
528  for (i=0;i<N;i++)
529  ZOPT[i] = res->zopt[i];
530 
531  // fopt
532  mxArray *MEX_fopt;
533  MEX_fopt=FOPT_OUT = mxCreateDoubleMatrix(1,1,mxREAL);
534  real_t *FOPT = mxGetPr(MEX_fopt);
535  *FOPT = res->fopt;
536 
537  // exitflag
538  mxArray *MEX_exitflag;
539  MEX_exitflag = EXITFLAG_OUT = mxCreateDoubleMatrix(1,1,mxREAL);
540  real_t *EXITFLAG = mxGetPr(MEX_exitflag);
541  *EXITFLAG = res->exitflag;
542 
543  // output (struct)
544  make_Output_struct(nlhs, plhs, res->out);
545 
546  // Lambda 1
547  mxArray *MEX_lambda1;
548  MEX_lambda1 = LAMBDA1_OUT = mxCreateDoubleMatrix(N,1,mxREAL);
549  real_t *LAMBDA1 = mxGetPr(MEX_lambda1);
550  for (i=0;i<N;i++)
551  LAMBDA1[i] = res->lambda1[i];
552 
553  if (ALGORITHM <= 4){
554  // Lambda 2
555  mxArray *MEX_lambda2;
556  MEX_lambda2 = LAMBDA2_OUT = mxCreateDoubleMatrix(N,1,mxREAL);
557  real_t *LAMBDA2 = mxGetPr(MEX_lambda2);
558  for (i=0;i<N;i++)
559  LAMBDA2[i] = res->lambda2[i];
560  }
561 }
562 
563 static void make_output_fail_safe(int nlhs, mxArray *plhs[])
564 {
565  uint32_t i;
566 
567  // zopt
568  mxArray *MEX_zopt;
569  MEX_zopt = ZOPT_OUT = mxCreateDoubleMatrix(1,1,mxREAL);
570  real_t *ZOPT = mxGetPr(MEX_zopt);
571  *ZOPT = -1;
572 
573  // fopt
574  mxArray *MEX_fopt;
575  MEX_fopt=FOPT_OUT = mxCreateDoubleMatrix(1,1,mxREAL);
576  real_t *FOPT = mxGetPr(MEX_fopt);
577  *FOPT = -1;
578 
579  // exitflag
580  mxArray *MEX_exitflag;
581  MEX_exitflag = EXITFLAG_OUT = mxCreateDoubleMatrix(1,1,mxREAL);
582  real_t *EXITFLAG = mxGetPr(MEX_exitflag);
583  *EXITFLAG = -1;
584 
585  // output (struct)
586  mxArray *MEX_output;
587  MEX_output = OUTPUT_STRUCT_OUT = mxCreateDoubleMatrix(1,1,mxREAL);
588  real_t *OUTPUT = mxGetPr(MEX_output);
589  *OUTPUT = -1;
590 
591  // Lambda 1
592  mxArray *MEX_lambda1;
593  MEX_lambda1 = LAMBDA1_OUT = mxCreateDoubleMatrix(N,1,mxREAL);
594  real_t *LAMBDA1 = mxGetPr(MEX_lambda1);
595  *LAMBDA1 = -1;
596 
597  // Lambda 2
598  mxArray *MEX_lambda2;
599  MEX_lambda2 = LAMBDA2_OUT = mxCreateDoubleMatrix(N,1,mxREAL);
600  real_t *LAMBDA2 = mxGetPr(MEX_lambda2);
601  *LAMBDA2 = -1;
602 
603 }
604 
605 
606 static void make_Output_struct(int nlhs, mxArray *plhs[], const struct Output * out)
607 {
608  #define NUM_FIELDS 11 // Number of fields in struct
609  #define NAME_LENGT 30
610 
611  #define ITERATION 0
612  #define ITERATION_INNER_TOT 1
613  #define TIME 2
614  #define TIME_TOT_INNER 3
615  #define FLAG_LAST_SATISFIED 4
616  #define NITER_FEASIBLE_DS 5
617  #define NITER_FEASIBLE_PF 6
618  #define EXITFLAG_INNER 7
619  #define NUM_EXCEEDED_MAX_NITER_INNER 8
620  #define DS_VECTOR 9
621  #define PF_VECTOR 10
622  uint32_t i;
623 
624  //Allocate memory for the fieldnames
625  const char *fieldnames[NUM_FIELDS]; //This will hold field names.
626  for (i=0;i<NUM_FIELDS;i++){
627  fieldnames[i] = (char*)mxMalloc(NAME_LENGT);
628  }
629 
630  // Get all the information
631  memcpy((void*)fieldnames[ITERATION],"iterations",sizeof(char)*NAME_LENGT);
632  mxArray *MEX_iterations = mxCreateDoubleMatrix (1,1,mxREAL);
633  real_t *iterations = mxGetPr(MEX_iterations);
634  iterations[0] = out->iterations;
635 
636  memcpy((void*)fieldnames[ITERATION_INNER_TOT],"iterations_inner_tot",sizeof(char)*NAME_LENGT);
637  mxArray *MEX_iterations_inner_tot = mxCreateDoubleMatrix (1,1,mxREAL);
638  real_t *iterations_inner_tot = mxGetPr(MEX_iterations_inner_tot);
639  iterations_inner_tot[0] = out->iterations_inner_tot;
640 
641  memcpy((void*)fieldnames[TIME],"time",sizeof(char)*NAME_LENGT);
642  mxArray *MEX_time = mxCreateDoubleMatrix (1,1,mxREAL);
643  real_t *time = mxGetPr(MEX_time);
644  time[0] = out->time;
645 
646  memcpy((void*)fieldnames[TIME_TOT_INNER],"time_tot_inner",sizeof(char)*NAME_LENGT);
647  mxArray *MEX_time_tot_inner = mxCreateDoubleMatrix (1,1,mxREAL);
648  real_t *time_tot_inner = mxGetPr(MEX_time_tot_inner);
649  time_tot_inner[0] = out->time_tot_inner;
650 
651  memcpy((void*)fieldnames[FLAG_LAST_SATISFIED],"flag_last_satisfied",sizeof(char)*NAME_LENGT);
652  mxArray *MEX_flag_last_satisfied = mxCreateDoubleMatrix (1,1,mxREAL);
653  real_t *flag_last_satisfied = mxGetPr(MEX_flag_last_satisfied);
654  flag_last_satisfied[0] = out->flag_last_satisfied;
655 
656  memcpy((void*)fieldnames[NITER_FEASIBLE_DS],"niter_feasible_ds",sizeof(char)*NAME_LENGT);
657  mxArray *MEX_niter_feasible_ds = mxCreateDoubleMatrix (1,1,mxREAL);
658  real_t *niter_feasible_ds = mxGetPr(MEX_niter_feasible_ds);
659  niter_feasible_ds[0] = out->niter_feasible_ds;
660 
661  memcpy((void*)fieldnames[NITER_FEASIBLE_PF],"niter_feasible_pf",sizeof(char)*NAME_LENGT);
662  mxArray *MEX_niter_feasible_pf = mxCreateDoubleMatrix (1,1,mxREAL);
663  real_t *niter_feasible_pf = mxGetPr(MEX_niter_feasible_pf);
664  niter_feasible_pf[0] = out->niter_feasible_pf;
665 
666  memcpy((void*)fieldnames[EXITFLAG_INNER],"exitflag_inner",sizeof(char)*NAME_LENGT);
667  mxArray *MEX_exitflag_inner = mxCreateDoubleMatrix (1,1,mxREAL);
668  real_t *exitflag_inner = mxGetPr(MEX_exitflag_inner);
669  exitflag_inner[0] = out->exitflag_inner;
670 
671  memcpy((void*)fieldnames[NUM_EXCEEDED_MAX_NITER_INNER],"num_exceeded_max_niter_inner",sizeof(char)*NAME_LENGT);
672  mxArray *MEX_num_exceeded_max_niter_inner = mxCreateDoubleMatrix (1,1,mxREAL);
673  real_t *num_exceeded_max_niter_inner = mxGetPr(MEX_num_exceeded_max_niter_inner);
674  num_exceeded_max_niter_inner[0] = out->num_exceeded_max_niter_inner;
675 
676  memcpy((void*)fieldnames[PF_VECTOR],"pf_vector",sizeof(char)*NAME_LENGT);
677  mxArray *MEX_pf_vector = mxCreateDoubleMatrix (out->iterations,1,mxREAL);
678  real_t *pf_vector = mxGetPr(MEX_pf_vector);
679  for (i=0;i<out->iterations;i++)
680  pf_vector[i] = out->pf_vector[i];
681 
682  memcpy((void*)fieldnames[DS_VECTOR],"ds_vector",sizeof(char)*NAME_LENGT);
683  mxArray *MEX_ds_vector = mxCreateDoubleMatrix (out->iterations,1,mxREAL);
684  real_t *ds_vector = mxGetPr(MEX_ds_vector);
685  for (i=0;i<out->iterations;i++)
686  ds_vector[i] = out->ds_vector[i];
687 
688  // Create the struct
689  OUTPUT_STRUCT_OUT = mxCreateStructMatrix(1,1,NUM_FIELDS,fieldnames);
690 
691  //Deallocate memory for the fieldnames
692  for (i=0;i<NUM_FIELDS;i++){
693  mxFree((void*) fieldnames[i] );
694  }
695 
696  // Set the info into the struct
697  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,ITERATION, MEX_iterations);
698  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,ITERATION_INNER_TOT, MEX_iterations_inner_tot);
699  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,TIME, MEX_time);
700  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,TIME_TOT_INNER, MEX_time_tot_inner);
701  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,FLAG_LAST_SATISFIED, MEX_flag_last_satisfied);
702  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,NITER_FEASIBLE_DS, MEX_niter_feasible_ds);
703  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,NITER_FEASIBLE_PF, MEX_niter_feasible_pf);
704  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,EXITFLAG_INNER, MEX_exitflag_inner);
705  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,NUM_EXCEEDED_MAX_NITER_INNER, MEX_num_exceeded_max_niter_inner);
706  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,DS_VECTOR, MEX_ds_vector);
707  mxSetFieldByNumber(OUTPUT_STRUCT_OUT,0,PF_VECTOR, MEX_pf_vector);
708 }
real_t * b_ub_hat
Definition: dfgm.h:34
real_t * temp3_dim_M
Definition: dfgm.h:33
real_t * lambda2
Definition: qp_structs.h:69
struct Info * info
Definition: alm.h:25
real_t * temp3_dim_M
Definition: dgm.h:33
real_t * A_z
Definition: falm.h:37
void free_pointer(real_t *pointer)
real_t time_tot_inner
Definition: qp_structs.h:54
unsigned int uint32_t
Definition: typedefs.h:19
real_t time
Definition: qp_structs.h:53
real_t * temp2_dim_M
Definition: falm.h:32
real_t * b_ub_hat
Definition: dgm.h:34
real_t * A_t
Definition: qp_structs.h:19
real_t * A_z
Definition: dfgm.h:39
uint32_t algorithm
Definition: qp_structs.h:34
real_t * z
Definition: dfgm.h:28
#define TRUE
Definition: head.h:29
struct Result * res
Definition: alm.h:26
real_t * lambda2
Definition: dgm.h:30
real_t * lambda_old
Definition: falm.h:40
#define B_IN
Definition: main.c:22
real_t * A2
Definition: falm.h:50
real_t * A_z
Definition: alm.h:37
#define NITER_FEASIBLE_DS
#define INFO_IN
Definition: main.c:29
#define OPT_IN
Definition: main.c:28
real_t * vector_alloc(uint32_t size)
#define NUM_FIELDS
real_t Ld
Definition: qp_structs.h:45
struct Output * out
Definition: qp_structs.h:70
real_t * pf_vec
Definition: falm.h:36
real_t * temp2_dim_M
Definition: alm.h:32
real_t * temp1_dim_N
Definition: dgm.h:31
boolean ub_is_inf
Definition: qp_structs.h:40
Definition: alm.h:21
real_t * zopt
Definition: qp_structs.h:65
uint32_t iterations_inner_tot
Definition: qp_structs.h:52
#define A2_IN
Definition: main.c:33
int32_t DFGM(struct Struct_DFGM *s)
Definition: dfgm.c:20
real_t * b_lb_hat
Definition: dfgm.h:35
real_t * A_z_ds
Definition: falm.h:43
real_t * summ
Definition: alm.h:35
#define FLAG_LAST_SATISFIED
real_t * z
Definition: dgm.h:28
boolean ub_hat_is_inf
Definition: qp_structs.h:42
struct Result * res
Definition: dgm.h:25
real_t * z_avg
Definition: dgm.h:36
real_t * z_avg
Definition: alm.h:34
struct Result * res
Definition: dfgm.h:25
real_t * lb
Definition: qp_structs.h:23
real_t * ds_vector
Definition: qp_structs.h:60
real_t * summ
Definition: falm.h:35
real_t * lambda
Definition: falm.h:29
uint32_t exitflag
Definition: qp_structs.h:67
real_t * temp3_dim_M
Definition: falm.h:33
#define Z0_IN
Definition: main.c:27
uint32_t flag_last_satisfied
Definition: qp_structs.h:55
real_t * A_z
Definition: dgm.h:39
real_t * pf_vec
Definition: alm.h:36
uint32_t pf_vec_length
Definition: qp_structs.h:47
#define C_IN
Definition: main.c:20
real_t * lambda2
Definition: dfgm.h:30
#define ZOPT_OUT
Definition: main.c:37
real_t eps_ds
Definition: qp_structs.h:31
real_t * H
Definition: qp_structs.h:16
#define RHO_AT_B_IN
Definition: main.c:34
real_t * lambda1_old
Definition: dfgm.h:42
real_t fopt
Definition: qp_structs.h:66
uint32_t iterations
Definition: qp_structs.h:51
struct Options * opt
Definition: dgm.h:23
#define LAMBDA2_OUT
Definition: main.c:42
#define EXITFLAG_INNER
real_t * A
Definition: qp_structs.h:18
real_t * z
Definition: alm.h:29
struct Options * opt
Definition: alm.h:24
struct Options * opt
Definition: falm.h:23
struct Info * info
Definition: falm.h:24
real_t * summ
Definition: dfgm.h:37
real_t * ub
Definition: qp_structs.h:24
struct Options * opt
Definition: dfgm.h:23
uint32_t maxiter_outer
Definition: qp_structs.h:29
uint32_t ALGORITHM
Definition: head.h:35
real_t * H_hat
Definition: alm.h:40
real_t * z
Definition: falm.h:28
struct Result * res
Definition: falm.h:25
struct Problem * prob
Definition: dfgm.h:22
real_t * b_lb_hat
Definition: dgm.h:35
real_t * y2
Definition: dfgm.h:46
real_t * pf_vec
Definition: dgm.h:38
#define NAME_LENGT
struct Problem * prob
Definition: dgm.h:22
real_t * lambda1
Definition: dfgm.h:29
real_t * temp1_dim_N
Definition: dfgm.h:31
real_t * A2
Definition: alm.h:41
uint32_t niter_feasible_pf
Definition: qp_structs.h:57
void mtx_transpose(const real_t *mtx, real_t *mtx_t, const uint32_t rows, const uint32_t cols)
real_t * lambda1
Definition: qp_structs.h:68
uint32_t M
Definition: head.h:34
int32_t DGM(struct Struct_DGM *s)
Definition: dgm.c:20
#define ITERATION
real_t * lambda
Definition: alm.h:30
uint32_t num_exceeded_max_niter_inner
Definition: qp_structs.h:59
#define H_HAT_IN
Definition: main.c:32
struct Info * info
Definition: dfgm.h:24
real_t * z_avg
Definition: falm.h:34
real_t * lambda1
Definition: dgm.h:29
real_t * temp2_dim_M
Definition: dfgm.h:32
real_t * temp3_dim_M
Definition: alm.h:33
real_t * rho_At_b
Definition: alm.h:42
#define LB_IN
Definition: main.c:25
#define LAMBDA1_OUT
Definition: main.c:41
real_t eps_inner
Definition: qp_structs.h:33
#define A_IN
Definition: main.c:21
float64_t real_t
Definition: typedefs.h:25
uint32_t exitflag_inner
Definition: qp_structs.h:58
boolean lb_is_inf
Definition: qp_structs.h:39
real_t * temp2_dim_M
Definition: dgm.h:32
real_t * y1
Definition: dfgm.h:44
#define NITER_FEASIBLE_PF
#define PF_VECTOR
struct Problem * prob
Definition: alm.h:23
struct Problem * prob
Definition: falm.h:22
#define FALSE
Definition: head.h:30
real_t * summ
Definition: dgm.h:37
Definition: dgm.h:20
real_t * z_avg
Definition: dfgm.h:36
#define FOPT_OUT
Definition: main.c:38
boolean lb_hat_is_inf
Definition: qp_structs.h:41
#define _SDEBUG(fmt)
Definition: head.h:60
#define TIME_TOT_INNER
real_t * temp1_dim_N
Definition: falm.h:31
real_t * temp1_dim_N
Definition: alm.h:31
#define EXITFLAG_OUT
Definition: main.c:39
uint32_t maxiter_inner
Definition: qp_structs.h:30
real_t * A_z_ds
Definition: dfgm.h:47
real_t * rho_At_b
Definition: falm.h:51
real_t * z_ds
Definition: dfgm.h:45
real_t rho
Definition: qp_structs.h:35
real_t * z0
Definition: qp_structs.h:25
int32_t FALM(struct Struct_FALM *s)
Definition: falm.c:20
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Definition: main.c:74
real_t * z_ds
Definition: falm.h:42
#define NUM_EXCEEDED_MAX_NITER_INNER
real_t * ub_hat
Definition: qp_structs.h:22
#define ITERATION_INNER_TOT
real_t eigH_min
Definition: qp_structs.h:44
real_t * H_hat
Definition: falm.h:49
uint32_t problem_case
Definition: qp_structs.h:46
real_t * y1
Definition: falm.h:41
#define ERROR(fmt)
Definition: head.h:54
real_t * pf_vec
Definition: dfgm.h:38
struct Info * info
Definition: dgm.h:24
#define LB_HAT_IN
Definition: main.c:23
real_t * pf_vector
Definition: qp_structs.h:61
real_t eps_pf
Definition: qp_structs.h:32
real_t eigH_max
Definition: qp_structs.h:43
#define OUTPUT_STRUCT_OUT
Definition: main.c:40
uint32_t niter_feasible_ds
Definition: qp_structs.h:56
#define UB_IN
Definition: main.c:26
#define TIME
#define UB_HAT_IN
Definition: main.c:24
real_t * lb_hat
Definition: qp_structs.h:21
real_t * lambda2_old
Definition: dfgm.h:43
#define H_IN
Definition: main.c:19
int32_t ALM(struct Struct_ALM *s)
Definition: alm.c:20
#define DS_VECTOR
real_t * b
Definition: qp_structs.h:20
uint32_t N
Definition: head.h:33
real_t * c
Definition: qp_structs.h:17