toss-devel-svn Mailing List for Toss (Page 15)
Status: Beta
Brought to you by:
lukaszkaiser
You can subscribe to this list here.
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(25) |
Dec
(62) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(26) |
Feb
(38) |
Mar
(67) |
Apr
(22) |
May
(41) |
Jun
(30) |
Jul
(24) |
Aug
(32) |
Sep
(29) |
Oct
(34) |
Nov
(18) |
Dec
(2) |
2012 |
Jan
(19) |
Feb
(25) |
Mar
(16) |
Apr
(2) |
May
(18) |
Jun
(21) |
Jul
(11) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <luk...@us...> - 2011-03-26 18:52:24
|
Revision: 1398 http://toss.svn.sourceforge.net/toss/?rev=1398&view=rev Author: lukaszkaiser Date: 2011-03-26 18:52:18 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Stupid timeout on/off bug. Modified Paths: -------------- trunk/Toss/Play/GameTree.ml Modified: trunk/Toss/Play/GameTree.ml =================================================================== --- trunk/Toss/Play/GameTree.ml 2011-03-26 16:04:58 UTC (rev 1397) +++ trunk/Toss/Play/GameTree.ml 2011-03-26 18:52:18 UTC (rev 1398) @@ -71,10 +71,8 @@ Solver.M.set_timeout timeout; let moves = Move.list_moves game state in if moves = [||] then ( - if timeout() then ( - Solver.M.clear_timeout(); - raise (Aux.Timeout "GameTree.unfold_abstract.term"); - ); + Solver.M.clear_timeout(); + if timeout() then raise (Aux.Timeout "GameTree.unfold_abstract.term"); Terminal (state, player, info_terminal depth game state player info) ) else let leaf_of_move i leaf_s = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-26 16:05:04
|
Revision: 1397 http://toss.svn.sourceforge.net/toss/?rev=1397&view=rev Author: lukaszkaiser Date: 2011-03-26 16:04:58 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Timeout in solver to improve timing. Modified Paths: -------------- trunk/Toss/Formula/Aux.ml trunk/Toss/Formula/Aux.mli trunk/Toss/Play/GameTree.ml trunk/Toss/Play/Play.ml trunk/Toss/Server/Server.ml trunk/Toss/Solver/Solver.ml trunk/Toss/Solver/Solver.mli Modified: trunk/Toss/Formula/Aux.ml =================================================================== --- trunk/Toss/Formula/Aux.ml 2011-03-26 00:30:21 UTC (rev 1396) +++ trunk/Toss/Formula/Aux.ml 2011-03-26 16:04:58 UTC (rev 1397) @@ -1,6 +1,8 @@ (* Auxiliary functions that operate on standard library data structures and standard library-like definitions. *) +exception Timeout of string + type ('a,'b) choice = Left of 'a | Right of 'b Modified: trunk/Toss/Formula/Aux.mli =================================================================== --- trunk/Toss/Formula/Aux.mli 2011-03-26 00:30:21 UTC (rev 1396) +++ trunk/Toss/Formula/Aux.mli 2011-03-26 16:04:58 UTC (rev 1397) @@ -1,6 +1,8 @@ (** Auxiliary functions that operate on standard library data structures and standard library-like definitions. *) +exception Timeout of string + type ('a, 'b) choice = Left of 'a | Right of 'b module Strings : Set.S with type elt = string Modified: trunk/Toss/Play/GameTree.ml =================================================================== --- trunk/Toss/Play/GameTree.ml 2011-03-26 00:30:21 UTC (rev 1396) +++ trunk/Toss/Play/GameTree.ml 2011-03-26 16:04:58 UTC (rev 1397) @@ -64,22 +64,32 @@ let rec unfold_abstract ?(timeout=fun () -> false) ?(depth=0) game ~info_terminal ~info_leaf ~info_node ~choice = function | Terminal _ -> - if !debug_level > 0 then print_endline "Terminal Unfold"; raise Not_found + if !debug_level > 0 then print_endline "Terminal Unfold"; + raise Not_found | Leaf (state, player, info) -> - if timeout() then raise Not_found; + if timeout() then raise (Aux.Timeout "GameTree.unfold_abstract.leaf1"); + Solver.M.set_timeout timeout; let moves = Move.list_moves game state in if moves = [||] then ( + if timeout() then ( + Solver.M.clear_timeout(); + raise (Aux.Timeout "GameTree.unfold_abstract.term"); + ); Terminal (state, player, info_terminal depth game state player info) ) else - let leaf_of_move leaf_s = - if timeout() then raise Not_found; + let leaf_of_move i leaf_s = + if timeout() then ( + Solver.M.clear_timeout(); + raise (Aux.Timeout "GameTree.unfold_abstract.lm"); + ); let l_pl = game.Arena.graph.(leaf_s.Arena.cur_loc).Arena.player in let l_info = info_leaf (depth+1) game leaf_s l_pl player in Leaf (leaf_s, l_pl, l_info) in - let children = Array.map (fun (m, s) -> (m, leaf_of_move s)) moves in + let children = Array.mapi (fun i (m,s) -> (m,leaf_of_move i s)) moves in + Solver.M.clear_timeout (); Node (state, player,info_node depth game state player children,children) | Node (state, player, info, children) -> - if timeout() then raise Not_found; + if timeout() then raise (Aux.Timeout "GameTree.unfold_abstract.node"); let n = choice depth game state player info children in let (move, child) = children.(n) in let child_unfolded = unfold_abstract ~timeout:timeout ~depth:(depth+1) @@ -178,7 +188,7 @@ let heurs = Array.mapi (fun p _ -> pval p) (node_values (snd child)) in let is_exact_child c = node_is_exact (snd children.(c)) in let non_leaf c = match snd children.(c) with Leaf _ -> false | _ -> true in - let exact_nonleaf c = is_exact_child c && non_leaf c in + (* let exact_nonleaf c = is_exact_child c && non_leaf c in *) { heurs= heurs; heurs_are_exact = List.exists non_leaf mids || List.for_all is_exact_child mids; Modified: trunk/Toss/Play/Play.ml =================================================================== --- trunk/Toss/Play/Play.ml 2011-03-26 00:30:21 UTC (rev 1396) +++ trunk/Toss/Play/Play.ml 2011-03-26 16:04:58 UTC (rev 1397) @@ -47,17 +47,18 @@ (* Maximax unfolding upto depth. *) let rec unfold_maximax_upto ?(ab=false) count game heur t = - if count = 0 || timed_out () then ( - if !debug_level > 1 && timed_out() then - print_endline "Timeout"; - t - ) else + if count = 0 || timed_out () then t else try - if timed_out() then t else - let u = unfold_maximax ~ab:ab game heur t in - if !debug_level > 0 then Printf.printf "%d,%!" (size u); - unfold_maximax_upto ~ab:ab (count-1) game heur u - with Not_found -> t + let u = unfold_maximax ~ab:ab game heur t in + if !debug_level > 0 then Printf.printf "%d,%!" (size u); + unfold_maximax_upto ~ab:ab (count-1) game heur u + with + | Not_found -> t + | Aux.Timeout msg -> + if !debug_level > 0 then + if !debug_level > 0 then Printf.printf "Timeout %f (%s)%!" + (Unix.gettimeofday() -. !timeout) msg; + t (* Maximax unfold upto depth and choose move. *) let maximax_unfold_choose count game state heur = @@ -67,8 +68,6 @@ Array.iter (fun h -> Array.iter Formula.print_real h) heur; let t = init game state (fun _ _ _ -> 0) heur in let u = unfold_maximax_upto ~ab count game heur t in - if !debug_level > 0 then Printf.printf "Timeout %f%!" - (Unix.gettimeofday() -. !timeout); if !debug_level > 1 then print_endline (str ~upto:1 ~struc:false string_of_int u); choose_move game u Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-03-26 00:30:21 UTC (rev 1396) +++ trunk/Toss/Server/Server.ml 2011-03-26 16:04:58 UTC (rev 1397) @@ -403,7 +403,7 @@ play, play_state | _ -> assert false in ignore (Unix.alarm (!playclock - (int_of_float time_used) - 1)); - Play.set_timeout (float(!playclock) -. time_used -. 0.03); + Play.set_timeout (float(!playclock) -. time_used -. 0.02); if !no_gtree then let res = Game.suggest p ps in Game.cancel_timeout (); Modified: trunk/Toss/Solver/Solver.ml =================================================================== --- trunk/Toss/Solver/Solver.ml 2011-03-26 00:30:21 UTC (rev 1396) +++ trunk/Toss/Solver/Solver.ml 2011-03-26 16:04:58 UTC (rev 1397) @@ -20,8 +20,11 @@ let get_cache () = (!cache_struc, Hashtbl.copy !cache_results) let set_cache (struc, res) = cache_struc := struc; cache_results := res - +let timeout = ref (fun () -> false) +let check_timeout msg = + if !timeout () then (timeout := (fun () -> false); raise (Aux.Timeout msg)); + (* ----------------------- BASIC TYPE DEFINITION -------------------------- *) type solver = { @@ -138,6 +141,7 @@ report (List.fold_left (sum elems) Empty asets) | Ex ([], phi) | All ([], phi) -> failwith "evaluating empty quantifier" | Ex (vl, phi) -> + check_timeout "Solver.eval.Ex"; let aset_vars = AssignmentSet.assigned_vars [] aset in let in_aset = (* FIXME; TODO; same-name quantified vars?! (tnf_fv!) *) if List.exists (fun v -> List.mem v aset_vars) vl then @@ -150,6 +154,7 @@ let phi_asgn = eval model elems in_aset phi in report (join aset (project_list elems phi_asgn vl)) | All (vl, phi) -> + check_timeout "Solver.eval.All"; let aset_vars = AssignmentSet.assigned_vars [] aset in let in_aset = (* FIXME; TODO; same-name quantified vars?! (tnf_fv!) *) if List.exists (fun v -> List.mem v aset_vars) vl then @@ -327,6 +332,7 @@ with Not_found -> if !debug_level > 0 then print_endline ("Eval_m " ^ (str phi)); let els = Set (Elems.cardinal struc.elements, struc.elements) in + check_timeout "Solver.eval_m"; let asg = eval struc (ref els) Any phi in incr eval_counter; Hashtbl.add !cache_results phi (asg, phi_rels phi); @@ -408,8 +414,6 @@ print_endline ("sum vars " ^ (Formula.var_list_str vl)); print_endline ("all vars " ^ (Formula.var_list_str all_vs)); ); - (* let gd = FFTNF.ff_tnf (FFSolver.promote_for struc) guard in - let asg_gd = join asg (FFSolver.evaluate struc gd) in *) let asg_gd = join asg (eval_cache_sentences solver struc guard) in let tps = tuples struc.elements (List.map var_str all_vs) asg_gd in let add_val acc tp = @@ -469,7 +473,7 @@ check_formula phi -(* Interface to {!SolverIntf}. *) +(* Interface *) module M = struct let solver = new_solver () @@ -483,11 +487,9 @@ let check struc phi = check solver ~formula:(register_formula_s struc solver phi) struc let get_real_val re struc = get_real_val_cache solver struc re - let formula_str phi = - (* let phi = Hashtbl.find solver.formulas_check phi in *) - Formula.str phi - let real_str expr = - Formula.real_str expr + + let set_timeout t = timeout := t + let clear_timeout () = timeout := (fun () -> false); end (* module M = FFSolver.M *) Modified: trunk/Toss/Solver/Solver.mli =================================================================== --- trunk/Toss/Solver/Solver.mli 2011-03-26 00:30:21 UTC (rev 1396) +++ trunk/Toss/Solver/Solver.mli 2011-03-26 16:04:58 UTC (rev 1397) @@ -25,6 +25,11 @@ (** Get the value of a real expression without free variables. *) val get_real_val : Formula.real_expr -> Structure.structure -> float + + (** Set timeout function. *) + val set_timeout : (unit -> bool) -> unit + (** Clear timeout function. *) + val clear_timeout : unit -> unit end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-26 00:30:27
|
Revision: 1396 http://toss.svn.sourceforge.net/toss/?rev=1396&view=rev Author: lukaszkaiser Date: 2011-03-26 00:30:21 +0000 (Sat, 26 Mar 2011) Log Message: ----------- Debugging - remove. Modified Paths: -------------- trunk/Toss/Play/Heuristic.ml Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-25 22:41:16 UTC (rev 1395) +++ trunk/Toss/Play/Heuristic.ml 2011-03-26 00:30:21 UTC (rev 1396) @@ -1188,7 +1188,7 @@ let res = mix_heur (default_heuristic_old ?struc ?advr g) 0.2 (fluents_heuristic g) in - if !debug_level > -4 (*1*) then ( + if !debug_level > 2 then ( print_endline "HEURISTIC MATRIX:"; Array.iteri (fun loc poffs -> Array.iteri (fun player poff -> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-25 22:41:22
|
Revision: 1395 http://toss.svn.sourceforge.net/toss/?rev=1395&view=rev Author: lukstafi Date: 2011-03-25 22:41:16 +0000 (Fri, 25 Mar 2011) Log Message: ----------- Reverting default non-monotonic adv ratio to 2. Modified Paths: -------------- trunk/Toss/Play/Heuristic.ml Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-25 22:33:05 UTC (rev 1394) +++ trunk/Toss/Play/Heuristic.ml 2011-03-25 22:41:16 UTC (rev 1395) @@ -259,7 +259,7 @@ {!Heuristic.default_heuristic_old}). *) let force_competitive = ref false (* TODO: not exporting these in the API as global variables? *) -let default_nonmonot_adv_ratio = 4.0 +let default_nonmonot_adv_ratio = 2.0 let default_monot_adv_ratio = 5.0 let suggest_expansion_coef = 0.5 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-25 22:33:11
|
Revision: 1394 http://toss.svn.sourceforge.net/toss/?rev=1394&view=rev Author: lukstafi Date: 2011-03-25 22:33:05 +0000 (Fri, 25 Mar 2011) Log Message: ----------- Increasing monotonic adv ratio to 5. Giving more time to GameBig tests (warning: they now take 12 minutes, consider tweaking timeouts to waste less) not to generate unnecessary fails or skips. Modified Paths: -------------- trunk/Toss/Play/GameTest.ml trunk/Toss/Play/Heuristic.ml Modified: trunk/Toss/Play/GameTest.ml =================================================================== --- trunk/Toss/Play/GameTest.ml 2011-03-25 22:24:30 UTC (rev 1393) +++ trunk/Toss/Play/GameTest.ml 2011-03-25 22:33:05 UTC (rev 1394) @@ -132,13 +132,13 @@ lazy (None, 2.0, state_of_file "./GGP/tests/breakthrough-simpl.toss") let tictactoe_game = - lazy (None, 4.0, state_of_file "./examples/Tic-Tac-Toe.toss") + lazy (None, 5.0, state_of_file "./examples/Tic-Tac-Toe.toss") let gomoku8x8_game = - lazy (None, 4.0, state_of_file "./examples/Gomoku.toss") + lazy (None, 5.0, state_of_file "./examples/Gomoku.toss") let gomoku19x19_game = - lazy (None, 4.0, state_of_file "./examples/Gomoku19x19.toss") + lazy (None, 5.0, state_of_file "./examples/Gomoku19x19.toss") let connect4_game = lazy (None, 2.0, state_of_file "./examples/Connect4.toss") @@ -443,7 +443,7 @@ "play: chess suggest first move" >:: (fun () -> - skip_if true "loading takes long, worked last time"; + skip_if false "loading takes long, worked last time"; let horizon, advr, state = Lazy.force chess_game in let move_opt = (let p,ps = Game.initialize_default state @@ -470,7 +470,7 @@ "play: chess begin random play" >:: (fun () -> - skip_if true "loading takes long, worked last time"; + skip_if false "loading takes long, worked last time"; let _, advr, state = Lazy.force chess_game in let (game, struc) = (fst state, (snd state).Arena.struc) in @@ -491,10 +491,10 @@ "chess draw" >:: (fun () -> - skip_if true "loading takes long, worked last time"; + skip_if false "loading takes long, worked last time"; let horizon, advr, state = - update_game chess_game -"[a1, b1, c1, d1, e1, f1, g1, h1, a2, b2, c2, d2, e2, f2, g2, h2, a3, b3, c3, d3, e3, f3, g3, h3, a4, b4, c4, d4, e4, f4, g4, h4, a5, b5, c5, d5, e5, f5, g5, h5, a6, b6, c6, d6, e6, f6, g6, h6, a7, b7, c7, d7, e7, f7, g7, h7, a8, b8, c8, d8, e8, f8, g8, h8 | D1 {(a1, b2); (b1, c2); (c1, d2); (d1, e2); (e1, f2); (f1, g2); (g1, h2); (a2, b3); (b2, a1); (b2, c3); (c2, b1); (c2, d3); (d2, c1); (d2, e3); (e2, d1); (e2, f3); (f2, e1); (f2, g3); (g2, f1); (g2, h3); (h2, g1); (a3, b4); (b3, a2); (b3, c4); (c3, b2); (c3, d4); (d3, c2); (d3, e4); (e3, d2); (e3, f4); (f3, e2); (f3, g4); (g3, f2); (g3, h4); (h3, g2); (a4, b5); (b4, a3); (b4, c5); (c4, b3); (c4, d5); (d4, c3); (d4, e5); (e4, d3); (e4, f5); (f4, e3); (f4, g5); (g4, f3); (g4, h5); (h4, g3); (a5, b6); (b5, a4); (b5, c6); (c5, b4); (c5, d6); (d5, c4); (d5, e6); (e5, d4); (e5, f6); (f5, e4); (f5, g6); (g5, f4); (g5, h6); (h5, g4); (a6, b7); (b6, a5); (b6, c7); (c6, b5); (c6, d7); (d6, c5); (d6, e7); (e6, d5); (e6, f7); (f6, e5); (f6, g7); (g6, f5); (g6, h7); (h6, g5); (a7, b8); (b7, a6); (b7, c8); (c7, b6); (c7, d8); (d7, c6); (d7, e8); (e7, d6); (e7, f8); (f7, e6); (f7, g8); (g7, f6); (g7, h8); (h7, g6); (b8, a7); (c8, b7); (d8, c7); (e8, d7); (f8, e7); (g8, f7); (h8, g7)}; D2 {(b1, a2); (c1, b2); (d1, c2); (e1, d2); (f1, e2); (g1, f2); (h1, g2); (a2, b1); (b2, c1); (b2, a3); (c2, d1); (c2, b3); (d2, e1); (d2, c3); (e2, f1); (e2, d3); (f2, g1); (f2, e3); (g2, h1); (g2, f3); (h2, g3); (a3, b2); (b3, c2); (b3, a4); (c3, d2); (c3, b4); (d3, e2); (d3, c4); (e3, f2); (e3, d4); (f3, g2); (f3, e4); (g3, h2); (g3, f4); (h3, g4); (a4, b3); (b4, c3); (b4, a5); (c4, d3); (c4, b5); (d4, e3); (d4, c5); (e4, f3); (e4, d5); (f4, g3); (f4, e5); (g4, h3); (g4, f5); (h4, g5); (a5, b4); (b5, c4); (b5, a6); (c5, d4); (c5, b6); (d5, e4); (d5, c6); (e5, f4); (e5, d6); (f5, g4); (f5, e6); (g5, h4); (g5, f6); (h5, g6); (a6, b5); (b6, c5); (b6, a7); (c6, d5); (c6, b7); (d6, e5); (d6, c7); (e6, f5); (e6, d7); (f6, g5); (f6, e7); (g6, h5); (g6, f7); (h6, g7); (a7, b6); (b7, c6); (b7, a8); (c7, d6); (c7, b8); (d7, e6); (d7, c8); (e7, f6); (e7, d8); (f7, g6); (f7, e8); (g7, h6); (g7, f8); (h7, g8); (a8, b7); (b8, c7); (c8, d7); (d8, e7); (e8, f7); (f8, g7); (g8, h7)}; bB:1 {}; wB:1 {}; wN:1 {}; wP:1 {}; wQ:1 {}; wR:1 {} | ] \" + update_game ~defs:true chess_game +"MODEL [ | bB:1 {}; wB:1 {}; wN:1 {}; wP:1 {}; wQ:1 {}; wR:1 {} | ] \" ... ... ... ... ... ... +bN ... ... ... ... ... @@ -511,7 +511,9 @@ ... ... ... ... ... ... ... ... ... ... ... ... -\"" 0 in +\" with +D1(x, y) = ex z ( (R(x, z) and C(z, y)) or (R(y, z) and C(z, x)) ) ; +D2(x, y) = ex z ( (R(x, z) and C(y, z)) or (R(y, z) and C(x, z)) )" 0 in let payoffs = Array.to_list (Array.mapi (fun i v->string_of_int i,v) @@ -545,6 +547,7 @@ let easy_case = compute_try algo randomize effort_easy time_easy and easy_big_case = compute_try algo randomize effort_easy time_medium and medium_case = compute_try algo randomize effort_medium time_medium + and hard_small_case = compute_try algo randomize effort_hard time_medium and hard_case = compute_try algo randomize effort_hard time_hard in (algo ^ "-" ^ comment) >::: [ @@ -942,7 +945,7 @@ \" with DiagA (x, y) = ex u (R(x, u) and C(u, y)) ; DiagB (x, y) = ex u (R(x, u) and C(y, u))" 0 in Heuristic.use_monotonic := false; - hard_case state 0 "should not attack" + hard_small_case state 0 "should not attack" (fun mov_s -> "Cross{1:f3}" <> mov_s); Heuristic.use_monotonic := true; ); @@ -982,7 +985,7 @@ let bigtests = "GameBig" >::: [ misc_tests_big; - search_tests "alpha_beta_ord" "time 8 16 32" false 10 8 10 16 10 32; + search_tests "alpha_beta_ord" "time 10 60 120" false 10 10 10 60 10 120; ] let experiments = "Game" >::: [ @@ -1029,15 +1032,15 @@ ); ] -let a = Aux.run_test_if_target "GameTest" tests +let a () = Aux.run_test_if_target "GameTest" tests -let a = Aux.run_test_if_target "GameTest" bigtests +let a () = Aux.run_test_if_target "GameTest" bigtests let a () = run_test_tt ~verbose:true experiments let a () = Heuristic.debug_level := 4; - FFTNF.debug_level := 4; + (* FFTNF.debug_level := 4; *) (* DiscreteRule.debug_level := 5; *) Game.set_debug_level 10 @@ -1045,8 +1048,8 @@ let a = match test_filter - ["Game:0:misc:4:breakthrough payoff GDL simplified game"] - tests + ["GameBig:0:misc_big:3:chess draw"] + bigtests with | Some tests -> ignore (run_test_tt ~verbose:true tests) | None -> () Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-25 22:24:30 UTC (rev 1393) +++ trunk/Toss/Play/Heuristic.ml 2011-03-25 22:33:05 UTC (rev 1394) @@ -260,7 +260,7 @@ let force_competitive = ref false (* TODO: not exporting these in the API as global variables? *) let default_nonmonot_adv_ratio = 4.0 -let default_monot_adv_ratio = 4.0 +let default_monot_adv_ratio = 5.0 let suggest_expansion_coef = 0.5 let f_monot adv_ratio n m = @@ -1079,10 +1079,8 @@ Aux.Strings.union posi_poff_rels nega_poff_rels in let frels = Aux.Strings.union indef_frels (Aux.Strings.union posi_frels nega_frels) in - let moves = match struc with | None -> [||] | Some strc -> - Move.gen_moves Move.cGRID_SIZE rules strc graph.(0) in - let monotonic = !use_monotonic && (Array.length moves > 60 || - Aux.Strings.is_empty (Aux.Strings.inter all_poff_rels indef_frels)) in + let monotonic = !use_monotonic && + Aux.Strings.is_empty (Aux.Strings.inter all_poff_rels indef_frels) in (* {{{ log entry *) if !debug_level > 0 then ( Printf.printf @@ -1190,7 +1188,7 @@ let res = mix_heur (default_heuristic_old ?struc ?advr g) 0.2 (fluents_heuristic g) in - if !debug_level > 1 then ( + if !debug_level > -4 (*1*) then ( print_endline "HEURISTIC MATRIX:"; Array.iteri (fun loc poffs -> Array.iteri (fun player poff -> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-25 22:24:36
|
Revision: 1393 http://toss.svn.sourceforge.net/toss/?rev=1393&view=rev Author: lukaszkaiser Date: 2011-03-25 22:24:30 +0000 (Fri, 25 Mar 2011) Log Message: ----------- GameTree corrections and better loging, more exact timers in Server. Modified Paths: -------------- trunk/Toss/Play/GameTree.ml trunk/Toss/Play/GameTree.mli trunk/Toss/Play/Play.ml trunk/Toss/Server/Server.ml trunk/Toss/examples/Gomoku.toss trunk/Toss/examples/Tic-Tac-Toe.toss Modified: trunk/Toss/Play/GameTree.ml =================================================================== --- trunk/Toss/Play/GameTree.ml 2011-03-25 20:12:20 UTC (rev 1392) +++ trunk/Toss/Play/GameTree.ml 2011-03-25 22:24:30 UTC (rev 1393) @@ -13,23 +13,26 @@ (* node with state, player, moves and info *) (* Abstract tree printing function. *) -let rec str_abstract ?(depth=0) str_info str_info_terminal tree = +let rec str_abstract ?(upto=100000000) ?(struc=true) ?(depth=0) + str_info str_info_terminal tree = let s msg state player info_s = - let struc_s = Structure.str state.Arena.struc in + let struc_s = if struc then Structure.str state.Arena.struc else "" in let head_s = Printf.sprintf "Player %d loc %d time %.1f.\n" player state.Arena.cur_loc state.Arena.time in let res = "\n" ^ msg ^ head_s ^ struc_s ^ "\n" ^ info_s in let prefix = if depth=0 then "" else (String.make depth '|') ^ " " in Str.global_replace (Str.regexp "\n") ("\n" ^ prefix) res in - match tree with - | Terminal (state, player, info) -> - s "Terminal. " state player (str_info_terminal info) - | Leaf (state, player, info) -> s "Leaf. " state player (str_info info) - | Node (state, player, info, children) -> - let next_str (_, t) = - str_abstract ~depth:(depth+1) str_info str_info_terminal t in - let child_s = Array.to_list (Array.map next_str children) in - String.concat "" ((s "Node. " state player (str_info info)) :: child_s) + if upto < 0 then " Cut;" else + match tree with + | Terminal (state, player, info) -> + s "Terminal. " state player (str_info_terminal info) + | Leaf (state, player, info) -> s "Leaf. " state player (str_info info) + | Node (state, player, info, children) -> + let next_str (_, t) = + str_abstract ~upto:(upto-1) ~struc:struc ~depth:(depth+1) + str_info str_info_terminal t in + let child_s = Array.to_list (Array.map next_str children) in + String.concat "" ((s "Node. " state player (str_info info)) :: child_s) (* Number of nodes in the tree. *) let rec size = function @@ -88,7 +91,7 @@ (* -------------- TREES WITH PAYOFF AND HEURISTIC DATA --------------- *) -let cPAYOFF_AS_HEUR = ref 1000. +let cPAYOFF_AS_HEUR = ref 10000. (* The general information in a game tree node. *) type 'a node_info = { @@ -107,18 +110,18 @@ (* Game tree printing function. *) -let str f ?(depth=0) tree = +let str f ?(upto=100000000) ?(struc=true) ?(depth=0) tree = let fas a = String.concat "; " (List.map string_of_float (Array.to_list a)) in let str_terminal i = "Payoffs: " ^ (fas i.payoffs) ^ " heurs: " ^ (fas i.heurs_t) ^ " info: " ^ (f i.info_t) in let str_node i = "Heurs: " ^ (fas i.heurs) ^ " exact: " ^ (string_of_bool i.heurs_are_exact) ^ " info: " ^ (f i.info) in - str_abstract ~depth:depth str_node str_terminal tree + str_abstract ~upto:upto ~struc:struc ~depth:depth str_node str_terminal tree (* Get the payoffs / heuristics array of a game tree node. *) let node_values = function - | Terminal (_, _, i) -> - Array.mapi (fun k p -> !cPAYOFF_AS_HEUR *. p +. i.heurs_t.(k)) i.payoffs + | Terminal (_, _, i) -> Array.mapi + (fun k p -> !cPAYOFF_AS_HEUR *. p +. 0.001 *. i.heurs_t.(k)) i.payoffs | Leaf (_, _, i) -> i.heurs | Node (_, _, i, _) -> i.heurs Modified: trunk/Toss/Play/GameTree.mli =================================================================== --- trunk/Toss/Play/GameTree.mli 2011-03-25 20:12:20 UTC (rev 1392) +++ trunk/Toss/Play/GameTree.mli 2011-03-25 22:24:30 UTC (rev 1393) @@ -14,8 +14,8 @@ (** node with state, player, moves *) (** Abstract tree printing function. *) -val str_abstract : ?depth:int -> ('a -> string) -> ('b -> string) -> - ('a, 'b) abstract_game_tree -> string +val str_abstract : ?upto:int -> ?struc:bool -> ?depth:int -> ('a -> string) -> + ('b -> string) -> ('a, 'b) abstract_game_tree -> string (** Number of nodes in the tree. *) val size : ('a, 'b) abstract_game_tree -> int @@ -66,7 +66,8 @@ (** Game tree printing function. *) -val str : ('a -> string) -> ?depth:int -> 'a game_tree -> string +val str : ('a -> string) -> ?upto:int -> ?struc:bool -> ?depth:int -> + 'a game_tree -> string (** The values of a game tree node. *) val node_values : 'a game_tree -> float array Modified: trunk/Toss/Play/Play.ml =================================================================== --- trunk/Toss/Play/Play.ml 2011-03-25 20:12:20 UTC (rev 1392) +++ trunk/Toss/Play/Play.ml 2011-03-25 22:24:30 UTC (rev 1393) @@ -19,15 +19,9 @@ let maximax_depth_choice ab stop_vals dp game cur_state player info children = let mval child = (node_values (snd child)).(player), node_info (snd child) in - let cmp_raw c1 c2 = + let cmp c1 c2 = let (v1, d1), (v2, d2) = mval c1, mval c2 in if v1 > v2 then 1 else if v2 > v1 then -1 else d1 - d2 in - let cmp c1 c2 = - match snd c1, snd c2 with - | Terminal _, Terminal _ -> cmp_raw c1 c2 - | Terminal _, _ -> -1 - | _, Terminal _ -> 1 - | _, _ -> cmp_raw c1 c2 in let res = Aux.random_elem (Aux.array_argfind_all_max cmp children) in if !debug_level > 2 then print_endline (Structure.str (state (snd children.(res))).Arena.struc); @@ -75,5 +69,6 @@ let u = unfold_maximax_upto ~ab count game heur t in if !debug_level > 0 then Printf.printf "Timeout %f%!" (Unix.gettimeofday() -. !timeout); - if !debug_level > 2 then print_endline (str string_of_int u); + if !debug_level > 1 then + print_endline (str ~upto:1 ~struc:false string_of_int u); choose_move game u Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-03-25 20:12:20 UTC (rev 1392) +++ trunk/Toss/Server/Server.ml 2011-03-25 22:24:30 UTC (rev 1393) @@ -163,7 +163,7 @@ let req_handle in_ch out_ch = try - let time_started = Sys.time () in + let time_started = Unix.gettimeofday () in let line = read_in_line in_ch in let req = req_of_str line in let resp = @@ -396,14 +396,14 @@ else let mov_msg = if GDL.our_turn !gdl_transl !state then ( - let time_used = time_started -. Sys.time () in + let time_used = time_started -. Unix.gettimeofday () in let p, ps = match !play, !play_state with | Some play, Some play_state -> play, play_state | _ -> assert false in ignore (Unix.alarm (!playclock - (int_of_float time_used) - 1)); - Play.set_timeout (float(!playclock) -. time_used -. 0.02); + Play.set_timeout (float(!playclock) -. time_used -. 0.03); if !no_gtree then let res = Game.suggest p ps in Game.cancel_timeout (); @@ -431,7 +431,7 @@ ^ string_of_int msg_len ^ "\r\n\r\n" ^ mov_msg in if !debug_level > 0 then ( - Printf.printf "Resp-time: %F\n%!" (Sys.time () -. time_started); + Printf.printf "Resp-time: %F\n%!" (Unix.gettimeofday() -. time_started); print_endline ("\nRepl: " ^ resp ^ "\n"); ); output_string out_ch (resp ^ "\n"); Modified: trunk/Toss/examples/Gomoku.toss =================================================================== --- trunk/Toss/examples/Gomoku.toss 2011-03-25 20:12:20 UTC (rev 1392) +++ trunk/Toss/examples/Gomoku.toss 2011-03-25 22:24:30 UTC (rev 1393) @@ -1,5 +1,5 @@ PLAYERS 1, 2 -DATA r1: circle, r2: line, adv_ratio: 4, depth: 2 +DATA r1: circle, r2: line, adv_ratio: 5, depth: 2 REL Row5 (x, y, z, v, w) = R(x, y) and R(y, z) and R(z, v) and R(v, w) REL Col5 (x, y, z, v, w) = C(x, y) and C(y, z) and C(z, v) and C(v, w) REL DiagA5 (x, y, z, v, w) = Modified: trunk/Toss/examples/Tic-Tac-Toe.toss =================================================================== --- trunk/Toss/examples/Tic-Tac-Toe.toss 2011-03-25 20:12:20 UTC (rev 1392) +++ trunk/Toss/examples/Tic-Tac-Toe.toss 2011-03-25 22:24:30 UTC (rev 1393) @@ -1,5 +1,5 @@ PLAYERS 1, 2 -DATA r1: circle, r2: line, adv_ratio: 4, depth: 3 +DATA r1: circle, r2: line, adv_ratio: 5, depth: 3 REL DiagA (x, y) = ex u (R(x, u) and C(u, y)) REL DiagB (x, y) = ex u (R(x, u) and C(y, u)) REL Row3 (x, y, z) = R(x, y) and R(y, z) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-25 20:12:26
|
Revision: 1392 http://toss.svn.sourceforge.net/toss/?rev=1392&view=rev Author: lukstafi Date: 2011-03-25 20:12:20 +0000 (Fri, 25 Mar 2011) Log Message: ----------- More logging. Heuristic: optional force-competitive reduces the default_heuristic_old to zero-sum (off by default, but currently always set on when playing GDL). Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/ContinuousRule.ml trunk/Toss/Arena/ContinuousRule.mli trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/Arena/DiscreteRule.mli trunk/Toss/GGP/GDL.ml trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/Heuristic.mli trunk/Toss/Server/Server.ml Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/Arena/Arena.ml 2011-03-25 20:12:20 UTC (rev 1392) @@ -322,7 +322,7 @@ let equational_def_style = ref true -let fprint_state ppf +let fprint_state_full print_compiled_rules ppf ({rules = rules; graph = graph; num_players = num_players; @@ -356,7 +356,7 @@ data; List.iter (fun (rname, r) -> Format.fprintf ppf "@[<1>RULE %s:@ %a@]@ " rname - ContinuousRule.fprint r) rules; + (ContinuousRule.fprint_full print_compiled_rules) r) rules; Array.iter (fun loc -> Format.fprintf ppf "@[<1>LOC %d@ {@,@[<1>@,%a@]@,}@]@ " loc.id (fprint_loc_body struc player_names) loc) graph; @@ -368,12 +368,19 @@ Format.fprintf ppf "@[<1>TIME@ %F@]@ " time; Format.fprintf ppf "@]" +let fprint_state = fprint_state_full false + let print_state r = fprint_state Format.std_formatter r let sprint_state r = ignore (Format.flush_str_formatter ()); fprint_state Format.str_formatter r; Format.flush_str_formatter () +let sprint_state_full r = + ignore (Format.flush_str_formatter ()); + fprint_state_full true Format.str_formatter r; + Format.flush_str_formatter () + let str game = sprint_state (game, snd empty_state) let state_str state = sprint_state state Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/Arena/Arena.mli 2011-03-25 20:12:20 UTC (rev 1392) @@ -64,9 +64,13 @@ syntax. Defaults to [true]. *) val equational_def_style : bool ref +val fprint_state_full : + bool -> Format.formatter -> game * game_state -> unit val fprint_state : Format.formatter -> game * game_state -> unit val print_state : game * game_state -> unit val sprint_state : game * game_state -> string +(** For the rules of the game, also print their compiled forms. *) +val sprint_state_full : game * game_state -> string (** The order of following entries matters: [DefPlayers] adds more players, with consecutive numbers starting from first available; Modified: trunk/Toss/Arena/ContinuousRule.ml =================================================================== --- trunk/Toss/Arena/ContinuousRule.ml 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/Arena/ContinuousRule.ml 2011-03-25 20:12:20 UTC (rev 1392) @@ -227,7 +227,7 @@ let has_update r = r.update <> [] (* List.exists (fun ((f, a), t) -> t <> Term.FVar (f,a)) r.update *) -let fprint f r = +let fprint_full print_compiled f r = Format.fprintf f "@[<1>%a" DiscreteRule.fprint_rule r.discrete; if has_dynamics r then Format.fprintf f "@ @[<hv>dynamics@ %a@]" @@ -235,6 +235,9 @@ if has_update r then Format.fprintf f "@ @[<hv>update@ %a@]" (Term.fprint_eqs ~diff:false) r.update; + if print_compiled then + Format.fprintf f "@ @[<1>compiled@ %a@]" + DiscreteRule.fprint_rule_obj r.compiled; if r.discrete.DiscreteRule.pre <> Formula.And [] then Format.fprintf f "@ @[<1>pre@ %a@]" Formula.fprint r.discrete.DiscreteRule.pre; @@ -244,6 +247,8 @@ Format.fprintf f "@ @[<1>post@ %a@]" Formula.fprint r.post; Format.fprintf f "@]" +let fprint = fprint_full false + let print r = fprint Format.std_formatter r let sprint r = ignore (Format.flush_str_formatter ()); Modified: trunk/Toss/Arena/ContinuousRule.mli =================================================================== --- trunk/Toss/Arena/ContinuousRule.mli 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/Arena/ContinuousRule.mli 2011-03-25 20:12:20 UTC (rev 1392) @@ -36,6 +36,7 @@ (** Print a rule to string. *) val str : rule -> string +val fprint_full : bool -> Format.formatter -> rule -> unit val fprint : Format.formatter -> rule -> unit val print : rule -> unit val sprint : rule -> string Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/Arena/DiscreteRule.ml 2011-03-25 20:12:20 UTC (rev 1392) @@ -1155,7 +1155,19 @@ Formula.str obj.lhs_form ^ "-> " ^ Formula.str (And (plits @ nlits)) +let fprint_rule_obj f obj = + let plits = Aux.concat_map (fun (r, tups) -> + List.map (fun tup->Rel (r,Array.map (fun v->`FO v) tup)) tups) + obj.rhs_pos_tuples in + let nlits = Aux.concat_map (fun (r, tups) -> + List.map (fun tup->Not (Rel (r,Array.map (fun v->`FO v) tup))) + tups) + obj.rhs_neg_tuples in + Format.fprintf f "@[<1>%a@ ->@ %a@]" + Formula.fprint obj.lhs_form + Formula.fprint (And (plits @ nlits)) + let fprint_matching f matching = let matched f (lhs,rhs) = Format.fprintf f "%d->%d" lhs rhs in Format.fprintf f "[@,@[%a@]@,]" Modified: trunk/Toss/Arena/DiscreteRule.mli =================================================================== --- trunk/Toss/Arena/DiscreteRule.mli 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/Arena/DiscreteRule.mli 2011-03-25 20:12:20 UTC (rev 1392) @@ -157,6 +157,9 @@ val fprint_rule : Format.formatter -> rule -> unit +val fprint_rule_obj : + Format.formatter -> rule_obj -> unit + val print_rule : rule -> unit val sprint_rule : rule -> string Modified: trunk/Toss/GGP/GDL.ml =================================================================== --- trunk/Toss/GGP/GDL.ml 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/GGP/GDL.ml 2011-03-25 20:12:20 UTC (rev 1392) @@ -3506,7 +3506,7 @@ ); if !debug_level > 1 then ( Printf.printf "\n\nGDL.translate_game: after simplification --\n%s\n%!" - (Arena.sprint_state result) + (Arena.sprint_state_full result) ); (* }}} *) {anchor_terms = !anchor_terms; Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/Play/Heuristic.ml 2011-03-25 20:12:20 UTC (rev 1392) @@ -254,8 +254,12 @@ let debug_level = ref 0 +(* Irrespective of the shape of payoffs, take the difference of + heuristics as the final heuristic for each player (in + {!Heuristic.default_heuristic_old}). *) +let force_competitive = ref false (* TODO: not exporting these in the API as global variables? *) -let default_nonmonot_adv_ratio = 2.0 +let default_nonmonot_adv_ratio = 4.0 let default_monot_adv_ratio = 4.0 let suggest_expansion_coef = 0.5 @@ -1078,15 +1082,20 @@ let moves = match struc with | None -> [||] | Some strc -> Move.gen_moves Move.cGRID_SIZE rules strc graph.(0) in let monotonic = !use_monotonic && (Array.length moves > 60 || - Aux.Strings.is_empty (Aux.Strings.inter all_poff_rels indef_frels)) in + Aux.Strings.is_empty (Aux.Strings.inter all_poff_rels indef_frels)) in (* {{{ log entry *) - if !debug_level > 1 then ( + if !debug_level > 0 then ( Printf.printf "default_heuristic_old: monotonic=%b; posi_frels=%s; nega_frels=%s;\ - indef_frels=%s\n%!" + indef_frels=%s; adv_ratio=%s\n%!" monotonic (String.concat ", " (Aux.Strings.elements posi_frels)) (String.concat ", " (Aux.Strings.elements nega_frels)) (String.concat ", " (Aux.Strings.elements indef_frels)) + (match advr with + | None -> "None "^ string_of_float ( + if monotonic then default_monot_adv_ratio + else default_nonmonot_adv_ratio) + | Some r -> "Some "^ string_of_float r) ); (* }}} *) let advr = @@ -1105,30 +1114,45 @@ Some (DiscreteRule.fluent_preconds drules signat posi_frels nega_frels indef_frels) else None in - Array.mapi (fun i node -> Array.map - (fun payoff -> - (* {{{ log entry *) - if !debug_level > (* 5 *) 1 then ( - Printf.printf - "default_heuristic: Computing for loc %d of payoff %s...\n%!" - i (Formula.sprint_real payoff); - ); - if !debug_level = 5 then ( - Printf.printf - "default_heuristic: Computing for loc %d\n%!" i; - ); - (* }}} *) - let res = - of_payoff ?struc ?fluent_preconds advr ~posi_frels ~nega_frels - frels payoff in - (* {{{ log entry *) - if !debug_level > (* 6 *) 1 then ( - Printf.printf "default_heuristic: %s\n%!" - (Formula.sprint_real res) - ); - (* }}} *) - res) - node.Arena.payoffs) graph + Array.mapi (fun i node -> + let res = Array.map + (fun payoff -> + (* {{{ log entry *) + if !debug_level > (* 5 *) 1 then ( + Printf.printf + "default_heuristic: Computing for loc %d of payoff %s...\n%!" + i (Formula.sprint_real payoff); + ); + if !debug_level = 5 then ( + Printf.printf + "default_heuristic: Computing for loc %d\n%!" i; + ); + (* }}} *) + let res = + of_payoff ?struc ?fluent_preconds advr ~posi_frels ~nega_frels + frels payoff in + (* {{{ log entry *) + if !debug_level > (* 6 *) 1 then ( + Printf.printf "default_heuristic: %s\n%!" + (Formula.sprint_real res) + ); + (* }}} *) + res) + node.Arena.payoffs in + if !force_competitive && Array.length res > 1 + then + Array.mapi (fun p v -> + let opponents = ref None in + for i = 0 to Array.length res - 1 do + if i <> p then ( + if !opponents = None then opponents := Some res.(i) + else opponents := + Some (Plus (Aux.unsome !opponents, res.(i)))) + done; + Plus (v, Times (Const (-1.), Aux.unsome !opponents)) + ) res + else res + ) graph let fluents_heuristic game = let (no_players, rules) = (game.Arena.num_players, game.Arena.rules) in @@ -1163,7 +1187,18 @@ Formula.Plus (p, Formula.Times (Formula.Const factor, h2.(i).(j)))) a) h1 let default_heuristic ?struc ?advr g = - mix_heur (default_heuristic_old ?struc ?advr g) 0.2 (fluents_heuristic g) + let res = + mix_heur (default_heuristic_old ?struc ?advr g) 0.2 + (fluents_heuristic g) in + if !debug_level > 1 then ( + print_endline "HEURISTIC MATRIX:"; + Array.iteri (fun loc poffs -> + Array.iteri (fun player poff -> + Printf.printf "LOC %d, player %d:\n%s\n%!" + loc player (Formula.sprint_real poff) + ) poffs ) res; + ); + res let is_constant_sum_one heur_arr = let is_const r1 r2 = Modified: trunk/Toss/Play/Heuristic.mli =================================================================== --- trunk/Toss/Play/Heuristic.mli 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/Play/Heuristic.mli 2011-03-25 20:12:20 UTC (rev 1392) @@ -59,6 +59,11 @@ val debug_level : int ref +(** Irrespective of the shape of payoffs, take the difference of + heuristics as the final heuristic for each player (in + {!Heuristic.default_heuristic_old}). *) +val force_competitive : bool ref + (** Returns a disjunction of existentially quantified conjunctions of atoms each disjunct being equivalent to the given formula in the given model. Testing purposes mostly. *) Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-03-25 17:06:20 UTC (rev 1391) +++ trunk/Toss/Server/Server.ml 2011-03-25 20:12:20 UTC (rev 1392) @@ -205,10 +205,9 @@ let heur = match !game_modified, !g_heur with | false, Some h -> h | true, _ | _, None -> - let adr = match advr with Some a -> a | None -> 4. in g_heur := Some (Heuristic.default_heuristic ~struc:(snd !state).Arena.struc - ~advr:adr (fst !state)); + ?advr (fst !state)); Aux.unsome !g_heur in let (move, _) = Play.maximax_unfold_choose effort (fst !state) (snd !state) heur in @@ -297,6 +296,8 @@ | Aux.Right (GDL.Start (_, player, game_descr, startcl, playcl)) -> Random.self_init (); (* Random.init 1234; for repeatablity *) + let old_force_competitive = !Heuristic.force_competitive in + Heuristic.force_competitive := true; let new_state, params, new_gdl_transl = GDL.initialize_game player game_descr startcl in state := new_state; gdl_transl := new_gdl_transl; @@ -313,7 +314,8 @@ playclock := playcl; g_heur := Some (Heuristic.default_heuristic ~struc:(snd !state).Arena.struc - ~advr:4. (fst !state)); + ?advr (fst !state)); + Heuristic.force_competitive := old_force_competitive; "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: 5" ^ "\r\n\r\nREADY" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-25 17:06:26
|
Revision: 1391 http://toss.svn.sourceforge.net/toss/?rev=1391&view=rev Author: lukaszkaiser Date: 2011-03-25 17:06:20 +0000 (Fri, 25 Mar 2011) Log Message: ----------- Correcting manual breakthrough translation. Modified Paths: -------------- trunk/Toss/GGP/GDL.ml trunk/Toss/Server/Server.ml Added Paths: ----------- trunk/Toss/GGP/examples/breakthrough_orig.gdl Modified: trunk/Toss/GGP/GDL.ml =================================================================== --- trunk/Toss/GGP/GDL.ml 2011-03-25 02:06:51 UTC (rev 1390) +++ trunk/Toss/GGP/GDL.ml 2011-03-25 17:06:20 UTC (rev 1391) @@ -3884,7 +3884,7 @@ match actions with | [Func ("MOVE", [Const x1; Const y1; Const x2; Const y2]); Const "NOOP"] when x1 = x2 -> - "WhiteMove", + "WhiteStraight", ["a1", Structure.board_coords_name (s2i x1, s2i y1); "a2", Structure.board_coords_name (s2i x2, s2i y2)] | [Func ("MOVE", [Const x1; Const y1; Const x2; Const y2]); @@ -3895,7 +3895,7 @@ | [Const "NOOP"; Func ("MOVE", [Const x1; Const y1; Const x2; Const y2])] when x1 = x2 -> - "BlackMove", + "BlackStraight", ["a2", Structure.board_coords_name (s2i x1, s2i y1); "a1", Structure.board_coords_name (s2i x2, s2i y2)] | [Const "NOOP"; @@ -4007,7 +4007,7 @@ let struc = (snd new_state).Arena.struc in match emb with | [(_,a); (_,b)] -> - let a, b = if rule = "BlackMove" then a, b else b, a in + let a, b = if rule = "BlackStraight" then a, b else b, a in let x1, y1 = Structure.board_elem_coords (Structure.elem_str struc a) and x2, y2 = Added: trunk/Toss/GGP/examples/breakthrough_orig.gdl =================================================================== --- trunk/Toss/GGP/examples/breakthrough_orig.gdl (rev 0) +++ trunk/Toss/GGP/examples/breakthrough_orig.gdl 2011-03-25 17:06:20 UTC (rev 1391) @@ -0,0 +1,153 @@ +; breakthrough +; +; a player wins if he reaches the opposite side of the board +; or if the opponent has no pieces left +; +; the game ends if one player wins (there is no draw) + +(role white) +(role black) +(init (cellholds 1 1 white)) +(init (cellholds 2 1 white)) +(init (cellholds 3 1 white)) +(init (cellholds 4 1 white)) +(init (cellholds 5 1 white)) +(init (cellholds 6 1 white)) +(init (cellholds 7 1 white)) +(init (cellholds 8 1 white)) +(init (cellholds 1 2 white)) +(init (cellholds 2 2 white)) +(init (cellholds 3 2 white)) +(init (cellholds 4 2 white)) +(init (cellholds 5 2 white)) +(init (cellholds 6 2 white)) +(init (cellholds 7 2 white)) +(init (cellholds 8 2 white)) +(init (cellholds 1 7 black)) +(init (cellholds 2 7 black)) +(init (cellholds 3 7 black)) +(init (cellholds 4 7 black)) +(init (cellholds 5 7 black)) +(init (cellholds 6 7 black)) +(init (cellholds 7 7 black)) +(init (cellholds 8 7 black)) +(init (cellholds 1 8 black)) +(init (cellholds 2 8 black)) +(init (cellholds 3 8 black)) +(init (cellholds 4 8 black)) +(init (cellholds 5 8 black)) +(init (cellholds 6 8 black)) +(init (cellholds 7 8 black)) +(init (cellholds 8 8 black)) +(init (control white)) +(<= (legal white (move ?x ?y1 ?x ?y2)) + (true (control white)) + (true (cellholds ?x ?y1 white)) + (++ ?y1 ?y2) + (cellempty ?x ?y2)) +(<= (legal white (move ?x1 ?y1 ?x2 ?y2)) + (true (control white)) + (true (cellholds ?x1 ?y1 white)) + (++ ?y1 ?y2) + (++ ?x1 ?x2) + (not (true (cellholds ?x2 ?y2 white)))) +(<= (legal white (move ?x1 ?y1 ?x2 ?y2)) + (true (control white)) + (true (cellholds ?x1 ?y1 white)) + (++ ?y1 ?y2) + (++ ?x2 ?x1) + (not (true (cellholds ?x2 ?y2 white)))) +(<= (legal black (move ?x ?y1 ?x ?y2)) + (true (control black)) + (true (cellholds ?x ?y1 black)) + (++ ?y2 ?y1) + (cellempty ?x ?y2)) +(<= (legal black (move ?x1 ?y1 ?x2 ?y2)) + (true (control black)) + (true (cellholds ?x1 ?y1 black)) + (++ ?y2 ?y1) + (++ ?x1 ?x2) + (not (true (cellholds ?x2 ?y2 black)))) +(<= (legal black (move ?x1 ?y1 ?x2 ?y2)) + (true (control black)) + (true (cellholds ?x1 ?y1 black)) + (++ ?y2 ?y1) + (++ ?x2 ?x1) + (not (true (cellholds ?x2 ?y2 black)))) +(<= (legal white noop) + (true (control black))) +(<= (legal black noop) + (true (control white))) +(<= (next (cellholds ?x2 ?y2 ?player)) + (role ?player) + (does ?player (move ?x1 ?y1 ?x2 ?y2))) +(<= (next (cellholds ?x3 ?y3 ?state)) + (true (cellholds ?x3 ?y3 ?state)) + (role ?player) + (does ?player (move ?x1 ?y1 ?x2 ?y2)) + (distinctcell ?x1 ?y1 ?x3 ?y3) + (distinctcell ?x2 ?y2 ?x3 ?y3)) +(<= (next (control white)) + (true (control black))) +(<= (next (control black)) + (true (control white))) +(<= terminal + whitewin) +(<= terminal + blackwin) +(<= (goal white 100) + whitewin) +(<= (goal white 0) + (not whitewin)) +(<= (goal black 100) + blackwin) +(<= (goal black 0) + (not blackwin)) +(<= (cell ?x ?y) + (index ?x) + (index ?y)) +(<= (cellempty ?x ?y) + (cell ?x ?y) + (not (true (cellholds ?x ?y white))) + (not (true (cellholds ?x ?y black)))) +(<= (distinctcell ?x1 ?y1 ?x2 ?y2) + (cell ?x1 ?y1) + (cell ?x2 ?y2) + (distinct ?x1 ?x2)) +(<= (distinctcell ?x1 ?y1 ?x2 ?y2) + (cell ?x1 ?y1) + (cell ?x2 ?y2) + (distinct ?y1 ?y2)) +(<= whitewin + (index ?x) + (true (cellholds ?x 8 white))) +(<= whitewin + (not blackcell)) +(<= blackwin + (index ?x) + (true (cellholds ?x 1 black))) +(<= blackwin + (not whitecell)) +(<= whitecell + (cell ?x ?y) + (true (cellholds ?x ?y white))) +(<= blackcell + (cell ?x ?y) + (true (cellholds ?x ?y black))) +(index 1) +(index 2) +(index 3) +(index 4) +(index 5) +(index 6) +(index 7) +(index 8) +(++ 1 2) +(++ 2 3) +(++ 3 4) +(++ 4 5) +(++ 5 6) +(++ 6 7) +(++ 7 8) + + Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-03-25 02:06:51 UTC (rev 1390) +++ trunk/Toss/Server/Server.ml 2011-03-25 17:06:20 UTC (rev 1391) @@ -622,7 +622,7 @@ parse_game_descr (String.uppercase gdl) in if !load_gdl then ( GDL.tictactoe_descr := Some (load_rules "tictactoe.gdl"); - GDL.breakthrough_descr := Some (load_rules "breakthrough.gdl"); + GDL.breakthrough_descr := Some (load_rules "breakthrough_orig.gdl"); GDL.connect5_descr := Some (load_rules "connect5.gdl"); GDL.connect4_descr := Some (load_rules "connect4.gdl"); GDL.pawn_whopping_descr := Some (load_rules "pawn_whopping.gdl"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-25 02:06:57
|
Revision: 1390 http://toss.svn.sourceforge.net/toss/?rev=1390&view=rev Author: lukaszkaiser Date: 2011-03-25 02:06:51 +0000 (Fri, 25 Mar 2011) Log Message: ----------- Avoid too fast terminal unfolding. Modified Paths: -------------- trunk/Toss/Play/GameTree.ml trunk/Toss/Play/Play.ml trunk/Toss/Server/Server.ml Modified: trunk/Toss/Play/GameTree.ml =================================================================== --- trunk/Toss/Play/GameTree.ml 2011-03-25 00:23:06 UTC (rev 1389) +++ trunk/Toss/Play/GameTree.ml 2011-03-25 02:06:51 UTC (rev 1390) @@ -60,7 +60,8 @@ (* Abstract game tree unfolding function, calls argument functions for work. *) let rec unfold_abstract ?(timeout=fun () -> false) ?(depth=0) game ~info_terminal ~info_leaf ~info_node ~choice = function - | Terminal _ -> raise Not_found + | Terminal _ -> + if !debug_level > 0 then print_endline "Terminal Unfold"; raise Not_found | Leaf (state, player, info) -> if timeout() then raise Not_found; let moves = Move.list_moves game state in Modified: trunk/Toss/Play/Play.ml =================================================================== --- trunk/Toss/Play/Play.ml 2011-03-25 00:23:06 UTC (rev 1389) +++ trunk/Toss/Play/Play.ml 2011-03-25 02:06:51 UTC (rev 1390) @@ -19,9 +19,15 @@ let maximax_depth_choice ab stop_vals dp game cur_state player info children = let mval child = (node_values (snd child)).(player), node_info (snd child) in - let cmp c1 c2 = + let cmp_raw c1 c2 = let (v1, d1), (v2, d2) = mval c1, mval c2 in if v1 > v2 then 1 else if v2 > v1 then -1 else d1 - d2 in + let cmp c1 c2 = + match snd c1, snd c2 with + | Terminal _, Terminal _ -> cmp_raw c1 c2 + | Terminal _, _ -> -1 + | _, Terminal _ -> 1 + | _, _ -> cmp_raw c1 c2 in let res = Aux.random_elem (Aux.array_argfind_all_max cmp children) in if !debug_level > 2 then print_endline (Structure.str (state (snd children.(res))).Arena.struc); @@ -63,9 +69,11 @@ let maximax_unfold_choose count game state heur = let ab = Heuristic.is_constant_sum heur in (* TODO: payoffs as well! *) if !debug_level > 0 then Printf.printf "Using Alpha-Beta: %B\n%!" ab; + if !debug_level > 3 then + Array.iter (fun h -> Array.iter Formula.print_real h) heur; let t = init game state (fun _ _ _ -> 0) heur in let u = unfold_maximax_upto ~ab count game heur t in if !debug_level > 0 then Printf.printf "Timeout %f%!" (Unix.gettimeofday() -. !timeout); - if !debug_level > 1 then print_endline (str string_of_int u); + if !debug_level > 2 then print_endline (str string_of_int u); choose_move game u Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-03-25 00:23:06 UTC (rev 1389) +++ trunk/Toss/Server/Server.ml 2011-03-25 02:06:51 UTC (rev 1390) @@ -311,7 +311,7 @@ game_modified := false; play := Some p; play_state := Some ps; playclock := playcl; - g_heur := Some (Heuristic.default_heuristic + g_heur := Some (Heuristic.default_heuristic ~struc:(snd !state).Arena.struc ~advr:4. (fst !state)); "HTTP/1.0 200 OK\r\nContent-type: text/acl\r\nContent-length: 5" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-25 00:23:12
|
Revision: 1389 http://toss.svn.sourceforge.net/toss/?rev=1389&view=rev Author: lukaszkaiser Date: 2011-03-25 00:23:06 +0000 (Fri, 25 Mar 2011) Log Message: ----------- Better timeout resolution in GameTree. Modified Paths: -------------- trunk/Toss/Play/GameTree.ml trunk/Toss/Play/GameTree.mli trunk/Toss/Play/Play.ml trunk/Toss/Server/Server.ml Modified: trunk/Toss/Play/GameTree.ml =================================================================== --- trunk/Toss/Play/GameTree.ml 2011-03-24 21:21:42 UTC (rev 1388) +++ trunk/Toss/Play/GameTree.ml 2011-03-25 00:23:06 UTC (rev 1389) @@ -58,26 +58,29 @@ (* Abstract game tree unfolding function, calls argument functions for work. *) -let rec unfold_abstract ?(depth=0) game +let rec unfold_abstract ?(timeout=fun () -> false) ?(depth=0) game ~info_terminal ~info_leaf ~info_node ~choice = function | Terminal _ -> raise Not_found | Leaf (state, player, info) -> + if timeout() then raise Not_found; let moves = Move.list_moves game state in - if moves = [||] then + if moves = [||] then ( Terminal (state, player, info_terminal depth game state player info) - else + ) else let leaf_of_move leaf_s = + if timeout() then raise Not_found; let l_pl = game.Arena.graph.(leaf_s.Arena.cur_loc).Arena.player in let l_info = info_leaf (depth+1) game leaf_s l_pl player in Leaf (leaf_s, l_pl, l_info) in let children = Array.map (fun (m, s) -> (m, leaf_of_move s)) moves in Node (state, player,info_node depth game state player children,children) | Node (state, player, info, children) -> + if timeout() then raise Not_found; let n = choice depth game state player info children in let (move, child) = children.(n) in - let child_unfolded = unfold_abstract ~depth:(depth+1) game - ~info_terminal:info_terminal ~info_leaf:info_leaf ~info_node:info_node - ~choice:choice child in + let child_unfolded = unfold_abstract ~timeout:timeout ~depth:(depth+1) + game ~info_terminal:info_terminal ~info_leaf:info_leaf + ~info_node:info_node ~choice:choice child in children.(n) <- (move, child_unfolded); Node (state, player, info_node depth game state player children, children) @@ -191,9 +194,10 @@ choice depth game state player info children (* Main unfolding function. *) -let unfold ?(ab=false) game heur ~info_leaf ~info_node ~choice = +let unfold ?(timeout=fun () -> false) ?(ab=false) game heur + ~info_leaf ~info_node ~choice = let (last_vals, stop_vals) = (ref None, ref None) in - unfold_abstract game + unfold_abstract ~timeout:timeout game ~info_terminal:(info_terminal_f info_leaf) ~info_leaf:(info_leaf_f ab last_vals stop_vals info_leaf heur) ~info_node:(info_node_f info_node) @@ -218,16 +222,17 @@ let move_s (m, n) = Move.move_gs_str_short (state n) m in if !debug_level > 0 then print_endline ("\nBest Moves: " ^ (String.concat ", " (List.map move_s maxs))); - if List.exists (fun x -> nonleaf (snd x)) maxs then + if List.exists (fun x -> nonleaf (snd x)) maxs then ( let (m, t) = Aux.random_elem maxs in (m, state t) - else ( (* Do *not* take a shallow leaf if possible. *) + ) else ( (* Do *not* take a shallow leaf if possible. *) let nonleaves = Aux.array_find_all (fun (_,c) -> nonleaf c) succ in - if nonleaves = [] then + if nonleaves = [] then ( let (m, t) = Aux.random_elem maxs in (m, state t) - else + ) else ( let upd_max mv (_, c) = max mv (node_values c).(p) in let sx = (node_values (snd (List.hd nonleaves))).(p) in let mx = List.fold_left upd_max sx nonleaves in let mxs = List.filter (fun (_,c) -> (node_values c).(p)=mx) nonleaves in let (m, t) = Aux.random_elem mxs in (m, state t) + ) ) Modified: trunk/Toss/Play/GameTree.mli =================================================================== --- trunk/Toss/Play/GameTree.mli 2011-03-24 21:21:42 UTC (rev 1388) +++ trunk/Toss/Play/GameTree.mli 2011-03-25 00:23:06 UTC (rev 1389) @@ -33,7 +33,7 @@ ('a, 'b) abstract_game_tree (** Abstract game tree unfolding function, calls argument functions for work. *) -val unfold_abstract : ?depth:int -> Arena.game -> +val unfold_abstract : ?timeout : (unit -> bool) -> ?depth : int -> Arena.game -> info_terminal : (int -> Arena.game -> Arena.game_state -> int -> 'a -> 'b) -> info_leaf : (int -> Arena.game -> Arena.game_state -> int -> int -> 'a) -> info_node : (int -> Arena.game -> Arena.game_state -> int -> @@ -85,7 +85,8 @@ Formula.real_expr array array -> 'a game_tree (** Game tree unfolding. *) -val unfold : ?ab:bool -> Arena.game -> Formula.real_expr array array -> +val unfold : ?timeout : (unit -> bool) -> ?ab:bool -> Arena.game -> + Formula.real_expr array array -> info_leaf : (int -> Arena.game -> Arena.game_state -> 'a) -> info_node : (int -> int -> float array -> (Move.move * 'a game_tree) array -> 'a) -> Modified: trunk/Toss/Play/Play.ml =================================================================== --- trunk/Toss/Play/Play.ml 2011-03-24 21:21:42 UTC (rev 1388) +++ trunk/Toss/Play/Play.ml 2011-03-25 00:23:06 UTC (rev 1389) @@ -6,9 +6,9 @@ let set_debug_level i = debug_level := i let timeout = ref 0. -let set_timeout t = timeout := Unix.time() +. t +let set_timeout t = timeout := Unix.gettimeofday() +. t let cancel_timeout () = timeout := 0. -let timed_out () = !timeout > 1. && Unix.time() > !timeout +let timed_out () = !timeout > 1. && Unix.gettimeofday() +. 0.01 > !timeout (* ------------ MAXIMAX BY DEPTH ------------- *) @@ -42,7 +42,7 @@ (* Maximax by depth unfolding function. Throws Not_found if ready. *) let unfold_maximax ?(ab=false) game heur = - unfold ~ab:ab game heur ~info_leaf:(fun _ _ _ -> 0) + unfold ~timeout:timed_out ~ab:ab game heur ~info_leaf:(fun _ _ _ -> 0) ~info_node:(maxdepth_node) ~choice:(maximax_depth_choice ab) (* Maximax unfolding upto depth. *) @@ -51,11 +51,12 @@ if !debug_level > 1 && timed_out() then print_endline "Timeout"; t - ) else + ) else try - let u = unfold_maximax ~ab:ab game heur t in - if !debug_level > 0 then Printf.printf "%d,%!" (size u); - unfold_maximax_upto ~ab:ab (count-1) game heur u + if timed_out() then t else + let u = unfold_maximax ~ab:ab game heur t in + if !debug_level > 0 then Printf.printf "%d,%!" (size u); + unfold_maximax_upto ~ab:ab (count-1) game heur u with Not_found -> t (* Maximax unfold upto depth and choose move. *) @@ -64,5 +65,7 @@ if !debug_level > 0 then Printf.printf "Using Alpha-Beta: %B\n%!" ab; let t = init game state (fun _ _ _ -> 0) heur in let u = unfold_maximax_upto ~ab count game heur t in + if !debug_level > 0 then Printf.printf "Timeout %f%!" + (Unix.gettimeofday() -. !timeout); if !debug_level > 1 then print_endline (str string_of_int u); choose_move game u Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-03-24 21:21:42 UTC (rev 1388) +++ trunk/Toss/Server/Server.ml 2011-03-25 00:23:06 UTC (rev 1389) @@ -56,9 +56,9 @@ Unix.setsockopt sock Unix.SO_REUSEADDR true; Unix.bind sock (Unix.ADDR_INET (get_inet_addr (addr_s), port)); Unix.listen sock 99; (* maximally 99 pending requests *) - let timeout = ref (Unix.time () +. float (!dtimeout)) in - while !dtimeout < 0 || Unix.time () < !timeout do - timeout := Unix.time () +. float (!dtimeout); + let timeout = ref (Unix.gettimeofday () +. float (!dtimeout)) in + while !dtimeout < 0 || Unix.gettimeofday () < !timeout do + timeout := Unix.gettimeofday () +. float (!dtimeout); let (cl_sock, _) = Unix.accept sock in f (Unix.in_channel_of_descr cl_sock) (Unix.out_channel_of_descr cl_sock); Unix.close cl_sock; @@ -401,7 +401,7 @@ play, play_state | _ -> assert false in ignore (Unix.alarm (!playclock - (int_of_float time_used) - 1)); - Play.set_timeout (float(!playclock) -. time_used -. 1.5); + Play.set_timeout (float(!playclock) -. time_used -. 0.02); if !no_gtree then let res = Game.suggest p ps in Game.cancel_timeout (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-24 21:21:48
|
Revision: 1388 http://toss.svn.sourceforge.net/toss/?rev=1388&view=rev Author: lukaszkaiser Date: 2011-03-24 21:21:42 +0000 (Thu, 24 Mar 2011) Log Message: ----------- Small corrections, timeout settings. Modified Paths: -------------- trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Formula/FormulaOps.mli trunk/Toss/GGP/GDL.ml trunk/Toss/Makefile trunk/Toss/Play/Play.ml trunk/Toss/Server/Server.ml trunk/Toss/Solver/Solver.ml trunk/Toss/WebClient/index.html Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-03-24 18:05:50 UTC (rev 1387) +++ trunk/Toss/Formula/FormulaOps.ml 2011-03-24 21:21:42 UTC (rev 1388) @@ -1307,9 +1307,9 @@ let is_fo = function `FO _ -> true | _ -> false in List.filter is_fo (free_vars f) -let rec order_by_fv structure acc_fv = function +let rec order_by_fv sizes acc_fv = function | [] -> [] - | [f] -> [order_by_fv_phi structure acc_fv f] + | [f] -> [order_by_fv_phi sizes acc_fv f] | l -> let cross x = let fv = free_vars x in @@ -1317,36 +1317,38 @@ let (cf, o) = List.partition cross l in if cf = [] then ( let new_fv = free_vars (List.hd l) in - order_by_fv structure new_fv l + order_by_fv sizes new_fv l ) else ( let new_fv = acc_fv @ (free_vars_fo (And cf)) in - (List.map (order_by_fv_phi structure acc_fv) cf) @ - (order_by_fv structure new_fv o) + (List.map (order_by_fv_phi sizes acc_fv) cf) @ + (order_by_fv sizes new_fv o) ) -and order_by_fv_phi structure acc_fv = function +and order_by_fv_phi sizes acc_fv = function | And fl -> let is_pred = function Rel (_, [|_|]) -> true | _ -> false in let (p_raw, np) = List.partition is_pred fl in - let p = match structure with | None -> p_raw | Some struc -> - let card = function | Rel (r,_) -> Structure.rel_size struc r | _-> 0 in - let cmp x y = (card x) - (card y) in - List.sort cmp p_raw in - let res = And (order_by_fv structure acc_fv (p @ np)) in + let p = match sizes with | None -> p_raw | Some slist -> + let card = function + | Rel (r, _) -> (try List.assoc r slist with Not_found -> 0) + | _-> 0 in + List.sort (fun x y -> (card x) - (card y)) p_raw in + let res = And (order_by_fv sizes acc_fv (p @ np)) in if !debug_level > 1 then print_endline ("fvordered and: " ^ (str res)); res | Or fl -> let is_pred = function Rel (_, [|_|]) -> true | _ -> false in let (p_raw, np) = List.partition is_pred fl in - let p = match structure with | None -> p_raw | Some struc -> - let card = function | Rel (r,_) -> Structure.rel_size struc r | _-> 0 in - let cmp x y = (card x) - (card y) in - List.sort cmp p_raw in - let res = Or (order_by_fv structure acc_fv (p @ np)) in + let p = match sizes with | None -> p_raw | Some slist -> + let card = function + | Rel (r, _) -> (try List.assoc r slist with Not_found -> 0) + | _-> 0 in + List.sort (fun x y -> (card x) - (card y)) p_raw in + let res = Or (order_by_fv sizes acc_fv (p @ np)) in if !debug_level > 1 then print_endline ("fvordered or: " ^ (str res)); res - | Ex (vs, phi) -> Ex (vs, order_by_fv_phi structure acc_fv phi) - | All (vs, phi) -> All (vs, order_by_fv_phi structure acc_fv phi) + | Ex (vs, phi) -> Ex (vs, order_by_fv_phi sizes acc_fv phi) + | All (vs, phi) -> All (vs, order_by_fv_phi sizes acc_fv phi) | f -> f let rec push_in_quant phi = @@ -1373,12 +1375,12 @@ let rec push_quant f = push_in_quant (flatten_sort (f)) -let tnf_fv ?structure phi = +let tnf_fv ?sizes phi = let fv = free_vars phi in let psi = rename_quant_avoiding [] (Ex (fv, phi)) in match mso_last (flatten (del_vars_quant fv (tnf psi))) with - | Or fl -> Or (List.map (order_by_fv_phi structure []) fl) - | f -> order_by_fv_phi structure [] f + | Or fl -> Or (List.map (order_by_fv_phi sizes []) fl) + | f -> order_by_fv_phi sizes [] f (* Assign emptyset to the MSO-variable v by replacing "x in X" with "false". *) let assign_emptyset v phi = Modified: trunk/Toss/Formula/FormulaOps.mli =================================================================== --- trunk/Toss/Formula/FormulaOps.mli 2011-03-24 18:05:50 UTC (rev 1387) +++ trunk/Toss/Formula/FormulaOps.mli 2011-03-24 21:21:42 UTC (rev 1388) @@ -187,7 +187,7 @@ in a NNF form which pushes quantifiers inside as strongly as possible. *) val tnf : formula -> formula val tnf_re : real_expr -> real_expr -val tnf_fv : ?structure : Structure.structure -> +val tnf_fv : ?sizes : (string * int) list -> formula -> formula (** first existentially quantifies free vars *) Modified: trunk/Toss/GGP/GDL.ml =================================================================== --- trunk/Toss/GGP/GDL.ml 2011-03-24 18:05:50 UTC (rev 1387) +++ trunk/Toss/GGP/GDL.ml 2011-03-24 21:21:42 UTC (rev 1388) @@ -3498,7 +3498,7 @@ let file = open_out ("./GGP/tests/"^game_name^"-simpl.toss") in output_string file (Arena.state_str result); close_out file); - if !debug_level > -1 then ( + if !debug_level > 1 then ( Printf.printf "\n\nGDL.translate_game: simplified rel sizes --\n%s\n%!" (String.concat ", "(List.map (fun (rel,ar) -> rel^":"^string_of_int ar) (Structure.rel_sizes Modified: trunk/Toss/Makefile =================================================================== --- trunk/Toss/Makefile 2011-03-24 18:05:50 UTC (rev 1387) +++ trunk/Toss/Makefile 2011-03-24 21:21:42 UTC (rev 1388) @@ -57,8 +57,8 @@ OCAMLBUILDNOPP=ocamlbuild -log build.log -j 8 -menhir ../menhir_conf \ $(OCB_LIB) $(OCB_CFLAG) $(OCB_LFLAG) -FormulaINC=Formula/Sat,Formula,Solver -SolverINC=Formula,Solver,Formula/Sat,Solver/RealQuantElim +FormulaINC=Formula/Sat +SolverINC=Formula,Formula/Sat,Solver/RealQuantElim ArenaINC=Formula,Formula/Sat,Solver/RealQuantElim,Solver PlayINC=Formula,Formula/Sat,Solver/RealQuantElim,Solver,Arena GGPINC=Formula,Formula/Sat,Solver/RealQuantElim,Solver,Arena,Play Modified: trunk/Toss/Play/Play.ml =================================================================== --- trunk/Toss/Play/Play.ml 2011-03-24 18:05:50 UTC (rev 1387) +++ trunk/Toss/Play/Play.ml 2011-03-24 21:21:42 UTC (rev 1388) @@ -47,8 +47,8 @@ (* Maximax unfolding upto depth. *) let rec unfold_maximax_upto ?(ab=false) count game heur t = - if count = 0 || Game.get_timeout () || timed_out () then ( - if !debug_level > 1 && (Game.get_timeout() || timed_out()) then + if count = 0 || timed_out () then ( + if !debug_level > 1 && timed_out() then print_endline "Timeout"; t ) else Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-03-24 18:05:50 UTC (rev 1387) +++ trunk/Toss/Server/Server.ml 2011-03-24 21:21:42 UTC (rev 1388) @@ -394,15 +394,14 @@ else let mov_msg = if GDL.our_turn !gdl_transl !state then ( - let time_used = - int_of_float time_started - - int_of_float (ceil (Sys.time ())) in + let time_used = time_started -. Sys.time () in let p, ps = match !play, !play_state with | Some play, Some play_state -> play, play_state | _ -> assert false in - ignore (Unix.alarm (!playclock - time_used - 1)); + ignore (Unix.alarm (!playclock - (int_of_float time_used) - 1)); + Play.set_timeout (float(!playclock) -. time_used -. 1.5); if !no_gtree then let res = Game.suggest p ps in Game.cancel_timeout (); Modified: trunk/Toss/Solver/Solver.ml =================================================================== --- trunk/Toss/Solver/Solver.ml 2011-03-24 18:05:50 UTC (rev 1387) +++ trunk/Toss/Solver/Solver.ml 2011-03-24 21:21:42 UTC (rev 1388) @@ -49,7 +49,7 @@ (Hashtbl.find solver.formulas_eval res, res) with Not_found -> if !debug_level > 0 then print_endline ("Entered " ^ (str phi)); - let psi = FormulaOps.tnf_fv ~structure:struc phi in + let psi = FormulaOps.tnf_fv ~sizes:(Structure.rel_sizes struc) phi in if !debug_level > 0 then print_endline ("Registering " ^ (str psi)); let id = Hashtbl.length solver.formulas_eval + 1 in Hashtbl.add solver.reg_formulas phi id; Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-03-24 18:05:50 UTC (rev 1387) +++ trunk/Toss/WebClient/index.html 2011-03-24 21:21:42 UTC (rev 1388) @@ -115,7 +115,21 @@ </p> <ul class="welcome-list"> -<li>Play Breakthrough, Checkers, Chess, Connect4, Gomoku, Pawn Whopping + <li>Play + <a href="http://en.wikipedia.org/wiki/Breakthrough_(board_game)" + >Breakthrough,</a> + <a href="http://en.wikipedia.org/wiki/English_draughts" + >Checkers,</a> + <a href="http://en.wikipedia.org/wiki/Chess" + >Chess,</a> + <a href="http://en.wikipedia.org/wiki/Connect4" + >Connect4,</a> + <a href="http://en.wikipedia.org/wiki/Entanglement_(graph_measure)" + >Entanglement,</a> + <a href="http://en.wikipedia.org/wiki/Gomoku" + >Gomoku,</a> + <a href="http://en.wikipedia.org/wiki/Pawn_(chess)" + >Pawn-Whopping,</a> and many other board games</li> <li>Challenge your friends or play a fast game against the computer for fun</li> <li>Focus fully on the game thanks to our intuitive clean interface</li> @@ -198,7 +212,7 @@ <p class="game-par"> <button onclick="new_play('Pawn-Whopping')" class="boldobt">Pawn-Whopping</button> - (<a href="http://en.wikipedia.org/wiki/Pawn-Whopping">info</a>) + (<a href="http://en.wikipedia.org/wiki/Pawn_(chess)">info</a>) </p> <ul class="plays-list" id="plays-list-Pawn-Whopping"> <li style="display: none;"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-24 18:05:56
|
Revision: 1387 http://toss.svn.sourceforge.net/toss/?rev=1387&view=rev Author: lukaszkaiser Date: 2011-03-24 18:05:50 +0000 (Thu, 24 Mar 2011) Log Message: ----------- Size-based predicate ordering in formula compilation. Modified Paths: -------------- trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Formula/FormulaOps.mli trunk/Toss/Makefile trunk/Toss/Solver/Solver.ml trunk/Toss/Solver/SolverTest.ml trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/Structure.mli Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-03-24 16:08:04 UTC (rev 1386) +++ trunk/Toss/Formula/FormulaOps.ml 2011-03-24 18:05:50 UTC (rev 1387) @@ -1307,9 +1307,9 @@ let is_fo = function `FO _ -> true | _ -> false in List.filter is_fo (free_vars f) -let rec order_by_fv acc_fv = function +let rec order_by_fv structure acc_fv = function | [] -> [] - | [f] -> [order_by_fv_phi acc_fv f] + | [f] -> [order_by_fv_phi structure acc_fv f] | l -> let cross x = let fv = free_vars x in @@ -1317,27 +1317,36 @@ let (cf, o) = List.partition cross l in if cf = [] then ( let new_fv = free_vars (List.hd l) in - order_by_fv new_fv l + order_by_fv structure new_fv l ) else ( let new_fv = acc_fv @ (free_vars_fo (And cf)) in - (List.map (order_by_fv_phi acc_fv) cf) @ (order_by_fv new_fv o) + (List.map (order_by_fv_phi structure acc_fv) cf) @ + (order_by_fv structure new_fv o) ) -and order_by_fv_phi acc_fv = function +and order_by_fv_phi structure acc_fv = function | And fl -> let is_pred = function Rel (_, [|_|]) -> true | _ -> false in - let (p, np) = List.partition is_pred fl in - let res = And (order_by_fv acc_fv (p @ np)) in + let (p_raw, np) = List.partition is_pred fl in + let p = match structure with | None -> p_raw | Some struc -> + let card = function | Rel (r,_) -> Structure.rel_size struc r | _-> 0 in + let cmp x y = (card x) - (card y) in + List.sort cmp p_raw in + let res = And (order_by_fv structure acc_fv (p @ np)) in if !debug_level > 1 then print_endline ("fvordered and: " ^ (str res)); res | Or fl -> let is_pred = function Rel (_, [|_|]) -> true | _ -> false in - let (p, np) = List.partition is_pred fl in - let res = Or (order_by_fv acc_fv (p @ np)) in + let (p_raw, np) = List.partition is_pred fl in + let p = match structure with | None -> p_raw | Some struc -> + let card = function | Rel (r,_) -> Structure.rel_size struc r | _-> 0 in + let cmp x y = (card x) - (card y) in + List.sort cmp p_raw in + let res = Or (order_by_fv structure acc_fv (p @ np)) in if !debug_level > 1 then print_endline ("fvordered or: " ^ (str res)); res - | Ex (vs, phi) -> Ex (vs, order_by_fv_phi acc_fv phi) - | All (vs, phi) -> All (vs, order_by_fv_phi acc_fv phi) + | Ex (vs, phi) -> Ex (vs, order_by_fv_phi structure acc_fv phi) + | All (vs, phi) -> All (vs, order_by_fv_phi structure acc_fv phi) | f -> f let rec push_in_quant phi = @@ -1364,12 +1373,12 @@ let rec push_quant f = push_in_quant (flatten_sort (f)) -let tnf_fv phi = +let tnf_fv ?structure phi = let fv = free_vars phi in let psi = rename_quant_avoiding [] (Ex (fv, phi)) in match mso_last (flatten (del_vars_quant fv (tnf psi))) with - | Or fl -> Or (List.map (order_by_fv_phi []) fl) - | f -> order_by_fv_phi [] f + | Or fl -> Or (List.map (order_by_fv_phi structure []) fl) + | f -> order_by_fv_phi structure [] f (* Assign emptyset to the MSO-variable v by replacing "x in X" with "false". *) let assign_emptyset v phi = Modified: trunk/Toss/Formula/FormulaOps.mli =================================================================== --- trunk/Toss/Formula/FormulaOps.mli 2011-03-24 16:08:04 UTC (rev 1386) +++ trunk/Toss/Formula/FormulaOps.mli 2011-03-24 18:05:50 UTC (rev 1387) @@ -187,7 +187,8 @@ in a NNF form which pushes quantifiers inside as strongly as possible. *) val tnf : formula -> formula val tnf_re : real_expr -> real_expr -val tnf_fv : formula -> formula (** first existentially quantifies free vars *) +val tnf_fv : ?structure : Structure.structure -> + formula -> formula (** first existentially quantifies free vars *) (** {2 Convert to CNF or DNF} *) Modified: trunk/Toss/Makefile =================================================================== --- trunk/Toss/Makefile 2011-03-24 16:08:04 UTC (rev 1386) +++ trunk/Toss/Makefile 2011-03-24 18:05:50 UTC (rev 1387) @@ -57,8 +57,8 @@ OCAMLBUILDNOPP=ocamlbuild -log build.log -j 8 -menhir ../menhir_conf \ $(OCB_LIB) $(OCB_CFLAG) $(OCB_LFLAG) -FormulaINC=Formula/Sat -SolverINC=Formula,Formula/Sat,Solver/RealQuantElim +FormulaINC=Formula/Sat,Formula,Solver +SolverINC=Formula,Solver,Formula/Sat,Solver/RealQuantElim ArenaINC=Formula,Formula/Sat,Solver/RealQuantElim,Solver PlayINC=Formula,Formula/Sat,Solver/RealQuantElim,Solver,Arena GGPINC=Formula,Formula/Sat,Solver/RealQuantElim,Solver,Arena,Play Modified: trunk/Toss/Solver/Solver.ml =================================================================== --- trunk/Toss/Solver/Solver.ml 2011-03-24 16:08:04 UTC (rev 1386) +++ trunk/Toss/Solver/Solver.ml 2011-03-24 18:05:50 UTC (rev 1387) @@ -39,7 +39,7 @@ formulas_check = Hashtbl.create 3 ; } -let register_formula_do solver phi = +let register_formula_do struc solver phi = let rec check_form = function Ex (vs, phi) -> check_form phi | phi -> phi in @@ -49,7 +49,7 @@ (Hashtbl.find solver.formulas_eval res, res) with Not_found -> if !debug_level > 0 then print_endline ("Entered " ^ (str phi)); - let psi = FormulaOps.tnf_fv phi in + let psi = FormulaOps.tnf_fv ~structure:struc phi in if !debug_level > 0 then print_endline ("Registering " ^ (str psi)); let id = Hashtbl.length solver.formulas_eval + 1 in Hashtbl.add solver.reg_formulas phi id; @@ -57,7 +57,7 @@ Hashtbl.add solver.formulas_check id (check_form psi); (psi, id) -let register_formula_s solver phi = +let register_formula_s struc solver phi = try let res = Hashtbl.find solver.reg_formulas phi in if !debug_level > 0 then print_endline ("DirectFound " ^ (str phi)); @@ -65,14 +65,15 @@ with Not_found -> match Formula.flatten phi with | And fl -> - let rfl = List.map (fun f -> fst (register_formula_do solver f)) fl in + let rfl = List.map (fun f -> + fst (register_formula_do struc solver f)) fl in let id = Hashtbl.length solver.formulas_eval + 1 in let psi = Formula.flatten (Or (FormulaOps.to_dnf (And rfl))) in Hashtbl.add solver.reg_formulas phi id; Hashtbl.add solver.formulas_eval id psi; Hashtbl.add solver.formulas_check id psi; id - | _ -> let (_, id) = register_formula_do solver phi in id + | _ -> let (_, id) = register_formula_do struc solver phi in id let get_formula solver i = Hashtbl.find solver.formulas_eval i @@ -357,7 +358,8 @@ let phi_id = Hashtbl.find solver.reg_formulas phi in Hashtbl.find solver.formulas_eval phi_id with Not_found -> - Hashtbl.find solver.formulas_eval (snd(register_formula_do solver phi)) in + Hashtbl.find solver.formulas_eval + (snd(register_formula_do struc solver phi)) in let eval_no_fv phi = if FormulaOps.free_vars phi = [] then ( if !debug_level > 1 then @@ -472,14 +474,14 @@ let solver = new_solver () let evaluate struc phi = - evaluate solver ~formula:(register_formula_s solver phi) struc + evaluate solver ~formula:(register_formula_s struc solver phi) struc let evaluate_real = evaluate_real let evaluate_partial struc intpr phi = - evaluate_partial_aset solver ~formula:(register_formula_s solver phi) + evaluate_partial_aset solver ~formula:(register_formula_s struc solver phi) struc intpr let check struc phi = - check solver ~formula:(register_formula_s solver phi) struc + check solver ~formula:(register_formula_s struc solver phi) struc let get_real_val re struc = get_real_val_cache solver struc re let formula_str phi = (* let phi = Hashtbl.find solver.formulas_check phi in *) Modified: trunk/Toss/Solver/SolverTest.ml =================================================================== --- trunk/Toss/Solver/SolverTest.ml 2011-03-24 16:08:04 UTC (rev 1386) +++ trunk/Toss/Solver/SolverTest.ml 2011-03-24 18:05:50 UTC (rev 1387) @@ -259,7 +259,7 @@ ] ;; -let a () = +let a = match test_filter [""] tests with | Some tests -> Aux.run_test_if_target "SolverTest" tests | None -> () Modified: trunk/Toss/Solver/Structure.ml =================================================================== --- trunk/Toss/Solver/Structure.ml 2011-03-24 16:08:04 UTC (rev 1386) +++ trunk/Toss/Solver/Structure.ml 2011-03-24 18:05:50 UTC (rev 1387) @@ -57,6 +57,12 @@ (* ----------------------- BASIC HELPER FUNCTIONS --------------------------- *) +(* Number of tuples in a relation. *) +let rel_size struc rel = + try + Tuples.cardinal (StringMap.find rel struc.relations) + with Not_found -> 0 + (* Reverse a map: make a string IntMap from an int StringMap. *) let rev_string_to_int_map map = StringMap.fold (fun n e m -> IntMap.add e n m) map IntMap.empty Modified: trunk/Toss/Solver/Structure.mli =================================================================== --- trunk/Toss/Solver/Structure.mli 2011-03-24 16:08:04 UTC (rev 1386) +++ trunk/Toss/Solver/Structure.mli 2011-03-24 18:05:50 UTC (rev 1387) @@ -34,6 +34,8 @@ (** {2 Basic helper functions} *) +(** Size of a relation, i.e. number of tuples in it. *) +val rel_size : structure -> string -> int (** Reverse a map: make a string IntMap from an int StringMap. *) val rev_string_to_int_map : int StringMap.t -> string IntMap.t This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-24 16:08:10
|
Revision: 1386 http://toss.svn.sourceforge.net/toss/?rev=1386&view=rev Author: lukstafi Date: 2011-03-24 16:08:04 +0000 (Thu, 24 Mar 2011) Log Message: ----------- Diagnostic display of cardinality of graphs of all relations in GDL translation result. Modified Paths: -------------- trunk/Toss/GGP/GDL.ml trunk/Toss/Solver/Structure.ml trunk/Toss/Solver/Structure.mli Modified: trunk/Toss/GGP/GDL.ml =================================================================== --- trunk/Toss/GGP/GDL.ml 2011-03-24 13:27:48 UTC (rev 1385) +++ trunk/Toss/GGP/GDL.ml 2011-03-24 16:08:04 UTC (rev 1386) @@ -3491,13 +3491,19 @@ | Some ([_; lead_term], _, _) -> Some lead_term | _ -> None ) loc_noop_legal in - (* {{{ log entry *) + (* {{{ log entry *) (match !generate_test_case with | None -> () | Some game_name -> let file = open_out ("./GGP/tests/"^game_name^"-simpl.toss") in output_string file (Arena.state_str result); close_out file); + if !debug_level > -1 then ( + Printf.printf "\n\nGDL.translate_game: simplified rel sizes --\n%s\n%!" + (String.concat ", "(List.map (fun (rel,ar) -> + rel^":"^string_of_int ar) (Structure.rel_sizes + (snd result).Arena.struc))) + ); if !debug_level > 1 then ( Printf.printf "\n\nGDL.translate_game: after simplification --\n%s\n%!" (Arena.sprint_state result) Modified: trunk/Toss/Solver/Structure.ml =================================================================== --- trunk/Toss/Solver/Structure.ml 2011-03-24 13:27:48 UTC (rev 1385) +++ trunk/Toss/Solver/Structure.ml 2011-03-24 16:08:04 UTC (rev 1386) @@ -80,7 +80,11 @@ StringMap.fold (fun r ar si -> (r,ar)::si) struc.rel_signature [] +let rel_sizes struc = + StringMap.fold (fun r tups si -> (r,Tuples.cardinal tups)::si) + struc.relations [] + (* Return the list of relation tuples incident to an element [e] in [struc]. *) let incident struc e = let acc_incident rname inc_map acc = Modified: trunk/Toss/Solver/Structure.mli =================================================================== --- trunk/Toss/Solver/Structure.mli 2011-03-24 13:27:48 UTC (rev 1385) +++ trunk/Toss/Solver/Structure.mli 2011-03-24 16:08:04 UTC (rev 1386) @@ -61,6 +61,9 @@ val rel_signature : structure -> (string * int) list +(** Cardinality of graphs of all relations in the structure. *) +val rel_sizes : structure -> (string * int) list + (** {2 Printing structures} *) (** Print the elements [e] as string. *) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-24 13:27:55
|
Revision: 1385 http://toss.svn.sourceforge.net/toss/?rev=1385&view=rev Author: lukstafi Date: 2011-03-24 13:27:48 +0000 (Thu, 24 Mar 2011) Log Message: ----------- GameSimpl: do not inverse-glue any relation with an equivalence relation (the latter is symmetric). Heuristic: looser (but more sensible) restrictions on expansion pattern-search-tree growth. Modified Paths: -------------- trunk/Toss/Formula/Aux.ml trunk/Toss/Formula/Aux.mli trunk/Toss/GGP/GameSimpl.ml trunk/Toss/GGP/GameSimplTest.ml trunk/Toss/GGP/tests/breakthrough-simpl.toss trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/HeuristicTest.ml Modified: trunk/Toss/Formula/Aux.ml =================================================================== --- trunk/Toss/Formula/Aux.ml 2011-03-23 21:14:31 UTC (rev 1384) +++ trunk/Toss/Formula/Aux.ml 2011-03-24 13:27:48 UTC (rev 1385) @@ -239,6 +239,16 @@ | [] -> acc in List.rev (aux [] l) +let add_to_maximal cmp l1 l2 = + let rec aux acc = function + | hd::tl when + not (List.exists (fun x-> cmp hd x) acc) && + not (List.exists (fun x-> cmp hd x) tl) -> + aux (hd::acc) tl + | hd::tl -> aux acc tl + | [] -> acc in + List.rev (aux (List.rev l2) l1) + (* Not tail-recursive. *) let unique_sorted l = let rec idemp = function Modified: trunk/Toss/Formula/Aux.mli =================================================================== --- trunk/Toss/Formula/Aux.mli 2011-03-23 21:14:31 UTC (rev 1384) +++ trunk/Toss/Formula/Aux.mli 2011-03-24 13:27:48 UTC (rev 1385) @@ -151,6 +151,10 @@ equal elements only the last one is preserved.) *) val maximal : ('a -> 'a -> bool) -> 'a list -> 'a list +(** Assuming that [l2] already has only maximal elements, + [add_to_maximal cmp l1 l2] computes [maximal cmp (l1 @ l2)]. *) +val add_to_maximal : ('a -> 'a -> bool) -> 'a list -> 'a list -> 'a list + (** Return the list of structurally unique elements, in order sorted by {!Pervasives.compare}. Not tail-recursive. *) val unique_sorted : 'a list -> 'a list Modified: trunk/Toss/GGP/GameSimpl.ml =================================================================== --- trunk/Toss/GGP/GameSimpl.ml 2011-03-23 21:14:31 UTC (rev 1384) +++ trunk/Toss/GGP/GameSimpl.ml 2011-03-24 13:27:48 UTC (rev 1385) @@ -62,7 +62,10 @@ (3b) For binary static relations, collect pairs such that one relation is applied to arguments in reverse order than the other one, and introduce a new relation for intersection of one with the - inverse of the other. + inverse of the other, but only if neither of them is an + equivalence relation beginning with "EQ__" -- in the latter case, + use a relation introduced in (3a) (introduce if not present), only + with arguments in order reverse to the order of non-EQ relation. (3c) Filter out relations beginning with "EQ__" by: (3c1) collecting equivalent elements in families of sets indexed by EQ @@ -189,14 +192,14 @@ crel <> None || ntups <= nelems / 2 then crel else - (* 1a *) + (* 1a *) let crel = Aux.not_conflicting_name ~truncate:true !used_rels "C" in - (* {{{ log entry *) + (* {{{ log entry *) if !debug_level > 3 then ( Printf.printf "Complemented: crel=%s\n%!" crel ); - (* }}} *) + (* }}} *) complemented := (crel, rel) :: !complemented; struc := Structure.add_rels !struc crel (Tups.elements (Tups.diff predicate_tups rel_tups)); @@ -471,23 +474,24 @@ let is_equiv rel = String.length rel >= 4 && String.sub rel 0 4 = "EQ__" in (* 3a *) + let glue_rels_args rels args = + let rels = List.sort String.compare rels in + (let try grel = Aux.rev_assoc !glued rels in + grel, args + with Not_found -> + let grel = + Aux.not_conflicting_name ~truncate:true !used_rels "R" in + used_rels := Aux.Strings.add grel !used_rels; + glued := (grel, rels) :: !glued; + struc := intersect_rels !struc grel rels; + signat := (grel, Array.length args) :: !signat; + grel, args) in let glue rels = let args_keys = Aux.collect (List.map (fun (rel,args)->args,rel) rels) in List.map (function | args, [rel] -> rel, args - | args, rels -> - let rels = List.sort String.compare rels in - (let try grel = Aux.rev_assoc !glued rels in - grel, args - with Not_found -> - let grel = - Aux.not_conflicting_name ~truncate:true !used_rels "R" in - used_rels := Aux.Strings.add grel !used_rels; - glued := (grel, rels) :: !glued; - struc := intersect_rels !struc grel rels; - signat := (grel, Array.length args) :: !signat; - grel, args) + | args, rels -> glue_rels_args rels args ) args_keys in (* 3b *) let glue_inv rels = @@ -500,22 +504,30 @@ if List.mem_assoc args2 more then let rel2, more = Aux.pop_assoc args2 more in - let rels = - if rel1 < rel2 then rel1, rel2 else rel2, rel1 in - let rel, args, inv_rel, inv_args = - if rel1 == fst rels - then rel1, args1, rel2, args2 - else rel2, args2, rel1, args1 in - (let try grel = Aux.rev_assoc !glued_inv rels in - (grel, args)::loop more - with Not_found -> - let grel = - Aux.not_conflicting_name ~truncate:true !used_rels "R" in - used_rels := Aux.Strings.add grel !used_rels; - glued_inv := (grel, rels) :: !glued_inv; - struc := intersect_with_inv !struc grel rel inv_rel; - signat := (grel, Array.length args) :: !signat; - (grel, args)::loop more) + if is_equiv rel1 || is_equiv rel2 then + let args, inv_args = + if is_equiv rel1 then args1, args2 + else args2, args1 in + let rels = [rel1; rel2] in + let result = glue_rels_args rels inv_args in + result::loop more + else + let rels = + if rel1 < rel2 then rel1, rel2 else rel2, rel1 in + let rel, args, inv_rel, inv_args = + if rel1 == fst rels + then rel1, args1, rel2, args2 + else rel2, args2, rel1, args1 in + (let try grel = Aux.rev_assoc !glued_inv rels in + (grel, args)::loop more + with Not_found -> + let grel = + Aux.not_conflicting_name ~truncate:true !used_rels "R" in + used_rels := Aux.Strings.add grel !used_rels; + glued_inv := (grel, rels) :: !glued_inv; + struc := intersect_with_inv !struc grel rel inv_rel; + signat := (grel, Array.length args) :: !signat; + (grel, args)::loop more) else (rel1, args1)::loop more | (args, rel)::rels -> (rel, args)::loop rels | [] -> [] in @@ -644,15 +656,27 @@ if List.mem_assoc args2 more then let rel2, more = Aux.pop_assoc args2 more in - let rels = - if rel1 < rel2 then rel1, rel2 else rel2, rel1 in - let rel, args, inv_rel, inv_args = - if rel1 == fst rels - then rel1, args1, rel2, args2 - else rel2, args2, rel1, args1 in - (let try grel = Aux.rev_assoc !glued_inv rels in - (grel, rels, args, inv_args)::loop more - with Not_found -> assert false) + if is_equiv rel1 || is_equiv rel2 then + let eq_rel, eq_args, inv_rel, inv_args = + if is_equiv rel1 then rel1, args1, rel2, args2 + else rel2, args2, rel1, args1 in + let rels = [rel1; rel2] in + let rels = List.sort String.compare rels in + (* pretend the equivalence is the inverted one *) + let result = + Aux.rev_assoc !glued rels, + (inv_rel, eq_rel), inv_args, eq_args in + result::loop more + else + let rels = + if rel1 < rel2 then rel1, rel2 else rel2, rel1 in + let rel, args, inv_rel, inv_args = + if rel1 == fst rels + then rel1, args1, rel2, args2 + else rel2, args2, rel1, args1 in + (let try grel = Aux.rev_assoc !glued_inv rels in + (grel, rels, args, inv_args)::loop more + with Not_found -> assert false) else loop more | _::rels -> loop rels | [] -> [] in Modified: trunk/Toss/GGP/GameSimplTest.ml =================================================================== --- trunk/Toss/GGP/GameSimplTest.ml 2011-03-23 21:14:31 UTC (rev 1384) +++ trunk/Toss/GGP/GameSimplTest.ml 2011-03-24 13:27:48 UTC (rev 1385) @@ -62,7 +62,7 @@ (* The action below is used to regenerate the test targets when {!GameSimpl.simplify} changes. *) let a () = - let game_name = "connect5" in + let game_name = (* "breakthrough" *) (* "connect5" *) "tictactoe" in let game = state_of_file ("./GGP/tests/"^game_name^"-raw.toss") in Printf.printf "\nINPUT:\n%s\n%!" (Arena.state_str game); Modified: trunk/Toss/GGP/tests/breakthrough-simpl.toss =================================================================== --- trunk/Toss/GGP/tests/breakthrough-simpl.toss 2011-03-23 21:14:31 UTC (rev 1384) +++ trunk/Toss/GGP/tests/breakthrough-simpl.toss 2011-03-24 13:27:48 UTC (rev 1385) @@ -4,8 +4,6 @@ EQ___cellholds_x2_y2_MV1_x2__AND__succ__cellholds_x2_y2_MV1_y2__cellholds_x2_y2_MV1_y2, R0: succ__cellholds_x2_y2_MV1_x2__cellholds_x2_y2_MV1_x2__AND__succ__cellholds_x2_y2_MV1_y2__cellholds_x2_y2_MV1_y2, - R2: - EQ___cellholds_x2_y2_MV1_x2__AND_INV__succ__cellholds_x2_y2_MV1_y2__cellholds_x2_y2_MV1_y2, R: succ__cellholds_x2_y2_MV1_x2__cellholds_x2_y2_MV1_x2__AND_INV__succ__cellholds_x2_y2_MV1_y2__cellholds_x2_y2_MV1_y2 RULE move_x1_y1_x2_y2_0: @@ -189,7 +187,7 @@ not control_MV1(cellholds_x377_y369__blank_))) RULE move_x_y1_x_y2_1: [cellholds_x_y1__blank_, cellholds_x_y2__blank_, control__blank_ | - R2 (cellholds_x_y1__blank_, cellholds_x_y2__blank_); + R1 (cellholds_x_y2__blank_, cellholds_x_y1__blank_); _opt_cellholds_x2_y2_black (control__blank_); _opt_cellholds_x2_y2_white {cellholds_x_y1__blank_; control__blank_}; _opt_control_black {cellholds_x_y1__blank_; cellholds_x_y2__blank_}; @@ -467,64 +465,6 @@ (cellholds_1_2_MV1, cellholds_1_3_MV1); (cellholds_1_1_MV1, cellholds_1_2_MV1) }; - R2 { - (cellholds_8_8_MV1, cellholds_8_7_MV1); - (cellholds_8_7_MV1, cellholds_8_6_MV1); - (cellholds_8_6_MV1, cellholds_8_5_MV1); - (cellholds_8_5_MV1, cellholds_8_4_MV1); - (cellholds_8_4_MV1, cellholds_8_3_MV1); - (cellholds_8_3_MV1, cellholds_8_2_MV1); - (cellholds_8_2_MV1, cellholds_8_1_MV1); - (cellholds_7_8_MV1, cellholds_7_7_MV1); - (cellholds_7_7_MV1, cellholds_7_6_MV1); - (cellholds_7_6_MV1, cellholds_7_5_MV1); - (cellholds_7_5_MV1, cellholds_7_4_MV1); - (cellholds_7_4_MV1, cellholds_7_3_MV1); - (cellholds_7_3_MV1, cellholds_7_2_MV1); - (cellholds_7_2_MV1, cellholds_7_1_MV1); - (cellholds_6_8_MV1, cellholds_6_7_MV1); - (cellholds_6_7_MV1, cellholds_6_6_MV1); - (cellholds_6_6_MV1, cellholds_6_5_MV1); - (cellholds_6_5_MV1, cellholds_6_4_MV1); - (cellholds_6_4_MV1, cellholds_6_3_MV1); - (cellholds_6_3_MV1, cellholds_6_2_MV1); - (cellholds_6_2_MV1, cellholds_6_1_MV1); - (cellholds_5_8_MV1, cellholds_5_7_MV1); - (cellholds_5_7_MV1, cellholds_5_6_MV1); - (cellholds_5_6_MV1, cellholds_5_5_MV1); - (cellholds_5_5_MV1, cellholds_5_4_MV1); - (cellholds_5_4_MV1, cellholds_5_3_MV1); - (cellholds_5_3_MV1, cellholds_5_2_MV1); - (cellholds_5_2_MV1, cellholds_5_1_MV1); - (cellholds_4_8_MV1, cellholds_4_7_MV1); - (cellholds_4_7_MV1, cellholds_4_6_MV1); - (cellholds_4_6_MV1, cellholds_4_5_MV1); - (cellholds_4_5_MV1, cellholds_4_4_MV1); - (cellholds_4_4_MV1, cellholds_4_3_MV1); - (cellholds_4_3_MV1, cellholds_4_2_MV1); - (cellholds_4_2_MV1, cellholds_4_1_MV1); - (cellholds_3_8_MV1, cellholds_3_7_MV1); - (cellholds_3_7_MV1, cellholds_3_6_MV1); - (cellholds_3_6_MV1, cellholds_3_5_MV1); - (cellholds_3_5_MV1, cellholds_3_4_MV1); - (cellholds_3_4_MV1, cellholds_3_3_MV1); - (cellholds_3_3_MV1, cellholds_3_2_MV1); - (cellholds_3_2_MV1, cellholds_3_1_MV1); - (cellholds_2_8_MV1, cellholds_2_7_MV1); - (cellholds_2_7_MV1, cellholds_2_6_MV1); - (cellholds_2_6_MV1, cellholds_2_5_MV1); - (cellholds_2_5_MV1, cellholds_2_4_MV1); - (cellholds_2_4_MV1, cellholds_2_3_MV1); - (cellholds_2_3_MV1, cellholds_2_2_MV1); - (cellholds_2_2_MV1, cellholds_2_1_MV1); - (cellholds_1_8_MV1, cellholds_1_7_MV1); - (cellholds_1_7_MV1, cellholds_1_6_MV1); - (cellholds_1_6_MV1, cellholds_1_5_MV1); - (cellholds_1_5_MV1, cellholds_1_4_MV1); - (cellholds_1_4_MV1, cellholds_1_3_MV1); - (cellholds_1_3_MV1, cellholds_1_2_MV1); - (cellholds_1_2_MV1, cellholds_1_1_MV1) - }; cellholds_1_y2_MV1 { cellholds_1_8_MV1; cellholds_1_7_MV1; cellholds_1_6_MV1; cellholds_1_5_MV1; cellholds_1_4_MV1; cellholds_1_3_MV1; Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-23 21:14:31 UTC (rev 1384) +++ trunk/Toss/Play/Heuristic.ml 2011-03-24 13:27:48 UTC (rev 1385) @@ -244,7 +244,6 @@ conjunctions whose sets of variable instantiations is a subset of some other. - TODO: perhaps the costly filtering above can be made online? *) open Formula open Aux @@ -386,6 +385,9 @@ let expanded_descr max_alt_descr elems rels struc all_vars xvars xsubsts = + (* for doing (m) online *) + let cmp_insts (_,_,insts1) (_,_,insts2) = + List.for_all (fun sb->List.mem sb insts2) insts1 in let alt_descr = ref 0 in let max_arity = find_max (-) (List.map (fun (_,tups) -> @@ -399,21 +401,21 @@ let partition_substs substs = let rec aux_x acc = function | TrieLeaf sbs, [] -> - TrieLeaf (List.rev acc::sbs) + TrieLeaf (List.rev acc::sbs) | TrieNode map, ((_, e as xe)::sb as xesb) -> - (try - let trie = - aux_x (xe::acc) (List.assoc e map, sb) in - TrieNode (replace_assoc e trie map) - with Not_found -> - raise (Outside_subst (List.rev_append acc xesb))) + (try + let trie = + aux_x (xe::acc) (List.assoc e map, sb) in + TrieNode (replace_assoc e trie map) + with Not_found -> + raise (Outside_subst (List.rev_append acc xesb))) | trie, sb -> assert false in let rec aux_y acc (trie, outside as res) = function | [] -> assert false | (x, _):: _ as sb when x = vx -> - (try - aux_x acc (trie, sb), outside - with Outside_subst sb -> trie, sb::outside) + (try + aux_x acc (trie, sb), outside + with Outside_subst sb -> trie, sb::outside) | ye::sb -> aux_y (ye::acc) res sb in let trie, outside = List.fold_left (aux_y []) (xsubsts_trie, []) substs in @@ -505,10 +507,10 @@ match res with | [] -> assert false | hd::tl -> - (* e *) - let res = - List.fold_left VarTups.inter hd tl in - rel, res + (* e *) + let res = + List.fold_left VarTups.inter hd tl in + rel, res ) rels in (* f *) let new_atoms = concat_map (fun (rel, tups) -> @@ -524,7 +526,7 @@ (* g *) let assgns = Solver.M.evaluate_partial struc path_assgns atom in let _ = if !debug_level > 3 then (printf "yxvars=%s\n" - (String.concat ", "(List.map var_str yxvars)); flush stdout) in + (String.concat ", "(List.map var_str yxvars)); flush stdout) in let substs = AssignmentSet.fo_assgn_to_list elems yxvars assgns in (* sort substitutions while checking for (i) *) let substs, repeating_inst, vs_insts = @@ -555,41 +557,55 @@ printf "node-ret-2: %s\n" (Formula.str atom); flush stdout) in Some (Left (yvars, atom::path_atoms, vs_insts)) end else if outside_count > 0 (* only the initial call has 0 *) - && new_outside_count >= outside_count + && new_outside_count >= outside_count (* h *) - then - let _ = if !debug_level > 3 then (printf "node-ret-3\n"; flush stdout) in - None - else - let _ = if !debug_level > 3 then ( - printf "node-ret-4: %s\n" (Formula.str atom); flush stdout) in - Some (Right (atom, assgns, new_inside, new_outside_count)) + then + let _ = if !debug_level > 3 then (printf "node-ret-3\n"; flush stdout) in + None + else + let _ = if !debug_level > 3 then ( + printf "node-ret-4: %s\n" (Formula.str atom); flush stdout) in + Some (Right (atom, assgns, new_inside, new_outside_count)) ) new_atoms in let viable_leafs, new_subnodes = partition_choice new_substs in + (* {{{ log entry *) + if !debug_level > 3 then ( + Printf.printf + "node(path=%s): # of viable leafs=%d, # of new subnodes=%d\n%!" + (Formula.str (And path_atoms)) + (List.length viable_leafs) (List.length new_subnodes) + ); + (* }}} *) (* i *) let viable_leafs, avoid_atoms = List.fold_left ( fun (viable_leafs, avoid_atoms) (atom, path_assgns, inside_yxsubsts, outside_count) -> + let viable_num = List.length viable_leafs in + (* {{{ log entry *) if !debug_level > 3 then ( - printf "subnode-atom: %s inside #=%d outside #=%d\n" + printf "subnode-atom: %s inside #=%d outside #=%d\ + viables #=%d skipping=%b\n%!" (Formula.str atom) (List.length inside_yxsubsts) - outside_count; - flush stdout); + outside_count viable_num (viable_num > max_alt_descr); + ); + (* }}} *) let avoid_atoms = atom::avoid_atoms in - let viable_leafs = - (if !alt_descr < max_alt_descr then - node ~more_vars:(max_arity - 1) - ~path_atoms:(atom::path_atoms) ~path_assgns - ~avoid_atoms ~new_yvars - ~yvars ~yxvars - ~all_vars ~inside_yxsubsts ~outside_count - else []) - @ viable_leafs in - viable_leafs, avoid_atoms + if viable_num > max_alt_descr + then viable_leafs, avoid_atoms + else + let viable_leafs = + add_to_maximal cmp_insts + (node ~more_vars:(max_arity - 1) + ~path_atoms:(atom::path_atoms) ~path_assgns + ~avoid_atoms ~new_yvars + ~yvars ~yxvars + ~all_vars ~inside_yxsubsts ~outside_count) + viable_leafs in + viable_leafs, avoid_atoms ) (viable_leafs, avoid_atoms) new_subnodes in - if more_vars <= 0 || !alt_descr >= max_alt_descr + if more_vars <= 0 || List.length viable_leafs > max_alt_descr then viable_leafs else (* j *) @@ -598,22 +614,20 @@ let new_yvars = if more_vars = max_arity - 1 then [nvar] else nvar::new_yvars in - node ~more_vars:(more_vars - 1) ~path_atoms ~path_assgns - ~avoid_atoms - ~new_yvars ~yvars:(nvar::yvars) - ~yxvars:(nvar::yxvars) ~all_vars:(Strings.add nvar_name all_vars) - ~inside_yxsubsts ~outside_count - @ viable_leafs in + add_to_maximal cmp_insts + (node ~more_vars:(more_vars - 1) ~path_atoms ~path_assgns + ~avoid_atoms + ~new_yvars ~yvars:(nvar::yvars) + ~yxvars:(nvar::yxvars) ~all_vars:(Strings.add nvar_name all_vars) + ~inside_yxsubsts ~outside_count) + viable_leafs in let viable_leafs = node ~more_vars:(max_arity - 1) ~new_yvars:[] ~yvars:[] ~path_atoms:[] ~path_assgns:Any ~avoid_atoms:[] ~yxvars:xvars ~all_vars ~inside_yxsubsts:(List.map (fun sb->[sb]) xsubsts) ~outside_count:0 in - (* m *) - let viable_leafs = maximal - (fun (_,_,insts1) (_,_,insts2) -> - List.for_all (fun sb->List.mem sb insts2) insts1) viable_leafs in + let viable_leafs = maximal cmp_insts viable_leafs in let disjuncts = List.map (fun (yvars, atoms, vs_insts) -> if yvars = [] then And atoms Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2011-03-23 21:14:31 UTC (rev 1384) +++ trunk/Toss/Play/HeuristicTest.ml 2011-03-24 13:27:48 UTC (rev 1385) @@ -347,7 +347,7 @@ Heuristic.default_heuristic_old ~struc:state.Arena.struc ~advr:2.0 game in assert_equal ~printer:(fun x->x) - "(100. * ((0.96875 + (1.9375 * :((not ex cellholds_x27_y26__blank_ ((cellholds_x2_y2_black(cellholds_x27_y26__blank_) and (not control_MV1(cellholds_x27_y26__blank_)))))))) + Sum (cellholds_x26_8__blank_ | (cellholds_x2_y2_white(cellholds_x26_8__blank_) and (not control_MV1(cellholds_x26_8__blank_))) : (0.0625 + Sum (y | R2(cellholds_x26_8__blank_, y) : (0.125 + Sum (y0 | R2(y, y0) : (0.25 + Sum (y1 | R2(y0, y1) : (0.5 + Sum (y2 | (R2(y1, y2) and cellholds_x2_4_MV1(y2)) : 1.)))))))))))" + "(100. * ((0.99609375 + (1.9921875 * :((not ex cellholds_x27_y26__blank_ ((cellholds_x2_y2_black(cellholds_x27_y26__blank_) and (not control_MV1(cellholds_x27_y26__blank_)))))))) + Sum (cellholds_x26_8__blank_ | (cellholds_x2_y2_white(cellholds_x26_8__blank_) and (not control_MV1(cellholds_x26_8__blank_))) : (0.0078125 + Sum (y | R1(y, cellholds_x26_8__blank_) : (0.015625 + Sum (y0 | R1(y0, y) : (0.03125 + Sum (y1 | R1(y1, y0) : (0.0625 + Sum (y2 | R1(y2, y1) : (0.125 + Sum (y3 | R1(y3, y2) : (0.25 + Sum (y4 | R1(y4, y3) : (0.5 + Sum (y5 | R1(y5, y4) : 1.)))))))))))))))))" (Formula.real_str loc_heurs.(0).(0)); ); @@ -473,10 +473,10 @@ let a () = DiscreteRule.debug_level := 4; - Heuristic.debug_level := 3 + Heuristic.debug_level := 4 let a () = - match test_filter ["Heuristic:11:default_heuristic_old: connect5 of GDL translation"] + match test_filter ["Heuristic:12:default_heuristic_old: expansion breakthrough of GDL translation"] tests with | Some tests -> ignore (run_test_tt ~verbose:true tests) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-23 21:14:38
|
Revision: 1384 http://toss.svn.sourceforge.net/toss/?rev=1384&view=rev Author: lukstafi Date: 2011-03-23 21:14:31 +0000 (Wed, 23 Mar 2011) Log Message: ----------- Specification-level bug in monotonic heuristic generation. More encompassing monotonicity detection and more clean monotonic heuristic generation for approximately monotonic games. Modified Paths: -------------- trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/Arena/DiscreteRule.mli trunk/Toss/Formula/Aux.ml trunk/Toss/Formula/Aux.mli trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Formula/FormulaOps.mli trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/HeuristicTest.ml Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2011-03-23 17:47:00 UTC (rev 1383) +++ trunk/Toss/Arena/DiscreteRule.ml 2011-03-23 21:14:31 UTC (rev 1384) @@ -2,6 +2,9 @@ let debug_level = ref 0 +let approximate_monotonic = ref true +let prune_indef_vars = ref true + type matching = (int * int) list type matchings = Assignments.assignment_set @@ -55,7 +58,10 @@ preconditions, and negative fluents only negatively on RHSes (are only deleted) and only positively on LHSes and in preconditions. (Call the remaining fluents indefinite.) See - Heuristic.ml. *) + Heuristic.ml. + + In case [approximate_monotonic] is true, ignore what happens on + RHSes. *) let fluents_make ?(only_pos=false) f r = let fl_make (s, tp) = if tp = [] then None else @@ -72,8 +78,14 @@ let nega_cands = Aux.strings_of_list ( Aux.concat_map (fun r->map_rels r.rhs_neg_tuples) rules) in let fluents = Aux.Strings.union posi_cands nega_cands in - let posi = Aux.Strings.diff posi_cands nega_cands - and nega = Aux.Strings.diff nega_cands posi_cands in + let posi = + if !approximate_monotonic + then fluents + else Aux.Strings.diff posi_cands nega_cands + and nega = + if !approximate_monotonic + then fluents + else Aux.Strings.diff nega_cands posi_cands in let posi_lhs, nega_lhs = List.fold_left (fun (posi,nega) r -> let mp, mn = FormulaOps.rels_signs r.lhs_form in @@ -89,17 +101,42 @@ position. We are only interested in expanding preconditions of positive and negative fluents. + The fluent preconditions have closed subformulas eliminated, as + these do not differentiate between different actions (usually they + represent termination conditions). Also remove indefinite fluents + as these are heuristically assumed to be irrelevant in monotonic + games for long-term payoff behavior. + + Additional (optional but on by default) heuristic pruning removes + also other atoms that contain variables that were constrained by + indefinite fluents (prune_indef_vars). + TODO: currently, only a single absence/presence tuple is removed from the precondition: the one from which it "derived"; shouldn't all added and deleted tuples be removed? *) -let fluent_preconds rules signature posi_frels nega_frels = - let fluents = - Aux.Strings.elements posi_frels @ Aux.Strings.elements nega_frels in - let fluent_precond rel = +let fluent_preconds rules signature posi_frels nega_frels indef_frels = + let indef_vars_fold = + {FormulaOps.make_fold Aux.unique_append [] with + FormulaOps.fold_Rel = (fun rel args -> + if Aux.Strings.mem rel indef_frels + then Array.to_list args else [])} in + let collect_indef_vars phi = + FormulaOps.fold_formula indef_vars_fold phi in + let rem_closed indef_vars = function + | Formula.Eq (x, y) -> + List.mem x indef_vars || List.mem y indef_vars + | Formula.In (x, _) -> List.mem x indef_vars + | Formula.Rel (rel, args) -> + Aux.Strings.mem rel indef_frels || + ( !prune_indef_vars && + Aux.array_existsi (fun _ v -> List.mem v indef_vars) args) + | phi -> FormulaOps.free_vars phi = [] in + let fluent_precond is_posi rel = (* rules that produce a fluent, together with its args *) let rel_prods = Aux.map_some (fun r -> - let rhs_tuples = r.rhs_pos_tuples @ r.rhs_neg_tuples in + let rhs_tuples = + if is_posi then r.rhs_pos_tuples else r.rhs_neg_tuples in if List.mem_assoc rel rhs_tuples then let rel_tups = List.assoc rel rhs_tuples in if rel_tups <> [] then Some (r, rel_tups) @@ -121,6 +158,14 @@ args | Some rlmap -> Array.map (fun e->List.assoc e rlmap) args in + (* {{{ log entry *) + if !debug_level > 3 then ( + Printf.printf "compose_pre: rel=%s; args=%s; lhs_args=%s\n%!" + rel + (String.concat ", " (Array.to_list args)) + (String.concat ", " (Array.to_list lhs_args)) + ); + (* }}} *) (* remove potential condition for absence/presence of the fluent being just added / deleted *) let body = FormulaOps.map_formula @@ -135,6 +180,22 @@ if b && Aux.Strings.mem rel nega_frels then Formula.And [] else if b && Aux.Strings.mem rel posi_frels then Formula.Or [] else Formula.Rel (b_rel, b_args))} body in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf "fluent_preconds: body before pruning:\n%s\n%!" + (Formula.sprint body) + ); + (* }}} *) + (* remove closed subformulas and indefinite fluents *) + let indef_vars = collect_indef_vars body in + let body = + FormulaOps.remove_subformulas (rem_closed indef_vars) body in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf "fluent_preconds: body after pruning:\n%s\n%!" + (Formula.sprint body) + ); + (* }}} *) let args = Array.to_list args in let body, other_vars, numap_cstr = match r.rlmap with @@ -164,8 +225,17 @@ | [] -> failwith ("fluent_preconds: not a fluent: "^rel) | [phi] -> phi | _ -> Formula.Or disjs in + let precond = FormulaOps.prune_unused_quants precond in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf "fluent_preconds: result -- rel=%s(%s), precond=\n%s\n%!" + rel (String.concat ", " nu_args) + (Formula.sprint precond) + ); + (* }}} *) rel, (nu_args, precond) in - List.map fluent_precond fluents + List.map (fluent_precond true) (Aux.Strings.elements posi_frels) @ + List.map (fluent_precond false) (Aux.Strings.elements nega_frels) (* {2 Embedding and rewriting.} *) Modified: trunk/Toss/Arena/DiscreteRule.mli =================================================================== --- trunk/Toss/Arena/DiscreteRule.mli 2011-03-23 17:47:00 UTC (rev 1383) +++ trunk/Toss/Arena/DiscreteRule.mli 2011-03-23 21:14:31 UTC (rev 1384) @@ -2,7 +2,13 @@ val debug_level : int ref -(* Single match of a rule, and a set of matches. *) +(** If [true], ignore what happens on RHSes of rules when assessing + if fluents are positive / negative (only check whether their + LHS+precondition occurrences are negative/positive). *) +val approximate_monotonic : bool ref +val prune_indef_vars : bool ref + +(** Single match of a rule, and a set of matches. *) type matching = (int * int) list type matchings = Assignments.assignment_set @@ -63,7 +69,8 @@ position. We are only interested in expanding preconditions of positive and negative fluents. *) val fluent_preconds : - rule_obj list -> (string -> int) -> Aux.Strings.t -> Aux.Strings.t -> + rule_obj list -> (string -> int) -> + Aux.Strings.t -> Aux.Strings.t -> Aux.Strings.t -> (string * (string list * Formula.formula)) list (* Helpers for special relations. *) Modified: trunk/Toss/Formula/Aux.ml =================================================================== --- trunk/Toss/Formula/Aux.ml 2011-03-23 17:47:00 UTC (rev 1383) +++ trunk/Toss/Formula/Aux.ml 2011-03-23 21:14:31 UTC (rev 1384) @@ -247,6 +247,10 @@ | [] -> [] in idemp (List.sort Pervasives.compare l) +let unique_append l1 l2 = + List.fold_left (fun l2 e -> + if List.mem e l2 then l2 else e::l2) l2 (List.rev l1) + (* TODO: that's quadratic, optimize? *) let rec unique eq = function | [] -> [] Modified: trunk/Toss/Formula/Aux.mli =================================================================== --- trunk/Toss/Formula/Aux.mli 2011-03-23 17:47:00 UTC (rev 1383) +++ trunk/Toss/Formula/Aux.mli 2011-03-23 21:14:31 UTC (rev 1384) @@ -155,6 +155,10 @@ by {!Pervasives.compare}. Not tail-recursive. *) val unique_sorted : 'a list -> 'a list +(** [unique_append l1 l2] appends elements not occurring in [l2] to + it, without repeating elements. *) +val unique_append : 'a list -> 'a list -> 'a list + (** Return the list of unique elements, under the given comparison (the input does not need to be sorted). (Currently uses a straightforward [n^2] algorithm. Currently not tail-recursive.) *) Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-03-23 17:47:00 UTC (rev 1383) +++ trunk/Toss/Formula/FormulaOps.ml 2011-03-23 21:14:31 UTC (rev 1384) @@ -889,7 +889,10 @@ map_Or = (function | [disj] -> disj | disjs -> Or (Aux.concat_map flat_or disjs)); - map_Not = (function Not phi -> phi | phi -> Not phi)} + map_Not = (function + | Or [] -> And [] + | And [] -> Or [] + | Not phi -> phi | phi -> Not phi)} let rec flatten_or = function | Or disjs -> Aux.concat_map flatten_or disjs @@ -921,6 +924,30 @@ | Not (Not phi) -> flatten_ands phi | phi -> [phi] +(* Currently, does not go down real expressions. *) +let remove_subformulas psub phi = + let rec map_formula subf = + if psub subf then raise Not_found; + match subf with + | Rel _ | Eq _ | RealExpr _ | In _ -> subf + | Not phi -> Not (map_formula phi) + | And conjs -> And (Aux.map_try map_formula conjs) + | Or disjs -> Or (Aux.map_try map_formula disjs) + | Ex (vs, phi) -> Ex (vs, map_formula phi) + | All (vs, phi) -> All (vs, map_formula phi) in + try flatten_formula (map_formula phi) + with Not_found -> And [] + +let unused_quants_map = {identity_map with + map_Ex = (fun vs phi -> + if Aux.list_inter vs (free_vars phi) = [] then phi + else Ex (vs, phi)); + map_All = (fun vs phi -> + if Aux.list_inter vs (free_vars phi) = [] then phi + else All (vs, phi))} + +let prune_unused_quants = map_formula unused_quants_map + (* Simplify the formula by removing relational literals, depending on what literals they are conjoined with up the tree, whether they are in a disjunction and what literals they are disjoined with, keeping Modified: trunk/Toss/Formula/FormulaOps.mli =================================================================== --- trunk/Toss/Formula/FormulaOps.mli 2011-03-23 17:47:00 UTC (rev 1383) +++ trunk/Toss/Formula/FormulaOps.mli 2011-03-23 21:14:31 UTC (rev 1384) @@ -161,6 +161,13 @@ negation over disjunction and pushing quantifiers inside. *) val flatten_ands : formula -> formula list +(** "Erase" indicated subformulas from the formula. *) +val remove_subformulas : (formula -> bool) -> formula -> formula + +(** Remove quantifiers that bind only variables not occurring freely + in the body. *) +val prune_unused_quants : formula -> formula + (** Simplify the formula by removing relational literals, depending on what literals they are conjoined with up the tree, whether they are in a disjunction and what literals they are disjoined with, keeping Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-23 17:47:00 UTC (rev 1383) +++ trunk/Toss/Play/Heuristic.ml 2011-03-23 21:14:31 UTC (rev 1384) @@ -51,11 +51,14 @@ module): H(Phi) = - Sum(V1, (F11\/...\/F1N_1) /\ Pre(F11/\.../\F1N_1) /\ Guard1, + Sum(V1, (F11\/...\/F1N_1) /\ + (F11\/Pre(F11)) /\ ... /\ (F1N_1\/Pre(F1N_1) /\ Guard1, CharSum(F11, ..., F1N_1)) + ... + - Sum(VM, (FM1\/...\/FMN_M) /\ Pre(FM1/\.../\FMN_M) /\ GuardM, + Sum(VM, (FM1\/...\/FMN_M) /\ + (FM1\/Pre(FM1)) /\ ... /\ (FMN_M\/Pre(FMN_M)) /\ GuardM, CharSum(FM1, ..., FMN_M)) + where: * CharSum(Fi1, ..., FiN_i) = f(Char(Fi1) + ... + Char(FiN_i), N_i) @@ -83,6 +86,15 @@ is equivalent to Phi with minimal application of distributivity (GuardI can contain disjunctions if they don't contain any of FIj) + The fluent preconditions Pre() have closed subformulas eliminated, + as these do not differentiate between different actions (usually + they represent termination conditions). Also remove indefinite + fluents as these are heuristically assumed to be irrelevant in + monotonic games for long-term payoff behavior. Additional + (optional but on by default) heuristic pruning removes also other + atoms that contain variables that were constrained by indefinite + fluents (parameter {!DiscreteRule.prune_indef_vars}}). + ********** Algorithm Alg(Ex(V,Phi), Guard0): @@ -888,7 +900,9 @@ let m = List.length literals in let pre_guard = And ( Or literals :: - List.map (FormulaOps.subst_once_rels preconds) atoms @ [guard]) in + List.map (fun atom -> + Or [atom; FormulaOps.subst_once_rels preconds atom]) + atoms @ [guard]) in Sum (avs, FormulaOps.simplify pre_guard, f_monot adv_ratio n m) ) guards in sum_exprs parts @@ -1075,7 +1089,7 @@ let fluent_preconds = if monotonic then Some (DiscreteRule.fluent_preconds drules signat - posi_frels nega_frels) + posi_frels nega_frels indef_frels) else None in Array.mapi (fun i node -> Array.map (fun payoff -> Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2011-03-23 17:47:00 UTC (rev 1383) +++ trunk/Toss/Play/HeuristicTest.ml 2011-03-23 21:14:31 UTC (rev 1384) @@ -75,7 +75,8 @@ (Aux.Strings.inter all_poff_rels indef_frels) in let fluent_preconds = if monotonic then Some ( - DiscreteRule.fluent_preconds drules signat posi_frels nega_frels) + DiscreteRule.fluent_preconds drules signat + posi_frels nega_frels indef_frels) else None in Heuristic.of_payoff ?struc ?fluent_preconds advance_ratio ~posi_frels ~nega_frels frels payoff @@ -267,14 +268,14 @@ rule_of_str sigPQ "[a | P:1 {}; Q:1 {} | ] -> [ | Q:1 {}; P(a) | ] emb P, Q"; rule_of_str sigPQ "[a | P:1 {}; Q:1 {} | ] -> [ | P:1 {}; Q(a) | ] emb P, Q"] in assert_equal ~printer:(fun x->x) ~msg:"adv_ratio=1" - "(Sum (z, y, x | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v ((C(z, u) and C(y, v) and R(y, u) and R(x, v))) or ex u, v ((R(y, u) and R(x, v) and C(v, y) and C(u, z)))) and (P(z) or P(y) or P(x)) and (not Q(x)) and (not Q(y)) and (not Q(z))) : (((:(P(x)) + :(P(y))) + :(P(z))) * 0.33)) + (-1. * Sum (z, y, x | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v ((C(z, u) and C(y, v) and R(y, u) and R(x, v))) or ex u, v ((R(y, u) and R(x, v) and C(v, y) and C(u, z)))) and (Q(z) or Q(y) or Q(x)) and (not P(x)) and (not P(y)) and (not P(z))) : (((:(Q(x)) + :(Q(y))) + :(Q(z))) * 0.33))))" + "(Sum (z, y, x | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v ((C(z, u) and C(y, v) and R(y, u) and R(x, v))) or ex u, v ((R(y, u) and R(x, v) and C(v, y) and C(u, z)))) and (P(x) or P(y) or P(z)) and ((not Q(x)) or P(x)) and ((not Q(y)) or P(y)) and ((not Q(z)) or P(z))) : (((:(P(x)) + :(P(y))) + :(P(z))) * 0.33)) + (-1. * Sum (z, y, x | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v ((C(z, u) and C(y, v) and R(y, u) and R(x, v))) or ex u, v ((R(y, u) and R(x, v) and C(v, y) and C(u, z)))) and (Q(x) or Q(y) or Q(z)) and ((not P(x)) or Q(x)) and ((not P(y)) or Q(y)) and ((not P(z)) or Q(z))) : (((:(Q(x)) + :(Q(y))) + :(Q(z))) * 0.33))))" (Formula.real_str (Heuristic.map_constants (fun c->(floor (c*.100.))/.100.) (default_heuristic 1. rules (real_of_str (":("^winPxyz^") - :("^winQxyz^")"))))); assert_equal ~printer:(fun x->x) ~msg:"adv_ratio=2" - "(Sum (z, y, x | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v ((C(z, u) and C(y, v) and R(y, u) and R(x, v))) or ex u, v ((R(y, u) and R(x, v) and C(v, y) and C(u, z)))) and (P(z) or P(y) or P(x)) and (not Q(x)) and (not Q(y)) and (not Q(z))) : ((((:(P(x)) + :(P(y))) + :(P(z))) * ((:(P(x)) + :(P(y))) + :(P(z)))) * 0.11)) + (-1. * Sum (z, y, x | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v ((C(z, u) and C(y, v) and R(y, u) and R(x, v))) or ex u, v ((R(y, u) and R(x, v) and C(v, y) and C(u, z)))) and (Q(z) or Q(y) or Q(x)) and (not P(x)) and (not P(y)) and (not P(z))) : ((((:(Q(x)) + :(Q(y))) + :(Q(z))) * ((:(Q(x)) + :(Q(y))) + :(Q(z)))) * 0.11))))" + "(Sum (z, y, x | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v ((C(z, u) and C(y, v) and R(y, u) and R(x, v))) or ex u, v ((R(y, u) and R(x, v) and C(v, y) and C(u, z)))) and (P(x) or P(y) or P(z)) and ((not Q(x)) or P(x)) and ((not Q(y)) or P(y)) and ((not Q(z)) or P(z))) : ((((:(P(x)) + :(P(y))) + :(P(z))) * ((:(P(x)) + :(P(y))) + :(P(z)))) * 0.11)) + (-1. * Sum (z, y, x | (((R(x, y) and R(y, z)) or (C(x, y) and C(y, z)) or ex u, v ((C(z, u) and C(y, v) and R(y, u) and R(x, v))) or ex u, v ((R(y, u) and R(x, v) and C(v, y) and C(u, z)))) and (Q(x) or Q(y) or Q(z)) and ((not P(x)) or Q(x)) and ((not P(y)) or Q(y)) and ((not P(z)) or Q(z))) : ((((:(Q(x)) + :(Q(y))) + :(Q(z))) * ((:(Q(x)) + :(Q(y))) + :(Q(z)))) * 0.11))))" (Formula.real_str (Heuristic.map_constants (fun c->(floor (c*.100.))/.100.) (default_heuristic 2. rules @@ -287,14 +288,14 @@ rule_of_str sigPQ "[a | P:1 {}; Q:1 {} | ] -> [ | Q:1 {}; P(a) | ] emb P, Q"; rule_of_str sigPQ "[a | P:1 {}; Q:1 {} | ] -> [ | P:1 {}; Q(a) | ] emb P, Q"] in assert_equal ~printer:(fun x->x) ~msg:"adv_ratio=2" - "(Sum (z, y, x, w, v | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u ((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r))) or ex r, s, t, u ((R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w)))) and (P(z) or P(y) or P(x) or P(w) or P(v)) and (not Q(v)) and (not Q(w)) and (not Q(x)) and (not Q(y)) and (not Q(z))) : ((((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z))) * ((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z)))) * 0.04)) + (-1. * Sum (z, y, x, w, v | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u ((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r))) or ex r, s, t, u ((R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w)))) and (Q(z) or Q(y) or Q(x) or Q(w) or Q(v)) and (not P(v)) and (not P(w)) and (not P(x)) and (not P(y)) and (not P(z))) : ((((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z))) * ((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z)))) * 0.04))))" + "(Sum (z, y, x, w, v | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u ((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r))) or ex r, s, t, u ((R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w)))) and (P(z) or P(y) or P(x) or P(w) or P(v)) and ((not Q(z)) or P(z)) and ((not Q(y)) or P(y)) and ((not Q(x)) or P(x)) and ((not Q(w)) or P(w)) and ((not Q(v)) or P(v))) : ((((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z))) * ((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z)))) * 0.04)) + (-1. * Sum (z, y, x, w, v | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u ((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r))) or ex r, s, t, u ((R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w)))) and (Q(z) or Q(y) or Q(x) or Q(w) or Q(v)) and ((not P(z)) or Q(z)) and ((not P(y)) or Q(y)) and ((not P(x)) or Q(x)) and ((not P(w)) or Q(w)) and ((not P(v)) or Q(v))) : ((((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z))) * ((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z)))) * 0.04))))" (Formula.real_str ((* Heuristic.map_constants (fun c->(floor (c*.100.))/.100.) *) (default_heuristic 2. rules (real_of_str (":("^winPvwxyz^") - :("^winQvwxyz^")"))))); assert_equal ~printer:(fun x->x) ~msg:"adv_ratio=3" - "(Sum (z, y, x, w, v | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u ((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r))) or ex r, s, t, u ((R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w)))) and (P(z) or P(y) or P(x) or P(w) or P(v)) and (not Q(v)) and (not Q(w)) and (not Q(x)) and (not Q(y)) and (not Q(z))) : ((((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z))) * (((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z))) * ((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z))))) * 0.008)) + (-1. * Sum (z, y, x, w, v | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u ((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r))) or ex r, s, t, u ((R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w)))) and (Q(z) or Q(y) or Q(x) or Q(w) or Q(v)) and (not P(v)) and (not P(w)) and (not P(x)) and (not P(y)) and (not P(z))) : ((((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z))) * (((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z))) * ((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z))))) * 0.008))))" + "(Sum (z, y, x, w, v | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u ((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r))) or ex r, s, t, u ((R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w)))) and (P(z) or P(y) or P(x) or P(w) or P(v)) and ((not Q(z)) or P(z)) and ((not Q(y)) or P(y)) and ((not Q(x)) or P(x)) and ((not Q(w)) or P(w)) and ((not Q(v)) or P(v))) : ((((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z))) * (((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z))) * ((((:(P(v)) + :(P(w))) + :(P(x))) + :(P(y))) + :(P(z))))) * 0.008)) + (-1. * Sum (z, y, x, w, v | (((R(v, w) and R(w, x) and R(x, y) and R(y, z)) or (C(v, w) and C(w, x) and C(x, y) and C(y, z)) or ex r, s, t, u ((C(z, u) and R(y, u) and C(y, t) and R(x, t) and C(x, s) and R(w, s) and C(w, r) and R(v, r))) or ex r, s, t, u ((R(y, u) and R(x, t) and R(w, s) and R(v, r) and C(u, z) and C(t, y) and C(s, x) and C(r, w)))) and (Q(z) or Q(y) or Q(x) or Q(w) or Q(v)) and ((not P(z)) or Q(z)) and ((not P(y)) or Q(y)) and ((not P(x)) or Q(x)) and ((not P(w)) or Q(w)) and ((not P(v)) or Q(v))) : ((((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z))) * (((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z))) * ((((:(Q(v)) + :(Q(w))) + :(Q(x))) + :(Q(y))) + :(Q(z))))) * 0.008))))" (Formula.real_str ((* Heuristic.map_constants (fun c->(floor (c*.1000.))/.1000.) *) (default_heuristic 3. rules @@ -328,15 +329,14 @@ "default_heuristic_old: connect5 of GDL translation" >:: (fun () -> - skip_if true "turns out connect5 is not monotonic"; let (game,state) = state_of_file "./GGP/tests/connect5-simpl.toss" in let loc_heurs = Heuristic.default_heuristic_old ~struc:state.Arena.struc ~advr:4.0 game in assert_equal ~printer:(fun x->x) - "SHOULD GENERATE AS FOR A MONOTONIC GAME" - (Formula.sprint_real loc_heurs.(0).(0)); + "((50. + (-50. * (((Sum (cell_x61_y61__blank_, cell_x60_y60__blank_, cell_x59_y59__blank_, cell_x58_y58__blank_, cell_x57_y57__blank_ | ((cell_x_y_o(cell_x61_y61__blank_) or cell_x_y_o(cell_x60_y60__blank_) or cell_x_y_o(cell_x59_y59__blank_) or cell_x_y_o(cell_x58_y58__blank_) or cell_x_y_o(cell_x57_y57__blank_)) and (cell_x_y_b(cell_x61_y61__blank_) or cell_x_y_o(cell_x61_y61__blank_)) and (cell_x_y_b(cell_x60_y60__blank_) or cell_x_y_o(cell_x60_y60__blank_)) and (cell_x_y_b(cell_x59_y59__blank_) or cell_x_y_o(cell_x59_y59__blank_)) and (cell_x_y_b(cell_x58_y58__blank_) or cell_x_y_o(cell_x58_y58__blank_)) and (cell_x_y_b(cell_x57_y57__blank_) or cell_x_y_o(cell_x57_y57__blank_)) and R2(cell_x61_y61__blank_, cell_x60_y60__blank_) and R2(cell_x60_y60__blank_, cell_x59_y59__blank_) and R2(cell_x59_y59__blank_, cell_x58_y58__blank_) and R2(cell_x58_y58__blank_, cell_x57_y57__blank_)) : ((((((:(cell_x_y_o(cell_x61_y61__blank_)) + :(cell_x_y_o(cell_x60_y60__blank_))) + :(cell_x_y_o(cell_x59_y59__blank_))) + :(cell_x_y_o(cell_x58_y58__blank_))) + :(cell_x_y_o(cell_x57_y57__blank_))) * (((((:(cell_x_y_o(cell_x61_y61__blank_)) + :(cell_x_y_o(cell_x60_y60__blank_))) + :(cell_x_y_o(cell_x59_y59__blank_))) + :(cell_x_y_o(cell_x58_y58__blank_))) + :(cell_x_y_o(cell_x57_y57__blank_))) * (((((:(cell_x_y_o(cell_x61_y61__blank_)) + :(cell_x_y_o(cell_x60_y60__blank_))) + :(cell_x_y_o(cell_x59_y59__blank_))) + :(cell_x_y_o(cell_x58_y58__blank_))) + :(cell_x_y_o(cell_x57_y57__blank_))) * ((((:(cell_x_y_o(cell_x61_y61__blank_)) + :(cell_x_y_o(cell_x60_y60__blank_))) + :(cell_x_y_o(cell_x59_y59__blank_))) + :(cell_x_y_o(cell_x58_y58__blank_))) + :(cell_x_y_o(cell_x57_y57__blank_)))))) * 0.0016)) + Sum (cell_x56_y56__blank_, cell_x55_y55__blank_, cell_x54_y54__blank_, cell_x53_y53__blank_, cell_x52_y52__blank_ | ((cell_x_y_o(cell_x56_y56__blank_) or cell_x_y_o(cell_x55_y55__blank_) or cell_x_y_o(cell_x54_y54__blank_) or cell_x_y_o(cell_x53_y53__blank_) or cell_x_y_o(cell_x52_y52__blank_)) and (cell_x_y_b(cell_x56_y56__blank_) or cell_x_y_o(cell_x56_y56__blank_)) and (cell_x_y_b(cell_x55_y55__blank_) or cell_x_y_o(cell_x55_y55__blank_)) and (cell_x_y_b(cell_x54_y54__blank_) or cell_x_y_o(cell_x54_y54__blank_)) and (cell_x_y_b(cell_x53_y53__blank_) or cell_x_y_o(cell_x53_y53__blank_)) and (cell_x_y_b(cell_x52_y52__blank_) or cell_x_y_o(cell_x52_y52__blank_)) and R1(cell_x56_y56__blank_, cell_x55_y55__blank_) and R1(cell_x55_y55__blank_, cell_x54_y54__blank_) and R1(cell_x54_y54__blank_, cell_x53_y53__blank_) and R1(cell_x53_y53__blank_, cell_x52_y52__blank_)) : ((((((:(cell_x_y_o(cell_x56_y56__blank_)) + :(cell_x_y_o(cell_x55_y55__blank_))) + :(cell_x_y_o(cell_x54_y54__blank_))) + :(cell_x_y_o(cell_x53_y53__blank_))) + :(cell_x_y_o(cell_x52_y52__blank_))) * (((((:(cell_x_y_o(cell_x56_y56__blank_)) + :(cell_x_y_o(cell_x55_y55__blank_))) + :(cell_x_y_o(cell_x54_y54__blank_))) + :(cell_x_y_o(cell_x53_y53__blank_))) + :(cell_x_y_o(cell_x52_y52__blank_))) * (((((:(cell_x_y_o(cell_x56_y56__blank_)) + :(cell_x_y_o(cell_x55_y55__blank_))) + :(cell_x_y_o(cell_x54_y54__blank_))) + :(cell_x_y_o(cell_x53_y53__blank_))) + :(cell_x_y_o(cell_x52_y52__blank_))) * ((((:(cell_x_y_o(cell_x56_y56__blank_)) + :(cell_x_y_o(cell_x55_y55__blank_))) + :(cell_x_y_o(cell_x54_y54__blank_))) + :(cell_x_y_o(cell_x53_y53__blank_))) + :(cell_x_y_o(cell_x52_y52__blank_)))))) * 0.0016))) + Sum (cell_e8_y51__blank_, cell_d8_y51__blank_, cell_c8_y51__blank_, cell_b8_y51__blank_, cell_a8_y51__blank_ | ((cell_x_y_o(cell_a8_y51__blank_) or cell_x_y_o(cell_b8_y51__blank_) or cell_x_y_o(cell_c8_y51__blank_) or cell_x_y_o(cell_d8_y51__blank_) or cell_x_y_o(cell_e8_y51__blank_)) and (cell_x_y_b(cell_a8_y51__blank_) or cell_x_y_o(cell_a8_y51__blank_)) and (cell_x_y_b(cell_b8_y51__blank_) or cell_x_y_o(cell_b8_y51__blank_)) and (cell_x_y_b(cell_c8_y51__blank_) or cell_x_y_o(cell_c8_y51__blank_)) and (cell_x_y_b(cell_d8_y51__blank_) or cell_x_y_o(cell_d8_y51__blank_)) and (cell_x_y_b(cell_e8_y51__blank_) or cell_x_y_o(cell_e8_y51__blank_)) and R0(cell_d8_y51__blank_, cell_e8_y51__blank_) and R0(cell_c8_y51__blank_, cell_d8_y51__blank_) and R0(cell_b8_y51__blank_, cell_c8_y51__blank_) and R0(cell_a8_y51__blank_, cell_b8_y51__blank_)) : ((((((:(cell_x_y_o(cell_a8_y51__blank_)) + :(cell_x_y_o(cell_b8_y51__blank_))) + :(cell_x_y_o(cell_c8_y51__blank_))) + :(cell_x_y_o(cell_d8_y51__blank_))) + :(cell_x_y_o(cell_e8_y51__blank_))) * (((((:(cell_x_y_o(cell_a8_y51__blank_)) + :(cell_x_y_o(cell_b8_y51__blank_))) + :(cell_x_y_o(cell_c8_y51__blank_))) + :(cell_x_y_o(cell_d8_y51__blank_))) + :(cell_x_y_o(cell_e8_y51__blank_))) * (((((:(cell_x_y_o(cell_a8_y51__blank_)) + :(cell_x_y_o(cell_b8_y51__blank_))) + :(cell_x_y_o(cell_c8_y51__blank_))) + :(cell_x_y_o(cell_d8_y51__blank_))) + :(cell_x_y_o(cell_e8_y51__blank_))) * ((((:(cell_x_y_o(cell_a8_y51__blank_)) + :(cell_x_y_o(cell_b8_y51__blank_))) + :(cell_x_y_o(cell_c8_y51__blank_))) + :(cell_x_y_o(cell_d8_y51__blank_))) + :(cell_x_y_o(cell_e8_y51__blank_)))))) * 0.0016))) + Sum (cell_x51_e7__blank_, cell_x51_d7__blank_, cell_x51_c7__blank_, cell_x51_b7__blank_, cell_x51_a7__blank_ | ((cell_x_y_o(cell_x51_a7__blank_) or cell_x_y_o(cell_x51_b7__blank_) or cell_x_y_o(cell_x51_c7__blank_) or cell_x_y_o(cell_x51_d7__blank_) or cell_x_y_o(cell_x51_e7__blank_)) and (cell_x_y_b(cell_x51_a7__blank_) or cell_x_y_o(cell_x51_a7__blank_)) and (cell_x_y_b(cell_x51_b7__blank_) or cell_x_y_o(cell_x51_b7__blank_)) and (cell_x_y_b(cell_x51_c7__blank_) or cell_x_y_o(cell_x51_c7__blank_)) and (cell_x_y_b(cell_x51_d7__blank_) or cell_x_y_o(cell_x51_d7__blank_)) and (cell_x_y_b(cell_x51_e7__blank_) or cell_x_y_o(cell_x51_e7__blank_)) and R(cell_x51_d7__blank_, cell_x51_e7__blank_) and R(cell_x51_c7__blank_, cell_x51_d7__blank_) and R(cell_x51_b7__blank_, cell_x51_c7__blank_) and R(cell_x51_a7__blank_, cell_x51_b7__blank_)) : ((((((:(cell_x_y_o(cell_x51_a7__blank_)) + :(cell_x_y_o(cell_x51_b7__blank_))) + :(cell_x_y_o(cell_x51_c7__blank_))) + :(cell_x_y_o(cell_x51_d7__blank_))) + :(cell_x_y_o(cell_x51_e7__blank_))) * (((((:(cell_x_y_o(cell_x51_a7__blank_)) + :(cell_x_y_o(cell_x51_b7__blank_))) + :(cell_x_y_o(cell_x51_c7__blank_))) + :(cell_x_y_o(cell_x51_d7__blank_))) + :(cell_x_y_o(cell_x51_e7__blank_))) * (((((:(cell_x_y_o(cell_x51_a7__blank_)) + :(cell_x_y_o(cell_x51_b7__blank_))) + :(cell_x_y_o(cell_x51_c7__blank_))) + :(cell_x_y_o(cell_x51_d7__blank_))) + :(cell_x_y_o(cell_x51_e7__blank_))) * ((((:(cell_x_y_o(cell_x51_a7__blank_)) + :(cell_x_y_o(cell_x51_b7__blank_))) + :(cell_x_y_o(cell_x51_c7__blank_))) + :(cell_x_y_o(cell_x51_d7__blank_))) + :(cell_x_y_o(cell_x51_e7__blank_)))))) * 0.0016))))) + (50. * (((Sum (cell_x50_y50__blank_, cell_x49_y49__blank_, cell_x48_y48__blank_, cell_x47_y47__blank_, cell_x46_y46__blank_ | ((cell_x_y_x(cell_x50_y50__blank_) or cell_x_y_x(cell_x49_y49__blank_) or cell_x_y_x(cell_x48_y48__blank_) or cell_x_y_x(cell_x47_y47__blank_) or cell_x_y_x(cell_x46_y46__blank_)) and (cell_x_y_b(cell_x50_y50__blank_) or cell_x_y_x(cell_x50_y50__blank_)) and (cell_x_y_b(cell_x49_y49__blank_) or cell_x_y_x(cell_x49_y49__blank_)) and (cell_x_y_b(cell_x48_y48__blank_) or cell_x_y_x(cell_x48_y48__blank_)) and (cell_x_y_b(cell_x47_y47__blank_) or cell_x_y_x(cell_x47_y47__blank_)) and (cell_x_y_b(cell_x46_y46__blank_) or cell_x_y_x(cell_x46_y46__blank_)) and R2(cell_x50_y50__blank_, cell_x49_y49__blank_) and R2(cell_x49_y49__blank_, cell_x48_y48__blank_) and R2(cell_x48_y48__blank_, cell_x47_y47__blank_) and R2(cell_x47_y47__blank_, cell_x46_y46__blank_)) : ((((((:(cell_x_y_x(cell_x50_y50__blank_)) + :(cell_x_y_x(cell_x49_y49__blank_))) + :(cell_x_y_x(cell_x48_y48__blank_))) + :(cell_x_y_x(cell_x47_y47__blank_))) + :(cell_x_y_x(cell_x46_y46__blank_))) * (((((:(cell_x_y_x(cell_x50_y50__blank_)) + :(cell_x_y_x(cell_x49_y49__blank_))) + :(cell_x_y_x(cell_x48_y48__blank_))) + :(cell_x_y_x(cell_x47_y47__blank_))) + :(cell_x_y_x(cell_x46_y46__blank_))) * (((((:(cell_x_y_x(cell_x50_y50__blank_)) + :(cell_x_y_x(cell_x49_y49__blank_))) + :(cell_x_y_x(cell_x48_y48__blank_))) + :(cell_x_y_x(cell_x47_y47__blank_))) + :(cell_x_y_x(cell_x46_y46__blank_))) * ((((:(cell_x_y_x(cell_x50_y50__blank_)) + :(cell_x_y_x(cell_x49_y49__blank_))) + :(cell_x_y_x(cell_x48_y48__blank_))) + :(cell_x_y_x(cell_x47_y47__blank_))) + :(cell_x_y_x(cell_x46_y46__blank_)))))) * 0.0016)) + Sum (cell_x45_y45__blank_, cell_x44_y44__blank_, cell_x43_y43__blank_, cell_x42_y42__blank_, cell_x41_y41__blank_ | ((cell_x_y_x(cell_x45_y45__blank_) or cell_x_y_x(cell_x44_y44__blank_) or cell_x_y_x(cell_x43_y43__blank_) or cell_x_y_x(cell_x42_y42__blank_) or cell_x_y_x(cell_x41_y41__blank_)) and (cell_x_y_b(cell_x45_y45__blank_) or cell_x_y_x(cell_x45_y45__blank_)) and (cell_x_y_b(cell_x44_y44__blank_) or cell_x_y_x(cell_x44_y44__blank_)) and (cell_x_y_b(cell_x43_y43__blank_) or cell_x_y_x(cell_x43_y43__blank_)) and (cell_x_y_b(cell_x42_y42__blank_) or cell_x_y_x(cell_x42_y42__blank_)) and (cell_x_y_b(cell_x41_y41__blank_) or cell_x_y_x(cell_x41_y41__blank_)) and R1(cell_x45_y45__blank_, cell_x44_y44__blank_) and R1(cell_x44_y44__blank_, cell_x43_y43__blank_) and R1(cell_x43_y43__blank_, cell_x42_y42__blank_) and R1(cell_x42_y42__blank_, cell_x41_y41__blank_)) : ((((((:(cell_x_y_x(cell_x45_y45__blank_)) + :(cell_x_y_x(cell_x44_y44__blank_))) + :(cell_x_y_x(cell_x43_y43__blank_))) + :(cell_x_y_x(cell_x42_y42__blank_))) + :(cell_x_y_x(cell_x41_y41__blank_))) * (((((:(cell_x_y_x(cell_x45_y45__blank_)) + :(cell_x_y_x(cell_x44_y44__blank_))) + :(cell_x_y_x(cell_x43_y43__blank_))) + :(cell_x_y_x(cell_x42_y42__blank_))) + :(cell_x_y_x(cell_x41_y41__blank_))) * (((((:(cell_x_y_x(cell_x45_y45__blank_)) + :(cell_x_y_x(cell_x44_y44__blank_))) + :(cell_x_y_x(cell_x43_y43__blank_))) + :(cell_x_y_x(cell_x42_y42__blank_))) + :(cell_x_y_x(cell_x41_y41__blank_))) * ((((:(cell_x_y_x(cell_x45_y45__blank_)) + :(cell_x_y_x(cell_x44_y44__blank_))) + :(cell_x_y_x(cell_x43_y43__blank_))) + :(cell_x_y_x(cell_x42_y42__blank_))) + :(cell_x_y_x(cell_x41_y41__blank_)))))) * 0.0016))) + Sum (cell_e6_y40__blank_, cell_d6_y40__blank_, cell_c6_y40__blank_, cell_b6_y40__blank_, cell_a6_y40__blank_ | ((cell_x_y_x(cell_a6_y40__blank_) or cell_x_y_x(cell_b6_y40__blank_) or cell_x_y_x(cell_c6_y40__blank_) or cell_x_y_x(cell_d6_y40__blank_) or cell_x_y_x(cell_e6_y40__blank_)) and (cell_x_y_b(cell_a6_y40__blank_) or cell_x_y_x(cell_a6_y40__blank_)) and (cell_x_y_b(cell_b6_y40__blank_) or cell_x_y_x(cell_b6_y40__blank_)) and (cell_x_y_b(cell_c6_y40__blank_) or cell_x_y_x(cell_c6_y40__blank_)) and (cell_x_y_b(cell_d6_y40__blank_) or cell_x_y_x(cell_d6_y40__blank_)) and (cell_x_y_b(cell_e6_y40__blank_) or cell_x_y_x(cell_e6_y40__blank_)) and R0(cell_d6_y40__blank_, cell_e6_y40__blank_) and R0(cell_c6_y40__blank_, cell_d6_y40__blank_) and R0(cell_b6_y40__blank_, cell_c6_y40__blank_) and R0(cell_a6_y40__blank_, cell_b6_y40__blank_)) : ((((((:(cell_x_y_x(cell_a6_y40__blank_)) + :(cell_x_y_x(cell_b6_y40__blank_))) + :(cell_x_y_x(cell_c6_y40__blank_))) + :(cell_x_y_x(cell_d6_y40__blank_))) + :(cell_x_y_x(cell_e6_y40__blank_))) * (((((:(cell_x_y_x(cell_a6_y40__blank_)) + :(cell_x_y_x(cell_b6_y40__blank_))) + :(cell_x_y_x(cell_c6_y40__blank_))) + :(cell_x_y_x(cell_d6_y40__blank_))) + :(cell_x_y_x(cell_e6_y40__blank_))) * (((((:(cell_x_y_x(cell_a6_y40__blank_)) + :(cell_x_y_x(cell_b6_y40__blank_))) + :(cell_x_y_x(cell_c6_y40__blank_))) + :(cell_x_y_x(cell_d6_y40__blank_))) + :(cell_x_y_x(cell_e6_y40__blank_))) * ((((:(cell_x_y_x(cell_a6_y40__blank_)) + :(cell_x_y_x(cell_b6_y40__blank_))) + :(cell_x_y_x(cell_c6_y40__blank_))) + :(cell_x_y_x(cell_d6_y40__blank_))) + :(cell_x_y_x(cell_e6_y40__blank_)))))) * 0.0016))) + Sum (cell_x40_e5__blank_, cell_x40_d5__blank_, cell_x40_c5__blank_, cell_x40_b5__blank_, cell_x40_a5__blank_ | ((cell_x_y_x(cell_x40_a5__blank_) or cell_x_y_x(cell_x40_b5__blank_) or cell_x_y_x(cell_x40_c5__blank_) or cell_x_y_x(cell_x40_d5__blank_) or cell_x_y_x(cell_x40_e5__blank_)) and (cell_x_y_b(cell_x40_a5__blank_) or cell_x_y_x(cell_x40_a5__blank_)) and (cell_x_y_b(cell_x40_b5__blank_) or cell_x_y_x(cell_x40_b5__blank_)) and (cell_x_y_b(cell_x40_c5__blank_) or cell_x_y_x(cell_x40_c5__blank_)) and (cell_x_y_b(cell_x40_d5__blank_) or cell_x_y_x(cell_x40_d5__blank_)) and (cell_x_y_b(cell_x40_e5__blank_) or cell_x_y_x(cell_x40_e5__blank_)) and R(cell_x40_d5__blank_, cell_x40_e5__blank_) and R(cell_x40_c5__blank_, cell_x40_d5__blank_) and R(cell_x40_b5__blank_, cell_x40_c5__blank_) and R(cell_x40_a5__blank_, cell_x40_b5__blank_)) : ((((((:(cell_x_y_x(cell_x40_a5__blank_)) + :(cell_x_y_x(cell_x40_b5__blank_))) + :(cell_x_y_x(cell_x40_c5__blank_))) + :(cell_x_y_x(cell_x40_d5__blank_))) + :(cell_x_y_x(cell_x40_e5__blank_))) * (((((:(cell_x_y_x(cell_x40_a5__blank_)) + :(cell_x_y_x(cell_x40_b5__blank_))) + :(cell_x_y_x(cell_x40_c5__blank_))) + :(cell_x_y_x(cell_x40_d5__blank_))) + :(cell_x_y_x(cell_x40_e5__blank_))) * (((((:(cell_x_y_x(cell_x40_a5__blank_)) + :(cell_x_y_x(cell_x40_b5__blank_))) + :(cell_x_y_x(cell_x40_c5__blank_))) + :(cell_x_y_x(cell_x40_d5__blank_))) + :(cell_x_y_x(cell_x40_e5__blank_))) * ((((:(cell_x_y_x(cell_x40_a5__blank_)) + :(cell_x_y_x(cell_x40_b5__blank_))) + :(cell_x_y_x(cell_x40_c5__blank_))) + :(cell_x_y_x(cell_x40_d5__blank_))) + :(cell_x_y_x(cell_x40_e5__blank_)))))) * 0.0016)))))" + (Formula.real_str loc_heurs.(0).(0)); ); "default_heuristic_old: expansion breakthrough of GDL translation" >:: @@ -472,11 +472,11 @@ Aux.run_test_if_target "HeuristicTest" bigtests let a () = - DiscreteRule.debug_level := 0; + DiscreteRule.debug_level := 4; Heuristic.debug_level := 3 let a () = - match test_filter ["Heuristic:10:default_heuristic_old: Connect4"] + match test_filter ["Heuristic:11:default_heuristic_old: connect5 of GDL translation"] tests with | Some tests -> ignore (run_test_tt ~verbose:true tests) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-23 17:47:09
|
Revision: 1383 http://toss.svn.sourceforge.net/toss/?rev=1383&view=rev Author: lukaszkaiser Date: 2011-03-23 17:47:00 +0000 (Wed, 23 Mar 2011) Log Message: ----------- Cleanups, deleting unused files, www upload script and smaller release without pdfs. Modified Paths: -------------- trunk/Toss/Makefile trunk/Toss/TossTest.ml trunk/Toss/WebClient/Main.js trunk/Toss/www/Makefile Added Paths: ----------- trunk/Toss/www/upload_sourceforge.sh Removed Paths: ------------- trunk/Toss/Solver/FFSolver.ml trunk/Toss/Solver/FFSolver.mli trunk/Toss/Solver/FFSolverTest.ml trunk/Toss/www/img/flags/ trunk/Toss/www/xsl/authors-person-extract.xsl trunk/Toss/www/xsl/games.xsl trunk/Toss/www/xsl/layout-games.xsl Modified: trunk/Toss/Makefile =================================================================== --- trunk/Toss/Makefile 2011-03-23 16:10:48 UTC (rev 1382) +++ trunk/Toss/Makefile 2011-03-23 17:47:00 UTC (rev 1383) @@ -20,6 +20,7 @@ rm -f toss_$(RELEASE)/www/code_doc mv toss_$(RELEASE)/_build/Toss.docdir toss_$(RELEASE)/www/code_doc rm -rf toss_$(RELEASE)/_build toss_$(RELEASE)/gmon.out + rm -rf toss_$(RELEASE)/www/pub zip -r toss_$(RELEASE).zip toss_$(RELEASE) rm -rf toss_$(RELEASE) Deleted: trunk/Toss/Solver/FFSolver.ml =================================================================== --- trunk/Toss/Solver/FFSolver.ml 2011-03-23 16:10:48 UTC (rev 1382) +++ trunk/Toss/Solver/FFSolver.ml 2011-03-23 17:47:00 UTC (rev 1383) @@ -1,1285 +0,0 @@ -(* A solver based on the FF Type Normal Form and {!AssignmentSet}s - without predetermined order of variables. Continuous aspects - (polynomials, real variables, formulas characterizing reals) are - not developed yet (but real expressions with [Sum]s, [Char]acteristic - and real functions are available). - - If the first element of AssignmentSet.FO assoc list has a negative - number instead of an element, it stores the common assignments for - all context elements different than the context elements of the - rest of the list, and the number is the negated number of these - elements (so it is always smaller than zero and the rest of the - list can be empty). This convention is respected by modules - {!AssignmentSet} and {!FFSolver}, but not necessarily ohters. *) - -open Formula -open Printf - -let debug_level = ref 0 - - -open Structure -module A = AssignmentSet - -module Vars = Set.Make (struct - type t = Formula.var - let compare = Pervasives.compare -end) -let add_vars nvs vs = - List.fold_left (fun vs nv -> Vars.add nv vs) vs nvs -let vars_of_list nvs = - add_vars nvs Vars.empty -let sum_vars vars = List.fold_left Vars.union Vars.empty vars -let vars_of_array nvs = - Array.fold_left (fun vs nv -> Vars.add nv vs) Vars.empty nvs - -let sb_str struc sb = - String.concat ", " (List.map (fun (v,e) -> - var_str v^"->"^Structure.elem_str struc e) sb) - -let rec is_unique_assoc = function - | [] -> true - | (e,_)::tl -> if List.mem_assoc e tl then false - else is_unique_assoc tl - -(* - let aFO lnum (v,assgns) = - Printf.printf "(%d:%s) %!" lnum (var_str v); - if is_unique_assoc assgns then A.FO (v, assgns) - else failwith - ("not unique "^string_of_int lnum^": "^A.str (A.FO (v,assgns))) -*) - -(* Exception handling unwinds the stack to the most recent point - selecting a value for a witness. - - It's possible to more thoroughly handle witnesses, by accumulating - all variables whose change might result in change of the resulting - assignment set; but unsure if it would be a considerable - gain. Currently witnesses are only reported for literals. *) -exception Unsatisfiable_FO of Vars.t -exception Unsatisfiable - -let rec map_try ?catch f = function - | [] -> [] - | hd::tl -> - let try r = f hd in - r :: map_try ?catch f tl - with - | Unsatisfiable_FO witnesses as exc -> - if catch = None || Vars.mem (Aux.unsome catch) witnesses - then map_try ?catch f tl - else raise exc - | Unsatisfiable -> - map_try ?catch f tl - -let rec fold_try ?catch f accu = function - | [] -> accu - | hd::tl -> - try - fold_try ?catch f (f accu hd) tl - with - | Unsatisfiable_FO witnesses as exc -> - if catch = None || Vars.mem (Aux.unsome catch) witnesses - then fold_try ?catch f accu tl - else raise exc - | Unsatisfiable -> - fold_try ?catch f accu tl - -let debug_count = ref 0 - -let list_existsi p l = - let rec aux i = function - | [] -> false - | a::l -> p i a || aux (i+1) l in - aux 0 l - -let explicit_v_domain v aset = - let rec aux = function - | A.FO (v1, dis_assgns) when v1 = v -> - let dis_assgns = - match dis_assgns with - | (e,_)::dis_assgns when e < 0 -> dis_assgns - | _ -> dis_assgns in - elems_of_list (List.map fst dis_assgns) - | A.FO (v1, assgns) -> - List.fold_left Elems.union Elems.empty - (List.map (fun (_,aset) -> aux aset) assgns) - | A.Real _ | A.MSO _ -> - failwith "FFSolver: Real/MSO assignments not supported yet" - | _ -> Elems.empty in - aux aset - -(* Remove a variable from an assignment by projecting on the given - element; if the variable does not admit the element, raise - [Unsatisfiable]. *) -let project_v_on_elem v e aset = - let rec aux = function - | A.Empty -> raise Unsatisfiable - | A.Any -> A.Any - | A.FO (v1, dis_assgns) when v1 = v -> - let other_aset, dis_assgns = - match dis_assgns with - | (e,aset)::dis_assgns when e < 0 -> aset, dis_assgns - | _ -> A.Empty, dis_assgns in - (try List.assoc e dis_assgns - with Not_found -> - if other_aset = A.Empty then raise Unsatisfiable - else other_aset) - | A.FO (v1, assgns) -> - let assgns = - map_try (fun (e, aset) -> e, aux aset) assgns in - if assgns = [] then raise Unsatisfiable - else A.FO (v1, assgns) - | A.Real _ | A.MSO _ -> - failwith "FFSolver: Real/MSO assignments not supported yet" in - aux aset - -(* Remove a variable from an assignment by projecting always on the implicit - elements; if the variable does not admit implicit elements, raise - [Unsatisfiable]. (Corresponds to projecting on an element outside of - {!FFSolver.explicit_v_domain}.) *) -let project_v_on_implicit v aset = - let rec aux = function - | A.Empty -> raise Unsatisfiable - | A.Any -> A.Any - | A.FO (v1, (e,aset)::_) when e < 0 && v1 = v -> aset - | A.FO (v1, _) when v1 = v -> raise Unsatisfiable - | A.FO (v1, assgns) -> - let assgns = - map_try (fun (e, aset) -> e, aux aset) assgns in - if assgns = [] then raise Unsatisfiable - else A.FO (v1, assgns) - | A.Real _ | A.MSO _ -> - failwith "FFSolver: Real/MSO assignments not supported yet" in - aux aset - -let rec aset_fo_vars = function - | A.Empty | A.Any -> [] - | A.FO (v, assgns) -> - v :: Aux.concat_map aset_fo_vars (List.map snd assgns) - | A.Real _ | A.MSO _ -> - failwith "FFSolver: Real/MSO assignments not supported yet" - -(* For debugging. Brute force check. *) -(* FIXME: doesn't handle "other element contexts" -let aset_subsumed all_elems a b = - let vars = aset_fo_vars a in - let asbs = A.fo_assgn_to_list all_elems vars a in - let asbs = - Aux.unique (=) (List.map (List.sort Pervasives.compare) asbs) in - let bsbs = A.fo_assgn_to_list all_elems vars b in - let bsbs = - Aux.unique (=) (List.map (List.sort Pervasives.compare) bsbs) in - (* {{{ log entry *) - if !debug_level > 3 then ( - printf "subsumption: test %d <= %d\n%!" - (List.length asbs) (List.length bsbs); - ); - (* }}} *) - List.for_all (fun asb -> - List.exists (fun bsb -> - try - List.for_all (fun (v,ae) -> - List.assoc v bsb = ae) asb - with Not_found -> false) bsbs) asbs -*) - -(* We assume that for every "not ex psi" subformula, "ex psi" is - ground, and that every other occurrence of negation is in a literal - (it is guaranteed by {!FFTNF.ff_tnf}). We assume that every - existentially quantified single disjunct [Ex (vs, Or [phi])] marks - the fact that the body [phi] does not have universal quantifiers - (guaranteed by {!FFSolver.add_locvar_info}). - - We use the structure of the formula to organize search and build - the result on the recursive stack. Accumulated substitution stores - the most recent variable first, it represents the path from root to - the current position in the aset being built. Our approach - resembles constraint propagation: we split the "search space" by - assigning values to a variable once we encounter the first "good" - constraint on that variable. We organize conjunctive constraints - into three queues: currently handled, delayed1: positive has more - than one undefined position or negative with exactly one undefined - position, delayed2: would have to split on all elements. We fold - over disjunctive constraints by keeping the aset subtree to which - we merge from the current context to produce the final answer. (It - is initialized with Empty aset.) In the same way we fold over - assignments for local variables: existentially quantified variables - that do not have a universal quantifier in their scope. - - The rules to merge (disjoin) the current aset (cur-aset) and the - current position (cur-pos): - - (a) cur-aset=Any: return Any (subsumption) - - (b) no more conjuncts in subformula: return Any (subsumption the - other way round) -- descending the recursion stack will rebuild the - final aset - - (c) introducing a variable v that is also the root of cur-aset: - - (c1) map-try over the cur-pos values of v, passing as aset to disjoin - the corresponding cur-aset subtree, or Empty if cur-aset does not - admit given value - - (c2) if map-try returned non-empty, add to it cur-aset subtrees of v - values outside of map-try results (if empty, raise Unsatisfiable) - - (d) introducing a (non-local) variable v that does not occur in cur-aset: - (includes case cur-aset=Empty) - - (d1) map-try over the cur-pos values of v, passing as aset to disjoin - the whole cur-aset - - (d2) if map-try returned non-empty, add to it the whole cur-aset - for v set to all elements outside of map-try results (unless - cur-aset is Empty); if map-try returned empty, raise Unsatisfiable - [TODO: this can benefit from extending the definition of asets with - "other-than" subtree] - - (e) introducing a variable v that occurs in cur-aset: - - (e1) cut the cur-aset into a forest: the aset without v (for each - occurrence of v in cur-aset removing the corresponding assignment - of its parent variable, perhaps recursively if it was a single - assignment), and the asets composed of a single path to each - occurrence of v and its subtree ("flower-trees") - - (e2) pull-out v by copying the trunk in front of each child-subtree - of v, for each "flower-tree" - - (e3) merge the resulting trees starting with "cur-aset with holes", - observing that they have the same order of variables as - "accumulator" on relevant paths, with v at root - - (e1-e3) observe that during merger, the "cur-aset with holes" will - be cloned over, and the v-occurrence-child-subtrees will either be - reintroduced to their original places or the holes kept, depending - on what v-assignment the clone belongs to; this observation is used - for the actual implementation - - (e4) apply the case (c) - - (f) introducing a local variable v (it cannot occur in cur-aset): - fold-try over the cur-pos values of v, passing as the initial aset - to disjoin the whole cur-aset. - - If the first element of [dis_assgns] assoc list has a negative - number instead of an element, it stores the common assignments for - all context elements different than the context elements of the - rest of the list. This convention is respected by modules - {!AssignmentSet} and {!FFSolver}, but not ohters. -*) -(* Model used only for debugging. *) -let merge model all_elems num_elems is_local v init_domain - sb cur_aset eval_cont = - let rec aux = function (* v not in local_vars *) - | A.MSO _ | A.Real _ -> failwith - "FFSolver.evaluate: MSO and Real not supported yet" - (* a *) - | A.Any -> A.Any - (* c *) - | A.FO (v1, dis_assgns) when v1 = v -> - let other_aset, num_implicit, dis_assgns = - match dis_assgns with - | (e,aset)::dis_assgns when e < 0 -> aset, ~-e, dis_assgns - | _ -> A.Empty, 10000 (*ignored*), dis_assgns in - let num_anys = ref 0 and other_used = ref 0 in - let choose e = - let ret_aset = - eval_cont ((v, e)::sb) - (try List.assoc e dis_assgns - with Not_found -> incr other_used; other_aset) in - if ret_aset = A.Any then incr num_anys; - e, ret_aset in - (* c1 *) - let pos_assgns = - map_try ~catch:(v :> var) choose init_domain in - if pos_assgns = [] then raise Unsatisfiable - else - (* c2 *) - let more_assgns = Aux.map_some (fun ((e,aset) as e_aset) -> - if List.mem_assoc e pos_assgns - then None else ( - if aset = A.Any then incr num_anys; - Some e_aset)) - dis_assgns in - let new_implicit = num_implicit - !other_used in - let other_assgns = - if other_aset = A.Empty || new_implicit <= 0 - then [] - else [~-new_implicit, other_aset] in - if other_aset = A.Any then - num_anys := !num_anys + new_implicit; - if !num_anys >= num_elems then A.Any - else A.FO (v, other_assgns @ pos_assgns @ more_assgns) - - (* d *) - | _ when not (A.mem_assoc v cur_aset) -> - (* Unlikely to be useful, but for completeness... *) - let num_anys = ref 0 in - let choose e = - let ret_aset = - eval_cont ((v, e)::sb) cur_aset in - if ret_aset = A.Any then incr num_anys; - e, ret_aset in - (* d1 *) - let pos_assgns = - map_try ~catch:(v :> var) choose init_domain in - if pos_assgns = [] then raise Unsatisfiable - else if !num_anys = num_elems then A.Any - else if cur_aset = A.Empty - then A.FO (v, pos_assgns) - else - (* d2 *) - let num_implicit = num_elems - List.length pos_assgns in - let other_assgns = - if num_implicit <= 0 then [] - else [~-num_implicit, cur_aset] in - A.FO (v, other_assgns @ pos_assgns) - - (* e *) - | _ -> (* when A.mem_assoc v cur_aset *) - let domain = explicit_v_domain v cur_aset in - let pull_v e = - e, project_v_on_elem v e cur_aset in - let pos_assgns = map_try pull_v (Elems.elements domain) in - let num_implicit = num_elems - List.length pos_assgns in - let other_assgns = - if num_implicit <= 0 then [] - else try - [~-num_implicit, project_v_on_implicit v cur_aset] - with Unsatisfiable -> [] in - let assgns = other_assgns @ pos_assgns in - if assgns = [] then raise Unsatisfiable - else aux (A.FO (v, assgns)) in - - if is_local then - (* f *) - let choose cur_aset e = - eval_cont ((v, e)::sb) cur_aset in - let pos_assgns = - fold_try ~catch:(v :> var) choose cur_aset init_domain in - if pos_assgns = A.Empty then raise Unsatisfiable - else pos_assgns - - else aux cur_aset - - -(* Use a bigger assignment set as the first argument. *) -(* Model used only for debugging. *) -let rec sum_assignment_sets model all_elems num_elems aset1 aset2 = - (* [sb] always has the form [v, e] *) - let rec cont disjs sb aset1 = - aux aset1 (List.assoc (snd (List.hd sb)) disjs) - and aux aset1 = function - | A.Empty -> aset1 - | A.Any -> A.Any (* subsumption *) - | A.FO (v, (impl, other_aset2)::dis_assgns) when impl < 0 -> - (* doing some of [merge] work to avoid enumerating all elements - as the init_domain *) - if A.mem_assoc v aset1 then - let domain = explicit_v_domain v aset1 in - let domain = add_elems (List.map fst dis_assgns) domain in - (* {{{ log entry *) - if !debug_level > 4 then ( - printf "sum: var %s -- explicit domain: %s\n%!" (var_str v) - (String.concat ", " (List.map (Structure.elem_str model) - (Elems.elements domain))); - ); - (* }}} *) - let num_anys = ref 0 in - let assgns = List.map (fun e -> - let aset2 = - try List.assoc e dis_assgns with Not_found -> other_aset2 in - let aset1 = - try project_v_on_elem v e aset1 - with Unsatisfiable -> A.Empty in - let aset = aux aset1 aset2 in - assert (aset <> A.Empty); - if aset = A.Any then incr num_anys; - e, aset) (Elems.elements domain) in - let num_implicit = num_elems - (Elems.cardinal domain) in - if !num_anys >= num_elems then A.Any - else if num_implicit <= 0 then A.FO (v, assgns) - else - let other_aset1 = project_v_on_implicit v aset1 in - A.FO (v,(~-num_implicit, aux other_aset1 other_aset2)::assgns) - else (* project v *) - let assgns = List.map snd dis_assgns in - let aset2 = List.fold_left aux other_aset2 assgns in - aux aset1 aset2 - | A.FO (v, assgns) -> - let init_domain = List.map fst assgns in - merge model all_elems num_elems false v init_domain - [] aset1 (cont assgns) - | A.Real _ | A.MSO _ -> - failwith "Real/MSO assignments not supported yet" in - aux aset1 aset2 - -(* Remove existentially quantified variables from the solution. *) -(* Model used only for debugging. *) -and project model all_elems num_elems aset v = - match aset with - | A.Empty -> A.Empty - | A.Any -> A.Any - | A.FO (_, []) -> assert false - | A.FO (v1, [e, aset]) when v1 = v -> aset - | A.FO (v1, (_, aset)::assgns) when v1 = v -> - List.fold_left (sum_assignment_sets model all_elems num_elems) aset - (List.map snd assgns) - | A.FO (v1, assgns) -> - A.FO (v1, List.map (fun (e, aset) -> - e, project model all_elems num_elems aset v) assgns) - | A.Real _ | A.MSO _ -> - failwith "FFSolver: Real/MSO assignments not supported yet" - -(* "Negate" the assignment set wrt. [all_elems]. *) -let rec complement all_elems num_elems = function - | A.Empty -> A.Any - | A.Any -> A.Empty - | A.FO (_, []) -> assert false - | A.FO (v, (impl, A.Any)::dis_assgns) when impl < 0 -> - let deeper = Aux.map_some - (fun (e, aset) -> - let assgn = complement all_elems num_elems aset in - if assgn = A.Empty then None else Some (e, assgn)) - dis_assgns in - if deeper = [] then A.Empty else A.FO (v, deeper) - | A.FO (v, all_assgns) -> - let other_aset, num_implicit, dis_assgns = - match all_assgns with - | (impl, other_aset)::dis_assgns when impl < 0 -> - other_aset, ~-impl, dis_assgns - | _ -> A.Empty, num_elems - List.length all_assgns, all_assgns in - let dropout = ref false in - let deeper = Aux.map_some - (fun (e, aset) -> - let assgn = complement all_elems num_elems aset in - if assgn = A.Empty then (dropout := true; None) - else Some (e, assgn)) - dis_assgns in - let other_aset = complement all_elems num_elems other_aset in - if not !dropout then - A.FO (v, (~-num_implicit, other_aset)::deeper) - else - let other_assgns = Aux.map_some (fun e-> - if List.mem_assoc e dis_assgns then None - else Some (e, other_aset)) all_elems in - let assgns = deeper @ other_assgns in - if assgns = [] then A.Empty else A.FO (v, assgns) - | A.Real _ | A.MSO _ -> - failwith "FFSolver: Real/MSO assignments not supported yet" - -(* Join several assignment sets using de Morgan laws. *) -(* TODO: optimize! write "join" analogous to "merge" to avoid going - through complement *) -(* Model used only for debugging. *) -let intersect_assignment_sets model all_elems num_elems asets = - match asets with - | [] -> A.Any - | [aset] -> aset - | aset::asets -> - let negated = List.map (complement all_elems num_elems) asets in - let neg_aset = complement all_elems num_elems aset in - (* {{{ log entry *) - if !debug_level > 3 then ( - printf "intersect: negated asets: %s\n%!" - (String.concat "; " ( - List.map (AssignmentSet.named_str model) ((neg_aset::negated)))); - ); - (* }}} *) - let union = - List.fold_left (sum_assignment_sets model all_elems num_elems) - neg_aset negated in - (* {{{ log entry *) - if !debug_level > 3 then ( - printf "intersect: union negated: %s\n%!" - (AssignmentSet.named_str model union); - ); - (* }}} *) - let res = complement all_elems num_elems union in - (* {{{ log entry *) - if !debug_level > 3 then ( - printf "intersect: result: %s\n%!" - (AssignmentSet.named_str model res); - ); - (* }}} *) - res - -(* Remove universally quantified variables from the solution. *) -(* Model used only for debugging. *) -let universal model all_elems num_elems aset v = - let rec aux = function - | A.Empty -> raise Unsatisfiable - | A.Any -> A.Any - | A.FO (_, []) -> assert false - | A.FO (v1, all_assgns) when v1 = v -> - let other_aset, num_implicit, dis_assgns = - match all_assgns with - | (e,aset)::dis_assgns when e < 0 -> aset, ~-e, dis_assgns - | _ -> A.Empty, num_elems - List.length all_assgns, all_assgns in - if other_aset = A.Empty && num_implicit > 0 - then ( - (* {{{ log entry *) - if !debug_level > 3 then ( - printf "universal: v=%s -- not enough elements\n%!" - (Formula.var_str v); - ); - (* }}} *) - raise Unsatisfiable - ) else - let aset = - intersect_assignment_sets model all_elems num_elems - (List.map snd all_assgns) in - if aset = A.Empty then ( - (* {{{ log entry *) - if !debug_level > 3 then ( - printf "universal: v=%s -- no common subassignment\n%!" - (Formula.var_str v); - ); - (* }}} *) - raise Unsatisfiable - ) else aset - | A.FO (v1, assgns) -> - let assgns = - map_try (fun (e, aset) -> e, aux aset) assgns in - if assgns = [] then raise Unsatisfiable - else A.FO (v1, assgns) - | A.Real _ | A.MSO _ -> - failwith "FFSolver: Real/MSO assignments not supported yet" in - aux aset - - -(* "Negate" the second assignment set wrt. [all_elems] and add it to the - first aset. *) -(* Model used only for debugging. *) -(* FIXME: handle "other element contexts". *) -let rec add_complement model all_elems num_elems disj_aset = function - | A.Empty -> A.Any - | A.Any -> - if disj_aset = A.Empty then raise Unsatisfiable; - disj_aset - | A.FO (_, []) -> assert false - | A.FO (v, assgns) -> - let add_cont sb dset = - let e = snd (List.hd sb) in - let cset = - (* Empty will turn into Any on recursive callback *) - try List.assoc e assgns with Not_found -> A.Empty in - add_complement model all_elems num_elems dset cset in - merge model all_elems num_elems false v all_elems [] disj_aset add_cont - - | A.Real _ | A.MSO _ -> - failwith "FFSolver: Real/MSO assignments not supported yet" - - -let evaluate model ?(sb=[]) ?(disj_aset=A.Empty) phi = - (* {{{ log entry *) - let guard_number = ref 0 in - if !debug_level > 1 then ( - printf "evaluate: phi=%s; sb=%s; disj_aset=%s\n%!" - (Formula.str phi) (sb_str model sb) - (AssignmentSet.named_str model disj_aset); - ); - (* }}} *) - let all_elems = Elems.elements model.elements in - let num_elems = Elems.cardinal model.elements in - - (* Process conjunctions by passing the remaining conjuncts a la CPS, - filtering according to subsumption with the current alternative - (cur-aset), accumulating assignments in a substitution and - rebuilding the resulting aset on return. Disjunctions are - processed by fold-try of the solution process with cur-aset as - accumulator. Branch on a variable when it is first encountered in - a literal. Eliminate a variable (and sum its branches) from the - assignment set when exiting an existential quantifier [TODO: - optimize]. Check universally quantified variables for coverage. - - Do not return [A.Empty], raise [Unsatisfiable] instead. *) - let rec solve local_vars delayed2 delayed1 conj_cont sb cur_aset = - (* {{{ log entry *) - if !debug_level > 3 then ( - printf "solve: remaining=%s\nsolve: sb=%s\nsolve: disj_aset=%s\n%!" - (Formula.str (And (conj_cont @ delayed1 @ delayed2))) - (sb_str model sb) (AssignmentSet.named_str model cur_aset); - ); - (* }}} *) - (* a *) - if cur_aset = A.Any then ( - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "a: cur_aset=Any subsuming phi=%s\n%!" - (Formula.str (And (conj_cont @ delayed1 @ delayed2))) - ); - (* }}} *) - A.Any - ) else match conj_cont with - | [] -> - if delayed1 <> [] - then solve local_vars delayed2 [] (List.rev delayed1) sb cur_aset - else if delayed2 <> [] - then solve local_vars [] [] (List.rev delayed2) sb cur_aset - (* b *) - else ( - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "b: phi=[] subsuming cur_aset=%s\n%!" - (AssignmentSet.named_str model cur_aset); - ); - (* }}} *) - A.Any (* subsuming [cur_aset] *) - ) - | Rel (relname, vtup) as atom :: conj_cont -> - let tuples_s = - try StringMap.find relname model.relations - with Not_found -> Tuples.empty in - (let try tup = Array.map (fun v->List.assoc v sb) vtup in - if not (Tuples.mem tup tuples_s) - then raise (Unsatisfiable_FO (vars_of_array (var_tup vtup))) - else if conj_cont <> [] - then solve local_vars delayed2 delayed1 conj_cont sb cur_aset - else if delayed1 <> [] - then solve local_vars delayed2 [] (List.rev delayed1) sb cur_aset - else solve local_vars [] [] (List.rev delayed2) sb cur_aset - with Not_found -> - (* we will add new variables one at a time *) - let nvi = - Aux.array_argfind (fun v->not (List.mem_assoc v sb)) vtup in - let nvar = vtup.(nvi) in - let oldvars = - Aux.array_find_all (fun v->List.mem_assoc v sb) vtup in - let multi_unkn = Aux.array_existsi - (fun i v->i>nvi && not (List.mem v oldvars)) vtup in - if multi_unkn && conj_cont <> [] then (* delay *) - solve local_vars delayed2 (atom::delayed1) conj_cont - sb cur_aset - else - (* to narrow the domain, lookup incidence of known vars, - filter for partial match and project on the nvar - position *) - let tuples_i = - try StringMap.find relname model.incidence - with Not_found -> IntMap.empty in - let tups_sets = List.map (fun v-> - try IntMap.find (List.assoc v sb) tuples_i - with Not_found -> Tuples.empty) oldvars in - let tuples = - match tups_sets with - | [] -> tuples_s - | [tups] -> tups - | tups::tups_sets -> - List.fold_left Tuples.inter tups tups_sets in - if Tuples.is_empty tuples - then raise - (Unsatisfiable_FO (vars_of_array (var_tup vtup))) - else - let known_tup = Array.map - (fun v -> try List.assoc v sb with Not_found -> -1) - vtup in - let init_domain = - Tuples.fold (fun tup dom -> - if Aux.array_for_all2 (fun known asked-> - known = -1 || known = asked) known_tup tup - && not (List.mem tup.(nvi) dom) - then tup.(nvi)::dom - else dom) tuples [] in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "init_domain: sb=%s; phi=%s; dom=%s\n%!" - (sb_str model sb) (Formula.str atom) - (String.concat ", " (List.map (Structure.elem_str model) - init_domain)); - ); - (* }}} *) - if init_domain = [] - then raise - (Unsatisfiable_FO (vars_of_array (var_tup vtup))) - else if not multi_unkn && conj_cont = [] && delayed1 = [] && - delayed2 = [] - then (* no more vars and conjuncts *) - merge model all_elems num_elems - (Vars.mem (nvar :> var) local_vars) - nvar init_domain sb cur_aset - (fun _ _ -> A.Any) (* subsume *) - else - let conj_cont = - if multi_unkn then atom::conj_cont else conj_cont in - (* If not [multi_unkn] then for elements in [init_domain] - rel holds *) - merge model all_elems num_elems - (Vars.mem (nvar :> var) local_vars) - nvar init_domain sb cur_aset - (solve local_vars delayed2 delayed1 conj_cont) - ) - - (* by analogy to the [Rel (relname, vtup)] case *) - | Eq (x, y) as atom :: conj_cont -> - let vtup = [x; y] in - (try - if not (List.assoc x sb = List.assoc y sb) - then raise (Unsatisfiable_FO (vars_of_list (vtup :> var list))) - else - solve local_vars delayed2 delayed1 conj_cont sb cur_aset - with Not_found -> - (* we will add new variables one at a time *) - let nvi, nvar = - if List.mem_assoc x sb then 1, y else 0, x in - let oldvars = - List.filter (fun v->List.mem_assoc v sb) vtup in - let multi_unkn = list_existsi - (fun i v->i>nvi && not (List.mem v oldvars)) vtup in - if multi_unkn && (conj_cont <> [] || delayed1 <> []) - then (* delay *) - solve local_vars (atom::delayed2) delayed1 conj_cont - sb cur_aset - else if multi_unkn then - let conj_cont = atom::conj_cont in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "init_domain: sb=%s; phi=%s; dom=ALL ELEMS\n%!" - (sb_str model sb) (Formula.str atom); - ); - (* }}} *) - merge model all_elems num_elems - (Vars.mem (nvar :> var) local_vars) - nvar all_elems sb cur_aset - (solve local_vars delayed2 delayed1 conj_cont) - else - let ovar = if nvi = 1 then x else y in - let e = List.assoc ovar sb in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "init_domain: sb=%s; phi=%s; dom=%s\n%!" - (sb_str model sb) (Formula.str atom) - (Structure.elem_str model e); - ); - (* }}} *) - merge model all_elems num_elems - (Vars.mem (nvar :> var) local_vars) - nvar [e] sb cur_aset - (solve local_vars delayed2 delayed1 conj_cont) - ) - - (* by analogy to the [Rel (relname, vtup)] case *) - | Not (Rel (relname, vtup)) as literal :: conj_cont -> - let tuples_s = - try StringMap.find relname model.relations - with Not_found -> Tuples.empty in - (let try tup = Array.map (fun v->List.assoc v sb) vtup in - if Tuples.mem tup tuples_s - then raise - (Unsatisfiable_FO (vars_of_array (var_tup vtup))) - else if conj_cont <> [] - then solve local_vars delayed2 delayed1 conj_cont sb cur_aset - else if delayed1 <> [] - then solve local_vars delayed2 [] (List.rev delayed1) sb cur_aset - else solve local_vars [] [] (List.rev delayed2) sb cur_aset - with Not_found -> - (* we will add new variables one at a time *) - let nvi = - Aux.array_argfind (fun v->not (List.mem_assoc v sb)) vtup in - let nvar = vtup.(nvi) in - let oldvars = - Aux.array_find_all (fun v->List.mem_assoc v sb) vtup in - let multi_unkn = Aux.array_existsi - (fun i v->i>nvi && not (List.mem v oldvars)) vtup in - if multi_unkn && (conj_cont <> [] || delayed1 <> []) - then (* delay *) - solve local_vars (literal::delayed2) delayed1 conj_cont - sb cur_aset - else if not multi_unkn && conj_cont <> [] - then - solve local_vars delayed2 (literal::delayed1) conj_cont - sb cur_aset - else if multi_unkn then - (* we cannot easily optimize *) - let conj_cont = [literal] in - merge model all_elems num_elems - (Vars.mem (nvar :> var) local_vars) - nvar all_elems sb cur_aset - (solve local_vars delayed2 delayed1 conj_cont) - else - let tuples_i = - try StringMap.find relname model.incidence - with Not_found -> IntMap.empty in - let tups_sets = List.map (fun v-> - try IntMap.find (List.assoc v sb) tuples_i - with Not_found -> Tuples.empty) oldvars in - let tuples = - match tups_sets with - | [] -> tuples_s - | [tups] -> tups - | tups::tups_sets -> - List.fold_left Tuples.inter tups tups_sets in - let init_domain = - if Tuples.is_empty tuples - then all_elems - else - let known_tup = Array.map - (fun v -> try List.assoc v sb with Not_found -> -1) - vtup in - let init_domain_co = - Tuples.fold (fun tup dom -> - if Aux.array_for_all2 (fun known asked-> - known = -1 || known = asked) known_tup tup - then Elems.add tup.(nvi) dom - else dom) tuples Elems.empty in - Elems.elements (Elems.diff model.elements init_domain_co) in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "init_domain: sb=%s; phi=%s; dom=%s\n%!" - (sb_str model sb) (Formula.str literal) - (String.concat ", " (List.map (Structure.elem_str model) - init_domain)); - ); - (* }}} *) - if init_domain = [] - then raise Unsatisfiable - else - (* If not [multi_unkn] then for elements in [init_domain] - rel does not hold *) - merge model all_elems num_elems - (Vars.mem (nvar :> var) local_vars) - nvar init_domain sb cur_aset - (solve local_vars delayed2 delayed1 conj_cont) - ) - - (* by analogy to both [Eq] and [not Rel] cases *) - | Not (Eq (x, y)) as literal :: conj_cont -> - let vtup = [x; y] in - (try - if List.assoc x sb = List.assoc y sb - then raise (Unsatisfiable_FO (vars_of_list ([x; y] :> var list))) - else - solve local_vars delayed2 delayed1 conj_cont sb cur_aset - with Not_found -> - (* we will add new variables one at a time *) - let nvi, nvar = - if List.mem_assoc x sb then 1, y else 0, x in - let oldvars = - List.filter (fun v->List.mem_assoc v sb) vtup in - let multi_unkn = list_existsi - (fun i v->i>nvi && not (List.mem v oldvars)) vtup in - if multi_unkn && (conj_cont <> [] || delayed1 <> []) - then (* delay *) - solve local_vars (literal::delayed2) delayed1 conj_cont - sb cur_aset - else if not multi_unkn && conj_cont <> [] then - solve local_vars delayed2 (literal::delayed1) conj_cont - sb cur_aset - else if multi_unkn then begin - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "init_domain: sb=%s; phi=%s; dom=ALL ELEMS\n%!" - (sb_str model sb) (Formula.str literal); - ); - (* }}} *) - merge model all_elems num_elems - (Vars.mem (nvar :> var) local_vars) - nvar all_elems sb cur_aset - (solve local_vars delayed2 delayed1 (literal :: conj_cont)) - end else (* optimize *) - let ovar = if nvi = 1 then x else y in - let e = List.assoc ovar sb in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "init_domain: sb=%s; phi=%s; dom=ALL ELEMS - %s\n%!" - (sb_str model sb) (Formula.str literal) - (Structure.elem_str model e); - ); - (* }}} *) - let init_domain = - Elems.elements (Elems.remove e model.elements) in - merge model all_elems num_elems - (Vars.mem (nvar :> var) local_vars) - nvar init_domain sb cur_aset - (solve local_vars delayed2 delayed1 conj_cont) - ) - - | Or [_] :: _ | And [_] :: _ -> assert false - - (* use associativity, but don't invert the order *) - | And conj :: conj_cont -> - let conj_cont = - if conj_cont = [] then conj else conj @ conj_cont in - solve local_vars delayed2 delayed1 conj_cont sb cur_aset - - (* Propagate implication constraints. *) - | Or fl :: conj_cont when List.exists - (function Not _ -> true | _ -> false) fl -> - (* {{{ log entry *) - let cur_guard = !guard_number in - if !debug_level > 2 then ( - printf "Computing guard no %d..." cur_guard; incr guard_number; - ); - (* }}} *) - let guard, body = Aux.partition_map - (function Not phi -> Aux.Left phi | phi -> Aux.Right phi) fl in - (* assignments of the guard alone *) - let guard_set = - try solve local_vars [] [] guard sb A.Empty - with Unsatisfiable_FO _ | Unsatisfiable -> A.Empty in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Guard: no %d guard_set=%s\nBody: %s\n%!" cur_guard - (AssignmentSet.named_str model guard_set) (Formula.str (Or body)); - ); - (* }}} *) - let cur_aset = - add_complement model all_elems num_elems cur_aset guard_set in - if body = [] || guard_set = A.Empty then - (* the positive part is in effect false -- discard it *) - solve local_vars delayed2 delayed1 conj_cont sb cur_aset - else - (* hopefully more constrained - (TODO: don't redo the guard?) *) - let concl = - match body with - | [concl] -> concl | _ -> Or body in - solve local_vars delayed2 delayed1 - (guard @ [concl] @ conj_cont) sb cur_aset - - (* Continue in each branch folding disjuncts; "Or []" is OK. *) - | Or fl :: conj_cont -> - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Folding-disjunctively-over: %s\ndisjunct-continuation: %s\n%!" - (Formula.str (Or fl)) (Formula.str (And conj_cont)); - ); - (* }}} *) - fold_try (fun dset phi -> - (* {{{ log entry *) - if !debug_level > 3 then ( - printf "disjunct: %s; prior dset=%s\n%!" - (Formula.str phi) (AssignmentSet.named_str model dset); - ); - (* }}} *) - (* DNF-style: if there are remaining conjuncts, solve them - in each branch of disjunction. *) - solve local_vars delayed2 delayed1 (phi::conj_cont) sb dset) - cur_aset fl - - | Ex ([], phi) :: _ | All ([], phi) :: _ -> assert false - - (* Local variables -- handled by merging online. *) - | Ex (vl, Or [phi]) :: conj_cont -> - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Solving-for-local-variables: %s...\n%!" - (String.concat ", " (List.map Formula.var_str vl)); - ); - (* }}} *) - let local_vars = add_vars vl local_vars in - (* FIXME: after debugging return to tail call *) - let aset = - solve local_vars delayed2 delayed1 (phi::conj_cont) sb - cur_aset in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Solved-local-variables: %s; aset=%s\n%!" - (String.concat ", " (List.map Formula.var_str vl)) - (AssignmentSet.named_str model aset); - ); - (* }}} *) - (* TODO: handle other kinds *) - aset - - (* Only project, as the mechanics of existential variables is - handled at the site of their first occurrence. *) - | Ex (vl, phi) :: conj_cont -> - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Solving-for-existential-variables: %s...\n%!" - (String.concat ", " (List.map Formula.var_str vl)); - ); - (* }}} *) - let aset = - solve local_vars delayed2 delayed1 (phi::conj_cont) sb cur_aset in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Solved-existential-variables: %s; aset=%s\n%!" - (String.concat ", " (List.map Formula.var_str vl)) - (AssignmentSet.named_str model aset); - ); - (* }}} *) - (* TODO: handle other kinds *) - let vl = List.map to_fo vl in - let aset = - List.fold_left (project model all_elems num_elems) aset vl in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Eliminated-variables: %s; aset=%s\n%!" - (String.concat ", " (List.map Formula.var_str vl)) - (AssignmentSet.named_str model aset); - ); - (* }}} *) - aset - - (* Check whether assignment set covers all elements for variables - [vl]. *) - | All (vl, phi) :: conj_cont -> - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Solving-for-universal-variables: %s...\n%!" - (String.concat ", " (List.map Formula.var_str vl)); - ); - (* }}} *) - let aset = - solve local_vars delayed2 delayed1 (phi::conj_cont) sb cur_aset in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Solved-universal-variables: %s; aset=%s\n%!" - (String.concat ", " (List.map Formula.var_str vl)) - (AssignmentSet.named_str model aset); - ); - (* }}} *) - (* TODO: handle other kinds *) - let vl = List.map to_fo vl in - let aset = - List.fold_left (universal model all_elems num_elems) aset vl in - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Eliminated-variables: %s; aset=%s\n%!" - (String.concat ", " (List.map Formula.var_str vl)) - (AssignmentSet.named_str model aset); - ); - (* }}} *) - aset - - (* By assumption that [phi] is ground, check it - separately and proceed or fail. *) - | Not phi as subtask :: conj_cont -> - (* {{{ log entry *) - if !debug_level > 2 then ( - printf "Solving-a-subtask: %s...\n" (Formula.str subtask); - ); - (* }}} *) - let aset = - (* solving in empty context! *) - try solve local_vars [] [] [phi] [] A.Empty - with Unsatisfiable_FO _ | Unsatisfiable -> A.Empty in - if !debug_level > 2 then ( - printf "Solved-subtask: %s\nsubtask: aset=%s\n%!" - (Formula.str subtask) (AssignmentSet.named_str model aset); - ); - if aset = A.Empty then - solve local_vars delayed2 delayed1 conj_cont sb cur_aset - else raise Unsatisfiable - - | RealExpr _ :: _ | In _ :: _ -> - failwith - "FFSolver: MSO and Reals not implemented yet." - - (* - and solve_db sb delayed2 delayed1 conj_cont = - let count = !debug_count in - incr debug_count; - printf "solve: #%d, sb=%s, conj_cont=%s\n%!" count - ("["^String.concat ", "(List.map (fun (v,e)-> - Formula.var_str v^":"^string_of_int e) sb)^"]") - (String.concat "; " (List.map Formula.str conj_cont)); - let aset = solve sb delayed2 delayed1 conj_cont in - printf "solve-ret: #%d, aset=%s\n%!" count (Assignments.str aset); - aset - *) - in - try solve Vars.empty [] [] [phi] sb disj_aset - with Unsatisfiable_FO _ | Unsatisfiable -> A.Empty - -(* Assignments of a single variable that are supported by all - assignments for remaining variables. *) -let rec assgn_of struc var = function - | A.Any -> - struc.elements - | A.Empty -> Elems.empty - | A.FO (v, (e,_)::els) when v = var && e < 0 -> - struc.elements - | A.FO (v, els) when v = var -> - List.fold_right Elems.add (List.map fst els) Elems.empty - | A.FO (_, els) -> - List.fold_left Elems.union - (assgn_of struc var (snd (List.hd els))) - (List.map (fun suba -> assgn_of struc var (snd suba)) - (List.tl els)) - | A.MSO (_, els) -> - List.fold_left Elems.union - (assgn_of struc var (snd (List.hd els))) - (List.map (fun suba -> assgn_of struc var (snd suba)) - (List.tl els)) - | A.Real _ -> - failwith "FFSolver: MSO and Reals not implemented yet." - -let rec check_formula struc ?sb ?disj_aset = function - | Ex (vs, phi) -> check_formula struc ?sb ?disj_aset phi - | Or (fl) -> List.exists (check_formula struc ?sb ?disj_aset) fl - | phi -> evaluate struc ?sb ?disj_aset phi <> A.Empty - -let get_real_val expr struc = - let all_elems = Structure.Elems.elements struc.elements in - let rec aux sb = function - | Char phi -> - if !debug_level > 5 then - printf "get_real_val: computing %s ..%!" (Formula.str phi); - let res = if check_formula struc ~sb phi then 1. else 0. in - if !debug_level > 5 then printf ". %f\n%!" res; - res - | Const v -> v - | Times (e1, e2) -> aux sb e1 *. aux sb e2 - | Plus (e1, e2) -> aux sb e1 +. aux sb e2 - | Sum (vl, guard, r) -> - let aset = evaluate struc ~sb guard in - let assgns = - A.fo_assgn_to_list all_elems vl aset in - List.fold_left (fun acc assgn -> - acc +. aux (assgn @ sb) r - ) 0. assgns - | Fun (s, v) -> - (let try e = List.assoc v sb in - IntMap.find e (StringMap.find s struc.functions) - with Not_found -> - failwith - ("Heuristic.get_real_val:" ^ - " function application "^s^"("^var_str (v :> var) ^ - ") to undefined variable")) - - | RVar _ -> - failwith "FFSolver: MSO and Reals not implemented yet." in - if !debug_level > 4 then - printf "get_real_val: %s\n%!" (Formula.real_str expr); - aux [] expr - -(** {2 Structure-based helper functions for {!FFTNF}.} *) - -(* Promote literals with less satisfying tuples, but prefer - equalities to other literal and disequalities less than other literals. *) -let promote_for model lit1 lit2 = - match lit1, lit2 with - | (Rel (r1, _) | Not (Rel (r1, _))), (Rel (r2, _) | Not (Rel (r2, _))) - -> - let tups1 = - try Structure.StringMap.find r1 model.Structure.relations - with Not_found -> Structure.Tuples.empty in - let tups2 = - try Structure.StringMap.find r2 model.Structure.relations - with Not_found -> Structure.Tuples.empty in - let n1, n2 = - Structure.Tuples.cardinal tups1, Structure.Tuples.cardinal tups2 in - begin match lit1, lit2 with - | Rel _, Rel _ -> n1 < n2 - | Not (Rel _), Rel _ -> false - | Rel _, Not (Rel _) -> true - | Not (Rel _), Not (Rel _) -> n1 > n2 - | _ -> assert false - end - | (Rel (r1, _) | Not (Rel (r1, _))), Not (Eq _) -> true - | Eq _, (Rel (r2, _) | Not (Rel (r2, _))) -> true - | _ -> false - -let normalize_for_model model ?fvars phi = - let fvars = match fvars with - | Some fv -> fv - | None -> FormulaOps.free_vars phi in - let phi = - Ex (fvars, FormulaOps.rename_quant_avoiding fvars phi) in - let rec erase_q = function - | Ex (vs, phi) -> - let nvs = - List.filter (fun v -> not (List.mem v fvars)) vs in - if nvs = [] then erase_q phi - else Ex (nvs, erase_q phi) - | All (vs, phi) -> - let nvs = - List.filter (fun v -> not (List.mem v fvars)) vs in - if nvs = [] then erase_q phi - else All (nvs, erase_q phi) - | And fs -> And (List.map erase_q fs) - | Or fs -> Or (List.map erase_q fs) - | Not phi -> Not (erase_q phi) - | (Rel _ | Eq _ | RealExpr _ | In _) as atom -> atom in - erase_q (FFTNF.ff_tnf (promote_for model) phi) - -let normalize_expr_for_model model expr = - let norm phi = - FFTNF.ff_tnf (promote_for model) phi in - let rec aux = function - | RVar _ - | Const _ - | Fun _ as expr -> expr - | Times (a, b) -> Times (aux a, aux b) - | Plus (a, b) -> Plus (aux a, aux b) - | Char phi -> Char (norm phi) - | Sum (vl, gd, e) -> Sum (vl, norm gd, aux e) in - aux expr - -let add_locvar_info phi = - let rec has_univ = function - | All _ -> true - | Or js | And js -> List.exists has_univ js - | Ex (_, phi) -> has_univ phi - | _ -> false in (* assumes (partial) NNF *) - let rec aux = function - | Ex (vs, phi) when not (has_univ phi) -> - Ex (vs, Or [aux phi]) - | Ex (vs, phi) -> Ex (vs, aux phi) - | All (vs, phi) -> All (vs, aux phi) - | Not phi -> Not (aux phi) (* subtasks also apply *) - | Or [phi] -> aux phi - | And [phi] -> aux phi - | Or djs -> Or (List.map aux djs) - | And cjs -> And (List.map aux cjs) - | atom -> atom in - aux phi - -let rec add_locvar_info_expr = function - | Times (a,b) -> - Times (add_locvar_info_expr a, add_locvar_info_expr b) - | Plus (a,b) -> - Plus (add_locvar_info_expr a, add_locvar_info_expr b) - | Char (phi) -> Char (add_locvar_info phi) - | Sum (vs, guard, expr) -> - Sum (vs, add_locvar_info guard, add_locvar_info_expr expr) - | simple -> simple - -(* Interface to {!SolverIntf}. *) -module M = struct - (* Store whether the formula has been preprocessed. *) - type registered_formula = (Formula.formula * bool) ref - type registered_real_expr = (Formula.real_expr * bool) ref - let register_formula phi = ref (phi, false) - let register_real_expr expr = ref (expr, false) - (* before {!FFSolver.M.evaluate} to avoid name conflict. *) - let evaluate_partial struc sb reg_phi = - if not (snd !reg_phi) then - reg_phi := - add_locvar_info - (normalize_for_model struc - ((* FormulaOps.simplify *) (fst !reg_phi))), true; - evaluate struc ~sb (fst !reg_phi) - let evaluate struc reg_phi = - if not (snd !reg_phi) then - reg_phi := - add_locvar_info - (normalize_for_model struc - ((* FormulaOps.simplify *) (fst !reg_phi))), true; - evaluate struc (fst !reg_phi) - let check_formula struc reg_phi = - if not (snd !reg_phi) then - reg_phi := - add_locvar_info - (normalize_for_model struc (fst !reg_phi)), true; - check_formula struc (fst !reg_phi) - let get_real_val reg_expr struc = - if not (snd !reg_expr) then - reg_expr := - add_locvar_info_expr - (normalize_expr_for_model struc (fst !reg_expr)), true; - get_real_val (fst !reg_expr) struc - let formula_str reg_phi = - if not (snd !reg_phi) then - (* TODO: inconsistent with other defs *) - (* to increase consistency of display *) - reg_phi := FormulaOps.simplify (fst !reg_phi), false; - Formula.str (fst !reg_phi) -end Deleted: trunk/Toss/Solver/FFSolver.mli =================================================================== --- trunk/Toss/Solver/FFSolver.mli 2011-03-23 16:10:48 UTC (rev 1382) +++ trunk/Toss/Solver/FFSolver.mli 2011-03-23 17:47:00 UTC (rev 1383) @@ -1,70 +0,0 @@ -(** A solver based on the FF Type Normal Form and - {!Assignments}. Continuous aspects (polynomials, real variables, - formulas characterizing reals) are not developed. Also fixes some - [Solver.Sum] computation bug. - -*) - - -val debug_level : int ref - - -(** Find satisfying substitutions for free variables of a formula that - extend the given substitution. *) -val evaluate : Structure.structure -> - ?sb:((Formula.fo_var * Structure.Elems.elt) list) -> - ?disj_aset:AssignmentSet.assignment_set -> - Formula.formula -> AssignmentSet.assignment_set - -(** Find satisfying substitutions for free variables of a formula (or - check if it holds if it is ground). Does not handle real - expressions and second-order variables currently. *) - -(** Find satisfying substitutions for free variables of a formula (or - check if it holds if it is ground). Does not handle real - expressions and second-order variables currently. *) -val check_formula : - Structure.structure -> - ?sb:((Formula.fo_var * Structure.Elems.elt) list) -> - ?disj_aset:AssignmentSet.assignment_set -> - Formula.formula -> bool - -(** Compute the value of an expresssion in a structure. Does not - handle polynomials. *) -val get_real_val : Formula.real_expr -> Structure.structure -> float - - -(** Promote relations of smaller cardinality in the example - structure. For use with {!FFTNF.ff_tnf}. *) -val promote_for : - Structure.structure -> Formula.formula -> Formula.formula -> bool - -(** An interface to {!FFTNF.ff_tnf} that uses {!promote_for}. *) -val normalize_for_model : - Structure.structure -> ?fvars:Formula.var list -> Formula.formula -> - Formula.formula - -(** Perform {!FFTNF.ff_tnf} (using {!promote_for}) on formulas - occurring in an expression. *) -val normalize_expr_for_model : - Structure.structure -> Formula.real_expr -> Formula.real_expr - -(* Interface to {!SolverIntf}. *) -module M : sig - type registered_formula - type registered_real_expr - val register_formula : - Formula.formula -> registered_formula - val register_real_expr : - Formula.real_expr -> registered_real_expr - val evaluate : Structure.structure -> - registered_formula -> AssignmentSet.assignment_set - val evaluate_partial : - Structure.structure -> (Formula.fo_var * int) list -> - registered_formula -> AssignmentSet.assignment_set - val check_formula : Structure.structure -> - registered_formula -> bool - val get_real_val : - registered_real_expr -> Structure.structure -> float - val formula_str : registered_formula -> string -end Deleted: trunk/Toss/Solver/FFSolverTest.ml =================================================================== --- trunk/Toss/Solver/FFSolverTest.ml 2011-03-23 16:10:48 UTC (rev 1382) +++ trunk/Toss/Solver/FFSolverTest.ml 2011-03-23 17:47:00 UTC (rev 1383) @@ -1,358 +0,0 @@ -open OUnit -open Aux -open Printf - -let my_cmp_float x y = - abs_float (x -. y) <= 0.01 - -let struc_of_str s = - StructureParser.parse_structure Lexer.lex (Lexing.from_string s) - -let formula_of_str s = - FormulaParser.parse_formula Lexer.lex (Lexing.from_string s) - -let real_of_str s = - FormulaParser.parse_real_expr Lexer.lex (Lexing.from_string s) - -let winQxyz = - "ex x, y, z ((((Q(x) and Q(y)) and Q(z)) and ((((R(x, y) and R(y, z)) or (C(x, y) and C(y, z))) or ex u, v ((((R(x, v) and C(v, y)) and R(y, u)) and C(u, z)))) or ex u, v ((((R(x, v) and C(y, v)) and R(y, u)) and C(z, u))))))" - -let winPxyz = - "ex x, y, z ((((P(x) and P(y)) and P(z)) and ((((R(x, y) and R(y, z)) or (C(x, y) and C(y, z))) or ex u, v ((((R(x, v) and C(v, y)) and R(y, u)) and C(u, z)))) or ex u, v ((((R(x, v) and C(y, v)) and R(y, u)) and C(z, u))))))" - -let winQvwxyz = - "ex v, w, x, y, z ((((((Q(v) and Q(w)) and Q(x)) and Q(y)) and Q(z)) and ((((((R(v, w) and R(w, x)) and R(x, y)) and R(y, z)) or (((C(v, w) and C(w, x)) and C(x, y)) and C(y, z))) or ex r, s, t, u ((((((((R(v, r) and C(r, w)) and R(w, s)) and C(s, x)) and R(x, t)) and C(t, y)) and R(y, u)) and C(u, z)))) or ex r, s, t, u ((((((((R(v, r) and C(w, r)) and R(w, s)) and C(x, s)) and R(x, t)) and C(y, t)) and R(y, u)) and C(z, u))))))" - -let breakW_expanded = "ex y8 ((W(y8) and ex y7 ((C(y7, y8) and ex y6 ((C(y6, y7) and ex y5 ((C(y5, y6) and ex y4 ((C(y4, y5) and ex y3 ((C(y3, y4) and ex y2 ((C(y2, y3) and ex y1 (C(y1, y2))))))))))))))))" - -let winQvwxyz_expanded = "ex z ((Q(z) and (ex u0 ((C(u0, z) and ex y ((R(y, u0) and Q(y) and ex t0 ((C(t0, y) and ex x ((R(x, t0) and Q(x) and ex s0 ((C(s0, x) and ex w ((R(w, s0) and Q(w) and ex r0 ((C(r0, w) and ex v ((R(v, r0) and Q(v))))))))))))))))) or ex u ((C(z, u) and ex y ((R(y, u) and Q(y) and ex t ((C(y, t) and ex x ((R(x, t) and Q(x) and ex s ((C(x, s) and ex w ((R(w, s) and Q(w) and ex r ((C(w, r) and ex v ((R(v, r) and Q(v))))))))))))))))) or ex y ((C(y, z) and Q(y) and ex x ((C(x, y) and Q(x) and ex w ((C(w, x) and Q(w) and ex v ((C(v, w) and Q(v))))))))) or ex y ((R(y, z) and Q(y) and ex x ((R(x, y) and Q(x) and ex w ((R(w, x) and Q(w) and ex v ((R(v, w) and Q(v))))))))))))" - -(* alfa-conversion of the above *) -let winQvwxyz_idempotent = "ex z ((Q(z) and (ex u0 ((C(u0, z) and ex y2 ((R(y2, u0) and Q(y2) and ex t0 ((C(t0, y2) and ex x2 ((R(x2, t0) and Q(x2) and ex s0 ((C(s0, x2) and ex w2 ((R(w2, s0) and Q(w2) and ex r0 ((C(r0, w2) and ex v2 ((R(v2, r0) and Q(v2))))))))))))))))) or ex u ((C(z, u) and ex y1 ((R(y1, u) and Q(y1) and ex t ((C(y1, t) and ex x1 ((R(x1, t) and Q(x1) and ex s ((C(x1, s) and ex w1 ((R(w1, s) and Q(w1) and ex r ((C(w1, r) and ex v1 ((R(v1, r) and Q(v1))))))))))))))))) or ex y0 ((C(y0, z) and Q(y0) and ex x0 ((C(x0, y0) and Q(x0) and ex w0 ((C(w0, x0) and Q(w0) and ex v0 ((C(v0, w0) and Q(v0))))))))) or ex y ((R(y, z) and Q(y) and ex x ((R(x, y) and Q(x) and ex w ((R(w, x) and Q(w) and ex v ((R(v, w) and Q(v))))))))))))" - -let eval_eq struc_s phi_s aset_s = - let struc = struc_of_str struc_s in - let f = FFSolver.M.register_formula (formula_of_str phi_s) in - assert_equal ~printer:(fun x -> x) aset_s - (AssignmentSet.named_str struc (FFSolver.M.evaluate struc f)) -;; - -let real_val_eq struc_s expr_s x = - let struc = struc_of_str struc_s in - let expr = - FFSolver.M.register_real_expr (real_of_str expr_s) in - assert_equal ~printer:(fun x -> string_of_float x) ~msg:expr_s - x (FFSolver.M.get_real_val expr struc) - -let tests = "FFSolver" >::: [ - "eval: first-order quantifier free from SolverTest.ml" >:: - (fun () -> - eval_eq "[ | R { (a, b); (a, c) } | ]" "x = y" - "{ x->a{ y->a } , x->b{ y->b } , x->c{ y->c } }"; - eval_eq "[ | R { (a, b); (b, c) }; P { b } | ]" "P(x) and x = y" - "{ x->b{ y->b } }"; - eval_eq "[ | R { (a, b); (a, c) } | ]" "R(x, y) and x = y" - "{}"; - eval_eq "[ | R { (a, a); (a, b) } | ]" "R(x, y) and x = y" - "{ x->a{ y->a } }"; - eval_eq "[ | R { (a, b); (a, c) } | ]" "not x = y" - "{ x->a{ y->b, y->c } , x->b{ y->a, y->c } , x->c{ y->a, y->b } }"; - eval_eq "[ | R { (a, a); (a, c) } | ]" "R (x, y) and not x = y" - "{ x->a{ y->c } }"; - ); - - "eval: first-order ... [truncated message content] |
From: <luk...@us...> - 2011-03-23 16:10:55
|
Revision: 1382 http://toss.svn.sourceforge.net/toss/?rev=1382&view=rev Author: lukstafi Date: 2011-03-23 16:10:48 +0000 (Wed, 23 Mar 2011) Log Message: ----------- Heuristic: expansion fixes; using suggest_expansion to avoid expanding existential formulas which already have rich structure. Modified Paths: -------------- trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/Heuristic.mli trunk/Toss/Play/HeuristicTest.ml Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-23 14:18:12 UTC (rev 1381) +++ trunk/Toss/Play/Heuristic.ml 2011-03-23 16:10:48 UTC (rev 1382) @@ -243,8 +243,10 @@ let debug_level = ref 0 +(* TODO: not exporting these in the API as global variables? *) let default_nonmonot_adv_ratio = 2.0 let default_monot_adv_ratio = 4.0 +let suggest_expansion_coef = 0.5 let f_monot adv_ratio n m = Times (Formula.pow n (int_of_float adv_ratio), @@ -637,6 +639,35 @@ expanded_descr max_alt_descr elems rels struc (strings_of_list (List.map var_str vars)) vars substs +let suggest_expansion struc phi = + let has_univ = + let gfold = + {FormulaOps.make_fold (||) false with + FormulaOps.fold_All = (fun _ _ -> true)} in + FormulaOps.fold_formula gfold in + let pattern_size = + let gfold = + {FormulaOps.make_fold (max) 0 with + FormulaOps.fold_And = (+); + fold_Ex = (fun vs s -> List.length vs + s); + fold_Sum = (fun vs s1 s2 -> List.length vs + s1 + s2) + } in + FormulaOps.fold_formula gfold in + let i2f = float_of_int in + let nelems = Structure.Elems.cardinal struc.Structure.elements in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf + "suggest_expansion: has_univ=%b; threshold=%F; pattern_size=%d; \ + phi=\n%s\n%!" + (has_univ phi) (suggest_expansion_coef *. sqrt (i2f nelems)) + (pattern_size phi) + (Formula.sprint phi) + ); + (* }}} *) + has_univ phi || + i2f (pattern_size phi) < suggest_expansion_coef *. sqrt (i2f nelems) + let expanded_form max_alt_descr frels struc phi = let elems = Elems.elements struc.elements in @@ -646,59 +677,67 @@ let rels = List.filter (fun (rel,_) -> not (Strings.mem rel frels)) rels in let rec aux all_vars = function - | Rel _ | Eq _ | In _ as phi -> phi - | Not (Rel _) | Not (Eq _) | Not (In _) as phi -> phi - | Not psi -> aux all_vars (FormulaOps.nnf ~neg:true psi) + | Eq _ | In _ | RealExpr _ as phi -> phi + | Not (Eq _) | Not (In _) | Not (RealExpr _) as phi -> phi + | Not psi when (match psi with Rel _ -> false | _ -> true) -> + aux all_vars (FormulaOps.nnf ~neg:true psi) | Or phis -> Or (List.map (aux all_vars) phis) | And phis (* as phi when (has_rels frels phi) *) -> And (List.map (aux all_vars) phis) - | Ex (vs, phi) when has_rels frels phi -> + | Ex (vs, phi) as ephi when has_rels frels phi + && suggest_expansion struc ephi -> Ex (vs, aux (add_strings (List.map var_str vs) all_vars) phi) - | phi -> - if has_rels frels phi then phi - else - let vars = + | phi when not (has_rels frels phi) + && suggest_expansion struc phi -> + let vars = (* TODO: assumes all variables are FO! *) - List.map Formula.to_fo (FormulaOps.free_vars phi) in - if vars = [] then phi - else begin + List.map Formula.to_fo (FormulaOps.free_vars phi) in + if vars = [] then phi + else begin (* {{{ log entry *) - if !debug_level > 2 then ( - Printf.printf - "Heuristic: computing expanded description for %s...\n%!" - (Formula.sprint phi) - ); + if !debug_level > 2 then ( + Printf.printf + "Heuristic: computing expanded description for %s...\n%!" + (Formula.sprint phi) + ); (* }}} *) - let asgns = Solver.M.evaluate struc phi in - let substs = - AssignmentSet.fo_assgn_to_list elems vars asgns in + let asgns = Solver.M.evaluate struc phi in + let substs = + AssignmentSet.fo_assgn_to_list elems vars asgns in (* sort substitutions; TODO: optimizable *) - let substs = trunc_to_vars vars substs in + let substs = trunc_to_vars vars substs in (* {{{ log entry *) - if !debug_level > 3 then ( - Printf.printf - "Heuristic: computed substitutions for expansion...\n%!" - ); + if !debug_level > 3 then ( + Printf.printf + "Heuristic: computed substitutions for expansion...\n%!" + ); (* }}} *) - let all_vars = add_strings (List.map var_str vars) all_vars in - match - expanded_descr max_alt_descr elems rels struc - all_vars vars substs - with - | Or [] -> - (match phi with - | And phis -> And (List.map (aux all_vars) phis) - | Ex (vs, phi) -> - Ex (vs, aux - (add_strings (List.map var_str vs) all_vars) phi) - | _ -> phi) - | Or [psi] -> psi - | psi -> psi - end in + let all_vars = add_strings (List.map var_str vars) all_vars in + match + expanded_descr max_alt_descr elems rels struc + all_vars vars substs + with + | Or [] -> + (match phi with + | And phis -> And (List.map (aux all_vars) phis) + | Ex (vs, phi) -> + Ex (vs, aux + (add_strings (List.map var_str vs) all_vars) phi) + | _ -> phi) + | Or [psi] -> + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf "Heuristic: expanded to %s\n%!" + (Formula.sprint psi) + ); + (* }}} *) + psi + | psi -> psi + end + | phi -> phi in aux Strings.empty phi - (* ********** Heuristic of Payoff Expression ********** *) (* Generalized product. [product l = gproduct (fun x y->x::y) [] l]. *) Modified: trunk/Toss/Play/Heuristic.mli =================================================================== --- trunk/Toss/Play/Heuristic.mli 2011-03-23 14:18:12 UTC (rev 1381) +++ trunk/Toss/Play/Heuristic.mli 2011-03-23 16:10:48 UTC (rev 1382) @@ -76,12 +76,10 @@ (** Whether a formula should be considered for expansion: has a universal quantifier or the number of its existential quantifiers - is smaller than the square root of the number of elements in the - structure. *) -(* + is smaller than [suggest_expansion_coef] times the + square root of the number of elements in the structure. *) val suggest_expansion : - Formula.formula -> Structure.structure -> bool -*) + Structure.structure -> Formula.formula -> bool (** Heuristic of payoff expression. *) val of_payoff : ?force_parsimony:int -> Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2011-03-23 14:18:12 UTC (rev 1381) +++ trunk/Toss/Play/HeuristicTest.ml 2011-03-23 16:10:48 UTC (rev 1382) @@ -347,46 +347,10 @@ Heuristic.default_heuristic_old ~struc:state.Arena.struc ~advr:2.0 game in assert_equal ~printer:(fun x->x) - "(100. * ((0.5 + (1. * :((not ex cellholds_x27_y26__blank_ ((cellholds_x2_y2_black(cellholds_x27_y26__blank_) and (not control_MV1(cellholds_x27_y26__blank_)))))))) + Sum (cellholds_x26_8__blank_ | cellholds_x2_y2_white(cellholds_x26_8__blank_) : (1. + MORE SUM TERMS HERE))))" + "(100. * ((0.96875 + (1.9375 * :((not ex cellholds_x27_y26__blank_ ((cellholds_x2_y2_black(cellholds_x27_y26__blank_) and (not control_MV1(cellholds_x27_y26__blank_)))))))) + Sum (cellholds_x26_8__blank_ | (cellholds_x2_y2_white(cellholds_x26_8__blank_) and (not control_MV1(cellholds_x26_8__blank_))) : (0.0625 + Sum (y | R2(cellholds_x26_8__blank_, y) : (0.125 + Sum (y0 | R2(y, y0) : (0.25 + Sum (y1 | R2(y0, y1) : (0.5 + Sum (y2 | (R2(y1, y2) and cellholds_x2_4_MV1(y2)) : 1.)))))))))))" (Formula.real_str loc_heurs.(0).(0)); ); -] - -let bigtests = "HeuristicBig" >::: [ - "expanded_description: fenced breakthrough 2 vars" >:: - (fun () -> - let state = - struc_of_string -"[ | | ] \" - - F F F F F F F F - ... ... ... ... - B B..B B..B B..B B.. - ... ... ... ... - B..B B..B B..B B..B - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ... ... ... - ... ... ... ... - W W..W W..W W..W W.. - ... ... ... ... - W..W W..W W..W W..W - - F F F F F F F F -\"" in - assert_equal ~printer:(fun x->x) - "ex y7, y6, y5, y4, y3, y2, y1, y0 ((C(y7, y6) and C(y6, y5) and C(y5, y4) and C(y4, y3) and C(y3, y2) and C(y2, y1) and C(y1, y0) and C(y0, x) and C(x, y)))" - (Formula.str (Heuristic.expanded_description 5 - (Aux.strings_of_list ["B"; "W"]) - state (formula_of_str "C(x, y) and F(y)"))); - ); -(* "suggest_expansion: tic-tac-toe" >:: (fun () -> let state = struc_of_string @@ -401,8 +365,8 @@ (* A single substructure usually has exponentially many different descriptions. *) assert_bool "Should suggest not expanding tic-tac-toe." - (not (Heuristic.suggest_expansion - (formula_of_str winQxyz) state)); + (not (Heuristic.suggest_expansion state + (formula_of_str winQxyz))); ); "suggest_expansion: breakthrough" >:: @@ -430,8 +394,8 @@ (* A single substructure usually has exponentially many different descriptions. *) assert_bool "Should suggest expanding breakthrough." - (Heuristic.suggest_expansion - (formula_of_str "ex x (W(x) and not ex y C(x, y))") state); + (Heuristic.suggest_expansion state + (formula_of_str "ex x (W(x) and not ex y C(x, y))")); ); "suggest_expansion: gomoku8x8" >:: @@ -457,13 +421,50 @@ ... ... ... ... \"" in assert_bool "Should suggest not expanding gomoku." - (not (Heuristic.suggest_expansion - (formula_of_str winQvwxyz) state)); + (not (Heuristic.suggest_expansion state + (formula_of_str winQvwxyz))); ); -*) + ] +let bigtests = "HeuristicBig" >::: [ + "expanded_description: fenced breakthrough 2 vars" >:: + (fun () -> + let state = + struc_of_string +"[ | | ] \" + + F F F F F F F F + ... ... ... ... + B B..B B..B B..B B.. + ... ... ... ... + B..B B..B B..B B..B + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + ... ... ... ... + W W..W W..W W..W W.. + ... ... ... ... + W..W W..W W..W W..W + + F F F F F F F F +\"" in + assert_equal ~printer:(fun x->x) + "ex y7, y6, y5, y4, y3, y2, y1, y0 ((C(y7, y6) and C(y6, y5) and C(y5, y4) and C(y4, y3) and C(y3, y2) and C(y2, y1) and C(y1, y0) and C(y0, x) and C(x, y)))" + (Formula.str (Heuristic.expanded_description 5 + (Aux.strings_of_list ["B"; "W"]) + state (formula_of_str "C(x, y) and F(y)"))); + ); + +] + + let a = Aux.run_test_if_target "HeuristicTest" tests @@ -471,11 +472,11 @@ Aux.run_test_if_target "HeuristicTest" bigtests let a () = - DiscreteRule.debug_level := 5; - Heuristic.debug_level := 5 + DiscreteRule.debug_level := 0; + Heuristic.debug_level := 3 let a () = - match test_filter ["Heuristic:11:default_heuristic_old: connect5 of GDL translation"] + match test_filter ["Heuristic:10:default_heuristic_old: Connect4"] tests with | Some tests -> ignore (run_test_tt ~verbose:true tests) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-23 14:18:20
|
Revision: 1381 http://toss.svn.sourceforge.net/toss/?rev=1381&view=rev Author: lukaszkaiser Date: 2011-03-23 14:18:12 +0000 (Wed, 23 Mar 2011) Log Message: ----------- Branching-based monotonicity, some www cleanup. Modified Paths: -------------- trunk/Toss/GGP/Makefile trunk/Toss/Play/Heuristic.ml trunk/Toss/www/ideas.xml trunk/Toss/www/xsl/books.xsl trunk/Toss/www/xsl/main.xsl trunk/Toss/www/xsl/publications.xsl Added Paths: ----------- trunk/Toss/www/xsl/bibtex.xsl trunk/Toss/www/xsl/common.xsl trunk/Toss/www/xsl/layout-games.xsl trunk/Toss/www/xsl/layout.xsl Removed Paths: ------------- trunk/Toss/www/style.css trunk/Toss/www/xsl/include/ trunk/Toss/www/xsl/main.xsl~ trunk/Toss/www/xsl/publications-games-past.xsl Modified: trunk/Toss/GGP/Makefile =================================================================== --- trunk/Toss/GGP/Makefile 2011-03-23 13:00:03 UTC (rev 1380) +++ trunk/Toss/GGP/Makefile 2011-03-23 14:18:12 UTC (rev 1381) @@ -16,11 +16,13 @@ GDLTestDebug: %.black: examples/%.gdl ../TossServer + make -C .. OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -d 2 & java -jar gamecontroller-cli.jar play $< 600 10 1 -random 1 -remote 2 toss localhost 8110 1 | grep results killall -v TossServer %.white: examples/%.gdl ../TossServer + make -C .. OCAMLRUNPARAM=b; export OCAMLRUNPARAM; ../TossServer -d 2 & java -jar gamecontroller-cli.jar play $< 600 10 1 -random 2 -remote 1 toss localhost 8110 1 | grep results killall -v TossServer Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-23 13:00:03 UTC (rev 1380) +++ trunk/Toss/Play/Heuristic.ml 2011-03-23 14:18:12 UTC (rev 1381) @@ -1008,9 +1008,10 @@ Aux.Strings.union posi_poff_rels nega_poff_rels in let frels = Aux.Strings.union indef_frels (Aux.Strings.union posi_frels nega_frels) in - let monotonic = !use_monotonic && - Aux.Strings.is_empty - (Aux.Strings.inter all_poff_rels indef_frels) in + let moves = match struc with | None -> [||] | Some strc -> + Move.gen_moves Move.cGRID_SIZE rules strc graph.(0) in + let monotonic = !use_monotonic && (Array.length moves > 60 || + Aux.Strings.is_empty (Aux.Strings.inter all_poff_rels indef_frels)) in (* {{{ log entry *) if !debug_level > 1 then ( Printf.printf Modified: trunk/Toss/www/ideas.xml =================================================================== --- trunk/Toss/www/ideas.xml 2011-03-23 13:00:03 UTC (rev 1380) +++ trunk/Toss/www/ideas.xml 2011-03-23 14:18:12 UTC (rev 1381) @@ -85,7 +85,6 @@ project, but it can become very interesting in the last phase! <br/><br/></par> <par><em>Possible Mentors (in order of preference):</em> - Michał Wójcik, Tobias Ganzow, Łukasz Stafiniak, Łukasz Kaiser </par> </section> @@ -121,7 +120,7 @@ and to be able to use and debug them in parallel. <br/><br/></par> <par><em>Possible Mentors (in order of preference):</em> - Łukasz Kaiser, Tobias Ganzow, Łukasz Stafiniak + Łukasz Kaiser, Łukasz Stafiniak </par> </section> @@ -160,7 +159,7 @@ interface design is necessary, and a lot of testing to make it right. <br/><br/></par> <par><em>Possible Mentors (in order of preference):</em> - Dietmar Berwanger, Michał Wójcik, Diana Fischer + Łukasz Kaiser, Łukasz Stafiniak </par> </section> @@ -198,7 +197,7 @@ their optimization techniques or constraint solving will be helpful. <br/><br/></par> <par><em>Possible Mentors (in order of preference):</em> - Tobias Ganzow, Łukasz Kaiser, Łukasz Stafiniak + Łukasz Kaiser, Łukasz Stafiniak </par> </section> @@ -312,7 +311,7 @@ to hard, depending on how much effort one makes to adapt automatic play. <br/><br/></par> <par><em>Possible Mentors (in order of preference):</em> - Łukasz Kaiser, Dietmar Berwanger, Tobias Ganzow + Łukasz Kaiser </par> </section> Deleted: trunk/Toss/www/style.css =================================================================== --- trunk/Toss/www/style.css 2011-03-23 13:00:03 UTC (rev 1380) +++ trunk/Toss/www/style.css 2011-03-23 14:18:12 UTC (rev 1381) @@ -1,90 +0,0 @@ -/* General */ - -html { - height: 100%; -} - -body { - /* background-color: #222222; */ - /* height: 60%; */ - /* width: 90%; */ -} - -#top { - margin-left: 13%; - margin-right: 13%; - font-size: 4em; - font-family: Times, serif; - color: #787878; - font-weight: bold; - background-color: #ffffff; - padding: 5px; -} - -#tossi { - float: right; - margin-top: 0em; -} - -#bottom { - margin-left: 13%; - margin-right: 13%; - background-color: #ffffff; - text-align: right; - padding: 5px; - padding-top: 3em; -} - -#sidebar { - text-align: center; - margin-left: 13%; - margin-right: 13%; - border-width: 5px 0px 5px 0px; - border-color: #787878; - border-style: solid; - background-color: #ffffff; - padding: 10px 0px 10px 0px; -} - - -/* Content */ - -.main { - margin-left: 13%; - margin-right: 13%; - height: 100%; - background-color: #ffffff; - padding: 20px; -} - -.main h1 { - text-align: center; -} - -.main a, a:link, a:active, a:visited, a:hover { - color: #787878; /*#b2cde0;*/ -} - -.nav-sep { - background-color: #787878; - width: 5px; -} - -.iface { - border-width: 1px; - border-color: #787878; - border-style: solid -} - -#sidebar a { - font-size: 1.2em; - font-weight: bold; - color: #787878; - width: 100%; - margin: 1em; -} - -#sidebar a:hover { - text-decoration: none; - color: black; -} Copied: trunk/Toss/www/xsl/bibtex.xsl (from rev 1380, trunk/Toss/www/xsl/include/bibtex.xsl) =================================================================== --- trunk/Toss/www/xsl/bibtex.xsl (rev 0) +++ trunk/Toss/www/xsl/bibtex.xsl 2011-03-23 14:18:12 UTC (rev 1381) @@ -0,0 +1,461 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE xsl:stylesheet SYSTEM "xhtml1-lat1.ent"> + +<xsl:stylesheet version="1.0" + xmlns:bibtex="http://bibtexml.sf.net/" + xmlns="http://www.w3.org/1999/xhtml" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + +<xsl:strip-space elements="*"/> + +<xsl:template match="bibtex:file"> + <table class="bibtex-bibliography"> + <xsl:apply-templates select="*" mode="number"> + <xsl:sort select="@id" data-type="text"/> + </xsl:apply-templates> + </table> +</xsl:template> + +<xsl:template match="bibtex:file" mode="number"> + <table class="bibtex-bibliography"> + <xsl:apply-templates select="*" mode="number"> + <xsl:sort select="@id" data-type="text"/> + </xsl:apply-templates> + </table> +</xsl:template> + +<xsl:template match="bibtex:file" mode="id"> + <table class="bibtex-bibliography"> + <xsl:apply-templates select="*" mode="id"> + <xsl:sort select="@id" data-type="text"/> + </xsl:apply-templates> + </table> +</xsl:template> + +<xsl:template match="bibtex:entry"> + <xsl:param name="index"/> + <tr> + <td class="index"> + <xsl:text>[</xsl:text> + <xsl:value-of select="$index"/> + <xsl:text>]</xsl:text> + </td> + <td class="entry"> + <xsl:apply-templates select="*"/> + </td> + </tr> +</xsl:template> + +<xsl:template match="bibtex:entry" mode="number"> + <xsl:apply-templates select="."> + <xsl:with-param name="index" select="position()"/> + </xsl:apply-templates> +</xsl:template> + +<xsl:template match="bibtex:entry" mode="id"> + <xsl:apply-templates select="."> + <xsl:with-param name="index" select="@id"/> + </xsl:apply-templates> +</xsl:template> + +<xsl:template match="bibtex:book|bibtex:inbook|bibtex:booklet| + bibtex:proceedings| + bibtex:manual|bibtex:techreport| + bibtex:unpublished|bibtex:misc"> + <xsl:apply-templates select="bibtex:authors|bibtex:editors"/> + <xsl:text>. </xsl:text> + <xsl:apply-templates select="bibtex:title"> + <xsl:with-param name="type">book</xsl:with-param> + </xsl:apply-templates> + <xsl:if test="not(substring(bibtex:title, string-length(bibtex:title)) = '.' or substring(bibtex:title, string-length(bibtex:title)) = '!' or substring(bibtex:title, string-length(bibtex:title)) = '?')"> + <xsl:text>.</xsl:text> + </xsl:if> + <xsl:text> </xsl:text> + <xsl:if test="../bibtex:techreport"> + <xsl:text>Technical Report. </xsl:text> + </xsl:if> + <xsl:call-template name="publisher"/> +</xsl:template> + +<xsl:template match="bibtex:mastersthesis|bibtex:phdthesis"> + <xsl:apply-templates select="bibtex:authors"/> + <xsl:text>. </xsl:text> + <xsl:apply-templates select="bibtex:chapter"/> + <xsl:apply-templates select="bibtex:title"> + <xsl:with-param name="type">book</xsl:with-param> + </xsl:apply-templates> + <xsl:if test="not(substring(bibtex:title, string-length(bibtex:title)) = '.' or substring(bibtex:title, string-length(bibtex:title)) = '!' or substring(bibtex:title, string-length(bibtex:title)) = '?')"> + <xsl:text>.</xsl:text> + </xsl:if> + <xsl:text> </xsl:text> + <xsl:if test="../bibtex:phdthesis"> + <xsl:text>PhD thesis</xsl:text> + </xsl:if> + <xsl:if test="../bibtex:mastersthesis"> + <xsl:text>Master's thesis</xsl:text> + </xsl:if> + <xsl:if test="bibtex:school"> + <xsl:text>, </xsl:text> + <xsl:apply-templates select="bibtex:school"/> + </xsl:if> + <xsl:if test="bibtex:year"> + <xsl:text>, </xsl:text> + <xsl:apply-templates select="bibtex:year"/> + </xsl:if> + <xsl:text>.</xsl:text> + <xsl:if test="not(bibtex:year)"> + <xsl:text> </xsl:text> + <xsl:text>To appear.</xsl:text> + </xsl:if> +</xsl:template> + +<xsl:template match="bibtex:article"> + <xsl:apply-templates select="bibtex:authors"/> + <xsl:text>. </xsl:text> + <xsl:apply-templates select="bibtex:title"> + <xsl:with-param name="type">article</xsl:with-param> + </xsl:apply-templates> + <xsl:if test="not(substring(bibtex:title, string-length(bibtex:title)) = '.' or substring(bibtex:title, string-length(bibtex:title)) = '!' or substring(bibtex:title, string-length(bibtex:title)) = '?')"> + <xsl:text>.</xsl:text> + </xsl:if> + <xsl:text> </xsl:text> + <em> + <xsl:apply-templates select="bibtex:journal"/> + </em> + <!-- <xsl:apply-templates select="bibtex:editors"/> --> + <xsl:call-template name="journal-volume"/> + <!-- <xsl:apply-templates select="bibtex:series"/> --> + <xsl:apply-templates select="bibtex:pages"/> + <xsl:if test="bibtex:year"> + <xsl:text>, </xsl:text> + <xsl:apply-templates select="bibtex:year"/> + </xsl:if> + <xsl:text>.</xsl:text> + <xsl:if test="not(bibtex:year)"> + <!-- previously, 'To appear' would be output automagically; + changed this to output of the bibtex-field note --> + <xsl:if test="bibtex:note"> + <xsl:text> </xsl:text> + <xsl:apply-templates select="bibtex:note"/> + <!--<xsl:text>To appear.</xsl:text>--> + </xsl:if> + </xsl:if> +</xsl:template> + +<xsl:template match="bibtex:incollection"> + <xsl:apply-templates select="bibtex:authors"/> + <xsl:text>. </xsl:text> + <xsl:apply-templates select="bibtex:title"> + <xsl:with-param name="type">incollection</xsl:with-param> + </xsl:apply-templates> + <xsl:if test="not(substring(bibtex:title, string-length(bibtex:title)) = '.' or substring(bibtex:title, string-length(bibtex:title)) = '!' or substring(bibtex:title, string-length(bibtex:title)) = '?')"> + </xsl:if> + <xsl:if test="bibtex:booktitle"> + <xsl:text>. In </xsl:text> + <em> + <xsl:apply-templates select="bibtex:booktitle"/> + </em> + </xsl:if> + <xsl:apply-templates select="bibtex:editors"/> + <xsl:apply-templates select="bibtex:volume"/> + <xsl:apply-templates select="bibtex:series"/> + <xsl:apply-templates select="bibtex:pages"/> + <xsl:choose> + <xsl:when test="bibtex:year and not(bibtex:publisher|bibtex:howpublished|bibtex:institution)"> + <xsl:text>, </xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>. </xsl:text> + </xsl:otherwise> + </xsl:choose> + <xsl:call-template name="publisher"/> +</xsl:template> + +<xsl:template match="bibtex:inproceedings|bibtex:conference"> + <xsl:apply-templates select="bibtex:authors"/> + <xsl:text>. </xsl:text> + <xsl:apply-templates select="bibtex:title"> + <xsl:with-param name="type">inproceedings</xsl:with-param> + </xsl:apply-templates> + <xsl:if test="not(substring(bibtex:title, string-length(bibtex:title)) = '.' or substring(bibtex:title, string-length(bibtex:title)) = '!' or substring(bibtex:title, string-length(bibtex:title)) = '?')"> + <xsl:text>.</xsl:text> + </xsl:if> + <xsl:text> In </xsl:text> + <em> + <xsl:apply-templates select="bibtex:booktitle"/> + </em> + <xsl:apply-templates select="bibtex:editors"/> + <xsl:apply-templates select="bibtex:volume"/> + <xsl:apply-templates select="bibtex:series"/> + <xsl:apply-templates select="bibtex:pages"/> + <xsl:if test="bibtex:address"> + <xsl:text>, </xsl:text> + <xsl:apply-templates select="bibtex:address"/> + </xsl:if> + <xsl:choose> + <xsl:when test="bibtex:year and not(bibtex:publisher|bibtex:howpublished|bibtex:institution)"> + <xsl:text>, </xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>. </xsl:text> + </xsl:otherwise> + </xsl:choose> + <xsl:call-template name="publisherofproceedings" /> +</xsl:template> + + +<xsl:template match="bibtex:abstract|bibtex:url"/> + +<xsl:template match="bibtex:authors"> + <xsl:apply-templates/> +</xsl:template> + +<xsl:template match="bibtex:editors"> + <xsl:choose> + <xsl:when test="../bibtex:authors"> + <xsl:text> (</xsl:text> + <xsl:apply-templates /> + <xsl:text>, Ed</xsl:text> + <xsl:if test="count(bibtex:person)>1"><xsl:text>s</xsl:text></xsl:if> + <xsl:text>.)</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates /> + <xsl:text> (Ed</xsl:text> + <xsl:if test="count(bibtex:person)>1"><xsl:text>s</xsl:text></xsl:if> + <xsl:text>.)</xsl:text> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template match="bibtex:person"> + <!-- Special treatment for the last author --> + <xsl:choose> + <xsl:when test="position()=last() and bibtex:last='Others'"> + <xsl:text>et al.</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:if test="position()=last() and not(position()=1)"> + <xsl:text>and </xsl:text> + </xsl:if> + <xsl:apply-templates /> + </xsl:otherwise> + </xsl:choose> + + <!-- don't print a comma if there are only two authors and for the last author --> + <xsl:choose> + <xsl:when test="count(../bibtex:person)=2 and position()=1"> + <xsl:text> </xsl:text> + </xsl:when> + <xsl:when test="position()=last()"> + </xsl:when> + <xsl:otherwise> + <xsl:text>, </xsl:text> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template match="bibtex:person/bibtex:last|bibtex:person/bibtex:prelast"> + <xsl:apply-templates/> + <xsl:if test="not(position()=last())"> + <xsl:text> </xsl:text> + </xsl:if> +</xsl:template> + +<xsl:template match="bibtex:person/bibtex:first|bibtex:person/bibtex:middle"> + <xsl:value-of select="substring(.,1,1)"/> + <xsl:text>. </xsl:text> +</xsl:template> + +<xsl:template match="bibtex:title" name="title"> + <xsl:param name="type">article</xsl:param> + + <xsl:choose> + <xsl:when test="../bibtex:url"> + <xsl:variable name="url" select="../bibtex:url"/> + <a href="{$url}" class="bibtex-title {$type}"><xsl:apply-templates/></a> + </xsl:when> + <xsl:otherwise> + <span class="bibtex-title {$type}"><xsl:apply-templates/></span> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template name="journal-volume"> + <xsl:if test="bibtex:volume"> + <xsl:text>, vol. </xsl:text> + <xsl:value-of select="bibtex:volume"/> + <xsl:if test="bibtex:number"> + <xsl:text>(</xsl:text> + <xsl:apply-templates select="bibtex:number"/> + <xsl:text>)</xsl:text> + </xsl:if> + </xsl:if> +</xsl:template> + +<xsl:template match="bibtex:volume"> + <xsl:text>, vol. </xsl:text> + <xsl:value-of select="."/> + <xsl:text> of</xsl:text> +</xsl:template> + +<xsl:template match="bibtex:number"> + <xsl:apply-templates /> +</xsl:template> + +<xsl:template match="bibtex:doi|bibtex:isbn|bibtex:issn|bibtex:lccn"> + <xsl:text>, </xsl:text> + <xsl:value-of select='substring-after(name(.),"bibtex:")'/> + <xsl:text>:</xsl:text> + <xsl:apply-templates /> +</xsl:template> + +<xsl:template match="bibtex:year|bibtex:publisher| + bibtex:institution|bibtex:booktitle| + bibtex:organization|bibtex:journal| + bibtex:address|bibtex:school| + bibtex:howpublished"> + <xsl:value-of select="."/> +</xsl:template> + +<xsl:template match="bibtex:series"> + <xsl:if test="not(../bibtex:volume)"> + <xsl:text>,</xsl:text> + </xsl:if> + <xsl:text> </xsl:text> + <xsl:value-of select="."/> +</xsl:template> + +<xsl:template match="bibtex:pages"> + <xsl:text>, pp. </xsl:text> + <xsl:value-of select="."/> +</xsl:template> + +<xsl:template match="bibtex:chapter"> + <xsl:text>`</xsl:text> + <xsl:apply-templates /> + <xsl:text>' in </xsl:text> +</xsl:template> + +<xsl:template name="publisher"> + <xsl:if test="bibtex:publisher|bibtex:howpublished|bibtex:institution"> + <xsl:apply-templates select="bibtex:publisher|bibtex:howpublished|bibtex:institution"/> + <xsl:if test="bibtex:address"> + <xsl:text>, </xsl:text> + <xsl:apply-templates select="bibtex:address"/> + </xsl:if> + <xsl:choose> + <xsl:when test="bibtex:year"> + <xsl:text>, </xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>. </xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:if> + <xsl:choose> + <xsl:when test="bibtex:year"> + <xsl:apply-templates select="bibtex:year"/> + </xsl:when> + <xsl:otherwise> + <xsl:text>To appear</xsl:text> + </xsl:otherwise> + </xsl:choose> + <xsl:text>.</xsl:text> +</xsl:template> + +<xsl:template name="publisherofproceedings"> + <xsl:if test="bibtex:publisher|bibtex:howpublished|bibtex:institution"> + <xsl:apply-templates select="bibtex:publisher|bibtex:howpublished|bibtex:institution"/> + <xsl:choose> + <xsl:when test="bibtex:year"> + <xsl:text>, </xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>. </xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:if> + <xsl:choose> + <xsl:when test="bibtex:year"> + <xsl:apply-templates select="bibtex:year"/> + </xsl:when> + <xsl:otherwise> + <xsl:text>To appear</xsl:text> + </xsl:otherwise> + </xsl:choose> + <xsl:text>.</xsl:text> +</xsl:template> + +<xsl:template match="bibtex:abstract"> + <xsl:copy-of select="node()"/> +</xsl:template> + +<xsl:template match="bibtex:note"> + <xsl:copy-of select="node()"/> +</xsl:template> + + +<!-- Handling bibtex-output --> + +<xsl:template match="bibtex:entry" mode="bibtex"> + <xsl:apply-templates mode="bibtex"/> +</xsl:template> + +<xsl:template match="bibtex:entry/*/bibtex:abstract" mode="bibtex"/> + +<xsl:template match="bibtex:entry/bibtex:*" mode="bibtex"> + <xsl:text>@</xsl:text> + <xsl:value-of select='substring-after(name(),"bibtex:")'/> + <xsl:text>{</xsl:text> + <xsl:value-of select="../@id"/> + <xsl:text>,</xsl:text> + <br/> + <!-- <xsl:text>
</xsl:text> --> + <xsl:apply-templates mode="bibtex"/> + <xsl:text>}</xsl:text> + <br/> + <!-- <xsl:text>
</xsl:text> --> +</xsl:template> + +<xsl:template match="bibtex:entry/*/bibtex:authors" mode="bibtex"> + + <xsl:text>author = {</xsl:text> + <xsl:apply-templates mode="bibtex"/> + <xsl:text>},</xsl:text> + <br/> +</xsl:template> + +<xsl:template match="bibtex:entry/*/bibtex:editors" mode="bibtex"> + + <xsl:text>editor = {</xsl:text> + <xsl:apply-templates mode="bibtex"/> + <xsl:text>},</xsl:text> + <br/> +</xsl:template> + +<xsl:template match="bibtex:person" mode="bibtex"> + <xsl:apply-templates mode="bibtex"/> + <xsl:if test="not(position()=last())"> + <xsl:text> and </xsl:text> + </xsl:if> +</xsl:template> + +<xsl:template match="bibtex:person/*" mode="bibtex"> + <xsl:apply-templates mode="bibtex"/> + <xsl:if test="not(position()=last())"> + <xsl:text> </xsl:text> + </xsl:if> +</xsl:template> + +<!-- All other bibtex tags. --> +<xsl:template match="bibtex:entry/*/bibtex:*" mode="bibtex"> + + <xsl:value-of select='substring-after(name(),"bibtex:")'/> + <xsl:text> = {</xsl:text> + <xsl:apply-templates mode="bibtex"/> + <xsl:text>},</xsl:text> + <br/> +</xsl:template> + +</xsl:stylesheet> Modified: trunk/Toss/www/xsl/books.xsl =================================================================== --- trunk/Toss/www/xsl/books.xsl 2011-03-23 13:00:03 UTC (rev 1380) +++ trunk/Toss/www/xsl/books.xsl 2011-03-23 14:18:12 UTC (rev 1381) @@ -7,8 +7,8 @@ xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> -<xsl:include href="include/layout.xsl"/> -<xsl:include href="include/bibtex.xsl"/> +<xsl:include href="layout.xsl"/> +<xsl:include href="bibtex.xsl"/> <xsl:template match="books"> <xsl:apply-templates select="include"/> Copied: trunk/Toss/www/xsl/common.xsl (from rev 1380, trunk/Toss/www/xsl/include/common.xsl) =================================================================== --- trunk/Toss/www/xsl/common.xsl (rev 0) +++ trunk/Toss/www/xsl/common.xsl 2011-03-23 14:18:12 UTC (rev 1381) @@ -0,0 +1,235 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE xsl:stylesheet SYSTEM "xhtml1-lat1.ent"> + +<xsl:stylesheet + version='1.0' + xmlns:bibtex='http://bibtexml.sf.net/' + xmlns:xsl='http://www.w3.org/1999/XSL/Transform' + xmlns="http://www.w3.org/1999/xhtml"> + +<xsl:preserve-space elements="par item"/> + +<xsl:template match="html"> + <xsl:copy-of select="node()"/> +</xsl:template> + +<xsl:template match="section"> + <xsl:choose> + <xsl:when test="@id"> + <h3 id="{@id}"><xsl:value-of select="@title"/></h3> + </xsl:when> + <xsl:otherwise> + <h3><xsl:value-of select="@title"/></h3> + </xsl:otherwise> + </xsl:choose> + <xsl:apply-templates /> +</xsl:template> + +<xsl:template match="subsection"> + <h4><xsl:value-of select="@title"/></h4> + <xsl:apply-templates /> +</xsl:template> + +<xsl:template match="enumerate"> + <ol> + <xsl:apply-templates /> + </ol> +</xsl:template> + +<xsl:template match="itemize"> + <xsl:variable name="style-mod"> + <xsl:if test="@style='none'">list-style: none;</xsl:if> + <xsl:if test="@style='no-indent'">list-style: none; margin-left: 0px;</xsl:if> + </xsl:variable> + <ul style="{$style-mod}"> + <xsl:choose> + <xsl:when test="@type='sort'"> + <xsl:for-each select="item"> + <xsl:sort select="."/> + <li class="{@new}"><xsl:apply-templates /></li> + </xsl:for-each> + </xsl:when> + <xsl:when test="@type='sort-after-first-space'"> + <xsl:for-each select="item"> + <xsl:sort select="substring-after(., ' ')"/> + <li class="{@new}"><xsl:apply-templates /></li> + </xsl:for-each> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates /> + </xsl:otherwise> + </xsl:choose> + </ul> +</xsl:template> + +<xsl:template match="item"> + <li class="{@new}"><xsl:apply-templates /></li> +</xsl:template> + +<xsl:template match="games-section"> + <xsl:choose> + <xsl:when test="$lang='de'"> + <h3><a href="http://tplay.org">Online Spielen gegen Toss</a></h3> + <xsl:apply-templates /> + <p><a href="http://tplay.org">Weitere Spiele</a></p> + </xsl:when> + <xsl:when test="$lang='pl'"> + <h3><a href="http://tplay.org">Zagraj Online z Tossem</a></h3> + <xsl:apply-templates /> + <p><a href="http://tplay.org">Więcej gier</a></p> + </xsl:when> + <xsl:when test="$lang='fr'"> + <h3><a href="http://tplay.org">Jouez en Ligne contre Toss</a></h3> + <xsl:apply-templates /> + <p><a href="http://tplay.org">Plus de Jeux</a></p> + </xsl:when> + <xsl:otherwise> + <h3><a href="http://tplay.org">Play Online Against Toss</a></h3> + <xsl:apply-templates /> + <p><a href="http://tplay.org">More Games</a></p> + </xsl:otherwise> + </xsl:choose> + +</xsl:template> + +<xsl:template match="game-div"> + <div class="game-div"><xsl:apply-templates /></div> +</xsl:template> + +<xsl:template match="ggp-game"> + <a href="http://euklid.inf.tu-dresden.de:8180/ggpserver/public/view_state.jsp?matchID={@match_id}&stepNumber=1&seconds=1"><xsl:value-of select="@name" /></a> + (<xsl:value-of select="@match_id" />) +</xsl:template> + +<xsl:template match="em"> + <em><xsl:apply-templates /></em> +</xsl:template> + +<xsl:template match="strong"> + <strong><xsl:apply-templates /></strong> +</xsl:template> + +<xsl:template match="br"> + <br/> +</xsl:template> + + +<xsl:template match="lecture-title"> + + <xsl:variable name="index" select="count(../preceding-sibling::*)"/> <!-- position() of the parent (ie of /item)--> + + <xsl:choose> + <xsl:when test="link/@inactive"> + <xsl:apply-templates /> + </xsl:when> + <xsl:otherwise> + <xsl:choose> + <xsl:when test="title[@lang='de']"> + <a href="{link}" ><xsl:value-of select="title[@lang='de']"/><!-- link to the lecture page--></a> + <xsl:if test="./grade"> <!-- If there are evaluation data--> + <span style="margin-left: 2em"> </span> + <a href="#" onclick="{concat('show_lecture_title(',$index , ')')}; return false;" rel="nofollow" class="evaluation"> <!-- call show_lecture($index) from main.js which changes the attribute 'display' of span with id='lecture_title$index'--> + Studentische Bewertung + </a> + <span style="display: none; margin-left: 2em; font-size: 90%" id="{concat('lecture_title', $index)}"><!---->Vorlesung: + <xsl:value-of select="grade[@tograde='lecture' and @part='int']"></xsl:value-of>,<xsl:value-of select="grade[@tograde='lecture' and @part='frac']"></xsl:value-of> + <span style="margin-left: 1em">Dozent: </span> + <xsl:value-of select="grade[@tograde='docent' and @part='int']"></xsl:value-of>,<xsl:value-of select="grade[@tograde='docent' and @part='frac']"></xsl:value-of> + </span> + </xsl:if> + </xsl:when> + <xsl:when test="title[@lang='en']"> + <a href="{link}" ><xsl:value-of select="title[@lang='en']"/></a> + <xsl:if test="./grade"> <!-- If there are evaluation data--> + <span style="margin-left: 2em"> </span> + <a href="#" onclick="{concat('show_lecture_title(',$index , ')')}; return false;" rel="nofollow" class="evaluation"> + Students' Evaluation + </a> + <span style="display: none; margin-left: 2em; font-size: 90%" id="{concat('lecture_title', $index)}">lecture: + <xsl:value-of select="grade[@tograde='lecture' and @part='int']"></xsl:value-of>.<xsl:value-of select="grade[@tograde='lecture' and @part='frac']"></xsl:value-of> + <span style="margin-left: 1em">docent: </span> + <xsl:value-of select="grade[@tograde='docent' and @part='int']"></xsl:value-of>.<xsl:value-of select="grade[@tograde='docent' and @part='frac']"></xsl:value-of> + </span> + </xsl:if> + </xsl:when> + </xsl:choose> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + + +<xsl:template match="a"> + <xsl:choose> + <xsl:when test="@inactive"> + <xsl:apply-templates /> + </xsl:when> + <xsl:otherwise> + <a href="{@href}"><xsl:apply-templates /></a> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template match="quote"> + <blockquote><xsl:apply-templates /></blockquote> +</xsl:template> + +<xsl:template match="image"> + <div class="image"> + <img src="{$topdir}/img/{@src}" alt="{@title}"/> + </div> +</xsl:template> + +<xsl:template match="game-link"> + <xsl:choose> + <xsl:when test="$lang='de'"> + <a href="http://tplay.org/index.html?game={@game}" + title="Spiel {@game}" class="game-link" id="game-link-{@game}"> + <img class="game-img" src="{$topdir}/img/{@game}.png" + alt="{@game}-Brett" id="game-img-{@game}" /> + </a> + </xsl:when> + <xsl:when test="$lang='pl'"> + <a href="http://tplay.org/index.html?game={@game}" + title="Graj w {@game}" class="game-link" id="game-link-{@game}"> + <img class="game-img" src="{$topdir}/img/{@game}.png" + alt="Plansza {@game}" id="game-img-{@game}" /> + </a> + </xsl:when> + <xsl:when test="$lang='fr'"> + <a href="http://tplay.org/index.html?game={@game}" + title="Jouez au {@game}" class="game-link" id="game-link-{@game}"> + <img class="game-img" src="{$topdir}/img/{@game}.png" + alt="Bord de {@game}" id="game-img-{@game}" /> + </a> + </xsl:when> + <xsl:otherwise> + <a href="http://tplay.org/index.html?game={@game}" + title="Play {@game}" class="game-link" id="game-link-{@game}"> + <img class="game-img" src="{$topdir}/img/{@game}.png" + alt="{@game} Board" id="game-img-{@game}" /> + </a> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template match="flag"> + <img src="/img/flags/{@country}.gif" alt="{@country}"/> + +</xsl:template> + +<xsl:template name="mail"> + <xsl:param name="user"/> + <xsl:param name="domain"/> + <xsl:param name="title" select="''"/> + + <xsl:choose> + <xsl:when test="$title"> + <script type="text/javascript">begin_mailto("<xsl:value-of select="$user"/>", "<xsl:value-of select="$domain"/>", "true");</script><xsl:value-of select="$title"/><script type="text/javascript">end_mailto();</script> + </xsl:when> + <xsl:otherwise> + <script type="text/javascript">begin_mailto("<xsl:value-of select="$user"/>", "<xsl:value-of select="$domain"/>");</script><xsl:value-of select="$user"/> [AT] <xsl:value-of select="$domain"/><script type="text/javascript">end_mailto();</script> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +</xsl:stylesheet> Copied: trunk/Toss/www/xsl/layout-games.xsl (from rev 1380, trunk/Toss/www/xsl/include/layout-games.xsl) =================================================================== --- trunk/Toss/www/xsl/layout-games.xsl (rev 0) +++ trunk/Toss/www/xsl/layout-games.xsl 2011-03-23 14:18:12 UTC (rev 1381) @@ -0,0 +1,210 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE xsl:stylesheet SYSTEM "xhtml1-lat1.ent"> + +<xsl:stylesheet + version='1.0' + xmlns:bibtex='http://bibtexml.sf.net/' + xmlns:xsl='http://www.w3.org/1999/XSL/Transform' + xmlns="http://www.w3.org/1999/xhtml"> + +<xsl:output + method="xml" version="1.0" + media-type="text/xml" + omit-xml-declaration = "yes" + doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" + doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" + indent="yes" + encoding="UTF-8"/> + + +<!-- do not output processing instructions --> +<xsl:template match="processing-instruction()"/> + + +<xsl:template match="/"> + <!-- XHTML-output --> + <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> + <link rel="stylesheet" type="text/css" href="/styles/common.css" media="all"/> + <link rel="stylesheet" type="text/css" href="/styles/screen.css" media="screen"/> + <link rel="stylesheet" type="text/css" href="/styles/print.css" media="print"/> + <link rel="shortcut icon" href="/img/favicon-games.ico"/> + + <!-- check whether a title is given in xml file, use parameter otherwise --> + <xsl:choose> + <xsl:when test="/*/title/@html"> + <title>GAMES - <xsl:value-of select="/*/title/@html"/></title> + </xsl:when> + <xsl:when test="/*/title"> + <title>GAMES - <xsl:value-of select="/*/title"/></title> + </xsl:when> + <xsl:otherwise> + <title>GAMES - <xsl:value-of select="$title"/></title> + </xsl:otherwise> + </xsl:choose> + + <script src="/scripts/main.js" type="text/javascript"/> + </head> + <body onload="gload()" onunload="gunload()"> + <div id="page"> + <div id="header"> + <div id="headerlogo"> + <a href="/"><div id="games-logo"></div></a> + </div> + <a href="http://www.esf.org/"><div id="esf-logo"></div></a> + <!-- <xsl:call-template name="navigation"/> --> + </div> + + <div id="container" class="with-sidebar"> + <div id="primary"> + <div id="content"> + <xsl:apply-templates/> + </div> + </div> + <div id="secondary"> + <div id="sidebar"> + <xsl:call-template name="navigation"/> + </div> + </div> + </div> + </div> + <div id="footer"> + © <xsl:value-of select="$year"/> <a href="http://www.logic.rwth-aachen.de">Mathematische Grundlagen der Informatik</a>, RWTH Aachen + (<a id="disclaimer" href="http://www.rwth-aachen.de/disclaimer">Disclaimer</a>) + </div> + </body> + </html> +</xsl:template> + +<xsl:template name="navigation"> + <div class="childnav" id="menu"> + <div class="childnav-top"></div> + <xsl:call-template name="menu"> + <xsl:with-param name="document" select="/"/> + <xsl:with-param name="menu" select="document('../../Games/navigation.xml')/navigation/menu"/> + </xsl:call-template> + </div> +</xsl:template> + +<xsl:template name="menu"> + <xsl:param name="document"/> + <xsl:param name="menu"/> + <xsl:param name="level" select="'top'"/> + + <ul> + <xsl:for-each select="$menu/*"> + <xsl:variable name="id"> + <xsl:value-of select="@id"/> + </xsl:variable> + <xsl:variable name="selected"> + <xsl:for-each select="$document/*/history/*"> + <xsl:if test="$id=@id">selected</xsl:if> + </xsl:for-each> + </xsl:variable> + <xsl:variable name="menu-title"> + <xsl:for-each select="$document/*/history/*"> + <xsl:if test="$id=@id">menu-title</xsl:if> + </xsl:for-each> + </xsl:variable> + <xsl:choose> + <xsl:when test="name()='item'"> + <li class="{$selected}"> + <xsl:choose> + <xsl:when test="@href"> + <a href="{@href}" class="menu-{$level}"><xsl:value-of select="."/><xsl:copy-of select="*"/></a> + </xsl:when> + <xsl:otherwise> + <span class="menu-{$level}"><xsl:value-of select="."/><xsl:copy-of select="*"/></span> + </xsl:otherwise> + </xsl:choose> + </li> + </xsl:when> + <xsl:when test="name()='menu'"> + <li class="{$selected}"> + <xsl:choose> + <xsl:when test="@href"> + <!-- + <xsl:choose> + <xsl:when test="@id='Authors'"> + <xsl:if test="$document/*/history/*[@id='PastPublications']"> + <a href="{@href}" class="{$menu-title} menu-{$level}"><xsl:value-of select="@title"/></a> + </xsl:if> + </xsl:when> + <xsl:otherwise> + --> + <a href="{@href}" class="{$menu-title} menu-{$level}"><xsl:value-of select="@title"/></a> + <!-- + </xsl:otherwise> + </xsl:choose> + --> + </xsl:when> + <xsl:otherwise> + <span class="{$menu-title} menu-{$level}"><xsl:value-of select="@title"/></span> + </xsl:otherwise> + </xsl:choose> + <!-- + <xsl:choose> + <xsl:when test="@id='Authors'"> + <xsl:if test="contains($selected, 'selected')"> + <xsl:if test="$document/*/history/*[@id='AuthorMenu']"> + <xsl:call-template name="author-menu-prevgames"/> + </xsl:if> + </xsl:if> + </xsl:when> + <xsl:otherwise> + --> + <xsl:choose> + <xsl:when test="contains($level, 'sub')"> + <xsl:call-template name="menu"> + <xsl:with-param name="document" select="$document"/> + <xsl:with-param name="menu" select="."/> + <xsl:with-param name="level" select="concat('sub',$level)"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="menu"> + <xsl:with-param name="document" select="$document"/> + <xsl:with-param name="menu" select="."/> + <xsl:with-param name="level" select="'sub'"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + <!-- + </xsl:otherwise> + </xsl:choose> + --> + </li> + </xsl:when> + </xsl:choose> + </xsl:for-each> + </ul> +</xsl:template> + + +<xsl:template name="author-menu-prevgames"> + <ul> + <li> + <ul> + <xsl:for-each select="document('../../Games/History/PastPublications/people.xml')/people/person[@type='researcher']"> + <xsl:sort select="@id"/> + <li class="item-prevgames-author"> + <a href="/History/PastPublications/{@id}.html" class="menu-sub"><xsl:value-of select="normalize-space(concat(first,' ',middle,' ',prelast,' ',last))"/></a> + </li> + </xsl:for-each> + + <xsl:for-each select="document('../../Games/History/PastPublications/people.xml')/people/person[@type='young']"> + <xsl:sort select="@id"/> + <xsl:variable name="author" select="last"/> + <xsl:if test="document('../../Games/History/PastPublications/all.xml')/bibtex:file/bibtex:entry/*/*/bibtex:person[bibtex:last=$author]"> + <li class="item-prevgames-author"> + <a href="/History/PastPublications/{@id}.html" class="menu-sub"><xsl:value-of select="normalize-space(concat(first,' ',middle,' ',prelast,' ',last))"/></a> + </li> + </xsl:if> + </xsl:for-each> + </ul> + </li> + </ul> +</xsl:template> + +</xsl:stylesheet> Copied: trunk/Toss/www/xsl/layout.xsl (from rev 1380, trunk/Toss/www/xsl/include/layout.xsl) =================================================================== --- trunk/Toss/www/xsl/layout.xsl (rev 0) +++ trunk/Toss/www/xsl/layout.xsl 2011-03-23 14:18:12 UTC (rev 1381) @@ -0,0 +1,335 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE xsl:stylesheet SYSTEM "xhtml1-lat1.ent"> + +<xsl:stylesheet + version='1.0' + xmlns:bibtex='http://bibtexml.sf.net/' + xmlns:xsl='http://www.w3.org/1999/XSL/Transform' + xmlns="http://www.w3.org/1999/xhtml"> + +<xsl:output + method="xml" version="1.0" + media-type="text/xml" + omit-xml-declaration = "yes" + doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" + doctype-system="http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd" + indent="yes" + encoding="UTF-8"/> + + +<!-- do not output processing instructions --> +<xsl:template match="processing-instruction()"/> + + +<xsl:template match="/"> + <!-- XHTML-output --> + <html xmlns='http://www.w3.org/1999/xhtml' + xmlns:dc='http://purl.org/dc/elements/1.1/' + xmlns:foaf='http://xmlns.com/foaf/0.1/' + xml:lang="{$lang}" + lang="{$lang}"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> + <link rel="stylesheet" type="text/css" href="{$topdir}/styles/common.css" media="all"/> + <link rel="stylesheet" type="text/css" href="{$topdir}/styles/screen.css" media="screen"/> + <link rel="stylesheet" type="text/css" href="{$topdir}/styles/print.css" media="print"/> + <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Ubuntu:regular,bold"/> + <link rel="shortcut icon" href="{$topdir}/img/favicon.ico"/> + + <!-- check whether a title is given in xml file, use parameter otherwise --> + <xsl:choose> + <xsl:when test="/*/title/@html"> + <title><xsl:value-of select="/*/title/@html"/></title> + </xsl:when> + <xsl:when test="/*/title/@nomgi"> + <title><xsl:value-of select="/*/title"/></title> + </xsl:when> + <xsl:when test="/*/title"> + <title><xsl:value-of select="/*/title"/></title> + </xsl:when> + <!-- if title is "Publications" check whether author is given --> + <xsl:when test="$title='Publications' and $author='all'"> + <xsl:if test="$lang='de'"> + <title>Publikationen</title> + </xsl:if> + <xsl:if test="$lang='en'"> + <title>Publications</title> + </xsl:if> + <xsl:if test="$lang='pl'"> + <title>Publikacje</title> + </xsl:if> + <xsl:if test="$lang='fr'"> + <title>Publications</title> + </xsl:if> + </xsl:when> + <xsl:when test="$title='Publications' and $author!='all'"> + <xsl:variable name="fullname" select="normalize-space(concat(document('../people.xml')/people/person[@id=$author]/first,' ',document('../people.xml')/people/person[@id=$author]/last))"/> + <xsl:if test="$lang='de'"> + <title>Publikationen: <xsl:value-of select="$fullname"/></title> + </xsl:if> + <xsl:if test="$lang='en'"> + <title>Publications: <xsl:value-of select="$fullname"/></title> + </xsl:if> + <xsl:if test="$lang='pl'"> + <title>Publikacje: <xsl:value-of select="$fullname"/></title> + </xsl:if> + <xsl:if test="$lang='fr'"> + <title>Publications de <xsl:value-of select="$fullname"/></title> + </xsl:if> + </xsl:when> + <xsl:otherwise> + <title><xsl:value-of select="$title"/></title> + </xsl:otherwise> + </xsl:choose> + + <xsl:choose> + <xsl:when test="//googlemap"> + <script src="{$topdir}/scripts/map.js" type="text/javascript"/> + </xsl:when> + <xsl:otherwise> + <script src="{$topdir}/scripts/nomap.js" type="text/javascript"/> + </xsl:otherwise> + </xsl:choose> + <script src="{$topdir}/scripts/main.js" type="text/javascript"/> + <!-- <script src="{$topdir}/scripts/portal.js" type="text/javascript"/> --> + </head> + <body onload="gload()" onunload="gunload()"> + <div id="page"> + <div id="header"> + <div id="headerlogo"> + <a href="http://toss.sourceforge.net" id="logo"></a> + <div id="mgi-title"> + <xsl:choose> + <xsl:when test="$lang='de'"> + <h3></h3> <!-- no title for now --> + </xsl:when> + <xsl:otherwise> + <h3></h3> <!-- no title for now --> + </xsl:otherwise> + </xsl:choose> + </div> + </div> + <a href="http://toss.sourceforge.net" id="left-logo">Toss</a> + <xsl:call-template name="langselect"/> + </div> + + <div id="container" class="with-sidebar"> + <div id="primary"> + <div id="content"> + <xsl:apply-templates/> + </div> + </div> + <div id="secondary"> + <div id="sidebar"> + <xsl:call-template name="navigation"/> + </div> + </div> + </div> + </div> + + <div id="footer"> + © <xsl:value-of select="$year"/> Toss Team + </div> + </body> + </html> +</xsl:template> + +<xsl:template name="langselect"> + <div id="parentnav"> + <ul> + <xsl:if test="$lang='de'"> + <li class="selected"><span>Deutsch</span></li> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.en')}">English</a> + </li> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.fr')}">Français</a> + </li> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.pl')}">Polski</a> + </li> + </xsl:if> + <xsl:if test="$lang='en'"> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.de')}">Deutsch</a> + </li> + <li class="selected"><span>English</span></li> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.fr')}">Français</a> + </li> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.pl')}">Polski</a> + </li> + </xsl:if> + <xsl:if test="$lang='pl'"> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.de')}">Deutsch</a> + </li> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.en')}">English</a> + </li> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.fr')}">Français</a> + </li> + <li class="selected"><span>Polski</span></li> + </xsl:if> + <xsl:if test="$lang='fr'"> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.de')}">Deutsch</a> + </li> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.en')}">English</a> + </li> + <li class="selected"><span>Français</span></li> + <li> + <a href="{concat(substring-before($uri,'.'),'.html.pl')}">Polski</a> + </li> + </xsl:if> + </ul> + </div> +</xsl:template> + +<xsl:template name="navigation"> + <div class="childnav" id="menu"> + <div class="childnav-top"></div> + <xsl:call-template name="menu"> + <xsl:with-param name="document" select="/"/> + <xsl:with-param name="menu" select="document('../navigation.xml')/navigation/menu[contains(@lang,$lang)]"/> + </xsl:call-template> + </div> +</xsl:template> + +<xsl:template name="menu"> + <xsl:param name="document"/> + <xsl:param name="menu"/> + <xsl:param name="level" select="'top'"/> + + <ul> + <xsl:for-each select="$menu/*"> + <xsl:variable name="id"> + <xsl:value-of select="@id"/> + </xsl:variable> + <xsl:variable name="selected"> + <xsl:for-each select="$document/*/history/*"> + <xsl:if test="$id=@id">selected</xsl:if> + </xsl:for-each> + </xsl:variable> + <xsl:choose> + <xsl:when test="name()='item'"> + <li class="{$selected}"> + <xsl:choose> + <xsl:when test="@href"> + <a href="{@href}" class="menu-{$level}"><xsl:value-of select="."/><xsl:copy-of select="*"/></a> + </xsl:when> + <xsl:otherwise> + <span class="menu-{$level}"><xsl:value-of select="."/><xsl:copy-of select="*"/></span> + </xsl:otherwise> + </xsl:choose> + </li> + </xsl:when> + <xsl:when test="name()='menu'"> + <li class="{$selected}"> + <xsl:choose> + <xsl:when test="@href"> + <a href="{@href}" class="menu-title menu-{$level}"><xsl:value-of select="@title"/></a> + </xsl:when> + <xsl:otherwise> + <span class="menu-title menu-{$level}"><xsl:value-of select="@title"/></span> + </xsl:otherwise> + </xsl:choose> + <xsl:choose> + <xsl:when test="@id='Publications'"> + <xsl:call-template name="author-menu"/> + </xsl:when> + <xsl:when test="@id='People'"> + <xsl:call-template name="people-menu"/> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="menu"> + <xsl:with-param name="document" select="$document"/> + <xsl:with-param name="menu" select="."/> + <xsl:with-param name="level" select="'sub'"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> + </li> + </xsl:when> + </xsl:choose> + </xsl:for-each> + </ul> +</xsl:template> + +<xsl:template name="people-menu"> + <ul> + <xsl:for-each select="document('../people.xml')/people/person[@type='prof']"> + <xsl:variable name="fullname" select="normalize-space(concat(first,' ',last))"/> + <xsl:if test="homepage and not(homepage='')"> + <li> + <a href="{homepage}"><xsl:value-of select="$fullname"/></a> + </li> + </xsl:if> + </xsl:for-each> + <xsl:for-each select="document('../people.xml')/people/person[@type='assistant']"> + <xsl:sort select="@id"/> + + <xsl:variable name="fullname" select="normalize-space(concat(first,' ',last))"/> + <xsl:if test="homepage and not(homepage='')"> + <li> + <a href="{homepage}"><xsl:value-of select="$fullname"/></a> + </li> + </xsl:if> + </xsl:for-each> + </ul> +</xsl:template> + +<xsl:template name="author-menu"> + <ul> + <li> + <xsl:if test="$lang='en'"> + <span class="menu-title menu-sub">Current Members</span> + </xsl:if> + <xsl:if test="$lang='de'"> + <span class="menu-title menu-sub">Aktuelle Mitarbeiter</span> + </xsl:if> + <ul> + <xsl:for-each select="document('../people.xml')/people/person[@type='prof']"> + <li> + <a href="{$topdir}/Publications/{@id}.html.{$lang}" class="menu-sub"><xsl:value-of select="normalize-space(concat(first,' ',last))"/></a> + </li> + </xsl:for-each> + <xsl:for-each select="document('../people.xml')/people/person[@type='assistant']"> + <xsl:sort select="@id"/> + + <xsl:variable name="author" select="last"/> + <xsl:if test="document('../Publications/all.xml')/bibtex:file/bibtex:entry/*/*/bibtex:person[bibtex:last=$author]"> + <li> + <a href="{$topdir}/Publications/{@id}.html.{$lang}" class="menu-sub"><xsl:value-of select="normalize-space(concat(first,' ',last))"/></a> + </li> + </xsl:if> + </xsl:for-each> + </ul> + </li> + <li> + <xsl:if test="$lang='en'"> + <span class="menu-title menu-sub">Former Members</span> + </xsl:if> + <xsl:if test="$lang='de'"> + <span class="menu-title menu-sub">Ehemalige Mitarbeiter</span> + </xsl:if> + <ul> + <xsl:for-each select="document('../people.xml')/people/person[@type='former-member']"> + <xsl:sort select="@id"/> + + <xsl:variable name="author" select="last"/> + <xsl:if test="document('../Publications/all.xml')/bibtex:file/bibtex:entry/*/*/bibtex:person[bibtex:last=$author]"> + <li> + <a href="{$topdir}/Publications/{@id}.html.{$lang}" class="menu-sub"><xsl:value-of select="normalize-space(concat(first,' ',last))"/></a> + </li> + </xsl:if> + </xsl:for-each> + </ul> + </li> + </ul> +</xsl:template> + +</xsl:stylesheet> Modified: trunk/Toss/www/xsl/main.xsl =================================================================== --- trunk/Toss/www/xsl/main.xsl 2011-03-23 13:00:03 UTC (rev 1380) +++ trunk/Toss/www/xsl/main.xsl 2011-03-23 14:18:12 UTC (rev 1381) @@ -8,9 +8,9 @@ xmlns="http://www.w3.org/1999/xhtml"> -<xsl:include href="include/layout.xsl"/> -<xsl:include href="include/common.xsl"/> -<xsl:include href="include/bibtex.xsl"/> +<xsl:include href="layout.xsl"/> +<xsl:include href="common.xsl"/> +<xsl:include href="bibtex.xsl"/> <xsl:template match="page"> <div class="title"> Deleted: trunk/Toss/www/xsl/main.xsl~ =================================================================== --- trunk/Toss/www/xsl/main.xsl~ 2011-03-23 13:00:03 UTC (rev 1380) +++ trunk/Toss/www/xsl/main.xsl~ 2011-03-23 14:18:12 UTC (rev 1381) @@ -1,953 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE xsl:stylesheet SYSTEM "xhtml1-lat1.ent"> - -<xsl:stylesheet - version='1.0' - xmlns:bibtex='http://bibtexml.sf.net/' - xmlns:xsl='http://www.w3.org/1999/XSL/Transform' - xmlns="http://www.w3.org/1999/xhtml"> - - -<xsl:include href="include/layout.xsl"/> -<xsl:include href="include/common.xsl"/> -<xsl:include href="include/bibtex.xsl"/> - -<xsl:template match="page"> - <div class="title"> - <h1 property="dc:title"><xsl:value-of select="title"/></h1> - <xsl:if test="subtitle"> - <h2><xsl:value-of select="subtitle"/></h2> - </xsl:if> - </div> - <!-- - <xsl:apply-templates select="news"/> - <xsl:apply-templates select="section|people"/> - --> - <xsl:apply-templates select="news|section|list-of-people|FMTpeople"/> - <xsl:apply-templates select="contact"/> -</xsl:template> - -<xsl:template match="course|seminar"> - <div class="title"> - <h1 property="dc:title"><xsl:value-of select="title"/></h1> - <h2><xsl:value-of select="semester|subtitle"/></h2> -<!-- - <xsl:if test="$lang='en'"> - <p><em>The content on this page is partially available in German only.</em></p> - </xsl:if> ---> - </div> - -<!-- - <xsl:apply-templates select="news"/> - <xsl:apply-templates select="schedule"/> - <xsl:apply-templates select="documents"/> - <xsl:apply-templates select="deadlines"/> - <xsl:apply-templates select="topics"/> - <xsl:apply-templates select="content"/> - <xsl:apply-templates select="literature"/> - <xsl:apply-templates select="classification"/> - <xsl:apply-templates select="prerequisites"/> - <xsl:apply-templates select="query"/> ---> - <xsl:apply-templates select="news|schedule|portal-login|documents|deadlines|topics|content|literature|classification|prerequisites|query|contact|section|recurrence|assessment|following"/> -</xsl:template> - - -<xsl:template match="news"> - <xsl:if test="$lang='de'"> - <h3>Aktuelles</h3> - </xsl:if> - <xsl:if test="$lang='en'"> - <h3>News</h3> - </xsl:if> - <xsl:choose> - <xsl:when test="item"> - <ul><xsl:apply-templates/></ul> - </xsl:when> - <xsl:otherwise> - <xsl:apply-templates /> - </xsl:otherwise> - </xsl:choose> -</xsl:template> - - -<xsl:template match="schedule"> - <xsl:if test="name(..)='course'"> - <xsl:if test="$lang='de'"> - <h3>Termine</h3> - </xsl:if> - <xsl:if test="$lang='en'"> - <h3>Schedule</h3> - </xsl:if> - <table class="showgrid"> - <thead> - <tr> - <th>Art</th> - <th colspan="4">Termin</th> - <th>Ort</th> - <th> </th> - <th>Veranstalter</th> - </tr> - </thead> - <tbody> - <xsl:apply-templates select="lecture"/> - <xsl:apply-templates select="exercise"/> - <xsl:apply-templates select="tutorial"/> - </tbody> - </table> - </xsl:if> - - <xsl:if test="name(..)='seminar'"> - <xsl:if test="$lang='de'"> - <h3>Programm</h3> - </xsl:if> - <xsl:if test="$lang='en'"> - <h3>Schedule</h3> - </xsl:if> - <table class="seminar-schedule"> - <tbody> - <xsl:for-each select="day"> - <tr><td colspan="5" class="heading"><strong><xsl:value-of select="@date"/></strong></td></tr> - <xsl:for-each select="talk"> - <xsl:choose> - <xsl:when test="@type='break'"> - <tr class="separator"> - <xsl:apply-templates select="."/> - </tr> - </xsl:when> - <xsl:otherwise> - <tr> - <xsl:apply-templates select="."/> - </tr> - </xsl:otherwise> - </xsl:choose> - </xsl:for-each> - </xsl:for-each> - </tbody> - </table> - </xsl:if> -</xsl:template> - -<xsl:template match="talk"> - <td><xsl:value-of select="begin"/></td> - <td>–</td> - <td><xsl:value-of select="end"/></td> - - <xsl:choose> - <xsl:when test="speaker"> - <td><xsl:value-of select="speaker"/></td> - <td><xsl:value-of select="topic"/></td> - </xsl:when> - <xsl:otherwise> - <xsl:variable name="id" select="topicid"/> - <td><xsl:value-of select="../../../topics/topic[@id=$id]/student"/></td> - <td><xsl:value-of select="../../../topics/topic[@id=$id]/title"/></td> - </xsl:otherwise> - </xsl:choose> -</xsl:template> - - -<xsl:template match="lecture|exercise|tutorial"> - <tr> - <xsl:variable name="type" select="name()"/> - <xsl:if test="not(preceding-sibling::*[name()=$type])"> - <xsl:variable name="number" select="count(../*[name()=$type])"/> - <xsl:variable name="amount" select="sum(../*[name()=$type]/@amount)"/> - <td rowspan="{$number}"> - <xsl:if test="name(.)='lecture'">V</xsl:if> - <xsl:if test="name(.)='exercise' or name(.)='tutorial'">Ü</xsl:if> - <xsl:if test="name(.)='lecture' or name(.)='exercise'"> - <xsl:value-of select="$amount"/> - </xsl:if> - <xsl:if test="name(.)='tutorial'"> - <xsl:value-of select="@amount"/> - </xsl:if> - </td> - </xsl:if> - <!-- <td class="datetime {datetime/@changed}"><xsl:copy-of select="datetime/*"/></td>--> - <!-- <td class="datetime {datetime/@changed}"><xsl:apply-templates select="datetime"/></td>--> - <xsl:apply-templates select="datetime"/> - <td class="{hall/@changed}"><xsl:value-of select="hall"/></td> - <td><xsl:value-of select="info"/></td> - <td><xsl:value-of select="lecturer"/></td> - </tr> -</xsl:template> - - -<xsl:template match="datetime"> - <xsl:choose> - <xsl:when test="dow"> - <!-- <span><xsl:value-of select="dow"/></span> - <span><xsl:value-of select="begin"/></span> - <span>–</span> - <span><xsl:value-of select="end"/></span> - <span> </span>--> - <td class="dow"><xsl:value-of select="dow"/></td> - <td><xsl:value-of select="begin"/></td> - <td>–</td> - <td><xsl:value-of select="end"/></td> - </xsl:when> - <xsl:otherwise> - <td class="datetime" colspan="4"><xsl:value-of select="."/></td> - </xsl:otherwise> - </xsl:choose> -</xsl:template> - - -<!-- -<xsl:template match="datetime|hall|info|lecturer"> - <xsl:choose> - <xsl:when test="@changed"> - <td ></td> - </xsl:if> - - </xsl:choose> -</xsl:template> ---> - -<xsl:template match="deadlines"> - <xsl:if test="$lang='de'"> - <h3>Zeitplan</h3> - </xsl:if> - <xsl:if test="$lang='en'"> - <h3>Deadlines</h3> - </xsl:if> - - <table class="showgrid"> - <tbody> - <xsl:apply-templates/> - </tbody> - </table> -</xsl:template> - - -<xsl:template match="deadline"> - <tr> - <td><xsl:value-of select="@date"/></td> - <td><xsl:value-of select="."/></td> - </tr> -</xsl:template> - - -<xsl:template match="documents"> - <!-- Check whether there are any exercise sheets --> - <xsl:if test="exercise-sheet"> - <xsl:if test="$lang='de'"> - <h3>Übungen</h3> - </xsl:if> - <xsl:if test="$lang='en'"> - <h3>Coursework</h3> - </xsl:if> - <ul> - <xsl:for-each select="exercise-sheet"> - <xsl:sort select="boolean(@no)" data-type="text" order="descending"/> - <xsl:sort select="@no" data-type="number"/> - - <xsl:variable name="no" select="@no"/> - <xsl:if test="not(preceding-sibling::exercise-sheet[@no=$no])"> - <!-- Process all exercise sheets with this number --> - <li> - <xsl:apply-templates select="."/> - <xsl:for-each select="following-sibling::exercise-sheet[@no=$no]"> - <xsl:text>, </xsl:text> - <xsl:apply-templates select="."/> - </xsl:for-each> - </li> - </xsl:if> - </xsl:for-each> - </ul> - </xsl:if> - <xsl:if test="lecture-supplement"> - <xsl:if test="$lang='de'"> - <h3>Materialien</h3> - </xsl:if> - <xsl:if test="$lang='en'"> - <h3>Supplements</h3> - </xsl:if> - <ul> - <xsl:apply-templates select="lecture-supplement"/> - </ul> - </xsl:if> - <xsl:if test="lecture-notes"> - <xsl:if test="$lang='de'"> - <h3>Skript <xsl:value-of select="@subtitle"/></h3> - </xsl:if> - <xsl:if test="$lang='en'"> - <h3>Lecture Notes <xsl:value-of select="@subtitle"/></h3> - </xsl:if> - <ul> - <xsl:apply-templates select="lecture-notes"> - ... [truncated message content] |
From: <luk...@us...> - 2011-03-23 13:00:10
|
Revision: 1380 http://toss.svn.sourceforge.net/toss/?rev=1380&view=rev Author: lukstafi Date: 2011-03-23 13:00:03 +0000 (Wed, 23 Mar 2011) Log Message: ----------- Fluents fix: consider all rules for sign check. GameSimpl: relation-with-inverse gluing bug fix; other minor bug fix. Tests: GDL test rule with inverse diagonal move; Server GDL auto-transl tictactoe more deterministic setup. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/Arena/DiscreteRule.mli trunk/Toss/GGP/GDLTest.ml trunk/Toss/GGP/GameSimpl.ml trunk/Toss/GGP/GameSimplTest.ml trunk/Toss/GGP/tests/breakthrough-simpl.toss trunk/Toss/GGP/tests/connect5-simpl.toss trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/HeuristicTest.ml trunk/Toss/Server/ServerGDLTest.in2 trunk/Toss/Server/ServerGDLTest.out2 Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/Arena/Arena.ml 2011-03-23 13:00:03 UTC (rev 1380) @@ -443,12 +443,7 @@ let all_fluents game = let drules = List.map (fun r -> (snd r).ContinuousRule.compiled) game.rules in - let fluents = List.map DiscreteRule.fluents drules in - let frels (posi_frels, nega_frels, indef_frels) = - Aux.Strings.union indef_frels - (Aux.Strings.union posi_frels nega_frels) in - List.fold_left Aux.Strings.union Aux.Strings.empty - (List.map frels fluents) + DiscreteRule.fluents drules (* Compare two (game, state) pairs and explain the first difference Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/Arena/Arena.mli 2011-03-23 13:00:03 UTC (rev 1380) @@ -124,7 +124,7 @@ val map_to_discrete : (DiscreteRule.rule -> DiscreteRule.rule) -> game -> game -val all_fluents : game -> Aux.Strings.t +val all_fluents : game -> Aux.Strings.t * Aux.Strings.t * Aux.Strings.t (** Compare two (game, state) pairs and explain the first difference met. Formulas and expressions are compared for syntactical Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/Arena/DiscreteRule.ml 2011-03-23 13:00:03 UTC (rev 1380) @@ -64,19 +64,26 @@ Aux.map_some fl_make r.rhs_pos_tuples else Aux.map_some fl_make (r.rhs_pos_tuples @ r.rhs_neg_tuples) -let fluents r = +let fluents rules = let map_rels = Aux.map_some (fun (rel,tups)->if tups=[] then None else Some rel) in - let posi_cands = Aux.strings_of_list (map_rels r.rhs_pos_tuples) in - let nega_cands = Aux.strings_of_list (map_rels r.rhs_neg_tuples) in + let posi_cands = Aux.strings_of_list ( + Aux.concat_map (fun r->map_rels r.rhs_pos_tuples) rules) in + let nega_cands = Aux.strings_of_list ( + Aux.concat_map (fun r->map_rels r.rhs_neg_tuples) rules) in let fluents = Aux.Strings.union posi_cands nega_cands in let posi = Aux.Strings.diff posi_cands nega_cands and nega = Aux.Strings.diff nega_cands posi_cands in - let posi_lhs, nega_lhs = FormulaOps.rels_signs r.lhs_form in + let posi_lhs, nega_lhs = + List.fold_left (fun (posi,nega) r -> + let mp, mn = FormulaOps.rels_signs r.lhs_form in + Aux.Strings.union mp posi, Aux.Strings.union mn nega) + (Aux.Strings.empty, Aux.Strings.empty) rules in let posi = Aux.Strings.diff posi posi_lhs in let nega = Aux.Strings.diff nega nega_lhs in posi, nega, Aux.Strings.diff fluents (Aux.Strings.union posi nega) + (* A fluent precondition is an approximation to the condition on a structure for the positive/negative fluent to appear/disappear at a position. We are only interested in expanding preconditions of Modified: trunk/Toss/Arena/DiscreteRule.mli =================================================================== --- trunk/Toss/Arena/DiscreteRule.mli 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/Arena/DiscreteRule.mli 2011-03-23 13:00:03 UTC (rev 1380) @@ -54,7 +54,7 @@ only deleted) and only positively on LHSes and in preconditions. (Call the remaining fluents indefinite.) See {!Heuristic}. *) -val fluents : rule_obj -> Aux.Strings.t * Aux.Strings.t * Aux.Strings.t +val fluents : rule_obj list -> Aux.Strings.t * Aux.Strings.t * Aux.Strings.t val fluents_make : ?only_pos : bool -> (string -> int -> 'a) -> rule_obj -> 'a list Modified: trunk/Toss/GGP/GDLTest.ml =================================================================== --- trunk/Toss/GGP/GDLTest.ml 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/GGP/GDLTest.ml 2011-03-23 13:00:03 UTC (rev 1380) @@ -174,12 +174,12 @@ "breakthrough" >:: (fun () -> game_test_case ~game_name:"breakthrough" ~player:"white" - ~loc0_rule_name:"move_x1_y1_x2_y2_00" + ~loc0_rule_name:"move_x1_y1_x2_y2_0" ~loc0_emb:[ "cellholds_x1_y1__blank_", "cellholds_2_2_MV1"; - "cellholds_x2_y2__blank_", "cellholds_3_3_MV1"; + "cellholds_x2_y2__blank_", "cellholds_1_3_MV1"; "control__blank_", "control_MV1"] - ~loc0_move:"(move 2 2 3 3)" ~loc0_noop:"noop" ~loc1:1 + ~loc0_move:"(move 2 2 1 3)" ~loc0_noop:"noop" ~loc1:1 ~loc1_rule_name:"move_x1_y1_x2_y2_1" ~loc1_emb:[ "cellholds_x1_y1__blank_", "cellholds_7_7_MV1"; Modified: trunk/Toss/GGP/GameSimpl.ml =================================================================== --- trunk/Toss/GGP/GameSimpl.ml 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/GGP/GameSimpl.ml 2011-03-23 13:00:03 UTC (rev 1380) @@ -135,7 +135,9 @@ let signat = Structure.rel_signature struc in let nelems = Structure.Elems.cardinal struc.Structure.elements in let tcard tups = Tups.cardinal tups in - let fluents = Arena.all_fluents game in + let posi_f, nega_f, indef_f = Arena.all_fluents game in + let fluents = + Aux.Strings.union (Aux.Strings.union posi_f nega_f) indef_f in (* {{{ log entry *) if !debug_level > 0 then ( Printf.printf "GameSimpl: fluents = %s\n%!" @@ -188,24 +190,26 @@ then crel else (* 1a *) - let crel = - Aux.not_conflicting_name ~truncate:true !used_rels "C" in + let crel = + Aux.not_conflicting_name ~truncate:true !used_rels "C" in (* {{{ log entry *) - if !debug_level > 3 then ( - Printf.printf "Complemented: crel=%s\n%!" crel - ); + if !debug_level > 3 then ( + Printf.printf "Complemented: crel=%s\n%!" crel + ); (* }}} *) - complemented := (crel, rel) :: !complemented; - struc := Structure.add_rels !struc crel - (Tups.elements (Tups.diff predicate_tups rel_tups)); - signat := (crel, arity) :: !signat; - used_rels := Aux.Strings.add crel !used_rels; - Some crel in + complemented := (crel, rel) :: !complemented; + struc := Structure.add_rels !struc crel + (Tups.elements (Tups.diff predicate_tups rel_tups)); + signat := (crel, arity) :: !signat; + used_rels := Aux.Strings.add crel !used_rels; + Some crel in Aux.StrMap.add rel crel table ) Aux.StrMap.empty !signat in let struc = !struc in let signat = !signat in - let complements rel = Aux.StrMap.find rel complements in + let complements rel = + try Aux.StrMap.find rel complements + with Not_found -> None in (* prepare for (1bc) and (2) *) let subset_table = List.fold_left (fun table (rel,arity) -> @@ -255,7 +259,7 @@ | None -> rel | Some spec -> DiscreteRule.orig_rel_of rel in rel <> "" && - not (Aux.Strings.mem rel fluents) && + not (Aux.Strings.mem rel fluents) && not (List.mem_assoc rel game.Arena.defined_rels) && not (List.exists (fun (_,(rel2,_)) -> rel2=rel) equivalent) && not (Aux.Strings.mem (fst (List.assoc rel equivalent)) fluents || @@ -442,6 +446,12 @@ | _ -> assert false) tuples2) in let tuples = Tups.elements (Tups.inter graph1 inv_graph) in + (* {{{ log entry *) + if !debug_level > 3 then ( + Printf.printf "Generating-inv: %s_INV_%s -- tuple: %s\n%!" + rel1 rel2 (Structure.tuple_str struc (List.hd tuples)) + ); + (* }}} *) Structure.add_rels struc grel tuples in (* preparing (3a-d) *) @@ -503,7 +513,7 @@ Aux.not_conflicting_name ~truncate:true !used_rels "R" in used_rels := Aux.Strings.add grel !used_rels; glued_inv := (grel, rels) :: !glued_inv; - struc := intersect_with_inv !struc grel rel1 rel2; + struc := intersect_with_inv !struc grel rel inv_rel; signat := (grel, Array.length args) :: !signat; (grel, args)::loop more) else (rel1, args1)::loop more @@ -531,8 +541,8 @@ List.fold_left (fun sets args -> let args = Array.to_list args in (let try set, sets = - Aux.pop_find (fun set -> - List.exists (fun a->List.mem a set) args) sets in + Aux.pop_find (fun set -> + List.exists (fun a->List.mem a set) args) sets in Aux.unique_sorted (args @ set) :: sets with Not_found -> args::sets) ) [] tups in @@ -546,8 +556,8 @@ with Not_found -> [], eq_sets in let argset = Array.to_list args in (let try set, sets = - Aux.pop_find (fun set -> - List.exists (fun a->List.mem a set) argset) sets in + Aux.pop_find (fun set -> + List.exists (fun a->List.mem a set) argset) sets in if List.for_all (fun a->List.mem a set) argset then old else @@ -556,7 +566,7 @@ with Not_found -> (rel, argset::sets)::eq_sets, atom::rels) ) (eq_sets, []) rels in grels @ rels in - + (* the step of 3d *) let gluable rel = not (Aux.Strings.mem rel fluents) && @@ -667,8 +677,8 @@ List.fold_left (fun sets args -> let args = Array.to_list args in (let try set, sets = - Aux.pop_find (fun set -> - List.exists (fun a->List.mem a set) args) sets in + Aux.pop_find (fun set -> + List.exists (fun a->List.mem a set) args) sets in Aux.unique_sorted (args @ set) :: sets with Not_found -> args::sets) ) [] tups in @@ -682,8 +692,8 @@ with Not_found -> [], eq_sets in let argset = Array.to_list args in (let try set, sets = - Aux.pop_find (fun set -> - List.exists (fun a->List.mem a set) argset) sets in + Aux.pop_find (fun set -> + List.exists (fun a->List.mem a set) argset) sets in if List.for_all (fun a->List.mem a set) argset then (rel, set::sets)::eq_sets, atom::drels else (rel, Aux.unique_sorted (argset @ set) :: sets) @@ -744,7 +754,7 @@ else DiscreteRule.orig_rel_of rel in let res = (not keep_predicates || List.assoc rel signat > 1) && - not (Aux.Strings.mem rel fluents) && + not (Aux.Strings.mem rel fluents) && not (List.mem_assoc rel game.Arena.defined_rels) && not (Aux.Strings.mem rel used_rels) in (* {{{ log entry *) Modified: trunk/Toss/GGP/GameSimplTest.ml =================================================================== --- trunk/Toss/GGP/GameSimplTest.ml 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/GGP/GameSimplTest.ml 2011-03-23 13:00:03 UTC (rev 1380) @@ -62,11 +62,11 @@ (* The action below is used to regenerate the test targets when {!GameSimpl.simplify} changes. *) let a () = - let game_name = "tictactoe" in - + let game_name = "connect5" in + let game = state_of_file ("./GGP/tests/"^game_name^"-raw.toss") in Printf.printf "\nINPUT:\n%s\n%!" (Arena.state_str game); - GameSimpl.debug_level := 4; + (* GameSimpl.debug_level := 5; *) let res = GameSimpl.simplify game in let resf = open_out ("./GGP/tests/"^game_name^"-simpl.toss") in let res_str = Arena.state_str res in Modified: trunk/Toss/GGP/tests/breakthrough-simpl.toss =================================================================== --- trunk/Toss/GGP/tests/breakthrough-simpl.toss 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/GGP/tests/breakthrough-simpl.toss 2011-03-23 13:00:03 UTC (rev 1380) @@ -308,55 +308,55 @@ cellholds_1_4_MV1, cellholds_1_3_MV1, cellholds_1_2_MV1, cellholds_1_1_MV1 | R { - (cellholds_8_7_MV1, cellholds_7_8_MV1); - (cellholds_8_6_MV1, cellholds_7_7_MV1); - (cellholds_8_5_MV1, cellholds_7_6_MV1); - (cellholds_8_4_MV1, cellholds_7_5_MV1); - (cellholds_8_3_MV1, cellholds_7_4_MV1); - (cellholds_8_2_MV1, cellholds_7_3_MV1); - (cellholds_8_1_MV1, cellholds_7_2_MV1); - (cellholds_7_7_MV1, cellholds_6_8_MV1); - (cellholds_7_6_MV1, cellholds_6_7_MV1); - (cellholds_7_5_MV1, cellholds_6_6_MV1); - (cellholds_7_4_MV1, cellholds_6_5_MV1); - (cellholds_7_3_MV1, cellholds_6_4_MV1); - (cellholds_7_2_MV1, cellholds_6_3_MV1); - (cellholds_7_1_MV1, cellholds_6_2_MV1); - (cellholds_6_7_MV1, cellholds_5_8_MV1); - (cellholds_6_6_MV1, cellholds_5_7_MV1); - (cellholds_6_5_MV1, cellholds_5_6_MV1); - (cellholds_6_4_MV1, cellholds_5_5_MV1); - (cellholds_6_3_MV1, cellholds_5_4_MV1); - (cellholds_6_2_MV1, cellholds_5_3_MV1); - (cellholds_6_1_MV1, cellholds_5_2_MV1); - (cellholds_5_7_MV1, cellholds_4_8_MV1); - (cellholds_5_6_MV1, cellholds_4_7_MV1); - (cellholds_5_5_MV1, cellholds_4_6_MV1); - (cellholds_5_4_MV1, cellholds_4_5_MV1); - (cellholds_5_3_MV1, cellholds_4_4_MV1); - (cellholds_5_2_MV1, cellholds_4_3_MV1); - (cellholds_5_1_MV1, cellholds_4_2_MV1); - (cellholds_4_7_MV1, cellholds_3_8_MV1); - (cellholds_4_6_MV1, cellholds_3_7_MV1); - (cellholds_4_5_MV1, cellholds_3_6_MV1); - (cellholds_4_4_MV1, cellholds_3_5_MV1); - (cellholds_4_3_MV1, cellholds_3_4_MV1); - (cellholds_4_2_MV1, cellholds_3_3_MV1); - (cellholds_4_1_MV1, cellholds_3_2_MV1); - (cellholds_3_7_MV1, cellholds_2_8_MV1); - (cellholds_3_6_MV1, cellholds_2_7_MV1); - (cellholds_3_5_MV1, cellholds_2_6_MV1); - (cellholds_3_4_MV1, cellholds_2_5_MV1); - (cellholds_3_3_MV1, cellholds_2_4_MV1); - (cellholds_3_2_MV1, cellholds_2_3_MV1); - (cellholds_3_1_MV1, cellholds_2_2_MV1); - (cellholds_2_7_MV1, cellholds_1_8_MV1); - (cellholds_2_6_MV1, cellholds_1_7_MV1); - (cellholds_2_5_MV1, cellholds_1_6_MV1); - (cellholds_2_4_MV1, cellholds_1_5_MV1); - (cellholds_2_3_MV1, cellholds_1_4_MV1); - (cellholds_2_2_MV1, cellholds_1_3_MV1); - (cellholds_2_1_MV1, cellholds_1_2_MV1) + (cellholds_7_8_MV1, cellholds_8_7_MV1); + (cellholds_7_7_MV1, cellholds_8_6_MV1); + (cellholds_7_6_MV1, cellholds_8_5_MV1); + (cellholds_7_5_MV1, cellholds_8_4_MV1); + (cellholds_7_4_MV1, cellholds_8_3_MV1); + (cellholds_7_3_MV1, cellholds_8_2_MV1); + (cellholds_7_2_MV1, cellholds_8_1_MV1); + (cellholds_6_8_MV1, cellholds_7_7_MV1); + (cellholds_6_7_MV1, cellholds_7_6_MV1); + (cellholds_6_6_MV1, cellholds_7_5_MV1); + (cellholds_6_5_MV1, cellholds_7_4_MV1); + (cellholds_6_4_MV1, cellholds_7_3_MV1); + (cellholds_6_3_MV1, cellholds_7_2_MV1); + (cellholds_6_2_MV1, cellholds_7_1_MV1); + (cellholds_5_8_MV1, cellholds_6_7_MV1); + (cellholds_5_7_MV1, cellholds_6_6_MV1); + (cellholds_5_6_MV1, cellholds_6_5_MV1); + (cellholds_5_5_MV1, cellholds_6_4_MV1); + (cellholds_5_4_MV1, cellholds_6_3_MV1); + (cellholds_5_3_MV1, cellholds_6_2_MV1); + (cellholds_5_2_MV1, cellholds_6_1_MV1); + (cellholds_4_8_MV1, cellholds_5_7_MV1); + (cellholds_4_7_MV1, cellholds_5_6_MV1); + (cellholds_4_6_MV1, cellholds_5_5_MV1); + (cellholds_4_5_MV1, cellholds_5_4_MV1); + (cellholds_4_4_MV1, cellholds_5_3_MV1); + (cellholds_4_3_MV1, cellholds_5_2_MV1); + (cellholds_4_2_MV1, cellholds_5_1_MV1); + (cellholds_3_8_MV1, cellholds_4_7_MV1); + (cellholds_3_7_MV1, cellholds_4_6_MV1); + (cellholds_3_6_MV1, cellholds_4_5_MV1); + (cellholds_3_5_MV1, cellholds_4_4_MV1); + (cellholds_3_4_MV1, cellholds_4_3_MV1); + (cellholds_3_3_MV1, cellholds_4_2_MV1); + (cellholds_3_2_MV1, cellholds_4_1_MV1); + (cellholds_2_8_MV1, cellholds_3_7_MV1); + (cellholds_2_7_MV1, cellholds_3_6_MV1); + (cellholds_2_6_MV1, cellholds_3_5_MV1); + (cellholds_2_5_MV1, cellholds_3_4_MV1); + (cellholds_2_4_MV1, cellholds_3_3_MV1); + (cellholds_2_3_MV1, cellholds_3_2_MV1); + (cellholds_2_2_MV1, cellholds_3_1_MV1); + (cellholds_1_8_MV1, cellholds_2_7_MV1); + (cellholds_1_7_MV1, cellholds_2_6_MV1); + (cellholds_1_6_MV1, cellholds_2_5_MV1); + (cellholds_1_5_MV1, cellholds_2_4_MV1); + (cellholds_1_4_MV1, cellholds_2_3_MV1); + (cellholds_1_3_MV1, cellholds_2_2_MV1); + (cellholds_1_2_MV1, cellholds_2_1_MV1) }; R0 { (cellholds_7_7_MV1, cellholds_8_8_MV1); Modified: trunk/Toss/GGP/tests/connect5-simpl.toss =================================================================== --- trunk/Toss/GGP/tests/connect5-simpl.toss 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/GGP/tests/connect5-simpl.toss 2011-03-23 13:00:03 UTC (rev 1380) @@ -730,31 +730,31 @@ (cell_a_a_MV1, cell_b_b_MV1) }; R2 { - (cell_h_g_MV1, cell_g_h_MV1); (cell_h_f_MV1, cell_g_g_MV1); - (cell_h_e_MV1, cell_g_f_MV1); (cell_h_d_MV1, cell_g_e_MV1); - (cell_h_c_MV1, cell_g_d_MV1); (cell_h_b_MV1, cell_g_c_MV1); - (cell_h_a_MV1, cell_g_b_MV1); (cell_g_g_MV1, cell_f_h_MV1); - (cell_g_f_MV1, cell_f_g_MV1); (cell_g_e_MV1, cell_f_f_MV1); - (cell_g_d_MV1, cell_f_e_MV1); (cell_g_c_MV1, cell_f_d_MV1); - (cell_g_b_MV1, cell_f_c_MV1); (cell_g_a_MV1, cell_f_b_MV1); - (cell_f_g_MV1, cell_e_h_MV1); (cell_f_f_MV1, cell_e_g_MV1); - (cell_f_e_MV1, cell_e_f_MV1); (cell_f_d_MV1, cell_e_e_MV1); - (cell_f_c_MV1, cell_e_d_MV1); (cell_f_b_MV1, cell_e_c_MV1); - (cell_f_a_MV1, cell_e_b_MV1); (cell_e_g_MV1, cell_d_h_MV1); - (cell_e_f_MV1, cell_d_g_MV1); (cell_e_e_MV1, cell_d_f_MV1); - (cell_e_d_MV1, cell_d_e_MV1); (cell_e_c_MV1, cell_d_d_MV1); - (cell_e_b_MV1, cell_d_c_MV1); (cell_e_a_MV1, cell_d_b_MV1); - (cell_d_g_MV1, cell_c_h_MV1); (cell_d_f_MV1, cell_c_g_MV1); - (cell_d_e_MV1, cell_c_f_MV1); (cell_d_d_MV1, cell_c_e_MV1); - (cell_d_c_MV1, cell_c_d_MV1); (cell_d_b_MV1, cell_c_c_MV1); - (cell_d_a_MV1, cell_c_b_MV1); (cell_c_g_MV1, cell_b_h_MV1); - (cell_c_f_MV1, cell_b_g_MV1); (cell_c_e_MV1, cell_b_f_MV1); - (cell_c_d_MV1, cell_b_e_MV1); (cell_c_c_MV1, cell_b_d_MV1); - (cell_c_b_MV1, cell_b_c_MV1); (cell_c_a_MV1, cell_b_b_MV1); - (cell_b_g_MV1, cell_a_h_MV1); (cell_b_f_MV1, cell_a_g_MV1); - (cell_b_e_MV1, cell_a_f_MV1); (cell_b_d_MV1, cell_a_e_MV1); - (cell_b_c_MV1, cell_a_d_MV1); (cell_b_b_MV1, cell_a_c_MV1); - (cell_b_a_MV1, cell_a_b_MV1) + (cell_g_h_MV1, cell_h_g_MV1); (cell_g_g_MV1, cell_h_f_MV1); + (cell_g_f_MV1, cell_h_e_MV1); (cell_g_e_MV1, cell_h_d_MV1); + (cell_g_d_MV1, cell_h_c_MV1); (cell_g_c_MV1, cell_h_b_MV1); + (cell_g_b_MV1, cell_h_a_MV1); (cell_f_h_MV1, cell_g_g_MV1); + (cell_f_g_MV1, cell_g_f_MV1); (cell_f_f_MV1, cell_g_e_MV1); + (cell_f_e_MV1, cell_g_d_MV1); (cell_f_d_MV1, cell_g_c_MV1); + (cell_f_c_MV1, cell_g_b_MV1); (cell_f_b_MV1, cell_g_a_MV1); + (cell_e_h_MV1, cell_f_g_MV1); (cell_e_g_MV1, cell_f_f_MV1); + (cell_e_f_MV1, cell_f_e_MV1); (cell_e_e_MV1, cell_f_d_MV1); + (cell_e_d_MV1, cell_f_c_MV1); (cell_e_c_MV1, cell_f_b_MV1); + (cell_e_b_MV1, cell_f_a_MV1); (cell_d_h_MV1, cell_e_g_MV1); + (cell_d_g_MV1, cell_e_f_MV1); (cell_d_f_MV1, cell_e_e_MV1); + (cell_d_e_MV1, cell_e_d_MV1); (cell_d_d_MV1, cell_e_c_MV1); + (cell_d_c_MV1, cell_e_b_MV1); (cell_d_b_MV1, cell_e_a_MV1); + (cell_c_h_MV1, cell_d_g_MV1); (cell_c_g_MV1, cell_d_f_MV1); + (cell_c_f_MV1, cell_d_e_MV1); (cell_c_e_MV1, cell_d_d_MV1); + (cell_c_d_MV1, cell_d_c_MV1); (cell_c_c_MV1, cell_d_b_MV1); + (cell_c_b_MV1, cell_d_a_MV1); (cell_b_h_MV1, cell_c_g_MV1); + (cell_b_g_MV1, cell_c_f_MV1); (cell_b_f_MV1, cell_c_e_MV1); + (cell_b_e_MV1, cell_c_d_MV1); (cell_b_d_MV1, cell_c_c_MV1); + (cell_b_c_MV1, cell_c_b_MV1); (cell_b_b_MV1, cell_c_a_MV1); + (cell_a_h_MV1, cell_b_g_MV1); (cell_a_g_MV1, cell_b_f_MV1); + (cell_a_f_MV1, cell_b_e_MV1); (cell_a_e_MV1, cell_b_d_MV1); + (cell_a_d_MV1, cell_b_c_MV1); (cell_a_c_MV1, cell_b_b_MV1); + (cell_a_b_MV1, cell_b_a_MV1) }; cell_a_y_MV1 { cell_a_h_MV1; cell_a_g_MV1; cell_a_f_MV1; cell_a_e_MV1; cell_a_d_MV1; Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/Play/Heuristic.ml 2011-03-23 13:00:03 UTC (rev 1380) @@ -991,32 +991,12 @@ let use_monotonic = ref true let default_heuristic_old ?struc ?advr - {Arena.rules=rules; Arena.graph=graph} = + ({Arena.rules=rules; Arena.graph=graph} as game) = (* TODO: cache the default heuristic in game definition or state *) let drules = List.map (fun r -> (snd r).ContinuousRule.compiled) rules in - let fluents = List.map DiscreteRule.fluents drules in let posi_frels, nega_frels, indef_frels = - List.fold_left (fun (posi_frels, nega_frels, indef_frels) - (more_posi, more_nega, more_indef) -> - let posi = - Aux.Strings.diff more_posi - (Aux.Strings.union nega_frels indef_frels) in - let nega = - Aux.Strings.diff more_nega - (Aux.Strings.union posi_frels indef_frels) in - let more = - Aux.Strings.union more_indef - (Aux.Strings.union more_posi more_nega) in - let indef = - Aux.Strings.diff more - (Aux.Strings.union posi nega) in - Aux.Strings.union posi - (Aux.Strings.diff posi_frels more), - Aux.Strings.union nega - (Aux.Strings.diff nega_frels more), - Aux.Strings.union indef indef_frels - ) (Aux.Strings.empty, Aux.Strings.empty, Aux.Strings.empty) fluents in + Arena.all_fluents game in let array_plus ar = Array.fold_right (fun x y->Plus (x, y)) ar (Const 0.) in let all_payoffs = Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/Play/HeuristicTest.ml 2011-03-23 13:00:03 UTC (rev 1380) @@ -62,28 +62,8 @@ (fun r ar si -> (r,ar)::si) signat_struc.Structure.rel_signature [] in let drules = List.map (DiscreteRule.compile_rule signature []) rules in - let fluents = List.map DiscreteRule.fluents drules in let posi_frels, nega_frels, indef_frels = - List.fold_left (fun (posi_frels, nega_frels, indef_frels) - (more_posi, more_nega, more_indef) -> - let posi = - Aux.Strings.diff more_posi - (Aux.Strings.union nega_frels indef_frels) in - let nega = - Aux.Strings.diff more_nega - (Aux.Strings.union posi_frels indef_frels) in - let more = - Aux.Strings.union more_indef - (Aux.Strings.union more_posi more_nega) in - let indef = - Aux.Strings.diff more - (Aux.Strings.union posi nega) in - Aux.Strings.union posi - (Aux.Strings.diff posi_frels more), - Aux.Strings.union nega - (Aux.Strings.diff nega_frels more), - Aux.Strings.union indef indef_frels - ) (Aux.Strings.empty, Aux.Strings.empty, Aux.Strings.empty) fluents in + DiscreteRule.fluents drules in let posi_poff_rels, nega_poff_rels = FormulaOps.rels_signs_expr payoff in let all_poff_rels = Modified: trunk/Toss/Server/ServerGDLTest.in2 =================================================================== --- trunk/Toss/Server/ServerGDLTest.in2 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/Server/ServerGDLTest.in2 2011-03-23 13:00:03 UTC (rev 1380) @@ -3,9 +3,9 @@ Sender: GAMEMASTER Receiver: GAMEPLAYER Content-type: text/acl -Content-length: 1652 +Content-length: 1664 -(START MATCH.3316980891 OPLAYER ((ROLE XPLAYER) (ROLE OPLAYER) (INIT (CELL 1 1 B)) (INIT (CELL 1 2 B)) (INIT (CELL 1 3 B)) (INIT (CELL 2 1 B)) (INIT (CELL 2 2 B)) (INIT (CELL 2 3 B)) (INIT (CELL 3 1 B)) (INIT (CELL 3 2 B)) (INIT (CELL 3 3 B)) (INIT (CONTROL XPLAYER)) (<= (NEXT (CELL ?X ?Y ?PLAYER)) (DOES ?PLAYER (MARK ?X ?Y))) (<= (NEXT (CELL ?X ?Y ?MARK)) (TRUE (CELL ?X ?Y ?MARK)) (DOES ?PLAYER (MARK ?M ?N)) (DISTINCTCELL ?X ?Y ?M ?N)) (<= (NEXT (CONTROL XPLAYER)) (TRUE (CONTROL OPLAYER))) (<= (NEXT (CONTROL OPLAYER)) (TRUE (CONTROL XPLAYER))) (<= (ROW ?X ?PLAYER) (ROLE ?PLAYER) (TRUE (CELL ?X 1 ?PLAYER)) (TRUE (CELL ?X 2 ?PLAYER)) (TRUE (CELL ?X 3 ?PLAYER))) (<= (COLUMN ?Y ?PLAYER) (ROLE ?PLAYER) (TRUE (CELL 1 ?Y ?PLAYER)) (TRUE (CELL 2 ?Y ?PLAYER)) (TRUE (CELL 3 ?Y ?PLAYER))) (<= (DIAGONAL ?PLAYER) (ROLE ?PLAYER) (TRUE (CELL 1 1 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 3 ?PLAYER))) (<= (DIAGONAL ?PLAYER) (ROLE ?PLAYER) (TRUE (CELL 1 3 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 1 ?PLAYER))) (<= (LINE ?PLAYER) (ROW ?X ?PLAYER)) (<= (LINE ?PLAYER) (COLUMN ?Y ?PLAYER)) (<= (LINE ?PLAYER) (DIAGONAL ?PLAYER)) (<= OPEN (TRUE (CELL ?X ?Y B))) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?X ?M)) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?Y ?N)) (<= (LEGAL ?PLAYER (MARK ?X ?Y)) (TRUE (CELL ?X ?Y B)) (TRUE (CONTROL ?PLAYER))) (<= (LEGAL ?PLAYER NOOP) (NOT (TRUE (CONTROL ?PLAYER)))) (<= (GOAL ?PLAYER 100) (LINE ?PLAYER)) (<= (GOAL ?PLAYER 50) (NOT (LINE XPLAYER)) (NOT (LINE OPLAYER)) (NOT OPEN)) (<= (GOAL ?PLAYER1 0) (LINE ?PLAYER2) (DISTINCT ?PLAYER1 ?PLAYER2)) (<= TERMINAL (LINE ?PLAYER)) (<= TERMINAL (NOT OPEN))) 30 30) +(START MATCH.3316980891 OPLAYER ((ROLE XPLAYER) (ROLE OPLAYER) (INIT (CELL 1 1 XPLAYER)) (INIT (CELL 1 2 OPLAYER)) (INIT (CELL 1 3 B)) (INIT (CELL 2 1 B)) (INIT (CELL 2 2 B)) (INIT (CELL 2 3 B)) (INIT (CELL 3 1 B)) (INIT (CELL 3 2 B)) (INIT (CELL 3 3 B)) (INIT (CONTROL XPLAYER)) (<= (NEXT (CELL ?X ?Y ?PLAYER)) (DOES ?PLAYER (MARK ?X ?Y))) (<= (NEXT (CELL ?X ?Y ?MARK)) (TRUE (CELL ?X ?Y ?MARK)) (DOES ?PLAYER (MARK ?M ?N)) (DISTINCTCELL ?X ?Y ?M ?N)) (<= (NEXT (CONTROL XPLAYER)) (TRUE (CONTROL OPLAYER))) (<= (NEXT (CONTROL OPLAYER)) (TRUE (CONTROL XPLAYER))) (<= (ROW ?X ?PLAYER) (ROLE ?PLAYER) (TRUE (CELL ?X 1 ?PLAYER)) (TRUE (CELL ?X 2 ?PLAYER)) (TRUE (CELL ?X 3 ?PLAYER))) (<= (COLUMN ?Y ?PLAYER) (ROLE ?PLAYER) (TRUE (CELL 1 ?Y ?PLAYER)) (TRUE (CELL 2 ?Y ?PLAYER)) (TRUE (CELL 3 ?Y ?PLAYER))) (<= (DIAGONAL ?PLAYER) (ROLE ?PLAYER) (TRUE (CELL 1 1 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 3 ?PLAYER))) (<= (DIAGONAL ?PLAYER) (ROLE ?PLAYER) (TRUE (CELL 1 3 ?PLAYER)) (TRUE (CELL 2 2 ?PLAYER)) (TRUE (CELL 3 1 ?PLAYER))) (<= (LINE ?PLAYER) (ROW ?X ?PLAYER)) (<= (LINE ?PLAYER) (COLUMN ?Y ?PLAYER)) (<= (LINE ?PLAYER) (DIAGONAL ?PLAYER)) (<= OPEN (TRUE (CELL ?X ?Y B))) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?X ?M)) (<= (DISTINCTCELL ?X ?Y ?M ?N) (DISTINCT ?Y ?N)) (<= (LEGAL ?PLAYER (MARK ?X ?Y)) (TRUE (CELL ?X ?Y B)) (TRUE (CONTROL ?PLAYER))) (<= (LEGAL ?PLAYER NOOP) (NOT (TRUE (CONTROL ?PLAYER)))) (<= (GOAL ?PLAYER 100) (LINE ?PLAYER)) (<= (GOAL ?PLAYER 50) (NOT (LINE XPLAYER)) (NOT (LINE OPLAYER)) (NOT OPEN)) (<= (GOAL ?PLAYER1 0) (LINE ?PLAYER2) (DISTINCT ?PLAYER1 ?PLAYER2)) (<= TERMINAL (LINE ?PLAYER)) (<= TERMINAL (NOT OPEN))) 30 30) POST / HTTP/1.0 Accept: text/delim @@ -23,7 +23,7 @@ Content-type: text/acl Content-length: 41 -(PLAY MATCH.3316980891 ((MARK 1 2) NOOP)) +(PLAY MATCH.3316980891 ((MARK 3 3) NOOP)) POST / HTTP/1.0 Accept: text/delim @@ -50,22 +50,4 @@ Content-type: text/acl Content-length: 41 -(PLAY MATCH.3316980891 (NOOP (MARK 1 1))) - -POST / HTTP/1.0 -Accept: text/delim -Sender: GAMEMASTER -Receiver: GAMEPLAYER -Content-type: text/acl -Content-length: 41 - -(PLAY MATCH.3316980891 ((MARK 2 3) NOOP)) - -POST / HTTP/1.0 -Accept: text/delim -Sender: GAMEMASTER -Receiver: GAMEPLAYER -Content-type: text/acl -Content-length: 41 - -(STOP MATCH.3316980891 (NOOP (MARK 3 3))) +(STOP MATCH.3316980891 (NOOP (MARK 3 2))) Modified: trunk/Toss/Server/ServerGDLTest.out2 =================================================================== --- trunk/Toss/Server/ServerGDLTest.out2 2011-03-23 00:41:31 UTC (rev 1379) +++ trunk/Toss/Server/ServerGDLTest.out2 2011-03-23 13:00:03 UTC (rev 1380) @@ -22,20 +22,10 @@ Content-type: text/acl Content-length: 10 -(MARK 1 1) +(MARK 3 2) HTTP/1.0 200 OK Content-type: text/acl Content-length: 4 -NOOP -HTTP/1.0 200 OK -Content-type: text/acl -Content-length: 10 - -(MARK 3 3) -HTTP/1.0 200 OK -Content-type: text/acl -Content-length: 4 - DONE ERR processing completed -- EOF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-23 00:41:39
|
Revision: 1379 http://toss.svn.sourceforge.net/toss/?rev=1379&view=rev Author: lukstafi Date: 2011-03-23 00:41:31 +0000 (Wed, 23 Mar 2011) Log Message: ----------- Generalized folds over formulas and real expressions. Major overhaul of monotonicity (detection and heuristics): distinction of positive, negative and indefinite fluents. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/DiscreteRule.ml trunk/Toss/Arena/DiscreteRule.mli trunk/Toss/Formula/FFTNF.ml trunk/Toss/Formula/FFTNF.mli trunk/Toss/Formula/FFTNFTest.ml trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Formula/FormulaOps.mli trunk/Toss/GGP/GameSimpl.ml trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/Heuristic.mli trunk/Toss/Play/HeuristicTest.ml trunk/Toss/Solver/SolverTest.ml Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Arena/Arena.ml 2011-03-23 00:41:31 UTC (rev 1379) @@ -439,6 +439,17 @@ rules = List.map (fun (rn, r) -> rn, {r with ContinuousRule.discrete = f r.ContinuousRule.discrete}) game.rules} + +let all_fluents game = + let drules = + List.map (fun r -> (snd r).ContinuousRule.compiled) game.rules in + let fluents = List.map DiscreteRule.fluents drules in + let frels (posi_frels, nega_frels, indef_frels) = + Aux.Strings.union indef_frels + (Aux.Strings.union posi_frels nega_frels) in + List.fold_left Aux.Strings.union Aux.Strings.empty + (List.map frels fluents) + (* Compare two (game, state) pairs and explain the first difference met. Formulas and expressions are compared for syntactical Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Arena/Arena.mli 2011-03-23 00:41:31 UTC (rev 1379) @@ -124,6 +124,8 @@ val map_to_discrete : (DiscreteRule.rule -> DiscreteRule.rule) -> game -> game +val all_fluents : game -> Aux.Strings.t + (** Compare two (game, state) pairs and explain the first difference met. Formulas and expressions are compared for syntactical equality. Players need to be given in the same order. Data is Modified: trunk/Toss/Arena/DiscreteRule.ml =================================================================== --- trunk/Toss/Arena/DiscreteRule.ml 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Arena/DiscreteRule.ml 2011-03-23 00:41:31 UTC (rev 1379) @@ -49,7 +49,13 @@ rlmap : (string * string) list option; (* rule_s on variables (?) *) } -(* We call fluents the relations that can be modified by a rule. *) +(* Fluents are relations that are changed by rules. Distinguish two + subclasses of fluents: positive fluents occur only positively on + RHSes (are only added) and only negatively on LHSes and in + preconditions, and negative fluents only negatively on RHSes (are + only deleted) and only positively on LHSes and in + preconditions. (Call the remaining fluents indefinite.) See + Heuristic.ml. *) let fluents_make ?(only_pos=false) f r = let fl_make (s, tp) = if tp = [] then None else @@ -61,41 +67,34 @@ let fluents r = let map_rels = Aux.map_some (fun (rel,tups)->if tups=[] then None else Some rel) in - map_rels r.rhs_pos_tuples @ map_rels r.rhs_neg_tuples - -(* A relation is monotonic if it cannot remove tuples. *) -let monotonic r = - List.for_all (fun (_,tups) -> tups = []) r.rhs_neg_tuples + let posi_cands = Aux.strings_of_list (map_rels r.rhs_pos_tuples) in + let nega_cands = Aux.strings_of_list (map_rels r.rhs_neg_tuples) in + let fluents = Aux.Strings.union posi_cands nega_cands in + let posi = Aux.Strings.diff posi_cands nega_cands + and nega = Aux.Strings.diff nega_cands posi_cands in + let posi_lhs, nega_lhs = FormulaOps.rels_signs r.lhs_form in + let posi = Aux.Strings.diff posi posi_lhs in + let nega = Aux.Strings.diff nega nega_lhs in + posi, nega, Aux.Strings.diff fluents (Aux.Strings.union posi nega) (* A fluent precondition is an approximation to the condition on a - structure for the fluent to appear at a position. *) -let fluent_preconds rules signature fluents = - (* Remove positive fluents as they could still be added later, also - remove the fluent under consideration *) - let module M = struct open Formula - (* TODO: since OCaml 3.12 *) (* let open Formula in *) - let rec negative_trace fluent neg = function - | Rel (rel, _) as atom -> - if rel = fluent || not neg && List.mem rel fluents - then raise Not_found - else atom - | (Eq _ | In _ | RealExpr _) as atom -> atom - | Not phi -> Not (negative_trace fluent (not neg) phi) - | And conjs -> - And (Aux.map_try (negative_trace fluent neg) conjs) - | Or disjs -> - Or (Aux.map_try (negative_trace fluent neg) disjs) - | Ex (vs, phi) -> Ex (vs, negative_trace fluent neg phi) - | All (vs, phi) -> All (vs, negative_trace fluent neg phi) end in - let negative_trace fluent phi = - try FormulaOps.flatten_formula (M.negative_trace fluent false phi) - with Not_found -> Formula.And [] in + structure for the positive/negative fluent to appear/disappear at a + position. We are only interested in expanding preconditions of + positive and negative fluents. + + TODO: currently, only a single absence/presence tuple is removed + from the precondition: the one from which it "derived"; shouldn't + all added and deleted tuples be removed? *) +let fluent_preconds rules signature posi_frels nega_frels = + let fluents = + Aux.Strings.elements posi_frels @ Aux.Strings.elements nega_frels in let fluent_precond rel = (* rules that produce a fluent, together with its args *) let rel_prods = Aux.map_some (fun r -> - if List.mem_assoc rel r.rhs_pos_tuples then - let rel_tups = List.assoc rel r.rhs_pos_tuples in + let rhs_tuples = r.rhs_pos_tuples @ r.rhs_neg_tuples in + if List.mem_assoc rel rhs_tuples then + let rel_tups = List.assoc rel rhs_tuples in if rel_tups <> [] then Some (r, rel_tups) else None else None) rules in @@ -108,7 +107,27 @@ Aux.not_conflicting_names "av__" all_names (Array.to_list (Array.make (signature rel) ())) in (* Encapsulate the precondition as a defined relation *) - let compose_pre r body args = + let compose_pre r body args = + let lhs_args = + match r.rlmap with + | None -> (* LHS and RHS vars are the same *) + args + | Some rlmap -> + Array.map (fun e->List.assoc e rlmap) args in + (* remove potential condition for absence/presence of the + fluent being just added / deleted *) + let body = FormulaOps.map_formula + {FormulaOps.identity_map with + (* remove the absence/presence condition of added/deleted + tuple (TODO: see header comment); we know by [rel \in + nega_frels/posi_frels] that the occurrence is + positive/negative *) + FormulaOps.map_Rel = (fun b_rel b_args -> + let b = rel = b_rel && lhs_args = + Array.map Formula.var_str b_args in + if b && Aux.Strings.mem rel nega_frels then Formula.And [] + else if b && Aux.Strings.mem rel posi_frels then Formula.Or [] + else Formula.Rel (b_rel, b_args))} body in let args = Array.to_list args in let body, other_vars, numap_cstr = match r.rlmap with @@ -131,9 +150,8 @@ else Formula.Ex (List.map (fun v-> `FO v) other_vars, body) in let disjs = Aux.concat_map - (fun (r, lhs, args_l)-> List.map (compose_pre r lhs) args_l) - (List.map (fun (r, args_l)-> - r, negative_trace rel r.lhs_form, args_l) rel_prods) in + (fun (r, args_l)-> List.map (compose_pre r r.lhs_form) args_l) + rel_prods in let precond = match disjs with | [] -> failwith ("fluent_preconds: not a fluent: "^rel) Modified: trunk/Toss/Arena/DiscreteRule.mli =================================================================== --- trunk/Toss/Arena/DiscreteRule.mli 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Arena/DiscreteRule.mli 2011-03-23 00:41:31 UTC (rev 1379) @@ -47,16 +47,23 @@ val elemvar_of_elem : elem_inv_names -> int -> string -(* We call fluents the relations that can be modified by a rule. *) -val fluents : rule_obj -> string list +(** Fluents are relations that are changed by rules. Distinguish two + subclasses of fluents: positive fluents occur only positively on + RHSes (are only added) and only negatively on LHSes and in + preconditions, and negative fluents only negatively on RHSes (are + only deleted) and only positively on LHSes and in + preconditions. (Call the remaining fluents indefinite.) See + {!Heuristic}. *) +val fluents : rule_obj -> Aux.Strings.t * Aux.Strings.t * Aux.Strings.t val fluents_make : ?only_pos : bool -> (string -> int -> 'a) -> rule_obj -> 'a list - -(* A relation is monotonic if it cannot remove tuples. *) -val monotonic : rule_obj -> bool +(** A fluent precondition is an approximation to the condition on a + structure for the positive/negative fluent to appear/disappear at a + position. We are only interested in expanding preconditions of + positive and negative fluents. *) val fluent_preconds : - rule_obj list -> (string -> int) -> string list -> + rule_obj list -> (string -> int) -> Aux.Strings.t -> Aux.Strings.t -> (string * (string list * Formula.formula)) list (* Helpers for special relations. *) Modified: trunk/Toss/Formula/FFTNF.ml =================================================================== --- trunk/Toss/Formula/FFTNF.ml 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Formula/FFTNF.ml 2011-03-23 00:41:31 UTC (rev 1379) @@ -1,143 +1,143 @@ -(* Computing the FF Type Normal Form, and the FF Separation. +(** Computing the FF Type Normal Form, and the FF Separation. - {2 Computing the FF Type Normal Form} + {2 Computing the FF Type Normal Form} - Because FFTNF adds considerably to the already high computational - cost of computing TNF, we turn off some of its flexibility - depending on the size of the normalized formula: + Because FFTNF adds considerably to the already high computational + cost of computing TNF, we turn off some of its flexibility + depending on the size of the normalized formula: - (1) at parsimony level 1 (PARL1), we do not move atoms that are - already protected (in the TNF sense) if that leads to formula - duplication; + (1) at parsimony level 1 (PARL1), we do not move atoms that are + already protected (in the TNF sense) if that leads to formula + duplication; - (2) at parsimony level 2 (PARL2), we do not reduce to PNF and do - not move protected atoms at all. + (2) at parsimony level 2 (PARL2), we do not reduce to PNF and do + not move protected atoms at all. - {3 Algorithm for calculating FFTNF(_<_):} + {3 Algorithm for calculating FFTNF(_<_):} - 1: Reduce to partially negation-normal prenex-normal form with - existential-first minimized alternation -- do not push negation - inside an existentially quantified ground subformula; collapse - nonalternating quantifiers into quantifying over sets of - variables. We call a negated existentially quantified ground - subformula -- or equivalently a universally quantified ground - subformula -- a subtask. PARL2: do partial NNF but not PNF. + 1: Reduce to partially negation-normal prenex-normal form with + existential-first minimized alternation -- do not push negation + inside an existentially quantified ground subformula; collapse + nonalternating quantifiers into quantifying over sets of + variables. We call a negated existentially quantified ground + subformula -- or equivalently a universally quantified ground + subformula -- a subtask. PARL2: do partial NNF but not PNF. - 2: Collapse conjunctions and disjunctions using associativity. + 2: Collapse conjunctions and disjunctions using associativity. - 3: The processed part is maintained explicitly; the zipper is - built during the depth-first search for unprocessed literal and - is then zipped by pulling-out the selected literal. PARL2: mark - protected literals as processed. + 3: The processed part is maintained explicitly; the zipper is + built during the depth-first search for unprocessed literal and + is then zipped by pulling-out the selected literal. PARL2: mark + protected literals as processed. - The whole term is searched depth-first for a subtask or the best - literal to pull-out. A subtask is preferred, otherwise the first - best literal is selected. + The whole term is searched depth-first for a subtask or the best + literal to pull-out. A subtask is preferred, otherwise the first + best literal is selected. - A literal that has all variables quantified in the scope of some - variable of another literal is worse than the other literal. If - their oldest (quantified with widest scope) variable is the same, - compare using the ordering _<_. "a _<_ b" means that a is better - than b -- should be pulled out earlier. "a _<_ b" returns false if - it is indifferent whether a or b should be first. + A literal that has all variables quantified in the scope of some + variable of another literal is worse than the other literal. If + their oldest (quantified with widest scope) variable is the same, + compare using the ordering _<_. "a _<_ b" means that a is better + than b -- should be pulled out earlier. "a _<_ b" returns false if + it is indifferent whether a or b should be first. - The subtask or literal to be pulled out is replaced by T = And[], - forming the initial location (context[],[T]). + The subtask or literal to be pulled out is replaced by T = And[], + forming the initial location (context[],[T]). - Note: the literal is treated as "conjoined", as opposed - to "disjoined", to the surroundings, because disjunctions of - literals are much rarer than conjunctions. + Note: the literal is treated as "conjoined", as opposed + to "disjoined", to the surroundings, because disjunctions of + literals are much rarer than conjunctions. - 4: When a subtask/literal is placed in its final location it is - marked as processed. Denote by Qn, Qn', etc., a quantifier over a - set of variables, and by -Qn a quantifier that is complementary to - Qn (e.g. -ex vs.Phi = all vs.Phi). The result of pulling out a - literal L of a location (context[],[fill-loc]) (denoted also as - context[][fill-loc]) by cases on context[]: + 4: When a subtask/literal is placed in its final location it is + marked as processed. Denote by Qn, Qn', etc., a quantifier over a + set of variables, and by -Qn a quantifier that is complementary to + Qn (e.g. -ex vs.Phi = all vs.Phi). The result of pulling out a + literal L of a location (context[],[fill-loc]) (denoted also as + context[][fill-loc]) by cases on context[]: - (a) context'[Qn.[]] where Qn = Qn' union Qn'' for Qn' - contained in Var(L) and Qn'' disjoint with Var(L) + (a) context'[Qn.[]] where Qn = Qn' union Qn'' for Qn' + contained in Var(L) and Qn'' disjoint with Var(L) - (a1) empty Qn': pull-out(context'[],[Qn.[fill-loc]]) + (a1) empty Qn': pull-out(context'[],[Qn.[fill-loc]]) - (a2) nonempty Qn': context'[Qn'.(L /\ Qn''.[fill-loc])] + (a2) nonempty Qn': context'[Qn'.(L /\ Qn''.[fill-loc])] - (b) context'[[] /\ C]: pull-out(context'[],[[fill-loc] /\ C]) + (b) context'[[] /\ C]: pull-out(context'[],[[fill-loc] /\ C]) - (c) context'[Qn.([] \/ D)] where Qn1=Qn & Var(L), - Qn2=Qn & Var(L,[fill-loc]) \ Var(D), Qn3=Qn & Var(L,[fill-loc]) & Var(D) - Qn4=Qn & Var(D) \ Qn3, Qn5=Qn & Var([fill-loc]) \ Qn1 \ Qn3, - Qn6=Qn & Var([fill-loc],D) + (c) context'[Qn.([] \/ D)] where Qn1=Qn & Var(L), + Qn2=Qn & Var(L,[fill-loc]) \ Var(D), Qn3=Qn & Var(L,[fill-loc]) & Var(D) + Qn4=Qn & Var(D) \ Qn3, Qn5=Qn & Var([fill-loc]) \ Qn1 \ Qn3, + Qn6=Qn & Var([fill-loc],D) - (c0) PARL1 and Qn1=Qn: - context[L /\ [fill-loc]] + (c0) PARL1 and Qn1=Qn: + context[L /\ [fill-loc]] - (c1) empty Qn3: - pull-out(context'[Qn2.[] \/ Qn4.D],[fill-loc]) + (c1) empty Qn3: + pull-out(context'[Qn2.[] \/ Qn4.D],[fill-loc]) - (c2) nonempty Qn3 and Qn1, (nonempty Qn1\Qn3 or empty Qn3\Qn1): - context'[Qn3.(Qn1\Qn3.(L /\ Qn5.[fill-loc]) \/ Qn4.D)] + (c2) nonempty Qn3 and Qn1, (nonempty Qn1\Qn3 or empty Qn3\Qn1): + context'[Qn3.(Qn1\Qn3.(L /\ Qn5.[fill-loc]) \/ Qn4.D)] - (c3) Qn existential, nonempty Qn3\Qn1, empty Qn1\Qn3: - pull-out(context'[Qn2+3.[] \/ Qn3+4.D],[fill-loc]) + (c3) Qn existential, nonempty Qn3\Qn1, empty Qn1\Qn3: + pull-out(context'[Qn2+3.[] \/ Qn3+4.D],[fill-loc]) - (c4) Qn universal, nonempty Qn3\Qn1, empty Qn1\Qn3: - pull-out(context'[Qn.(([] \/ D) /\ ([fill-loc] \/ D))],[T]) + (c4) Qn universal, nonempty Qn3\Qn1, empty Qn1\Qn3: + pull-out(context'[Qn.(([] \/ D) /\ ([fill-loc] \/ D))],[T]) - (d) context'[Qn.(([] \/ D) /\ C)] where Qn1=Qn & Var(L), - Qn2=Qn & Var(L,[fill-loc],D) \ Var(C), - Qn3=Qn & Var(L,[fill-loc],D) & Var(C) - Qn4=Qn & Var(C) \ Qn3, Qn5=Qn & Var(D,C), - Qn6=Qn & Var(L,[fill-loc],C) + (d) context'[Qn.(([] \/ D) /\ C)] where Qn1=Qn & Var(L), + Qn2=Qn & Var(L,[fill-loc],D) \ Var(C), + Qn3=Qn & Var(L,[fill-loc],D) & Var(C) + Qn4=Qn & Var(C) \ Qn3, Qn5=Qn & Var(D,C), + Qn6=Qn & Var(L,[fill-loc],C) - (d0) PARL1 and Qn1=Qn: - context[L /\ [fill-loc]] + (d0) PARL1 and Qn1=Qn: + context[L /\ [fill-loc]] - (d1) empty Qn3: - pull-out(context'[Qn2.([] \/ D) /\ Qn4.C],[fill-loc]) + (d1) empty Qn3: + pull-out(context'[Qn2.([] \/ D) /\ Qn4.C],[fill-loc]) - (d2) Qn universal: - pull-out(context'[Qn2+3.([] \/ D) /\ Qn3+4.C]) + (d2) Qn universal: + pull-out(context'[Qn2+3.([] \/ D) /\ Qn3+4.C]) - (d3) Qn existential, nonempty Qn3: - pull-out(context'[Qn6.([] /\ C) \/ Qn5.(D /\ C)],[fill-loc]) + (d3) Qn existential, nonempty Qn3: + pull-out(context'[Qn6.([] /\ C) \/ Qn5.(D /\ C)],[fill-loc]) - (e) context'[[] \/ D] when no quantifier in context': - context[L /\ [fill-loc]] + (e) context'[[] \/ D] when no quantifier in context': + context[L /\ [fill-loc]] - (f) context'[([] \/ D) /\ C] when neither case (d) nor (e): + (f) context'[([] \/ D) /\ C] when neither case (d) nor (e): - (f1) If the pulled-out literal is protected in current scope, leave - it here. - context[L /\ [fill-loc]] + (f1) If the pulled-out literal is protected in current scope, leave + it here. + context[L /\ [fill-loc]] - (f2) when the nearest quantifier is existential: - pull-out(context'[([] /\ C) \/ (D /\ C)], [fill-loc]) + (f2) when the nearest quantifier is existential: + pull-out(context'[([] /\ C) \/ (D /\ C)], [fill-loc]) - (f3) context'[(([] \/ D) /\ C) \/ E] (when the nearest q. is universal): - pull-out(context'[([] \/ D \/ E) /\ (C \/ E)], [fill-loc]) + (f3) context'[(([] \/ D) /\ C) \/ E] (when the nearest q. is universal): + pull-out(context'[([] \/ D \/ E) /\ (C \/ E)], [fill-loc]) - The same rules are applied for subtasks, where we take - Var(subtask)=empty, and a subtask is protected only when not in - scope of any quantifier. + The same rules are applied for subtasks, where we take + Var(subtask)=empty, and a subtask is protected only when not in + scope of any quantifier. - 5: since the literals in conjunctions have been scrambled by the - zipping process, they are sorted into the order in which they have - been processed. + 5: since the literals in conjunctions have been scrambled by the + zipping process, they are sorted into the order in which they have + been processed. - Compact tentative specification of FFTNF(_<_): + Compact tentative specification of FFTNF(_<_): - Consider a graph whose nodes are literals of a formula and two - nodes are connected by an edge iff the literals share a - variable. Direct the edges so that there is no edge a->b for - b_<_a. The formula is in FFTNF(_<_) iff it is in TNF and the number - of quantifiers a literal is in scope of never decreases along an - edge, for some such directing of edges. + Consider a graph whose nodes are literals of a formula and two + nodes are connected by an edge iff the literals share a + variable. Direct the edges so that there is no edge a->b for + b_<_a. The formula is in FFTNF(_<_) iff it is in TNF and the number + of quantifiers a literal is in scope of never decreases along an + edge, for some such directing of edges. - FIXME: the above specification is not correct (too weak). + FIXME: the above specification is not correct (too weak). *) @@ -1017,87 +1017,90 @@ -(* ************************************************** +(** ************************************************** - {2 Computing the FF Separation} + {2 Computing the FF Separation} - Let FFSEP(F)(Phi) be - ((V1,F11,...,F1N_1,Guard1), ..., (VM,FM1,...,FMN_M,GuardM)) - where + Let FFSEP(PF,NF)(Phi) be + ((V1,F11,...,F1N_1,Guard1), ..., (VM,FM1,...,FMN_M,GuardM)) + where - * {F1, ..., FMN_M} are all fluent atoms that occur positively in Phi and - whose free variables are contained in the existential prefix of - PNF(Phi) (where PNF is "prenex normal, existential-first with - minimized alternation, form") plus the free variables of Phi + * {F1, ..., FMN_M} are all PF atoms that occur positively in Phi + and NF atoms that occur negatively in Phi, and whose free variables + are contained in the existential prefix of PNF(Phi) (where PNF is + "prenex normal, existential-first with minimized alternation, + form") plus the free variables of Phi - * (ex V1 (F11/\.../\F1N_1/\Guard1) \/ ... - \/ ex VM (FM1/\.../\FMN_M/\GuardM)) - is equivalent to Phi with minimal application of distributivity - (GuardI can contain disjunctions if they don't contain any of FIj) + * (ex V1 (F11/\.../\F1N_1/\Guard1) \/ ... + \/ ex VM (FM1/\.../\FMN_M/\GuardM)) + is equivalent to Phi with minimal application of distributivity + (GuardI can contain disjunctions if they don't contain any of FIj) - {3 Algorithm for computing the FFSEP(F)(Phi):} + {3 Algorithm for computing the FFSEP(PF,NF)(Phi):} - 1: Find the free variables FV and existential prefix variables - EV. Let "active atoms" be the positive atoms R(tup) with [R \in F] - and [tup \in EV+FV]. + 1: Find the free variables FV and existential prefix variables + EV. Let "active atoms" be the positive/negative atoms R(tup) with + [R \in PF/NF] and [tup \in EV+FV]. - 2: Flatten the formula Phi (using associativity), and push negation - inside (partial NN) only when there is an active atom in the subformula. - (Use [TProc (Not ...)] otherwise.) + 2: Flatten the formula Phi (using associativity), and push negation + inside (partial NN) only when there is an active atom in the subformula. + (Use [TProc (Not ...)] otherwise.) - 3: Loop using a forest initialized with a single tree of - the formula and empty atoms list. (The "already processed - literal" tag [TProc] will not be used.) The forest of trees with - atoms will constitute the answer ((F11,...,F1N_1,Guard1), ..., - (FM1,...,FMN_M,GuardM)). + 3: Loop using a forest initialized with a single tree of + the formula and empty atoms list. (The "already processed + literal" tag [TProc] will not be used.) The forest of trees with + atoms will constitute the answer ((F11,...,F1N_1,Guard1), ..., + (FM1,...,FMN_M,GuardM)). - 4: Find a positive atom R(tup) with [R \in F] and [tup \in EV], - building a zipper to it. (Preprocessing guarantees that all other - literals are packed into [TProc] during the main loop.) + 4: Find a positive/negative literal R(tup) with [R \in PF/NF] and + [tup \in EV], building a zipper to it. (Preprocessing guarantees + that all other literals are packed into [TProc] during the main + loop.) - The atom to be pulled out is replaced by T = And[], forming the - initial location (context[],[T]). + The literal to be pulled out is replaced by T = And[] (note the NN + form -- T is not under a negation), forming the initial location + (context[],[T]). - 5: In the final location, attach the pulled-out atom to the tree's - list. For a nonempty context location - pull-out(context[],[fill-loc]) by cases on context[]: + 5: In the final location, attach the pulled-out literal to the tree's + list. For a nonempty context location + pull-out(context[],[fill-loc]) by cases on context[]: - (a) context'[Qn.[]]: pull-out(context[],Qn.[fill-loc]) + (a) context'[Qn.[]]: pull-out(context[],Qn.[fill-loc]) - (b) context'[[] /\ C]: pull-out(context[],[fill-loc] /\ C) + (b) context'[[] /\ C]: pull-out(context[],[fill-loc] /\ C) - (c) context'[Qn.([] \/ D)]: + (c) context'[Qn.([] \/ D)]: - (c1) Qn existential: pull-out(context'[Qn.[] \/ Qn.D], [fill-loc]) + (c1) Qn existential: pull-out(context'[Qn.[] \/ Qn.D], [fill-loc]) - (c2) Qn universal, FV([fill-loc]) & Qn is empty: - pull-out(context'[[] \/ Qn.D], [fill-loc]) + (c2) Qn universal, FV([fill-loc]) & Qn is empty: + pull-out(context'[[] \/ Qn.D], [fill-loc]) - (c3) Qn universal, FV([fill-loc]) & Qn is not empty: - pull-out(context'[([] \/ Qn.D) /\ Qn.([fill-loc] \/ D)],[T]) + (c3) Qn universal, FV([fill-loc]) & Qn is not empty: + pull-out(context'[([] \/ Qn.D) /\ Qn.([fill-loc] \/ D)],[T]) - (d) context'[([] \/ D) /\ C] when the nearest quantifier is - existential or none: - pull-out(context'[([] /\ C) \/ (D /\ C)], [fill-loc]) + (d) context'[([] \/ D) /\ C] when the nearest quantifier is + existential or none: + pull-out(context'[([] /\ C) \/ (D /\ C)], [fill-loc]) - (e) context'[Qn.(([] \/ D) /\ C)] (when Qn is universal): - pull-out(context'[Qn.([] \/ D) /\ Qn.C], [fill-loc]) + (e) context'[Qn.(([] \/ D) /\ C)] (when Qn is universal): + pull-out(context'[Qn.([] \/ D) /\ Qn.C], [fill-loc]) - (f) context'[(([] \/ D) /\ C) \/ E] (when the nearest q. is universal): - pull-out(context'[([] \/ D \/ E) /\ (C \/ E)], [fill-loc]) + (f) context'[(([] \/ D) /\ C) \/ E] (when the nearest q. is universal): + pull-out(context'[([] \/ D \/ E) /\ (C \/ E)], [fill-loc]) - (g) [] \/ D: split the tree into [fill-loc] and D trees, sharing - atom lists, add the new atom to the [fill-loc] tree only + (g) [] \/ D: split the tree into [fill-loc] and D trees, sharing + atom lists, add the new atom to the [fill-loc] tree only - 6: V = FV(F11,...,FMN_M), erase quantification over V from - Guard1,...,GuardM. + 6: V = FV(F11,...,FMN_M), erase quantification over V from + Guard1,...,GuardM. *) (* Steps 1 and 2: Find free vars FV and existential prefix vars EV, flatten formula, build the tree while pushing negation inside (flatten if possible) if the subformula contains active atoms. *) -let ffsep_init frels phi = +let ffsep_init posi_frels nega_frels phi = let fvs = FormulaOps.free_vars phi in let rec aux neg evs = function | Ex (vs, phi) when not neg -> @@ -1111,12 +1114,12 @@ | Rel _ | RealExpr _ | Eq _ | In _ -> evs in let evs = aux false Vars.empty phi in let fevs = add_vars fvs evs in - let is_active rel vs = - Strings.mem rel frels && + let is_active neg rel vs = + (neg && Strings.mem rel nega_frels || + (not neg && Strings.mem rel posi_frels)) && array_for_all (fun v->Vars.mem v fevs) vs in let rec has_active neg = function - | Rel (rel, vs) when neg -> false - | Rel (rel, vs) -> is_active rel (Formula.var_tup vs) + | Rel (rel, vs) -> is_active neg rel (Formula.var_tup vs) | Not phi -> has_active (not neg) phi | And js | Or js -> List.exists (has_active neg) js | Ex (_, phi) | All (_, phi) -> has_active neg phi @@ -1127,7 +1130,8 @@ t=TProc (0, if neg then Not phi else phi)} else match phi with - | Rel _ as atom -> assert (not neg); + | Rel _ as atom -> + (* the atom is actually a literal, negative if [rel \in NF] *) {fvs=vars_of_list (FormulaOps.free_vars atom); t=TLit atom} | Not phi -> build (not neg) phi | Ex (vs, phi) -> @@ -1260,8 +1264,8 @@ (* Step 3, point (g) of step 5, step 6. *) -let ffsep frels phi = - let fvs, evs, tree = ffsep_init frels phi in +let ffsep posi_frels nega_frels phi = + let fvs, evs, tree = ffsep_init posi_frels nega_frels phi in (* step 3 *) let rec loop solved climbed = match climbed with [] -> solved Modified: trunk/Toss/Formula/FFTNF.mli =================================================================== --- trunk/Toss/Formula/FFTNF.mli 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Formula/FFTNF.mli 2011-03-23 00:41:31 UTC (rev 1379) @@ -36,5 +36,5 @@ val ffsep : - Aux.Strings.t -> Formula.formula -> + Aux.Strings.t -> Aux.Strings.t -> Formula.formula -> (Formula.fo_var list * Formula.formula list * Formula.formula) list Modified: trunk/Toss/Formula/FFTNFTest.ml =================================================================== --- trunk/Toss/Formula/FFTNFTest.ml 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Formula/FFTNFTest.ml 2011-03-23 00:41:31 UTC (rev 1379) @@ -32,8 +32,8 @@ (* Alpha-conversion of the above. *) let winQvwxyz_idempotent = "ex v ((Q(v) and (ex w2 ((R(v, w2) and Q(w2) and ex x2 ((R(w2, x2) and Q(x2) and ex y2 ((R(x2, y2) and Q(y2) and ex z2 ((R(y2, z2) and Q(z2))))))))) or ex w1 ((C(v, w1) and Q(w1) and ex x1 ((C(w1, x1) and Q(x1) and ex y1 ((C(x1, y1) and Q(y1) and ex z1 ((C(y1, z1) and Q(z1))))))))) or ex r0 ((R(v, r0) and ex w0 ((C(r0, w0) and Q(w0) and ex s0 ((R(w0, s0) and ex x0 ((C(s0, x0) and Q(x0) and ex t0 ((R(x0, t0) and ex y0 ((C(t0, y0) and Q(y0) and ex u0 ((R(y0, u0) and ex z0 ((C(u0, z0) and Q(z0))))))))))))))))) or ex r ((R(v, r) and ex w ((C(w, r) and Q(w) and ex s ((R(w, s) and ex x ((C(x, s) and Q(x) and ex t ((R(x, t) and ex y ((C(y, t) and Q(y) and ex u ((R(y, u) and ex z ((C(z, u) and Q(z))))))))))))))))))))" -let formula_of_guards frels phi = - let guards = FFTNF.ffsep frels phi in +let formula_of_guards posi_frels nega_frels phi = + let guards = FFTNF.ffsep posi_frels nega_frels phi in let parts = List.map (fun (avs, atoms, guard) -> if avs = [] then Formula.And (atoms @ [guard]) else @@ -107,14 +107,24 @@ (fun () -> assert_equal ~printer:(fun x->x) "true" - (Formula.str (formula_of_guards (Aux.strings_of_list ["P"; "Q"]) - (Formula.And []))); + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"; "Q"]) + Aux.Strings.empty (Formula.And []))); assert_equal ~printer:(fun x->x) "(P(x) and Q(y) and R(x, y))" - (Formula.str (formula_of_guards (Aux.strings_of_list ["P"; "Q"]) - (formula_of_str "R(x, y) and P(x) and Q(y)"))); + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"; "Q"]) + Aux.Strings.empty + (formula_of_str "R(x, y) and P(x) and Q(y)"))); + assert_equal ~printer:(fun x->x) + "(P(x) and Q(y) and R(x, y))" + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"]) + (Aux.strings_of_list ["Q"]) + (formula_of_str "R(x, y) and P(x) and not Q(y)"))); + ); @@ -133,13 +143,17 @@ (fun () -> assert_equal ~printer:(fun x->x) ~msg:"simple idempotence" winQzyx - (Formula.str (formula_of_guards (Aux.strings_of_list ["P"; "Q"]) - (formula_of_str winQzyx))); + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"; "Q"]) + Aux.Strings.empty + (formula_of_str winQzyx))); assert_equal ~printer:(fun x->x) ~msg:"reversing ff_tnf" "(ex z, y, x ((Q(z) and Q(y) and Q(x) and ex u0 ((ex v0 ((R(x, v0) and C(v0, y))) and R(y, u0) and C(u0, z))))) or ex z, y, x ((Q(z) and Q(y) and Q(x) and ex u ((ex v ((R(x, v) and C(y, v))) and R(y, u) and C(z, u))))) or ex z, y, x ((Q(z) and Q(y) and Q(x) and (R(x, y) and R(y, z)))) or ex z, y, x ((Q(z) and Q(y) and Q(x) and (C(x, y) and C(y, z)))))" - (Formula.str (formula_of_guards (Aux.strings_of_list ["P"; "Q"]) - (formula_of_str "ex z ((Q(z) and (ex y ((C(y, z) and Q(y) and ex x ((C(x, y) and Q(x))))) or ex y ((R(y, z) and Q(y) and ex x ((R(x, y) and Q(x))))) or ex u ((C(z, u) and ex y ((R(y, u) and Q(y) and ex v ((C(y, v) and ex x ((R(x, v) and Q(x))))))))) or ex u0 ((C(u0, z) and ex y ((R(y, u0) and Q(y) and ex v0 ((C(v0, y) and ex x ((R(x, v0) and Q(x))))))))))))"))); + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"; "Q"]) + Aux.Strings.empty + (formula_of_str "ex z ((Q(z) and (ex y ((C(y, z) and Q(y) and ex x ((C(x, y) and Q(x))))) or ex y ((R(y, z) and Q(y) and ex x ((R(x, y) and Q(x))))) or ex u ((C(z, u) and ex y ((R(y, u) and Q(y) and ex v ((C(y, v) and ex x ((R(x, v) and Q(x))))))))) or ex u0 ((C(u0, z) and ex y ((R(y, u0) and Q(y) and ex v0 ((C(v0, y) and ex x ((R(x, v0) and Q(x))))))))))))"))); ); @@ -224,24 +238,64 @@ (* only pulls out positive fluents *) assert_equal ~printer:(fun x->x) ~msg:"#1" "(ex y, z (((not R(x, y)) and (not Q(z)))) or ex x ((P(x) and ex y, z ((C(y, z) and (not Q(z)))))))" - (Formula.str (formula_of_guards (Aux.strings_of_list ["P"; "Q"]) - (formula_of_str "ex x, y, z ((not R(x,y) or (P(x) and C(y,z))) and not Q(z))"))); + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"; "Q"]) + Aux.Strings.empty + (formula_of_str "ex x, y, z ((not R(x,y) or (P(x) and C(y,z))) and not Q(z))"))); assert_equal ~printer:(fun x->x) ~msg:"#2" "ex z ((Q(z) and ex x, y ((not (R(x, y) and (P(x) or C(y, z)))))))" - (Formula.str (formula_of_guards (Aux.strings_of_list ["P"; "Q"]) - (formula_of_str "ex x, y, z not ((R(x,y) and (P(x) or C(y,z))) or not Q(z))"))); + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"; "Q"]) + Aux.Strings.empty + (formula_of_str "ex x, y, z not ((R(x,y) and (P(x) or C(y,z))) or not Q(z))"))); (* TODO? simplify the result *) assert_equal ~printer:(fun x->x) ~msg:"#3" "(ex y ((C(y, z) and R(x, y))) or ex z ((Q(z) and ex y (true))) or ex x ((P(x) and ex y (R(x, y)))))" - (Formula.str (formula_of_guards (Aux.strings_of_list ["P"; "Q"]) - (formula_of_str "ex x, y, z ((R(x,y) and (P(x) or C(y,z))) or Q(z))"))); + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"; "Q"]) + Aux.Strings.empty + (formula_of_str "ex x, y, z ((R(x,y) and (P(x) or C(y,z))) or Q(z))"))); assert_equal ~printer:(fun x->x) ~msg:"#4" "(ex y ((C(y, z) and R(x, y) and C(x, z))) or ex z ((Q(z) and ex y (C(x, z)))) or ex x ((P(x) and ex y ((R(x, y) and C(x, z))))))" - (Formula.str (formula_of_guards (Aux.strings_of_list ["P"; "Q"]) - (formula_of_str "ex x, y, z (C(x, z) and ((R(x,y) and (P(x) or C(y,z))) or Q(z)))"))); + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"; "Q"]) + Aux.Strings.empty + (formula_of_str "ex x, y, z (C(x, z) and ((R(x,y) and (P(x) or C(y,z))) or Q(z)))"))); + + (* interpretation warning: in cases below, pulled-out "Q" in the + result represents "not Q" actually (a negative literal) *) + assert_equal ~printer:(fun x->x) ~msg:"#5" + "(ex z ((Q(z) and ex y ((not R(x, y))))) or ex z, x ((P(x) and Q(z) and ex y (C(y, z)))))" + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"]) + (Aux.strings_of_list ["Q"]) + (formula_of_str "ex x, y, z ((not R(x,y) or (P(x) and C(y,z))) and not Q(z))"))); + + assert_equal ~printer:(fun x->x) ~msg:"#6" + "ex x, y, z ((not ((R(x, y) and (P(x) or C(y, z))) or (not Q(z)))))" + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"]) + (Aux.strings_of_list ["Q"]) + (formula_of_str "ex x, y, z not ((R(x,y) and (P(x) or C(y,z))) or not Q(z))"))); + + (* distributes to extract P, not because of Q *) + assert_equal ~printer:(fun x->x) ~msg:"#7" + "(ex y, z ((Q(z) or (C(y, z) and R(x, y)))) or ex x ((P(x) and ex y, z (R(x, y)))))" + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"]) + (Aux.strings_of_list ["Q"]) + (formula_of_str "ex x, y, z ((R(x,y) and (P(x) or C(y,z))) or Q(z))"))); + + assert_equal ~printer:(fun x->x) ~msg:"#8" + "(ex y ((C(y, z) and R(x, y) and C(x, z))) or ex z ((Q(z) and ex y (C(x, z)))) or ex x ((P(x) and ex y ((R(x, y) and C(x, z))))))" + (Formula.str ( + formula_of_guards (Aux.strings_of_list ["P"]) + (Aux.strings_of_list ["Q"]) + (formula_of_str "ex x, y, z (C(x, z) and ((R(x,y) and (P(x) or C(y,z))) or not Q(z)))"))); + ); "ff_tnf: simple subtasks" >:: Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Formula/FormulaOps.ml 2011-03-23 00:41:31 UTC (rev 1379) @@ -190,6 +190,96 @@ gmap.map_Sum vs (map_formula gmap guard) (map_real_expr gmap expr) +(* Generalized fold over formula and real expression types. *) +type 'a formula_and_expr_fold = { + fold_Rel : string -> fo_var array -> 'a; + fold_Eq : fo_var -> fo_var -> 'a; + fold_In : fo_var -> mso_var -> 'a; + fold_RealExpr : 'a -> sign_op -> 'a; + fold_Not : 'a -> 'a; + fold_And : 'a -> 'a -> 'a; + fold_Or : 'a -> 'a -> 'a; + fold_Ex : var list -> 'a -> 'a; + fold_All : var list -> 'a -> 'a; + + fold_RVar : string -> 'a; + fold_Const : float -> 'a; + fold_Times : 'a -> 'a -> 'a; + fold_Plus : 'a -> 'a -> 'a; + fold_Fun : string -> fo_var -> 'a; + fold_Char : 'a -> 'a; + fold_Sum : fo_var list -> 'a -> 'a -> 'a +} + +let make_fold union empty = { + fold_Rel = (fun _ _ -> empty); + fold_Eq = (fun _ _ -> empty); + fold_In = (fun _ _ -> empty); + fold_RealExpr = (fun expr _ -> expr); + fold_Not = (fun phi -> phi); + fold_And = union; + fold_Or = union; + fold_Ex = (fun _ phi -> phi); + fold_All = (fun _ phi -> phi); + + fold_RVar = (fun _ -> empty); + fold_Const = (fun _ -> empty); + fold_Times = union; + fold_Plus = union; + fold_Fun = (fun _ _ -> empty); + fold_Char = (fun phi -> phi); + fold_Sum = (fun _ guard expr -> union guard expr) +} + +open Aux.BasicOperators + +let rec fold_formula gfold = function + | Rel (rel, args) -> gfold.fold_Rel rel args + | Eq (x, y) -> gfold.fold_Eq x y + | In (x, ys) -> gfold.fold_In x ys + | RealExpr (expr, sign) -> + gfold.fold_RealExpr (fold_real_expr gfold expr) sign + | Not phi -> gfold.fold_Not (fold_formula gfold phi) + | And [] -> + gfold.fold_RealExpr (fold_real_expr gfold (Const 1.)) GZero + | And [conj] -> fold_formula gfold conj + | And (conj::conjs) -> + List.fold_right (gfold.fold_And -| fold_formula gfold) conjs + (fold_formula gfold conj) + | Or [] -> + gfold.fold_RealExpr (fold_real_expr gfold (Const 1.)) LZero + | Or [disj] -> fold_formula gfold disj + | Or (disj::disjs) -> + List.fold_right (gfold.fold_Or -| fold_formula gfold) disjs + (fold_formula gfold disj) + | Ex (vs, phi) -> gfold.fold_Ex vs (fold_formula gfold phi) + | All (vs, phi) -> gfold.fold_All vs (fold_formula gfold phi) + +and fold_real_expr gfold = function + | RVar v -> gfold.fold_RVar v + | Const c -> gfold.fold_Const c + | Times (expr1, expr2) -> + gfold.fold_Times (fold_real_expr gfold expr1) (fold_real_expr gfold expr2) + | Plus (expr1, expr2) -> + gfold.fold_Plus (fold_real_expr gfold expr1) (fold_real_expr gfold expr2) + | Fun (f, v) -> gfold.fold_Fun f v + | Char phi -> gfold.fold_Char (fold_formula gfold phi) + | Sum (vs, guard, expr) -> + gfold.fold_Sum vs (fold_formula gfold guard) (fold_real_expr gfold expr) + +let rels_signs_fold = + {make_fold + (fun (posi1,nega1) (posi2,nega2) -> + Aux.Strings.union posi1 posi2, Aux.Strings.union nega1 nega2) + (Aux.Strings.empty, Aux.Strings.empty) with + fold_Rel = (fun rel _ -> + Aux.Strings.singleton rel, Aux.Strings.empty); + fold_Not = (fun (posi,nega) -> nega,posi)} + +(* Find all positively and negatively occurring relations. *) +let rels_signs = fold_formula rels_signs_fold +let rels_signs_expr = fold_real_expr rels_signs_fold + (* Map [f] to all literals (i.e. atoms or not(atom)'s) in the given formula. Preserves order of subformulas. *) let rec map_to_literals f g = function @@ -733,7 +823,13 @@ let sl = subst_l x in Ex (get_fo sl, subst_vars sl f) | All (x, f) when List.for_all is_fo x -> let sl = subst_l x in All (get_fo sl, subst_vars sl f) - | psi -> print_endline ("PSi: " ^ (Formula.str psi)); psi in + | psi -> + (* {{{ log entry *) + if !debug_level > 1 then ( + print_endline ("PSi: " ^ (Formula.str psi)); + ); + (* }}} *) + psi in if do_formula then Char (simplify ~do_pnf ~do_re:true ~ni new_phi) else Char new_phi Modified: trunk/Toss/Formula/FormulaOps.mli =================================================================== --- trunk/Toss/Formula/FormulaOps.mli 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Formula/FormulaOps.mli 2011-03-23 00:41:31 UTC (rev 1379) @@ -47,6 +47,37 @@ val map_formula : formula_and_expr_map -> formula -> formula val map_real_expr : formula_and_expr_map -> real_expr -> real_expr +(** Generalized fold over formula and real expression types. *) +type 'a formula_and_expr_fold = { + fold_Rel : string -> fo_var array -> 'a; + fold_Eq : fo_var -> fo_var -> 'a; + fold_In : fo_var -> mso_var -> 'a; + fold_RealExpr : 'a -> sign_op -> 'a; + fold_Not : 'a -> 'a; + fold_And : 'a -> 'a -> 'a; + fold_Or : 'a -> 'a -> 'a; + fold_Ex : var list -> 'a -> 'a; + fold_All : var list -> 'a -> 'a; + + fold_RVar : string -> 'a; + fold_Const : float -> 'a; + fold_Times : 'a -> 'a -> 'a; + fold_Plus : 'a -> 'a -> 'a; + fold_Fun : string -> fo_var -> 'a; + fold_Char : 'a -> 'a; + fold_Sum : fo_var list -> 'a -> 'a -> 'a +} + +val make_fold : ('a -> 'a -> 'a) -> 'a -> 'a formula_and_expr_fold + +(** Fold the structure using the operations. (Not tail-recursive.) *) +val fold_formula : 'a formula_and_expr_fold -> formula -> 'a +val fold_real_expr : 'a formula_and_expr_fold -> real_expr -> 'a + +(** Find all positively and negatively occurring relations. *) +val rels_signs : formula -> Aux.Strings.t * Aux.Strings.t +val rels_signs_expr : real_expr -> Aux.Strings.t * Aux.Strings.t + (** Map [f] to all literals (i.e. atoms or not(atom)'s) in the given formula. Preserves order of subformulas. *) val map_to_literals : (formula -> formula) -> (real_expr -> real_expr) -> Modified: trunk/Toss/GGP/GameSimpl.ml =================================================================== --- trunk/Toss/GGP/GameSimpl.ml 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/GGP/GameSimpl.ml 2011-03-23 00:41:31 UTC (rev 1379) @@ -135,15 +135,11 @@ let signat = Structure.rel_signature struc in let nelems = Structure.Elems.cardinal struc.Structure.elements in let tcard tups = Tups.cardinal tups in - let fluents = - Aux.unique_sorted - (Aux.concat_map (fun (_,r) -> - DiscreteRule.fluents r.ContinuousRule.compiled) - game.Arena.rules) in + let fluents = Arena.all_fluents game in (* {{{ log entry *) if !debug_level > 0 then ( Printf.printf "GameSimpl: fluents = %s\n%!" - (String.concat ", " fluents) + (String.concat ", " (Aux.Strings.elements fluents)) ); (* }}} *) (* 1 *) @@ -175,7 +171,7 @@ let ntups2 = tcard rel2_tups in if ntups >= ntups2 && ntups + ntups2 = Aux.int_pow nelems arity && - not (List.mem rel2 fluents) && + not (Aux.Strings.mem rel2 fluents) && Tups.is_empty (Tups.inter rel_tups rel2_tups) then ( (* {{{ log entry *) @@ -245,7 +241,7 @@ let rel2, _ = List.find (fun (rel2, arity2) -> arity = arity2 && - not (List.mem rel2 fluents || + not (Aux.Strings.mem rel2 fluents || List.mem_assoc rel2 game.Arena.defined_rels) && included_in rel1 rel2 && included_in rel2 rel1 ) signat in @@ -259,10 +255,10 @@ | None -> rel | Some spec -> DiscreteRule.orig_rel_of rel in rel <> "" && - not (List.mem rel fluents) && + not (Aux.Strings.mem rel fluents) && not (List.mem_assoc rel game.Arena.defined_rels) && not (List.exists (fun (_,(rel2,_)) -> rel2=rel) equivalent) && - not (List.mem (fst (List.assoc rel equivalent)) fluents || + not (Aux.Strings.mem (fst (List.assoc rel equivalent)) fluents || List.mem_assoc (fst (List.assoc rel equivalent)) game.Arena.defined_rels) in @@ -414,8 +410,8 @@ match phi1, phi2 with | _ when phi1 = phi2 -> true | Rel (rel1, args1), Rel (rel2, args2) when args1 = args2 -> - not (List.mem rel1 fluents) && - not (List.mem rel2 fluents) && + not (Aux.Strings.mem rel1 fluents) && + not (Aux.Strings.mem rel2 fluents) && included_in rel1 rel2 | _ -> false in let game = @@ -563,7 +559,7 @@ (* the step of 3d *) let gluable rel = - not (List.mem rel fluents) && + not (Aux.Strings.mem rel fluents) && not (List.mem_assoc rel game.Arena.defined_rels) in let glue_phi = FormulaOps.map_formula {FormulaOps.identity_map with @@ -748,7 +744,7 @@ else DiscreteRule.orig_rel_of rel in let res = (not keep_predicates || List.assoc rel signat > 1) && - not (List.mem rel fluents) && + not (Aux.Strings.mem rel fluents) && not (List.mem_assoc rel game.Arena.defined_rels) && not (Aux.Strings.mem rel used_rels) in (* {{{ log entry *) Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-22 18:22:54 UTC (rev 1378) +++ trunk/Toss/Play/Heuristic.ml 2011-03-23 00:41:31 UTC (rev 1379) @@ -1,214 +1,238 @@ -(* Generate a heuristic from a payoff. +(** Generate a heuristic from a payoff. - Input: a set of relations F whose instances can be altered during a - game; initial state structure S of the game; payoff of the game for a - player; advancement value ratio AR; for monotonic games, a mapping - from fluents to their preconditions (in the form of defined relations). + Input: a set of relations F whose instances can be altered during a + game; initial state structure S of the game; payoff of the game for a + player; advancement value ratio AR; for monotonic games, a mapping + from fluents to their preconditions (in the form of defined relations). - Return a homomorphic image of the payoff which transforms Char(Phi) - into H(Phi). + Return a homomorphic image of the payoff which transforms Char(Phi) + into H(Phi). - The heuristic is generated differently for monotonic and - nonmonotonic games. General case: + The heuristic is generated differently for monotonic and + nonmonotonic games. TODO: make the monotonic/nonmonotonic decision + at the level of subexpressions instead of the level of the whole + game. - H(Phi) = Alg(FFTNF(promote relations F) of Phi', True) - where Phi' = ExpandedForm(F, S, FFTNF(promote relations F) of Phi) + Fluents are relations that are changed by rules. Distinguish + two subclasses of fluents: positive fluents occur only positively on + RHSes (are only added) and only negatively on LHSes and in + preconditions, and negative fluents only negatively on RHSes (are only + deleted) and only positively on LHSes and in preconditions. (Call the + remaining fluents indefinite.) A game is monotonic, if its indefinite + fluents don't occur in any payoff of the game. - Since formula transformations involved in generating the heuristic - are costly, we use the parsimony model from FFTNF: + The monotonic-case heuristic is computed by pulling out + positive/negative occurrences of positive/negative fluents from + the formula; building a guard by substituting these by + preconditions (of their addition / deletion) and conjoining with + the rest of the formula; and counting the number of + positive/negative fluents that are already present/absent (as + required) under each match of the guard. - (1) at parsimony level 1 (PARL1), we do not compute FFTNF prior to - expanding the formula: + General case -- game is not monotonic: - H(Phi) = Alg(FFTNF(promote relations F) of Phi', True) - where Phi' = ExpandedForm(F, S, Phi) + H(Phi) = Alg(FFTNF(promote relations F) of Phi', True) + where Phi' = ExpandedForm(F, S, FFTNF(promote relations F) of Phi) - (2) at parsimony level 2 (PARL2), we do not expand the formula: + Since formula transformations involved in generating the heuristic + are costly, we use the parsimony model from FFTNF: - H(Phi) = Alg(FFTNF(promote relations F) of Phi, True) + (1) at parsimony level 1 (PARL1), we do not compute FFTNF prior to + expanding the formula: - Monotonic case (see also the definition of FFSEP(F) in {!FFTNF} - module): + H(Phi) = Alg(FFTNF(promote relations F) of Phi', True) + where Phi' = ExpandedForm(F, S, Phi) - H(Phi) = - Sum(V1, (F11\/...\/F1N_1) /\ Pre(F11/\.../\F1N_1) /\ Guard1, - CharSum(F11, ..., F1N_1)) + - ... + - Sum(VM, (FM1\/...\/FMN_M) /\ Pre(FM1/\.../\FMN_M) /\ GuardM, - CharSum(FM1, ..., FMN_M)) - where: + (2) at parsimony level 2 (PARL2), we do not expand the formula: - * CharSum(Fi1, ..., FiN_i) = f(Char(Fi1) + ... + Char(FiN_i), N_i) - CharSum() = 1 for N_i = 0 + H(Phi) = Alg(FFTNF(promote relations F) of Phi, True) - * f(n,N) = (1 + AR + ... + AR^n) / (1+AR+...+AR^N); f(0,N) = 0 - simpler variant: f(n,N) = n^AR/N^AR. + Monotonic case (see also the definition of FFSEP(PF,NF) in {!FFTNF} + module): - * Pre() is the substitution of fluent precondition relations for - fluents + H(Phi) = + Sum(V1, (F11\/...\/F1N_1) /\ Pre(F11/\.../\F1N_1) /\ Guard1, + CharSum(F11, ..., F1N_1)) + + ... + + Sum(VM, (FM1\/...\/FMN_M) /\ Pre(FM1/\.../\FMN_M) /\ GuardM, + CharSum(FM1, ..., FMN_M)) + where: - * (V1,F11,...,F1N_1,Guard1; ...; VM,FM1,...,FMN_M,GuardM) = FFSEP(F)(Phi) + * CharSum(Fi1, ..., FiN_i) = f(Char(Fi1) + ... + Char(FiN_i), N_i) + CharSum() = 1 for N_i = 0 - ** {F1, ..., FMN_M} are all fluent atoms that occur positively in Phi and - whose free variables are contained in the existential prefix of - PNF(Phi) (where PNF is "prenex normal, existential-first with - minimized alternation, form") + * f(n,N) = (1 + AR + ... + AR^n) / (1+AR+...+AR^N); f(0,N) = 0 + simpler variant: f(n,N) = n^AR/N^AR. - ** (ex V1 (F11/\.../\F1N_1/\Guard1) \/ ... - \/ ex VM (FM1/\.../\FMN_M/\GuardM)) - is equivalent to Phi with minimal application of distributivity - (GuardI can contain disjunctions if they don't contain any of FIj) + * Pre() is the substitution of preconditions of adding/deleting + positive/negative fluents for the fluents - ********** + * (V1,F11,...,F1N_1,Guard1; ...; VM,FM1,...,FMN_M,GuardM) + = FFSEP(PF,NF)(Phi) - Algorithm Alg(Ex(V,Phi), Guard0): + ** PF are positive fluents, NF are negative fluents of the game - 1: Segregate Phi into Guard/\Subgoals where Guard is a boolean - combination of atoms and quantified subformulas - universal-in-positive / existential-in-negative positions, and each - conjunct in Subgoals contains a positive occurrence of existential - quantifier (not in scope of any other quantifier). + ** {F1, ..., FMN_M} are all positive/negative fluent atoms that + occur positively/negatively in Phi and whose free variables are + contained in the existential prefix of PNF(Phi) (where PNF is + "prenex normal, existential-first with minimized alternation, + form") - 2: Reduce Subgoals to DNF treating quantified subformulas opaquely. + ** (ex V1 (F11/\.../\F1N_1/\Guard1) \/ ... + \/ ex VM (FM1/\.../\FMN_M/\GuardM)) + is equivalent to Phi with minimal application of distributivity + (GuardI can contain disjunctions if they don't contain any of FIj) - 3: Each disjunct Dj is a conjunction of literals and existentially - quantified formulas. Split the conjuncts into existential - quantifications {Ex(Vj1,Ej1), ..., Ex(Vjn,Ejn)} and others - (Gj). Let + ********** - Rji=Alg(Ex(Vji,Eji),Gj) + Algorithm Alg(Ex(V,Phi), Guard0): - and Wji be the weight assigned to Vji (see below) and PWji be the - total weight of each root-leaf path in Rji. Let Rji' be Rji with - all weights rescaled proportionally (Wji->Wji', but also other - weights nested deeper in Rji) so that all PWji' are - equal. Result for a disjunct j: + 1: Segregate Phi into Guard/\Subgoals where Guard is a boolean + combination of atoms and quantified subformulas + universal-in-positive / existential-in-negative positions, and each + conjunct in Subgoals contains a positive occurrence of existential + quantifier (not in scope of any other quantifier). - DRj = normalized_mult(Rj1', ..., Rjn') + 2: Reduce Subgoals to DNF treating quantified subformulas opaquely. - where + 3: Each disjunct Dj is a conjunction of literals and existentially + quantified formulas. Split the conjuncts into existential + quantifications {Ex(Vj1,Ej1), ..., Ex(Vjn,Ejn)} and others + (Gj). Let - normalized_mult(x1,..,xn) = n^(n-1)*x1*...*xn / (x1+...+xn)^(n-1) + Rji=Alg(Ex(Vji,Eji),Gj) - In each disjunct n>0, but Subgoals can be empty (m=0). + and Wji be the weight assigned to Vji (see below) and PWji be the + total weight of each root-leaf path in Rji. Let Rji' be Rji with + all weights rescaled proportionally (Wji->Wji', but also other + weights nested deeper in Rji) so that all PWji' are + equal. Result for a disjunct j: - 4: Return + DRj = normalized_mult(Rj1', ..., Rjn') - Sum(V, Guard0/\Guard, W + DR1 + ... + DRm) + where - and PW=W+PW11', where W is Max_ji(Wji')/AR; the weights are - assigned such that each path from root to leaf has the same weight - (by rescaling Rji->Rji'). The (maximal) ratio of weight change towards - the leaves (the "advancement value ratio") is a parameter (bigger - means more stubborn, smaller means more undirected play). + normalized_mult(x1,..,xn) = n^(n-1)*x1*...*xn / (x1+...+xn)^(n-1) - ********** + In each disjunct n>0, but Subgoals can be empty (m=0). - Tentative compact specification of ExpandedDescription: + 4: Return - ExpandedDescription(S, T) of a set of substitutions T(x1,...,xn) - (which can be seen as a set of n-tuples interpreting T in S) over - elements a structure S is built from minimal sets of atoms Psi over - variables (x1,...,xn,y1,...,yk) as "\/ ex y1,...,yk /\Psi" such - that every "ex y1,...,yk /\Psi" is equivalent to T(x1,...,xn) in S - (minimality means that for no proper subset Psi' of Psi is "ex - y1,...,yk /\Psi'" equivalent to T(x1,...,xn) in - S). ExpandedDescription may not exist for some pairs (S,T). + Sum(V, Guard0/\Guard, W + DR1 + ... + DRm) - Maximal expanded description is an expanded description which - cannot be extended with a disjunct nonequivalent to disjuncts - actually present in it. The algorithm falls short of maximality - because of parts marked as GREEDY (for the same reason the - algorithm is not complete). + and PW=W+PW11', where W is Max_ji(Wji')/AR; the weights are + assigned such that each path from root to leaf has the same weight + (by rescaling Rji->Rji'). The (maximal) ratio of weight change towards + the leaves (the "advancement value ratio") is a parameter (bigger + means more stubborn, smaller means more undirected play). - By ExpandedDescription(F, S, psi) (where psi is a formula not - containing relations from F) we will denote - ExpandedDescription(S',T) where T is a set of substitutions - satisfying psi in S', and S' is S truncated to relations outside F. - - Algorithm for finding the ExpandedForm(F,S,Phi): + ********** - Let Phi=CDE(psi_1,...,psi_m) be a - conjunctive-disjunctive-existential combination of - (psi_1,...,psi_m), where each psi_i is either an atom, or has a - conjunction, a negation or a quantification as its root. + Tentative compact specification of ExpandedDescription: - ExpandedForm(F,S,Phi) = CDE(ED(psi_1), ..., ED(psi_m)), where - "ED(psi) = ExpandedDescription(F,S,psi)" if psi does not contain - relations from F and ExpandedDescription(F,S,psi) exists, otherwise - "ED(psi_1 and ... and psi_n) = ED(psi_1) and ... and ED(psi_n)", - "ED(ex x psi) = ex x ED(psi)", in other cases "ED(psi) = psi". - (Where psi is either a formula or a set of all satisfying - substitutions for psi in S, depending on context.) - - Algorithm for finding ExpandedDescription(F, S, T): + ExpandedDescription(S, T) of a set of substitutions T(x1,...,xn) + (which can be seen as a set of n-tuples interpreting T in S) over + elements a structure S is built from minimal sets of atoms Psi over + variables (x1,...,xn,y1,...,yk) as "\/ ex y1,...,yk /\Psi" such + that every "ex y1,...,yk /\Psi" is equivalent to T(x1,...,xn) in S + (minimality means that for no proper subset Psi' of Psi is "ex + y1,...,yk /\Psi'" equivalent to T(x1,...,xn) in + S). ExpandedDescription may not exist for some pairs (S,T). - Build a forest of atoms as follows: + Maximal expanded description is an expanded description which + cannot be extended with a disjunct nonequivalent to disjuncts + actually present in it. The algorithm falls short of maximality + because of parts marked as GREEDY (for the same reason the + algorithm is not complete). - (0) For a path in a tree, maintain substitutions that satisfy the - path atoms, partitioned into classes of substitutions extending a - substitution satisfying T (called "inside classes" below), plus a - class of substitutions that do not satisfy T (called "outside - class" below). - - (a) To add an atom of a relation R to the forest: Take the - pre-image (i.e. one-to-many) of the tuples of the relation R - through a substitution, add new variables if they are not yet in - substitutions, and take cartesian product. + By ExpandedDescription(F, S, psi) (where psi is a formula not + containing relations from F) we will denote + ExpandedDescription(S',T) where T is a set of substitutions + satisfying psi in S', and S' is S truncated to relations outside F. + + Algorithm for finding the ExpandedForm(F,S,Phi): - (b) Filter the tuples so that if new variables are being added (not - yet in substitutions), each tuple has some old variable and new - variables form "triangluar matrix" (reducing "repetition modulo - renaming variables"). + Let Phi=CDE(psi_1,...,psi_m) be a + conjunctive-disjunctive-existential combination of + (psi_1,...,psi_m), where each psi_i is either an atom, or has a + conjunction, a negation or a quantification as its root. - (c) Filter the tuples so that all new variables are present in each - tuple (even if new variabl... [truncated message content] |
From: <luk...@us...> - 2011-03-22 18:23:01
|
Revision: 1378 http://toss.svn.sourceforge.net/toss/?rev=1378&view=rev Author: lukaszkaiser Date: 2011-03-22 18:22:54 +0000 (Tue, 22 Mar 2011) Log Message: ----------- Extending real expr simplification to rename sum-variables. Modified Paths: -------------- trunk/Toss/Formula/FormulaOps.ml trunk/Toss/Formula/FormulaOps.mli trunk/Toss/Formula/FormulaOpsTest.ml trunk/Toss/Solver/SolverTest.ml trunk/Toss/WebClient/Login.js trunk/Toss/WebClient/index.html trunk/Toss/www/xsl/include/common.xsl Modified: trunk/Toss/Formula/FormulaOps.ml =================================================================== --- trunk/Toss/Formula/FormulaOps.ml 2011-03-22 09:04:34 UTC (rev 1377) +++ trunk/Toss/Formula/FormulaOps.ml 2011-03-22 18:22:54 UTC (rev 1378) @@ -29,6 +29,7 @@ match psi with Rel _ | Eq _ | In _ | RealExpr _ as atom -> if neg then Not atom else atom | Not phi -> if neg then nnf ~neg:false phi else nnf ~neg:true phi + | And [f] | Or [f] -> nnf ~neg f | And (flist) when neg -> Or (List.map (nnf ~neg:true) flist) | And (flist) -> And (List.map (nnf ~neg:false) flist) | Or (flist) when neg -> And (List.map (nnf ~neg:true) flist) @@ -320,7 +321,8 @@ | Sum (vs, phi, r) -> let in_vs (s, _) = List.exists (fun v -> var_str v = s) vs in let new_vs = List.filter (fun x -> not (in_vs x)) subst in - if new_vs = [] then Sum(vs, phi, r) else Sum(vs, subst_vars new_vs phi, r) + if new_vs = [] then Sum(vs, phi, r) else + Sum(vs, subst_vars new_vs phi, subst_vars_expr new_vs r) (* Helper function: strip digits from string end except if it starts with one. *) let rec strip_digits s = @@ -675,7 +677,7 @@ (* Recursively simplify a formula *) -let rec simplify ?(do_pnf=false) ?(do_re=true) phi = +let rec simplify ?(do_pnf=false) ?(do_re=true) ?(ni=0) phi = let do_simplify phi = let (ids, rev_ids, free_id) = (Hashtbl.create 7, Hashtbl.create 7, ref 1) in let boolean_phi = BoolFormula.bool_formula_of_formula_arg phi (ids, rev_ids, free_id) in @@ -687,7 +689,7 @@ Rel _ | Eq _ | In _ as atom -> atom | RealExpr (re, sgn) as rx -> if do_re then - RealExpr (simplify_re ~do_pnf ~do_formula:true re, sgn) + RealExpr (simplify_re ~do_pnf ~do_formula:true ~ni re, sgn) else rx | Not psi -> do_simplify (Not (simplify_subformulas psi)) | And (flist) -> do_simplify (And (List.rev_map simplify_subformulas flist)) @@ -719,15 +721,34 @@ ) else simplified_prenex_phi -and simplify_re ?(do_pnf=false) ?(do_formula=true) = function +and simplify_re ?(do_pnf=false) ?(do_formula=true) ?(ni=0) = function | RVar _ | Const _ | Fun _ as atom -> atom | Char phi -> - if do_formula then Char (simplify ~do_pnf ~do_re:true phi) else Char phi + let name_i = ref ni in + let namef () = incr name_i; string_of_int !name_i in + let subst_l l = List.map (fun v -> (var_str v, "fo__cx_" ^ namef())) l in + let get_fo sl = List.map (fun (_, v) -> var_of_string v) sl in + let new_phi = match nnf phi with + | Ex (x, f) when List.for_all is_fo x -> + let sl = subst_l x in Ex (get_fo sl, subst_vars sl f) + | All (x, f) when List.for_all is_fo x -> + let sl = subst_l x in All (get_fo sl, subst_vars sl f) + | psi -> print_endline ("PSi: " ^ (Formula.str psi)); psi in + if do_formula then + Char (simplify ~do_pnf ~do_re:true ~ni new_phi) + else Char new_phi | Sum (l, phi, re) -> - let re_simp = simplify_re ~do_pnf ~do_formula re in - if do_formula then - Sum (l, simplify ~do_pnf ~do_re:true phi, re_simp) - else Sum (l, phi, re_simp) + let name_i = ref ni in + let namef () = incr name_i; string_of_int !name_i in + let subst_l = List.map (fun v -> (var_str v, "fo__sx_" ^ namef())) l in + let new_re = subst_vars_expr subst_l re in + let re_simp = simplify_re ~do_pnf ~do_formula ~ni:!name_i new_re in + let new_phi = subst_vars subst_l phi in + let phi_simp = + if do_formula then simplify ~do_pnf ~do_re:true ~ni:!name_i new_phi else + new_phi in + Sum (List.map (fun (_, v) -> fo_var_of_string v) subst_l, + phi_simp, re_simp) | Plus _ | Times (Const _, _) | Times (_, Const _) as x -> let rec get_linear = function | Plus (p, q) -> List.rev_append (get_linear p) (get_linear q) @@ -743,18 +764,21 @@ | (c, x) :: ls when c = 0. -> collect_linear ls | (c, x) :: (d, y) :: ls when x = y -> collect_linear ((c +. d, x) :: ls) - | x :: y :: ls -> Plus (one x, collect_linear (y :: ls)) in + | x :: y :: ls -> + let rest = collect_linear (y :: ls) in + if one x = Const 0. then rest else if rest = Const 0. then one x else + Plus (one x, rest) in let l = get_linear x in let cmp (c, x) (d, y) = let x = Pervasives.compare x y in if x <> 0 then x else if c > d then 1 else if d > c then -1 else 0 in - let s = List.map (fun (c, r) -> (c, simplify_re ~do_pnf ~do_formula r)) l in + let s = List.map (fun (c,r)->(c,simplify_re ~do_pnf ~do_formula ~ni r)) l in collect_linear (List.sort cmp s) | Times (p, q) -> - let simp_p = simplify_re ~do_pnf ~do_formula p in - let simp_q = simplify_re ~do_pnf ~do_formula q in + let simp_p = simplify_re ~do_pnf ~do_formula ~ni p in + let simp_q = simplify_re ~do_pnf ~do_formula ~ni q in if simp_p = p && simp_q = q then Times (p, q) else - simplify_re ~do_pnf ~do_formula (Times (simp_p, simp_q)) + simplify_re ~do_pnf ~do_formula ~ni (Times (simp_p, simp_q)) (* Flatten "and"s and "or"s in a formula -- Modified: trunk/Toss/Formula/FormulaOps.mli =================================================================== --- trunk/Toss/Formula/FormulaOps.mli 2011-03-22 09:04:34 UTC (rev 1377) +++ trunk/Toss/Formula/FormulaOps.mli 2011-03-22 18:22:54 UTC (rev 1378) @@ -113,10 +113,11 @@ (** {2 Simplification} *) (** Recursively simplify a formula *) -val simplify : ?do_pnf : bool -> ?do_re : bool -> formula -> formula +val simplify : ?do_pnf : bool -> ?do_re : bool -> ?ni:int -> formula -> formula (** Recursively simplify a real expr *) -val simplify_re : ?do_pnf: bool -> ?do_formula: bool -> real_expr -> real_expr +val simplify_re : ?do_pnf: bool -> ?do_formula: bool -> ?ni:int -> + real_expr -> real_expr val pnf : formula -> formula Modified: trunk/Toss/Formula/FormulaOpsTest.ml =================================================================== --- trunk/Toss/Formula/FormulaOpsTest.ml 2011-03-22 09:04:34 UTC (rev 1377) +++ trunk/Toss/Formula/FormulaOpsTest.ml 2011-03-22 18:22:54 UTC (rev 1378) @@ -252,6 +252,10 @@ simp_eq ":f(x) + 3 * :f(x)" "4 * :f(x)"; simp_eq " 3 + 4 * 5 - 12" "11"; simp_eq ":(ex x R(x)) - :(ex x R(x))" "0"; + simp_eq ":(ex x P(x)) - :(ex y P(y))" "0"; + simp_eq "Sum (x | P(x) : :f(x)) - Sum (y | P(y) : :f(y))" "0"; + simp_eq ("Sum (x | P(x) : Sum (y | Q(y) : :f(x)))" ^ + "- Sum (y | P(y) : Sum (z | Q(z) : :f(y)))") "0"; ); "prenex" >:: Modified: trunk/Toss/Solver/SolverTest.ml =================================================================== --- trunk/Toss/Solver/SolverTest.ml 2011-03-22 09:04:34 UTC (rev 1377) +++ trunk/Toss/Solver/SolverTest.ml 2011-03-22 18:22:54 UTC (rev 1378) @@ -259,385 +259,360 @@ "eval: GDL" >:: (fun () -> + Solver.set_debug_level 2; eval_eq - "[CONTROL_MV1, CELLHOLDS_8_8_MV1, CELLHOLDS_8_7_MV1, CELLHOLDS_8_6_MV1, - CELLHOLDS_8_5_MV1, CELLHOLDS_8_4_MV1, CELLHOLDS_8_3_MV1, CELLHOLDS_8_2_MV1, - CELLHOLDS_8_1_MV1, CELLHOLDS_7_8_MV1, CELLHOLDS_7_7_MV1, CELLHOLDS_7_6_MV1, - CELLHOLDS_7_5_MV1, CELLHOLDS_7_4_MV1, CELLHOLDS_7_3_MV1, CELLHOLDS_7_2_MV1, - CELLHOLDS_7_1_MV1, CELLHOLDS_6_8_MV1, CELLHOLDS_6_7_MV1, CELLHOLDS_6_6_MV1, - CELLHOLDS_6_5_MV1, CELLHOLDS_6_4_MV1, CELLHOLDS_6_3_MV1, CELLHOLDS_6_2_MV1, - CELLHOLDS_6_1_MV1, CELLHOLDS_5_8_MV1, CELLHOLDS_5_7_MV1, CELLHOLDS_5_6_MV1, - CELLHOLDS_5_5_MV1, CELLHOLDS_5_4_MV1, CELLHOLDS_5_3_MV1, CELLHOLDS_5_2_MV1, - CELLHOLDS_5_1_MV1, CELLHOLDS_4_8_MV1, CELLHOLDS_4_7_MV1, CELLHOLDS_4_6_MV1, - CELLHOLDS_4_5_MV1, CELLHOLDS_4_4_MV1, CELLHOLDS_4_3_MV1, CELLHOLDS_4_2_MV1, - CELLHOLDS_4_1_MV1, CELLHOLDS_3_8_MV1, CELLHOLDS_3_7_MV1, CELLHOLDS_3_6_MV1, - CELLHOLDS_3_5_MV1, CELLHOLDS_3_4_MV1, CELLHOLDS_3_3_MV1, CELLHOLDS_3_2_MV1, - CELLHOLDS_3_1_MV1, CELLHOLDS_2_8_MV1, CELLHOLDS_2_7_MV1, CELLHOLDS_2_6_MV1, - CELLHOLDS_2_5_MV1, CELLHOLDS_2_4_MV1, CELLHOLDS_2_3_MV1, CELLHOLDS_2_2_MV1, - CELLHOLDS_2_1_MV1, CELLHOLDS_1_8_MV1, CELLHOLDS_1_7_MV1, CELLHOLDS_1_6_MV1, - CELLHOLDS_1_5_MV1, CELLHOLDS_1_4_MV1, CELLHOLDS_1_3_MV1, CELLHOLDS_1_2_MV1, - CELLHOLDS_1_1_MV1 | - CELLHOLDS_1_Y2_MV1 { - CELLHOLDS_1_8_MV1; CELLHOLDS_1_7_MV1; CELLHOLDS_1_6_MV1; - CELLHOLDS_1_5_MV1; CELLHOLDS_1_4_MV1; CELLHOLDS_1_3_MV1; - CELLHOLDS_1_2_MV1; CELLHOLDS_1_1_MV1 + "[CONTROL, C8_8, C8_7, C8_6, + C8_5, C8_4, C8_3, C8_2, + C8_1, C7_8, C7_7, C7_6, + C7_5, C7_4, C7_3, C7_2, + C7_1, C6_8, C6_7, C6_6, + C6_5, C6_4, C6_3, C6_2, + C6_1, C5_8, C5_7, C5_6, + C5_5, C5_4, C5_3, C5_2, + C5_1, C4_8, C4_7, C4_6, + C4_5, C4_4, C4_3, C4_2, + C4_1, C3_8, C3_7, C3_6, + C3_5, C3_4, C3_3, C3_2, + C3_1, C2_8, C2_7, C2_6, + C2_5, C2_4, C2_3, C2_2, + C2_1, C1_8, C1_7, C1_6, + C1_5, C1_4, C1_3, C1_2, + C1_1 | + C1_Y2 { + C1_8; C1_7; C1_6; + C1_5; C1_4; C1_3; + C1_2; C1_1 }; - CELLHOLDS_2_Y2_MV1 { - CELLHOLDS_2_8_MV1; CELLHOLDS_2_7_MV1; CELLHOLDS_2_6_MV1; - CELLHOLDS_2_5_MV1; CELLHOLDS_2_4_MV1; CELLHOLDS_2_3_MV1; - CELLHOLDS_2_2_MV1; CELLHOLDS_2_1_MV1 + C2_Y2 { + C2_8; C2_7; C2_6; + C2_5; C2_4; C2_3; + C2_2; C2_1 }; - CELLHOLDS_3_Y2_MV1 { - CELLHOLDS_3_8_MV1; CELLHOLDS_3_7_MV1; CELLHOLDS_3_6_MV1; - CELLHOLDS_3_5_MV1; CELLHOLDS_3_4_MV1; CELLHOLDS_3_3_MV1; - CELLHOLDS_3_2_MV1; CELLHOLDS_3_1_MV1 + C3_Y2 { + C3_8; C3_7; C3_6; + C3_5; C3_4; C3_3; + C3_2; C3_1 }; - CELLHOLDS_4_Y2_MV1 { - CELLHOLDS_4_8_MV1; CELLHOLDS_4_7_MV1; CELLHOLDS_4_6_MV1; - CELLHOLDS_4_5_MV1; CELLHOLDS_4_4_MV1; CELLHOLDS_4_3_MV1; - CELLHOLDS_4_2_MV1; CELLHOLDS_4_1_MV1 + C4_Y2 { + C4_8; C4_7; C4_6; + C4_5; C4_4; C4_3; + C4_2; C4_1 }; - CELLHOLDS_5_Y2_MV1 { - CELLHOLDS_5_8_MV1; CELLHOLDS_5_7_MV1; CELLHOLDS_5_6_MV1; - CELLHOLDS_5_5_MV1; CELLHOLDS_5_4_MV1; CELLHOLDS_5_3_MV1; - CELLHOLDS_5_2_MV1; CELLHOLDS_5_1_MV1 + C5_Y2 { + C5_8; C5_7; C5_6; + C5_5; C5_4; C5_3; + C5_2; C5_1 }; - CELLHOLDS_6_Y2_MV1 { - CELLHOLDS_6_8_MV1; CELLHOLDS_6_7_MV1; CELLHOLDS_6_6_MV1; - CELLHOLDS_6_5_MV1; CELLHOLDS_6_4_MV1; CELLHOLDS_6_3_MV1; - CELLHOLDS_6_2_MV1; CELLHOLDS_6_1_MV1 + C6_Y2 { + C6_8; C6_7; C6_6; + C6_5; C6_4; C6_3; + C6_2; C6_1 }; - CELLHOLDS_7_Y2_MV1 { - CELLHOLDS_7_8_MV1; CELLHOLDS_7_7_MV1; CELLHOLDS_7_6_MV1; - CELLHOLDS_7_5_MV1; CELLHOLDS_7_4_MV1; CELLHOLDS_7_3_MV1; - CELLHOLDS_7_2_MV1; CELLHOLDS_7_1_MV1 + C7_Y2 { + C7_8; C7_7; C7_6; + C7_5; C7_4; C7_3; + C7_2; C7_1 }; - CELLHOLDS_8_Y2_MV1 { - CELLHOLDS_8_8_MV1; CELLHOLDS_8_7_MV1; CELLHOLDS_8_6_MV1; - CELLHOLDS_8_5_MV1; CELLHOLDS_8_4_MV1; CELLHOLDS_8_3_MV1; - CELLHOLDS_8_2_MV1; CELLHOLDS_8_1_MV1 + C8_Y2 { + C8_8; C8_7; C8_6; + C8_5; C8_4; C8_3; + C8_2; C8_1 }; - CELLHOLDS_X2_1_MV1 { - CELLHOLDS_8_1_MV1; CELLHOLDS_7_1_MV1; CELLHOLDS_6_1_MV1; - CELLHOLDS_5_1_MV1; CELLHOLDS_4_1_MV1; CELLHOLDS_3_1_MV1; - CELLHOLDS_2_1_MV1; CELLHOLDS_1_1_MV1 + CX2_1 { + C8_1; C7_1; C6_1; + C5_1; C4_1; C3_1; + C2_1; C1_1 }; - CELLHOLDS_X2_2_MV1 { - CELLHOLDS_8_2_MV1; CELLHOLDS_7_2_MV1; CELLHOLDS_6_2_MV1; - CELLHOLDS_5_2_MV1; CELLHOLDS_4_2_MV1; CELLHOLDS_3_2_MV1; - CELLHOLDS_2_2_MV1; CELLHOLDS_1_2_MV1 + CX2_2 { + C8_2; C7_2; C6_2; + C5_2; C4_2; C3_2; + C2_2; C1_2 }; - CELLHOLDS_X2_3_MV1 { - CELLHOLDS_8_3_MV1; CELLHOLDS_7_3_MV1; CELLHOLDS_6_3_MV1; - CELLHOLDS_5_3_MV1; CELLHOLDS_4_3_MV1; CELLHOLDS_3_3_MV1; - CELLHOLDS_2_3_MV1; CELLHOLDS_1_3_MV1 + CX2_3 { + C8_3; C7_3; C6_3; + C5_3; C4_3; C3_3; + C2_3; C1_3 }; - CELLHOLDS_X2_4_MV1 { - CELLHOLDS_8_4_MV1; CELLHOLDS_7_4_MV1; CELLHOLDS_6_4_MV1; - CELLHOLDS_5_4_MV1; CELLHOLDS_4_4_MV1; CELLHOLDS_3_4_MV1; - CELLHOLDS_2_4_MV1; CELLHOLDS_1_4_MV1 + CX2_4 { + C8_4; C7_4; C6_4; + C5_4; C4_4; C3_4; + C2_4; C1_4 }; - CELLHOLDS_X2_5_MV1 { - CELLHOLDS_8_5_MV1; CELLHOLDS_7_5_MV1; CELLHOLDS_6_5_MV1; - CELLHOLDS_5_5_MV1; CELLHOLDS_4_5_MV1; CELLHOLDS_3_5_MV1; - CELLHOLDS_2_5_MV1; CELLHOLDS_1_5_MV1 + CX2_5 { + C8_5; C7_5; C6_5; + C5_5; C4_5; C3_5; + C2_5; C1_5 }; - CELLHOLDS_X2_6_MV1 { - CELLHOLDS_8_6_MV1; CELLHOLDS_7_6_MV1; CELLHOLDS_6_6_MV1; - CELLHOLDS_5_6_MV1; CELLHOLDS_4_6_MV1; CELLHOLDS_3_6_MV1; - CELLHOLDS_2_6_MV1; CELLHOLDS_1_6_MV1 + CX2_6 { + C8_6; C7_6; C6_6; + C5_6; C4_6; C3_6; + C2_6; C1_6 }; - CELLHOLDS_X2_7_MV1 { - CELLHOLDS_8_7_MV1; CELLHOLDS_7_7_MV1; CELLHOLDS_6_7_MV1; - CELLHOLDS_5_7_MV1; CELLHOLDS_4_7_MV1; CELLHOLDS_3_7_MV1; - CELLHOLDS_2_7_MV1; CELLHOLDS_1_7_MV1 + CX2_7 { + C8_7; C7_7; C6_7; + C5_7; C4_7; C3_7; + C2_7; C1_7 }; - CELLHOLDS_X2_8_MV1 { - CELLHOLDS_8_8_MV1; CELLHOLDS_7_8_MV1; CELLHOLDS_6_8_MV1; - CELLHOLDS_5_8_MV1; CELLHOLDS_4_8_MV1; CELLHOLDS_3_8_MV1; - CELLHOLDS_2_8_MV1; CELLHOLDS_1_8_MV1 + CX2_8 { + C8_8; C7_8; C6_8; + C5_8; C4_8; C3_8; + C2_8; C1_8 }; - CELLHOLDS_X2_Y2_BLACK { - CELLHOLDS_8_8_MV1; CELLHOLDS_7_8_MV1; CELLHOLDS_7_7_MV1; - CELLHOLDS_7_6_MV1; CELLHOLDS_6_8_MV1; CELLHOLDS_6_6_MV1; - CELLHOLDS_5_8_MV1; CELLHOLDS_5_7_MV1; CELLHOLDS_4_8_MV1; - CELLHOLDS_4_7_MV1; CELLHOLDS_3_7_MV1; CELLHOLDS_3_6_MV1; - CELLHOLDS_1_8_MV1; CELLHOLDS_1_7_MV1; CELLHOLDS_1_6_MV1; - CELLHOLDS_1_5_MV1 + CX2_Y2_BLACK { + C8_8; C7_8; C7_7; + C7_6; C6_8; C6_6; + C5_8; C5_7; C4_8; + C4_7; C3_7; C3_6; + C1_8; C1_7; C1_6; + C1_5 }; - CELLHOLDS_X2_Y2_MV1:1 {}; - CELLHOLDS_X2_Y2_WHITE { - CELLHOLDS_8_3_MV1; CELLHOLDS_8_1_MV1; CELLHOLDS_7_4_MV1; - CELLHOLDS_7_1_MV1; CELLHOLDS_6_3_MV1; CELLHOLDS_6_1_MV1; - CELLHOLDS_5_4_MV1; CELLHOLDS_5_3_MV1; CELLHOLDS_5_1_MV1; - CELLHOLDS_4_2_MV1; CELLHOLDS_4_1_MV1; CELLHOLDS_3_2_MV1; - CELLHOLDS_2_2_MV1; CELLHOLDS_2_1_MV1; CELLHOLDS_1_3_MV1; - CELLHOLDS_1_1_MV1 + CX2_Y2:1 {}; + CX2_Y2_WHITE { + C8_3; C8_1; C7_4; + C7_1; C6_3; C6_1; + C5_4; C5_3; C5_1; + C4_2; C4_1; C3_2; + C2_2; C2_1; C1_3; + C1_1 }; - CONTROL_BLACK (CONTROL_MV1); CONTROL_MV1 (CONTROL_MV1); - CONTROL_WHITE:1 {}; INDEX__CELLHOLDS_X2_Y2_MV1_X2:1 {}; - INDEX__CELLHOLDS_X2_Y2_MV1_Y2:1 {}; + CONTROL_BLACK (CONTROL); CONTROL (CONTROL); + CONTROL_WHITE:1 {}; INDEX__CX2_Y2_X2:1 {}; + INDEX__CX2_Y2_Y2:1 {}; R { - (CELLHOLDS_8_7_MV1, CELLHOLDS_7_8_MV1); - (CELLHOLDS_8_6_MV1, CELLHOLDS_7_7_MV1); - (CELLHOLDS_8_5_MV1, CELLHOLDS_7_6_MV1); - (CELLHOLDS_8_4_MV1, CELLHOLDS_7_5_MV1); - (CELLHOLDS_8_3_MV1, CELLHOLDS_7_4_MV1); - (CELLHOLDS_8_2_MV1, CELLHOLDS_7_3_MV1); - (CELLHOLDS_8_1_MV1, CELLHOLDS_7_2_MV1); - (CELLHOLDS_7_7_MV1, CELLHOLDS_6_8_MV1); - (CELLHOLDS_7_6_MV1, CELLHOLDS_6_7_MV1); - (CELLHOLDS_7_5_MV1, CELLHOLDS_6_6_MV1); - (CELLHOLDS_7_4_MV1, CELLHOLDS_6_5_MV1); - (CELLHOLDS_7_3_MV1, CELLHOLDS_6_4_MV1); - (CELLHOLDS_7_2_MV1, CELLHOLDS_6_3_MV1); - (CELLHOLDS_7_1_MV1, CELLHOLDS_6_2_MV1); - (CELLHOLDS_6_7_MV1, CELLHOLDS_5_8_MV1); - (CELLHOLDS_6_6_MV1, CELLHOLDS_5_7_MV1); - (CELLHOLDS_6_5_MV1, CELLHOLDS_5_6_MV1); - (CELLHOLDS_6_4_MV1, CELLHOLDS_5_5_MV1); - (CELLHOLDS_6_3_MV1, CELLHOLDS_5_4_MV1); - (CELLHOLDS_6_2_MV1, CELLHOLDS_5_3_MV1); - (CELLHOLDS_6_1_MV1, CELLHOLDS_5_2_MV1); - (CELLHOLDS_5_7_MV1, CELLHOLDS_4_8_MV1); - (CELLHOLDS_5_6_MV1, CELLHOLDS_4_7_MV1); - (CELLHOLDS_5_5_MV1, CELLHOLDS_4_6_MV1); - (CELLHOLDS_5_4_MV1, CELLHOLDS_4_5_MV1); - (CELLHOLDS_5_3_MV1, CELLHOLDS_4_4_MV1); - (CELLHOLDS_5_2_MV1, CELLHOLDS_4_3_MV1); - (CELLHOLDS_5_1_MV1, CELLHOLDS_4_2_MV1); - (CELLHOLDS_4_7_MV1, CELLHOLDS_3_8_MV1); - (CELLHOLDS_4_6_MV1, CELLHOLDS_3_7_MV1); - (CELLHOLDS_4_5_MV1, CELLHOLDS_3_6_MV1); - (CELLHOLDS_4_4_MV1, CELLHOLDS_3_5_MV1); - (CELLHOLDS_4_3_MV1, CELLHOLDS_3_4_MV1); - (CELLHOLDS_4_2_MV1, CELLHOLDS_3_3_MV1); - (CELLHOLDS_4_1_MV1, CELLHOLDS_3_2_MV1); - (CELLHOLDS_3_7_MV1, CELLHOLDS_2_8_MV1); - (CELLHOLDS_3_6_MV1, CELLHOLDS_2_7_MV1); - (CELLHOLDS_3_5_MV1, CELLHOLDS_2_6_MV1); - (CELLHOLDS_3_4_MV1, CELLHOLDS_2_5_MV1); - (CELLHOLDS_3_3_MV1, CELLHOLDS_2_4_MV1); - (CELLHOLDS_3_2_MV1, CELLHOLDS_2_3_MV1); - (CELLHOLDS_3_1_MV1, CELLHOLDS_2_2_MV1); - (CELLHOLDS_2_7_MV1, CELLHOLDS_1_8_MV1); - (CELLHOLDS_2_6_MV1, CELLHOLDS_1_7_MV1); - (CELLHOLDS_2_5_MV1, CELLHOLDS_1_6_MV1); - (CELLHOLDS_2_4_MV1, CELLHOLDS_1_5_MV1); - (CELLHOLDS_2_3_MV1, CELLHOLDS_1_4_MV1); - (CELLHOLDS_2_2_MV1, CELLHOLDS_1_3_MV1); - (CELLHOLDS_2_1_MV1, CELLHOLDS_1_2_MV1) + (C8_7, C7_8); + (C8_6, C7_7); + (C8_5, C7_6); + (C8_4, C7_5); + (C8_3, C7_4); + (C8_2, C7_3); + (C8_1, C7_2); + (C7_7, C6_8); + (C7_6, C6_7); + (C7_5, C6_6); + (C7_4, C6_5); + (C7_3, C6_4); + (C7_2, C6_3); + (C7_1, C6_2); + (C6_7, C5_8); + (C6_6, C5_7); + (C6_5, C5_6); + (C6_4, C5_5); + (C6_3, C5_4); + (C6_2, C5_3); + (C6_1, C5_2); + (C5_7, C4_8); + (C5_6, C4_7); + (C5_5, C4_6); + (C5_4, C4_5); + (C5_3, C4_4); + (C5_2, C4_3); + (C5_1, C4_2); + (C4_7, C3_8); + (C4_6, C3_7); + (C4_5, C3_6); + (C4_4, C3_5); + (C4_3, C3_4); + (C4_2, C3_3); + (C4_1, C3_2); + (C3_7, C2_8); + (C3_6, C2_7); + (C3_5, C2_6); + (C3_4, C2_5); + (C3_3, C2_4); + (C3_2, C2_3); + (C3_1, C2_2); + (C2_7, C1_8); + (C2_6, C1_7); + (C2_5, C1_6); + (C2_4, C1_5); + (C2_3, C1_4); + (C2_2, C1_3); + (C2_1, C1_2) }; R0 { - (CELLHOLDS_7_7_MV1, CELLHOLDS_8_8_MV1); - (CELLHOLDS_7_6_MV1, CELLHOLDS_8_7_MV1); - (CELLHOLDS_7_5_MV1, CELLHOLDS_8_6_MV1); - (CELLHOLDS_7_4_MV1, CELLHOLDS_8_5_MV1); - (CELLHOLDS_7_3_MV1, CELLHOLDS_8_4_MV1); - (CELLHOLDS_7_2_MV1, CELLHOLDS_8_3_MV1); - (CELLHOLDS_7_1_MV1, CELLHOLDS_8_2_MV1); - (CELLHOLDS_6_7_MV1, CELLHOLDS_7_8_MV1); - (CELLHOLDS_6_6_MV1, CELLHOLDS_7_7_MV1); - (CELLHOLDS_6_5_MV1, CELLHOLDS_7_6_MV1); - (CELLHOLDS_6_4_MV1, CELLHOLDS_7_5_MV1); - (CELLHOLDS_6_3_MV1, CELLHOLDS_7_4_MV1); - (CELLHOLDS_6_2_MV1, CELLHOLDS_7_3_MV1); - (CELLHOLDS_6_1_MV1, CELLHOLDS_7_2_MV1); - (CELLHOLDS_5_7_MV1, CELLHOLDS_6_8_MV1); - (CELLHOLDS_5_6_MV1, CELLHOLDS_6_7_MV1); - (CELLHOLDS_5_5_MV1, CELLHOLDS_6_6_MV1); - (CELLHOLDS_5_4_MV1, CELLHOLDS_6_5_MV1); - (CELLHOLDS_5_3_MV1, CELLHOLDS_6_4_MV1); - (CELLHOLDS_5_2_MV1, CELLHOLDS_6_3_MV1); - (CELLHOLDS_5_1_MV1, CELLHOLDS_6_2_MV1); - (CELLHOLDS_4_7_MV1, CELLHOLDS_5_8_MV1); - (CELLHOLDS_4_6_MV1, CELLHOLDS_5_7_MV1); - (CELLHOLDS_4_5_MV1, CELLHOLDS_5_6_MV1); - (CELLHOLDS_4_4_MV1, CELLHOLDS_5_5_MV1); - (CELLHOLDS_4_3_MV1, CELLHOLDS_5_4_MV1); - (CELLHOLDS_4_2_MV1, CELLHOLDS_5_3_MV1); - (CELLHOLDS_4_1_MV1, CELLHOLDS_5_2_MV1); - (CELLHOLDS_3_7_MV1, CELLHOLDS_4_8_MV1); - (CELLHOLDS_3_6_MV1, CELLHOLDS_4_7_MV1); - (CELLHOLDS_3_5_MV1, CELLHOLDS_4_6_MV1); - (CELLHOLDS_3_4_MV1, CELLHOLDS_4_5_MV1); - (CELLHOLDS_3_3_MV1, CELLHOLDS_4_4_MV1); - (CELLHOLDS_3_2_MV1, CELLHOLDS_4_3_MV1); - (CELLHOLDS_3_1_MV1, CELLHOLDS_4_2_MV1); - (CELLHOLDS_2_7_MV1, CELLHOLDS_3_8_MV1); - (CELLHOLDS_2_6_MV1, CELLHOLDS_3_7_MV1); - (CELLHOLDS_2_5_MV1, CELLHOLDS_3_6_MV1); - (CELLHOLDS_2_4_MV1, CELLHOLDS_3_5_MV1); - (CELLHOLDS_2_3_MV1, CELLHOLDS_3_4_MV1); - (CELLHOLDS_2_2_MV1, CELLHOLDS_3_3_MV1); - (CELLHOLDS_2_1_MV1, CELLHOLDS_3_2_MV1); - (CELLHOLDS_1_7_MV1, CELLHOLDS_2_8_MV1); - (CELLHOLDS_1_6_MV1, CELLHOLDS_2_7_MV1); - (CELLHOLDS_1_5_MV1, CELLHOLDS_2_6_MV1); - (CELLHOLDS_1_4_MV1, CELLHOLDS_2_5_MV1); - (CELLHOLDS_1_3_MV1, CELLHOLDS_2_4_MV1); - (CELLHOLDS_1_2_MV1, CELLHOLDS_2_3_MV1); - (CELLHOLDS_1_1_MV1, CELLHOLDS_2_2_MV1) + (C7_7, C8_8); + (C7_6, C8_7); + (C7_5, C8_6); + (C7_4, C8_5); + (C7_3, C8_4); + (C7_2, C8_3); + (C7_1, C8_2); + (C6_7, C7_8); + (C6_6, C7_7); + (C6_5, C7_6); + (C6_4, C7_5); + (C6_3, C7_4); + (C6_2, C7_3); + (C6_1, C7_2); + (C5_7, C6_8); + (C5_6, C6_7); + (C5_5, C6_6); + (C5_4, C6_5); + (C5_3, C6_4); + (C5_2, C6_3); + (C5_1, C6_2); + (C4_7, C5_8); + (C4_6, C5_7); + (C4_5, C5_6); + (C4_4, C5_5); + (C4_3, C5_4); + (C4_2, C5_3); + (C4_1, C5_2); + (C3_7, C4_8); + (C3_6, C4_7); + (C3_5, C4_6); + (C3_4, C4_5); + (C3_3, C4_4); + (C3_2, C4_3); + (C3_1, C4_2); + (C2_7, C3_8); + (C2_6, C3_7); + (C2_5, C3_6); + (C2_4, C3_5); + (C2_3, C3_4); + (C2_2, C3_3); + (C2_1, C3_2); + (C1_7, C2_8); + (C1_6, C2_7); + (C1_5, C2_6); + (C1_4, C2_5); + (C1_3, C2_4); + (C1_2, C2_3); + (C1_1, C2_2) }; R1 { - (CELLHOLDS_8_7_MV1, CELLHOLDS_8_8_MV1); - (CELLHOLDS_8_6_MV1, CELLHOLDS_8_7_MV1); - (CELLHOLDS_8_5_MV1, CELLHOLDS_8_6_MV1); - (CELLHOLDS_8_4_MV1, CELLHOLDS_8_5_MV1); - (CELLHOLDS_8_3_MV1, CELLHOLDS_8_4_MV1); - (CELLHOLDS_8_2_MV1, CELLHOLDS_8_3_MV1); - (CELLHOLDS_8_1_MV1, CELLHOLDS_8_2_MV1); - (CELLHOLDS_7_7_MV1, CELLHOLDS_7_8_MV1); - (CELLHOLDS_7_6_MV1, CELLHOLDS_7_7_MV1); - (CELLHOLDS_7_5_MV1, CELLHOLDS_7_6_MV1); - (CELLHOLDS_7_4_MV1, CELLHOLDS_7_5_MV1); - (CELLHOLDS_7_3_MV1, CELLHOLDS_7_4_MV1); - (CELLHOLDS_7_2_MV1, CELLHOLDS_7_3_MV1); - (CELLHOLDS_7_1_MV1, CELLHOLDS_7_2_MV1); - (CELLHOLDS_6_7_MV1, CELLHOLDS_6_8_MV1); - (CELLHOLDS_6_6_MV1, CELLHOLDS_6_7_MV1); - (CELLHOLDS_6_5_MV1, CELLHOLDS_6_6_MV1); - (CELLHOLDS_6_4_MV1, CELLHOLDS_6_5_MV1); - (CELLHOLDS_6_3_MV1, CELLHOLDS_6_4_MV1); - (CELLHOLDS_6_2_MV1, CELLHOLDS_6_3_MV1); - (CELLHOLDS_6_1_MV1, CELLHOLDS_6_2_MV1); - (CELLHOLDS_5_7_MV1, CELLHOLDS_5_8_MV1); - (CELLHOLDS_5_6_MV1, CELLHOLDS_5_7_MV1); - (CELLHOLDS_5_5_MV1, CELLHOLDS_5_6_MV1); - (CELLHOLDS_5_4_MV1, CELLHOLDS_5_5_MV1); - (CELLHOLDS_5_3_MV1, CELLHOLDS_5_4_MV1); - (CELLHOLDS_5_2_MV1, CELLHOLDS_5_3_MV1); - (CELLHOLDS_5_1_MV1, CELLHOLDS_5_2_MV1); - (CELLHOLDS_4_7_MV1, CELLHOLDS_4_8_MV1); - (CELLHOLDS_4_6_MV1, CELLHOLDS_4_7_MV1); - (CELLHOLDS_4_5_MV1, CELLHOLDS_4_6_MV1); - (CELLHOLDS_4_4_MV1, CELLHOLDS_4_5_MV1); - (CELLHOLDS_4_3_MV1, CELLHOLDS_4_4_MV1); - (CELLHOLDS_4_2_MV1, CELLHOLDS_4_3_MV1); - (CELLHOLDS_4_1_MV1, CELLHOLDS_4_2_MV1); - (CELLHOLDS_3_7_MV1, CELLHOLDS_3_8_MV1); - (CELLHOLDS_3_6_MV1, CELLHOLDS_3_7_MV1); - (CELLHOLDS_3_5_MV1, CELLHOLDS_3_6_MV1); - (CELLHOLDS_3_4_MV1, CELLHOLDS_3_5_MV1); - (CELLHOLDS_3_3_MV1, CELLHOLDS_3_4_MV1); - (CELLHOLDS_3_2_MV1, CELLHOLDS_3_3_MV1); - (CELLHOLDS_3_1_MV1, CELLHOLDS_3_2_MV1); - (CELLHOLDS_2_7_MV1, CELLHOLDS_2_8_MV1); - (CELLHOLDS_2_6_MV1, CELLHOLDS_2_7_MV1); - (CELLHOLDS_2_5_MV1, CELLHOLDS_2_6_MV1); - (CELLHOLDS_2_4_MV1, CELLHOLDS_2_5_MV1); - (CELLHOLDS_2_3_MV1, CELLHOLDS_2_4_MV1); - (CELLHOLDS_2_2_MV1, CELLHOLDS_2_3_MV1); - (CELLHOLDS_2_1_MV1, CELLHOLDS_2_2_MV1); - (CELLHOLDS_1_7_MV1, CELLHOLDS_1_8_MV1); - (CELLHOLDS_1_6_MV1, CELLHOLDS_1_7_MV1); - (CELLHOLDS_1_5_MV1, CELLHOLDS_1_6_MV1); - (CELLHOLDS_1_4_MV1, CELLHOLDS_1_5_MV1); - (CELLHOLDS_1_3_MV1, CELLHOLDS_1_4_MV1); - (CELLHOLDS_1_2_MV1, CELLHOLDS_1_3_MV1); - (CELLHOLDS_1_1_MV1, CELLHOLDS_1_2_MV1) + (C8_7, C8_8); + (C8_6, C8_7); + (C8_5, C8_6); + (C8_4, C8_5); + (C8_3, C8_4); + (C8_2, C8_3); + (C8_1, C8_2); + (C7_7, C7_8); + (C7_6, C7_7); + (C7_5, C7_6); + (C7_4, C7_5); + (C7_3, C7_4); + (C7_2, C7_3); + (C7_1, C7_2); + (C6_7, C6_8); + (C6_6, C6_7); + (C6_5, C6_6); + (C6_4, C6_5); + (C6_3, C6_4); + (C6_2, C6_3); + (C6_1, C6_2); + (C5_7, C5_8); + (C5_6, C5_7); + (C5_5, C5_6); + (C5_4, C5_5); + (C5_3, C5_4); + (C5_2, C5_3); + (C5_1, C5_2); + (C4_7, C4_8); + (C4_6, C4_7); + (C4_5, C4_6); + (C4_4, C4_5); + (C4_3, C4_4); + (C4_2, C4_3); + (C4_1, C4_2); + (C3_7, C3_8); + (C3_6, C3_7); + (C3_5, C3_6); + (C3_4, C3_5); + (C3_3, C3_4); + (C3_2, C3_3); + (C3_1, C3_2); + (C2_7, C2_8); + (C2_6, C2_7); + (C2_5, C2_6); + (C2_4, C2_5); + (C2_3, C2_4); + (C2_2, C2_3); + (C2_1, C2_2); + (C1_7, C1_8); + (C1_6, C1_7); + (C1_5, C1_6); + (C1_4, C1_5); + (C1_3, C1_4); + (C1_2, C1_3); + (C1_1, C1_2) }; R2 { - (CELLHOLDS_8_8_MV1, CELLHOLDS_8_7_MV1); - (CELLHOLDS_8_7_MV1, CELLHOLDS_8_6_MV1); - (CELLHOLDS_8_6_MV1, CELLHOLDS_8_5_MV1); - (CELLHOLDS_8_5_MV1, CELLHOLDS_8_4_MV1); - (CELLHOLDS_8_4_MV1, CELLHOLDS_8_3_MV1); - (CELLHOLDS_8_3_MV1, CELLHOLDS_8_2_MV1); - (CELLHOLDS_8_2_MV1, CELLHOLDS_8_1_MV1); - (CELLHOLDS_7_8_MV1, CELLHOLDS_7_7_MV1); - (CELLHOLDS_7_7_MV1, CELLHOLDS_7_6_MV1); - (CELLHOLDS_7_6_MV1, CELLHOLDS_7_5_MV1); - (CELLHOLDS_7_5_MV1, CELLHOLDS_7_4_MV1); - (CELLHOLDS_7_4_MV1, CELLHOLDS_7_3_MV1); - (CELLHOLDS_7_3_MV1, CELLHOLDS_7_2_MV1); - (CELLHOLDS_7_2_MV1, CELLHOLDS_7_1_MV1); - (CELLHOLDS_6_8_MV1, CELLHOLDS_6_7_MV1); - (CELLHOLDS_6_7_MV1, CELLHOLDS_6_6_MV1); - (CELLHOLDS_6_6_MV1, CELLHOLDS_6_5_MV1); - (CELLHOLDS_6_5_MV1, CELLHOLDS_6_4_MV1); - (CELLHOLDS_6_4_MV1, CELLHOLDS_6_3_MV1); - (CELLHOLDS_6_3_MV1, CELLHOLDS_6_2_MV1); - (CELLHOLDS_6_2_MV1, CELLHOLDS_6_1_MV1); - (CELLHOLDS_5_8_MV1, CELLHOLDS_5_7_MV1); - (CELLHOLDS_5_7_MV1, CELLHOLDS_5_6_MV1); - (CELLHOLDS_5_6_MV1, CELLHOLDS_5_5_MV1); - (CELLHOLDS_5_5_MV1, CELLHOLDS_5_4_MV1); - (CELLHOLDS_5_4_MV1, CELLHOLDS_5_3_MV1); - (CELLHOLDS_5_3_MV1, CELLHOLDS_5_2_MV1); - (CELLHOLDS_5_2_MV1, CELLHOLDS_5_1_MV1); - (CELLHOLDS_4_8_MV1, CELLHOLDS_4_7_MV1); - (CELLHOLDS_4_7_MV1, CELLHOLDS_4_6_MV1); - (CELLHOLDS_4_6_MV1, CELLHOLDS_4_5_MV1); - (CELLHOLDS_4_5_MV1, CELLHOLDS_4_4_MV1); - (CELLHOLDS_4_4_MV1, CELLHOLDS_4_3_MV1); - (CELLHOLDS_4_3_MV1, CELLHOLDS_4_2_MV1); - (CELLHOLDS_4_2_MV1, CELLHOLDS_4_1_MV1); - (CELLHOLDS_3_8_MV1, CELLHOLDS_3_7_MV1); - (CELLHOLDS_3_7_MV1, CELLHOLDS_3_6_MV1); - (CELLHOLDS_3_6_MV1, CELLHOLDS_3_5_MV1); - (CELLHOLDS_3_5_MV1, CELLHOLDS_3_4_MV1); - (CELLHOLDS_3_4_MV1, CELLHOLDS_3_3_MV1); - (CELLHOLDS_3_3_MV1, CELLHOLDS_3_2_MV1); - (CELLHOLDS_3_2_MV1, CELLHOLDS_3_1_MV1); - (CELLHOLDS_2_8_MV1, CELLHOLDS_2_7_MV1); - (CELLHOLDS_2_7_MV1, CELLHOLDS_2_6_MV1); - (CELLHOLDS_2_6_MV1, CELLHOLDS_2_5_MV1); - (CELLHOLDS_2_5_MV1, CELLHOLDS_2_4_MV1); - (CELLHOLDS_2_4_MV1, CELLHOLDS_2_3_MV1); - (CELLHOLDS_2_3_MV1, CELLHOLDS_2_2_MV1); - (CELLHOLDS_2_2_MV1, CELLHOLDS_2_1_MV1); - (CELLHOLDS_1_8_MV1, CELLHOLDS_1_7_MV1); - (CELLHOLDS_1_7_MV1, CELLHOLDS_1_6_MV1); - (CELLHOLDS_1_6_MV1, CELLHOLDS_1_5_MV1); - (CELLHOLDS_1_5_MV1, CELLHOLDS_1_4_MV1); - (CELLHOLDS_1_4_MV1, CELLHOLDS_1_3_MV1); - (CELLHOLDS_1_3_MV1, CELLHOLDS_1_2_MV1); - (CELLHOLDS_1_2_MV1, CELLHOLDS_1_1_MV1) + (C8_8, C8_7); + (C8_7, C8_6); + (C8_6, C8_5); + (C8_5, C8_4); + (C8_4, C8_3); + (C8_3, C8_2); + (C8_2, C8_1); + (C7_8, C7_7); + (C7_7, C7_6); + (C7_6, C7_5); + (C7_5, C7_4); + (C7_4, C7_3); + (C7_3, C7_2); + (C7_2, C7_1); + (C6_8, C6_7); + (C6_7, C6_6); + (C6_6, C6_5); + (C6_5, C6_4); + (C6_4, C6_3); + (C6_3, C6_2); + (C6_2, C6_1); + (C5_8, C5_7); + (C5_7, C5_6); + (C5_6, C5_5); + (C5_5, C5_4); + (C5_4, C5_3); + (C5_3, C5_2); + (C5_2, C5_1); + (C4_8, C4_7); + (C4_7, C4_6); + (C4_6, C4_5); + (C4_5, C4_4); + (C4_4, C4_3); + (C4_3, C4_2); + (C4_2, C4_1); + (C3_8, C3_7); + (C3_7, C3_6); + (C3_6, C3_5); + (C3_5, C3_4); + (C3_4, C3_3); + (C3_3, C3_2); + (C3_2, C3_1); + (C2_8, C2_7); + (C2_7, C2_6); + (C2_6, C2_5); + (C2_5, C2_4); + (C2_4, C2_3); + (C2_3, C2_2); + (C2_2, C2_1); + (C1_8, C1_7); + (C1_7, C1_6); + (C1_6, C1_5); + (C1_5, C1_4); + (C1_4, C1_3); + (C1_3, C1_2); + (C1_2, C1_1) }; - _del_CELLHOLDS_X2_Y2_WHITE (CELLHOLDS_8_2_MV1); - _del_CONTROL_WHITE (CONTROL_MV1); - _new_CELLHOLDS_X2_Y2_WHITE (CELLHOLDS_8_3_MV1); - _new_CONTROL_BLACK (CONTROL_MV1); init__CELLHOLDS_X2_Y2_MV1_X2:1 {}; - init__CELLHOLDS_X2_Y2_MV1_Y2:1 {}; role__CELLHOLDS_X2_Y2_MV1_X2:1 {}; - role__CELLHOLDS_X2_Y2_MV1_Y2:1 {} - | -]" - "(CELLHOLDS_X2_6_MV1(cellholds_x2_y2__blank_) and - CELLHOLDS_X2_6_MV1(cellholds_x2_y2__blank_) and - CELLHOLDS_4_Y2_MV1(cellholds_x2_y2__blank_) and - CELLHOLDS_4_Y2_MV1(cellholds_x2_y2__blank_) and - CELLHOLDS_X2_7_MV1(cellholds_x1_y1__blank_) and - CELLHOLDS_X2_7_MV1(cellholds_x1_y1__blank_) and - CELLHOLDS_3_Y2_MV1(cellholds_x1_y1__blank_) and - CELLHOLDS_3_Y2_MV1(cellholds_x1_y1__blank_) and - R(cellholds_x1_y1__blank_, cellholds_x2_y2__blank_) and - CONTROL_BLACK(control__blank_) and - CELLHOLDS_X2_Y2_BLACK(cellholds_x1_y1__blank_) and - not CONTROL_MV1(cellholds_x1_y1__blank_) and - not CONTROL_MV1(cellholds_x2_y2__blank_) and - not CELLHOLDS_X2_Y2_BLACK(cellholds_x2_y2__blank_) and - not CONTROL_WHITE(control__blank_) and - not cellholds_x1_y1__blank_ = cellholds_x2_y2__blank_ and - not cellholds_x1_y1__blank_ = control__blank_ and - not cellholds_x2_y2__blank_ = control__blank_ and - not - ex cellholds_x374_8__blank_ - (CELLHOLDS_X2_8_MV1(cellholds_x374_8__blank_) and - not CONTROL_MV1(cellholds_x374_8__blank_) and - CELLHOLDS_X2_Y2_WHITE(cellholds_x374_8__blank_)) and - ex cellholds_x375_y368__blank_ - (CELLHOLDS_X2_Y2_BLACK(cellholds_x375_y368__blank_) and - not CONTROL_MV1(cellholds_x375_y368__blank_)) and - not - ex cellholds_x376_1__blank_ - (CELLHOLDS_X2_1_MV1(cellholds_x376_1__blank_) and - not CONTROL_MV1(cellholds_x376_1__blank_) and - CELLHOLDS_X2_Y2_BLACK(cellholds_x376_1__blank_)) and - ex cellholds_x377_y369__blank_ - (CELLHOLDS_X2_Y2_WHITE(cellholds_x377_y369__blank_) and - not CONTROL_MV1(cellholds_x377_y369__blank_)))" - "{ cellholds_x1_y1__blank_->42{ cellholds_x2_y2__blank_->35 } }"; + _del_CX2_Y2_WHITE (C8_2); + _del_CONTROL_WHITE (CONTROL); + _new_CX2_Y2_WHITE (C8_3); + _new_CONTROL_BLACK (CONTROL); init__CX2_Y2_X2:1 {}; + init__CX2_Y2_Y2:1 {}; role__CX2_Y2_X2:1 {}; + role__CX2_Y2_Y2:1 {} + | ]" + "(CX2_6(x2_y2) and + CX2_6(x2_y2) and + C4_Y2(x2_y2) and + C4_Y2(x2_y2) and + CX2_7(x1_y1) and + CX2_7(x1_y1) and + C3_Y2(x1_y1) and + C3_Y2(x1_y1) and + R(x2_y2, x1_y1))" + "{ x1_y1->42{ x2_y2->35 } }"; ); ] ;; Modified: trunk/Toss/WebClient/Login.js =================================================================== --- trunk/Toss/WebClient/Login.js 2011-03-22 09:04:34 UTC (rev 1377) +++ trunk/Toss/WebClient/Login.js 2011-03-22 18:22:54 UTC (rev 1378) @@ -47,15 +47,23 @@ // Onload handler function startup (game) { - if (navigator.userAgent.indexOf('MSIE') !=-1 && navigator.userAgent.indexOf('MSIE 9') ==-1) { + if (navigator.userAgent.indexOf('MSIE') != -1 && + navigator.userAgent.indexOf('MSIE 9') == -1) { document.getElementById("nosvg").style.display = "block"; } else { var udata = srv("USERPLAYS", "user"); if (udata != "") { setup_user (udata.split("$")) }; } - if (game != "") { - new_play_guest (game); + cur_game = ""; + if (game) { var cur_game = game; } + var gindex = window.location.href.indexOf("?game=") + if (gindex > 0) { + cur_game = window.location.href.substring(gindex+6, + window.location.href.length) } + if (cur_game != "") { + new_play_guest (cur_game); + } } // Html of the list item for adding new opponents. Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-03-22 09:04:34 UTC (rev 1377) +++ trunk/Toss/WebClient/index.html 2011-03-22 18:22:54 UTC (rev 1378) @@ -115,7 +115,8 @@ </p> <ul class="welcome-list"> -<li>Play Breakthrough, Checkers, Chess, Gomoku and many other board games</li> +<li>Play Breakthrough, Checkers, Chess, Connect4, Gomoku, Pawn Whopping + and many other board games</li> <li>Challenge your friends or play a fast game against the computer for fun</li> <li>Focus fully on the game thanks to our intuitive clean interface</li> <li>Keep and analyze your games to improve your strength</li> Modified: trunk/Toss/www/xsl/include/common.xsl =================================================================== --- trunk/Toss/www/xsl/include/common.xsl 2011-03-22 09:04:34 UTC (rev 1377) +++ trunk/Toss/www/xsl/include/common.xsl 2011-03-22 18:22:54 UTC (rev 1378) @@ -182,29 +182,29 @@ <xsl:template match="game-link"> <xsl:choose> <xsl:when test="$lang='de'"> - <a href="http://tplay.org/index_{@game}.html" + <a href="http://tplay.org/index.html?game={@game}" title="Spiel {@game}" class="game-link" id="game-link-{@game}"> <img class="game-img" src="{$topdir}/img/{@game}.png" alt="{@game}-Brett" id="game-img-{@game}" /> </a> </xsl:when> <xsl:when test="$lang='pl'"> - <a href="http://tplay.org/index_{@game}.html" + <a href="http://tplay.org/index.html?game={@game}" title="Graj w {@game}" class="game-link" id="game-link-{@game}"> <img class="game-img" src="{$topdir}/img/{@game}.png" alt="Plansza {@game}" id="game-img-{@game}" /> </a> </xsl:when> <xsl:when test="$lang='fr'"> - <a href="http://tplay.org/index_{@game}.html" - title="Graj w {@game}" class="game-link" id="game-link-{@game}"> + <a href="http://tplay.org/index.html?game={@game}" + title="Jouez au {@game}" class="game-link" id="game-link-{@game}"> <img class="game-img" src="{$topdir}/img/{@game}.png" alt="Bord de {@game}" id="game-img-{@game}" /> </a> </xsl:when> <xsl:otherwise> - <a href="http://tplay.org/index_{@game}.html" - title="Jouez au {@game}" class="game-link" id="game-link-{@game}"> + <a href="http://tplay.org/index.html?game={@game}" + title="Play {@game}" class="game-link" id="game-link-{@game}"> <img class="game-img" src="{$topdir}/img/{@game}.png" alt="{@game} Board" id="game-img-{@game}" /> </a> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-22 09:04:41
|
Revision: 1377 http://toss.svn.sourceforge.net/toss/?rev=1377&view=rev Author: lukstafi Date: 2011-03-22 09:04:34 +0000 (Tue, 22 Mar 2011) Log Message: ----------- Possible Solver problem: investigate the test. Generalized monotonicity test. Modified Paths: -------------- trunk/Toss/Play/Heuristic.ml trunk/Toss/Play/HeuristicTest.ml trunk/Toss/Solver/SolverTest.ml Modified: trunk/Toss/Play/Heuristic.ml =================================================================== --- trunk/Toss/Play/Heuristic.ml 2011-03-21 23:38:06 UTC (rev 1376) +++ trunk/Toss/Play/Heuristic.ml 2011-03-22 09:04:34 UTC (rev 1377) @@ -971,6 +971,15 @@ FormulaOps.free_vars pre = [] in let monotonic = !use_monotonic && List.for_all free_pre rules && List.for_all DiscreteRule.monotonic drules in + (* {{{ log entry *) + if !debug_level > 1 then ( + Printf.printf + "default_heuristic_old: monotonic=%b; use_monotonic=%b; \ + free_pre rules=%b; monotone rules=%b\n%!" + monotonic !use_monotonic (List.for_all free_pre rules) + (List.for_all DiscreteRule.monotonic drules) + ); + (* }}} *) let advr = match advr with Some r -> r | None -> if monotonic then default_monot_adv_ratio Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2011-03-21 23:38:06 UTC (rev 1376) +++ trunk/Toss/Play/HeuristicTest.ml 2011-03-22 09:04:34 UTC (rev 1377) @@ -307,6 +307,18 @@ )); + "default_heuristic_old: connect5 of GDL translation" >:: + (fun () -> + let (game,state) = + state_of_file "./GGP/tests/connect5-simpl.toss" in + let loc_heurs = + Heuristic.default_heuristic_old ~struc:state.Arena.struc + ~advr:4.0 game in + assert_equal ~printer:(fun x->x) + "SHOULD GENERATE AS FOR A MONOTONIC GAME" + (Formula.sprint_real loc_heurs.(0).(0)); + ); + "default_heuristic_old: expansion breakthrough of GDL translation" >:: (fun () -> let (game,state) = @@ -432,17 +444,17 @@ ] -let a = +let a () = Aux.run_test_if_target "HeuristicTest" tests -let a = +let a () = Aux.run_test_if_target "HeuristicTest" bigtests -let a () = +let a = Heuristic.debug_level := 5 -let a () = - match test_filter ["Heuristic:10:default_heuristic_old: expansion breakthrough of GDL translation"] +let a = + match test_filter ["Heuristic:10:default_heuristic_old: connect5 of GDL translation"] tests with | Some tests -> ignore (run_test_tt ~verbose:true tests) Modified: trunk/Toss/Solver/SolverTest.ml =================================================================== --- trunk/Toss/Solver/SolverTest.ml 2011-03-21 23:38:06 UTC (rev 1376) +++ trunk/Toss/Solver/SolverTest.ml 2011-03-22 09:04:34 UTC (rev 1377) @@ -256,6 +256,390 @@ real_val_eq "[ | R { (a, a); (a, b) } | ] " "Sum (x, y | R (x, y) : 1)" 2.; ); + + "eval: GDL" >:: + (fun () -> + eval_eq + "[CONTROL_MV1, CELLHOLDS_8_8_MV1, CELLHOLDS_8_7_MV1, CELLHOLDS_8_6_MV1, + CELLHOLDS_8_5_MV1, CELLHOLDS_8_4_MV1, CELLHOLDS_8_3_MV1, CELLHOLDS_8_2_MV1, + CELLHOLDS_8_1_MV1, CELLHOLDS_7_8_MV1, CELLHOLDS_7_7_MV1, CELLHOLDS_7_6_MV1, + CELLHOLDS_7_5_MV1, CELLHOLDS_7_4_MV1, CELLHOLDS_7_3_MV1, CELLHOLDS_7_2_MV1, + CELLHOLDS_7_1_MV1, CELLHOLDS_6_8_MV1, CELLHOLDS_6_7_MV1, CELLHOLDS_6_6_MV1, + CELLHOLDS_6_5_MV1, CELLHOLDS_6_4_MV1, CELLHOLDS_6_3_MV1, CELLHOLDS_6_2_MV1, + CELLHOLDS_6_1_MV1, CELLHOLDS_5_8_MV1, CELLHOLDS_5_7_MV1, CELLHOLDS_5_6_MV1, + CELLHOLDS_5_5_MV1, CELLHOLDS_5_4_MV1, CELLHOLDS_5_3_MV1, CELLHOLDS_5_2_MV1, + CELLHOLDS_5_1_MV1, CELLHOLDS_4_8_MV1, CELLHOLDS_4_7_MV1, CELLHOLDS_4_6_MV1, + CELLHOLDS_4_5_MV1, CELLHOLDS_4_4_MV1, CELLHOLDS_4_3_MV1, CELLHOLDS_4_2_MV1, + CELLHOLDS_4_1_MV1, CELLHOLDS_3_8_MV1, CELLHOLDS_3_7_MV1, CELLHOLDS_3_6_MV1, + CELLHOLDS_3_5_MV1, CELLHOLDS_3_4_MV1, CELLHOLDS_3_3_MV1, CELLHOLDS_3_2_MV1, + CELLHOLDS_3_1_MV1, CELLHOLDS_2_8_MV1, CELLHOLDS_2_7_MV1, CELLHOLDS_2_6_MV1, + CELLHOLDS_2_5_MV1, CELLHOLDS_2_4_MV1, CELLHOLDS_2_3_MV1, CELLHOLDS_2_2_MV1, + CELLHOLDS_2_1_MV1, CELLHOLDS_1_8_MV1, CELLHOLDS_1_7_MV1, CELLHOLDS_1_6_MV1, + CELLHOLDS_1_5_MV1, CELLHOLDS_1_4_MV1, CELLHOLDS_1_3_MV1, CELLHOLDS_1_2_MV1, + CELLHOLDS_1_1_MV1 | + CELLHOLDS_1_Y2_MV1 { + CELLHOLDS_1_8_MV1; CELLHOLDS_1_7_MV1; CELLHOLDS_1_6_MV1; + CELLHOLDS_1_5_MV1; CELLHOLDS_1_4_MV1; CELLHOLDS_1_3_MV1; + CELLHOLDS_1_2_MV1; CELLHOLDS_1_1_MV1 + }; + CELLHOLDS_2_Y2_MV1 { + CELLHOLDS_2_8_MV1; CELLHOLDS_2_7_MV1; CELLHOLDS_2_6_MV1; + CELLHOLDS_2_5_MV1; CELLHOLDS_2_4_MV1; CELLHOLDS_2_3_MV1; + CELLHOLDS_2_2_MV1; CELLHOLDS_2_1_MV1 + }; + CELLHOLDS_3_Y2_MV1 { + CELLHOLDS_3_8_MV1; CELLHOLDS_3_7_MV1; CELLHOLDS_3_6_MV1; + CELLHOLDS_3_5_MV1; CELLHOLDS_3_4_MV1; CELLHOLDS_3_3_MV1; + CELLHOLDS_3_2_MV1; CELLHOLDS_3_1_MV1 + }; + CELLHOLDS_4_Y2_MV1 { + CELLHOLDS_4_8_MV1; CELLHOLDS_4_7_MV1; CELLHOLDS_4_6_MV1; + CELLHOLDS_4_5_MV1; CELLHOLDS_4_4_MV1; CELLHOLDS_4_3_MV1; + CELLHOLDS_4_2_MV1; CELLHOLDS_4_1_MV1 + }; + CELLHOLDS_5_Y2_MV1 { + CELLHOLDS_5_8_MV1; CELLHOLDS_5_7_MV1; CELLHOLDS_5_6_MV1; + CELLHOLDS_5_5_MV1; CELLHOLDS_5_4_MV1; CELLHOLDS_5_3_MV1; + CELLHOLDS_5_2_MV1; CELLHOLDS_5_1_MV1 + }; + CELLHOLDS_6_Y2_MV1 { + CELLHOLDS_6_8_MV1; CELLHOLDS_6_7_MV1; CELLHOLDS_6_6_MV1; + CELLHOLDS_6_5_MV1; CELLHOLDS_6_4_MV1; CELLHOLDS_6_3_MV1; + CELLHOLDS_6_2_MV1; CELLHOLDS_6_1_MV1 + }; + CELLHOLDS_7_Y2_MV1 { + CELLHOLDS_7_8_MV1; CELLHOLDS_7_7_MV1; CELLHOLDS_7_6_MV1; + CELLHOLDS_7_5_MV1; CELLHOLDS_7_4_MV1; CELLHOLDS_7_3_MV1; + CELLHOLDS_7_2_MV1; CELLHOLDS_7_1_MV1 + }; + CELLHOLDS_8_Y2_MV1 { + CELLHOLDS_8_8_MV1; CELLHOLDS_8_7_MV1; CELLHOLDS_8_6_MV1; + CELLHOLDS_8_5_MV1; CELLHOLDS_8_4_MV1; CELLHOLDS_8_3_MV1; + CELLHOLDS_8_2_MV1; CELLHOLDS_8_1_MV1 + }; + CELLHOLDS_X2_1_MV1 { + CELLHOLDS_8_1_MV1; CELLHOLDS_7_1_MV1; CELLHOLDS_6_1_MV1; + CELLHOLDS_5_1_MV1; CELLHOLDS_4_1_MV1; CELLHOLDS_3_1_MV1; + CELLHOLDS_2_1_MV1; CELLHOLDS_1_1_MV1 + }; + CELLHOLDS_X2_2_MV1 { + CELLHOLDS_8_2_MV1; CELLHOLDS_7_2_MV1; CELLHOLDS_6_2_MV1; + CELLHOLDS_5_2_MV1; CELLHOLDS_4_2_MV1; CELLHOLDS_3_2_MV1; + CELLHOLDS_2_2_MV1; CELLHOLDS_1_2_MV1 + }; + CELLHOLDS_X2_3_MV1 { + CELLHOLDS_8_3_MV1; CELLHOLDS_7_3_MV1; CELLHOLDS_6_3_MV1; + CELLHOLDS_5_3_MV1; CELLHOLDS_4_3_MV1; CELLHOLDS_3_3_MV1; + CELLHOLDS_2_3_MV1; CELLHOLDS_1_3_MV1 + }; + CELLHOLDS_X2_4_MV1 { + CELLHOLDS_8_4_MV1; CELLHOLDS_7_4_MV1; CELLHOLDS_6_4_MV1; + CELLHOLDS_5_4_MV1; CELLHOLDS_4_4_MV1; CELLHOLDS_3_4_MV1; + CELLHOLDS_2_4_MV1; CELLHOLDS_1_4_MV1 + }; + CELLHOLDS_X2_5_MV1 { + CELLHOLDS_8_5_MV1; CELLHOLDS_7_5_MV1; CELLHOLDS_6_5_MV1; + CELLHOLDS_5_5_MV1; CELLHOLDS_4_5_MV1; CELLHOLDS_3_5_MV1; + CELLHOLDS_2_5_MV1; CELLHOLDS_1_5_MV1 + }; + CELLHOLDS_X2_6_MV1 { + CELLHOLDS_8_6_MV1; CELLHOLDS_7_6_MV1; CELLHOLDS_6_6_MV1; + CELLHOLDS_5_6_MV1; CELLHOLDS_4_6_MV1; CELLHOLDS_3_6_MV1; + CELLHOLDS_2_6_MV1; CELLHOLDS_1_6_MV1 + }; + CELLHOLDS_X2_7_MV1 { + CELLHOLDS_8_7_MV1; CELLHOLDS_7_7_MV1; CELLHOLDS_6_7_MV1; + CELLHOLDS_5_7_MV1; CELLHOLDS_4_7_MV1; CELLHOLDS_3_7_MV1; + CELLHOLDS_2_7_MV1; CELLHOLDS_1_7_MV1 + }; + CELLHOLDS_X2_8_MV1 { + CELLHOLDS_8_8_MV1; CELLHOLDS_7_8_MV1; CELLHOLDS_6_8_MV1; + CELLHOLDS_5_8_MV1; CELLHOLDS_4_8_MV1; CELLHOLDS_3_8_MV1; + CELLHOLDS_2_8_MV1; CELLHOLDS_1_8_MV1 + }; + CELLHOLDS_X2_Y2_BLACK { + CELLHOLDS_8_8_MV1; CELLHOLDS_7_8_MV1; CELLHOLDS_7_7_MV1; + CELLHOLDS_7_6_MV1; CELLHOLDS_6_8_MV1; CELLHOLDS_6_6_MV1; + CELLHOLDS_5_8_MV1; CELLHOLDS_5_7_MV1; CELLHOLDS_4_8_MV1; + CELLHOLDS_4_7_MV1; CELLHOLDS_3_7_MV1; CELLHOLDS_3_6_MV1; + CELLHOLDS_1_8_MV1; CELLHOLDS_1_7_MV1; CELLHOLDS_1_6_MV1; + CELLHOLDS_1_5_MV1 + }; + CELLHOLDS_X2_Y2_MV1:1 {}; + CELLHOLDS_X2_Y2_WHITE { + CELLHOLDS_8_3_MV1; CELLHOLDS_8_1_MV1; CELLHOLDS_7_4_MV1; + CELLHOLDS_7_1_MV1; CELLHOLDS_6_3_MV1; CELLHOLDS_6_1_MV1; + CELLHOLDS_5_4_MV1; CELLHOLDS_5_3_MV1; CELLHOLDS_5_1_MV1; + CELLHOLDS_4_2_MV1; CELLHOLDS_4_1_MV1; CELLHOLDS_3_2_MV1; + CELLHOLDS_2_2_MV1; CELLHOLDS_2_1_MV1; CELLHOLDS_1_3_MV1; + CELLHOLDS_1_1_MV1 + }; + CONTROL_BLACK (CONTROL_MV1); CONTROL_MV1 (CONTROL_MV1); + CONTROL_WHITE:1 {}; INDEX__CELLHOLDS_X2_Y2_MV1_X2:1 {}; + INDEX__CELLHOLDS_X2_Y2_MV1_Y2:1 {}; + R { + (CELLHOLDS_8_7_MV1, CELLHOLDS_7_8_MV1); + (CELLHOLDS_8_6_MV1, CELLHOLDS_7_7_MV1); + (CELLHOLDS_8_5_MV1, CELLHOLDS_7_6_MV1); + (CELLHOLDS_8_4_MV1, CELLHOLDS_7_5_MV1); + (CELLHOLDS_8_3_MV1, CELLHOLDS_7_4_MV1); + (CELLHOLDS_8_2_MV1, CELLHOLDS_7_3_MV1); + (CELLHOLDS_8_1_MV1, CELLHOLDS_7_2_MV1); + (CELLHOLDS_7_7_MV1, CELLHOLDS_6_8_MV1); + (CELLHOLDS_7_6_MV1, CELLHOLDS_6_7_MV1); + (CELLHOLDS_7_5_MV1, CELLHOLDS_6_6_MV1); + (CELLHOLDS_7_4_MV1, CELLHOLDS_6_5_MV1); + (CELLHOLDS_7_3_MV1, CELLHOLDS_6_4_MV1); + (CELLHOLDS_7_2_MV1, CELLHOLDS_6_3_MV1); + (CELLHOLDS_7_1_MV1, CELLHOLDS_6_2_MV1); + (CELLHOLDS_6_7_MV1, CELLHOLDS_5_8_MV1); + (CELLHOLDS_6_6_MV1, CELLHOLDS_5_7_MV1); + (CELLHOLDS_6_5_MV1, CELLHOLDS_5_6_MV1); + (CELLHOLDS_6_4_MV1, CELLHOLDS_5_5_MV1); + (CELLHOLDS_6_3_MV1, CELLHOLDS_5_4_MV1); + (CELLHOLDS_6_2_MV1, CELLHOLDS_5_3_MV1); + (CELLHOLDS_6_1_MV1, CELLHOLDS_5_2_MV1); + (CELLHOLDS_5_7_MV1, CELLHOLDS_4_8_MV1); + (CELLHOLDS_5_6_MV1, CELLHOLDS_4_7_MV1); + (CELLHOLDS_5_5_MV1, CELLHOLDS_4_6_MV1); + (CELLHOLDS_5_4_MV1, CELLHOLDS_4_5_MV1); + (CELLHOLDS_5_3_MV1, CELLHOLDS_4_4_MV1); + (CELLHOLDS_5_2_MV1, CELLHOLDS_4_3_MV1); + (CELLHOLDS_5_1_MV1, CELLHOLDS_4_2_MV1); + (CELLHOLDS_4_7_MV1, CELLHOLDS_3_8_MV1); + (CELLHOLDS_4_6_MV1, CELLHOLDS_3_7_MV1); + (CELLHOLDS_4_5_MV1, CELLHOLDS_3_6_MV1); + (CELLHOLDS_4_4_MV1, CELLHOLDS_3_5_MV1); + (CELLHOLDS_4_3_MV1, CELLHOLDS_3_4_MV1); + (CELLHOLDS_4_2_MV1, CELLHOLDS_3_3_MV1); + (CELLHOLDS_4_1_MV1, CELLHOLDS_3_2_MV1); + (CELLHOLDS_3_7_MV1, CELLHOLDS_2_8_MV1); + (CELLHOLDS_3_6_MV1, CELLHOLDS_2_7_MV1); + (CELLHOLDS_3_5_MV1, CELLHOLDS_2_6_MV1); + (CELLHOLDS_3_4_MV1, CELLHOLDS_2_5_MV1); + (CELLHOLDS_3_3_MV1, CELLHOLDS_2_4_MV1); + (CELLHOLDS_3_2_MV1, CELLHOLDS_2_3_MV1); + (CELLHOLDS_3_1_MV1, CELLHOLDS_2_2_MV1); + (CELLHOLDS_2_7_MV1, CELLHOLDS_1_8_MV1); + (CELLHOLDS_2_6_MV1, CELLHOLDS_1_7_MV1); + (CELLHOLDS_2_5_MV1, CELLHOLDS_1_6_MV1); + (CELLHOLDS_2_4_MV1, CELLHOLDS_1_5_MV1); + (CELLHOLDS_2_3_MV1, CELLHOLDS_1_4_MV1); + (CELLHOLDS_2_2_MV1, CELLHOLDS_1_3_MV1); + (CELLHOLDS_2_1_MV1, CELLHOLDS_1_2_MV1) + }; + R0 { + (CELLHOLDS_7_7_MV1, CELLHOLDS_8_8_MV1); + (CELLHOLDS_7_6_MV1, CELLHOLDS_8_7_MV1); + (CELLHOLDS_7_5_MV1, CELLHOLDS_8_6_MV1); + (CELLHOLDS_7_4_MV1, CELLHOLDS_8_5_MV1); + (CELLHOLDS_7_3_MV1, CELLHOLDS_8_4_MV1); + (CELLHOLDS_7_2_MV1, CELLHOLDS_8_3_MV1); + (CELLHOLDS_7_1_MV1, CELLHOLDS_8_2_MV1); + (CELLHOLDS_6_7_MV1, CELLHOLDS_7_8_MV1); + (CELLHOLDS_6_6_MV1, CELLHOLDS_7_7_MV1); + (CELLHOLDS_6_5_MV1, CELLHOLDS_7_6_MV1); + (CELLHOLDS_6_4_MV1, CELLHOLDS_7_5_MV1); + (CELLHOLDS_6_3_MV1, CELLHOLDS_7_4_MV1); + (CELLHOLDS_6_2_MV1, CELLHOLDS_7_3_MV1); + (CELLHOLDS_6_1_MV1, CELLHOLDS_7_2_MV1); + (CELLHOLDS_5_7_MV1, CELLHOLDS_6_8_MV1); + (CELLHOLDS_5_6_MV1, CELLHOLDS_6_7_MV1); + (CELLHOLDS_5_5_MV1, CELLHOLDS_6_6_MV1); + (CELLHOLDS_5_4_MV1, CELLHOLDS_6_5_MV1); + (CELLHOLDS_5_3_MV1, CELLHOLDS_6_4_MV1); + (CELLHOLDS_5_2_MV1, CELLHOLDS_6_3_MV1); + (CELLHOLDS_5_1_MV1, CELLHOLDS_6_2_MV1); + (CELLHOLDS_4_7_MV1, CELLHOLDS_5_8_MV1); + (CELLHOLDS_4_6_MV1, CELLHOLDS_5_7_MV1); + (CELLHOLDS_4_5_MV1, CELLHOLDS_5_6_MV1); + (CELLHOLDS_4_4_MV1, CELLHOLDS_5_5_MV1); + (CELLHOLDS_4_3_MV1, CELLHOLDS_5_4_MV1); + (CELLHOLDS_4_2_MV1, CELLHOLDS_5_3_MV1); + (CELLHOLDS_4_1_MV1, CELLHOLDS_5_2_MV1); + (CELLHOLDS_3_7_MV1, CELLHOLDS_4_8_MV1); + (CELLHOLDS_3_6_MV1, CELLHOLDS_4_7_MV1); + (CELLHOLDS_3_5_MV1, CELLHOLDS_4_6_MV1); + (CELLHOLDS_3_4_MV1, CELLHOLDS_4_5_MV1); + (CELLHOLDS_3_3_MV1, CELLHOLDS_4_4_MV1); + (CELLHOLDS_3_2_MV1, CELLHOLDS_4_3_MV1); + (CELLHOLDS_3_1_MV1, CELLHOLDS_4_2_MV1); + (CELLHOLDS_2_7_MV1, CELLHOLDS_3_8_MV1); + (CELLHOLDS_2_6_MV1, CELLHOLDS_3_7_MV1); + (CELLHOLDS_2_5_MV1, CELLHOLDS_3_6_MV1); + (CELLHOLDS_2_4_MV1, CELLHOLDS_3_5_MV1); + (CELLHOLDS_2_3_MV1, CELLHOLDS_3_4_MV1); + (CELLHOLDS_2_2_MV1, CELLHOLDS_3_3_MV1); + (CELLHOLDS_2_1_MV1, CELLHOLDS_3_2_MV1); + (CELLHOLDS_1_7_MV1, CELLHOLDS_2_8_MV1); + (CELLHOLDS_1_6_MV1, CELLHOLDS_2_7_MV1); + (CELLHOLDS_1_5_MV1, CELLHOLDS_2_6_MV1); + (CELLHOLDS_1_4_MV1, CELLHOLDS_2_5_MV1); + (CELLHOLDS_1_3_MV1, CELLHOLDS_2_4_MV1); + (CELLHOLDS_1_2_MV1, CELLHOLDS_2_3_MV1); + (CELLHOLDS_1_1_MV1, CELLHOLDS_2_2_MV1) + }; + R1 { + (CELLHOLDS_8_7_MV1, CELLHOLDS_8_8_MV1); + (CELLHOLDS_8_6_MV1, CELLHOLDS_8_7_MV1); + (CELLHOLDS_8_5_MV1, CELLHOLDS_8_6_MV1); + (CELLHOLDS_8_4_MV1, CELLHOLDS_8_5_MV1); + (CELLHOLDS_8_3_MV1, CELLHOLDS_8_4_MV1); + (CELLHOLDS_8_2_MV1, CELLHOLDS_8_3_MV1); + (CELLHOLDS_8_1_MV1, CELLHOLDS_8_2_MV1); + (CELLHOLDS_7_7_MV1, CELLHOLDS_7_8_MV1); + (CELLHOLDS_7_6_MV1, CELLHOLDS_7_7_MV1); + (CELLHOLDS_7_5_MV1, CELLHOLDS_7_6_MV1); + (CELLHOLDS_7_4_MV1, CELLHOLDS_7_5_MV1); + (CELLHOLDS_7_3_MV1, CELLHOLDS_7_4_MV1); + (CELLHOLDS_7_2_MV1, CELLHOLDS_7_3_MV1); + (CELLHOLDS_7_1_MV1, CELLHOLDS_7_2_MV1); + (CELLHOLDS_6_7_MV1, CELLHOLDS_6_8_MV1); + (CELLHOLDS_6_6_MV1, CELLHOLDS_6_7_MV1); + (CELLHOLDS_6_5_MV1, CELLHOLDS_6_6_MV1); + (CELLHOLDS_6_4_MV1, CELLHOLDS_6_5_MV1); + (CELLHOLDS_6_3_MV1, CELLHOLDS_6_4_MV1); + (CELLHOLDS_6_2_MV1, CELLHOLDS_6_3_MV1); + (CELLHOLDS_6_1_MV1, CELLHOLDS_6_2_MV1); + (CELLHOLDS_5_7_MV1, CELLHOLDS_5_8_MV1); + (CELLHOLDS_5_6_MV1, CELLHOLDS_5_7_MV1); + (CELLHOLDS_5_5_MV1, CELLHOLDS_5_6_MV1); + (CELLHOLDS_5_4_MV1, CELLHOLDS_5_5_MV1); + (CELLHOLDS_5_3_MV1, CELLHOLDS_5_4_MV1); + (CELLHOLDS_5_2_MV1, CELLHOLDS_5_3_MV1); + (CELLHOLDS_5_1_MV1, CELLHOLDS_5_2_MV1); + (CELLHOLDS_4_7_MV1, CELLHOLDS_4_8_MV1); + (CELLHOLDS_4_6_MV1, CELLHOLDS_4_7_MV1); + (CELLHOLDS_4_5_MV1, CELLHOLDS_4_6_MV1); + (CELLHOLDS_4_4_MV1, CELLHOLDS_4_5_MV1); + (CELLHOLDS_4_3_MV1, CELLHOLDS_4_4_MV1); + (CELLHOLDS_4_2_MV1, CELLHOLDS_4_3_MV1); + (CELLHOLDS_4_1_MV1, CELLHOLDS_4_2_MV1); + (CELLHOLDS_3_7_MV1, CELLHOLDS_3_8_MV1); + (CELLHOLDS_3_6_MV1, CELLHOLDS_3_7_MV1); + (CELLHOLDS_3_5_MV1, CELLHOLDS_3_6_MV1); + (CELLHOLDS_3_4_MV1, CELLHOLDS_3_5_MV1); + (CELLHOLDS_3_3_MV1, CELLHOLDS_3_4_MV1); + (CELLHOLDS_3_2_MV1, CELLHOLDS_3_3_MV1); + (CELLHOLDS_3_1_MV1, CELLHOLDS_3_2_MV1); + (CELLHOLDS_2_7_MV1, CELLHOLDS_2_8_MV1); + (CELLHOLDS_2_6_MV1, CELLHOLDS_2_7_MV1); + (CELLHOLDS_2_5_MV1, CELLHOLDS_2_6_MV1); + (CELLHOLDS_2_4_MV1, CELLHOLDS_2_5_MV1); + (CELLHOLDS_2_3_MV1, CELLHOLDS_2_4_MV1); + (CELLHOLDS_2_2_MV1, CELLHOLDS_2_3_MV1); + (CELLHOLDS_2_1_MV1, CELLHOLDS_2_2_MV1); + (CELLHOLDS_1_7_MV1, CELLHOLDS_1_8_MV1); + (CELLHOLDS_1_6_MV1, CELLHOLDS_1_7_MV1); + (CELLHOLDS_1_5_MV1, CELLHOLDS_1_6_MV1); + (CELLHOLDS_1_4_MV1, CELLHOLDS_1_5_MV1); + (CELLHOLDS_1_3_MV1, CELLHOLDS_1_4_MV1); + (CELLHOLDS_1_2_MV1, CELLHOLDS_1_3_MV1); + (CELLHOLDS_1_1_MV1, CELLHOLDS_1_2_MV1) + }; + R2 { + (CELLHOLDS_8_8_MV1, CELLHOLDS_8_7_MV1); + (CELLHOLDS_8_7_MV1, CELLHOLDS_8_6_MV1); + (CELLHOLDS_8_6_MV1, CELLHOLDS_8_5_MV1); + (CELLHOLDS_8_5_MV1, CELLHOLDS_8_4_MV1); + (CELLHOLDS_8_4_MV1, CELLHOLDS_8_3_MV1); + (CELLHOLDS_8_3_MV1, CELLHOLDS_8_2_MV1); + (CELLHOLDS_8_2_MV1, CELLHOLDS_8_1_MV1); + (CELLHOLDS_7_8_MV1, CELLHOLDS_7_7_MV1); + (CELLHOLDS_7_7_MV1, CELLHOLDS_7_6_MV1); + (CELLHOLDS_7_6_MV1, CELLHOLDS_7_5_MV1); + (CELLHOLDS_7_5_MV1, CELLHOLDS_7_4_MV1); + (CELLHOLDS_7_4_MV1, CELLHOLDS_7_3_MV1); + (CELLHOLDS_7_3_MV1, CELLHOLDS_7_2_MV1); + (CELLHOLDS_7_2_MV1, CELLHOLDS_7_1_MV1); + (CELLHOLDS_6_8_MV1, CELLHOLDS_6_7_MV1); + (CELLHOLDS_6_7_MV1, CELLHOLDS_6_6_MV1); + (CELLHOLDS_6_6_MV1, CELLHOLDS_6_5_MV1); + (CELLHOLDS_6_5_MV1, CELLHOLDS_6_4_MV1); + (CELLHOLDS_6_4_MV1, CELLHOLDS_6_3_MV1); + (CELLHOLDS_6_3_MV1, CELLHOLDS_6_2_MV1); + (CELLHOLDS_6_2_MV1, CELLHOLDS_6_1_MV1); + (CELLHOLDS_5_8_MV1, CELLHOLDS_5_7_MV1); + (CELLHOLDS_5_7_MV1, CELLHOLDS_5_6_MV1); + (CELLHOLDS_5_6_MV1, CELLHOLDS_5_5_MV1); + (CELLHOLDS_5_5_MV1, CELLHOLDS_5_4_MV1); + (CELLHOLDS_5_4_MV1, CELLHOLDS_5_3_MV1); + (CELLHOLDS_5_3_MV1, CELLHOLDS_5_2_MV1); + (CELLHOLDS_5_2_MV1, CELLHOLDS_5_1_MV1); + (CELLHOLDS_4_8_MV1, CELLHOLDS_4_7_MV1); + (CELLHOLDS_4_7_MV1, CELLHOLDS_4_6_MV1); + (CELLHOLDS_4_6_MV1, CELLHOLDS_4_5_MV1); + (CELLHOLDS_4_5_MV1, CELLHOLDS_4_4_MV1); + (CELLHOLDS_4_4_MV1, CELLHOLDS_4_3_MV1); + (CELLHOLDS_4_3_MV1, CELLHOLDS_4_2_MV1); + (CELLHOLDS_4_2_MV1, CELLHOLDS_4_1_MV1); + (CELLHOLDS_3_8_MV1, CELLHOLDS_3_7_MV1); + (CELLHOLDS_3_7_MV1, CELLHOLDS_3_6_MV1); + (CELLHOLDS_3_6_MV1, CELLHOLDS_3_5_MV1); + (CELLHOLDS_3_5_MV1, CELLHOLDS_3_4_MV1); + (CELLHOLDS_3_4_MV1, CELLHOLDS_3_3_MV1); + (CELLHOLDS_3_3_MV1, CELLHOLDS_3_2_MV1); + (CELLHOLDS_3_2_MV1, CELLHOLDS_3_1_MV1); + (CELLHOLDS_2_8_MV1, CELLHOLDS_2_7_MV1); + (CELLHOLDS_2_7_MV1, CELLHOLDS_2_6_MV1); + (CELLHOLDS_2_6_MV1, CELLHOLDS_2_5_MV1); + (CELLHOLDS_2_5_MV1, CELLHOLDS_2_4_MV1); + (CELLHOLDS_2_4_MV1, CELLHOLDS_2_3_MV1); + (CELLHOLDS_2_3_MV1, CELLHOLDS_2_2_MV1); + (CELLHOLDS_2_2_MV1, CELLHOLDS_2_1_MV1); + (CELLHOLDS_1_8_MV1, CELLHOLDS_1_7_MV1); + (CELLHOLDS_1_7_MV1, CELLHOLDS_1_6_MV1); + (CELLHOLDS_1_6_MV1, CELLHOLDS_1_5_MV1); + (CELLHOLDS_1_5_MV1, CELLHOLDS_1_4_MV1); + (CELLHOLDS_1_4_MV1, CELLHOLDS_1_3_MV1); + (CELLHOLDS_1_3_MV1, CELLHOLDS_1_2_MV1); + (CELLHOLDS_1_2_MV1, CELLHOLDS_1_1_MV1) + }; + _del_CELLHOLDS_X2_Y2_WHITE (CELLHOLDS_8_2_MV1); + _del_CONTROL_WHITE (CONTROL_MV1); + _new_CELLHOLDS_X2_Y2_WHITE (CELLHOLDS_8_3_MV1); + _new_CONTROL_BLACK (CONTROL_MV1); init__CELLHOLDS_X2_Y2_MV1_X2:1 {}; + init__CELLHOLDS_X2_Y2_MV1_Y2:1 {}; role__CELLHOLDS_X2_Y2_MV1_X2:1 {}; + role__CELLHOLDS_X2_Y2_MV1_Y2:1 {} + | +]" + "(CELLHOLDS_X2_6_MV1(cellholds_x2_y2__blank_) and + CELLHOLDS_X2_6_MV1(cellholds_x2_y2__blank_) and + CELLHOLDS_4_Y2_MV1(cellholds_x2_y2__blank_) and + CELLHOLDS_4_Y2_MV1(cellholds_x2_y2__blank_) and + CELLHOLDS_X2_7_MV1(cellholds_x1_y1__blank_) and + CELLHOLDS_X2_7_MV1(cellholds_x1_y1__blank_) and + CELLHOLDS_3_Y2_MV1(cellholds_x1_y1__blank_) and + CELLHOLDS_3_Y2_MV1(cellholds_x1_y1__blank_) and + R(cellholds_x1_y1__blank_, cellholds_x2_y2__blank_) and + CONTROL_BLACK(control__blank_) and + CELLHOLDS_X2_Y2_BLACK(cellholds_x1_y1__blank_) and + not CONTROL_MV1(cellholds_x1_y1__blank_) and + not CONTROL_MV1(cellholds_x2_y2__blank_) and + not CELLHOLDS_X2_Y2_BLACK(cellholds_x2_y2__blank_) and + not CONTROL_WHITE(control__blank_) and + not cellholds_x1_y1__blank_ = cellholds_x2_y2__blank_ and + not cellholds_x1_y1__blank_ = control__blank_ and + not cellholds_x2_y2__blank_ = control__blank_ and + not + ex cellholds_x374_8__blank_ + (CELLHOLDS_X2_8_MV1(cellholds_x374_8__blank_) and + not CONTROL_MV1(cellholds_x374_8__blank_) and + CELLHOLDS_X2_Y2_WHITE(cellholds_x374_8__blank_)) and + ex cellholds_x375_y368__blank_ + (CELLHOLDS_X2_Y2_BLACK(cellholds_x375_y368__blank_) and + not CONTROL_MV1(cellholds_x375_y368__blank_)) and + not + ex cellholds_x376_1__blank_ + (CELLHOLDS_X2_1_MV1(cellholds_x376_1__blank_) and + not CONTROL_MV1(cellholds_x376_1__blank_) and + CELLHOLDS_X2_Y2_BLACK(cellholds_x376_1__blank_)) and + ex cellholds_x377_y369__blank_ + (CELLHOLDS_X2_Y2_WHITE(cellholds_x377_y369__blank_) and + not CONTROL_MV1(cellholds_x377_y369__blank_)))" + "{ cellholds_x1_y1__blank_->42{ cellholds_x2_y2__blank_->35 } }"; + ); + ] ;; let a = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-21 23:38:19
|
Revision: 1376 http://toss.svn.sourceforge.net/toss/?rev=1376&view=rev Author: lukstafi Date: 2011-03-21 23:38:06 +0000 (Mon, 21 Mar 2011) Log Message: ----------- GDL action translation adopted to game simplification. GDL test cases extended with action translation tests. Small GDL test case: tictactoe. More logging. Modified Paths: -------------- trunk/Toss/Arena/Arena.ml trunk/Toss/Arena/Arena.mli trunk/Toss/Arena/ContinuousRule.ml trunk/Toss/Arena/ContinuousRule.mli trunk/Toss/GGP/GDL.ml trunk/Toss/GGP/GDL.mli trunk/Toss/GGP/GDLParser.mly trunk/Toss/GGP/GDLTest.ml trunk/Toss/GGP/GameSimpl.ml trunk/Toss/GGP/GameSimpl.mli trunk/Toss/GGP/GameSimplTest.ml trunk/Toss/GGP/tests/breakthrough-simpl.toss trunk/Toss/GGP/tests/connect5-simpl.toss Added Paths: ----------- trunk/Toss/GGP/tests/tictactoe-raw.toss trunk/Toss/GGP/tests/tictactoe-simpl.toss Modified: trunk/Toss/Arena/Arena.ml =================================================================== --- trunk/Toss/Arena/Arena.ml 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/Arena/Arena.ml 2011-03-21 23:38:06 UTC (rev 1376) @@ -60,6 +60,14 @@ (* -------------------- PARSER HELPER ------------------------------ *) +let emb_of_names (game, state) rname emb_str = + let lhs = + (List.assoc rname game.rules + ).ContinuousRule.discrete.DiscreteRule.lhs_struc in + List.map (fun (lhs_e, m_e) -> + Structure.find_elem lhs lhs_e, Structure.find_elem state.struc m_e) + emb_str + (* Rules with which a player with given number can move. *) let rules_for_player player_no game = let rules_of_loc l = @@ -935,11 +943,9 @@ let r = List.assoc r_name state_game.rules in let matches = ContinuousRule.matches_post struc r state.time in (* matches are from LHS to model *) - let name (lhs,rhs) = - Structure.elem_str (ContinuousRule.lhs r) lhs ^ " -> " ^ - Structure.elem_str struc rhs in - let mname m = String.concat ", " (List.map name m) in - ((state_game, state), String.concat "; " (List.map mname matches)) + ((state_game, state), + String.concat "; " ( + List.map (ContinuousRule.embedding_str r struc) matches)) with Not_found -> ((state_game, state), "ERR getting "^r_name^" matches, rule not found") ) Modified: trunk/Toss/Arena/Arena.mli =================================================================== --- trunk/Toss/Arena/Arena.mli 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/Arena/Arena.mli 2011-03-21 23:38:06 UTC (rev 1376) @@ -40,6 +40,10 @@ val empty_state : game * game_state +(** Translate from names to elements to get rule embedding. *) +val emb_of_names : + game * game_state -> string -> (string * string) list -> (int * int) list + (** Rules with which a player with given number can move. *) val rules_for_player : int -> game -> string list Modified: trunk/Toss/Arena/ContinuousRule.ml =================================================================== --- trunk/Toss/Arena/ContinuousRule.ml 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/Arena/ContinuousRule.ml 2011-03-21 23:38:06 UTC (rev 1376) @@ -250,6 +250,11 @@ fprint Format.str_formatter r; Format.flush_str_formatter () +let embedding_str r struc emb = + let name (lhs_e,rhs_e) = + Structure.elem_str (lhs r) lhs_e ^ " -> " ^ + Structure.elem_str struc rhs_e in + String.concat ", " (List.map name emb) (* Compare two rules and explain the first difference met. Formulas and expressions are compared for structural equality. *) Modified: trunk/Toss/Arena/ContinuousRule.mli =================================================================== --- trunk/Toss/Arena/ContinuousRule.mli 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/Arena/ContinuousRule.mli 2011-03-21 23:38:06 UTC (rev 1376) @@ -39,6 +39,8 @@ val fprint : Format.formatter -> rule -> unit val print : rule -> unit val sprint : rule -> string +val embedding_str : + rule -> Structure.structure -> (int * int) list -> string (** {2 Applying function to side structures} *) Modified: trunk/Toss/GGP/GDL.ml =================================================================== --- trunk/Toss/GGP/GDL.ml 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/GGP/GDL.ml 2011-03-21 23:38:06 UTC (rev 1376) @@ -484,6 +484,9 @@ (V_1 - V_K) :(phi_1) + ... (V_n - V_K) :(phi_n)" thus removing phi_K from translation. + (8d) Finally, we simplify the result. Unused predicates are not + removed, because some of them will be needed for action translation. + (9) To translate an incoming action, we: (9a) find the "lead legal" term to which the "does move" ground @@ -544,6 +547,9 @@ type pair_matrix = Pairs_all | Pairs_triang | Pairs_star let equivalences_all_tuples = ref Pairs_triang +(** Generate test case for the given game name. *) +let generate_test_case = ref None + open Aux.BasicOperators type term = @@ -659,6 +665,28 @@ | Currently arg -> "true", [arg] | Does (arg1, arg2) -> "does", [arg1; arg2] +let fprint_gdl_transl_data ?(details=false) ppf gdl = + (* TODO: print more data if needed *) + Format.fprintf ppf "GDL_DATA@,{@[<1>FLUENTS@ %a;@ PLAYING_AS@ %d;" + (Aux.fprint_sep_list ";" Format.pp_print_string) gdl.fluents + gdl.playing_as; + Aux.StrMap.iter (fun rname data -> + Format.fprintf ppf "@ @[<1>RULE@ %s:@ LEGAL=@,%s;@ PRECOND=@,%a;@ " + rname (term_str data.lead_legal) Formula.fprint data.precond; + Format.fprintf ppf "{@[<1>RHS ADD:@ "; + Aux.fprint_sep_list ";" Format.pp_print_string ppf + (List.map (fun (rel,args) -> rel^"("^String.concat ", " + (Array.to_list args)^")") data.rhs_add); + Format.fprintf ppf "@]}@]" + ) gdl.tossrule_data; + Format.fprintf ppf "@]}" + +let sprint_gdl_transl_data ?(details=false) gdl = + ignore (Format.flush_str_formatter ()); + Format.fprintf Format.str_formatter "@[%a@]" + (fprint_gdl_transl_data ~details) gdl; + Format.flush_str_formatter () + let rec body_of_literal = function | Pos (Distinct args) -> [Aux.Right ("distinct", args)] (* not negated actually! *) @@ -3435,18 +3463,26 @@ time = 0.; cur_loc = 0; } in - (* {{{ log entry *) - (* * - let file = open_out "./GGP/tests/breakthrough-raw.toss" in - output_string file (Arena.state_str result); - close_out file; - * *) + (* {{{ log entry *) + (match !generate_test_case with + | None -> () + | Some game_name -> + let file = open_out ("./GGP/tests/"^game_name^"-raw.toss") in + output_string file (Arena.state_str result); + close_out file); if !debug_level > 1 then ( Printf.printf "\n\nGDL.translate_game: before simplification --\n%s\n%!" (Arena.sprint_state result) ); (* }}} *) + (* 8d *) let result = GameSimpl.simplify result in + let tossrule_data = + Aux.StrMap.mapi (fun rname rdata -> + let r = List.assoc rname (fst result).Arena.rules in + {rdata with precond = + r.ContinuousRule.compiled.DiscreteRule.lhs_form} + ) !tossrule_data in let playing_as = find_player player_term in let noop_actions = Array.mapi (fun loc noops-> @@ -3456,18 +3492,19 @@ | _ -> None ) loc_noop_legal in (* {{{ log entry *) - (* * - let file = open_out "./GGP/tests/breakthrough-simpl.toss" in - output_string file (Arena.state_str result); - close_out file; - * *) + (match !generate_test_case with + | None -> () + | Some game_name -> + let file = open_out ("./GGP/tests/"^game_name^"-simpl.toss") in + output_string file (Arena.state_str result); + close_out file); if !debug_level > 1 then ( Printf.printf "\n\nGDL.translate_game: after simplification --\n%s\n%!" (Arena.sprint_state result) ); (* }}} *) {anchor_terms = !anchor_terms; - tossrule_data = !tossrule_data; + tossrule_data = tossrule_data; t_elements = t_elements; playing_as = playing_as; noop_actions = noop_actions; @@ -3500,88 +3537,90 @@ let actions = Array.of_list actions in let location = (fst state).Arena.graph.(loc) in let player_action = actions.(location.Arena.player) in + let struc = (snd state).Arena.struc in + (* {{{ log entry *) + if !debug_level > 2 then ( + Printf.printf "\ntranslate_incoming_move:\nGDL=%s\n%!" + (sprint_gdl_transl_data gdl) + ); + if !debug_level > 3 then ( + Printf.printf "STRUC=%s\n%!" (Structure.sprint struc) + ); + (* }}} *) (* 9a *) let tossrules = Aux.strmap_filter (fun _ rdata -> try ignore (match_meta [] [] [player_action] [rdata.lead_legal]); true with Not_found -> false ) gdl.tossrule_data in - let tossrules = Aux.collect - (List.map (fun (rname, rdata) -> - rdata.lead_legal, - (rname, rdata.precond, rdata.rhs_add, rdata.struc_elems, - rdata.fixvar_elemvars)) tossrules) in - let lead, tossrules = - match tossrules with - | [lead, tossrules] -> lead, tossrules - | _ -> assert false in (* {{{ log entry *) if !debug_level > 0 then ( - Printf.printf "GDL.translate_incoming_move: action=%s; lead=%s\n%!" - (term_str player_action) (term_str lead) + Printf.printf "GDL.translate_incoming_move: action=%s\n%!" + (term_str player_action) ); (* }}} *) (* 9c *) - let fixed_inst, _ = - match_meta [] [] [player_action] [lead] in - let struc = (snd state).Arena.struc in - let candidates = Aux.map_some ( - fun (rname, precond, add, struc_elems, fixvar_elemvars) -> + let candidates = Aux.map_some (fun (rname, rdata) -> + let fixed_inst, _ = + match_meta [] [] [player_action] [rdata.lead_legal] in (* 9d *) (* {{{ log entry *) - if !debug_level > 4 then ( - Printf.printf "fixvar_elemvars: %s\n%!" - (String.concat "; " - (List.map (fun (v,ts)->v^": "^ - String.concat ", " (List.map (fun (t,_)->term_str t) ts)) - fixvar_elemvars)) - ); + if !debug_level > 4 then ( + Printf.printf "fixvar_elemvars: %s\n%!" + (String.concat "; " + (List.map (fun (v,ts)->v^": "^ + String.concat ", " (List.map (fun (t,_)->term_str t) ts)) + rdata.fixvar_elemvars)) + ); (* }}} *) - let anchors = Aux.concat_map (fun (v,t) -> - let elemvars = List.assoc v fixvar_elemvars in - Aux.concat_map (fun (mask, pevs) -> - Aux.concat_map (fun (path, evs) -> - let pred = List.assoc t - (List.assoc path (List.assoc mask gdl.anchor_terms)) in - List.map (fun ev-> - Formula.Rel (pred, [|Formula.fo_var_of_string - (String.lowercase ev)|])) evs) - pevs) elemvars - ) fixed_inst in - let precond = Formula.And (anchors @ [precond]) in + let anchors = Aux.concat_map (fun (v,t) -> + let elemvars = List.assoc v rdata.fixvar_elemvars in + Aux.concat_map (fun (mask, pevs) -> + Aux.concat_map (fun (path, evs) -> + let pred = List.assoc t + (List.assoc path (List.assoc mask gdl.anchor_terms)) in + List.map (fun ev-> + Formula.Rel (pred, [|Formula.fo_var_of_string + (String.lowercase ev)|])) evs) + pevs) elemvars + ) fixed_inst in + let precond = Formula.And (anchors @ [rdata.precond]) in (* {{{ log entry *) - if !debug_level > 4 then ( - Printf.printf "GDL.translate_incoming_move: trying precond=\n%s\n...%!" - (Formula.sprint precond) - ); + if !debug_level > 2 then ( + Printf.printf + "GDL.translate_incoming_move: rule=%s; trying precond=\n%s\n...%!" + rname (Formula.sprint precond) + ); (* }}} *) - let signat = Structure.rel_signature struc in - let rule = - DiscreteRule.translate_from_precond ~precond ~add - ~emb_rels:gdl.fluents ~signat ~struc_elems in - let lhs_struc = rule.DiscreteRule.lhs_struc in - let rule = DiscreteRule.compile_rule - (Structure.rel_signature struc) [] rule in - let asgns = - DiscreteRule.find_matchings struc rule in + let signat = Structure.rel_signature struc in + let rule = + DiscreteRule.translate_from_precond ~precond ~add:rdata.rhs_add + ~emb_rels:gdl.fluents ~signat ~struc_elems:rdata.struc_elems in + let lhs_struc = rule.DiscreteRule.lhs_struc in + let rule = DiscreteRule.compile_rule signat [] rule in + let asgns = + DiscreteRule.find_matchings struc rule in (* {{{ log entry *) - if !debug_level > 2 then ( - Printf.printf "found %s\n%!" (AssignmentSet.str asgns) - ); + if !debug_level > 2 then ( + Printf.printf "found %s\n%!" (AssignmentSet.str asgns) + ); (* }}} *) (* faster *) (* let emb = DiscreteRule.choose_match (snd state).Arena.struc rule asgns in *) (* but we should check whether there's no ambiguity... *) - match - DiscreteRule.enumerate_matchings struc rule asgns - with - | [] -> None - | [emb] -> Some (rname, emb, lhs_struc) - | _ -> failwith - ("GDL.translate_incoming_move: match ambiguity for rule "^rname) + match + DiscreteRule.enumerate_matchings struc rule asgns + with + | [] -> None + | [emb] -> Some (rname, emb, lhs_struc) + | _ -> failwith + ("GDL.translate_incoming_move: match ambiguity for rule "^rname) ) tossrules in match candidates with + | [] -> + failwith + "GDL.translate_incoming_move: no matching rule found" | [rname, emb, lhs_struc] -> (* {{{ log entry *) if !debug_level > 0 then ( @@ -3593,9 +3632,21 @@ ); (* }}} *) rname, emb - | _ -> failwith - ("GDL.translate_incoming_move: ambiguity among rules "^ - String.concat ", " (List.map Aux.fst3 candidates)) + | _ -> + (* {{{ log entry *) + if !debug_level > 0 then ( + Printf.printf "GDL.translate_incoming_move: ambiguity\n%!"; + List.iter (fun (rname, emb, lhs_struc) -> + Printf.printf "rname=%s; emb=%s\n%!" + rname + (String.concat ", " (List.map (fun (v,e) -> + Structure.elem_str lhs_struc v ^ ": " ^ + Structure.elem_str struc e) emb))) candidates + ); + (* }}} *) + failwith + ("GDL.translate_incoming_move: ambiguity among rules "^ + String.concat ", " (List.map Aux.fst3 candidates)) (* Modified: trunk/Toss/GGP/GDL.mli =================================================================== --- trunk/Toss/GGP/GDL.mli 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/GGP/GDL.mli 2011-03-21 23:38:06 UTC (rev 1376) @@ -9,6 +9,9 @@ type pair_matrix = Pairs_all | Pairs_triang | Pairs_star val equivalences_all_tuples : pair_matrix ref +(** Generate test case for the given game name. *) +val generate_test_case : string option ref + val manual_translation : bool ref val manual_game : string ref val top_exec_path : string ref @@ -96,11 +99,19 @@ term -> game_descr_entry list -> int -> (Arena.game * Arena.game_state) * (int * int * float) option * gdl_translation +val translate_incoming_move : + gdl_translation -> Arena.game * Arena.game_state -> term list -> + string * DiscreteRule.matching +(** As {!GDL.translate_incoming_move}, but with optional manual translation. *) val translate_last_action : gdl_translation -> Arena.game * Arena.game_state -> term list -> string * DiscreteRule.matching (** Rule name, embedding, game state. *) +val translate_outgoing_move : + gdl_translation -> Arena.game * Arena.game_state -> + string -> (int * int) list -> string +(** As {!GDL.translate_outgoing_move}, but with optional manual translation. *) val translate_move : gdl_translation -> Arena.game * Arena.game_state -> string -> (int * int) list -> string Modified: trunk/Toss/GGP/GDLParser.mly =================================================================== --- trunk/Toss/GGP/GDLParser.mly 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/GGP/GDLParser.mly 2011-03-21 23:38:06 UTC (rev 1376) @@ -14,8 +14,9 @@ %token FORALL EXISTS EOF -%start parse_game_description parse_request +%start parse_game_description parse_request parse_term %type <GDL.request> parse_request request +%type <GDL.term> parse_term %type <GDL.game_descr_entry list> parse_game_description game_description @@ -173,3 +174,6 @@ parse_request: | request EOF { $1 } + +parse_term: + | term EOF { $1 } Modified: trunk/Toss/GGP/GDLTest.ml =================================================================== --- trunk/Toss/GGP/GDLTest.ml 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/GGP/GDLTest.ml 2011-03-21 23:38:06 UTC (rev 1376) @@ -5,6 +5,12 @@ GDLParser.parse_game_description KIFLexer.lex (Lexing.from_string s) +let parse_term s = + GDLParser.parse_term KIFLexer.lex + (Lexing.from_string s) + +let pte = parse_term + let state_of_file s = let f = open_in s in let res = @@ -19,6 +25,14 @@ (Lexing.from_channel f) in (* List.map GDL.rule_of_entry *) descr +let emb_str (game, state) (rname, emb) = + let r = List.assoc rname game.Arena.rules in + let struc = state.Arena.struc in + ContinuousRule.embedding_str r struc emb + +let norm_move (rname,emb) = + rname, List.sort Pervasives.compare emb + let check_alternate players playout = let rec aux turn playout = match turn, playout with @@ -30,6 +44,47 @@ else aux turn playout in aux players playout +let game_test_case ~game_name ~player ~loc0_rule_name ~loc0_emb + ~loc0_move ~loc0_noop ~loc1 ~loc1_rule_name ~loc1_emb ~loc1_noop + ~loc1_move = + let game = load_rules ("./GGP/examples/"^game_name^".gdl") in + let gdl, res = GDL.translate_game (Const player) game in + let goal = state_of_file ("./GGP/tests/"^game_name^"-simpl.toss") in + let resf = open_out ("./GGP/tests/"^game_name^"-temp.toss") in + let res_str = Arena.state_str res in + output_string resf res_str; + close_out resf; + let eq, msg = Arena.compare_diff goal res in + assert_bool + ("GGP/examples/"^game_name^".gdl to GGP/tests/"^game_name^ + "-simpl.toss, see GGP/tests/"^game_name^"-temp.toss: "^msg) + eq; + Sys.remove ("./GGP/tests/"^game_name^"-temp.toss"); + let rname = loc0_rule_name in + let emb = + Arena.emb_of_names res rname loc0_emb in + let transl = + GDL.translate_outgoing_move gdl res rname emb in + assert_equal ~printer:(fun x->x) loc0_move transl; + let move = + GDL.translate_incoming_move gdl res + [pte loc0_move; pte loc0_noop] in + assert_equal ~msg:"own incoming move" ~printer:(emb_str res) + (norm_move (rname, emb)) (norm_move move); + let req = Arena.ApplyRuleInt (rname, emb, 0.1, []) in + let ((game,state), _) = Arena.handle_request res req in + let res = game, {state with Arena.cur_loc = loc1} in + let rname = loc1_rule_name in + let emb = + Arena.emb_of_names res rname loc1_emb in + let move = + GDL.translate_incoming_move gdl res + [pte loc1_noop; pte loc1_move] in + assert_equal ~msg:"opponent incoming move" + ~printer:(emb_str res) + (norm_move (rname, emb)) (norm_move move) + + let tests = "GDL" >::: [ "saturate" >:: @@ -82,46 +137,56 @@ (String.concat "\n" (List.map GDL.exp_def_str res)); ); + + "tictactoe" >:: + (fun () -> + game_test_case ~game_name:"tictactoe" ~player:"xplayer" + ~loc0_rule_name:"mark_x_y_0" + ~loc0_emb:[ + "cell_x_y__blank_", "cell_2_2_MV1"; + "control__blank_", "control_MV1"] + ~loc0_move:"(mark 2 2)" ~loc0_noop:"noop" + ~loc1:1 ~loc1_rule_name:"mark_x_y_1" + ~loc1_emb:[ + "cell_x_y__blank_", "cell_1_1_MV1"; + "control__blank_", "control_MV1"] + ~loc1_noop:"noop" ~loc1_move:"(mark 1 1)" + ); ] let bigtests = "GDLBig" >::: [ "connect5" >:: (fun () -> - let connect5 = load_rules "./GGP/examples/connect5.gdl" in - let _, res = GDL.translate_game (Const "x") connect5 in - let goal = state_of_file "./GGP/tests/connect5-simpl.toss" in - let resf = open_out "./GGP/tests/connect5-temp.toss" in - let res_str = Arena.state_str res in - output_string resf res_str; - close_out resf; - let eq, msg = Arena.compare_diff goal res in - assert_bool - ("GGP/examples/connect5.gdl to GGP/tests/connect5-simpl.toss, \ - see GGP/tests/connect5-temp.toss: "^msg) - eq; - Sys.remove "./GGP/tests/connect5-temp.toss" + game_test_case ~game_name:"connect5" ~player:"x" + ~loc0_rule_name:"mark_x149_y149_0" + ~loc0_emb:[ + "cell_x149_y149__blank_", "cell_e_f_MV1"; + "control__blank_", "control_MV1"] + ~loc0_move:"(mark e f)" ~loc0_noop:"noop" + ~loc1:1 ~loc1_rule_name:"mark_x159_y159_1" + ~loc1_emb:[ + "cell_x159_y159__blank_", "cell_f_g_MV1"; + "control__blank_", "control_MV1"] + ~loc1_noop:"noop" ~loc1_move:"(mark f g)" ); "breakthrough" >:: (fun () -> - let breakthrough = load_rules "./GGP/examples/breakthrough.gdl" in - let _, res = GDL.translate_game (Const "white") breakthrough in - let goal = state_of_file "./GGP/tests/breakthrough-simpl.toss" in - let resf = open_out "./GGP/tests/breakthrough-temp.toss" in - let res_str = Arena.state_str res in - output_string resf res_str; - close_out resf; - let eq, msg = Arena.compare_diff goal res in - assert_bool - ("GGP/examples/breakthrough.gdl to \ - GGP/tests/breakthrough-simpl.toss, see - GGP/tests/breakthrough-temp.toss: "^msg) - eq; - Sys.remove "./GGP/tests/breakthrough-temp.toss" + game_test_case ~game_name:"breakthrough" ~player:"white" + ~loc0_rule_name:"move_x1_y1_x2_y2_00" + ~loc0_emb:[ + "cellholds_x1_y1__blank_", "cellholds_2_2_MV1"; + "cellholds_x2_y2__blank_", "cellholds_3_3_MV1"; + "control__blank_", "control_MV1"] + ~loc0_move:"(move 2 2 3 3)" ~loc0_noop:"noop" ~loc1:1 + ~loc1_rule_name:"move_x1_y1_x2_y2_1" + ~loc1_emb:[ + "cellholds_x1_y1__blank_", "cellholds_7_7_MV1"; + "cellholds_x2_y2__blank_", "cellholds_6_6_MV1"; + "control__blank_", "control_MV1"] + ~loc1_noop:"noop" ~loc1_move:"(move 7 7 6 6)" ); - - ] @@ -132,19 +197,26 @@ Aux.run_test_if_target "GDLTest" bigtests let a () = + GDL.debug_level := 4; + (* GameSimpl.debug_level := 4; *) + (* DiscreteRule.debug_level := 4; *) + () + +let a () = match test_filter - ["GDL:2:masks"] - tests + [(* "GDLBig:1:breakthrough" *) "GDLBig:0:connect5"] + bigtests with | Some tests -> ignore (run_test_tt ~verbose:true tests) | None -> () let a () = + let game_name = "tictactoe" in + let player = "xplayer" in (* GDL.debug_level := 4; *) (* GameSimpl.debug_level := 4; *) (* DiscreteRule.debug_level := 4; *) - let breakthrough = load_rules "./GGP/examples/breakthrough.gdl" in - let connect5 = load_rules "./GGP/examples/connect5.gdl" in - let tictactoe = load_rules "./GGP/examples/tictactoe.gdl" in - let gdl_def, toss_def = GDL.translate_game (Const "white") breakthrough in - ignore gdl_def; ignore connect5; ignore breakthrough; ignore tictactoe + GDL.generate_test_case := Some game_name; + let game = load_rules ("./GGP/examples/"^game_name^".gdl") in + ignore (GDL.translate_game (Const player) game); + GDL.generate_test_case := None Modified: trunk/Toss/GGP/GameSimpl.ml =================================================================== --- trunk/Toss/GGP/GameSimpl.ml 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/GGP/GameSimpl.ml 2011-03-21 23:38:06 UTC (rev 1376) @@ -93,7 +93,7 @@ (4) Update rewrite rule signatures to contain all introduced relations. Remove from the structures relations that are no longer - used. + used; if [keep_predicates] is true, do not remove predicates. *) open Formula @@ -130,7 +130,7 @@ module Tups = Structure.Tuples -let simplify (game, state) = +let simplify ?(keep_predicates=true) (game, state) = let struc = state.Arena.struc in let signat = Structure.rel_signature struc in let nelems = Structure.Elems.cardinal struc.Structure.elements in @@ -747,6 +747,7 @@ if DiscreteRule.special_rel_of rel = None then rel else DiscreteRule.orig_rel_of rel in let res = + (not keep_predicates || List.assoc rel signat > 1) && not (List.mem rel fluents) && not (List.mem_assoc rel game.Arena.defined_rels) && not (Aux.Strings.mem rel used_rels) in Modified: trunk/Toss/GGP/GameSimpl.mli =================================================================== --- trunk/Toss/GGP/GameSimpl.mli 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/GGP/GameSimpl.mli 2011-03-21 23:38:06 UTC (rev 1376) @@ -11,4 +11,5 @@ val niceness : Formula.formula -> int val simplify : + ?keep_predicates:bool -> Arena.game * Arena.game_state -> Arena.game * Arena.game_state Modified: trunk/Toss/GGP/GameSimplTest.ml =================================================================== --- trunk/Toss/GGP/GameSimplTest.ml 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/GGP/GameSimplTest.ml 2011-03-21 23:38:06 UTC (rev 1376) @@ -59,23 +59,16 @@ | Some tests -> ignore (run_test_tt ~verbose:true tests) | None -> () +(* The action below is used to regenerate the test targets when + {!GameSimpl.simplify} changes. *) let a () = - let breakthrough = state_of_file "./GGP/tests/breakthrough-raw.toss" in - Printf.printf "\nINPUT:\n%s\n%!" (Arena.state_str breakthrough); - GameSimpl.debug_level := 4; - let res = GameSimpl.simplify breakthrough in - let resf = open_out "./GGP/tests/breakthrough-simpl.toss" in - let res_str = Arena.state_str res in - output_string resf res_str; - close_out resf; - Printf.printf "\nRESULT:\n%s\n%!" res_str + let game_name = "tictactoe" in -let a () = - let connect5 = state_of_file "./GGP/tests/connect5-raw.toss" in - Printf.printf "\nINPUT:\n%s\n%!" (Arena.state_str connect5); + let game = state_of_file ("./GGP/tests/"^game_name^"-raw.toss") in + Printf.printf "\nINPUT:\n%s\n%!" (Arena.state_str game); GameSimpl.debug_level := 4; - let res = GameSimpl.simplify connect5 in - let resf = open_out "./GGP/tests/connect5-simpl.toss" in + let res = GameSimpl.simplify game in + let resf = open_out ("./GGP/tests/"^game_name^"-simpl.toss") in let res_str = Arena.state_str res in output_string resf res_str; close_out resf; Modified: trunk/Toss/GGP/tests/breakthrough-simpl.toss =================================================================== --- trunk/Toss/GGP/tests/breakthrough-simpl.toss 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/GGP/tests/breakthrough-simpl.toss 2011-03-21 23:38:06 UTC (rev 1376) @@ -525,16 +525,87 @@ (cellholds_1_3_MV1, cellholds_1_2_MV1); (cellholds_1_2_MV1, cellholds_1_1_MV1) }; + cellholds_1_y2_MV1 { + cellholds_1_8_MV1; cellholds_1_7_MV1; cellholds_1_6_MV1; + cellholds_1_5_MV1; cellholds_1_4_MV1; cellholds_1_3_MV1; + cellholds_1_2_MV1; cellholds_1_1_MV1 + }; + cellholds_2_y2_MV1 { + cellholds_2_8_MV1; cellholds_2_7_MV1; cellholds_2_6_MV1; + cellholds_2_5_MV1; cellholds_2_4_MV1; cellholds_2_3_MV1; + cellholds_2_2_MV1; cellholds_2_1_MV1 + }; + cellholds_3_y2_MV1 { + cellholds_3_8_MV1; cellholds_3_7_MV1; cellholds_3_6_MV1; + cellholds_3_5_MV1; cellholds_3_4_MV1; cellholds_3_3_MV1; + cellholds_3_2_MV1; cellholds_3_1_MV1 + }; + cellholds_4_y2_MV1 { + cellholds_4_8_MV1; cellholds_4_7_MV1; cellholds_4_6_MV1; + cellholds_4_5_MV1; cellholds_4_4_MV1; cellholds_4_3_MV1; + cellholds_4_2_MV1; cellholds_4_1_MV1 + }; + cellholds_5_y2_MV1 { + cellholds_5_8_MV1; cellholds_5_7_MV1; cellholds_5_6_MV1; + cellholds_5_5_MV1; cellholds_5_4_MV1; cellholds_5_3_MV1; + cellholds_5_2_MV1; cellholds_5_1_MV1 + }; + cellholds_6_y2_MV1 { + cellholds_6_8_MV1; cellholds_6_7_MV1; cellholds_6_6_MV1; + cellholds_6_5_MV1; cellholds_6_4_MV1; cellholds_6_3_MV1; + cellholds_6_2_MV1; cellholds_6_1_MV1 + }; + cellholds_7_y2_MV1 { + cellholds_7_8_MV1; cellholds_7_7_MV1; cellholds_7_6_MV1; + cellholds_7_5_MV1; cellholds_7_4_MV1; cellholds_7_3_MV1; + cellholds_7_2_MV1; cellholds_7_1_MV1 + }; + cellholds_8_y2_MV1 { + cellholds_8_8_MV1; cellholds_8_7_MV1; cellholds_8_6_MV1; + cellholds_8_5_MV1; cellholds_8_4_MV1; cellholds_8_3_MV1; + cellholds_8_2_MV1; cellholds_8_1_MV1 + }; cellholds_x2_1_MV1 { cellholds_8_1_MV1; cellholds_7_1_MV1; cellholds_6_1_MV1; cellholds_5_1_MV1; cellholds_4_1_MV1; cellholds_3_1_MV1; cellholds_2_1_MV1; cellholds_1_1_MV1 }; + cellholds_x2_2_MV1 { + cellholds_8_2_MV1; cellholds_7_2_MV1; cellholds_6_2_MV1; + cellholds_5_2_MV1; cellholds_4_2_MV1; cellholds_3_2_MV1; + cellholds_2_2_MV1; cellholds_1_2_MV1 + }; + cellholds_x2_3_MV1 { + cellholds_8_3_MV1; cellholds_7_3_MV1; cellholds_6_3_MV1; + cellholds_5_3_MV1; cellholds_4_3_MV1; cellholds_3_3_MV1; + cellholds_2_3_MV1; cellholds_1_3_MV1 + }; + cellholds_x2_4_MV1 { + cellholds_8_4_MV1; cellholds_7_4_MV1; cellholds_6_4_MV1; + cellholds_5_4_MV1; cellholds_4_4_MV1; cellholds_3_4_MV1; + cellholds_2_4_MV1; cellholds_1_4_MV1 + }; + cellholds_x2_5_MV1 { + cellholds_8_5_MV1; cellholds_7_5_MV1; cellholds_6_5_MV1; + cellholds_5_5_MV1; cellholds_4_5_MV1; cellholds_3_5_MV1; + cellholds_2_5_MV1; cellholds_1_5_MV1 + }; + cellholds_x2_6_MV1 { + cellholds_8_6_MV1; cellholds_7_6_MV1; cellholds_6_6_MV1; + cellholds_5_6_MV1; cellholds_4_6_MV1; cellholds_3_6_MV1; + cellholds_2_6_MV1; cellholds_1_6_MV1 + }; + cellholds_x2_7_MV1 { + cellholds_8_7_MV1; cellholds_7_7_MV1; cellholds_6_7_MV1; + cellholds_5_7_MV1; cellholds_4_7_MV1; cellholds_3_7_MV1; + cellholds_2_7_MV1; cellholds_1_7_MV1 + }; cellholds_x2_8_MV1 { cellholds_8_8_MV1; cellholds_7_8_MV1; cellholds_6_8_MV1; cellholds_5_8_MV1; cellholds_4_8_MV1; cellholds_3_8_MV1; cellholds_2_8_MV1; cellholds_1_8_MV1 }; + cellholds_x2_y2_MV1:1 {}; cellholds_x2_y2_black { cellholds_8_8_MV1; cellholds_8_7_MV1; cellholds_7_8_MV1; cellholds_7_7_MV1; cellholds_6_8_MV1; cellholds_6_7_MV1; @@ -552,6 +623,9 @@ cellholds_1_1_MV1 }; control_MV1 (control_MV1); control_black:1 {}; - control_white (control_MV1) + control_white (control_MV1); index__cellholds_x2_y2_MV1_x2:1 {}; + index__cellholds_x2_y2_MV1_y2:1 {}; init__cellholds_x2_y2_MV1_x2:1 {}; + init__cellholds_x2_y2_MV1_y2:1 {}; role__cellholds_x2_y2_MV1_x2:1 {}; + role__cellholds_x2_y2_MV1_y2:1 {} | ] Modified: trunk/Toss/GGP/tests/connect5-simpl.toss =================================================================== --- trunk/Toss/GGP/tests/connect5-simpl.toss 2011-03-21 10:39:44 UTC (rev 1375) +++ trunk/Toss/GGP/tests/connect5-simpl.toss 2011-03-21 23:38:06 UTC (rev 1376) @@ -756,6 +756,71 @@ (cell_b_c_MV1, cell_a_d_MV1); (cell_b_b_MV1, cell_a_c_MV1); (cell_b_a_MV1, cell_a_b_MV1) }; + cell_a_y_MV1 { + cell_a_h_MV1; cell_a_g_MV1; cell_a_f_MV1; cell_a_e_MV1; cell_a_d_MV1; + cell_a_c_MV1; cell_a_b_MV1; cell_a_a_MV1 + }; + cell_b_y_MV1 { + cell_b_h_MV1; cell_b_g_MV1; cell_b_f_MV1; cell_b_e_MV1; cell_b_d_MV1; + cell_b_c_MV1; cell_b_b_MV1; cell_b_a_MV1 + }; + cell_c_y_MV1 { + cell_c_h_MV1; cell_c_g_MV1; cell_c_f_MV1; cell_c_e_MV1; cell_c_d_MV1; + cell_c_c_MV1; cell_c_b_MV1; cell_c_a_MV1 + }; + cell_d_y_MV1 { + cell_d_h_MV1; cell_d_g_MV1; cell_d_f_MV1; cell_d_e_MV1; cell_d_d_MV1; + cell_d_c_MV1; cell_d_b_MV1; cell_d_a_MV1 + }; + cell_e_y_MV1 { + cell_e_h_MV1; cell_e_g_MV1; cell_e_f_MV1; cell_e_e_MV1; cell_e_d_MV1; + cell_e_c_MV1; cell_e_b_MV1; cell_e_a_MV1 + }; + cell_f_y_MV1 { + cell_f_h_MV1; cell_f_g_MV1; cell_f_f_MV1; cell_f_e_MV1; cell_f_d_MV1; + cell_f_c_MV1; cell_f_b_MV1; cell_f_a_MV1 + }; + cell_g_y_MV1 { + cell_g_h_MV1; cell_g_g_MV1; cell_g_f_MV1; cell_g_e_MV1; cell_g_d_MV1; + cell_g_c_MV1; cell_g_b_MV1; cell_g_a_MV1 + }; + cell_h_y_MV1 { + cell_h_h_MV1; cell_h_g_MV1; cell_h_f_MV1; cell_h_e_MV1; cell_h_d_MV1; + cell_h_c_MV1; cell_h_b_MV1; cell_h_a_MV1 + }; + cell_x_a_MV1 { + cell_h_a_MV1; cell_g_a_MV1; cell_f_a_MV1; cell_e_a_MV1; cell_d_a_MV1; + cell_c_a_MV1; cell_b_a_MV1; cell_a_a_MV1 + }; + cell_x_b_MV1 { + cell_h_b_MV1; cell_g_b_MV1; cell_f_b_MV1; cell_e_b_MV1; cell_d_b_MV1; + cell_c_b_MV1; cell_b_b_MV1; cell_a_b_MV1 + }; + cell_x_c_MV1 { + cell_h_c_MV1; cell_g_c_MV1; cell_f_c_MV1; cell_e_c_MV1; cell_d_c_MV1; + cell_c_c_MV1; cell_b_c_MV1; cell_a_c_MV1 + }; + cell_x_d_MV1 { + cell_h_d_MV1; cell_g_d_MV1; cell_f_d_MV1; cell_e_d_MV1; cell_d_d_MV1; + cell_c_d_MV1; cell_b_d_MV1; cell_a_d_MV1 + }; + cell_x_e_MV1 { + cell_h_e_MV1; cell_g_e_MV1; cell_f_e_MV1; cell_e_e_MV1; cell_d_e_MV1; + cell_c_e_MV1; cell_b_e_MV1; cell_a_e_MV1 + }; + cell_x_f_MV1 { + cell_h_f_MV1; cell_g_f_MV1; cell_f_f_MV1; cell_e_f_MV1; cell_d_f_MV1; + cell_c_f_MV1; cell_b_f_MV1; cell_a_f_MV1 + }; + cell_x_g_MV1 { + cell_h_g_MV1; cell_g_g_MV1; cell_f_g_MV1; cell_e_g_MV1; cell_d_g_MV1; + cell_c_g_MV1; cell_b_g_MV1; cell_a_g_MV1 + }; + cell_x_h_MV1 { + cell_h_h_MV1; cell_g_h_MV1; cell_f_h_MV1; cell_e_h_MV1; cell_d_h_MV1; + cell_c_h_MV1; cell_b_h_MV1; cell_a_h_MV1 + }; + cell_x_y_MV1:1 {}; cell_x_y_b { cell_h_h_MV1; cell_h_g_MV1; cell_h_f_MV1; cell_h_e_MV1; cell_h_d_MV1; cell_h_c_MV1; cell_h_b_MV1; cell_h_a_MV1; cell_g_h_MV1; cell_g_g_MV1; @@ -772,6 +837,9 @@ cell_a_d_MV1; cell_a_c_MV1; cell_a_b_MV1; cell_a_a_MV1 }; cell_x_y_o:1 {}; cell_x_y_x:1 {}; control_MV1 (control_MV1); - control_o:1 {}; control_x (control_MV1) + control_o:1 {}; control_x (control_MV1); coordinate__cell_x_y_MV1_x:1 {}; + coordinate__cell_x_y_MV1_y:1 {}; init__cell_x_y_MV1_x:1 {}; + init__cell_x_y_MV1_y:1 {}; role__cell_x_y_MV1_x:1 {}; + role__cell_x_y_MV1_y:1 {} | ] Added: trunk/Toss/GGP/tests/tictactoe-raw.toss =================================================================== --- trunk/Toss/GGP/tests/tictactoe-raw.toss (rev 0) +++ trunk/Toss/GGP/tests/tictactoe-raw.toss 2011-03-21 23:38:06 UTC (rev 1376) @@ -0,0 +1,552 @@ +PLAYERS xplayer, oplayer +RULE mark_x_y_0: + [cell_x_y__blank_, control__blank_ | + _opt_cell_m_n_b (control__blank_); + _opt_cell_m_n_o {cell_x_y__blank_; control__blank_}; + _opt_cell_m_n_x {cell_x_y__blank_; control__blank_}; + _opt_control_oplayer (cell_x_y__blank_); + _opt_control_xplayer (cell_x_y__blank_); cell_m_n_b (cell_x_y__blank_); + control_xplayer (control__blank_) + | + ] -> + [cell_x_y__blank_, control__blank_ | + cell_m_n_x (cell_x_y__blank_); control_oplayer (control__blank_) | + ] + emb cell_m_n_b, cell_m_n_o, cell_m_n_x, control_oplayer, control_xplayer + pre + (not + ex cell_m43_3__blank_, cell_m43_2__blank_, cell_m43_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m43_1__blank_, cell_m43_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m43_1__blank_, cell_m43_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m43_2__blank_, cell_m43_3__blank_) and + cell_m_1_MV1(cell_m43_1__blank_) and + cell_m_2_MV1(cell_m43_2__blank_) and + cell_m_3_MV1(cell_m43_3__blank_) and + cell_m_n_x(cell_m43_1__blank_) and cell_m_n_x(cell_m43_2__blank_) and + cell_m_n_x(cell_m43_3__blank_)) and + not + ex cell_3_m44__blank_, cell_2_m44__blank_, cell_1_m44__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m44__blank_, cell_2_m44__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m44__blank_, cell_3_m44__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m44__blank_, cell_3_m44__blank_) and + cell_1_n_MV1(cell_1_m44__blank_) and + cell_2_n_MV1(cell_2_m44__blank_) and + cell_3_n_MV1(cell_3_m44__blank_) and + cell_m_n_x(cell_1_m44__blank_) and cell_m_n_x(cell_2_m44__blank_) and + cell_m_n_x(cell_3_m44__blank_)) and + not + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and cell_3_n_MV1(cell_3_3__blank_) and + cell_m_n_x(cell_1_1__blank_) and cell_m_n_x(cell_2_2__blank_) and + cell_m_n_x(cell_3_3__blank_)) and + not + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and cell_3_n_MV1(cell_3_1__blank_) and + cell_m_n_x(cell_1_3__blank_) and cell_m_n_x(cell_2_2__blank_) and + cell_m_n_x(cell_3_1__blank_)) and + not + ex cell_m45_3__blank_, cell_m45_2__blank_, cell_m45_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m45_1__blank_, cell_m45_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m45_1__blank_, cell_m45_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m45_2__blank_, cell_m45_3__blank_) and + cell_m_1_MV1(cell_m45_1__blank_) and + cell_m_2_MV1(cell_m45_2__blank_) and + cell_m_3_MV1(cell_m45_3__blank_) and + cell_m_n_o(cell_m45_1__blank_) and cell_m_n_o(cell_m45_2__blank_) and + cell_m_n_o(cell_m45_3__blank_)) and + not + ex cell_3_m46__blank_, cell_2_m46__blank_, cell_1_m46__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m46__blank_, cell_2_m46__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m46__blank_, cell_3_m46__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m46__blank_, cell_3_m46__blank_) and + cell_1_n_MV1(cell_1_m46__blank_) and + cell_2_n_MV1(cell_2_m46__blank_) and + cell_3_n_MV1(cell_3_m46__blank_) and + cell_m_n_o(cell_1_m46__blank_) and cell_m_n_o(cell_2_m46__blank_) and + cell_m_n_o(cell_3_m46__blank_)) and + not + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and cell_3_n_MV1(cell_3_3__blank_) and + cell_m_n_o(cell_1_1__blank_) and cell_m_n_o(cell_2_2__blank_) and + cell_m_n_o(cell_3_3__blank_)) and + not + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and cell_3_n_MV1(cell_3_1__blank_) and + cell_m_n_o(cell_1_3__blank_) and cell_m_n_o(cell_2_2__blank_) and + cell_m_n_o(cell_3_1__blank_)) and + ex cell_m47_n23__blank_ cell_m_n_b(cell_m47_n23__blank_)) +RULE mark_x_y_1: + [cell_x_y__blank_, control__blank_ | + _opt_cell_m_n_b (control__blank_); + _opt_cell_m_n_o {cell_x_y__blank_; control__blank_}; + _opt_cell_m_n_x {cell_x_y__blank_; control__blank_}; + _opt_control_oplayer (cell_x_y__blank_); + _opt_control_xplayer (cell_x_y__blank_); cell_m_n_b (cell_x_y__blank_); + control_oplayer (control__blank_) + | + ] -> + [cell_x_y__blank_, control__blank_ | + cell_m_n_o (cell_x_y__blank_); control_xplayer (control__blank_) | + ] + emb cell_m_n_b, cell_m_n_o, cell_m_n_x, control_oplayer, control_xplayer + pre + (not + ex cell_m43_3__blank_, cell_m43_2__blank_, cell_m43_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m43_1__blank_, cell_m43_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m43_1__blank_, cell_m43_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m43_2__blank_, cell_m43_3__blank_) and + cell_m_1_MV1(cell_m43_1__blank_) and + cell_m_2_MV1(cell_m43_2__blank_) and + cell_m_3_MV1(cell_m43_3__blank_) and + cell_m_n_x(cell_m43_1__blank_) and cell_m_n_x(cell_m43_2__blank_) and + cell_m_n_x(cell_m43_3__blank_)) and + not + ex cell_3_m44__blank_, cell_2_m44__blank_, cell_1_m44__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m44__blank_, cell_2_m44__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m44__blank_, cell_3_m44__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m44__blank_, cell_3_m44__blank_) and + cell_1_n_MV1(cell_1_m44__blank_) and + cell_2_n_MV1(cell_2_m44__blank_) and + cell_3_n_MV1(cell_3_m44__blank_) and + cell_m_n_x(cell_1_m44__blank_) and cell_m_n_x(cell_2_m44__blank_) and + cell_m_n_x(cell_3_m44__blank_)) and + not + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and cell_3_n_MV1(cell_3_3__blank_) and + cell_m_n_x(cell_1_1__blank_) and cell_m_n_x(cell_2_2__blank_) and + cell_m_n_x(cell_3_3__blank_)) and + not + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and cell_3_n_MV1(cell_3_1__blank_) and + cell_m_n_x(cell_1_3__blank_) and cell_m_n_x(cell_2_2__blank_) and + cell_m_n_x(cell_3_1__blank_)) and + not + ex cell_m45_3__blank_, cell_m45_2__blank_, cell_m45_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m45_1__blank_, cell_m45_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m45_1__blank_, cell_m45_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m45_2__blank_, cell_m45_3__blank_) and + cell_m_1_MV1(cell_m45_1__blank_) and + cell_m_2_MV1(cell_m45_2__blank_) and + cell_m_3_MV1(cell_m45_3__blank_) and + cell_m_n_o(cell_m45_1__blank_) and cell_m_n_o(cell_m45_2__blank_) and + cell_m_n_o(cell_m45_3__blank_)) and + not + ex cell_3_m46__blank_, cell_2_m46__blank_, cell_1_m46__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m46__blank_, cell_2_m46__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m46__blank_, cell_3_m46__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m46__blank_, cell_3_m46__blank_) and + cell_1_n_MV1(cell_1_m46__blank_) and + cell_2_n_MV1(cell_2_m46__blank_) and + cell_3_n_MV1(cell_3_m46__blank_) and + cell_m_n_o(cell_1_m46__blank_) and cell_m_n_o(cell_2_m46__blank_) and + cell_m_n_o(cell_3_m46__blank_)) and + not + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and cell_3_n_MV1(cell_3_3__blank_) and + cell_m_n_o(cell_1_1__blank_) and cell_m_n_o(cell_2_2__blank_) and + cell_m_n_o(cell_3_3__blank_)) and + not + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and cell_3_n_MV1(cell_3_1__blank_) and + cell_m_n_o(cell_1_3__blank_) and cell_m_n_o(cell_2_2__blank_) and + cell_m_n_o(cell_3_1__blank_)) and + ex cell_m47_n23__blank_ cell_m_n_b(cell_m47_n23__blank_)) +LOC 0 { + PLAYER xplayer + PAYOFF { + xplayer: + 50. + + -50. * + :( + ex cell_m7_3__blank_, cell_m7_2__blank_, cell_m7_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m7_1__blank_, cell_m7_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m7_1__blank_, cell_m7_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m7_2__blank_, cell_m7_3__blank_) and + cell_m_1_MV1(cell_m7_1__blank_) and + cell_m_2_MV1(cell_m7_2__blank_) and + cell_m_3_MV1(cell_m7_3__blank_) and + cell_m_n_o(cell_m7_1__blank_) and cell_m_n_o(cell_m7_2__blank_) and + cell_m_n_o(cell_m7_3__blank_)) or + ex cell_3_m8__blank_, cell_2_m8__blank_, cell_1_m8__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m8__blank_, cell_2_m8__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m8__blank_, cell_3_m8__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m8__blank_, cell_3_m8__blank_) and + cell_1_n_MV1(cell_1_m8__blank_) and + cell_2_n_MV1(cell_2_m8__blank_) and + cell_3_n_MV1(cell_3_m8__blank_) and + cell_m_n_o(cell_1_m8__blank_) and cell_m_n_o(cell_2_m8__blank_) and + cell_m_n_o(cell_3_m8__blank_)) or + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and + cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and + cell_3_n_MV1(cell_3_3__blank_) and cell_m_n_o(cell_1_1__blank_) and + cell_m_n_o(cell_2_2__blank_) and cell_m_n_o(cell_3_3__blank_)) or + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and + cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and + cell_3_n_MV1(cell_3_1__blank_) and cell_m_n_o(cell_1_3__blank_) and + cell_m_n_o(cell_2_2__blank_) and cell_m_n_o(cell_3_1__blank_)) + ) + + + 50. * + :( + ex cell_m0_3__blank_, cell_m0_2__blank_, cell_m0_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m0_1__blank_, cell_m0_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m0_1__blank_, cell_m0_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m0_2__blank_, cell_m0_3__blank_) and + cell_m_1_MV1(cell_m0_1__blank_) and + cell_m_2_MV1(cell_m0_2__blank_) and + cell_m_3_MV1(cell_m0_3__blank_) and + cell_m_n_x(cell_m0_1__blank_) and cell_m_n_x(cell_m0_2__blank_) and + cell_m_n_x(cell_m0_3__blank_)) or + ex cell_3_m1__blank_, cell_2_m1__blank_, cell_1_m1__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m1__blank_, cell_2_m1__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m1__blank_, cell_3_m1__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m1__blank_, cell_3_m1__blank_) and + cell_1_n_MV1(cell_1_m1__blank_) and + cell_2_n_MV1(cell_2_m1__blank_) and + cell_3_n_MV1(cell_3_m1__blank_) and + cell_m_n_x(cell_1_m1__blank_) and cell_m_n_x(cell_2_m1__blank_) and + cell_m_n_x(cell_3_m1__blank_)) or + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and + cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and + cell_3_n_MV1(cell_3_3__blank_) and cell_m_n_x(cell_1_1__blank_) and + cell_m_n_x(cell_2_2__blank_) and cell_m_n_x(cell_3_3__blank_)) or + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and + cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and + cell_3_n_MV1(cell_3_1__blank_) and cell_m_n_x(cell_1_3__blank_) and + cell_m_n_x(cell_2_2__blank_) and cell_m_n_x(cell_3_1__blank_)) + ); + oplayer: + 50. + + -50. * + :( + ex cell_m16_3__blank_, cell_m16_2__blank_, cell_m16_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m16_1__blank_, cell_m16_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m16_1__blank_, cell_m16_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m16_2__blank_, cell_m16_3__blank_) and + cell_m_1_MV1(cell_m16_1__blank_) and + cell_m_2_MV1(cell_m16_2__blank_) and + cell_m_3_MV1(cell_m16_3__blank_) and + cell_m_n_x(cell_m16_1__blank_) and + cell_m_n_x(cell_m16_2__blank_) and cell_m_n_x(cell_m16_3__blank_)) or + ex cell_3_m17__blank_, cell_2_m17__blank_, cell_1_m17__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m17__blank_, cell_2_m17__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m17__blank_, cell_3_m17__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m17__blank_, cell_3_m17__blank_) and + cell_1_n_MV1(cell_1_m17__blank_) and + cell_2_n_MV1(cell_2_m17__blank_) and + cell_3_n_MV1(cell_3_m17__blank_) and + cell_m_n_x(cell_1_m17__blank_) and + cell_m_n_x(cell_2_m17__blank_) and cell_m_n_x(cell_3_m17__blank_)) or + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and + cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and + cell_3_n_MV1(cell_3_3__blank_) and + cell_m_n_x(cell_1_1__blank_) and cell_m_n_x(cell_2_2__blank_) and + cell_m_n_x(cell_3_3__blank_)) or + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and + cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and + cell_3_n_MV1(cell_3_1__blank_) and + cell_m_n_x(cell_1_3__blank_) and cell_m_n_x(cell_2_2__blank_) and + cell_m_n_x(cell_3_1__blank_)) + ) + + + 50. * + :( + ex cell_m9_3__blank_, cell_m9_2__blank_, cell_m9_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m9_1__blank_, cell_m9_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m9_1__blank_, cell_m9_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m9_2__blank_, cell_m9_3__blank_) and + cell_m_1_MV1(cell_m9_1__blank_) and + cell_m_2_MV1(cell_m9_2__blank_) and + cell_m_3_MV1(cell_m9_3__blank_) and + cell_m_n_o(cell_m9_1__blank_) and cell_m_n_o(cell_m9_2__blank_) and + cell_m_n_o(cell_m9_3__blank_)) or + ex cell_3_m10__blank_, cell_2_m10__blank_, cell_1_m10__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m10__blank_, cell_2_m10__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m10__blank_, cell_3_m10__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m10__blank_, cell_3_m10__blank_) and + cell_1_n_MV1(cell_1_m10__blank_) and + cell_2_n_MV1(cell_2_m10__blank_) and + cell_3_n_MV1(cell_3_m10__blank_) and + cell_m_n_o(cell_1_m10__blank_) and + cell_m_n_o(cell_2_m10__blank_) and cell_m_n_o(cell_3_m10__blank_)) or + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and + cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and + cell_3_n_MV1(cell_3_3__blank_) and + cell_m_n_o(cell_1_1__blank_) and cell_m_n_o(cell_2_2__blank_) and + cell_m_n_o(cell_3_3__blank_)) or + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and + cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and + cell_3_n_MV1(cell_3_1__blank_) and + cell_m_n_o(cell_1_3__blank_) and cell_m_n_o(cell_2_2__blank_) and + cell_m_n_o(cell_3_1__blank_)) + ) + } + MOVES [mark_x_y_0 -> 1] + } +LOC 1 { + PLAYER oplayer + PAYOFF { + xplayer: + 50. + + -50. * + :( + ex cell_m7_3__blank_, cell_m7_2__blank_, cell_m7_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m7_1__blank_, cell_m7_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m7_1__blank_, cell_m7_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m7_2__blank_, cell_m7_3__blank_) and + cell_m_1_MV1(cell_m7_1__blank_) and + cell_m_2_MV1(cell_m7_2__blank_) and + cell_m_3_MV1(cell_m7_3__blank_) and + cell_m_n_o(cell_m7_1__blank_) and cell_m_n_o(cell_m7_2__blank_) and + cell_m_n_o(cell_m7_3__blank_)) or + ex cell_3_m8__blank_, cell_2_m8__blank_, cell_1_m8__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m8__blank_, cell_2_m8__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m8__blank_, cell_3_m8__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m8__blank_, cell_3_m8__blank_) and + cell_1_n_MV1(cell_1_m8__blank_) and + cell_2_n_MV1(cell_2_m8__blank_) and + cell_3_n_MV1(cell_3_m8__blank_) and + cell_m_n_o(cell_1_m8__blank_) and cell_m_n_o(cell_2_m8__blank_) and + cell_m_n_o(cell_3_m8__blank_)) or + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and + cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and + cell_3_n_MV1(cell_3_3__blank_) and cell_m_n_o(cell_1_1__blank_) and + cell_m_n_o(cell_2_2__blank_) and cell_m_n_o(cell_3_3__blank_)) or + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and + cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and + cell_3_n_MV1(cell_3_1__blank_) and cell_m_n_o(cell_1_3__blank_) and + cell_m_n_o(cell_2_2__blank_) and cell_m_n_o(cell_3_1__blank_)) + ) + + + 50. * + :( + ex cell_m0_3__blank_, cell_m0_2__blank_, cell_m0_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m0_1__blank_, cell_m0_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m0_1__blank_, cell_m0_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m0_2__blank_, cell_m0_3__blank_) and + cell_m_1_MV1(cell_m0_1__blank_) and + cell_m_2_MV1(cell_m0_2__blank_) and + cell_m_3_MV1(cell_m0_3__blank_) and + cell_m_n_x(cell_m0_1__blank_) and cell_m_n_x(cell_m0_2__blank_) and + cell_m_n_x(cell_m0_3__blank_)) or + ex cell_3_m1__blank_, cell_2_m1__blank_, cell_1_m1__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m1__blank_, cell_2_m1__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m1__blank_, cell_3_m1__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m1__blank_, cell_3_m1__blank_) and + cell_1_n_MV1(cell_1_m1__blank_) and + cell_2_n_MV1(cell_2_m1__blank_) and + cell_3_n_MV1(cell_3_m1__blank_) and + cell_m_n_x(cell_1_m1__blank_) and cell_m_n_x(cell_2_m1__blank_) and + cell_m_n_x(cell_3_m1__blank_)) or + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and + cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and + cell_3_n_MV1(cell_3_3__blank_) and cell_m_n_x(cell_1_1__blank_) and + cell_m_n_x(cell_2_2__blank_) and cell_m_n_x(cell_3_3__blank_)) or + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and + cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and + cell_3_n_MV1(cell_3_1__blank_) and cell_m_n_x(cell_1_3__blank_) and + cell_m_n_x(cell_2_2__blank_) and cell_m_n_x(cell_3_1__blank_)) + ); + oplayer: + 50. + + -50. * + :( + ex cell_m16_3__blank_, cell_m16_2__blank_, cell_m16_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m16_1__blank_, cell_m16_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m16_1__blank_, cell_m16_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m16_2__blank_, cell_m16_3__blank_) and + cell_m_1_MV1(cell_m16_1__blank_) and + cell_m_2_MV1(cell_m16_2__blank_) and + cell_m_3_MV1(cell_m16_3__blank_) and + cell_m_n_x(cell_m16_1__blank_) and + cell_m_n_x(cell_m16_2__blank_) and cell_m_n_x(cell_m16_3__blank_)) or + ex cell_3_m17__blank_, cell_2_m17__blank_, cell_1_m17__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m17__blank_, cell_2_m17__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m17__blank_, cell_3_m17__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m17__blank_, cell_3_m17__blank_) and + cell_1_n_MV1(cell_1_m17__blank_) and + cell_2_n_MV1(cell_2_m17__blank_) and + cell_3_n_MV1(cell_3_m17__blank_) and + cell_m_n_x(cell_1_m17__blank_) and + cell_m_n_x(cell_2_m17__blank_) and cell_m_n_x(cell_3_m17__blank_)) or + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and + cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and + cell_3_n_MV1(cell_3_3__blank_) and + cell_m_n_x(cell_1_1__blank_) and cell_m_n_x(cell_2_2__blank_) and + cell_m_n_x(cell_3_3__blank_)) or + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and + cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(cell_3_1__blank_) and + cell_3_n_MV1(cell_3_1__blank_) and + cell_m_n_x(cell_1_3__blank_) and cell_m_n_x(cell_2_2__blank_) and + cell_m_n_x(cell_3_1__blank_)) + ) + + + 50. * + :( + ex cell_m9_3__blank_, cell_m9_2__blank_, cell_m9_1__blank_ + (EQ___cell_m_n_MV1_m(cell_m9_1__blank_, cell_m9_2__blank_) and + EQ___cell_m_n_MV1_m(cell_m9_1__blank_, cell_m9_3__blank_) and + EQ___cell_m_n_MV1_m(cell_m9_2__blank_, cell_m9_3__blank_) and + cell_m_1_MV1(cell_m9_1__blank_) and + cell_m_2_MV1(cell_m9_2__blank_) and + cell_m_3_MV1(cell_m9_3__blank_) and + cell_m_n_o(cell_m9_1__blank_) and cell_m_n_o(cell_m9_2__blank_) and + cell_m_n_o(cell_m9_3__blank_)) or + ex cell_3_m10__blank_, cell_2_m10__blank_, cell_1_m10__blank_ + (EQ___cell_m_n_MV1_n(cell_1_m10__blank_, cell_2_m10__blank_) and + EQ___cell_m_n_MV1_n(cell_1_m10__blank_, cell_3_m10__blank_) and + EQ___cell_m_n_MV1_n(cell_2_m10__blank_, cell_3_m10__blank_) and + cell_1_n_MV1(cell_1_m10__blank_) and + cell_2_n_MV1(cell_2_m10__blank_) and + cell_3_n_MV1(cell_3_m10__blank_) and + cell_m_n_o(cell_1_m10__blank_) and + cell_m_n_o(cell_2_m10__blank_) and cell_m_n_o(cell_3_m10__blank_)) or + ex cell_3_3__blank_, cell_2_2__blank_, cell_1_1__blank_ + (cell_m_1_MV1(cell_1_1__blank_) and + cell_1_n_MV1(cell_1_1__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_3_MV1(cell_3_3__blank_) and + cell_3_n_MV1(cell_3_3__blank_) and + cell_m_n_o(cell_1_1__blank_) and cell_m_n_o(cell_2_2__blank_) and + cell_m_n_o(cell_3_3__blank_)) or + ex cell_3_1__blank_, cell_2_2__blank_, cell_1_3__blank_ + (cell_m_3_MV1(cell_1_3__blank_) and + cell_1_n_MV1(cell_1_3__blank_) and + cell_m_2_MV1(cell_2_2__blank_) and + cell_2_n_MV1(cell_2_2__blank_) and + cell_m_1_MV1(c... [truncated message content] |
From: <luk...@us...> - 2011-03-21 10:39:50
|
Revision: 1375 http://toss.svn.sourceforge.net/toss/?rev=1375&view=rev Author: lukstafi Date: 2011-03-21 10:39:44 +0000 (Mon, 21 Mar 2011) Log Message: ----------- Heuristic test for GGP/tests/breakthrough-simpl.toss (forgot to switch logging off). Modified Paths: -------------- trunk/Toss/Play/HeuristicTest.ml Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2011-03-21 10:35:26 UTC (rev 1374) +++ trunk/Toss/Play/HeuristicTest.ml 2011-03-21 10:39:44 UTC (rev 1375) @@ -432,16 +432,16 @@ ] -let a () = +let a = Aux.run_test_if_target "HeuristicTest" tests -let a () = +let a = Aux.run_test_if_target "HeuristicTest" bigtests -let a = +let a () = Heuristic.debug_level := 5 -let a = +let a () = match test_filter ["Heuristic:10:default_heuristic_old: expansion breakthrough of GDL translation"] tests with This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <luk...@us...> - 2011-03-21 10:35:32
|
Revision: 1374 http://toss.svn.sourceforge.net/toss/?rev=1374&view=rev Author: lukstafi Date: 2011-03-21 10:35:26 +0000 (Mon, 21 Mar 2011) Log Message: ----------- Heuristic test for GGP/tests/breakthrough-simpl.toss. Modified Paths: -------------- trunk/Toss/Play/HeuristicTest.ml Modified: trunk/Toss/Play/HeuristicTest.ml =================================================================== --- trunk/Toss/Play/HeuristicTest.ml 2011-03-21 09:38:35 UTC (rev 1373) +++ trunk/Toss/Play/HeuristicTest.ml 2011-03-21 10:35:26 UTC (rev 1374) @@ -18,6 +18,13 @@ DiscreteRuleParser.parse_discrete_rule Lexer.lex (Lexing.from_string s) signat (Formula.And []) +let state_of_file s = + let f = open_in s in + let res = + ArenaParser.parse_game_state Lexer.lex + (Lexing.from_channel f) in + res + let winQxyz = "ex x, y, z ((((Q(x) and Q(y)) and Q(z)) and ((((R(x, y) and R(y, z)) or (C(x, y) and C(y, z))) or ex u, v ((((R(x, v) and C(v, y)) and R(y, u)) and C(u, z)))) or ex u, v ((((R(x, v) and C(y, v)) and R(y, u)) and C(z, u))))))" @@ -298,6 +305,19 @@ (Heuristic.is_constant_sum_one [|h; Formula.Times (Formula.Const (-1.), h)|]) )); + + + "default_heuristic_old: expansion breakthrough of GDL translation" >:: + (fun () -> + let (game,state) = + state_of_file "./GGP/tests/breakthrough-simpl.toss" in + let loc_heurs = + Heuristic.default_heuristic_old ~struc:state.Arena.struc + ~advr:2.0 game in + assert_equal ~printer:(fun x->x) + "(100. * ((0.5 + (1. * :((not ex cellholds_x27_y26__blank_ ((cellholds_x2_y2_black(cellholds_x27_y26__blank_) and (not control_MV1(cellholds_x27_y26__blank_)))))))) + Sum (cellholds_x26_8__blank_ | cellholds_x2_y2_white(cellholds_x26_8__blank_) : (1. + MORE SUM TERMS HERE))))" + (Formula.real_str loc_heurs.(0).(0)); + ); ] @@ -412,14 +432,17 @@ ] -let a = +let a () = Aux.run_test_if_target "HeuristicTest" tests -let a = +let a () = Aux.run_test_if_target "HeuristicTest" bigtests -let a () = - match test_filter ["Heuristic:9:of_payoff: monotonic gomoku"] +let a = + Heuristic.debug_level := 5 + +let a = + match test_filter ["Heuristic:10:default_heuristic_old: expansion breakthrough of GDL translation"] tests with | Some tests -> ignore (run_test_tt ~verbose:true tests) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |