TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcnlopt
rndpoint.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <math.h>
10
#include <time.h>
11
#include <string.h>
12
/*****************************************************************************/
13
#include "
tpcextensions.h
"
14
#include "
tpcrand.h
"
15
/*****************************************************************************/
16
#include "
tpcnlopt.h
"
17
/*****************************************************************************/
18
19
/*****************************************************************************/
28
int
nloptRandomPoint
(
30
double
*p,
32
double
*low,
34
double
*up,
36
unsigned
int
n,
40
MERTWI
*mt
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
}
59
/*****************************************************************************/
60
61
/*****************************************************************************/
70
int
nloptGaussianPoint
(
72
double
*p,
74
double
*mean,
76
double
*sd,
79
double
*low,
82
double
*up,
84
unsigned
int
n,
88
MERTWI
*mt
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
}
102
/*****************************************************************************/
103
104
/*****************************************************************************/
drand
double drand()
Definition
gaussdev.c:66
drandGaussian
double drandGaussian()
Get pseudo-random number with normal (Gaussian) distribution with mean 0 and SD 1.
Definition
gaussdev.c:144
mertwiRandomDouble1
double mertwiRandomDouble1(MERTWI *mt)
Generate a 64-bit double precision floating point pseudo-random number in the range of [0,...
Definition
mertwi.c:216
mertwiRandomGaussian
double mertwiRandomGaussian(MERTWI *mt)
Generate a 64-bit double precision floating point pseudo-random number with normal (Gaussian) distrib...
Definition
mertwi.c:354
nloptRandomPoint
int nloptRandomPoint(double *p, double *low, double *up, unsigned int n, MERTWI *mt)
Definition
rndpoint.c:28
nloptGaussianPoint
int nloptGaussianPoint(double *p, double *mean, double *sd, double *low, double *up, unsigned int n, MERTWI *mt)
Definition
rndpoint.c:70
MERTWI
Definition
tpcrand.h:32
tpcextensions.h
Header file for library libtpcextensions.
tpcnlopt.h
Header file for library libtpcnlopt.
tpcrand.h
Header file for libtpcrand.
Generated on
for TPCCLIB by
1.17.0