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
3378aefe
Commit
3378aefe
authored
Mar 30, 2020
by
Lambert Patrick
Browse files
with Time as a field of BasinNetwork
to avoid multiplication of Time instances
parent
e07d6cb4
Changes
37
Hide whitespace changes
Inline
Side-by-side
src/main/java/environment/Basin.java
View file @
3378aefe
...
...
@@ -14,237 +14,238 @@ import species.DiadromousFishGroup;
public
class
Basin
implements
Position
,
Comparable
<
Basin
>
{
@Override
public
int
compareTo
(
Basin
t
)
{
return
id
-
t
.
id
;
}
public
static
enum
TypeBassin
{
RIVER
,
SEA
,
OFFSHORE
};
/**
* Identifier of basin in GR3D
* if n is the number of basin, id from 0 to n-1 correspond to riverBasin, from n to 2n-1 to seaBasin
* and the next to offshore basins.
* with modulo operation it is possible to find to which riverBasin a seaBassin corresponds to
* @unit -
*/
private
final
int
id
;
/**
* the name of the catchement
* @unit -
*/
private
final
String
name
;
/**
* the type of the basin
* @unit -
*/
protected
TypeBassin
type
;
/**
* the mean temperature during the current winter
* @unit °C
*/
private
double
winterTemperature
;
/**
* the mean temperature during the current spring
* @unit °C
*/
private
double
springTemperature
;
/**
* the mean temperature during the current summer
* @unit °C
*/
private
double
summerTemperature
;
/**
* the mean temperature during the current winter
* @unit °C
*/
private
double
fallTemperature
;
//private double latitude;
// private double longitude;
@Override
public
int
compareTo
(
Basin
t
)
{
return
id
-
t
.
id
;
}
public
static
enum
TypeBassin
{
RIVER
,
SEA
,
OFFSHORE
};
/**
* Identifier of basin in GR3D
* if n is the number of basin, id from 0 to n-1 correspond to riverBasin, from n to 2n-1 to seaBasin
* and the next to offshore basins.
* with modulo operation it is possible to find to which riverBasin a seaBassin corresponds to
* @unit -
*/
private
final
int
id
;
/**
* the name of the catchement
* @unit -
*/
private
final
String
name
;
/**
* the type of the basin
* @unit -
*/
protected
TypeBassin
type
;
/**
* the mean temperature during the current winter
* @unit °C
*/
private
double
winterTemperature
;
/**
* the mean temperature during the current spring
* @unit °C
*/
private
double
springTemperature
;
/**
* the mean temperature during the current summer
* @unit °C
*/
private
double
summerTemperature
;
/**
* the mean temperature during the current winter
* @unit °C
*/
private
double
fallTemperature
;
//private double latitude;
// private double longitude;
//private double alphaBH; // Correspond to the carrying capacity
//private double betaBH; // Correspond to level of genitors to produce alpha/2 recruits
//private double depensatoryBH = 1.; // If d=1, no depensatory dynamics; if d>1 Allee effect
/**
* the basin shape to be drawn
* @unit
*/
private
final
Path2D
.
Double
shape
;
/**
* distance to other catchments in the universe (from the same type ?)
* @unit km
*/
private
Map
<
Basin
,
Double
>
neighboursDistances
;
/**
* list of diadromous fish present in the basin for each group
* @unit
*/
private
Map
<
DiadromousFishGroup
,
List
<
DiadromousFish
>>
fishPerGroup
;
/**
* effective of fish present in the basin for each group
* @unit
*/
private
Map
<
DiadromousFishGroup
,
Long
>
effectivePerGroup
;
public
Basin
(
int
id
,
String
name
,
double
winterTemperature
,
double
springTemperature
,
double
summerTemperature
,
double
fallTemperature
)
{
this
.
id
=
id
;
this
.
name
=
name
;
this
.
winterTemperature
=
winterTemperature
;
this
.
springTemperature
=
springTemperature
;
this
.
summerTemperature
=
summerTemperature
;
this
.
fallTemperature
=
fallTemperature
;
this
.
shape
=
new
Path2D
.
Double
();
fishPerGroup
=
new
TreeMap
<
DiadromousFishGroup
,
List
<
DiadromousFish
>>();
effectivePerGroup
=
new
TreeMap
<
DiadromousFishGroup
,
Long
>();
neighboursDistances
=
new
TreeMap
<
Basin
,
Double
>();
}
public
TypeBassin
getType
()
{
return
type
;
}
public
Map
<
Basin
,
Double
>
getNeighboursDistances
()
{
return
neighboursDistances
;
}
public
void
setNeighboursDistances
(
Map
<
Basin
,
Double
>
neighboursDistances
)
{
this
.
neighboursDistances
=
neighboursDistances
;
}
public
Set
<
DiadromousFishGroup
>
getGroups
()
{
return
fishPerGroup
.
keySet
();
}
public
List
<
DiadromousFish
>
getFishs
(
DiadromousFishGroup
group
)
{
return
fishPerGroup
.
get
(
group
);
}
public
void
updateEffective
()
{
for
(
DiadromousFishGroup
group
:
fishPerGroup
.
keySet
())
{
long
eff
=
0
;
for
(
DiadromousFish
fish
:
fishPerGroup
.
get
(
group
))
{
eff
+=
fish
.
getAmount
();
}
effectivePerGroup
.
put
(
group
,
eff
);
}
}
public
Map
<
DiadromousFishGroup
,
List
<
DiadromousFish
>>
getFishPerGroup
()
{
return
fishPerGroup
;
}
public
long
getEffective
(
DiadromousFishGroup
group
)
{
long
eff
=
0
;
if
(
fishPerGroup
.
containsKey
(
group
))
{
for
(
DiadromousFish
fish
:
fishPerGroup
.
get
(
group
))
{
eff
+=
fish
.
getAmount
();
}
}
return
eff
;
}
public
int
getSuperFishNumber
(
DiadromousFishGroup
group
)
{
int
nb
=
0
;
if
(
fishPerGroup
.
containsKey
(
group
))
{
nb
=
fishPerGroup
.
get
(
group
).
size
();
}
return
nb
;
}
public
boolean
addFish
(
DiadromousFish
fish
,
DiadromousFishGroup
group
)
{
if
(!
fishPerGroup
.
containsKey
(
group
))
{
fishPerGroup
.
put
(
group
,
new
ArrayList
<
DiadromousFish
>());
}
return
(
fishPerGroup
.
get
(
group
)).
add
(
fish
);
}
public
boolean
removeFish
(
DiadromousFish
fish
,
DiadromousFishGroup
group
)
{
return
(
fishPerGroup
.
get
(
group
)).
remove
(
fish
);
}
public
double
getAnnualTemperature
()
{
return
((
winterTemperature
+
springTemperature
+
summerTemperature
+
fallTemperature
)
/
4
.);
}
public
double
getCurrentTemperature
(
Pilot
pilot
)
{
if
(
Time
.
getSeason
(
pilot
)
==
Season
.
WINTER
)
{
return
(
winterTemperature
);
}
else
if
(
Time
.
getSeason
(
pilot
)
==
Season
.
SPRING
)
{
return
(
springTemperature
);
}
else
if
(
Time
.
getSeason
(
pilot
)
==
Season
.
SUMMER
)
{
return
(
summerTemperature
);
}
else
{
return
(
fallTemperature
);
}
}
public
Path2D
.
Double
getShape
()
{
return
shape
;
}
/* public void setShape(Path2D.Double shape) {
//private double betaBH; // Correspond to level of genitors to produce alpha/2 recruits
//private double depensatoryBH = 1.; // If d=1, no depensatory dynamics; if d>1 Allee effect
/**
* the basin shape to be drawn
* @unit
*/
private
final
Path2D
.
Double
shape
;
/**
* distance to other catchments in the universe (from the same type ?)
* @unit km
*/
private
Map
<
Basin
,
Double
>
neighboursDistances
;
/**
* list of diadromous fish present in the basin for each group
* @unit
*/
private
Map
<
DiadromousFishGroup
,
List
<
DiadromousFish
>>
fishPerGroup
;
/**
* effective of fish present in the basin for each group
* @unit
*/
private
Map
<
DiadromousFishGroup
,
Long
>
effectivePerGroup
;
public
Basin
(
int
id
,
String
name
,
double
winterTemperature
,
double
springTemperature
,
double
summerTemperature
,
double
fallTemperature
)
{
this
.
id
=
id
;
this
.
name
=
name
;
this
.
winterTemperature
=
winterTemperature
;
this
.
springTemperature
=
springTemperature
;
this
.
summerTemperature
=
summerTemperature
;
this
.
fallTemperature
=
fallTemperature
;
this
.
shape
=
new
Path2D
.
Double
();
fishPerGroup
=
new
TreeMap
<
DiadromousFishGroup
,
List
<
DiadromousFish
>>();
effectivePerGroup
=
new
TreeMap
<
DiadromousFishGroup
,
Long
>();
neighboursDistances
=
new
TreeMap
<
Basin
,
Double
>();
}
public
TypeBassin
getType
()
{
return
type
;
}
public
Map
<
Basin
,
Double
>
getNeighboursDistances
()
{
return
neighboursDistances
;
}
public
void
setNeighboursDistances
(
Map
<
Basin
,
Double
>
neighboursDistances
)
{
this
.
neighboursDistances
=
neighboursDistances
;
}
public
Set
<
DiadromousFishGroup
>
getGroups
()
{
return
fishPerGroup
.
keySet
();
}
public
List
<
DiadromousFish
>
getFishs
(
DiadromousFishGroup
group
)
{
return
fishPerGroup
.
get
(
group
);
}
public
void
updateEffective
()
{
for
(
DiadromousFishGroup
group
:
fishPerGroup
.
keySet
())
{
long
eff
=
0
;
for
(
DiadromousFish
fish
:
fishPerGroup
.
get
(
group
))
{
eff
+=
fish
.
getAmount
();
}
effectivePerGroup
.
put
(
group
,
eff
);
}
}
public
Map
<
DiadromousFishGroup
,
List
<
DiadromousFish
>>
getFishPerGroup
()
{
return
fishPerGroup
;
}
public
long
getEffective
(
DiadromousFishGroup
group
)
{
long
eff
=
0
;
if
(
fishPerGroup
.
containsKey
(
group
))
{
for
(
DiadromousFish
fish
:
fishPerGroup
.
get
(
group
))
{
eff
+=
fish
.
getAmount
();
}
}
return
eff
;
}
public
int
getSuperFishNumber
(
DiadromousFishGroup
group
)
{
int
nb
=
0
;
if
(
fishPerGroup
.
containsKey
(
group
))
{
nb
=
fishPerGroup
.
get
(
group
).
size
();
}
return
nb
;
}
public
boolean
addFish
(
DiadromousFish
fish
,
DiadromousFishGroup
group
)
{
if
(!
fishPerGroup
.
containsKey
(
group
))
{
fishPerGroup
.
put
(
group
,
new
ArrayList
<
DiadromousFish
>());
}
return
(
fishPerGroup
.
get
(
group
)).
add
(
fish
);
}
public
boolean
removeFish
(
DiadromousFish
fish
,
DiadromousFishGroup
group
)
{
return
(
fishPerGroup
.
get
(
group
)).
remove
(
fish
);
}
public
double
getAnnualTemperature
()
{
return
((
winterTemperature
+
springTemperature
+
summerTemperature
+
fallTemperature
)
/
4
.);
}
public
double
getCurrentTemperature
(
Pilot
pilot
)
{
Time
time
=(
(
BasinNetwork
)
pilot
.
getAquaticWorld
().
getEnvironment
()).
getTime
();
if
(
time
.
getSeason
(
pilot
)
==
Season
.
WINTER
)
{
return
(
winterTemperature
);
}
else
if
(
time
.
getSeason
(
pilot
)
==
Season
.
SPRING
)
{
return
(
springTemperature
);
}
else
if
(
time
.
getSeason
(
pilot
)
==
Season
.
SUMMER
)
{
return
(
summerTemperature
);
}
else
{
return
(
fallTemperature
);
}
}
public
Path2D
.
Double
getShape
()
{
return
shape
;
}
/* public void setShape(Path2D.Double shape) {
this.shape = shape;
}*/
public
String
getName
()
{
return
name
;
}
public
String
getName
()
{
return
name
;
}
public
int
getId
()
{
return
id
;
}
public
int
getId
()
{
return
id
;
}
public
double
getWinterTemperature
()
{
return
winterTemperature
;
}
public
double
getWinterTemperature
()
{
return
winterTemperature
;
}
public
double
getSpringTemperature
()
{
return
springTemperature
;
}
public
double
getSpringTemperature
()
{
return
springTemperature
;
}
public
double
getSummerTemperature
()
{
return
summerTemperature
;
}
public
double
getSummerTemperature
()
{
return
summerTemperature
;
}
public
double
getFallTemperature
()
{
return
fallTemperature
;
}
public
double
getFallTemperature
()
{
return
fallTemperature
;
}
public
void
setWinterTemperature
(
double
winterTemperature
)
{
this
.
winterTemperature
=
winterTemperature
;
}
public
void
setWinterTemperature
(
double
winterTemperature
)
{
this
.
winterTemperature
=
winterTemperature
;
}
public
void
setSpringTemperature
(
double
springTemperature
)
{
this
.
springTemperature
=
springTemperature
;
}
public
void
setSpringTemperature
(
double
springTemperature
)
{
this
.
springTemperature
=
springTemperature
;
}
public
void
setSummerTemperature
(
double
summerTemperature
)
{
this
.
summerTemperature
=
summerTemperature
;
}
public
void
setSummerTemperature
(
double
summerTemperature
)
{
this
.
summerTemperature
=
summerTemperature
;
}
public
void
setFallTemperature
(
double
fallTemperature
)
{
this
.
fallTemperature
=
fallTemperature
;
}
public
void
setFallTemperature
(
double
fallTemperature
)
{
this
.
fallTemperature
=
fallTemperature
;
}
}
src/main/java/environment/BasinNetwork.java
View file @
3378aefe
...
...
@@ -2,6 +2,9 @@ package environment;
import
fr.cemagref.simaqualife.kernel.AquaNismsGroup
;
import
fr.cemagref.simaqualife.kernel.spatial.Environment
;
import
fr.cemagref.simaqualife.kernel.util.TransientParameters.InitTransientParameters
;
import
fr.cemagref.simaqualife.pilot.Pilot
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -21,6 +24,14 @@ public abstract class BasinNetwork extends Environment<Basin, DiadromousFish> {
protected
transient
Basin
[]
grid
;
protected
transient
double
[][]
distanceGrid
;
protected
transient
Time
time
;
@InitTransientParameters
public
void
initTransientParameters
(
Pilot
pilot
)
{
time
=
new
Time
();
}
public
int
getRow
(
int
id
)
{
return
(
id
%
nbBasin
);
...
...
@@ -291,4 +302,17 @@ public abstract class BasinNetwork extends Environment<Basin, DiadromousFish> {
public
abstract
Map
<
String
,
Double
[]>
getTemperaturesBasin
(
long
year
);
public
abstract
String
getTemperatureCatchmentFile
();
/**
* @return the time
*/
public
Time
getTime
()
{
return
time
;
}
}
src/main/java/environment/BasinNetworkNEA.java
View file @
3378aefe
...
...
@@ -149,6 +149,8 @@ public class BasinNetworkNEA extends BasinNetwork {
@InitTransientParameters
public
void
initTransientParameters
(
Pilot
pilot
)
{
super
.
initTransientParameters
(
pilot
);
FileReader
reader
;
Scanner
scanner
;
// =============================================
...
...
src/main/java/environment/BasinNetworkObserver.java
View file @
3378aefe
...
...
@@ -43,6 +43,7 @@ public class BasinNetworkObserver extends ObserverListener implements Configurab
protected
String
title
;
protected
transient
BasinNetwork
bn
;
protected
transient
Time
time
;
protected
transient
double
minX
,
minY
,
rangeX
,
rangeY
;
// list of reachRect
...
...
@@ -140,10 +141,12 @@ public class BasinNetworkObserver extends ObserverListener implements Configurab
}
@Override
public
void
valueChanged
(
ObservablesHandler
arg0
,
Object
env
,
long
time
)
{
public
void
valueChanged
(
ObservablesHandler
arg0
,
Object
env
,
long
arg2
)
{
display
.
repaint
();
String
txt
=
(
new
Long
(
Time
.
getYear
(
pilot
))).
toString
()
+
(
" "
)
+
Time
.
getSeason
(
pilot
).
toString
();
String
txt
=
(
Long
.
valueOf
(
time
.
getYear
(
pilot
))).
toString
()
+
(
" "
)
+
time
.
getSeason
(
pilot
).
toString
();
label
.
setText
(
txt
);
}
...
...
@@ -158,8 +161,8 @@ public class BasinNetworkObserver extends ObserverListener implements Configurab
int
x
=
(
e
.
getX
());
Basin
basin
;
String
txt
=
(
new
Long
(
T
ime
.
getYear
(
pilot
))).
toString
()
+
(
" "
)
+
T
ime
.
getSeason
(
pilot
).
toString
()
+
" - "
;
String
txt
=
Long
.
valueOf
((
t
ime
.
getYear
(
pilot
))).
toString
()
+
(
" "
)
+
t
ime
.
getSeason
(
pilot
).
toString
()
+
" - "
;
for
(
Shape
shape
:
shapeBasinMap
.
keySet
())
{
if
(
shape
.
contains
(
x
,
y
))
{
...
...
@@ -178,7 +181,11 @@ public class BasinNetworkObserver extends ObserverListener implements Configurab
@Override
public
JComponent
getDisplay
()
{
//CHECK
if
(
bn
==
null
)
{
bn
=
(
BasinNetwork
)
pilot
.
getAquaticWorld
().
getEnvironment
();
time
=
bn
.
getTime
();
}
// compute min and max of x and y
double
maxX
,
maxY
;
...
...
src/main/java/environment/BasinNetworkObserverNEA.java
View file @
3378aefe
...
...
@@ -42,12 +42,16 @@ Drawable, MouseMotionListener {
// a basin network
private
transient
BasinNetworkNEA
bn
;
// the time
private
transient
Time
time
;
// list of reachRect
private
transient
Map
<
Shape
,
Basin
>
shapeBasinMap
;
// continent
private
Map
<
String
,
Path2D
.
Double
>
mapContinent
;
private
transient
Map
<
String
,
Path2D
.
Double
>
mapContinent
;
protected
transient
Pilot
pilot
;
// use to draw objects ( basins andt continent)
private
transient
double
minX
,
minY
,
rangeX
,
rangeY
;
...
...
@@ -70,7 +74,6 @@ Drawable, MouseMotionListener {
public
void
init
()
{
// nothing to do
}
protected
transient
Pilot
pilot
;
@TransientParameters
.
InitTransientParameters
public
void
init
(
Pilot
pilot
)
{
...
...
@@ -95,18 +98,21 @@ Drawable, MouseMotionListener {
// Initialize the map linking shape with basin
shapeBasinMap
=
new
HashMap
<
Shape
,
Basin
>();
// load basin to a have access to the shape
bn
=
(
BasinNetworkNEA
)
pilot
.
getAquaticWorld
().
getEnvironment
();
// time in bn is not yet created
time
=
new
Time
();
}
@Override
public
void
valueChanged
(
ObservablesHandler
arg0
,
Object
arg1
,
long
arg2
)
{
display
.
repaint
();
// update the label
String
txt
=
Long
.
valueOf
((
T
ime
.
getYear
(
pilot
))).
toString
()
+
(
" "
)
+
T
ime
.
getSeason
(
pilot
).
toString
();
label
.
setText
(
txt
);
/*
// update the label
String txt = Long.valueOf((
t
ime.getYear(pilot))).toString() + (" ")
+
t
ime.getSeason(pilot).toString();