Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cats
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BDC
cats
Commits
98a13dd9
Commit
98a13dd9
authored
1 year ago
by
Andreas Gattringer
Browse files
Options
Downloads
Patches
Plain Diff
new validator function: valid_population grid
parent
af5fa520
No related branches found
No related tags found
1 merge request
!1
preparations for multi-scale simulations
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cats/inline_population.h
+12
-14
12 additions, 14 deletions
src/cats/inline_population.h
with
12 additions
and
14 deletions
src/cats/inline_population.h
+
12
−
14
View file @
98a13dd9
...
@@ -36,15 +36,20 @@
...
@@ -36,15 +36,20 @@
#include
"populations/plant_juveniles.h"
#include
"populations/plant_juveniles.h"
#include
"grids/dimensions.h"
#include
"grids/dimensions.h"
static
inline
bool
valid_population_grid
(
const
struct
cats_grid
*
grid
,
cats_dt_coord
row
)
{
if
(
grid
==
NULL
)
return
false
;
if
(
grid
->
population
==
NULL
)
return
false
;
if
(
grid
->
population
[
row
]
==
NULL
)
return
false
;
// validator [valid_population_grid]
return
true
;
}
static
inline
cats_dt_population
static
inline
cats_dt_population
get_adult_population
(
const
struct
cats_grid
*
grid
,
cats_dt_coord
row
,
cats_dt_coord
col
)
get_adult_population
(
const
struct
cats_grid
*
grid
,
cats_dt_coord
row
,
cats_dt_coord
col
)
{
{
assert
(
grid
!=
NULL
&&
grid
->
population
!=
NULL
);
assert
(
valid_population_grid
(
grid
,
row
)
);
assert
(
valid_coordinates
(
&
grid
->
dimension
,
row
,
col
));
assert
(
valid_coordinates
(
&
grid
->
dimension
,
row
,
col
));
assert
(
grid
->
population
[
row
]
!=
NULL
);
assert
(
grid
->
population
[
row
][
col
]
>=
0
);
return
grid
->
population
[
row
][
col
];
// getter
}
}
...
@@ -81,16 +86,12 @@ static inline cats_dt_population
...
@@ -81,16 +86,12 @@ static inline cats_dt_population
reduce_population_by
(
const
struct
cats_grid
*
grid
,
cats_dt_coord
row
,
cats_dt_coord
col
,
cats_dt_population
to_reduce
)
reduce_population_by
(
const
struct
cats_grid
*
grid
,
cats_dt_coord
row
,
cats_dt_coord
col
,
cats_dt_population
to_reduce
)
{
{
assert
(
to_reduce
>=
0
);
assert
(
to_reduce
>=
0
);
assert
(
grid
!=
NULL
);
assert
(
valid_population_grid
(
grid
,
row
));
assert
(
grid
->
population
!=
NULL
);
assert
(
valid_coordinates
(
&
grid
->
dimension
,
row
,
col
));
assert
(
valid_coordinates
(
&
grid
->
dimension
,
row
,
col
));
assert
(
grid
->
population
[
row
]
!=
NULL
);
//cats_dt_population cc = get_carrying_capacity(grid, row, col);
cats_dt_population
pop
=
get_adult_population
(
grid
,
row
,
col
);
cats_dt_population
pop
=
get_adult_population
(
grid
,
row
,
col
);
if
(
to_reduce
>
pop
)
{
to_reduce
=
pop
;
}
if
(
to_reduce
>
pop
)
{
to_reduce
=
pop
;
}
grid
->
population
[
row
][
col
]
=
pop
-
to_reduce
;
// setter;
grid
->
population
[
row
][
col
]
=
pop
-
to_reduce
;
// setter;
return
to_reduce
;
return
to_reduce
;
...
@@ -101,9 +102,8 @@ static inline void
...
@@ -101,9 +102,8 @@ static inline void
set_population_ignore_cc
(
const
struct
cats_grid
*
grid
,
const
cats_dt_coord
row
,
const
cats_dt_coord
col
,
set_population_ignore_cc
(
const
struct
cats_grid
*
grid
,
const
cats_dt_coord
row
,
const
cats_dt_coord
col
,
const
cats_dt_population
pop
)
const
cats_dt_population
pop
)
{
{
assert
(
grid
!=
NULL
&&
grid
->
population
!=
NULL
);
assert
(
valid_population_grid
(
grid
,
row
)
);
assert
(
valid_coordinates
(
&
grid
->
dimension
,
row
,
col
));
assert
(
valid_coordinates
(
&
grid
->
dimension
,
row
,
col
));
assert
(
grid
->
population
[
row
]
!=
NULL
);
if
(
pop
>
CATS_MAX_POPULATION
||
pop
<
0
.
0
)
{
if
(
pop
>
CATS_MAX_POPULATION
||
pop
<
0
.
0
)
{
log_message
(
LOG_ERROR
,
"%s: population %d out of allowed population range [0, %d]."
,
log_message
(
LOG_ERROR
,
"%s: population %d out of allowed population range [0, %d]."
,
...
@@ -166,10 +166,8 @@ static inline cats_dt_population
...
@@ -166,10 +166,8 @@ static inline cats_dt_population
get_population_ts
(
const
struct
cats_grid
*
grid
,
const
cats_dt_coord
row
,
const
cats_dt_coord
col
,
const
int
threshold
,
get_population_ts
(
const
struct
cats_grid
*
grid
,
const
cats_dt_coord
row
,
const
cats_dt_coord
col
,
const
int
threshold
,
int64_t
*
unfiltered
)
int64_t
*
unfiltered
)
{
{
assert
(
grid
!=
NULL
);
assert
(
valid_population_grid
(
grid
,
row
));
assert
(
grid
->
population
!=
NULL
);
assert
(
valid_coordinates
(
&
grid
->
dimension
,
row
,
col
));
assert
(
valid_coordinates
(
&
grid
->
dimension
,
row
,
col
));
assert
(
grid
->
population
[
row
]
!=
NULL
);
cats_dt_population
tmp
=
grid
->
population
[
row
][
col
];
// getter
cats_dt_population
tmp
=
grid
->
population
[
row
][
col
];
// getter
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment