Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add primal_internal.h #194

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions c/include/prima/prima_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef PRIMA_INTERNAL_H
#define PRIMA_INTERNAL_H

#include "prima/prima.h"

unsigned int get_random_seed(void);

// Function to check whether the problem matches the algorithm
prima_rc_t prima_check_problem(const prima_problem_t problem, const prima_algorithm_t algorithm);

// Function to initialize the result
prima_rc_t prima_init_result(prima_result_t *const result, const prima_problem_t problem);

// Functions implemented in Fortran (*_c.f90)
int cobyla_c(const int m_nlcon, const prima_objcon_t calcfc, const void *data, const int n, double x[], double *const f, double *const cstrv, double nlconstr[],
const int m_ineq, const double Aineq[], const double bineq[],
const int m_eq, const double Aeq[], const double beq[],
const double xl[], const double xu[],
const double f0, const double nlconstr0[],
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, const double ctol,
const prima_callback_t callback, int *const info);

int bobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, const double xl[], const double xu[],
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const prima_callback_t callback, int *const info);

int newuoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f,
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const prima_callback_t callback, int *const info);

int uobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f,
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, const prima_callback_t callback, int *const info);

int lincoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f,
double *const cstrv, const int m_ineq, const double Aineq[], const double bineq[],
const int m_eq, const double Aeq[], const double beq[], const double xl[], const double xu[],
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const double ctol,
const prima_callback_t callback, int *const info);

#endif
28 changes: 1 addition & 27 deletions c/prima.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Dedicated to the late Professor M. J. D. Powell FRS (1936--2015).


#include "prima/prima.h"
#include "prima/prima_internal.h"
#include <limits.h>
#include <math.h>
#include <stdio.h>
Expand Down Expand Up @@ -203,32 +203,6 @@ const char *prima_get_rc_string(const prima_rc_t rc)
}
}


// Functions implemented in Fortran (*_c.f90)
int cobyla_c(const int m_nlcon, const prima_objcon_t calcfc, const void *data, const int n, double x[], double *const f, double *const cstrv, double nlconstr[],
const int m_ineq, const double Aineq[], const double bineq[],
const int m_eq, const double Aeq[], const double beq[],
const double xl[], const double xu[],
const double f0, const double nlconstr0[],
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, const double ctol,
const prima_callback_t callback, int *const info);

int bobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f, const double xl[], const double xu[],
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const prima_callback_t callback, int *const info);

int newuoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f,
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const prima_callback_t callback, int *const info);

int uobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f,
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, const prima_callback_t callback, int *const info);

int lincoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *const f,
double *const cstrv, const int m_ineq, const double Aineq[], const double bineq[],
const int m_eq, const double Aeq[], const double beq[], const double xl[], const double xu[],
int *const nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, const double ctol,
const prima_callback_t callback, int *const info);


// The function that does the minimization using a PRIMA solver
prima_rc_t prima_minimize(const prima_algorithm_t algorithm, const prima_problem_t problem, const prima_options_t options, prima_result_t *const result)
{
Expand Down
16 changes: 12 additions & 4 deletions c/tests/stress.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
#include <time.h>

// Make PRIMA available
#include "prima/prima.h"
#include "prima/prima_internal.h"

// Thread-safe version of localtime
#ifdef _WIN32
#define localtime_safe(a, b) localtime_s(a, b)
#else
#define localtime_safe(a, b) localtime_r(b, a)
#endif

#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define N_MAX 2000
Expand Down Expand Up @@ -65,8 +72,9 @@
// Set the random seed to year/week
char buf[10] = {0};
time_t t = time(NULL);
struct tm *tmp = localtime(&t);
int rc = strftime(buf, 10, "%y%W", tmp);
struct tm timeinfo;
Fixed Show fixed Hide fixed

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error test

timeinfo is not a recognized word. (unrecognized-spelling)
localtime_safe(&timeinfo, &t);
Fixed Show fixed Hide fixed

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error test

timeinfo is not a recognized word. (unrecognized-spelling)
int rc = strftime(buf, 10, "%y%W", &timeinfo);

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error test

timeinfo is not a recognized word. (unrecognized-spelling)
if (!rc)
return 42;
else
Expand All @@ -87,7 +95,7 @@
printf("Debug = %d\n", debug);

unsigned int seed = get_random_seed();
printf("Random seed = %d\n", seed);
printf("Random seed = %u\n", seed);
srand(seed);

// Set up the options
Expand Down
Loading