Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Larry Price
gmsh
Commits
d8c9644e
Commit
d8c9644e
authored
8 years ago
by
Kilian Verhetsel
Browse files
Options
Downloads
Patches
Plain Diff
Removed lambda expressions from search.hpp
parent
bcdfa495
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Mesh/search.hpp
+35
-18
35 additions, 18 deletions
Mesh/search.hpp
with
35 additions
and
18 deletions
Mesh/search.hpp
+
35
−
18
View file @
d8c9644e
...
@@ -152,20 +152,26 @@ void greedy_search(State &state, Successor &fn, Evaluator &eval) {
...
@@ -152,20 +152,26 @@ void greedy_search(State &state, Successor &fn, Evaluator &eval) {
}
}
std
::
vector
<
delta
>
changes
(
actions
.
size
());
std
::
vector
<
delta
>
changes
(
actions
.
size
());
std
::
transform
(
actions
.
begin
(),
actions
.
end
(),
changes
.
begin
(),
[
&
](
const
action
&
a
)
{
typename
std
::
vector
<
action
>::
const_iterator
actions_it
;
return
a
(
state
);
typename
std
::
vector
<
delta
>::
iterator
changes_it
;
});
for
(
actions_it
=
actions
.
begin
(),
changes_it
=
changes
.
begin
();
actions_it
!=
actions
.
end
();
actions_it
++
,
changes_it
++
)
{
const
action
&
a
=
*
actions_it
;
*
changes_it
=
a
(
state
);
}
std
::
vector
<
score
>
scores
(
actions
.
size
());
std
::
vector
<
score
>
scores
(
actions
.
size
());
std
::
transform
(
changes
.
begin
(),
changes
.
end
(),
scores
.
begin
(),
[
&
](
const
delta
&
delta
)
{
delta
.
apply
(
state
);
auto
result
=
eval
(
state
);
delta
.
reverse
(
state
);
return
result
;
typename
std
::
vector
<
score
>::
iterator
scores_it
;
});
for
(
changes_it
=
changes
.
begin
(),
scores_it
=
scores
.
begin
();
changes_it
!=
changes
.
end
();
changes_it
++
,
scores_it
++
)
{
const
delta
&
delta
=
*
changes_it
;
delta
.
apply
(
state
);
*
scores_it
=
eval
(
state
);
delta
.
reverse
(
state
);
}
auto
it
=
std
::
max_element
(
scores
.
begin
(),
scores
.
end
());
auto
it
=
std
::
max_element
(
scores
.
begin
(),
scores
.
end
());
...
@@ -214,21 +220,32 @@ struct mcts_node {
...
@@ -214,21 +220,32 @@ struct mcts_node {
return
(
x_1
/
visit_count
)
+
std
::
sqrt
(
2
*
std
::
log
(
Score
(
n
))
/
visit_count
);
return
(
x_1
/
visit_count
)
+
std
::
sqrt
(
2
*
std
::
log
(
Score
(
n
))
/
visit_count
);
}
}
class
compare_by_ucb1
{
std
::
size_t
_n
;
public:
compare_by_ucb1
(
std
::
size_t
n
)
:
_n
(
n
)
{}
bool
operator
()(
const
mcts_node
<
Score
>
&
a
,
const
mcts_node
<
Score
>
&
b
)
const
{
return
a
.
ucb1
(
_n
)
<
b
.
ucb1
(
_n
);
}
};
struct
compare_by_mean
{
bool
operator
()(
const
mcts_node
<
Score
>
&
a
,
const
mcts_node
<
Score
>
&
b
)
const
{
return
a
.
x_1
<
b
.
x_1
;
}
};
std
::
size_t
best_child
(
std
::
size_t
n
)
const
{
std
::
size_t
best_child
(
std
::
size_t
n
)
const
{
auto
it
=
std
::
max_element
(
children
.
begin
(),
children
.
end
(),
auto
it
=
std
::
max_element
(
children
.
begin
(),
children
.
end
(),
[
&
](
const
mcts_node
<
Score
>
&
a
,
const
mcts_node
<
Score
>
&
b
)
{
compare_by_ucb1
(
n
));
return
a
.
ucb1
(
n
)
<
b
.
ucb1
(
n
);
});
return
std
::
distance
(
children
.
begin
(),
it
);
return
std
::
distance
(
children
.
begin
(),
it
);
}
}
std
::
size_t
best_move
(
std
::
size_t
n
)
const
{
std
::
size_t
best_move
(
std
::
size_t
n
)
const
{
auto
it
=
std
::
max_element
(
children
.
begin
(),
children
.
end
(),
auto
it
=
std
::
max_element
(
children
.
begin
(),
children
.
end
(),
[
&
](
const
mcts_node
<
Score
>
&
a
,
const
mcts_node
<
Score
>
&
b
)
{
compare_by_mean
());
return
a
.
x_1
<
b
.
x_1
;
});
return
std
::
distance
(
children
.
begin
(),
it
);
return
std
::
distance
(
children
.
begin
(),
it
);
}
}
};
};
...
...
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