490f2915466f

More plotting
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 25 May 2017 15:49:38 +0000
parents 2ad170fcb598
children fc378d24dd2f
branches/tags (none)
files plot-iset-sizes.gp src/players/random-zdd.lisp src/reasoners/zdd.lisp

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plot-iset-sizes.gp	Thu May 25 15:49:38 2017 +0000
@@ -0,0 +1,29 @@
+set terminal png size 1200, 1200 linewidth 3
+
+set output 'plot-iset-sizes-latenttictactoe.png'
+
+set xtics font "Lucida Grande,20"
+set ytics font "Lucida Grande,20"
+
+set size 0.6, 0.8
+set bmargin at screen 0.18
+set tmargin at screen 0.9
+set lmargin at screen 0.1
+set rmargin at screen 0.95
+
+set xlabel "States in Information Set" font "Lucida Grande,20" offset 0,-1
+set ylabel "Nodes/Objects" font "Lucida Grande,20" offset -1
+
+set key on font "Lucida Grande,20" bottom right at screen 0.98,0.05
+
+# set xtics rotate by -40 offset 0,-1
+
+set title "Information set sizes for LATENTTICTACTOE" font "Lucida Grande,24" offset 0,1
+
+# set xrange[0.2:8]
+# set yrange[0.5:1.3]
+
+# Data columns: game, state count, node-count, object-size
+
+plot 'data-iset-sizes' using 2:3 with points pointsize 2 pointtype 2 title "ZDD Node Count", \
+     'data-iset-sizes' using 2:4 with points pointsize 2 pointtype 4 title "Vanilla Object Size"
--- a/src/players/random-zdd.lisp	Wed May 24 13:27:57 2017 +0000
+++ b/src/players/random-zdd.lisp	Thu May 25 15:49:38 2017 +0000
@@ -1,6 +1,5 @@
 (in-package :scully.players.random-zdd)
 
-(defvar *data-file* nil)
 (defparameter *current-game* 'stratego)
 (defvar *prev-time* 0.0)
 (defvar *prev-gc* 0.0)
@@ -23,10 +22,7 @@
 (defmethod ggp:player-start-game ((player random-zdd-player) rules role timeout)
   (incf (rp-game player))
   (sb-ext:gc :full t)
-  (setf *data-file* (open "data-zdd" :direction :output
-                          :if-exists :append
-                          :if-does-not-exist :create)
-        *prev-time* 0.0
+  (setf *prev-time* 0.0
         *prev-gc* 0.0)
   (scully.zdd::with-zdd
     (let* ((grounded-rules (-<> rules
@@ -43,14 +39,13 @@
 
 (defmethod ggp:player-stop-game ((player random-zdd-player))
   (format t "Done~%")
-  (finish-output *data-file*)
-  (close *data-file*)
   (scully.zdd::with-zdd
     (with-random-zdd-player (player)
       (setf role nil
             reasoner nil
             iset nil))))
 
+
 (defun information-set-objects (iset)
   (apply #'+ (mapcar #'length iset)))
 
@@ -60,6 +55,17 @@
   (finish-output)
   obj)
 
+(defun log-iset-data (data-file game state-count node-count object-size)
+  (with-open-file (data data-file :direction :output
+                        :if-exists :append
+                        :if-does-not-exist :create)
+    (format data "~A ~D ~D ~D~%"
+            game
+            state-count
+            node-count
+            object-size)
+    (finish-output data)))
+
 (defmethod ggp:player-update-game-ii ((player random-zdd-player) move percepts)
   (incf (rp-turn player))
   (format t "~2%=====================================~%")
@@ -112,17 +118,19 @@
         (format t "Information set size: ~D states, ~D ZDD nodes~%" state-count node-count)
         (format t "      Iset cons size: ~D conses~%" object-size)
         (format t "       Max iset size: ~D ZDD nodes~%" max-node-count)
-        (format *data-file* "~A,~D,~D,~D,~D,~D,~D,~,4F,~,4F~%"
-                *current-game*
-                game
-                turn
-                state-count
-                node-count
-                max-node-count
-                object-size
-                elapsed
-                gc)
-        (finish-output *data-file*)))))
+        (log-iset-data "data-iset-sizes"
+                       *current-game* state-count node-count object-size)
+        ;; (format *data-file* "~A,~D,~D,~D,~D,~D,~D,~,4F,~,4F~%"
+        ;;         *current-game*
+        ;;         game
+        ;;         turn
+        ;;         state-count
+        ;;         node-count
+        ;;         max-node-count
+        ;;         object-size
+        ;;         elapsed
+        ;;         gc)
+        ))))
 
 (defmethod ggp:player-select-move ((player random-zdd-player) timeout)
   (scully.zdd::with-zdd
@@ -137,7 +145,7 @@
       ;; (dump-iset reasoner iset)
       ;; (format t "LEGAL MOVES:~%")
       ;; (pr (legal-moves-for reasoner iset role))
-      (pr (first (scully.gdl::sort-moves (legal-moves-for reasoner iset role)))))))
+      (pr (random-elt (scully.gdl::sort-moves (legal-moves-for reasoner iset role)))))))
 
 
 ;;;; Run ----------------------------------------------------------------------
@@ -147,8 +155,8 @@
                    :name "Scully-Random-ZDD"
                    :port 5003))
 
-;; (setf *current-game* 'mastermind448)
-;; (setf scully.terms::*shuffle-variables* t)
+;; (setf *current-game* 'latenttictactoe)
+;; (setf scully.terms::*shuffle-variables* nil)
 
 ;; (ggp:start-player *player* :server :hunchentoot :use-thread t)
 ;; (ggp:kill-player *player*)
--- a/src/reasoners/zdd.lisp	Wed May 24 13:27:57 2017 +0000
+++ b/src/reasoners/zdd.lisp	Thu May 25 15:49:38 2017 +0000
@@ -611,12 +611,21 @@
 
 ; Data columns: X Min 1stQuartile Median 3rdQuartile Max BoxWidth Titles
 
+(defun ground-gdl-size (gdl)
+  (iterate (for rule :in gdl)
+           (summing (if (and (consp rule)
+                             (equal (first rule) 'ggp-rules::<=))
+                      (1- (length rule))
+                      1))))
+
 (defun run-test (game-name shuffle?)
   (let* ((scully.terms::*shuffle-variables* shuffle?)
          (gdl (scully.gdl::read-gdl (format nil "gdl/~(~A~)-grounded.gdl" game-name)))
+         (gdl-size (ground-gdl-size gdl))
          (r (make-zdd-reasoner gdl))
          (sizes (reasoner-rule-tree-sizes r)))
-    sizes))
+    (values sizes gdl-size)))
+
 
 (defun percentile (sorted-numbers p)
   (nth (truncate (* (/ p 100) (length sorted-numbers)))
@@ -630,6 +639,7 @@
             (percentile sorted 75)
             (percentile sorted 95))))
 
+
 (defun run-shuffle-test (x game-name &optional (iterations 10))
   (with-open-file (data "data-shuffling-rule-trees"
                         :direction :output
@@ -654,4 +664,25 @@
     (for x :from 1)
     (run-shuffle-test x game iterations)))
 
-(run-shuffle-tests 50)
+
+(defun run-basic-test (game-name)
+  (with-open-file (data "data-rule-tree-sizes"
+                        :direction :output
+                        :if-exists :append
+                        :if-does-not-exist :create)
+    (multiple-value-bind (sizes gdl-size)
+        (run-test game-name nil)
+      (format data "~A ~D ~D ~D~%"
+              game-name
+              gdl-size
+              (length sizes)
+              (apply #'+ sizes)))))
+
+(defun run-basic-tests ()
+  (iterate
+    (for game :in '(montyhall meier mastermind448 transit vis_pacman3p latenttictactoe stratego))
+    (pr game)
+    (run-basic-test game)))
+
+;; (run-shuffle-tests 50)
+;; (run-basic-tests)