Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
SimAquaLife
GR3D
Commits
59532e56
Commit
59532e56
authored
Apr 01, 2020
by
Lambert Patrick
Browse files
with an instance of UniformGen
parent
1e052862
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/miscellaneous/Miscellaneous.java
View file @
59532e56
...
...
@@ -7,31 +7,32 @@ import umontreal.iro.lecuyer.randvar.UniformGen;
public
class
Miscellaneous
{
public
static
long
binomialForSuperIndividual
(
Pilot
pilot
,
long
amount
,
double
succesProba
,
long
threshold
)
{
long
amountWithSuccess
;
if
(
amount
>
threshold
)
{
// use a normal approximation for huge amount
/* double p=-1.;
while (p<0 | p>1){
p = genAleaNormal.nextDouble() *
Math.sqrt(succesProba * (1 - succesProba) /amount) + succesProba;
}
amountWithSuccess = (long) Math.round(p* amount);*/
amountWithSuccess
=
-
1
;
while
(
amountWithSuccess
<
0
|
amountWithSuccess
>
amount
)
{
amountWithSuccess
=
Math
.
round
(
NormalGen
.
nextDouble
(
pilot
.
getRandomStream
(),
0
.,
1
.)
*
Math
.
sqrt
(
succesProba
*
(
1
-
succesProba
)
*
amount
)
+
succesProba
*
amount
);
}
long
amountWithSuccess
;
if
(
amount
>
threshold
)
{
// use a normal approximation for huge amount
/* double p=-1.;
while (p<0 | p>1){
p = genAleaNormal.nextDouble() *
Math.sqrt(succesProba * (1 - succesProba) /amount) + succesProba;
}
amountWithSuccess = (long) Math.round(p* amount);*/
amountWithSuccess
=
-
1
;
while
(
amountWithSuccess
<
0
|
amountWithSuccess
>
amount
)
{
amountWithSuccess
=
Math
.
round
(
NormalGen
.
nextDouble
(
pilot
.
getRandomStream
(),
0
.,
1
.)
*
Math
.
sqrt
(
succesProba
*
(
1
-
succesProba
)
*
amount
)
+
succesProba
*
amount
);
}
}
else
{
UniformGen
aleaGen
=
new
UniformGen
(
pilot
.
getRandomStream
(),
0
.,
1
.);
amountWithSuccess
=
0
;
for
(
long
i
=
0
;
i
<
amount
;
i
++)
{
if
(
aleaGen
.
nextDouble
()
<
succesProba
)
{
amountWithSuccess
++;
}
}
else
{
UniformGen
aleaGen
=
new
UniformGen
(
pilot
.
getRandomStream
(),
0
.,
1
.);
amountWithSuccess
=
0
;
for
(
long
i
=
0
;
i
<
amount
;
i
++)
{
if
(
aleaGen
.
nextDouble
()
<
succesProba
)
{
amountWithSuccess
++;
}
}
return
amountWithSuccess
;
}
return
amountWithSuccess
;
}
public
static
long
binomialForSuperIndividual
(
Pilot
pilot
,
long
amount
,
double
succesProba
)
{
return
binomialForSuperIndividual
(
pilot
,
amount
,
succesProba
,
50
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment