2
2
[ ![ codecov] ( https://codecov.io/gh/CyCTW/Parallel-MCTS/branch/master/graph/badge.svg?token=LPORRSHSZT )] ( https://codecov.io/gh/CyCTW/Parallel-MCTS )
3
3
4
4
# Parallel Monte Carlo Tree Search
5
- This repo contains the implementation of Parallel Monte Carlo Tree Search with C++.
6
- Three parallel method:
7
- - ** Leaf parallelization**
8
- - ** Root parallelization**
9
- - ** Tree parallelization**
5
+ This repo implements three methods of Parallel Monte Carlo Tree Search with C++.
6
+
7
+ ** The Three parallel methods:**
8
+ - Leaf parallelization
9
+ - Root parallelization
10
+ - Tree parallelization
10
11
11
12
Also, we analyze different methods' performance against each other in [ Surakarta] ( https://en.wikipedia.org/wiki/Surakarta_(game) ) Game.
12
- If you're interested in details, here is the links of our search:
13
+ If you're interested in details, here are the links to our search:
13
14
- [ Experiment report] ( https://hackmd.io/2I8fuKY0TY-sRNQU4Dcuog ) .
14
15
- [ Slides] ( https://docs.google.com/presentation/d/11DV9MijsDh2fgR8W5I8kdCT4u630Bibq6ZfMPpffD6U/edit#slide=id.p )
16
+ ## Features
17
+ - CI pipeline (Autobuild, Autotest)
18
+ - Code coverage check
19
+ ## Structure
20
+ ```
21
+ Parallel-MCTS/
22
+ ├── build
23
+ ├── CMakeLists.txt
24
+ ├── CMakeLists.txt.in
25
+ ├── LICENSE
26
+ ├── README.md
27
+ ├── script
28
+ │ ├── cov.sh
29
+ │ └── record.sh
30
+ ├── src
31
+ │ ├── Agent.h
32
+ │ ├── board.h
33
+ │ ├── config.h
34
+ │ ├── Log.h
35
+ │ ├── main.cpp
36
+ │ ├── MCTS.h
37
+ │ ├── ParallelRoot.h
38
+ │ ├── ParallelTree.h
39
+ │ ├── Policy.h
40
+ │ └── TreeNode.h
41
+ └── unittest
42
+ └── MCTS_UnitTest.cpp
15
43
44
+ 4 directories, 17 files
45
+ ```
16
46
## Development Environment
17
47
- Ubuntu 18.04
18
48
- GCC 7.5.0
19
49
- CMAKE 3.10
20
50
- GoogleTest 1.10.0 (latest)
21
51
22
52
## Requirement
53
+ ### Must
23
54
- C++ 17
24
55
- OpenMP
25
56
- CMAKE (3.10)
57
+ ### optional
58
+ - lcov
59
+ - gcov
26
60
27
61
## Build
28
62
### Construct build directory (optional, but recommened)
29
63
```
30
64
mkdir build
31
65
```
32
- This step create a ` build ` directory, which build a clean environment for CMake compiling and building.
66
+ This step creates a ` build ` directory, which builds a clean environment for CMake compiling and building.
33
67
### Compile file with CMake
34
68
```
35
69
cd build
39
73
```
40
74
cmake .
41
75
```
42
- if you don't create ` build ` directory.
76
+ if you don't create the ` build ` directory.
43
77
### Build file
44
78
```
45
79
cmake --build .
@@ -65,33 +99,35 @@ Usage: mcts [options]
65
99
66
100
Note: -c (count) & -t (time) options can't be specified simultaneously.
67
101
68
- -c --simCount <simulationCount> Set simulation count per step
69
- -t --simTime <simulationTime (second)> Set simulation time per step
70
- -T --threadNum <threadNum> Set number of thread num
102
+ -c --simCount <simulationCount> Set simulation count per step. default: 1000
103
+ -t --simTime <simulationTime (second)> Set simulation time per step. default: -1
104
+ -T --threadNum <threadNum> Set number of thread num. default: 4
71
105
-p --policy <blackAndWhitePolicy> Set Player's policy
72
- <blackPolicy> <whitePolicy> ( choice: Serial, Leaf, Root, Tree. default: Tree Serial)
106
+ <blackPolicy> <whitePolicy> (options: Serial, Leaf, Root, Tree) default: Tree Serial)
107
+
73
108
-m --method <blackAndWhiteMethod> Set Player's arallel methods
74
- <blackMethod> <whiteMethod> ( choice: openmp, pthread. default: openmp )
75
- -? --help Edit config.h to set parameter
109
+ <blackMethod> <whiteMethod> (options: openmp, pthread) default: openmp)
110
+
111
+ -? --help Help message.
76
112
```
77
113
78
- ### Some Examples :
79
- - Serial version (Black) v.s. Serial version (White) with simulation count $ 1000$
114
+ ### Some quick examples :
115
+ - Serial version (Black) v.s. Serial version (White) with simulation count 1000
80
116
```
81
117
./mcts -c 1000 -p Serial
82
118
```
83
- - ParallelTree version (Black) v.s. Serial version (White) with simulation time $2s$
119
+ - ParallelTree version (Black) v.s. Serial version (White) with simulation time 2s
84
120
```
85
121
./mcts -t 2 -p Tree Serial
86
122
```
87
123
*Note: we can't set Count and Time simultaneously, choose only one option.*
88
124
89
- - ParallelRoot version (Black) v.s. ParallelLeaf (White) with $4$ thread, both use `openmp` implementation.
125
+ - ParallelRoot version (Black) v.s. ParallelLeaf (White) with 4 thread, both use `openmp` implementation.
90
126
```
91
127
./mcts -T 4 -p Root Tree -m openmp
92
128
```
93
129
94
- - ParallelRoot version (Black) v.s. ParallelLeaf (White) with $4$ thread. Use `openmp` (Black) and `pthread` (White) implementation.
130
+ - ParallelRoot version (Black) v.s. ParallelLeaf (White) with 4 thread. Use `openmp` (Black) and `pthread` (White) implementation.
95
131
```
96
132
./mcts -T 4 -p Root Leaf -m openmp pthread
97
133
```
@@ -107,9 +143,77 @@ ctest
107
143
Both command will run the same unittest script stored in `<ProjectRoot>/unittest/MCTS_UnitTest.cpp`
108
144
109
145
*Note:*
110
- *The first command run test script using Googletest's origin format.*
111
- *The second command run the same test script, but from CMake.*
146
+ *The first command runs the test script using Googletest's origin format.*
147
+
148
+ *The second command runs the same test script, but from CMake.*
112
149
### Explanation
113
- Mainly, the test script check the Monte Carlo Tree Search's simulation count and simulation time works correctly.
150
+ Mainly, the test script checks the Monte Carlo Tree Search's simulation count and simulation time works correctly.
151
+
152
+ ## CodeCoverage Report
153
+ If you want to see the code coverage report, you should recompile the project with `-DCOVERAGE=ON`
154
+ *Note: default option is `-DCOVERAGE=OFF` because this option will slow down the whole program.*
155
+
156
+ First return to build directory.
157
+ ```
158
+ cd <ProjectRoot >/build
159
+ ```
160
+ Then, recompile project with flag `-DCOVERAGE=OFF`
161
+ ```
162
+ cmake -DCOVERAGE=ON ..
163
+ ```
164
+ Rebuild the project
165
+ ```
166
+ cmake --build .
167
+ ```
168
+ Last, move to `script` folder and execute the `cov.sh` script.
169
+ ```
170
+ cd <ProjectRoot >/script
171
+ ./cov.sh
172
+ ```
173
+ *Note: you should install `lcov` and `gcov` before execute the script.*
174
+
175
+ If everything works fine, the script will open a html file, which contains the code coverage report.
176
+ ## Experiment record
177
+ If you want to run multiple games on different policys, and record the result for further analysis, you can check our `record.sh`
114
178
179
+ You can move to `script` directory to check the `record.sh` file.
180
+ ```
181
+ cd <ProjectRoot >/script
182
+ ```
183
+ ### usage
184
+ ```
185
+ Usage: ./record.sh [ options]
115
186
187
+ Note: -c (count) & -t (time) options can't be specified simultaneously.
188
+
189
+ -c --simCount <simulationCount > Set simulation count per step. default: 1000
190
+ -t --simTime <simulationTime (second)> Set simulation time per step. default: -1
191
+ -T --threadNum <threadNum > Set number of thread num. default: 4
192
+ -p --policy <blackAndWhitePolicy > Set Player's policy
193
+ <blackPolicy > <whitePolicy > (options: Serial, Leaf, Root, Tree) default: Tree Serial)
194
+
195
+ -m --method <blackAndWhiteMethod > Set Player's arallel methods
196
+ <blackMethod > <whiteMethod > (options: openmp, pthread) default: openmp)
197
+
198
+ ```
199
+
200
+ ### Some quick examples:
201
+ - Serial version (Black) v.s. Serial version (White) with simulation count 1000
202
+ ```
203
+ ./record.sh -c 1000 -p Serial
204
+ ```
205
+ - ParallelTree version (Black) v.s. Serial version (White) with simulation time 2s
206
+ ```
207
+ ./record.sh -t 2 -p Tree Serial
208
+ ```
209
+ *Note: we can't set Count and Time simultaneously, choose only one option.*
210
+
211
+ - ParallelRoot version (Black) v.s. ParallelLeaf (White) with 4 thread, both use `openmp` implementation.
212
+ ```
213
+ ./record.sh -T 4 -p Root Tree -m openmp
214
+ ```
215
+
216
+ - ParallelRoot version (Black) v.s. ParallelLeaf (White) with 4 thread. Use `openmp` (Black) and `pthread` (White) implementation.
217
+ ```
218
+ ./record.sh -T 4 -p Root Leaf -m openmp pthread
219
+ ```
0 commit comments