Skip to content

Commit

Permalink
Refactor/animal parameters (#43)
Browse files Browse the repository at this point in the history
* updated hydration and dehydration rate

* added properties for default values

* changed hydration and dehydration rate

* refactoring and commenting
  • Loading branch information
lorenzosenarigo authored Jan 28, 2024
1 parent c0dc0dc commit a4b849e
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 35 deletions.
4 changes: 1 addition & 3 deletions GeoRasterBlueprint/Model/AbstractAnimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ public abstract class AbstractAnimal : IPositionable, IAgent<LandscapeLayer> {
private const int RandomWalkMinDistanceInM = 10;
public const double MaxHydration = 100.0;
public const double MaxSatiety = 100.0;
public const double DehydrationRate = 6.0;
public const double StarvationRate = 4.0;
public const int MaxAge = 25;

public void Init(LandscapeLayer layer) {
LandscapeLayer = layer;

Expand Down
48 changes: 38 additions & 10 deletions GeoRasterBlueprint/Model/Bison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,53 @@ public class Bison : AbstractAnimal {
public override double Longitude { get; set; }

#endregion

#region Constants
private readonly Dictionary<AnimalLifePeriod, double> _satietyIntakeHourly = new()
private readonly Dictionary<AnimalLifePeriod, double> _starvationRate = new()
{
//food per day (kg) / 16 (hours)
{ AnimalLifePeriod.Calf, 0.56 }, //9kg per day
{ AnimalLifePeriod.Adolescent, 1.81 }, //20-29 kg per day
{ AnimalLifePeriod.Adult, 3.75 } //60 kg per day, 113 liter
/*
* DailyFood / 16 is the gross starvation rate
* but MaxSatiety = 100 != total food need per day
* so the rate has to be adjusted
* Total food need per day : 100 = (Total food need per day / 24) : adjusted rate
*/
{ AnimalLifePeriod.Calf, MaxSatiety * DailyFoodCalf / 16 / DailyFoodAdult },
{ AnimalLifePeriod.Adolescent, MaxSatiety * DailyFoodAdolescent / 16 / DailyFoodAdult },
{ AnimalLifePeriod.Adult, MaxSatiety * DailyFoodAdult / 16 / DailyFoodAdult }
};

private readonly Dictionary<AnimalLifePeriod, double> _dehydrationRate =
new()
{
{ AnimalLifePeriod.Calf, 0.7 }, // daily water consumption 17.0 = 9 / 60 * 113, divided by 24
{ AnimalLifePeriod.Adolescent, 2.29 }, //daily water consumption 55.0 = 29 / 60 * 113, all divided by 24
{ AnimalLifePeriod.Adult, 4.7} //daily water consumption 113, divided by 24
/*
* DailyWater / 24 is the gross starvation rate
* but MaxHydration = 100 != total food need per day
* so the rate has to be adjusted
* Total water need per day : 100 = (Total water need per day / 24) : adjusted rate
*/
{ AnimalLifePeriod.Calf, MaxHydration * DailyWaterCalf / 24 / DailyWaterAdult },
{ AnimalLifePeriod.Adolescent, MaxHydration * DailyWaterAdolescent / 24 / DailyWaterAdult},
{ AnimalLifePeriod.Adult, MaxHydration * DailyWaterAdult / 24 / DailyWaterAdult}
};

[PropertyDescription]
public static double DailyFoodAdult { get; set; }
[PropertyDescription]
public static double DailyFoodCalf { get; set; }
[PropertyDescription]
public static double DailyFoodAdolescent { get; set; }

//total need of water per day in liters
[PropertyDescription]
public static double DailyWaterAdult { get; set; }
[PropertyDescription]
public static double DailyWaterCalf { get; set; }
[PropertyDescription]
public static double DailyWaterAdolescent { get; set; }
#endregion

public override void Tick() {

if (!IsAlive) return;
_hoursLived++;
if (_hoursLived == 300)
Expand Down Expand Up @@ -70,12 +98,12 @@ protected override void UpdateState()


if (currentHour is >= 21 and <= 23 || currentHour is >= 0 and <= 4 ) {
BurnSatiety(_satietyIntakeHourly[_LifePeriod] / 4); //less food is consumed while sleeping
BurnSatiety(_starvationRate[_LifePeriod] / 4); //less food is consumed while sleeping
Dehydrate(_dehydrationRate[_LifePeriod]/2); //less water is consumed at night
}
else
{
BurnSatiety(_satietyIntakeHourly[_LifePeriod]);
BurnSatiety(_starvationRate[_LifePeriod]);
Dehydrate(_dehydrationRate[_LifePeriod]);
}
}
Expand Down
48 changes: 37 additions & 11 deletions GeoRasterBlueprint/Model/Elk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,50 @@ public class Elk : AbstractAnimal {

#region constants

//TODO use real Elk data
private readonly Dictionary<AnimalLifePeriod, double> _satietyIntakeHourly = new()
private readonly Dictionary<AnimalLifePeriod, double> _starvationRate = new()
{
//food per day (kg) / 16 (hours)
{ AnimalLifePeriod.Calf, 0.56 }, //9kg per day
{ AnimalLifePeriod.Adolescent, 1.81 }, //20-29 kg per day
{ AnimalLifePeriod.Adult, 3.75 } //60 kg per day, 113 liter
/*
* DailyFood / 16 is the gross starvation rate
* but MaxSatiety = 100 != total food need per day
* so the rate has to be adjusted
* Total food need per day : 100 = (Total food need per day / 24) : adjusted rate
*/
{ AnimalLifePeriod.Calf, MaxSatiety * DailyFoodCalf / 16 / DailyFoodAdult },
{ AnimalLifePeriod.Adolescent, MaxSatiety * DailyFoodAdolescent / 16 / DailyFoodAdult },
{ AnimalLifePeriod.Adult, MaxSatiety * DailyFoodAdult / 16 / DailyFoodAdult }
};

private readonly Dictionary<AnimalLifePeriod, double> _dehydrationRate =
new()
{
{ AnimalLifePeriod.Calf, 0.7 }, // daily water consumption 17.0 = 9 / 60 * 113, divided by 24
{ AnimalLifePeriod.Adolescent, 2.29 }, //daily water consumption 55.0 = 29 / 60 * 113, all divided by 24
{ AnimalLifePeriod.Adult, 4.7} //daily water consumption 113, divided by 24
/*
* DailyWater / 24 is the gross starvation rate
* but MaxHydration = 100 != total food need per day
* so the rate has to be adjusted
* Total water need per day : 100 = (Total water need per day / 24) : adjusted rate
*/
{ AnimalLifePeriod.Calf, MaxHydration * DailyWaterCalf / 24 / DailyWaterAdult },
{ AnimalLifePeriod.Adolescent, MaxHydration * DailyWaterAdolescent / 24 / DailyWaterAdult},
{ AnimalLifePeriod.Adult, MaxHydration * DailyWaterAdult / 24 / DailyWaterAdult}
};

[PropertyDescription]
public static double DailyFoodAdult { get; set; }
[PropertyDescription]
public static double DailyFoodCalf { get; set; }
[PropertyDescription]
public static double DailyFoodAdolescent { get; set; }

//total need of water per day in liters
[PropertyDescription]
public static double DailyWaterAdult { get; set; }
[PropertyDescription]
public static double DailyWaterCalf { get; set; }
[PropertyDescription]
public static double DailyWaterAdolescent { get; set; }
#endregion
public override void Tick() {

if (!IsAlive) return;
_hoursLived++;
if (_hoursLived == 300)
Expand Down Expand Up @@ -74,12 +100,12 @@ protected override void UpdateState()


if (currentHour is >= 21 and <= 23 || currentHour is >= 0 and <= 4 ) {
BurnSatiety(_satietyIntakeHourly[_LifePeriod] / 4); //less food is consumed while sleeping
BurnSatiety(_starvationRate[_LifePeriod] / 4); //less food is consumed while sleeping
Dehydrate(_dehydrationRate[_LifePeriod]/2); //less water is consumed at night
}
else
{
BurnSatiety(_satietyIntakeHourly[_LifePeriod]);
BurnSatiety(_starvationRate[_LifePeriod]);
Dehydrate(_dehydrationRate[_LifePeriod]);
}
}
Expand Down
49 changes: 38 additions & 11 deletions GeoRasterBlueprint/Model/Moose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,51 @@ public class Moose : AbstractAnimal {
#endregion

#region Constants
//TODO use real moose data
private readonly Dictionary<AnimalLifePeriod, double> _satietyIntakeHourly = new()
private readonly Dictionary<AnimalLifePeriod, double> _starvationRate = new()
{
//food per day (kg) / 16 (hours)
{ AnimalLifePeriod.Calf, 0.56 }, //9kg per day
{ AnimalLifePeriod.Adolescent, 1.81 }, //20-29 kg per day
{ AnimalLifePeriod.Adult, 3.75 } //60 kg per day, 113 liter
/*
* DailyFood / 16 is the gross starvation rate
* but MaxSatiety = 100 != total food need per day
* so the rate has to be adjusted
* Total food need per day : 100 = (Total food need per day / 24) : adjusted rate
*/
{ AnimalLifePeriod.Calf, MaxSatiety * DailyFoodCalf / 16 / DailyFoodAdult },
{ AnimalLifePeriod.Adolescent, MaxSatiety * DailyFoodAdolescent / 16 / DailyFoodAdult },
{ AnimalLifePeriod.Adult, MaxSatiety * DailyFoodAdult / 16 / DailyFoodAdult }
};

private readonly Dictionary<AnimalLifePeriod, double> _dehydrationRate =
new()
{
{ AnimalLifePeriod.Calf, 0.7 }, // daily water consumption 17.0 = 9 / 60 * 113, divided by 24
{ AnimalLifePeriod.Adolescent, 2.29 }, //daily water consumption 55.0 = 29 / 60 * 113, all divided by 24
{ AnimalLifePeriod.Adult, 4.7} //daily water consumption 113, divided by 24
/*
* DailyWater / 24 is the gross starvation rate
* but MaxHydration = 100 != total food need per day
* so the rate has to be adjusted
* Total water need per day : 100 = (Total water need per day / 24) : adjusted rate
*/
{ AnimalLifePeriod.Calf, MaxHydration * DailyWaterCalf / 24 / DailyWaterAdult },
{ AnimalLifePeriod.Adolescent, MaxHydration * DailyWaterAdolescent / 24 / DailyWaterAdult},
{ AnimalLifePeriod.Adult, MaxHydration * DailyWaterAdult / 24 / DailyWaterAdult}
};

//total need of food per day in kilogramms
[PropertyDescription]
public static double DailyFoodAdult { get; set; }
[PropertyDescription]
public static double DailyFoodCalf { get; set; }
[PropertyDescription]
public static double DailyFoodAdolescent { get; set; }

//total need of water per day in liters
[PropertyDescription]
public static double DailyWaterAdult { get; set; }
[PropertyDescription]
public static double DailyWaterCalf { get; set; }
[PropertyDescription]
public static double DailyWaterAdolescent { get; set; }
#endregion
public override void Tick() {

if (!IsAlive) return;
_hoursLived++;
if (_hoursLived == 300)
Expand Down Expand Up @@ -73,12 +100,12 @@ protected override void UpdateState()


if (currentHour is >= 21 and <= 23 || currentHour is >= 0 and <= 4 ) {
BurnSatiety(_satietyIntakeHourly[_LifePeriod] / 4); //less food is consumed while sleeping
BurnSatiety(_starvationRate[_LifePeriod] / 4); //less food is consumed while sleeping
Dehydrate(_dehydrationRate[_LifePeriod]/2); //less water is consumed at night
}
else
{
BurnSatiety(_satietyIntakeHourly[_LifePeriod]);
BurnSatiety(_starvationRate[_LifePeriod]);
Dehydrate(_dehydrationRate[_LifePeriod]);
}
}
Expand Down
78 changes: 78 additions & 0 deletions GeoRasterBlueprint/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,98 @@
"agents": [
{
"name": "Bison",
"mapping": [
{
"parameter": "DailyFoodAdult",
"value": 60
},
{
"parameter": "DailyFoodAdolescent",
"value": 29
},
{
"parameter": "DailyFoodCalf",
"value": 9
},
{
"parameter": "DailyWaterAdult",
"value": 113
},
{
"parameter": "DailyWaterAdolescent",
"value": 55
},
{
"parameter": "DailyWaterCalf",
"value": 17
}
],
"file":"Resources/bisons.csv",
"outputs": [
{"kind": "trips"}
]
},
{
"name": "Moose",
"mapping": [
{
"parameter": "DailyFoodAdult",
"value": 27
},
{
"parameter": "DailyFoodAdolescent",
"value": 13
},
{
"parameter": "DailyFoodCalf",
"value": 4
},
{
"parameter": "DailyWaterAdult",
"value": 529
},
{
"parameter": "DailyWaterAdolescent",
"value": 258
},
{
"parameter": "DailyWaterCalf",
"value": 79
}
],
"file":"Resources/moose.csv",
"outputs": [
{"kind": "trips"}
]
},
{
"name": "Elk",
"mapping": [
{
"parameter": "DailyFoodAdult",
"value": 9.1
},
{
"parameter": "DailyFoodAdolescent",
"value": 4.2
},
{
"parameter": "DailyFoodCalf",
"value": 2.0
},
{
"parameter": "DailyWaterAdult",
"value": 60
},
{
"parameter": "DailyWaterAdolescent",
"value": 29
},
{
"parameter": "DailyWaterCalf",
"value": 9
}
],
"file":"Resources/elks.csv",
"outputs": [
{"kind": "trips"}
Expand Down

0 comments on commit a4b849e

Please sign in to comment.