[Toss-devel-svn] SF.net SVN: toss:[1723] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
|
From: <luk...@us...> - 2012-06-09 20:09:15
|
Revision: 1723
http://toss.svn.sourceforge.net/toss/?rev=1723&view=rev
Author: lukaszkaiser
Date: 2012-06-09 20:09:07 +0000 (Sat, 09 Jun 2012)
Log Message:
-----------
Work on the Parsing game and other small improvements.
Modified Paths:
--------------
trunk/Toss/Arena/Arena.ml
trunk/Toss/Arena/Arena.mli
trunk/Toss/Arena/ArenaParser.mly
trunk/Toss/Arena/ArenaTest.ml
trunk/Toss/Client/State.js
trunk/Toss/Client/Style.css
trunk/Toss/Client/eval.html
trunk/Toss/Client/img/Forces.png
trunk/Toss/Client/img/Parsing.png
trunk/Toss/Solver/Solver.ml
trunk/Toss/Solver/Structure.ml
trunk/Toss/Solver/Structure.mli
trunk/Toss/examples/Forces.toss
trunk/Toss/examples/Parsing.toss
trunk/Toss/www/index.xml
Modified: trunk/Toss/Arena/Arena.ml
===================================================================
--- trunk/Toss/Arena/Arena.ml 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Arena/Arena.ml 2012-06-09 20:09:07 UTC (rev 1723)
@@ -267,6 +267,15 @@
let add_def_rels struc rels = List.fold_left add_def_rel_single struc rels
+let add_def_fun_single struc (f, v, def_re) =
+ let elems = Structure.elements struc in
+ let asg e = AssignmentSet.FO (v, [(e, AssignmentSet.Any)]) in
+ let fval e = Solver.M.get_real_val ~asg:(asg e) def_re struc in
+ List.fold_left (fun s e-> Structure.change_fun_int s f e (fval e)) struc elems
+
+let add_def_funs struc funs = List.fold_left add_def_fun_single struc funs
+
+
(* The order of following entries matters: [DefPlayers] adds more
players, with consecutive numbers starting from first available;
later [StartStruc], [CurrentStruc], [StateTime] and [StateLoc] entries
Modified: trunk/Toss/Arena/Arena.mli
===================================================================
--- trunk/Toss/Arena/Arena.mli 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Arena/Arena.mli 2012-06-09 20:09:07 UTC (rev 1723)
@@ -70,7 +70,10 @@
val add_def_rels : Structure.structure ->
(string * string list * Formula.formula) list -> Structure.structure
+val add_def_funs : Structure.structure ->
+ (string * string * Formula.real_expr) list -> Structure.structure
+
(** Print a label as a string. *)
val label_str : label -> string
val move_str : (label * int) -> string
Modified: trunk/Toss/Arena/ArenaParser.mly
===================================================================
--- trunk/Toss/Arena/ArenaParser.mly 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Arena/ArenaParser.mly 2012-06-09 20:09:07 UTC (rev 1723)
@@ -94,6 +94,10 @@
| rel = ID args = delimited (OPEN, separated_list (COMMA, ID), CLOSE)
EQ body = formula_expr_err { (rel, args, body) }
+fun_def_simple:
+ | COLON f = ID OPEN v = ID CLOSE EQ body = real_expr
+ { (f, v, body) }
+
game_move_timed:
| OPENSQ r = id_int t = FLOAT RARR l = INT EMB
emb = separated_list (COMMA, separated_pair (ID, COLON, id_int)) CLOSESQ
@@ -138,11 +142,19 @@
| START model = struct_expr WITH
defs = separated_list (SEMICOLON, rel_def_simple)
{ StartStruc (Arena.add_def_rels model defs) }
+ | START model = struct_expr WITH
+ defs = separated_list (SEMICOLON, rel_def_simple) WITH
+ funs = separated_list (SEMICOLON, fun_def_simple)
+ { StartStruc (Arena.add_def_funs (Arena.add_def_rels model defs) funs) }
| CURRENT model = struct_expr
{ CurrentStruc model }
| CURRENT model = struct_expr WITH
defs = separated_list (SEMICOLON, rel_def_simple)
{ CurrentStruc (Arena.add_def_rels model defs) }
+ | CURRENT model = struct_expr WITH
+ defs = separated_list (SEMICOLON, rel_def_simple) WITH
+ funs = separated_list (SEMICOLON, fun_def_simple)
+ { StartStruc (Arena.add_def_funs (Arena.add_def_rels model defs) funs) }
| MOVES moves = separated_list (SEMICOLON, game_move_timed)
{ History (moves) }
| TIME_MOD t = FLOAT
Modified: trunk/Toss/Arena/ArenaTest.ml
===================================================================
--- trunk/Toss/Arena/ArenaTest.ml 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Arena/ArenaTest.ml 2012-06-09 20:09:07 UTC (rev 1723)
@@ -17,7 +17,9 @@
"structure with rels parsing" >::
(fun () ->
let test p s res = assert_equal ~printer:(fun x -> x) res (rel_str p s) in
- test "P" "START [ 1 - 5 | | - ] with P(a) = :nbr(a) = 2" "P (e2)";
+ test "P" "START [ 1 - 5 | | - ] with P(a) = :nbr(a)= 2" "P (e2)";
+ test "P" "START [ 1 - 5 | | - ] with P(a) = :nbr(a)= 2 with :y(a) = 10*&a"
+ "P (e2)";
test "P" ("START [ 1 - 10 | | - ] with P(z) = &z > 1 and " ^
"all x, y (&x * &y = &z -> (&x = 1 or &y = 1))")
"P {e2; e3; e5; e7}";
Modified: trunk/Toss/Client/State.js
===================================================================
--- trunk/Toss/Client/State.js 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Client/State.js 2012-06-09 20:09:07 UTC (rev 1723)
@@ -196,10 +196,14 @@
}
function square_elements_game (game) {
- return (game !== "Connect4" &&
- game !== "Bounce" &&
- game !== "Cell-Cycle-Tyson-1991" &&
- game !== "Rewriting-Example")
+ return (game === "Breakthrough" ||
+ game === "Checkers" ||
+ game === "Chess" ||
+ game === "Entanglement" ||
+ game === "Gomoku" ||
+ game === "Pawn-Whopping" ||
+ game === "Tic-Tac-Toe" ||
+ game === "Hnefatafl")
}
// Draw the model.
@@ -261,8 +265,8 @@
}
// Main draw_model function.
- var sqrt = Math.round (Math.sqrt (this.elems.length));
- if (sqrt * sqrt == this.elems.length) { // perhaps a grid
+ var sqrt = Math.round (Math.sqrt (this.elems.length)); // perhaps a grid
+ if (sqrt * sqrt == this.elems.length && (sqrt > 4 || game=="Tic-Tac-Toe")) {
SHAPES.elem_size_x = SVG_WIDTH / (2.0 * (sqrt-1));
SHAPES.elem_size_y = SVG_HEIGHT / (2.0 * (sqrt-1));
} else {
Modified: trunk/Toss/Client/Style.css
===================================================================
--- trunk/Toss/Client/Style.css 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Client/Style.css 2012-06-09 20:09:07 UTC (rev 1723)
@@ -1055,17 +1055,17 @@
stroke-width: 5px;
}
-.model-pred-Cyc {
+.model-pred-Cyc, .model-pred-Pone {
stroke: #260314;
stroke-width: 3px;
fill: #e5effa;
}
-.model-pred-CycP1 {
+.model-pred-CycP1, .model-pred-Tnbr {
stroke: #260314;
stroke-width: 3px;
fill: #a5afaa;
}
-.model-pred-Cdc2 {
+.model-pred-Cdc2, .model-pred-Pnil {
stroke: #260314;
stroke-width: 3px;
fill: #93a605;
@@ -1075,7 +1075,7 @@
stroke-width: 3px;
fill: #3e5916;
}
-.model-pred-Cdc2CycP1 {
+.model-pred-Cdc2CycP1, .model-pred-Tlist {
stroke: #260314;
stroke-width: 3px;
fill: #f28705;
Modified: trunk/Toss/Client/eval.html
===================================================================
--- trunk/Toss/Client/eval.html 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Client/eval.html 2012-06-09 20:09:07 UTC (rev 1723)
@@ -94,7 +94,8 @@
<textarea id="structure" rows="3" cols="40">
[ 1 - 5 | | - ] with
-E(x, y) = &x = &y + 1</textarea>
+E(x, y) = &x = &y + 1
+with :y(a) = -10 * &a</textarea>
<button onclick="eval()">Eval and Draw</button>
Modified: trunk/Toss/Client/img/Forces.png
===================================================================
(Binary files differ)
Modified: trunk/Toss/Client/img/Parsing.png
===================================================================
(Binary files differ)
Modified: trunk/Toss/Solver/Solver.ml
===================================================================
--- trunk/Toss/Solver/Solver.ml 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Solver/Solver.ml 2012-06-09 20:09:07 UTC (rev 1723)
@@ -526,13 +526,13 @@
| re ->
update_cache struc;
try
- let (res, _) = Hashtbl.find !re_cache_results re in
+ let (res, _) = Hashtbl.find !re_cache_results (re, asg) in
LOG 2 "found in re cache: %s" (Formula.real_str re);
res
with Not_found ->
LOG 1 "Get real val %s" (real_str re);
let re_val = get_real_val solver asg re struc in
- Hashtbl.add !re_cache_results re (re_val, re_rels re);
+ Hashtbl.add !re_cache_results (re, asg) (re_val, re_rels re);
re_val
(* Evaluate i-th formula on j-th structure. *)
Modified: trunk/Toss/Solver/Structure.ml
===================================================================
--- trunk/Toss/Solver/Structure.ml 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Solver/Structure.ml 2012-06-09 20:09:07 UTC (rev 1723)
@@ -349,11 +349,12 @@
List.fold_left (fun s a -> add_fun s fn a) struc assgns
(* Change function [fn] assignment for element [e] to [x] in [struc]. *)
-let change_fun struc fn elem x =
- let assgs, e = StringMap.find fn struc.functions, elem_nbr struc elem in
+let change_fun_int struc fn e x =
+ let assgs = StringMap.find fn struc.functions in
let new_functions = StringMap.add fn (IntMap.add e x assgs) struc.functions in
{ struc with functions = new_functions }
+let change_fun struc fn elem x = change_fun_int struc fn (elem_nbr struc elem) x
(* ------------ GLOBAL FUNCTIONS TO CREATE STRUCTURES FROM LISTS ------------ *)
Modified: trunk/Toss/Solver/Structure.mli
===================================================================
--- trunk/Toss/Solver/Structure.mli 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/Solver/Structure.mli 2012-06-09 20:09:07 UTC (rev 1723)
@@ -229,6 +229,7 @@
(** Change function [fn] assignment for element [e] to [x] in [struc]. *)
val change_fun : structure -> string -> string -> float -> structure
+val change_fun_int : structure -> string -> int -> float -> structure
(** {2 Global function to create structures from lists} *)
Modified: trunk/Toss/examples/Forces.toss
===================================================================
--- trunk/Toss/examples/Forces.toss 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/examples/Forces.toss 2012-06-09 20:09:07 UTC (rev 1723)
@@ -42,7 +42,7 @@
LOC 0 {
PLAYER 1 { PAYOFF 0. MOVES [Move,
- :t : 3. -- 3.,
+ :t : 5. -- 5.,
:k : 0.1 -- 0.1,
:f : 0.1 -- 0.1,
:ke : 200. -- 200. -> 0] }
@@ -50,6 +50,6 @@
UNIVERSAL { Coulomb, Hooke, Friction }
}
-START [ e5 | Start(e1); E { (e1, e2); (e1, e3); (e1, e4) } |
- vx { e1->0, e2->0, e3->0, e4->0, e5->0 }; vy { e1->0, e2->0, e3->0, e4->0,e5->0 };
- x { e1->0., e2->10., e3->10., e4->10, e5->0. }; y { e1->0., e2->9, e3->0, e4->-9, e5->0 } ]
+START [ | Start(e1); E { (e1, e2); (e1, e3); (e1, e4) } |
+ vx { e1->0, e2->0, e3->0, e4->0 }; vy { e1->0, e2->0, e3->0, e4->0 };
+ x { e1->0., e2->10., e3->10., e4->10 }; y { e1->0., e2->9, e3->0, e4->-9 } ]
Modified: trunk/Toss/examples/Parsing.toss
===================================================================
--- trunk/Toss/examples/Parsing.toss 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/examples/Parsing.toss 2012-06-09 20:09:07 UTC (rev 1723)
@@ -1,16 +1,35 @@
PLAYERS 1, 2
RULE NilList:
- [e1 | Pnil(e1) | ] -> [a1, a2 | Pnil (a1); Tp (a1, a2); Tlist (a2) | ]
+ [e1 | Pnil(e1) | ] -> [a1, a2 | Pnil (a1); E (a1, a2); Tlist (a2) | ]
emb Pnil with [a1 <- e1] update
:x(a1) = :x(e1);
:x(a2) = :x(e1);
:y(a1) = :y(e1);
- :y(a2) = :y(e1) + 1.
+ :y(a2) = :y(e1) - 1
+RULE OneNbr:
+ [e1 | Pone(e1) | ] -> [a1, a2 | Pone (a1); E (a1, a2); Tnbr (a2) | ]
+ emb Pone with [a1 <- e1] update
+ :x(a1) = :x(e1);
+ :x(a2) = :x(e1);
+ :y(a1) = :y(e1);
+ :y(a2) = :y(e1) - 1
+
+RULE NbrList:
+ [e1, e2 | Tnbr(e1); Tlist(e2) | ] ->
+ [a1, a2, a3 | Tnbr (a1); Tlist (a2); Tlist (a3); E (a1, a3); E (a2, a3) | ]
+ emb Pone with [a1 <- e1, a2 <- e2] update
+ :x(a1) = :x(e1);
+ :x(a2) = :x(e2);
+ :x(a3) = :x(e1) + :x(e2) / 2;
+ :y(a1) = :y(e1);
+ :y(a2) = :y(e2);
+ :y(a3) = ((:y(e2) + :y(e2)) / 2) - 1
+
LOC 0 {
- PLAYER 1 { PAYOFF 0. MOVES [NilList -> 0] }
+ PLAYER 1 { PAYOFF 0. MOVES [NilList -> 0]; [NbrList -> 0]; [OneNbr -> 0] }
PLAYER 2 { PAYOFF 0. }
}
-START [ | Tp:2 {}; Tlist:1 {}; Pone (one); Ptrue (t); Pnil (nil);
+START [ | E:2 {}; Tlist:1 {}; Tnbr:1 {}; Pone (one); Pone (t); Pnil (nil);
S { (one, t); (t, nil) } | - ]
Modified: trunk/Toss/www/index.xml
===================================================================
--- trunk/Toss/www/index.xml 2012-06-07 21:55:42 UTC (rev 1722)
+++ trunk/Toss/www/index.xml 2012-06-09 20:09:07 UTC (rev 1723)
@@ -35,18 +35,22 @@
<section title="News">
<itemize>
+ <newsitem date="07/06/12">
+ Switching to a new ODE solver which uses the Cash-Karp method</newsitem>
+ <newsitem date="02/06/12">
+ Starting work on an interface for structures and formula evaluation</newsitem>
<newsitem date="27/05/12">
First structures defined using the term rewriting system syntax</newsitem>
<newsitem date="24/05/12">
Code for Term functions cleaned up and made JS compatible</newsitem>
- <newsitem date="13/05/12">
- Toss release 0.8 with full JS compatibility with dynamics</newsitem>
- <newsitem date="04/05/12">
- Dynamics debugged and animations now work in the JS interface</newsitem>
- <newsitem date="04/05/12">
- Old rewriting example works with the JS interface</newsitem>
- <newsitem date="25/04/12">
- Work on positioning with the JS interface</newsitem>
+ <oldnewsitem date="13/05/12">
+ Toss release 0.8 with full JS compatibility with dynamics</oldnewsitem>
+ <oldnewsitem date="04/05/12">
+ Dynamics debugged and animations now work in the JS interface</oldnewsitem>
+ <oldnewsitem date="04/05/12">
+ Old rewriting example works with the JS interface</oldnewsitem>
+ <oldnewsitem date="25/04/12">
+ Work on positioning with the JS interface</oldnewsitem>
<oldnewsitem date="30/03/12">
Adding Hnefatafl to example Toss games</oldnewsitem>
<oldnewsitem date="21/03/12">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|