mdpsolver 0.9.7__tar.gz → 0.9.9__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 (32) hide show
  1. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/LICENSE +1 -1
  2. {mdpsolver-0.9.7/src/mdpsolver.egg-info → mdpsolver-0.9.9}/PKG-INFO +12 -6
  3. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/README.md +7 -3
  4. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/pyproject.toml +4 -3
  5. mdpsolver-0.9.9/src/mdpsolver/__init__.py +1 -0
  6. mdpsolver-0.9.9/src/mdpsolver/model.py +189 -0
  7. mdpsolver-0.9.9/src/mdpsolver/problems/cbmaux.py +40 -0
  8. mdpsolver-0.9.9/src/mdpsolver/problems/tbmaux.py +40 -0
  9. mdpsolver-0.9.9/src/mdpsolver/solvermodule.cp313-win_amd64.pyd +0 -0
  10. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver/solvermodule.cpython-310-x86_64-linux-gnu.so +0 -0
  11. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver/solvermodule.cpython-311-x86_64-linux-gnu.so +0 -0
  12. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver/solvermodule.cpython-312-x86_64-linux-gnu.so +0 -0
  13. mdpsolver-0.9.9/src/mdpsolver/solvermodule.cpython-313-x86_64-linux-gnu.so +0 -0
  14. {mdpsolver-0.9.7 → mdpsolver-0.9.9/src/mdpsolver.egg-info}/PKG-INFO +12 -6
  15. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver.egg-info/SOURCES.txt +2 -0
  16. mdpsolver-0.9.9/tests/test1.py +713 -0
  17. mdpsolver-0.9.9/tests/test2.py +87 -0
  18. mdpsolver-0.9.7/src/mdpsolver/__init__.py +0 -1
  19. mdpsolver-0.9.7/src/mdpsolver/model.py +0 -139
  20. mdpsolver-0.9.7/src/mdpsolver/problems/cbmaux.py +0 -39
  21. mdpsolver-0.9.7/src/mdpsolver/problems/tbmaux.py +0 -39
  22. mdpsolver-0.9.7/tests/test1.py +0 -646
  23. mdpsolver-0.9.7/tests/test2.py +0 -75
  24. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/MANIFEST.in +0 -0
  25. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/setup.cfg +0 -0
  26. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver/problems/__pycache__/cbmaux.cpython-310.pyc +0 -0
  27. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver/problems/__pycache__/tbmaux.cpython-310.pyc +0 -0
  28. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver/solvermodule.cp310-win_amd64.pyd +0 -0
  29. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver/solvermodule.cp311-win_amd64.pyd +0 -0
  30. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver/solvermodule.cp312-win_amd64.pyd +0 -0
  31. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/src/mdpsolver.egg-info/dependency_links.txt +0 -0
  32. {mdpsolver-0.9.7 → mdpsolver-0.9.9}/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,17 +1,19 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: mdpsolver
3
- Version: 0.9.7
3
+ Version: 0.9.9
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
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
11
+ Classifier: Operating System :: Microsoft :: Windows
12
+ Classifier: Operating System :: POSIX :: Linux
12
13
  Requires-Python: >=3.10
13
14
  Description-Content-Type: text/markdown
14
15
  License-File: LICENSE
16
+ Dynamic: license-file
15
17
 
16
18
  # MDPSolver
17
19
 
@@ -38,7 +40,11 @@ Install directly from PyPI with:
38
40
  pip install mdpsolver
39
41
  ```
40
42
 
41
- MDPSolver works *out of the box* on Linux.
43
+ MDPSolver works *out of the box* on Ubuntu 22 and newer.
44
+
45
+ ### GLIBC not found
46
+
47
+ 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
48
 
43
49
  ## Windows
44
50
 
@@ -157,7 +163,7 @@ mdl.mdp(discount=0.8,
157
163
 
158
164
  # Documentation
159
165
 
160
- The documentation can be found in the wiki for MDPSolver (https://github.com/areenberg/MDPSolver/wiki).
166
+ The documentation can be found in the [wiki for MDPSolver](https://github.com/areenberg/MDPSolver/wiki).
161
167
 
162
168
  # How to cite
163
169
 
@@ -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.9"
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"
@@ -22,7 +22,8 @@ classifiers = [
22
22
  "Development Status :: 3 - Alpha",
23
23
  "Programming Language :: Python :: 3",
24
24
  "License :: OSI Approved :: MIT License",
25
- "Operating System :: OS Independent",
25
+ "Operating System :: Microsoft :: Windows",
26
+ "Operating System :: POSIX :: Linux"
26
27
  ]
27
28
 
28
29
  [project.urls]
@@ -0,0 +1 @@
1
+ from mdpsolver.model import model
@@ -0,0 +1,189 @@
1
+ """
2
+ MDPSolver
3
+
4
+ This file defines a `model` class that wraps around the `solvermodule` to create
5
+ and solve Markov Decision Processes (MDPs). It provides methods to configure the model,
6
+ solve it, and extract the resulting policy and value vectors.
7
+ """
8
+
9
+ from mdpsolver import solvermodule
10
+
11
+
12
+ class model:
13
+ """
14
+ Creates an MDPSolver object.
15
+
16
+ This class provides methods to initialize, solve, and return results
17
+ from an MDP model.
18
+ """
19
+
20
+ def __init__(self):
21
+ """Initialize the model by creating a solver module object."""
22
+ self.initialize()
23
+
24
+ def initialize(self):
25
+ """Create and initialize the solver module object."""
26
+ self.mdl = solvermodule.Model()
27
+
28
+ def solve(
29
+ self,
30
+ algorithm="mpi",
31
+ tolerance=1e-3,
32
+ update="standard",
33
+ criterion="discounted",
34
+ parIterLim=100,
35
+ SORrelaxation=1.0,
36
+ initPolicy=list(),
37
+ initValueVector=list(),
38
+ verbose=False,
39
+ postProcessing=True,
40
+ makeFinalCheck=True,
41
+ parallel=True,
42
+ ):
43
+ """
44
+ Derive an epsilon-optimal policy for the selected MDP model.
45
+
46
+ Args:
47
+ algorithm (str): Algorithm to use.
48
+ tolerance (float): Convergence threshold for the algorithm.
49
+ update (str): The value-update method.
50
+ criterion (str): The optimality criterion.
51
+ parIterLim (int): The partial evaluation limit employed in the modified policy iteration algorithm.
52
+ SORrelaxation (float): Relaxation parameter for the Successive Over-Relaxation method.
53
+ initPolicy (list): A 1D-list defining the initial policy. This option can be used for "warm starting" the optimization procedure.
54
+ initValueVector (list): A 1D-list defining the initial value vector. This option can be used for "warm starting" the optimization procedure.
55
+ verbose (bool): If True, prints solver progress to console.
56
+ postProcessing (bool): If True, performs post-processing after solving.
57
+ makeFinalCheck (bool): If True, makes a final check of the value vector. This process checks if the resulting values are reasonable.
58
+ parallel (bool): If True, enables parallel computation for faster solving. This option is only available for the custom MDP model with standard updates.
59
+
60
+ Returns:
61
+ None
62
+ """
63
+ self.mdl.solve(
64
+ algorithm=algorithm,
65
+ tolerance=tolerance,
66
+ update=update,
67
+ criterion=criterion,
68
+ parIterLim=parIterLim,
69
+ SORrelaxation=SORrelaxation,
70
+ initPolicy=initPolicy,
71
+ initValueVector=initValueVector,
72
+ verbose=verbose,
73
+ postProcessing=postProcessing,
74
+ makeFinalCheck=makeFinalCheck,
75
+ parallel=parallel,
76
+ )
77
+
78
+ def getRuntime(self):
79
+ """
80
+ Get the runtime of the last solver execution.
81
+
82
+ Returns:
83
+ float: Runtime in milliseconds.
84
+ """
85
+ return self.mdl.getRuntime()
86
+
87
+ def printPolicy(self):
88
+ """Print the entire policy to the terminal."""
89
+ self.mdl.printPolicy()
90
+
91
+ def printValueVector(self):
92
+ """Print the entire value vector to the terminal."""
93
+ self.mdl.printValueVector()
94
+
95
+ def getAction(self, stateIndex=0):
96
+ """
97
+ Get the action from the optimized policy for a specific state.
98
+
99
+ Args:
100
+ stateIndex (int): Index of the state.
101
+
102
+ Returns:
103
+ int: Action for the given state.
104
+ """
105
+ return self.mdl.getAction(stateIndex=stateIndex)
106
+
107
+ def getValue(self, stateIndex=0):
108
+ """
109
+ Get the value from the optimized value vector for a specific state.
110
+
111
+ Args:
112
+ stateIndex (int): Index of the state.
113
+
114
+ Returns:
115
+ float: Value for the given state.
116
+ """
117
+ return self.mdl.getValue(stateIndex=stateIndex)
118
+
119
+ def getPolicy(self):
120
+ """
121
+ Get the entire optimized policy.
122
+
123
+ Returns:
124
+ list: Optimized policy.
125
+ """
126
+ return self.mdl.getPolicy()
127
+
128
+ def getValueVector(self):
129
+ """
130
+ Get the entire optimized value vector.
131
+
132
+ Returns:
133
+ list: Optimized value vector.
134
+ """
135
+ return self.mdl.getValueVector()
136
+
137
+ def saveToFile(self, fileName="result.csv", type="policy"):
138
+ """
139
+ Save the optimized policy or value vector to a file.
140
+
141
+ Args:
142
+ fileName (str): Name of the output file.
143
+ type (str): Type of result to save ('policy' or 'value').
144
+
145
+ Returns:
146
+ None
147
+ """
148
+ return self.mdl.saveToFile(fileName=fileName, type=type)
149
+
150
+ def mdp(
151
+ self,
152
+ discount=0.99,
153
+ rewards=list(),
154
+ rewardsElementwise=list(),
155
+ rewardsFromFile="rewards.csv",
156
+ tranMatWithZeros=list(),
157
+ tranMatElementwise=list(),
158
+ tranMatProbs=list(),
159
+ tranMatColumns=list(),
160
+ tranMatFromFile="transitions.csv",
161
+ ):
162
+ """
163
+ Define the generic MDP model.
164
+
165
+ Args:
166
+ discount (float): Discount factor.
167
+ rewards (list): A 2D-list containing the reward (float) of a particular action in a particular state.
168
+ rewardsElementwise (list): Alternative reward format. A 2D-list where each row corresponds to a combination of a state and an action.
169
+ rewardsFromFile (str): Load the rewards from a comma-separated (,) file.
170
+ tranMatWithZeros (list): A 3D-list containing the transition probabilities.
171
+ tranMatElementwise (list): Sparse transition probabilities (option 1). A 2D-list where each row corresponds to a combination of a current state, an action, and a next state.
172
+ tranMatProbs (list): Sparse transition probabilities (option 2, part 1). A 3D-list containing the non-zero transition probabilities.
173
+ tranMatColumns (list): Sparse transition probabilities (option 2, part 2). A 3D-list containing the columns of the non-zero transition probabilities.
174
+ tranMatFromFile (str): Load the transition probabilities from a comma-separated (,) file.
175
+
176
+ Returns:
177
+ None
178
+ """
179
+ self.mdl.mdp(
180
+ discount=discount,
181
+ rewards=rewards,
182
+ rewardsElementwise=rewardsElementwise,
183
+ rewardsFromFile=rewardsFromFile,
184
+ tranMatWithZeros=tranMatWithZeros,
185
+ tranMatElementwise=tranMatElementwise,
186
+ tranMatProbs=tranMatProbs,
187
+ tranMatColumns=tranMatColumns,
188
+ tranMatFromFile=tranMatFromFile,
189
+ )
@@ -0,0 +1,40 @@
1
+ import math
2
+
3
+ # Condition-based maintenance problem
4
+
5
+ # Note: The class is only used for retrieving/converting information
6
+ # (i.e. returning an action of the policy). The policy is optimized
7
+ # in the 'model' (model.py) class.
8
+
9
+
10
+ class cbmaux:
11
+
12
+ def __init__(self, components, stages):
13
+ self.components = components
14
+ self.stages = stages
15
+
16
+ def compToState(self, compStates):
17
+ # input: list containing the stage of each component
18
+ # output: the associated state index
19
+ prod = self.components * [1]
20
+ if self.components > 1:
21
+ for i in range(self.components - 2, -1, -1):
22
+ prod[i] = prod[i + 1] * self.stages
23
+ stateIndex = 0
24
+ for i in range(self.components):
25
+ stateIndex += compStates[i] * prod[i]
26
+ return stateIndex
27
+
28
+ def actionToReplace(self, actionIndex):
29
+ # input: action index from the optimized policy
30
+ # output: list of bools indicating which comps to replace
31
+ prod = self.components * [1]
32
+ if self.components > 1:
33
+ for i in range(self.components - 2, -1, -1):
34
+ prod[i] = prod[i + 1] * 2
35
+ replace = self.components * [False]
36
+ for i in range(self.components):
37
+ if math.floor(actionIndex / prod[i]) > 0:
38
+ replace[i] = True
39
+ actionIndex -= prod[i]
40
+ return replace
@@ -0,0 +1,40 @@
1
+ import math
2
+
3
+ # Time-based maintenance problem
4
+
5
+ # Note: The class is only used for retrieving/converting information
6
+ # (i.e. returning an action of the policy). The policy is optimized
7
+ # in the 'model' (model.py) class.
8
+
9
+
10
+ class tbmaux:
11
+
12
+ def __init__(self, components, stages):
13
+ self.components = components
14
+ self.stages = stages
15
+
16
+ def compToState(self, compStates):
17
+ # input: list containing the stage of each component
18
+ # output: the associated state index
19
+ prod = self.components * [1]
20
+ if self.components > 1:
21
+ for i in range(self.components - 2, -1, -1):
22
+ prod[i] = prod[i + 1] * self.stages
23
+ stateIndex = 0
24
+ for i in range(self.components):
25
+ stateIndex += compStates[i] * prod[i]
26
+ return stateIndex
27
+
28
+ def actionToReplace(self, actionIndex):
29
+ # input: action index from the optimized policy
30
+ # output: list of bools indicating which comps to replace
31
+ prod = self.components * [1]
32
+ if self.components > 1:
33
+ for i in range(self.components - 2, -1, -1):
34
+ prod[i] = prod[i + 1] * 2
35
+ replace = self.components * [False]
36
+ for i in range(self.components):
37
+ if math.floor(actionIndex / prod[i]) > 0:
38
+ replace[i] = True
39
+ actionIndex -= prod[i]
40
+ return replace
@@ -1,17 +1,19 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: mdpsolver
3
- Version: 0.9.7
3
+ Version: 0.9.9
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
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
11
+ Classifier: Operating System :: Microsoft :: Windows
12
+ Classifier: Operating System :: POSIX :: Linux
12
13
  Requires-Python: >=3.10
13
14
  Description-Content-Type: text/markdown
14
15
  License-File: LICENSE
16
+ Dynamic: license-file
15
17
 
16
18
  # MDPSolver
17
19
 
@@ -38,7 +40,11 @@ Install directly from PyPI with:
38
40
  pip install mdpsolver
39
41
  ```
40
42
 
41
- MDPSolver works *out of the box* on Linux.
43
+ MDPSolver works *out of the box* on Ubuntu 22 and newer.
44
+
45
+ ### GLIBC not found
46
+
47
+ 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
48
 
43
49
  ## Windows
44
50
 
@@ -157,7 +163,7 @@ mdl.mdp(discount=0.8,
157
163
 
158
164
  # Documentation
159
165
 
160
- The documentation can be found in the wiki for MDPSolver (https://github.com/areenberg/MDPSolver/wiki).
166
+ The documentation can be found in the [wiki for MDPSolver](https://github.com/areenberg/MDPSolver/wiki).
161
167
 
162
168
  # How to cite
163
169
 
@@ -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