-
Notifications
You must be signed in to change notification settings - Fork 0
/
robust.py
60 lines (49 loc) · 1.52 KB
/
robust.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# coding: utf-8
from csrl.mdp import GridMDP
from csrl.oa import OmegaAutomaton
from csrl import ControlSynthesis
import numpy as np
import sys
method = sys.argv[1]
T = 2**int(sys.argv[2])
K = 2**int(sys.argv[3])
suffix = sys.argv[2]+'-'+sys.argv[3]
print('robust-'+suffix)
# Specification
ltl = 'G F b & G F c & (F G d | F G e)'
oa = OmegaAutomaton(ltl,oa_type='dra')
print('Number of Omega-automaton states (including the trap state):',oa.shape[1])
print('Number of accepting pairs:',oa.shape[0])
# MDP Description
shape = (5,5)
# E: Empty, T: Trap, B: Obstacle
structure = np.array([
['E', 'E', 'B', 'E', 'E'],
['E', 'E', 'E', 'E', 'E'],
['E', 'E', 'E', 'E', 'E'],
['E', 'E', 'E', 'E', 'E'],
['E', 'E', 'E', 'E', 'E']
])
label = np.array([
[('b','d'), ('c','d'), (), ('b','d'), ('c','d')],
[('e',), ('e',), ('e',), ('e',), ('e',)],
[('e',), ('e',), ('e',), ('e',), ('e',)],
[('e',), ('e',), (), ('e',), ('e',)],
[('e',), ('b','e'), ('e',), ('c','e'), ('e',)]
],dtype=np.object)
reward = np.zeros(shape)
lcmap={
'b':'peachpuff',
'c':'plum',
'd':'greenyellow',
'e':'palegreen'
}
grid_mdp = GridMDP(shape=shape,structure=structure,reward=reward,label=label,figsize=5,robust=True,lcmap=lcmap) # Use figsize=4 for smaller figures
grid_mdp.plot()
# Construct the product MDP
csrl = ControlSynthesis(grid_mdp,oa)
if method == 'shapley':
csrl.shapley(T=T)
elif method =='minimax_q':
csrl.minimax_q(T=T,K=K)