TPCCLIB
Loading...
Searching...
No Matches
rndpoint.c File Reference

Random point for optimization routines. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpcextensions.h"
#include "tpcrand.h"
#include "tpcnlopt.h"

Go to the source code of this file.

Functions

int nloptRandomPoint (double *p, double *low, double *up, unsigned int n, MERTWI *mt)
int nloptGaussianPoint (double *p, double *mean, double *sd, double *low, double *up, unsigned int n, MERTWI *mt)

Detailed Description

Random point for optimization routines.

Definition in file rndpoint.c.

Function Documentation

◆ nloptGaussianPoint()

int nloptGaussianPoint ( double * p,
double * mean,
double * sd,
double * low,
double * up,
unsigned int n,
MERTWI * mt )

Create random parameters with Gaussian distribution.

Precondition
Uses rand(), therefore set seed for a new series of pseudo-random numbers; to produce truly random numbers (not just pseudo-random), do srand(time(0)) before calling this function. If no seed is set, then value 1 is used as default seed by rand().
See also
drand, nloptRandomPoint, drandRange, drandGaussian, drandExponential, mertwiRandomGaussian
Author
Vesa Oikonen
Returns
Returns non-zero in case of an error.
Parameters
pPointer to parameter list to be filled, allocated for length n.
meanPointer to list of mean values for each parameter.
sdPointer to list of standard deviations for each parameter.
lowPointer to parameter lower limits; generated pseudo-random numbers falling below the lower limit will be set to the limit; NULL if not needed.
upPointer to parameter upper limits; generated pseudo-random numbers falling above the upper limit will be set to the limit; NULL if not needed.
nList length.
mtPointer to initiated and seeded Mersenne Twister MT19937 data structure; enter NULL to use drandGaussian() instead.
See also
mertwiInit, mertwiInitWithSeed64

Definition at line 70 of file rndpoint.c.

89 {
90 if(p==NULL || mean==NULL || sd==NULL) return(1);
91 if(n==0) return(0);
92
93 for(unsigned int i=0; i<n; i++) {
94 if(mt==NULL) p[i]=mean[i]+sd[i]*drandGaussian();
95 else p[i]=mean[i]+sd[i]*mertwiRandomGaussian(mt);
96 if(low!=NULL && p[i]<low[i]) p[i]=low[i];
97 if(up!=NULL && p[i]>up[i]) p[i]=up[i];
98 }
99
100 return(0);
101}
double drandGaussian()
Get pseudo-random number with normal (Gaussian) distribution with mean 0 and SD 1.
Definition gaussdev.c:144
double mertwiRandomGaussian(MERTWI *mt)
Generate a 64-bit double precision floating point pseudo-random number with normal (Gaussian) distrib...
Definition mertwi.c:354

Referenced by nloptIATGO(), nloptMPSO(), and nloptSimplexARRS().

◆ nloptRandomPoint()

int nloptRandomPoint ( double * p,
double * low,
double * up,
unsigned int n,
MERTWI * mt )

Create random parameters between specified limits.

Precondition
Uses rand(), therefore set seed for a new series of pseudo-random numbers; to produce truly random numbers (not just pseudo-random), do srand(time(0)) before calling this function. If no seed is set, then value 1 is used as default seed by rand().
See also
drand, drandRange, drandGaussian, drandExponential, mertwiRandomBetween
Author
Vesa Oikonen
Returns
Returns non-zero in case of an error.
Parameters
pPointer to parameter list to be filled.
lowPointer to parameter lower limits.
upPointer to parameter upper limits.
nList length.
mtPointer to initiated and seeded Mersenne Twister MT19937 data structure; enter NULL to use drand() instead.
See also
mertwiInit, mertwiInitWithSeed64

Definition at line 28 of file rndpoint.c.

41 {
42 if(p==NULL || low==NULL || up==NULL) return(1);
43 if(n==0) return(0);
44
45 if(mt==NULL) {
46 for(unsigned int i=0; i<n; i++) {
47 double dif=up[i]-low[i];
48 if(dif<=0.0) p[i]=low[i]; else p[i]=low[i]+drand()*dif;
49 }
50 } else {
51 for(unsigned int i=0; i<n; i++) {
52 double dif=up[i]-low[i];
53 if(dif<=0.0) p[i]=low[i]; else p[i]=low[i]+mertwiRandomDouble1(mt)*dif;
54 }
55 }
56
57 return(0);
58}
double drand()
Definition gaussdev.c:66
double mertwiRandomDouble1(MERTWI *mt)
Generate a 64-bit double precision floating point pseudo-random number in the range of [0,...
Definition mertwi.c:216

Referenced by nloptIATGO(), nloptITGO1(), nloptITGO2(), nloptMPSO(), and nloptSimplexARRS().