Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sergey Kireev
nle
Commits
45485050
Commit
45485050
authored
Oct 20, 2021
by
Sergey Kireev
Browse files
get_groups_statistics implemented
parent
67c2fb3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
nle_cpp/src/ca2d.cpp
View file @
45485050
...
...
@@ -522,7 +522,7 @@ int CA2D<State,hood_type>::find_groups_hex(std::function<bool(const State &)> ma
groupsize
[
label
]
=
sum
;
k
+=
dk
;
}
{
const
int
ix
=
nx
-
1
;
// сцепленные группы отцепляются в направлении 1-4 при переходе через вертикальную границу
{
const
int
ix
=
nx
-
1
;
for
(
int
iy
=
0
;
iy
<
ny
-
1
;
iy
++
)
if
(
match
(
get
(
ix
,
iy
)))
{
XY
n1
(
ix
,
iy
);
hood
.
move
(
n1
,
4
);
hood
.
fix
(
n1
,
nx
,
ny
);
...
...
@@ -624,5 +624,25 @@ int CA2D<State,hood_type>::find_groups_hex(std::function<bool(const State &)> ma
return
k
;
}
template
<
class
State
,
Neighborhood_type
hood_type
>
CA2D
<
State
,
hood_type
>::
GroupStatistics
CA2D
<
State
,
hood_type
>::
get_groups_statistics
(
int
threshold
)
{
int
grpSizeThreshold
=
threshold
;
int
grpCount
=
0
;
int
grpMinSize
=
nx
*
ny
;
int
grpMidSize
=
0
;
int
grpMaxSize
=
0
;
for
(
int
i
=
0
;
i
<
group_labels_upper_bound
;
i
++
)
{
const
int
size
=
groupsize
[
i
];
if
(
size
>
0
&&
size
>
threshold
)
{
grpCount
++
;
grpMinSize
=
std
::
min
(
grpMinSize
,
size
);
grpMaxSize
=
std
::
max
(
grpMaxSize
,
size
);
grpMidSize
+=
size
;
}
}
grpMidSize
/=
grpCount
;
return
{
threshold
,
grpCount
,
grpMinSize
,
grpMidSize
,
grpMaxSize
};
}
}
// namespace ca2d
nle_cpp/src/ca2d.h
View file @
45485050
...
...
@@ -171,6 +171,14 @@ private:
public:
struct
GroupStatistics
{
int
grpSizeThreshold
;
int
grpCount
;
int
grpMinSize
;
int
grpMidSize
;
int
grpMaxSize
;
};
const
int
nx
,
ny
;
const
int
groups_max
;
...
...
@@ -226,6 +234,8 @@ public:
return
find_groups_sqr4
(
match
);
}
GroupStatistics
get_groups_statistics
(
int
minsize
=
0
);
//void save_char(const std::string &fn,int it=-1,const std::string &ext="") const;
void
print_fraction
(
const
std
::
vector
<
State
>
&
states
,
const
std
::
vector
<
std
::
string
>
&
names
)
const
;
...
...
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