Skip to content

Commit

Permalink
Fix after VLA commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Oct 26, 2023
1 parent 0f93202 commit fe95efd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions c/examples/cobyla/cobyla_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <math.h>
#include <stdint.h>

#define m_nlcon 1
#define M_NLCON 1

static void fun(const double x[], double *f, double constr[], const void *data)
{
Expand All @@ -31,7 +31,7 @@ int main(int argc, char * argv[])
options.iprint = PRIMA_MSG_EXIT;
options.rhoend= 1e-3;
options.maxfun = 200*n;
problem.m_nlcon = m_nlcon;
problem.m_nlcon = M_NLCON;
// x1<=4, x2<=3, x1+x2<=10
problem.m_ineq = 3;
double Aineq[3*2] = {1.0, 0.0,
Expand Down
4 changes: 2 additions & 2 deletions c/tests/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <stdlib.h>
#include <string.h>

#define M_NLCON 1
const int n = 2;
#define m_nlcon 1
int debug = 0;
static int int_data = 0xff;
void * data_ref = &int_data;
Expand Down Expand Up @@ -98,7 +98,7 @@ int main(int argc, char * argv[])
}
else if(strcmp(algo, "cobyla") == 0)
{
problem.m_nlcon = m_nlcon;
problem.m_nlcon = M_NLCON;
rc = prima_cobyla(&problem, &options, &result);
}
else if(strcmp(algo, "lincoa") == 0)
Expand Down
31 changes: 16 additions & 15 deletions c/tests/stress.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

#define MIN(x, y) (((x) < (y)) ? (x) : (y))

#define n_max 2000
#define N_MAX 2000
#define M_INEQ_MAX 1000
#define M_NLCON 200

int n = 0;
#define m_ineq_max 1000
int m_ineq = 0;
#define m_nlcon 200
const double alpha = 4.0;
int debug = 0;

Expand Down Expand Up @@ -45,7 +46,7 @@ static void fun_con(const double x[], double *f, double constr[], const void *da
for (int i = 0; i < n-1; ++ i)
*f += (x[i] - 1.0) * (x[i] - 1.0) + alpha * (x[i+1] - x[i]*x[i]) * (x[i+1] - x[i]*x[i]);
// x_{i+1} <= x_i^2
for (int i = 0; i < MIN(m_nlcon, n-1); ++ i)
for (int i = 0; i < MIN(M_NLCON, n-1); ++ i)
constr[i] = x[i+1] - x[i] * x[i];

static int count = 0;
Expand Down Expand Up @@ -79,31 +80,31 @@ int main(int argc, char * argv[])
printf("seed=%d\n", seed);
srand(seed);

double x0[n_max];
double xl[n_max];
double xu[n_max];
double x0[N_MAX];
double xl[N_MAX];
double xu[N_MAX];
prima_problem problem;
prima_init_problem(&problem, n_max);
prima_init_problem(&problem, N_MAX);
problem.x0 = x0;
problem.calcfc = &fun_con;
problem.calfun = &fun;
prima_options options;
prima_init_options(&options);
options.iprint = PRIMA_MSG_RHO;
options.maxfun = 500*n_max;
double *Aineq = malloc(n_max*m_ineq_max*sizeof(double));
double bineq[m_ineq_max];
options.maxfun = 500*N_MAX;
double *Aineq = malloc(N_MAX*M_INEQ_MAX*sizeof(double));
double bineq[M_INEQ_MAX];
problem.Aineq = Aineq;
problem.bineq = bineq;
problem.xl = xl;
problem.xu = xu;
for (int j = 0; j < m_ineq_max; ++ j)
for (int j = 0; j < M_INEQ_MAX; ++ j)
bineq[j] = random_gen(-1.0, 1.0);

for (int i = 0; i < n_max; ++ i)
for (int i = 0; i < N_MAX; ++ i)
{
for (int j = 0; j < m_ineq; ++ j)
Aineq[j*n_max+i] = random_gen(-1.0, 1.0);
Aineq[j*N_MAX+i] = random_gen(-1.0, 1.0);
x0[i] = random_gen(-1.0, 1.0);
xl[i] = -1.0;
xu[i] = 1.0;
Expand All @@ -117,7 +118,7 @@ int main(int argc, char * argv[])
else if(strcmp(algo, "cobyla") == 0)
{
problem.n = 800;
problem.m_nlcon = m_nlcon;
problem.m_nlcon = M_NLCON;
problem.m_ineq = 600;
rc = prima_cobyla(&problem, &options, &result);
}
Expand Down

0 comments on commit fe95efd

Please sign in to comment.