DuQuad  v1.0
Quadratic Programming Optimizations
 All Data Structures Files Functions Variables Typedefs Macros
gdm.c
Go to the documentation of this file.
1 #include "gdm.h"
2 
3 // This function is not maintained
4 
5 //static void gradientGD();
6 
8 {
9 
10  s->exitflag = 1;
11 
12  // z = z0
13  vector_copy(s->z0,s->z,N);
14 
15 
16  // Initialize the function value, and difference between the new and previous function value
17  real_t f = obj(s->z, s->H, s->c, s->temp1_dim_N);
18  real_t fnew = 0.0;
19  real_t f_diff = s->eps + 1;
20 
21  // Declaration and initialization of other necessary variables
22  real_t L = s->eigH_max;
23  // real_t mu = s->eigH_min;
24  real_t one_over_L = 1.0/L;
25 
26  // iteration counter
27  uint32_t niter = 0;
28 
29 
30  /* ##################################################################################
31  START WHILE-LOOP
32  ################################################################################## */
33  while(f_diff > s->eps)
34  {
35 
36  if (niter > s->maxiter){
37  //fprintf(stderr, "reached maximum number of iterations in FGM (inner problem)\n");
38  s->exitflag = 2;
39  break;
40  }
41 
42  // calculating gradient
43  //gradientGD(s->z,s->H,s->c,s->temp1_dim_N);
44  mtx_vec_mul(s->H,s->z,s->temp1_dim_N,N,N); // H * y
45  vector_add(s->c,s->temp1_dim_N,s->temp1_dim_N,N); // + c
46 
47 
48 
49  /* *********************************************************************
50  Finding znew
51  ********************************************************************* */
52 // for(i=0;i<N;i++){
53 // s->znew[i] = s->z[i] - (opt->alpha * s->temp1_dim_N[i]);
54 // }
55 
56  vector_scalar_mul(s->temp1_dim_N, one_over_L, s->temp1_dim_N, N); // 1/L * f'(y)
57  vector_sub(s->z, s->temp1_dim_N, s->znew, N); // y - ans
58 
59 
60 
61  // projection znew on the feasible set made of lb and ub
62  if(!s->ub_is_inf)
63  vector_min(s->ub,s->znew,s->znew,N);
64  if(!s->lb_is_inf)
65  vector_max(s->lb,s->znew,s->znew,N);
66 
67  /* *********************************************************************
68  Finding f_diff
69  ********************************************************************* */
70 
71  // calculate the difference between the new and previous function value
72  fnew = obj(s->znew, s->H, s->c, s->temp1_dim_N);
73  f_diff = abs_2(fnew - f);
74 
75  /* *********************************************************************
76  Update the variables
77  ********************************************************************* */
78 // for(i=0;i<N;i++)
79 // s->z[i] = s->znew[i];
80  vector_copy(s->znew,s->z,N);
81  f = fnew;
82  niter = niter+1;
83  }
84 
85  vector_copy(s->znew,s->zopt,N);
86  s->fopt = fnew;
87 
88  return niter;
89 }
90 
91 
92 // This function is not used by fgm or dfgm
93 void clean_up_GDM_C(struct Struct_GDM *s)
94 {
95  free_pointer(s->H);
96  free_pointer(s->c);
97  free_pointer(s->lb);
98  free_pointer(s->ub);
99  free_pointer(s->z0);
100  free_pointer(s->zopt);
101  free_pointer(s->z);
102  free_pointer(s->znew);
104 }
void vector_add(const real_t *v1, const real_t *v2, real_t *res, const uint32_t length)
void free_pointer(real_t *pointer)
real_t abs_2(const real_t a)
unsigned int uint32_t
Definition: typedefs.h:19
uint32_t GDM(struct Struct_GDM *s)
Definition: gdm.c:7
real_t * z0
Definition: gdm.h:21
real_t * temp1_dim_N
Definition: gdm.h:39
real_t obj(const real_t *z, const real_t *H, const real_t *c, real_t *temp)
void vector_min(const real_t *v1, const real_t *v2, real_t *res, const uint32_t length)
boolean lb_is_inf
Definition: gdm.h:29
uint32_t maxiter
Definition: gdm.h:42
real_t * ub
Definition: gdm.h:20
real_t eigH_max
Definition: gdm.h:31
real_t eps
Definition: gdm.h:43
real_t * H
Definition: gdm.h:17
real_t * zopt
Definition: gdm.h:24
real_t * znew
Definition: gdm.h:37
void vector_sub(const real_t *v1, const real_t *v2, real_t *res, const uint32_t length)
real_t * z
Definition: gdm.h:35
boolean ub_is_inf
Definition: gdm.h:30
void vector_copy(const real_t *v1, real_t *v2, const uint32_t length)
real_t * lb
Definition: gdm.h:19
float64_t real_t
Definition: typedefs.h:25
real_t fopt
Definition: gdm.h:25
uint32_t exitflag
Definition: gdm.h:26
Definition: gdm.h:15
real_t * c
Definition: gdm.h:18
void vector_scalar_mul(const real_t *v1, const real_t scalar, real_t *res, const uint32_t length)
void mtx_vec_mul(const real_t *mtx, const real_t *v, real_t *res, const uint32_t rows, const uint32_t cols)
void vector_max(const real_t *v1, const real_t *v2, real_t *res, const uint32_t length)
void clean_up_GDM_C(struct Struct_GDM *s)
Definition: gdm.c:93
uint32_t N
Definition: head.h:33