Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
pymdptoolbox
Commits
66b34533
Commit
66b34533
authored
Jan 26, 2013
by
Steven Cordwell
Browse files
LP reorganised to remove f, h and M as data attributes
parent
731802b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
mdp.py
View file @
66b34533
...
...
@@ -690,13 +690,17 @@ class LP(MDP):
"linear programming functionality."
)
from
scipy.sparse
import
eye
as
speye
self
.
_speye
=
speye
MDP
.
__init__
(
self
,
transitions
,
reward
,
discount
,
None
,
None
)
# this doesn't do what I want it to do c.f. issue #3
if
not
self
.
verbose
:
solvers
.
options
[
'show_progress'
]
=
False
def
iterate
(
self
):
"""Run the linear programming algorithm."""
self
.
time
=
time
()
# The objective is to resolve : min V / V >= PR + discount*P*V
# The function linprog of the optimisation Toolbox of Mathworks
# resolves :
...
...
@@ -705,28 +709,19 @@ class LP(MDP):
# min V / (discount*P-I) * V <= - PR
# To avoid loop on states, the matrix M is structured following actions
# M(A*S,S)
self
.
f
=
self
.
_cvxmat
(
ones
((
self
.
S
,
1
)))
self
.
M
=
zeros
((
self
.
A
*
self
.
S
,
self
.
S
))
f
=
self
.
_cvxmat
(
ones
((
self
.
S
,
1
)))
h
=
self
.
_cvxmat
(
self
.
R
.
reshape
(
self
.
S
*
self
.
A
,
1
,
order
=
"F"
),
tc
=
'd'
)
M
=
zeros
((
self
.
A
*
self
.
S
,
self
.
S
))
for
aa
in
range
(
self
.
A
):
pos
=
(
aa
+
1
)
*
self
.
S
self
.
M
[(
pos
-
self
.
S
):
pos
,
:]
=
(
discount
*
self
.
P
[
aa
]
-
speye
(
self
.
S
,
self
.
S
))
self
.
M
=
self
.
_cvxmat
(
self
.
M
)
def
iterate
(
self
):
"""Run the linear programming algorithm."""
self
.
time
=
time
()
h
=
self
.
_cvxmat
(
self
.
R
.
reshape
(
self
.
S
*
self
.
A
,
1
,
order
=
"F"
),
tc
=
'd'
)
M
[(
pos
-
self
.
S
):
pos
,
:]
=
(
self
.
discount
*
self
.
P
[
aa
]
-
self
.
_speye
(
self
.
S
,
self
.
S
))
M
=
self
.
_cvxmat
(
M
)
# Using the glpk option will make this behave more like Octave
# (Octave uses glpk) and perhaps Matlab. If solver=None (ie using the
# default cvxopt solver) then V agrees with the Octave equivalent
# only to 10e-8 places.
self
.
V
=
matrix
(
self
.
_linprog
(
self
.
f
,
self
.
M
,
-
h
,
solver
=
'glpk'
)[
'x'
])
self
.
V
=
matrix
(
self
.
_linprog
(
f
,
M
,
-
h
,
solver
=
'glpk'
)[
'x'
])
self
.
policy
,
self
.
V
=
self
.
_bellmanOperator
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment