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
2bab1201
Commit
2bab1201
authored
Apr 04, 2020
by
Lambert Patrick
Browse files
move static method do BinomialForSuperIndividualGen
parent
9ee28bfa
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/miscellaneous/BinomialForSuperIndividualGen.java
View file @
2bab1201
...
...
@@ -19,6 +19,7 @@
*/
package
miscellaneous
;
import
fr.cemagref.simaqualife.pilot.Pilot
;
import
umontreal.iro.lecuyer.randvar.NormalACRGen
;
import
umontreal.iro.lecuyer.randvar.NormalGen
;
import
umontreal.iro.lecuyer.randvar.UniformGen
;
...
...
@@ -107,12 +108,44 @@ public class BinomialForSuperIndividualGen {
if
(
3
.
*
standardDeviation
<
1
.)
return
constantDraw
(
mean
);
else
{
else
return
normalDraw
(
draws
,
mean
,
standardDeviation
);
}
}
else
{
return
binomialDraw
(
draws
,
succesProbability
);
}
}
public
static
long
getSuccessNumber
(
Pilot
pilot
,
long
amount
,
double
succesProba
,
long
threshold
)
{
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);*/
double
amountWithSuccess
=
-
1
;
while
(
amountWithSuccess
<
0
|
amountWithSuccess
>
amount
)
{
amountWithSuccess
=
Math
.
round
(
NormalGen
.
nextDouble
(
pilot
.
getRandomStream
(),
0
.,
1
.)
*
Math
.
sqrt
(
succesProba
*
(
1
-
succesProba
)
*
amount
)
+
succesProba
*
amount
);
}
return
(
long
)
amountWithSuccess
;
}
else
{
UniformGen
aleaGen
=
new
UniformGen
(
pilot
.
getRandomStream
(),
0
.,
1
.);
long
amountWithSuccess
=
0L
;
for
(
long
i
=
0
;
i
<
amount
;
i
++)
{
if
(
aleaGen
.
nextDouble
()
<
succesProba
)
{
amountWithSuccess
++;
}
}
return
amountWithSuccess
;
}
}
public
static
long
getSuccessNumber
(
Pilot
pilot
,
long
amount
,
double
succesProba
)
{
return
getSuccessNumber
(
pilot
,
amount
,
succesProba
,
50
);
}
}
src/main/java/miscellaneous/Miscellaneous.java
View file @
2bab1201
...
...
@@ -6,37 +6,6 @@ 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
);
}
}
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
;
}
public
static
long
binomialForSuperIndividual
(
Pilot
pilot
,
long
amount
,
double
succesProba
)
{
return
binomialForSuperIndividual
(
pilot
,
amount
,
succesProba
,
50
);
}
static
public
double
temperatureEffect
(
double
T
,
double
Tmin
,
double
Topt
,
double
Tmax
)
{
if
(
T
<=
Tmin
||
T
>=
Tmax
)
{
return
0
;
...
...
src/main/java/species/DisperseAndMigrateToRiver.java
View file @
2bab1201
...
...
@@ -11,6 +11,7 @@ import environment.RiverBasin;
import
environment.Time
;
import
environment.Time.Season
;
import
fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess
;
import
miscellaneous.BinomialForSuperIndividualGen
;
import
miscellaneous.Miscellaneous
;
import
org.openide.util.lookup.ServiceProvider
;
...
...
@@ -50,7 +51,7 @@ public class DisperseAndMigrateToRiver extends DisperseAndMigrateToRiverBasic {
if
(
fish
.
isMature
())
{
// fish with homing
amountWithHoming
=
Miscellaneous
.
b
inomialForSuperIndividual
(
group
.
getPilot
(),
fish
.
getAmount
(),
pHoming
);
// seuil par d�faut fix� � 50
amountWithHoming
=
B
inomialForSuperIndividual
Gen
.
getSuccessNumber
(
group
.
getPilot
(),
fish
.
getAmount
(),
pHoming
);
// seuil par d�faut fix� � 50
// strayed fish
strayedAmount
=
fish
.
getAmount
()
-
amountWithHoming
;
...
...
@@ -93,7 +94,7 @@ public class DisperseAndMigrateToRiver extends DisperseAndMigrateToRiverBasic {
// compute sequentially the prob to go into a basin
for
(
Basin
accBasin
:
accBasOfFish
.
keySet
()){
probToGo
=
accBasOfFish
.
get
(
accBasin
)
/
totalWeight
;
amountToGo
=
Miscellaneous
.
b
inomialForSuperIndividual
(
group
.
getPilot
(),
strayedAmount
,
probToGo
);
amountToGo
=
B
inomialForSuperIndividual
Gen
.
getSuccessNumber
(
group
.
getPilot
(),
strayedAmount
,
probToGo
);
if
(
amountToGo
>
0
){
newFish
.
add
(
fish
.
duplicateWithNewPositionAndAmount
(
group
.
getPilot
(),
bn
.
getAssociatedRiverBasin
(
accBasin
),
amountToGo
));
...
...
src/main/java/species/DisperseAndMigrateToRiverStandardization.java
View file @
2bab1201
...
...
@@ -16,7 +16,7 @@ import environment.Time.Season;
import
fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess
;
import
fr.cemagref.simaqualife.kernel.util.TransientParameters.InitTransientParameters
;
import
fr.cemagref.simaqualife.pilot.Pilot
;
import
miscellaneous.BinomialForSuperIndividualGen
;
import
miscellaneous.Miscellaneous
;
import
org.openide.util.lookup.ServiceProvider
;
...
...
@@ -140,7 +140,7 @@ public class DisperseAndMigrateToRiverStandardization extends AquaNismsGroupProc
if
(
fish
.
isMature
())
{
// fish with homing
homingAmount
=
Miscellaneous
.
b
inomialForSuperIndividual
(
group
.
getPilot
(),
fish
.
getAmount
(),
pHoming
);
// seuil par d�faut fix� � 50
homingAmount
=
B
inomialForSuperIndividual
Gen
.
getSuccessNumber
(
group
.
getPilot
(),
fish
.
getAmount
(),
pHoming
);
// seuil par d�faut fix� � 50
// strayed fish
strayedAmount
=
fish
.
getAmount
()
-
homingAmount
;
...
...
@@ -177,7 +177,7 @@ public class DisperseAndMigrateToRiverStandardization extends AquaNismsGroupProc
// compute sequentially the prob to go into a basin
for
(
RiverBasin
destination
:
wForAccessibleBasins
.
keySet
()){
probToGo
=
wForAccessibleBasins
.
get
(
destination
)
/
totalWeight
;
amountToGo
=
Miscellaneous
.
b
inomialForSuperIndividual
(
group
.
getPilot
(),
strayedAmount
,
probToGo
);
amountToGo
=
B
inomialForSuperIndividual
Gen
.
getSuccessNumber
(
group
.
getPilot
(),
strayedAmount
,
probToGo
);
if
(
amountToGo
>
0
){
// add a "duplicated" fish in the destination basin
...
...
src/main/java/species/ReproduceAndSurviveAfterReproduction.java
View file @
2bab1201
...
...
@@ -8,6 +8,7 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.TreeMap
;
import
miscellaneous.BinomialForSuperIndividualGen
;
import
miscellaneous.Duo
;
import
miscellaneous.Miscellaneous
;
import
species.DiadromousFish.Gender
;
...
...
@@ -160,7 +161,7 @@ public class ReproduceAndSurviveAfterReproduction extends AquaNismsGroupProcess<
fish
.
incNumberOfReproduction
();
// survival after reproduction (semelparity or iteroparity) of SI (change the amount of the SI)
survivalAmount
=
Miscellaneous
.
b
inomialForSuperIndividual
(
group
.
getPilot
(),
fish
.
getAmount
(),
survivalRateAfterReproduction
);
survivalAmount
=
B
inomialForSuperIndividual
Gen
.
getSuccessNumber
(
group
.
getPilot
(),
fish
.
getAmount
(),
survivalRateAfterReproduction
);
if
(
survivalAmount
>
0
)
fish
.
setAmount
(
survivalAmount
);
...
...
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