mdpsolver 0.9.7__tar.gz → 0.9.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/LICENSE +1 -1
  2. {mdpsolver-0.9.7/src/mdpsolver.egg-info → mdpsolver-0.9.8}/PKG-INFO +9 -5
  3. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/README.md +7 -3
  4. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/pyproject.toml +2 -2
  5. mdpsolver-0.9.8/src/mdpsolver/solvermodule.cp313-win_amd64.pyd +0 -0
  6. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/solvermodule.cpython-310-x86_64-linux-gnu.so +0 -0
  7. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/solvermodule.cpython-311-x86_64-linux-gnu.so +0 -0
  8. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/solvermodule.cpython-312-x86_64-linux-gnu.so +0 -0
  9. mdpsolver-0.9.8/src/mdpsolver/solvermodule.cpython-313-x86_64-linux-gnu.so +0 -0
  10. {mdpsolver-0.9.7 → mdpsolver-0.9.8/src/mdpsolver.egg-info}/PKG-INFO +9 -5
  11. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver.egg-info/SOURCES.txt +2 -0
  12. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/tests/test1.py +172 -132
  13. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/tests/test2.py +10 -4
  14. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/MANIFEST.in +0 -0
  15. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/setup.cfg +0 -0
  16. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/__init__.py +0 -0
  17. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/model.py +0 -0
  18. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/problems/__pycache__/cbmaux.cpython-310.pyc +0 -0
  19. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/problems/__pycache__/tbmaux.cpython-310.pyc +0 -0
  20. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/problems/cbmaux.py +0 -0
  21. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/problems/tbmaux.py +0 -0
  22. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/solvermodule.cp310-win_amd64.pyd +0 -0
  23. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/solvermodule.cp311-win_amd64.pyd +0 -0
  24. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver/solvermodule.cp312-win_amd64.pyd +0 -0
  25. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver.egg-info/dependency_links.txt +0 -0
  26. {mdpsolver-0.9.7 → mdpsolver-0.9.8}/src/mdpsolver.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Anders Reenberg Andersen and Jesper Fink Andersen
3
+ Copyright (c) 2025 Anders Reenberg Andersen and Jesper Fink Andersen
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: mdpsolver
3
- Version: 0.9.7
3
+ Version: 0.9.8
4
4
  Summary: A fast solver for Markov Decision Processes
5
- Author-email: Anders Reenberg Andersen <andersra@live.dk>, Jesper Fink Andersen <jfan@dtu.dk>
5
+ Author-email: Anders Reenberg Andersen <andersra@live.dk>, Jesper Fink Andersen <jesperfinkandersen@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/areenberg/MDPSolver
7
7
  Project-URL: Issues, https://github.com/areenberg/MDPSolver/issues
8
8
  Classifier: Development Status :: 3 - Alpha
@@ -38,7 +38,11 @@ Install directly from PyPI with:
38
38
  pip install mdpsolver
39
39
  ```
40
40
 
41
- MDPSolver works *out of the box* on Linux.
41
+ MDPSolver works *out of the box* on Ubuntu 22 and newer.
42
+
43
+ ### GLIBC not found
44
+
45
+ Some users will encounter the `version 'GLIBC_2.32' not found` error when attempting to import MDPSolver in Python. In this case, it might help to manually compile and replace the SO-file for the optimization module in the MDPSolver package. See the steps on how to solve the issue in the [documentation](https://github.com/areenberg/MDPSolver/wiki#how-to-install).
42
46
 
43
47
  ## Windows
44
48
 
@@ -157,7 +161,7 @@ mdl.mdp(discount=0.8,
157
161
 
158
162
  # Documentation
159
163
 
160
- The documentation can be found in the wiki for MDPSolver (https://github.com/areenberg/MDPSolver/wiki).
164
+ The documentation can be found in the [wiki for MDPSolver](https://github.com/areenberg/MDPSolver/wiki).
161
165
 
162
166
  # How to cite
163
167
 
@@ -23,7 +23,11 @@ Install directly from PyPI with:
23
23
  pip install mdpsolver
24
24
  ```
25
25
 
26
- MDPSolver works *out of the box* on Linux.
26
+ MDPSolver works *out of the box* on Ubuntu 22 and newer.
27
+
28
+ ### GLIBC not found
29
+
30
+ Some users will encounter the `version 'GLIBC_2.32' not found` error when attempting to import MDPSolver in Python. In this case, it might help to manually compile and replace the SO-file for the optimization module in the MDPSolver package. See the steps on how to solve the issue in the [documentation](https://github.com/areenberg/MDPSolver/wiki#how-to-install).
27
31
 
28
32
  ## Windows
29
33
 
@@ -142,8 +146,8 @@ mdl.mdp(discount=0.8,
142
146
 
143
147
  # Documentation
144
148
 
145
- The documentation can be found in the wiki for MDPSolver (https://github.com/areenberg/MDPSolver/wiki).
149
+ The documentation can be found in the [wiki for MDPSolver](https://github.com/areenberg/MDPSolver/wiki).
146
150
 
147
151
  # How to cite
148
152
 
149
- [![DOI](https://zenodo.org/badge/294063917.svg)](https://zenodo.org/badge/latestdoi/294063917)
153
+ [![DOI](https://zenodo.org/badge/294063917.svg)](https://zenodo.org/badge/latestdoi/294063917)
@@ -10,10 +10,10 @@ where = ["src"]
10
10
 
11
11
  [project]
12
12
  name = "mdpsolver"
13
- version = "0.9.7"
13
+ version = "0.9.8"
14
14
  authors = [
15
15
  { name="Anders Reenberg Andersen", email="andersra@live.dk" },
16
- { name="Jesper Fink Andersen", email="jfan@dtu.dk" },
16
+ { name="Jesper Fink Andersen", email="jesperfinkandersen@gmail.com" },
17
17
  ]
18
18
  description = "A fast solver for Markov Decision Processes"
19
19
  readme = "README.md"
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: mdpsolver
3
- Version: 0.9.7
3
+ Version: 0.9.8
4
4
  Summary: A fast solver for Markov Decision Processes
5
- Author-email: Anders Reenberg Andersen <andersra@live.dk>, Jesper Fink Andersen <jfan@dtu.dk>
5
+ Author-email: Anders Reenberg Andersen <andersra@live.dk>, Jesper Fink Andersen <jesperfinkandersen@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/areenberg/MDPSolver
7
7
  Project-URL: Issues, https://github.com/areenberg/MDPSolver/issues
8
8
  Classifier: Development Status :: 3 - Alpha
@@ -38,7 +38,11 @@ Install directly from PyPI with:
38
38
  pip install mdpsolver
39
39
  ```
40
40
 
41
- MDPSolver works *out of the box* on Linux.
41
+ MDPSolver works *out of the box* on Ubuntu 22 and newer.
42
+
43
+ ### GLIBC not found
44
+
45
+ Some users will encounter the `version 'GLIBC_2.32' not found` error when attempting to import MDPSolver in Python. In this case, it might help to manually compile and replace the SO-file for the optimization module in the MDPSolver package. See the steps on how to solve the issue in the [documentation](https://github.com/areenberg/MDPSolver/wiki#how-to-install).
42
46
 
43
47
  ## Windows
44
48
 
@@ -157,7 +161,7 @@ mdl.mdp(discount=0.8,
157
161
 
158
162
  # Documentation
159
163
 
160
- The documentation can be found in the wiki for MDPSolver (https://github.com/areenberg/MDPSolver/wiki).
164
+ The documentation can be found in the [wiki for MDPSolver](https://github.com/areenberg/MDPSolver/wiki).
161
165
 
162
166
  # How to cite
163
167
 
@@ -7,9 +7,11 @@ src/mdpsolver/model.py
7
7
  src/mdpsolver/solvermodule.cp310-win_amd64.pyd
8
8
  src/mdpsolver/solvermodule.cp311-win_amd64.pyd
9
9
  src/mdpsolver/solvermodule.cp312-win_amd64.pyd
10
+ src/mdpsolver/solvermodule.cp313-win_amd64.pyd
10
11
  src/mdpsolver/solvermodule.cpython-310-x86_64-linux-gnu.so
11
12
  src/mdpsolver/solvermodule.cpython-311-x86_64-linux-gnu.so
12
13
  src/mdpsolver/solvermodule.cpython-312-x86_64-linux-gnu.so
14
+ src/mdpsolver/solvermodule.cpython-313-x86_64-linux-gnu.so
13
15
  src/mdpsolver.egg-info/PKG-INFO
14
16
  src/mdpsolver.egg-info/SOURCES.txt
15
17
  src/mdpsolver.egg-info/dependency_links.txt
@@ -1,5 +1,7 @@
1
1
  import mdpsolver
2
2
  import random
3
+ import sys
4
+ import numpy as np
3
5
  from random import randint
4
6
 
5
7
  #TEST 1
@@ -9,8 +11,6 @@ from random import randint
9
11
  # CONFIGURATION 1
10
12
  #---------------------------------------
11
13
 
12
- print("## CONFIG. 1 ##\n")
13
-
14
14
  #rewards
15
15
  #1st index: from (current) states
16
16
  #2nd index: actions
@@ -31,7 +31,6 @@ random.seed(10)
31
31
  initPolicy = [randint(0, 1) for p in range(0, 3)]
32
32
 
33
33
  #Model 1a (discounted reward, parallel)
34
- print("# Model 1a (discounted reward, parallel) #")
35
34
  mdl1a = mdpsolver.model()
36
35
  mdl1a.mdp(discount=0.95,
37
36
  rewards=rewards,
@@ -40,11 +39,12 @@ mdl1a.solve(algorithm="mpi",
40
39
  update="standard",
41
40
  parallel=True,
42
41
  initPolicy=initPolicy)
43
- print(mdl1a.getPolicy())
44
- print(mdl1a.getValueVector())
42
+ if not np.array_equal(np.array(mdl1a.getPolicy()),np.array([1,1,0])):
43
+ sys.exit("Model 1a failed!")
44
+ if not np.array_equal(np.round(np.array(mdl1a.getValueVector()),6),np.round(np.array([200.00114718191236,212.86672887958622,298.7090458676583]),6)):
45
+ sys.exit("Model 1a failed!")
45
46
 
46
47
  #Model 2a (discounted reward, parallel)
47
- print("# Model 2a (discounted reward, parallel) #")
48
48
  mdl2a = mdpsolver.model()
49
49
  mdl2a.mdp(discount=0.95,
50
50
  rewards=rewards,
@@ -53,11 +53,12 @@ mdl2a.solve(algorithm="pi",
53
53
  update="standard",
54
54
  parallel=True,
55
55
  initPolicy=initPolicy)
56
- print(mdl2a.getPolicy())
57
- print(mdl2a.getValueVector())
56
+ if not np.array_equal(np.array(mdl2a.getPolicy()),np.array([1,1,0])):
57
+ sys.exit("Model 2a failed!")
58
+ if not np.array_equal(np.round(np.array(mdl2a.getValueVector()),6),np.round(np.array([200.00114718191236,212.86672887958622,298.7090458676583]),6)):
59
+ sys.exit("Model 2a failed!")
58
60
 
59
61
  #Model 3a (discounted reward, parallel)
60
- print("# Model 3a (discounted reward, parallel) #")
61
62
  mdl3a = mdpsolver.model()
62
63
  mdl3a.mdp(discount=0.95,
63
64
  rewards=rewards,
@@ -65,11 +66,12 @@ mdl3a.mdp(discount=0.95,
65
66
  mdl3a.solve(algorithm="vi",
66
67
  update="standard",
67
68
  parallel=True)
68
- print(mdl3a.getPolicy())
69
- print(mdl3a.getValueVector())
69
+ if not np.array_equal(np.array(mdl3a.getPolicy()),np.array([1,1,0])):
70
+ sys.exit("Model 3a failed!")
71
+ if not np.array_equal(np.round(np.array(mdl3a.getValueVector()),6),np.round(np.array([200.0013199959708, 212.86689665815788, 298.709197760198]),6)):
72
+ sys.exit("Model 3a failed!")
70
73
 
71
74
  #Model 1b (discounted reward, unparallel)
72
- print("# Model 1b (discounted reward, unparallel) #")
73
75
  mdl1b = mdpsolver.model()
74
76
  mdl1b.mdp(discount=0.95,
75
77
  rewards=rewards,
@@ -78,11 +80,12 @@ mdl1b.solve(algorithm="mpi",
78
80
  update="standard",
79
81
  parallel=False,
80
82
  initPolicy=initPolicy)
81
- print(mdl1b.getPolicy())
82
- print(mdl1b.getValueVector())
83
+ if not np.array_equal(np.array(mdl1b.getPolicy()),np.array([1,1,0])):
84
+ sys.exit("Model 1b failed!")
85
+ if not np.array_equal(np.round(np.array(mdl1b.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
86
+ sys.exit("Model 1b failed!")
83
87
 
84
88
  #Model 2b (discounted reward, unparallel)
85
- print("# Model 2b (discounted reward, unparallel) #")
86
89
  mdl2b = mdpsolver.model()
87
90
  mdl2b.mdp(discount=0.95,
88
91
  rewards=rewards,
@@ -91,11 +94,12 @@ mdl2b.solve(algorithm="pi",
91
94
  update="standard",
92
95
  parallel=False,
93
96
  initPolicy=initPolicy)
94
- print(mdl2b.getPolicy())
95
- print(mdl2b.getValueVector())
97
+ if not np.array_equal(np.array(mdl2b.getPolicy()),np.array([1,1,0])):
98
+ sys.exit("Model 2b failed!")
99
+ if not np.array_equal(np.round(np.array(mdl2b.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
100
+ sys.exit("Model 2b failed!")
96
101
 
97
102
  #Model 3b (discounted reward, unparallel)
98
- print("# Model 3b (discounted reward, unparallel) #")
99
103
  mdl3b = mdpsolver.model()
100
104
  mdl3b.mdp(discount=0.95,
101
105
  rewards=rewards,
@@ -103,11 +107,12 @@ mdl3b.mdp(discount=0.95,
103
107
  mdl3b.solve(algorithm="vi",
104
108
  update="standard",
105
109
  parallel=False)
106
- print(mdl3b.getPolicy())
107
- print(mdl3b.getValueVector())
110
+ if not np.array_equal(np.array(mdl3b.getPolicy()),np.array([1,1,0])):
111
+ sys.exit("Model 3b failed!")
112
+ if not np.array_equal(np.round(np.array(mdl3b.getValueVector()),6),np.round(np.array([200.0013199959708, 212.86689665815788, 298.709197760198]),6)):
113
+ sys.exit("Model 3b failed!")
108
114
 
109
115
  #Model 1a (average reward, parallel)
110
- print("# Model 1a (average reward, parallel) #")
111
116
  mdl1a = mdpsolver.model()
112
117
  mdl1a.mdp(rewards=rewards,
113
118
  tranMatWithZeros=tranMatWithZeros)
@@ -116,11 +121,12 @@ mdl1a.solve(algorithm="mpi",
116
121
  criterion="average",
117
122
  parallel=True,
118
123
  initPolicy=initPolicy)
119
- print(mdl1a.getPolicy())
120
- print(mdl1a.getValueVector())
124
+ if not np.array_equal(np.array(mdl1a.getPolicy()),np.array([1,1,0])):
125
+ sys.exit("Model 1a failed!")
126
+ if not np.array_equal(np.round(np.array(mdl1a.getValueVector()),6),np.round(np.array([354.2101307157537, 368.21018917357264, 457.21037278800077]),6)):
127
+ sys.exit("Model 1a failed!")
121
128
 
122
129
  #Model 2a (average reward, parallel)
123
- print("# Model 2a (average reward, parallel) #")
124
130
  mdl2a = mdpsolver.model()
125
131
  mdl2a.mdp(rewards=rewards,
126
132
  tranMatWithZeros=tranMatWithZeros)
@@ -129,11 +135,12 @@ mdl2a.solve(algorithm="pi",
129
135
  criterion="average",
130
136
  parallel=True,
131
137
  initPolicy=initPolicy)
132
- print(mdl2a.getPolicy())
133
- print(mdl2a.getValueVector())
138
+ if not np.array_equal(np.array(mdl2a.getPolicy()),np.array([1,1,0])):
139
+ sys.exit("Model 2a failed!")
140
+ if not np.array_equal(np.round(np.array(mdl2a.getValueVector()),6),np.round(np.array([354.2101307157537, 368.21018917357264, 457.21037278800077]),6)):
141
+ sys.exit("Model 2a failed!")
134
142
 
135
143
  #Model 3a (average reward, parallel)
136
- print("# Model 3a (average reward, parallel) #")
137
144
  mdl3a = mdpsolver.model()
138
145
  mdl3a.mdp(rewards=rewards,
139
146
  tranMatWithZeros=tranMatWithZeros)
@@ -141,11 +148,12 @@ mdl3a.solve(algorithm="vi",
141
148
  update="standard",
142
149
  criterion="average",
143
150
  parallel=True)
144
- print(mdl3a.getPolicy())
145
- print(mdl3a.getValueVector())
151
+ if not np.array_equal(np.array(mdl3a.getPolicy()),np.array([1,1,0])):
152
+ sys.exit("Model 3a failed!")
153
+ if not np.array_equal(np.round(np.array(mdl3a.getValueVector()),6),np.round(np.array([158.23345351808334, 172.23340169038516, 261.233237936489]),6)):
154
+ sys.exit("Model 3a failed!")
146
155
 
147
156
  #Model 1b (average reward, unparallel)
148
- print("# Model 1b (average reward, unparallel) #")
149
157
  mdl1b = mdpsolver.model()
150
158
  mdl1b.mdp(rewards=rewards,
151
159
  tranMatWithZeros=tranMatWithZeros)
@@ -154,11 +162,12 @@ mdl1b.solve(algorithm="mpi",
154
162
  criterion="average",
155
163
  parallel=False,
156
164
  initPolicy=initPolicy)
157
- print(mdl1b.getPolicy())
158
- print(mdl1b.getValueVector())
165
+ if not np.array_equal(np.array(mdl1b.getPolicy()),np.array([1,1,0])):
166
+ sys.exit("Model 1b failed!")
167
+ if not np.array_equal(np.round(np.array(mdl1b.getValueVector()),6),np.round(np.array([354.2101307157537, 368.21018917357264, 457.21037278800077]),6)):
168
+ sys.exit("Model 1b failed!")
159
169
 
160
170
  #Model 2b (average reward, unparallel)
161
- print("# Model 2b (average reward, unparallel) #")
162
171
  mdl2b = mdpsolver.model()
163
172
  mdl2b.mdp(rewards=rewards,
164
173
  tranMatWithZeros=tranMatWithZeros)
@@ -167,11 +176,12 @@ mdl2b.solve(algorithm="pi",
167
176
  criterion="average",
168
177
  parallel=False,
169
178
  initPolicy=initPolicy)
170
- print(mdl2b.getPolicy())
171
- print(mdl2b.getValueVector())
179
+ if not np.array_equal(np.array(mdl2b.getPolicy()),np.array([1,1,0])):
180
+ sys.exit("Model 2b failed!")
181
+ if not np.array_equal(np.round(np.array(mdl2b.getValueVector()),6),np.round(np.array([354.2101307157537, 368.21018917357264, 457.21037278800077]),6)):
182
+ sys.exit("Model 2b failed!")
172
183
 
173
184
  #Model 3b (average reward, unparallel)
174
- print("# Model 3b (average reward, unparallel) #")
175
185
  mdl3b = mdpsolver.model()
176
186
  mdl3b.mdp(rewards=rewards,
177
187
  tranMatWithZeros=tranMatWithZeros)
@@ -179,11 +189,12 @@ mdl3b.solve(algorithm="vi",
179
189
  update="standard",
180
190
  criterion="average",
181
191
  parallel=False)
182
- print(mdl3b.getPolicy())
183
- print(mdl3b.getValueVector())
192
+ if not np.array_equal(np.array(mdl3b.getPolicy()),np.array([1,1,0])):
193
+ sys.exit("Model 3b failed!")
194
+ if not np.array_equal(np.round(np.array(mdl3b.getValueVector()),6),np.round(np.array([158.23345351808334, 172.23340169038516, 261.233237936489]),6)):
195
+ sys.exit("Model 3b failed!")
184
196
 
185
197
  #Model 1c (discounted, Gauss-Seidel)
186
- print("# Model 1c (discounted reward, Gauss-Seidel) #")
187
198
  mdl1c = mdpsolver.model()
188
199
  mdl1c.mdp(discount=0.95,
189
200
  rewards=rewards,
@@ -192,11 +203,12 @@ mdl1c.solve(algorithm="mpi",
192
203
  update="gs",
193
204
  parallel=False,
194
205
  initPolicy=initPolicy)
195
- print(mdl1c.getPolicy())
196
- print(mdl1c.getValueVector())
206
+ if not np.array_equal(np.array(mdl1c.getPolicy()),np.array([1,1,0])):
207
+ sys.exit("Model 1c failed!")
208
+ if not np.array_equal(np.round(np.array(mdl1c.getValueVector()),6),np.round(np.array([200.0012771893156, 212.86686671568802, 298.7091798650016]),6)):
209
+ sys.exit("Model 1c failed!")
197
210
 
198
211
  #Model 2c (Gauss-Seidel)
199
- print("# Model 2c (discounted reward, Gauss-Seidel) #")
200
212
  initPolicy=[1,1,1]
201
213
  mdl2c = mdpsolver.model()
202
214
  mdl2c.mdp(discount=0.95,
@@ -206,11 +218,12 @@ mdl2c.solve(algorithm="pi",
206
218
  update="gs",
207
219
  parallel=False,
208
220
  initPolicy=initPolicy)
209
- print(mdl2c.getPolicy())
210
- print(mdl2c.getValueVector())
221
+ if not np.array_equal(np.array(mdl2c.getPolicy()),np.array([1,1,0])):
222
+ sys.exit("Model 2c failed!")
223
+ if not np.array_equal(np.round(np.array(mdl2c.getValueVector()),6),np.round(np.array([200.0012771893156, 212.86686671568802, 298.7091798650016]),6)):
224
+ sys.exit("Model 2c failed!")
211
225
 
212
226
  #Model 3c (Gauss-Seidel)
213
- print("# Model 3c (discounted reward, Gauss-Seidel) #")
214
227
  mdl3c = mdpsolver.model()
215
228
  mdl3c.mdp(discount=0.95,
216
229
  rewards=rewards,
@@ -218,11 +231,12 @@ mdl3c.mdp(discount=0.95,
218
231
  mdl3c.solve(algorithm="vi",
219
232
  update="gs",
220
233
  parallel=False)
221
- print(mdl3c.getPolicy())
222
- print(mdl3c.getValueVector())
234
+ if not np.array_equal(np.array(mdl3c.getPolicy()),np.array([1,1,0])):
235
+ sys.exit("Model 3c failed!")
236
+ if not np.array_equal(np.round(np.array(mdl3c.getValueVector()),6),np.round(np.array([200.0010604606014, 212.86664512773723, 298.7089561808565]),6)):
237
+ sys.exit("Model 3c failed!")
223
238
 
224
239
  #Model 1d (SOR)
225
- print("# Model 1d (discounted reward, SOR) #")
226
240
  mdl1d = mdpsolver.model()
227
241
  mdl1d.mdp(discount=0.95,
228
242
  rewards=rewards,
@@ -232,11 +246,12 @@ mdl1d.solve(algorithm="mpi",
232
246
  SORrelaxation=1.01,
233
247
  parallel=False,
234
248
  initPolicy=initPolicy)
235
- print(mdl1d.getPolicy())
236
- print(mdl1d.getValueVector())
249
+ if not np.array_equal(np.array(mdl1d.getPolicy()),np.array([1,1,0])):
250
+ sys.exit("Model 1d failed!")
251
+ if not np.array_equal(np.round(np.array(mdl1d.getValueVector()),6),np.round(np.array([200.00127021272166, 212.86686059325598, 298.70917425463125]),6)):
252
+ sys.exit("Model 1d failed!")
237
253
 
238
254
  #Model 2d (SOR)
239
- print("# Model 2d (discounted reward, SOR) #")
240
255
  mdl2d = mdpsolver.model()
241
256
  mdl2d.mdp(discount=0.95,
242
257
  rewards=rewards,
@@ -246,11 +261,12 @@ mdl2d.solve(algorithm="pi",
246
261
  SORrelaxation=1.01,
247
262
  parallel=False,
248
263
  initPolicy=initPolicy)
249
- print(mdl2d.getPolicy())
250
- print(mdl2d.getValueVector())
264
+ if not np.array_equal(np.array(mdl2d.getPolicy()),np.array([1,1,0])):
265
+ sys.exit("Model 2d failed!")
266
+ if not np.array_equal(np.round(np.array(mdl2d.getValueVector()),6),np.round(np.array([200.00127021272166, 212.86686059325598, 298.70917425463125]),6)):
267
+ sys.exit("Model 2d failed!")
251
268
 
252
269
  #Model 3d (SOR)
253
- print("# Model 3d (discounted reward, SOR) #")
254
270
  mdl3d = mdpsolver.model()
255
271
  mdl3d.mdp(discount=0.95,
256
272
  rewards=rewards,
@@ -259,15 +275,15 @@ mdl3d.solve(algorithm="vi",
259
275
  update="sor",
260
276
  SORrelaxation=1.01,
261
277
  parallel=False)
262
- print(mdl3d.getPolicy())
263
- print(mdl3d.getValueVector())
278
+ if not np.array_equal(np.array(mdl3d.getPolicy()),np.array([1,1,0])):
279
+ sys.exit("Model 3d failed!")
280
+ if not np.array_equal(np.round(np.array(mdl3d.getValueVector()),6),np.round(np.array([206.69740452375487, 222.30968454932525, 305.91165352015094]),6)):
281
+ sys.exit("Model 3d failed!")
264
282
 
265
283
  #---------------------------------------
266
284
  # CONFIGURATION 2
267
285
  #---------------------------------------
268
286
 
269
- print("\n ## CONFIG. 2 ##\n")
270
-
271
287
  #rewards
272
288
  #1st index: from (current) states
273
289
  #2nd index: actions
@@ -298,7 +314,6 @@ random.seed(10)
298
314
  initPolicy = [randint(0, 1) for p in range(0, 3)]
299
315
 
300
316
  #Model 1a
301
- print("# Model 1a #")
302
317
  mdl1a = mdpsolver.model()
303
318
  mdl1a.mdp(discount=0.95,
304
319
  rewards=rewards,
@@ -307,11 +322,12 @@ mdl1a.solve(algorithm="mpi",
307
322
  update="standard",
308
323
  parallel=True,
309
324
  initPolicy=initPolicy)
310
- print(mdl1a.getPolicy())
311
- print(mdl1a.getValueVector())
325
+ if not np.array_equal(np.array(mdl1a.getPolicy()),np.array([1,1,0])):
326
+ sys.exit("Model 1a failed!")
327
+ if not np.array_equal(np.round(np.array(mdl1a.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
328
+ sys.exit("Model 1a failed!")
312
329
 
313
330
  #Model 2a
314
- print("# Model 2a #")
315
331
  mdl2a = mdpsolver.model()
316
332
  mdl2a.mdp(discount=0.95,
317
333
  rewards=rewards,
@@ -320,11 +336,12 @@ mdl2a.solve(algorithm="pi",
320
336
  update="standard",
321
337
  parallel=True,
322
338
  initPolicy=initPolicy)
323
- print(mdl2a.getPolicy())
324
- print(mdl2a.getValueVector())
339
+ if not np.array_equal(np.array(mdl2a.getPolicy()),np.array([1,1,0])):
340
+ sys.exit("Model 2a failed!")
341
+ if not np.array_equal(np.round(np.array(mdl2a.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
342
+ sys.exit("Model 2a failed!")
325
343
 
326
344
  #Model 3a
327
- print("# Model 3a #")
328
345
  mdl3a = mdpsolver.model()
329
346
  mdl3a.mdp(discount=0.95,
330
347
  rewards=rewards,
@@ -332,11 +349,12 @@ mdl3a.mdp(discount=0.95,
332
349
  mdl3a.solve(algorithm="vi",
333
350
  update="standard",
334
351
  parallel=True)
335
- print(mdl3a.getPolicy())
336
- print(mdl3a.getValueVector())
352
+ if not np.array_equal(np.array(mdl3a.getPolicy()),np.array([1,1,0])):
353
+ sys.exit("Model 3a failed!")
354
+ if not np.array_equal(np.round(np.array(mdl3a.getValueVector()),6),np.round(np.array([200.0013199959708, 212.86689665815788, 298.709197760198]),6)):
355
+ sys.exit("Model 3a failed!")
337
356
 
338
357
  #Model 1b
339
- print("# Model 1b #")
340
358
  mdl1b = mdpsolver.model()
341
359
  mdl1b.mdp(discount=0.95,
342
360
  rewards=rewards,
@@ -345,11 +363,12 @@ mdl1b.solve(algorithm="mpi",
345
363
  update="standard",
346
364
  parallel=False,
347
365
  initPolicy=initPolicy)
348
- print(mdl1b.getPolicy())
349
- print(mdl1b.getValueVector())
366
+ if not np.array_equal(np.array(mdl1b.getPolicy()),np.array([1,1,0])):
367
+ sys.exit("Model 1b failed!")
368
+ if not np.array_equal(np.round(np.array(mdl1b.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
369
+ sys.exit("Model 1b failed!")
350
370
 
351
371
  #Model 2b
352
- print("# Model 2b #")
353
372
  mdl2b = mdpsolver.model()
354
373
  mdl2b.mdp(discount=0.95,
355
374
  rewards=rewards,
@@ -358,11 +377,12 @@ mdl2b.solve(algorithm="pi",
358
377
  update="standard",
359
378
  parallel=False,
360
379
  initPolicy=initPolicy)
361
- print(mdl2b.getPolicy())
362
- print(mdl2b.getValueVector())
380
+ if not np.array_equal(np.array(mdl2b.getPolicy()),np.array([1,1,0])):
381
+ sys.exit("Model 2b failed!")
382
+ if not np.array_equal(np.round(np.array(mdl2b.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
383
+ sys.exit("Model 2b failed!")
363
384
 
364
385
  #Model 3b
365
- print("# Model 3b #")
366
386
  mdl3b = mdpsolver.model()
367
387
  mdl3b.mdp(discount=0.95,
368
388
  rewards=rewards,
@@ -370,11 +390,12 @@ mdl3b.mdp(discount=0.95,
370
390
  mdl3b.solve(algorithm="vi",
371
391
  update="standard",
372
392
  parallel=False)
373
- print(mdl3b.getPolicy())
374
- print(mdl3b.getValueVector())
393
+ if not np.array_equal(np.array(mdl3b.getPolicy()),np.array([1,1,0])):
394
+ sys.exit("Model 3b failed!")
395
+ if not np.array_equal(np.round(np.array(mdl3b.getValueVector()),6),np.round(np.array([200.0013199959708, 212.86689665815788, 298.709197760198]),6)):
396
+ sys.exit("Model 3b failed!")
375
397
 
376
398
  #Model 1c
377
- print("# Model 1c #")
378
399
  mdl1c = mdpsolver.model()
379
400
  mdl1c.mdp(discount=0.95,
380
401
  rewards=rewards,
@@ -383,11 +404,12 @@ mdl1c.solve(algorithm="mpi",
383
404
  update="gs",
384
405
  parallel=False,
385
406
  initPolicy=initPolicy)
386
- print(mdl1c.getPolicy())
387
- print(mdl1c.getValueVector())
407
+ if not np.array_equal(np.array(mdl1c.getPolicy()),np.array([1,1,0])):
408
+ sys.exit("Model 1c failed!")
409
+ if not np.array_equal(np.round(np.array(mdl1c.getValueVector()),6),np.round(np.array([200.0012771893156, 212.86686671568802, 298.7091798650016]),6)):
410
+ sys.exit("Model 1c failed!")
388
411
 
389
412
  #Model 2c
390
- print("# Model 2c #")
391
413
  mdl2c = mdpsolver.model()
392
414
  mdl2c.mdp(discount=0.95,
393
415
  rewards=rewards,
@@ -396,11 +418,12 @@ mdl2c.solve(algorithm="pi",
396
418
  update="gs",
397
419
  parallel=False,
398
420
  initPolicy=initPolicy)
399
- print(mdl2c.getPolicy())
400
- print(mdl2c.getValueVector())
421
+ if not np.array_equal(np.array(mdl2c.getPolicy()),np.array([1,1,0])):
422
+ sys.exit("Model 2c failed!")
423
+ if not np.array_equal(np.round(np.array(mdl2c.getValueVector()),6),np.round(np.array([200.0012771893156, 212.86686671568802, 298.7091798650016]),6)):
424
+ sys.exit("Model 2c failed!")
401
425
 
402
426
  #Model 3c
403
- print("# Model 3c #")
404
427
  mdl3c = mdpsolver.model()
405
428
  mdl3c.mdp(discount=0.95,
406
429
  rewards=rewards,
@@ -408,11 +431,12 @@ mdl3c.mdp(discount=0.95,
408
431
  mdl3c.solve(algorithm="vi",
409
432
  update="gs",
410
433
  parallel=False)
411
- print(mdl3c.getPolicy())
412
- print(mdl3c.getValueVector())
434
+ if not np.array_equal(np.array(mdl3c.getPolicy()),np.array([1,1,0])):
435
+ sys.exit("Model 3c failed!")
436
+ if not np.array_equal(np.round(np.array(mdl3c.getValueVector()),6),np.round(np.array([200.0010604606014, 212.86664512773723, 298.7089561808565]),6)):
437
+ sys.exit("Model 3c failed!")
413
438
 
414
439
  #Model 1d
415
- print("# Model 1d #")
416
440
  mdl1d = mdpsolver.model()
417
441
  mdl1d.mdp(discount=0.95,
418
442
  rewards=rewards,
@@ -422,11 +446,12 @@ mdl1d.solve(algorithm="mpi",
422
446
  SORrelaxation=1.01,
423
447
  parallel=False,
424
448
  initPolicy=initPolicy)
425
- print(mdl1d.getPolicy())
426
- print(mdl1d.getValueVector())
449
+ if not np.array_equal(np.array(mdl1d.getPolicy()),np.array([1,1,0])):
450
+ sys.exit("Model 1d failed!")
451
+ if not np.array_equal(np.round(np.array(mdl1d.getValueVector()),6),np.round(np.array([200.00127021272166, 212.86686059325598, 298.70917425463125]),6)):
452
+ sys.exit("Model 1d failed!")
427
453
 
428
454
  #Model 2d
429
- print("# Model 2d #")
430
455
  mdl2d = mdpsolver.model()
431
456
  mdl2d.mdp(discount=0.95,
432
457
  rewards=rewards,
@@ -436,11 +461,12 @@ mdl2d.solve(algorithm="pi",
436
461
  SORrelaxation=1.01,
437
462
  parallel=False,
438
463
  initPolicy=initPolicy)
439
- print(mdl2d.getPolicy())
440
- print(mdl2d.getValueVector())
464
+ if not np.array_equal(np.array(mdl2d.getPolicy()),np.array([1,1,0])):
465
+ sys.exit("Model 2d failed!")
466
+ if not np.array_equal(np.round(np.array(mdl2d.getValueVector()),6),np.round(np.array([200.00127021272166, 212.86686059325598, 298.70917425463125]),6)):
467
+ sys.exit("Model 2d failed!")
441
468
 
442
469
  #Model 3d
443
- print("# Model 3d #")
444
470
  mdl3d = mdpsolver.model()
445
471
  mdl3d.mdp(discount=0.95,
446
472
  rewards=rewards,
@@ -449,15 +475,15 @@ mdl3d.solve(algorithm="vi",
449
475
  update="sor",
450
476
  SORrelaxation=1.01,
451
477
  parallel=False)
452
- print(mdl3d.getPolicy())
453
- print(mdl3d.getValueVector())
478
+ if not np.array_equal(np.array(mdl3d.getPolicy()),np.array([1,1,0])):
479
+ sys.exit("Model 3d failed!")
480
+ if not np.array_equal(np.round(np.array(mdl3d.getValueVector()),6),np.round(np.array([206.69740452375487, 222.30968454932525, 305.91165352015094]),6)):
481
+ sys.exit("Model 3d failed!")
454
482
 
455
483
  #---------------------------------------
456
484
  # CONFIGURATION 3
457
485
  #---------------------------------------
458
486
 
459
- print("\n ## CONFIG. 3 ##\n")
460
-
461
487
  #rewards
462
488
  #1st index: from (current) states
463
489
  #2nd index: actions
@@ -479,7 +505,6 @@ random.seed(10)
479
505
  initPolicy = [randint(0, 1) for p in range(0, 3)]
480
506
 
481
507
  #Model 1a
482
- print("# Model 1a #")
483
508
  mdl1a = mdpsolver.model()
484
509
  mdl1a.mdp(discount=0.95,
485
510
  rewards=rewards,
@@ -489,11 +514,12 @@ mdl1a.solve(algorithm="mpi",
489
514
  update="standard",
490
515
  parallel=True,
491
516
  initPolicy=initPolicy)
492
- print(mdl1a.getPolicy())
493
- print(mdl1a.getValueVector())
517
+ if not np.array_equal(np.array(mdl1a.getPolicy()),np.array([1,1,0])):
518
+ sys.exit("Model 1a failed!")
519
+ if not np.array_equal(np.round(np.array(mdl1a.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
520
+ sys.exit("Model 1a failed!")
494
521
 
495
522
  #Model 2a
496
- print("# Model 2a #")
497
523
  mdl2a = mdpsolver.model()
498
524
  mdl2a.mdp(discount=0.95,
499
525
  rewards=rewards,
@@ -503,11 +529,12 @@ mdl2a.solve(algorithm="pi",
503
529
  update="standard",
504
530
  parallel=True,
505
531
  initPolicy=initPolicy)
506
- print(mdl2a.getPolicy())
507
- print(mdl2a.getValueVector())
532
+ if not np.array_equal(np.array(mdl2a.getPolicy()),np.array([1,1,0])):
533
+ sys.exit("Model 2a failed!")
534
+ if not np.array_equal(np.round(np.array(mdl2a.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
535
+ sys.exit("Model 2a failed!")
508
536
 
509
537
  #Model 3a
510
- print("# Model 3a #")
511
538
  mdl3a = mdpsolver.model()
512
539
  mdl3a.mdp(discount=0.95,
513
540
  rewards=rewards,
@@ -516,11 +543,12 @@ mdl3a.mdp(discount=0.95,
516
543
  mdl3a.solve(algorithm="vi",
517
544
  update="standard",
518
545
  parallel=True)
519
- print(mdl3a.getPolicy())
520
- print(mdl3a.getValueVector())
546
+ if not np.array_equal(np.array(mdl3a.getPolicy()),np.array([1,1,0])):
547
+ sys.exit("Model 3a failed!")
548
+ if not np.array_equal(np.round(np.array(mdl3a.getValueVector()),6),np.round(np.array([200.0013199959708, 212.86689665815788, 298.709197760198]),6)):
549
+ sys.exit("Model 3a failed!")
521
550
 
522
551
  #Model 1b
523
- print("# Model 1b #")
524
552
  mdl1b = mdpsolver.model()
525
553
  mdl1b.mdp(discount=0.95,
526
554
  rewards=rewards,
@@ -530,11 +558,12 @@ mdl1b.solve(algorithm="mpi",
530
558
  update="standard",
531
559
  parallel=False,
532
560
  initPolicy=initPolicy)
533
- print(mdl1b.getPolicy())
534
- print(mdl1b.getValueVector())
561
+ if not np.array_equal(np.array(mdl1b.getPolicy()),np.array([1,1,0])):
562
+ sys.exit("Model 1b failed!")
563
+ if not np.array_equal(np.round(np.array(mdl1b.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
564
+ sys.exit("Model 1b failed!")
535
565
 
536
566
  #Model 2b
537
- print("# Model 2b #")
538
567
  mdl2b = mdpsolver.model()
539
568
  mdl2b.mdp(discount=0.95,
540
569
  rewards=rewards,
@@ -544,11 +573,12 @@ mdl2b.solve(algorithm="pi",
544
573
  update="standard",
545
574
  parallel=False,
546
575
  initPolicy=initPolicy)
547
- print(mdl2b.getPolicy())
548
- print(mdl2b.getValueVector())
576
+ if not np.array_equal(np.array(mdl2b.getPolicy()),np.array([1,1,0])):
577
+ sys.exit("Model 2b failed!")
578
+ if not np.array_equal(np.round(np.array(mdl2b.getValueVector()),6),np.round(np.array([200.00114718191236, 212.86672887958622, 298.7090458676583]),6)):
579
+ sys.exit("Model 2b failed!")
549
580
 
550
581
  #Model 3b
551
- print("# Model 3b #")
552
582
  mdl3b = mdpsolver.model()
553
583
  mdl3b.mdp(discount=0.95,
554
584
  rewards=rewards,
@@ -557,11 +587,12 @@ mdl3b.mdp(discount=0.95,
557
587
  mdl3b.solve(algorithm="vi",
558
588
  update="standard",
559
589
  parallel=False)
560
- print(mdl3b.getPolicy())
561
- print(mdl3b.getValueVector())
590
+ if not np.array_equal(np.array(mdl3b.getPolicy()),np.array([1,1,0])):
591
+ sys.exit("Model 3b failed!")
592
+ if not np.array_equal(np.round(np.array(mdl3b.getValueVector()),6),np.round(np.array([200.0013199959708, 212.86689665815788, 298.709197760198]),6)):
593
+ sys.exit("Model 3b failed!")
562
594
 
563
595
  #Model 1c
564
- print("# Model 1c #")
565
596
  mdl1c = mdpsolver.model()
566
597
  mdl1c.mdp(discount=0.95,
567
598
  rewards=rewards,
@@ -571,11 +602,12 @@ mdl1c.solve(algorithm="mpi",
571
602
  update="gs",
572
603
  parallel=False,
573
604
  initPolicy=initPolicy)
574
- print(mdl1c.getPolicy())
575
- print(mdl1c.getValueVector())
605
+ if not np.array_equal(np.array(mdl1c.getPolicy()),np.array([1,1,0])):
606
+ sys.exit("Model 1c failed!")
607
+ if not np.array_equal(np.round(np.array(mdl1c.getValueVector()),6),np.round(np.array([200.0012771893156, 212.86686671568802, 298.7091798650016]),6)):
608
+ sys.exit("Model 1c failed!")
576
609
 
577
610
  #Model 2c
578
- print("# Model 2c #")
579
611
  mdl2c = mdpsolver.model()
580
612
  mdl2c.mdp(discount=0.95,
581
613
  rewards=rewards,
@@ -585,11 +617,12 @@ mdl2c.solve(algorithm="pi",
585
617
  update="gs",
586
618
  parallel=False,
587
619
  initPolicy=initPolicy)
588
- print(mdl2c.getPolicy())
589
- print(mdl2c.getValueVector())
620
+ if not np.array_equal(np.array(mdl2c.getPolicy()),np.array([1,1,0])):
621
+ sys.exit("Model 2c failed!")
622
+ if not np.array_equal(np.round(np.array(mdl2c.getValueVector()),6),np.round(np.array([200.0012771893156, 212.86686671568802, 298.7091798650016]),6)):
623
+ sys.exit("Model 2c failed!")
590
624
 
591
625
  #Model 3c
592
- print("# Model 3c #")
593
626
  mdl3c = mdpsolver.model()
594
627
  mdl3c.mdp(discount=0.95,
595
628
  rewards=rewards,
@@ -598,11 +631,12 @@ mdl3c.mdp(discount=0.95,
598
631
  mdl3c.solve(algorithm="vi",
599
632
  update="gs",
600
633
  parallel=False)
601
- print(mdl3c.getPolicy())
602
- print(mdl3c.getValueVector())
634
+ if not np.array_equal(np.array(mdl3c.getPolicy()),np.array([1,1,0])):
635
+ sys.exit("Model 3c failed!")
636
+ if not np.array_equal(np.round(np.array(mdl3c.getValueVector()),6),np.round(np.array([200.0010604606014, 212.86664512773723, 298.7089561808565]),6)):
637
+ sys.exit("Model 3c failed!")
603
638
 
604
639
  #Model 1d
605
- print("# Model 1d #")
606
640
  mdl1d = mdpsolver.model()
607
641
  mdl1d.mdp(discount=0.95,
608
642
  rewards=rewards,
@@ -613,11 +647,12 @@ mdl1d.solve(algorithm="mpi",
613
647
  SORrelaxation=1.01,
614
648
  parallel=False,
615
649
  initPolicy=initPolicy)
616
- print(mdl1d.getPolicy())
617
- print(mdl1d.getValueVector())
650
+ if not np.array_equal(np.array(mdl1d.getPolicy()),np.array([1,1,0])):
651
+ sys.exit("Model 1d failed!")
652
+ if not np.array_equal(np.round(np.array(mdl1d.getValueVector()),6),np.round(np.array([200.00127021272166, 212.86686059325598, 298.70917425463125]),6)):
653
+ sys.exit("Model 1d failed!")
618
654
 
619
655
  #Model 2d
620
- print("# Model 2d #")
621
656
  mdl2d = mdpsolver.model()
622
657
  mdl2d.mdp(discount=0.95,
623
658
  rewards=rewards,
@@ -628,11 +663,12 @@ mdl2d.solve(algorithm="pi",
628
663
  SORrelaxation=1.01,
629
664
  parallel=False,
630
665
  initPolicy=initPolicy)
631
- print(mdl2d.getPolicy())
632
- print(mdl2d.getValueVector())
666
+ if not np.array_equal(np.array(mdl2d.getPolicy()),np.array([1,1,0])):
667
+ sys.exit("Model 2d failed!")
668
+ if not np.array_equal(np.round(np.array(mdl2d.getValueVector()),6),np.round(np.array([200.00127021272166, 212.86686059325598, 298.70917425463125]),6)):
669
+ sys.exit("Model 2d failed!")
633
670
 
634
671
  #Model 3d
635
- print("# Model 3d #")
636
672
  mdl3d = mdpsolver.model()
637
673
  mdl3d.mdp(discount=0.95,
638
674
  rewards=rewards,
@@ -642,5 +678,9 @@ mdl3d.solve(algorithm="vi",
642
678
  update="sor",
643
679
  SORrelaxation=1.01,
644
680
  parallel=False)
645
- print(mdl3d.getPolicy())
646
- print(mdl3d.getValueVector())
681
+ if not np.array_equal(np.array(mdl3d.getPolicy()),np.array([1,1,0])):
682
+ sys.exit("Model 3d failed!")
683
+ if not np.array_equal(np.round(np.array(mdl3d.getValueVector()),6),np.round(np.array([206.69740452375487, 222.30968454932525, 305.91165352015094]),6)):
684
+ sys.exit("Model 3d failed!")
685
+
686
+ print("Test 1 succesfully reproduced output!")
@@ -1,5 +1,7 @@
1
1
  import mdpsolver
2
2
  import example_model
3
+ import sys
4
+ import numpy as np
3
5
 
4
6
  #TEST 2
5
7
  #In this test, we load the rewards and transition probabilities
@@ -43,8 +45,8 @@ mdl1.mdp(discount=0.99,
43
45
  tranMatFromFile="transitions_example2.csv")
44
46
 
45
47
  mdl1.solve(algorithm="vi")
46
-
47
- print("Value iteration:",mdl1.getRuntime(),"milliseconds.")
48
+ if not np.round(np.mean(mdl1.getValueVector()),6)==np.round(17074.81609832942,6):
49
+ sys.exit("Model 1 failed!")
48
50
 
49
51
  #---------------------------------------
50
52
  # POLICY ITERATION
@@ -58,7 +60,8 @@ mdl2.mdp(discount=0.99,
58
60
 
59
61
  mdl2.solve(algorithm="pi")
60
62
 
61
- print("Policy iteration:",mdl2.getRuntime(),"milliseconds.")
63
+ if not np.round(np.mean(mdl2.getValueVector()),6)==np.round(17074.815578793514,6):
64
+ sys.exit("Model 2 failed!")
62
65
 
63
66
  #---------------------------------------
64
67
  # MODIFIED POLICY ITERATION
@@ -72,4 +75,7 @@ mdl3.mdp(discount=0.99,
72
75
 
73
76
  mdl3.solve(algorithm="mpi")
74
77
 
75
- print("Modified policy iteration:",mdl3.getRuntime(),"milliseconds.")
78
+ if not np.round(np.mean(mdl3.getValueVector()),6)==np.round(17074.815563750446,6):
79
+ sys.exit("Model 3 failed!")
80
+
81
+ print("Test 2 succesfully reproduced output!")
File without changes
File without changes