[Toss-devel-svn] SF.net SVN: toss:[1527] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
|
From: <luk...@us...> - 2011-08-05 18:35:16
|
Revision: 1527
http://toss.svn.sourceforge.net/toss/?rev=1527&view=rev
Author: lukstafi
Date: 2011-08-05 18:35:09 +0000 (Fri, 05 Aug 2011)
Log Message:
-----------
GDL translation fixing: initial structure generation bug (wrong terms as elements); setting up formula translation testing.
Modified Paths:
--------------
trunk/Toss/GGP/GDL.mli
trunk/Toss/GGP/TranslateGame.ml
trunk/Toss/GGP/TranslateGameTest.ml
trunk/Toss/Server/Tests.ml
Added Paths:
-----------
trunk/Toss/GGP/TranslateFormulaTest.ml
Modified: trunk/Toss/GGP/GDL.mli
===================================================================
--- trunk/Toss/GGP/GDL.mli 2011-08-05 12:09:48 UTC (rev 1526)
+++ trunk/Toss/GGP/GDL.mli 2011-08-05 18:35:09 UTC (rev 1527)
@@ -174,6 +174,8 @@
val at_paths : ?fail_at_missing:bool -> path_set -> term -> term list
val empty_path_set : path_set
+(** Add path to a set. First argument gives term arities. *)
+val add_path : (string -> int) -> path -> path_set -> path_set
val paths_union : path_set -> path_set -> path_set
(** List the paths in a set. *)
Added: trunk/Toss/GGP/TranslateFormulaTest.ml
===================================================================
--- trunk/Toss/GGP/TranslateFormulaTest.ml (rev 0)
+++ trunk/Toss/GGP/TranslateFormulaTest.ml 2011-08-05 18:35:09 UTC (rev 1527)
@@ -0,0 +1,74 @@
+open OUnit
+open TranslateFormula
+
+let parse_game_descr s =
+ 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 =
+ ArenaParser.parse_game_state Lexer.lex
+ (Lexing.from_channel f) in
+ res
+
+let load_rules fname =
+ let f = open_in fname in
+ let descr =
+ GDLParser.parse_game_description KIFLexer.lex
+ (Lexing.from_channel f) in
+ descr
+
+let connect5_data =
+ let term_arities =
+ ["control", 1; "cell", 3; "x", 0; "o", 0; "b", 0; "mark", 2] in
+ let arities f = List.assoc f term_arities in
+ let f_paths = List.fold_right (GDL.add_path arities)
+ [["cell", 2]; ["control", 0]] GDL.empty_path_set in
+ let m_paths = List.fold_right (GDL.add_path arities)
+ [["cell", 0]; ["cell", 1]] GDL.empty_path_set in
+ let all_paths = GDL.paths_union f_paths m_paths in
+ let mask_reps =
+ [GDL.Func ("control", [|GDL.blank|]);
+ GDL.Func ("cell", [|GDL.blank; GDL.blank; GDL.blank|])] in
+ let defined_rels = [
+ "adjacent_cell"; "col"; "conn5"; "diag1"; "diag2";
+ "exists_empty_cell"; "exists_line_of_five"; "goal"; "legal"; "next";
+ "row"; "terminal"] in
+ {
+ f_paths = f_paths;
+ m_paths = m_paths;
+ all_paths = all_paths;
+ mask_reps = mask_reps;
+ defined_rels = defined_rels;
+ defrel_arg_type = ref [];
+ term_arities = term_arities;
+ }
+
+let tests = "TranslateFormula" >::: [
+
+ "defined relations connect5" >::
+ (fun () ->
+ let descr = load_rules ("./GGP/examples/connect5.gdl") in
+ let clauses = GDL.expand_players descr in
+ let transl_data = connect5_data in
+ let defined_rels =
+ TranslateFormula.build_defrels transl_data clauses in
+ let res = String.concat "\n"
+ (List.map (fun (rel,(args,body)) ->
+ rel^"("^String.concat ", " args^
+ ") = "^Formula.str body) defined_rels) in
+ assert_equal ~msg:"connect5 noop moves by players"
+ ~printer:(fun x->x)
+ "" res;
+ );
+
+]
+
+let exec = Aux.run_test_if_target "TranslateFormulaTest" tests
Modified: trunk/Toss/GGP/TranslateGame.ml
===================================================================
--- trunk/Toss/GGP/TranslateGame.ml 2011-08-05 12:09:48 UTC (rev 1526)
+++ trunk/Toss/GGP/TranslateGame.ml 2011-08-05 18:35:09 UTC (rev 1527)
@@ -327,6 +327,7 @@
(String.concat ", " struc_rels) (String.concat ", " defined_rels)
);
(* }}} *)
+ let stable_rels = ref Aux.Strings.empty in
let struc =
List.fold_left (fun struc rel ->
let arity = List.assoc rel arities in
@@ -338,37 +339,42 @@
let tup = Array.of_list (List.map2 at_path etup ptup) in
if rel = "EQ_" && arity = 2 && tup.(0) = tup.(1)
|| List.mem (rel, tup) static_base
- then
+ then (
+ stable_rels := Aux.Strings.add fact_rel !stable_rels;
Structure.add_rel_named_elems struc fact_rel
- (Array.map term_to_name tup)
+ (* we add the element repr. tuple if subterms at ptup
+ are in relation *)
+ (Aux.array_map_of_list term_to_name etup))
else struc
) struc elem_tups
) struc path_tups
) (Structure.empty_structure ()) struc_rels in
(* adding anchor and fluent predicates *)
- let add_pred rels struc paths elements =
+ let add_pred sig_only rels struc paths elements =
List.fold_left (fun struc path ->
Aux.fold_left_try (fun struc elem ->
let pred =
pred_on_path_subterm path (at_path elem path) in
- if List.mem pred !rels then struc
- else (
- rels := pred :: !rels;
- let tup = [|elem|] in
- Structure.add_rel_named_elems struc pred
- (Array.map term_to_name tup))
+ rels := Aux.Strings.add pred !rels;
+ if sig_only
+ then Structure.add_rel_name pred 1 struc
+ else
+ (* in case the state term is not element repr. yet *)
+ let elem = simult_subst f_paths blank elem in
+ let tup = [|term_to_name elem|] in
+ Structure.add_rel_named_elems struc pred tup
) struc elements
) struc paths in
- let stable_rels = ref [] in
- let fluents = ref [] in
- let struc = add_pred stable_rels struc m_pathl element_reps in
- let struc = add_pred fluents struc f_pathl init_state in
+ let fluents = ref Aux.Strings.empty in
+ let struc = add_pred false stable_rels struc m_pathl element_reps in
+ let struc = add_pred false fluents struc f_pathl init_state in
+ let struc = add_pred true fluents struc f_pathl element_terms in
(* adding mask predicates *)
let all_paths = paths_union m_paths f_paths in
let struc =
List.fold_left (fun struc m ->
let pred = term_to_name m in
- stable_rels := pred :: !stable_rels;
+ stable_rels := Aux.Strings.add pred !stable_rels;
List.fold_left (fun struc elem ->
if simult_subst all_paths blank elem = m
then (
@@ -378,7 +384,7 @@
) struc element_reps
) struc mask_reps in
(* {{{ log entry *)
- if !debug_level > 2 then (
+ if !debug_level > 4 then (
Printf.printf "create_init_struc: resulting struc=\n%s\n%!"
(Structure.str struc)
);
@@ -392,7 +398,7 @@
Structure.find_elem struc (term_to_name e), e) element_reps) in
players, rules,
next_clauses, f_paths, m_paths, mask_reps, defined_rels,
- !stable_rels, !fluents,
+ Aux.Strings.elements !stable_rels, Aux.Strings.elements !fluents,
static_base, init_state, struc, agg_actions, elem_term_map
(* substitute a "next" clause with frame info *)
Modified: trunk/Toss/GGP/TranslateGameTest.ml
===================================================================
--- trunk/Toss/GGP/TranslateGameTest.ml 2011-08-05 12:09:48 UTC (rev 1526)
+++ trunk/Toss/GGP/TranslateGameTest.ml 2011-08-05 18:35:09 UTC (rev 1527)
@@ -143,18 +143,18 @@
assert_equal ~msg:"defined_rels" ~printer:(fun x->x)
"adjacent_cell, col, conn5, diag1, diag2, exists_empty_cell, exists_line_of_five, goal, legal, next, row, terminal"
- (String.concat ", " defined_rels);
+ (String.concat ", " (List.sort String.compare defined_rels));
assert_equal ~msg:"fluents" ~printer:(fun x->x)
- "control_0x, control_0o, cell_2b, cell_2x, cell_2o"
+ "cell_2b, cell_2o, cell_2x, control_0o, control_0x"
(String.concat ", " fluents);
assert_equal ~msg:"stable_rels" ~printer:(fun x->x)
- "A LOT OF THEM"
+ "EQ___cell_0__cell_0, EQ___cell_0__cell_1, EQ___cell_1__cell_0, EQ___cell_1__cell_1, adjacent__cell_0__cell_0, adjacent__cell_0__cell_1, adjacent__cell_1__cell_0, adjacent__cell_1__cell_1, cell_0a, cell_0b, cell_0c, cell_0d, cell_0e, cell_0f, cell_0g, cell_0h, cell_1a, cell_1b, cell_1c, cell_1d, cell_1e, cell_1f, cell_1g, cell_1h, cell__BLANK___BLANK___BLANK_, control__BLANK_, coordinate__cell_0, coordinate__cell_1, nextcol__cell_0__cell_0, nextcol__cell_0__cell_1, nextcol__cell_1__cell_0, nextcol__cell_1__cell_1"
(String.concat ", " stable_rels);
assert_equal ~msg:"structure elements" ~printer:(fun x->x)
- "cell_a_a__BLANK_, cell_a_b__BLANK_, cell_a_c__BLANK_, cell_a_d__BLANK_, cell_a_e__BLANK_, cell_a_f__BLANK_, cell_a_g__BLANK_, cell_a_h__BLANK_, cell_b_a__BLANK_, cell_b_b__BLANK_, cell_b_c__BLANK_, cell_b_d__BLANK_, cell_b_e__BLANK_, cell_b_f__BLANK_, cell_b_g__BLANK_, cell_b_h__BLANK_, cell_c_a__BLANK_, cell_c_b__BLANK_, cell_c_c__BLANK_, cell_c_d__BLANK_, cell_c_e__BLANK_, cell_c_f__BLANK_, cell_c_g__BLANK_, cell_c_h__BLANK_, cell_d_a__BLANK_, cell_d_b__BLANK_, cell_d_c__BLANK_, cell_d_d__BLANK_, cell_d_e__BLANK_, cell_d_f__BLANK_, cell_d_g__BLANK_, cell_d_h__BLANK_, cell_e_a__BLANK_, cell_e_b__BLANK_, cell_e_c__BLANK_, cell_e_d__BLANK_, cell_e_e__BLANK_, cell_e_f__BLANK_, cell_e_g__BLANK_, cell_e_h__BLANK_, cell_f_a__BLANK_, cell_f_b__BLANK_, cell_f_c__BLANK_, cell_f_d__BLANK_, cell_f_e__BLANK_, cell_f_f__BLANK_, cell_f_g__BLANK_, cell_f_h__BLANK_, cell_g_a__BLANK_, cell_g_b__BLANK_, cell_g_c__BLANK_, cell_g_d__BLANK_, cell_g_e__BLANK_, cell_g_f__BLANK_, cell_g_g__BLANK_, cell_g_h__BLANK_, cell_h_a__BLANK_, cell_h_b__BLANK_, cell_h_c__BLANK_, cell_h_d__BLANK_, cell_h_e__BLANK_, cell_h_f__BLANK_, cell_h_g__BLANK_, cell_h_h__BLANK_"
+ "cell_a_a__BLANK_, cell_a_b__BLANK_, cell_a_c__BLANK_, cell_a_d__BLANK_, cell_a_e__BLANK_, cell_a_f__BLANK_, cell_a_g__BLANK_, cell_a_h__BLANK_, cell_b_a__BLANK_, cell_b_b__BLANK_, cell_b_c__BLANK_, cell_b_d__BLANK_, cell_b_e__BLANK_, cell_b_f__BLANK_, cell_b_g__BLANK_, cell_b_h__BLANK_, cell_c_a__BLANK_, cell_c_b__BLANK_, cell_c_c__BLANK_, cell_c_d__BLANK_, cell_c_e__BLANK_, cell_c_f__BLANK_, cell_c_g__BLANK_, cell_c_h__BLANK_, cell_d_a__BLANK_, cell_d_b__BLANK_, cell_d_c__BLANK_, cell_d_d__BLANK_, cell_d_e__BLANK_, cell_d_f__BLANK_, cell_d_g__BLANK_, cell_d_h__BLANK_, cell_e_a__BLANK_, cell_e_b__BLANK_, cell_e_c__BLANK_, cell_e_d__BLANK_, cell_e_e__BLANK_, cell_e_f__BLANK_, cell_e_g__BLANK_, cell_e_h__BLANK_, cell_f_a__BLANK_, cell_f_b__BLANK_, cell_f_c__BLANK_, cell_f_d__BLANK_, cell_f_e__BLANK_, cell_f_f__BLANK_, cell_f_g__BLANK_, cell_f_h__BLANK_, cell_g_a__BLANK_, cell_g_b__BLANK_, cell_g_c__BLANK_, cell_g_d__BLANK_, cell_g_e__BLANK_, cell_g_f__BLANK_, cell_g_g__BLANK_, cell_g_h__BLANK_, cell_h_a__BLANK_, cell_h_b__BLANK_, cell_h_c__BLANK_, cell_h_d__BLANK_, cell_h_e__BLANK_, cell_h_f__BLANK_, cell_h_g__BLANK_, cell_h_h__BLANK_, control__BLANK_"
(String.concat ", "
(List.map (Structure.elem_name struc) (Structure.elements struc)))
);
@@ -236,48 +236,7 @@
"control__blank_", "control_MV1"]
~loc1_noop:"noop" ~loc1_move:"(mark f g)"
-let a () =
- let descr = load_rules ("./GGP/examples/connect5.gdl") in
- let clauses = GDL.expand_players descr in
- let players, rules,
- next_cls, f_paths, m_paths, mask_reps, defined_rels,
- stable_rels, fluents,
- stable_base, init_state, struc, agg_actions, elem_term_map =
- TranslateGame.create_init_struc clauses in
- assert_equal ~msg:"f_paths" ~printer:(fun x->x)
- "cell_2; control_0"
- (String.concat "; "
- (List.map GDL.path_str (GDL.paths_to_list f_paths)));
-
- assert_equal ~msg:"m_paths" ~printer:(fun x->x)
- "cell_0; cell_1"
- (String.concat "; "
- (List.map GDL.path_str (GDL.paths_to_list m_paths)));
-
- assert_equal ~msg:"mask_reps" ~printer:(fun x->x)
- "(cell _BLANK_ _BLANK_ _BLANK_); (control _BLANK_)"
- (String.concat "; "
- (List.map GDL.term_str mask_reps));
-
- assert_equal ~msg:"defined_rels" ~printer:(fun x->x)
- "adjacent_cell, col, conn5, diag1, diag2, exists_empty_cell, exists_line_of_five, goal, legal, next, row, terminal"
- (String.concat ", " defined_rels);
-
- assert_equal ~msg:"fluents" ~printer:(fun x->x)
- "control_0x, control_0o, cell_2b, cell_2x, cell_2o"
- (String.concat ", " fluents);
-
- assert_equal ~msg:"stable_rels" ~printer:(fun x->x)
- "A LOT OF THEM"
- (String.concat ", " stable_rels);
-
- assert_equal ~msg:"structure elements" ~printer:(fun x->x)
- "cell_a_a__BLANK_, cell_a_b__BLANK_, cell_a_c__BLANK_, cell_a_d__BLANK_, cell_a_e__BLANK_, cell_a_f__BLANK_, cell_a_g__BLANK_, cell_a_h__BLANK_, cell_b_a__BLANK_, cell_b_b__BLANK_, cell_b_c__BLANK_, cell_b_d__BLANK_, cell_b_e__BLANK_, cell_b_f__BLANK_, cell_b_g__BLANK_, cell_b_h__BLANK_, cell_c_a__BLANK_, cell_c_b__BLANK_, cell_c_c__BLANK_, cell_c_d__BLANK_, cell_c_e__BLANK_, cell_c_f__BLANK_, cell_c_g__BLANK_, cell_c_h__BLANK_, cell_d_a__BLANK_, cell_d_b__BLANK_, cell_d_c__BLANK_, cell_d_d__BLANK_, cell_d_e__BLANK_, cell_d_f__BLANK_, cell_d_g__BLANK_, cell_d_h__BLANK_, cell_e_a__BLANK_, cell_e_b__BLANK_, cell_e_c__BLANK_, cell_e_d__BLANK_, cell_e_e__BLANK_, cell_e_f__BLANK_, cell_e_g__BLANK_, cell_e_h__BLANK_, cell_f_a__BLANK_, cell_f_b__BLANK_, cell_f_c__BLANK_, cell_f_d__BLANK_, cell_f_e__BLANK_, cell_f_f__BLANK_, cell_f_g__BLANK_, cell_f_h__BLANK_, cell_g_a__BLANK_, cell_g_b__BLANK_, cell_g_c__BLANK_, cell_g_d__BLANK_, cell_g_e__BLANK_, cell_g_f__BLANK_, cell_g_g__BLANK_, cell_g_h__BLANK_, cell_h_a__BLANK_, cell_h_b__BLANK_, cell_h_c__BLANK_, cell_h_d__BLANK_, cell_h_e__BLANK_, cell_h_f__BLANK_, cell_h_g__BLANK_, cell_h_h__BLANK_"
- (String.concat ", "
- (List.map (Structure.elem_name struc) (Structure.elements struc)))
-
-
let a () =
match test_filter
[(* "GDLBig:1:breakthrough" *) "GDLBig:0:connect5"]
@@ -303,3 +262,8 @@
(* regenerate ~debug:true ~game_name:"pawn_whopping" ~player:"x"; *)
(* regen_with_debug ~game_name:"connect4" ~player:"white" *)
*)
+
+let exec =
+ Aux.run_test_if_target "TranslateGameTest"
+ ("TranslateGame" >::: [tests; bigtests])
+
Modified: trunk/Toss/Server/Tests.ml
===================================================================
--- trunk/Toss/Server/Tests.ml 2011-08-05 12:09:48 UTC (rev 1526)
+++ trunk/Toss/Server/Tests.ml 2011-08-05 18:35:09 UTC (rev 1527)
@@ -35,6 +35,7 @@
"GameSimplTest", [GameSimplTest.tests];
"GDLTest", [GDLTest.tests];
"TranslateGameTest", [TranslateGameTest.tests; TranslateGameTest.bigtests];
+ "TranslateFormulaTest", [TranslateFormulaTest.tests];
]
let server_tests = "Server", [
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|