4
4
import tkinter .messagebox
5
5
from functools import partial
6
6
from tkinter import ttk
7
+ import time
8
+
9
+ sys .path .append (os .path .join (os .path .dirname (__file__ ), '..' ))
7
10
8
11
import matplotlib
9
12
import matplotlib .animation as animation
15
18
16
19
from mdp import *
17
20
18
- sys .path .append (os .path .join (os .path .dirname (__file__ ), '..' ))
19
21
20
22
matplotlib .use ('TkAgg' )
21
23
style .use ('ggplot' )
22
24
23
- fig = Figure (figsize = (20 , 15 ))
25
+ fig = Figure (figsize = (20 , 25 ))
24
26
sub = fig .add_subplot (111 )
25
27
plt .rcParams ['axes.grid' ] = False
26
28
@@ -47,11 +49,12 @@ def extents(f):
47
49
return [f [0 ] - delta / 2 , f [- 1 ] + delta / 2 ]
48
50
49
51
50
- def display (gridmdp , _height , _width ):
52
+ def display (gridmdp , _height , _width , _a ):
51
53
"""displays matrix"""
52
54
53
55
dialog = tk .Toplevel ()
54
- dialog .wm_title ('Values' )
56
+ #dialog.wm_title('Values')
57
+ dialog .wm_title (_a )
55
58
56
59
container = tk .Frame (dialog )
57
60
container .pack (side = tk .TOP , fill = tk .BOTH , expand = True )
@@ -125,7 +128,8 @@ def initialize_dialogbox(_width, _height, gridmdp, terminals, buttons):
125
128
btn_ok = ttk .Button (container , text = 'Ok' , command = dialog .destroy )
126
129
btn_ok .grid (row = 5 , column = 2 , sticky = 'nsew' , pady = 5 , padx = 5 )
127
130
128
- dialog .geometry ('400x200' )
131
+ #dialog.geometry('400x200')
132
+ dialog .geometry ('1600x200' )
129
133
dialog .mainloop ()
130
134
131
135
@@ -393,7 +397,7 @@ def view_matrix(self):
393
397
_height = self .shared_data ['height' ].get ()
394
398
_width = self .shared_data ['width' ].get ()
395
399
print (build_page .gridmdp )
396
- display (build_page .gridmdp , _height , _width )
400
+ display (build_page .gridmdp , _height , _width , "aaaaa" )
397
401
398
402
def view_terminals (self ):
399
403
"""prints current terminals to console"""
@@ -570,6 +574,9 @@ def __init__(self, parent, controller):
570
574
self .epsilon = 0.001
571
575
self .delta = 0
572
576
577
+ def print_inter_matrix (self , values , h , w ):
578
+ display (values , h , w , "aaaaa" )
579
+
573
580
def process_data (self , terminals , _height , _width , gridmdp ):
574
581
"""preprocess variables"""
575
582
@@ -606,7 +613,7 @@ def create_graph(self, gridmdp, terminals, _height, _width):
606
613
607
614
self .canvas = FigureCanvasTkAgg (fig , self .frame )
608
615
self .canvas .get_tk_widget ().pack (side = tk .TOP , fill = tk .BOTH , expand = True )
609
- self .anim = animation .FuncAnimation (fig , self .animate_graph , interval = 50 )
616
+ self .anim = animation .FuncAnimation (fig , self .animate_graph , interval = 300 )
610
617
self .canvas .show ()
611
618
612
619
def animate_graph (self , i ):
@@ -620,8 +627,14 @@ def animate_graph(self, i):
620
627
y = np .linspace (0 , len (self .gridmdp ) - 1 , y_interval )
621
628
622
629
sub .clear ()
623
- sub .imshow (self .grid_to_show , cmap = 'BrBG' , aspect = 'auto' , interpolation = 'none' , extent = extents (x ) + extents (y ),
630
+ #sub.imshow(self.grid_to_show, cmap='BrBG', aspect='auto', interpolation='none', extent=extents(x) + extents(y),
631
+ # origin='lower')
632
+
633
+ for (j ,i ),label in np .ndenumerate (self .grid_to_show ):
634
+ sub .text (i ,j ,label ,ha = 'center' ,va = 'center' )
635
+ sub .imshow (self .grid_to_show , aspect = 'auto' , interpolation = 'none' , extent = extents (x ) + extents (y ),
624
636
origin = 'lower' )
637
+
625
638
fig .tight_layout ()
626
639
627
640
U = self .U1 .copy ()
@@ -634,16 +647,20 @@ def animate_graph(self, i):
634
647
self .grid_to_show = grid_to_show = [[0.0 ] * max (1 , self ._width ) for _ in range (max (1 , self ._height ))]
635
648
for k , v in U .items ():
636
649
self .grid_to_show [k [1 ]][k [0 ]] = v
650
+
651
+ #time.sleep(1)
637
652
638
653
if (self .delta < self .epsilon * (1 - self .gamma ) / self .gamma ) or (
639
654
self .iterations > 60 ) and self .terminated is False :
640
655
self .terminated = True
641
- display (self .grid_to_show , self ._height , self ._width )
656
+ display (self .grid_to_show , self ._height , self ._width , "Final Value" )
642
657
643
658
pi = best_policy (self .sequential_decision_environment ,
644
659
value_iteration (self .sequential_decision_environment , .01 ))
645
660
display_best_policy (self .sequential_decision_environment .to_arrows (pi ), self ._height , self ._width )
646
661
662
+
663
+
647
664
ax = fig .gca ()
648
665
ax .xaxis .set_major_locator (MaxNLocator (integer = True ))
649
666
ax .yaxis .set_major_locator (MaxNLocator (integer = True ))
0 commit comments