mdpsolver 0.9.6__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.
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/LICENSE +1 -1
- {mdpsolver-0.9.6/src/mdpsolver.egg-info → mdpsolver-0.9.8}/PKG-INFO +12 -7
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/README.md +10 -5
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/pyproject.toml +2 -2
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver/model.py +2 -0
- mdpsolver-0.9.8/src/mdpsolver/solvermodule.cp310-win_amd64.pyd +0 -0
- mdpsolver-0.9.8/src/mdpsolver/solvermodule.cp311-win_amd64.pyd +0 -0
- mdpsolver-0.9.8/src/mdpsolver/solvermodule.cp312-win_amd64.pyd +0 -0
- mdpsolver-0.9.8/src/mdpsolver/solvermodule.cp313-win_amd64.pyd +0 -0
- mdpsolver-0.9.8/src/mdpsolver/solvermodule.cpython-310-x86_64-linux-gnu.so +0 -0
- mdpsolver-0.9.8/src/mdpsolver/solvermodule.cpython-311-x86_64-linux-gnu.so +0 -0
- mdpsolver-0.9.8/src/mdpsolver/solvermodule.cpython-312-x86_64-linux-gnu.so +0 -0
- mdpsolver-0.9.8/src/mdpsolver/solvermodule.cpython-313-x86_64-linux-gnu.so +0 -0
- {mdpsolver-0.9.6 → mdpsolver-0.9.8/src/mdpsolver.egg-info}/PKG-INFO +12 -7
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver.egg-info/SOURCES.txt +5 -1
- mdpsolver-0.9.8/tests/test1.py +686 -0
- mdpsolver-0.9.8/tests/test2.py +81 -0
- mdpsolver-0.9.6/src/mdpsolver/solvermodule.cp310-win_amd64.pyd +0 -0
- mdpsolver-0.9.6/src/mdpsolver/solvermodule.cp311-win_amd64.pyd +0 -0
- mdpsolver-0.9.6/src/mdpsolver/solvermodule.cp312-win_amd64.pyd +0 -0
- mdpsolver-0.9.6/src/mdpsolver/solvermodule.cpython-310-x86_64-linux-gnu.so +0 -0
- mdpsolver-0.9.6/src/mdpsolver/solvermodule.cpython-311-x86_64-linux-gnu.so +0 -0
- mdpsolver-0.9.6/src/mdpsolver/solvermodule.cpython-312-x86_64-linux-gnu.so +0 -0
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/MANIFEST.in +0 -0
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/setup.cfg +0 -0
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver/__init__.py +0 -0
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver/problems/__pycache__/cbmaux.cpython-310.pyc +0 -0
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver/problems/__pycache__/tbmaux.cpython-310.pyc +0 -0
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver/problems/cbmaux.py +0 -0
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver/problems/tbmaux.py +0 -0
- {mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver.egg-info/dependency_links.txt +0 -0
- {mdpsolver-0.9.6 → 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)
|
|
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
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: mdpsolver
|
|
3
|
-
Version: 0.9.
|
|
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 <
|
|
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
|
|
@@ -17,13 +17,14 @@ License-File: LICENSE
|
|
|
17
17
|
|
|
18
18
|
<img src="https://github.com/areenberg/MDPSolver/blob/anders_development/Images/MDPSolver_logo_3.png" alt="Logo" width="180">
|
|
19
19
|
|
|
20
|
-
MDPSolver is a Python package for Markov Decision Processes (MDPs) with
|
|
20
|
+
MDPSolver is a Python package for large Markov Decision Processes (MDPs) with infinite-horizons.
|
|
21
21
|
|
|
22
22
|
## Features
|
|
23
23
|
|
|
24
24
|
* Fast solver: Our C++-based solver is substantially faster than other MDP packages available for Python. See details in the documentation.
|
|
25
|
+
* Two optimality criteria: *Discounted* and *Average* reward.
|
|
25
26
|
* Three optimization algorithms: *Value iteration*, *Policy iteration*, and *Modified policy iteration*.
|
|
26
|
-
* Three value-update methods: *Standard*, *Gauss–Seidel*, *Successive over-relaxation*.
|
|
27
|
+
* Three value-update methods: *Standard*, *Gauss–Seidel*, and *Successive over-relaxation*.
|
|
27
28
|
* Supports sparse matrices.
|
|
28
29
|
* Employs parallel computing.
|
|
29
30
|
|
|
@@ -37,7 +38,11 @@ Install directly from PyPI with:
|
|
|
37
38
|
pip install mdpsolver
|
|
38
39
|
```
|
|
39
40
|
|
|
40
|
-
|
|
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).
|
|
41
46
|
|
|
42
47
|
## Windows
|
|
43
48
|
|
|
@@ -156,7 +161,7 @@ mdl.mdp(discount=0.8,
|
|
|
156
161
|
|
|
157
162
|
# Documentation
|
|
158
163
|
|
|
159
|
-
The documentation can be found in the wiki for MDPSolver
|
|
164
|
+
The documentation can be found in the [wiki for MDPSolver](https://github.com/areenberg/MDPSolver/wiki).
|
|
160
165
|
|
|
161
166
|
# How to cite
|
|
162
167
|
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
<img src="https://github.com/areenberg/MDPSolver/blob/anders_development/Images/MDPSolver_logo_3.png" alt="Logo" width="180">
|
|
4
4
|
|
|
5
|
-
MDPSolver is a Python package for Markov Decision Processes (MDPs) with
|
|
5
|
+
MDPSolver is a Python package for large Markov Decision Processes (MDPs) with infinite-horizons.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
* Fast solver: Our C++-based solver is substantially faster than other MDP packages available for Python. See details in the documentation.
|
|
10
|
+
* Two optimality criteria: *Discounted* and *Average* reward.
|
|
10
11
|
* Three optimization algorithms: *Value iteration*, *Policy iteration*, and *Modified policy iteration*.
|
|
11
|
-
* Three value-update methods: *Standard*, *Gauss–Seidel*, *Successive over-relaxation*.
|
|
12
|
+
* Three value-update methods: *Standard*, *Gauss–Seidel*, and *Successive over-relaxation*.
|
|
12
13
|
* Supports sparse matrices.
|
|
13
14
|
* Employs parallel computing.
|
|
14
15
|
|
|
@@ -22,7 +23,11 @@ Install directly from PyPI with:
|
|
|
22
23
|
pip install mdpsolver
|
|
23
24
|
```
|
|
24
25
|
|
|
25
|
-
|
|
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).
|
|
26
31
|
|
|
27
32
|
## Windows
|
|
28
33
|
|
|
@@ -141,8 +146,8 @@ mdl.mdp(discount=0.8,
|
|
|
141
146
|
|
|
142
147
|
# Documentation
|
|
143
148
|
|
|
144
|
-
The documentation can be found in the wiki for MDPSolver
|
|
149
|
+
The documentation can be found in the [wiki for MDPSolver](https://github.com/areenberg/MDPSolver/wiki).
|
|
145
150
|
|
|
146
151
|
# How to cite
|
|
147
152
|
|
|
148
|
-
[](https://zenodo.org/badge/latestdoi/294063917)
|
|
153
|
+
[](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.
|
|
13
|
+
version = "0.9.8"
|
|
14
14
|
authors = [
|
|
15
15
|
{ name="Anders Reenberg Andersen", email="andersra@live.dk" },
|
|
16
|
-
{ name="Jesper Fink Andersen", email="
|
|
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"
|
|
@@ -17,6 +17,7 @@ class model:
|
|
|
17
17
|
algorithm="mpi",
|
|
18
18
|
tolerance=1e-3,
|
|
19
19
|
update="standard",
|
|
20
|
+
criterion="discounted",
|
|
20
21
|
parIterLim=100,
|
|
21
22
|
SORrelaxation=1.0,
|
|
22
23
|
initPolicy=list(),
|
|
@@ -29,6 +30,7 @@ class model:
|
|
|
29
30
|
self.mdl.solve(algorithm=algorithm,
|
|
30
31
|
tolerance=tolerance,
|
|
31
32
|
update=update,
|
|
33
|
+
criterion=criterion,
|
|
32
34
|
parIterLim=parIterLim,
|
|
33
35
|
SORrelaxation=SORrelaxation,
|
|
34
36
|
initPolicy=initPolicy,
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: mdpsolver
|
|
3
|
-
Version: 0.9.
|
|
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 <
|
|
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
|
|
@@ -17,13 +17,14 @@ License-File: LICENSE
|
|
|
17
17
|
|
|
18
18
|
<img src="https://github.com/areenberg/MDPSolver/blob/anders_development/Images/MDPSolver_logo_3.png" alt="Logo" width="180">
|
|
19
19
|
|
|
20
|
-
MDPSolver is a Python package for Markov Decision Processes (MDPs) with
|
|
20
|
+
MDPSolver is a Python package for large Markov Decision Processes (MDPs) with infinite-horizons.
|
|
21
21
|
|
|
22
22
|
## Features
|
|
23
23
|
|
|
24
24
|
* Fast solver: Our C++-based solver is substantially faster than other MDP packages available for Python. See details in the documentation.
|
|
25
|
+
* Two optimality criteria: *Discounted* and *Average* reward.
|
|
25
26
|
* Three optimization algorithms: *Value iteration*, *Policy iteration*, and *Modified policy iteration*.
|
|
26
|
-
* Three value-update methods: *Standard*, *Gauss–Seidel*, *Successive over-relaxation*.
|
|
27
|
+
* Three value-update methods: *Standard*, *Gauss–Seidel*, and *Successive over-relaxation*.
|
|
27
28
|
* Supports sparse matrices.
|
|
28
29
|
* Employs parallel computing.
|
|
29
30
|
|
|
@@ -37,7 +38,11 @@ Install directly from PyPI with:
|
|
|
37
38
|
pip install mdpsolver
|
|
38
39
|
```
|
|
39
40
|
|
|
40
|
-
|
|
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).
|
|
41
46
|
|
|
42
47
|
## Windows
|
|
43
48
|
|
|
@@ -156,7 +161,7 @@ mdl.mdp(discount=0.8,
|
|
|
156
161
|
|
|
157
162
|
# Documentation
|
|
158
163
|
|
|
159
|
-
The documentation can be found in the wiki for MDPSolver
|
|
164
|
+
The documentation can be found in the [wiki for MDPSolver](https://github.com/areenberg/MDPSolver/wiki).
|
|
160
165
|
|
|
161
166
|
# How to cite
|
|
162
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
|
|
@@ -17,4 +19,6 @@ src/mdpsolver.egg-info/top_level.txt
|
|
|
17
19
|
src/mdpsolver/problems/cbmaux.py
|
|
18
20
|
src/mdpsolver/problems/tbmaux.py
|
|
19
21
|
src/mdpsolver/problems/__pycache__/cbmaux.cpython-310.pyc
|
|
20
|
-
src/mdpsolver/problems/__pycache__/tbmaux.cpython-310.pyc
|
|
22
|
+
src/mdpsolver/problems/__pycache__/tbmaux.cpython-310.pyc
|
|
23
|
+
tests/test1.py
|
|
24
|
+
tests/test2.py
|
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
import mdpsolver
|
|
2
|
+
import random
|
|
3
|
+
import sys
|
|
4
|
+
import numpy as np
|
|
5
|
+
from random import randint
|
|
6
|
+
|
|
7
|
+
#TEST 1
|
|
8
|
+
#Simple MDP with 3 states and 2 actions in each state.
|
|
9
|
+
|
|
10
|
+
#---------------------------------------
|
|
11
|
+
# CONFIGURATION 1
|
|
12
|
+
#---------------------------------------
|
|
13
|
+
|
|
14
|
+
#rewards
|
|
15
|
+
#1st index: from (current) states
|
|
16
|
+
#2nd index: actions
|
|
17
|
+
rewards = [[5,-1],
|
|
18
|
+
[1,-2],
|
|
19
|
+
[50,0]]
|
|
20
|
+
|
|
21
|
+
#transition probabilities
|
|
22
|
+
#1st index: from (current) states
|
|
23
|
+
#2nd index: actions
|
|
24
|
+
#3rd index: to (next) states
|
|
25
|
+
tranMatWithZeros = [[[0.9,0.1,0.0],[0.1,0.9,0.0]],
|
|
26
|
+
[[0.4,0.5,0.1],[0.3,0.5,0.2]],
|
|
27
|
+
[[0.2,0.2,0.6],[0.5,0.5,0.0]]]
|
|
28
|
+
|
|
29
|
+
#initial policy
|
|
30
|
+
random.seed(10)
|
|
31
|
+
initPolicy = [randint(0, 1) for p in range(0, 3)]
|
|
32
|
+
|
|
33
|
+
#Model 1a (discounted reward, parallel)
|
|
34
|
+
mdl1a = mdpsolver.model()
|
|
35
|
+
mdl1a.mdp(discount=0.95,
|
|
36
|
+
rewards=rewards,
|
|
37
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
38
|
+
mdl1a.solve(algorithm="mpi",
|
|
39
|
+
update="standard",
|
|
40
|
+
parallel=True,
|
|
41
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
46
|
+
|
|
47
|
+
#Model 2a (discounted reward, parallel)
|
|
48
|
+
mdl2a = mdpsolver.model()
|
|
49
|
+
mdl2a.mdp(discount=0.95,
|
|
50
|
+
rewards=rewards,
|
|
51
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
52
|
+
mdl2a.solve(algorithm="pi",
|
|
53
|
+
update="standard",
|
|
54
|
+
parallel=True,
|
|
55
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
60
|
+
|
|
61
|
+
#Model 3a (discounted reward, parallel)
|
|
62
|
+
mdl3a = mdpsolver.model()
|
|
63
|
+
mdl3a.mdp(discount=0.95,
|
|
64
|
+
rewards=rewards,
|
|
65
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
66
|
+
mdl3a.solve(algorithm="vi",
|
|
67
|
+
update="standard",
|
|
68
|
+
parallel=True)
|
|
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!")
|
|
73
|
+
|
|
74
|
+
#Model 1b (discounted reward, unparallel)
|
|
75
|
+
mdl1b = mdpsolver.model()
|
|
76
|
+
mdl1b.mdp(discount=0.95,
|
|
77
|
+
rewards=rewards,
|
|
78
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
79
|
+
mdl1b.solve(algorithm="mpi",
|
|
80
|
+
update="standard",
|
|
81
|
+
parallel=False,
|
|
82
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
87
|
+
|
|
88
|
+
#Model 2b (discounted reward, unparallel)
|
|
89
|
+
mdl2b = mdpsolver.model()
|
|
90
|
+
mdl2b.mdp(discount=0.95,
|
|
91
|
+
rewards=rewards,
|
|
92
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
93
|
+
mdl2b.solve(algorithm="pi",
|
|
94
|
+
update="standard",
|
|
95
|
+
parallel=False,
|
|
96
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
101
|
+
|
|
102
|
+
#Model 3b (discounted reward, unparallel)
|
|
103
|
+
mdl3b = mdpsolver.model()
|
|
104
|
+
mdl3b.mdp(discount=0.95,
|
|
105
|
+
rewards=rewards,
|
|
106
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
107
|
+
mdl3b.solve(algorithm="vi",
|
|
108
|
+
update="standard",
|
|
109
|
+
parallel=False)
|
|
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!")
|
|
114
|
+
|
|
115
|
+
#Model 1a (average reward, parallel)
|
|
116
|
+
mdl1a = mdpsolver.model()
|
|
117
|
+
mdl1a.mdp(rewards=rewards,
|
|
118
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
119
|
+
mdl1a.solve(algorithm="mpi",
|
|
120
|
+
update="standard",
|
|
121
|
+
criterion="average",
|
|
122
|
+
parallel=True,
|
|
123
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
128
|
+
|
|
129
|
+
#Model 2a (average reward, parallel)
|
|
130
|
+
mdl2a = mdpsolver.model()
|
|
131
|
+
mdl2a.mdp(rewards=rewards,
|
|
132
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
133
|
+
mdl2a.solve(algorithm="pi",
|
|
134
|
+
update="standard",
|
|
135
|
+
criterion="average",
|
|
136
|
+
parallel=True,
|
|
137
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
142
|
+
|
|
143
|
+
#Model 3a (average reward, parallel)
|
|
144
|
+
mdl3a = mdpsolver.model()
|
|
145
|
+
mdl3a.mdp(rewards=rewards,
|
|
146
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
147
|
+
mdl3a.solve(algorithm="vi",
|
|
148
|
+
update="standard",
|
|
149
|
+
criterion="average",
|
|
150
|
+
parallel=True)
|
|
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!")
|
|
155
|
+
|
|
156
|
+
#Model 1b (average reward, unparallel)
|
|
157
|
+
mdl1b = mdpsolver.model()
|
|
158
|
+
mdl1b.mdp(rewards=rewards,
|
|
159
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
160
|
+
mdl1b.solve(algorithm="mpi",
|
|
161
|
+
update="standard",
|
|
162
|
+
criterion="average",
|
|
163
|
+
parallel=False,
|
|
164
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
169
|
+
|
|
170
|
+
#Model 2b (average reward, unparallel)
|
|
171
|
+
mdl2b = mdpsolver.model()
|
|
172
|
+
mdl2b.mdp(rewards=rewards,
|
|
173
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
174
|
+
mdl2b.solve(algorithm="pi",
|
|
175
|
+
update="standard",
|
|
176
|
+
criterion="average",
|
|
177
|
+
parallel=False,
|
|
178
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
183
|
+
|
|
184
|
+
#Model 3b (average reward, unparallel)
|
|
185
|
+
mdl3b = mdpsolver.model()
|
|
186
|
+
mdl3b.mdp(rewards=rewards,
|
|
187
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
188
|
+
mdl3b.solve(algorithm="vi",
|
|
189
|
+
update="standard",
|
|
190
|
+
criterion="average",
|
|
191
|
+
parallel=False)
|
|
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!")
|
|
196
|
+
|
|
197
|
+
#Model 1c (discounted, Gauss-Seidel)
|
|
198
|
+
mdl1c = mdpsolver.model()
|
|
199
|
+
mdl1c.mdp(discount=0.95,
|
|
200
|
+
rewards=rewards,
|
|
201
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
202
|
+
mdl1c.solve(algorithm="mpi",
|
|
203
|
+
update="gs",
|
|
204
|
+
parallel=False,
|
|
205
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
210
|
+
|
|
211
|
+
#Model 2c (Gauss-Seidel)
|
|
212
|
+
initPolicy=[1,1,1]
|
|
213
|
+
mdl2c = mdpsolver.model()
|
|
214
|
+
mdl2c.mdp(discount=0.95,
|
|
215
|
+
rewards=rewards,
|
|
216
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
217
|
+
mdl2c.solve(algorithm="pi",
|
|
218
|
+
update="gs",
|
|
219
|
+
parallel=False,
|
|
220
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
225
|
+
|
|
226
|
+
#Model 3c (Gauss-Seidel)
|
|
227
|
+
mdl3c = mdpsolver.model()
|
|
228
|
+
mdl3c.mdp(discount=0.95,
|
|
229
|
+
rewards=rewards,
|
|
230
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
231
|
+
mdl3c.solve(algorithm="vi",
|
|
232
|
+
update="gs",
|
|
233
|
+
parallel=False)
|
|
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!")
|
|
238
|
+
|
|
239
|
+
#Model 1d (SOR)
|
|
240
|
+
mdl1d = mdpsolver.model()
|
|
241
|
+
mdl1d.mdp(discount=0.95,
|
|
242
|
+
rewards=rewards,
|
|
243
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
244
|
+
mdl1d.solve(algorithm="mpi",
|
|
245
|
+
update="sor",
|
|
246
|
+
SORrelaxation=1.01,
|
|
247
|
+
parallel=False,
|
|
248
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
253
|
+
|
|
254
|
+
#Model 2d (SOR)
|
|
255
|
+
mdl2d = mdpsolver.model()
|
|
256
|
+
mdl2d.mdp(discount=0.95,
|
|
257
|
+
rewards=rewards,
|
|
258
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
259
|
+
mdl2d.solve(algorithm="pi",
|
|
260
|
+
update="sor",
|
|
261
|
+
SORrelaxation=1.01,
|
|
262
|
+
parallel=False,
|
|
263
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
268
|
+
|
|
269
|
+
#Model 3d (SOR)
|
|
270
|
+
mdl3d = mdpsolver.model()
|
|
271
|
+
mdl3d.mdp(discount=0.95,
|
|
272
|
+
rewards=rewards,
|
|
273
|
+
tranMatWithZeros=tranMatWithZeros)
|
|
274
|
+
mdl3d.solve(algorithm="vi",
|
|
275
|
+
update="sor",
|
|
276
|
+
SORrelaxation=1.01,
|
|
277
|
+
parallel=False)
|
|
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!")
|
|
282
|
+
|
|
283
|
+
#---------------------------------------
|
|
284
|
+
# CONFIGURATION 2
|
|
285
|
+
#---------------------------------------
|
|
286
|
+
|
|
287
|
+
#rewards
|
|
288
|
+
#1st index: from (current) states
|
|
289
|
+
#2nd index: actions
|
|
290
|
+
rewards = [[5,-1],
|
|
291
|
+
[1,-2],
|
|
292
|
+
[50,0]]
|
|
293
|
+
|
|
294
|
+
#transition probabilities
|
|
295
|
+
#[from_state,action,to_state,probability]
|
|
296
|
+
tranMatElementwise = [[0,0,0,0.9],
|
|
297
|
+
[0,0,1,0.1],
|
|
298
|
+
[0,1,0,0.1],
|
|
299
|
+
[0,1,1,0.9],
|
|
300
|
+
[1,0,0,0.4],
|
|
301
|
+
[1,0,1,0.5],
|
|
302
|
+
[1,0,2,0.1],
|
|
303
|
+
[1,1,0,0.3],
|
|
304
|
+
[1,1,1,0.5],
|
|
305
|
+
[1,1,2,0.2],
|
|
306
|
+
[2,0,0,0.2],
|
|
307
|
+
[2,0,1,0.2],
|
|
308
|
+
[2,0,2,0.6],
|
|
309
|
+
[2,1,0,0.5],
|
|
310
|
+
[2,1,1,0.5]]
|
|
311
|
+
|
|
312
|
+
#initial policy
|
|
313
|
+
random.seed(10)
|
|
314
|
+
initPolicy = [randint(0, 1) for p in range(0, 3)]
|
|
315
|
+
|
|
316
|
+
#Model 1a
|
|
317
|
+
mdl1a = mdpsolver.model()
|
|
318
|
+
mdl1a.mdp(discount=0.95,
|
|
319
|
+
rewards=rewards,
|
|
320
|
+
tranMatElementwise=tranMatElementwise)
|
|
321
|
+
mdl1a.solve(algorithm="mpi",
|
|
322
|
+
update="standard",
|
|
323
|
+
parallel=True,
|
|
324
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
329
|
+
|
|
330
|
+
#Model 2a
|
|
331
|
+
mdl2a = mdpsolver.model()
|
|
332
|
+
mdl2a.mdp(discount=0.95,
|
|
333
|
+
rewards=rewards,
|
|
334
|
+
tranMatElementwise=tranMatElementwise)
|
|
335
|
+
mdl2a.solve(algorithm="pi",
|
|
336
|
+
update="standard",
|
|
337
|
+
parallel=True,
|
|
338
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
343
|
+
|
|
344
|
+
#Model 3a
|
|
345
|
+
mdl3a = mdpsolver.model()
|
|
346
|
+
mdl3a.mdp(discount=0.95,
|
|
347
|
+
rewards=rewards,
|
|
348
|
+
tranMatElementwise=tranMatElementwise)
|
|
349
|
+
mdl3a.solve(algorithm="vi",
|
|
350
|
+
update="standard",
|
|
351
|
+
parallel=True)
|
|
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!")
|
|
356
|
+
|
|
357
|
+
#Model 1b
|
|
358
|
+
mdl1b = mdpsolver.model()
|
|
359
|
+
mdl1b.mdp(discount=0.95,
|
|
360
|
+
rewards=rewards,
|
|
361
|
+
tranMatElementwise=tranMatElementwise)
|
|
362
|
+
mdl1b.solve(algorithm="mpi",
|
|
363
|
+
update="standard",
|
|
364
|
+
parallel=False,
|
|
365
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
370
|
+
|
|
371
|
+
#Model 2b
|
|
372
|
+
mdl2b = mdpsolver.model()
|
|
373
|
+
mdl2b.mdp(discount=0.95,
|
|
374
|
+
rewards=rewards,
|
|
375
|
+
tranMatElementwise=tranMatElementwise)
|
|
376
|
+
mdl2b.solve(algorithm="pi",
|
|
377
|
+
update="standard",
|
|
378
|
+
parallel=False,
|
|
379
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
384
|
+
|
|
385
|
+
#Model 3b
|
|
386
|
+
mdl3b = mdpsolver.model()
|
|
387
|
+
mdl3b.mdp(discount=0.95,
|
|
388
|
+
rewards=rewards,
|
|
389
|
+
tranMatElementwise=tranMatElementwise)
|
|
390
|
+
mdl3b.solve(algorithm="vi",
|
|
391
|
+
update="standard",
|
|
392
|
+
parallel=False)
|
|
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!")
|
|
397
|
+
|
|
398
|
+
#Model 1c
|
|
399
|
+
mdl1c = mdpsolver.model()
|
|
400
|
+
mdl1c.mdp(discount=0.95,
|
|
401
|
+
rewards=rewards,
|
|
402
|
+
tranMatElementwise=tranMatElementwise)
|
|
403
|
+
mdl1c.solve(algorithm="mpi",
|
|
404
|
+
update="gs",
|
|
405
|
+
parallel=False,
|
|
406
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
411
|
+
|
|
412
|
+
#Model 2c
|
|
413
|
+
mdl2c = mdpsolver.model()
|
|
414
|
+
mdl2c.mdp(discount=0.95,
|
|
415
|
+
rewards=rewards,
|
|
416
|
+
tranMatElementwise=tranMatElementwise)
|
|
417
|
+
mdl2c.solve(algorithm="pi",
|
|
418
|
+
update="gs",
|
|
419
|
+
parallel=False,
|
|
420
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
425
|
+
|
|
426
|
+
#Model 3c
|
|
427
|
+
mdl3c = mdpsolver.model()
|
|
428
|
+
mdl3c.mdp(discount=0.95,
|
|
429
|
+
rewards=rewards,
|
|
430
|
+
tranMatElementwise=tranMatElementwise)
|
|
431
|
+
mdl3c.solve(algorithm="vi",
|
|
432
|
+
update="gs",
|
|
433
|
+
parallel=False)
|
|
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!")
|
|
438
|
+
|
|
439
|
+
#Model 1d
|
|
440
|
+
mdl1d = mdpsolver.model()
|
|
441
|
+
mdl1d.mdp(discount=0.95,
|
|
442
|
+
rewards=rewards,
|
|
443
|
+
tranMatElementwise=tranMatElementwise)
|
|
444
|
+
mdl1d.solve(algorithm="mpi",
|
|
445
|
+
update="sor",
|
|
446
|
+
SORrelaxation=1.01,
|
|
447
|
+
parallel=False,
|
|
448
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
453
|
+
|
|
454
|
+
#Model 2d
|
|
455
|
+
mdl2d = mdpsolver.model()
|
|
456
|
+
mdl2d.mdp(discount=0.95,
|
|
457
|
+
rewards=rewards,
|
|
458
|
+
tranMatElementwise=tranMatElementwise)
|
|
459
|
+
mdl2d.solve(algorithm="pi",
|
|
460
|
+
update="sor",
|
|
461
|
+
SORrelaxation=1.01,
|
|
462
|
+
parallel=False,
|
|
463
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
468
|
+
|
|
469
|
+
#Model 3d
|
|
470
|
+
mdl3d = mdpsolver.model()
|
|
471
|
+
mdl3d.mdp(discount=0.95,
|
|
472
|
+
rewards=rewards,
|
|
473
|
+
tranMatElementwise=tranMatElementwise)
|
|
474
|
+
mdl3d.solve(algorithm="vi",
|
|
475
|
+
update="sor",
|
|
476
|
+
SORrelaxation=1.01,
|
|
477
|
+
parallel=False)
|
|
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!")
|
|
482
|
+
|
|
483
|
+
#---------------------------------------
|
|
484
|
+
# CONFIGURATION 3
|
|
485
|
+
#---------------------------------------
|
|
486
|
+
|
|
487
|
+
#rewards
|
|
488
|
+
#1st index: from (current) states
|
|
489
|
+
#2nd index: actions
|
|
490
|
+
rewards = [[5,-1],
|
|
491
|
+
[1,-2],
|
|
492
|
+
[50,0]]
|
|
493
|
+
|
|
494
|
+
#transition probabilities
|
|
495
|
+
tranMatProbs = [[[0.9,0.1],[0.1,0.9]],
|
|
496
|
+
[[0.4,0.5,0.1],[0.3,0.5,0.2]],
|
|
497
|
+
[[0.2,0.2,0.6],[0.5,0.5]]]
|
|
498
|
+
|
|
499
|
+
tranMatColumns = [[[0,1],[0,1]],
|
|
500
|
+
[[0,1,2],[0,1,2]],
|
|
501
|
+
[[0,1,2],[0,1]]]
|
|
502
|
+
|
|
503
|
+
#initial policy
|
|
504
|
+
random.seed(10)
|
|
505
|
+
initPolicy = [randint(0, 1) for p in range(0, 3)]
|
|
506
|
+
|
|
507
|
+
#Model 1a
|
|
508
|
+
mdl1a = mdpsolver.model()
|
|
509
|
+
mdl1a.mdp(discount=0.95,
|
|
510
|
+
rewards=rewards,
|
|
511
|
+
tranMatProbs=tranMatProbs,
|
|
512
|
+
tranMatColumns=tranMatColumns)
|
|
513
|
+
mdl1a.solve(algorithm="mpi",
|
|
514
|
+
update="standard",
|
|
515
|
+
parallel=True,
|
|
516
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
521
|
+
|
|
522
|
+
#Model 2a
|
|
523
|
+
mdl2a = mdpsolver.model()
|
|
524
|
+
mdl2a.mdp(discount=0.95,
|
|
525
|
+
rewards=rewards,
|
|
526
|
+
tranMatProbs=tranMatProbs,
|
|
527
|
+
tranMatColumns=tranMatColumns)
|
|
528
|
+
mdl2a.solve(algorithm="pi",
|
|
529
|
+
update="standard",
|
|
530
|
+
parallel=True,
|
|
531
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
536
|
+
|
|
537
|
+
#Model 3a
|
|
538
|
+
mdl3a = mdpsolver.model()
|
|
539
|
+
mdl3a.mdp(discount=0.95,
|
|
540
|
+
rewards=rewards,
|
|
541
|
+
tranMatProbs=tranMatProbs,
|
|
542
|
+
tranMatColumns=tranMatColumns)
|
|
543
|
+
mdl3a.solve(algorithm="vi",
|
|
544
|
+
update="standard",
|
|
545
|
+
parallel=True)
|
|
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!")
|
|
550
|
+
|
|
551
|
+
#Model 1b
|
|
552
|
+
mdl1b = mdpsolver.model()
|
|
553
|
+
mdl1b.mdp(discount=0.95,
|
|
554
|
+
rewards=rewards,
|
|
555
|
+
tranMatProbs=tranMatProbs,
|
|
556
|
+
tranMatColumns=tranMatColumns)
|
|
557
|
+
mdl1b.solve(algorithm="mpi",
|
|
558
|
+
update="standard",
|
|
559
|
+
parallel=False,
|
|
560
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
565
|
+
|
|
566
|
+
#Model 2b
|
|
567
|
+
mdl2b = mdpsolver.model()
|
|
568
|
+
mdl2b.mdp(discount=0.95,
|
|
569
|
+
rewards=rewards,
|
|
570
|
+
tranMatProbs=tranMatProbs,
|
|
571
|
+
tranMatColumns=tranMatColumns)
|
|
572
|
+
mdl2b.solve(algorithm="pi",
|
|
573
|
+
update="standard",
|
|
574
|
+
parallel=False,
|
|
575
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
580
|
+
|
|
581
|
+
#Model 3b
|
|
582
|
+
mdl3b = mdpsolver.model()
|
|
583
|
+
mdl3b.mdp(discount=0.95,
|
|
584
|
+
rewards=rewards,
|
|
585
|
+
tranMatProbs=tranMatProbs,
|
|
586
|
+
tranMatColumns=tranMatColumns)
|
|
587
|
+
mdl3b.solve(algorithm="vi",
|
|
588
|
+
update="standard",
|
|
589
|
+
parallel=False)
|
|
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!")
|
|
594
|
+
|
|
595
|
+
#Model 1c
|
|
596
|
+
mdl1c = mdpsolver.model()
|
|
597
|
+
mdl1c.mdp(discount=0.95,
|
|
598
|
+
rewards=rewards,
|
|
599
|
+
tranMatProbs=tranMatProbs,
|
|
600
|
+
tranMatColumns=tranMatColumns)
|
|
601
|
+
mdl1c.solve(algorithm="mpi",
|
|
602
|
+
update="gs",
|
|
603
|
+
parallel=False,
|
|
604
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
609
|
+
|
|
610
|
+
#Model 2c
|
|
611
|
+
mdl2c = mdpsolver.model()
|
|
612
|
+
mdl2c.mdp(discount=0.95,
|
|
613
|
+
rewards=rewards,
|
|
614
|
+
tranMatProbs=tranMatProbs,
|
|
615
|
+
tranMatColumns=tranMatColumns)
|
|
616
|
+
mdl2c.solve(algorithm="pi",
|
|
617
|
+
update="gs",
|
|
618
|
+
parallel=False,
|
|
619
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
624
|
+
|
|
625
|
+
#Model 3c
|
|
626
|
+
mdl3c = mdpsolver.model()
|
|
627
|
+
mdl3c.mdp(discount=0.95,
|
|
628
|
+
rewards=rewards,
|
|
629
|
+
tranMatProbs=tranMatProbs,
|
|
630
|
+
tranMatColumns=tranMatColumns)
|
|
631
|
+
mdl3c.solve(algorithm="vi",
|
|
632
|
+
update="gs",
|
|
633
|
+
parallel=False)
|
|
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!")
|
|
638
|
+
|
|
639
|
+
#Model 1d
|
|
640
|
+
mdl1d = mdpsolver.model()
|
|
641
|
+
mdl1d.mdp(discount=0.95,
|
|
642
|
+
rewards=rewards,
|
|
643
|
+
tranMatProbs=tranMatProbs,
|
|
644
|
+
tranMatColumns=tranMatColumns)
|
|
645
|
+
mdl1d.solve(algorithm="mpi",
|
|
646
|
+
update="sor",
|
|
647
|
+
SORrelaxation=1.01,
|
|
648
|
+
parallel=False,
|
|
649
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
654
|
+
|
|
655
|
+
#Model 2d
|
|
656
|
+
mdl2d = mdpsolver.model()
|
|
657
|
+
mdl2d.mdp(discount=0.95,
|
|
658
|
+
rewards=rewards,
|
|
659
|
+
tranMatProbs=tranMatProbs,
|
|
660
|
+
tranMatColumns=tranMatColumns)
|
|
661
|
+
mdl2d.solve(algorithm="pi",
|
|
662
|
+
update="sor",
|
|
663
|
+
SORrelaxation=1.01,
|
|
664
|
+
parallel=False,
|
|
665
|
+
initPolicy=initPolicy)
|
|
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!")
|
|
670
|
+
|
|
671
|
+
#Model 3d
|
|
672
|
+
mdl3d = mdpsolver.model()
|
|
673
|
+
mdl3d.mdp(discount=0.95,
|
|
674
|
+
rewards=rewards,
|
|
675
|
+
tranMatProbs=tranMatProbs,
|
|
676
|
+
tranMatColumns=tranMatColumns)
|
|
677
|
+
mdl3d.solve(algorithm="vi",
|
|
678
|
+
update="sor",
|
|
679
|
+
SORrelaxation=1.01,
|
|
680
|
+
parallel=False)
|
|
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!")
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import mdpsolver
|
|
2
|
+
import example_model
|
|
3
|
+
import sys
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
#TEST 2
|
|
7
|
+
#In this test, we load the rewards and transition probabilities
|
|
8
|
+
#from two CSV-files (rewards_example.csv and transitions.csv).
|
|
9
|
+
#In addition, we test three optimization algorithms and compare
|
|
10
|
+
#the runtimes.
|
|
11
|
+
|
|
12
|
+
#PROBLEM DESCRIPTION: We derive the policy for a decision problem
|
|
13
|
+
#involving a queueing system with finite capacity and two customer
|
|
14
|
+
#types. The system is observed whenever a new customer arrives.
|
|
15
|
+
#Customers are not allowed to wait and can only be accepted if there
|
|
16
|
+
#are idle servers. Thus, with each arrival, we must choose whether
|
|
17
|
+
#to accept or reject the customer. We receive a low reward for
|
|
18
|
+
#accepting the first, more common type, and a high reward for
|
|
19
|
+
#accepting the second, rarer type.
|
|
20
|
+
|
|
21
|
+
#---------------------------------------
|
|
22
|
+
# CREATE PARAMETERS
|
|
23
|
+
#---------------------------------------
|
|
24
|
+
|
|
25
|
+
#rewards
|
|
26
|
+
capacity=100
|
|
27
|
+
rewardCust1=1
|
|
28
|
+
rewardCust2=1000
|
|
29
|
+
example_model.rewards(capacity,rewardCust1,rewardCust2,"rewards_example2.csv")
|
|
30
|
+
|
|
31
|
+
#transitions
|
|
32
|
+
arrRate1=50
|
|
33
|
+
arrRate2=10
|
|
34
|
+
serRate=3/4
|
|
35
|
+
example_model.tranMat(arrRate1,arrRate2,serRate,capacity,"transitions_example2.csv")
|
|
36
|
+
|
|
37
|
+
#---------------------------------------
|
|
38
|
+
# VALUE ITERATION
|
|
39
|
+
#---------------------------------------
|
|
40
|
+
|
|
41
|
+
mdl1 = mdpsolver.model()
|
|
42
|
+
|
|
43
|
+
mdl1.mdp(discount=0.99,
|
|
44
|
+
rewardsFromFile="rewards_example2.csv",
|
|
45
|
+
tranMatFromFile="transitions_example2.csv")
|
|
46
|
+
|
|
47
|
+
mdl1.solve(algorithm="vi")
|
|
48
|
+
if not np.round(np.mean(mdl1.getValueVector()),6)==np.round(17074.81609832942,6):
|
|
49
|
+
sys.exit("Model 1 failed!")
|
|
50
|
+
|
|
51
|
+
#---------------------------------------
|
|
52
|
+
# POLICY ITERATION
|
|
53
|
+
#---------------------------------------
|
|
54
|
+
|
|
55
|
+
mdl2 = mdpsolver.model()
|
|
56
|
+
|
|
57
|
+
mdl2.mdp(discount=0.99,
|
|
58
|
+
rewardsFromFile="rewards_example2.csv",
|
|
59
|
+
tranMatFromFile="transitions_example2.csv")
|
|
60
|
+
|
|
61
|
+
mdl2.solve(algorithm="pi")
|
|
62
|
+
|
|
63
|
+
if not np.round(np.mean(mdl2.getValueVector()),6)==np.round(17074.815578793514,6):
|
|
64
|
+
sys.exit("Model 2 failed!")
|
|
65
|
+
|
|
66
|
+
#---------------------------------------
|
|
67
|
+
# MODIFIED POLICY ITERATION
|
|
68
|
+
#---------------------------------------
|
|
69
|
+
|
|
70
|
+
mdl3 = mdpsolver.model()
|
|
71
|
+
|
|
72
|
+
mdl3.mdp(discount=0.99,
|
|
73
|
+
rewardsFromFile="rewards_example2.csv",
|
|
74
|
+
tranMatFromFile="transitions_example2.csv")
|
|
75
|
+
|
|
76
|
+
mdl3.solve(algorithm="mpi")
|
|
77
|
+
|
|
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!")
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver/problems/__pycache__/cbmaux.cpython-310.pyc
RENAMED
|
File without changes
|
{mdpsolver-0.9.6 → mdpsolver-0.9.8}/src/mdpsolver/problems/__pycache__/tbmaux.cpython-310.pyc
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|