[Toss-devel-svn] SF.net SVN: toss:[1215] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
|
From: <luk...@us...> - 2010-12-04 01:59:13
|
Revision: 1215
http://toss.svn.sourceforge.net/toss/?rev=1215&view=rev
Author: lukaszkaiser
Date: 2010-12-04 01:59:06 +0000 (Sat, 04 Dec 2010)
Log Message:
-----------
Entanglement rewrite and WebClient corrections.
Modified Paths:
--------------
trunk/Toss/Solver/Structure.ml
trunk/Toss/WebClient/TossConnect.js
trunk/Toss/WebClient/Wrapper.py
trunk/Toss/examples/Entanglement.toss
Modified: trunk/Toss/Solver/Structure.ml
===================================================================
--- trunk/Toss/Solver/Structure.ml 2010-12-02 22:51:40 UTC (rev 1214)
+++ trunk/Toss/Solver/Structure.ml 2010-12-04 01:59:06 UTC (rev 1215)
@@ -286,7 +286,8 @@
| None ->
if tps = [] then raise (
Structure_mismatch
- "Structure.add_from_lists: relation of undetermined arity")
+ ("Structure.add_from_lists: relation of undetermined arity: " ^
+ rn))
else Array.length (List.hd tps)
| Some ar -> ar in
let s = add_rel_name rn arity s in
Modified: trunk/Toss/WebClient/TossConnect.js
===================================================================
--- trunk/Toss/WebClient/TossConnect.js 2010-12-02 22:51:40 UTC (rev 1214)
+++ trunk/Toss/WebClient/TossConnect.js 2010-12-04 01:59:06 UTC (rev 1215)
@@ -93,8 +93,10 @@
var rels = [];
for (var i = 0; i < r.length; i++) {
var rel_name = strip(' ', '\'', r[i].substring(1,r[i].indexOf(',')));
- var args_s = r[i].substring(r[i].indexOf('['), r[i].indexOf(']'));
- rels.push ([rel_name, convert_python_list (',', args_s)]);
+ var args_s = r[i].substring(r[i].indexOf('[')+1, r[i].indexOf(']'));
+ if (rel_name[0] != "_" && args_s != "''") {
+ rels.push ([rel_name, convert_python_list (',', args_s)]);
+ }
}
return (rels)
}
Modified: trunk/Toss/WebClient/Wrapper.py
===================================================================
--- trunk/Toss/WebClient/Wrapper.py 2010-12-02 22:51:40 UTC (rev 1214)
+++ trunk/Toss/WebClient/Wrapper.py 2010-12-04 01:59:06 UTC (rev 1215)
@@ -21,7 +21,7 @@
return ("SOME MODEL", "SFX")
def _pos (self):
- if self.i == 0:
+ if self.i == ";MODEL":
return (" MODEL ")
if self.p == 0:
return (" RULE " + (str (self.i)) + " LEFT ")
@@ -123,9 +123,9 @@
def get_rel (self, rel_name):
m = self.s.msg ("GET ALLOF REL" + (self._pos ()) + rel_name)
cur = m.find('{')
- if cur < 0: return ([])
- if m.find('(') < 0: return ([])
- tps = [ts.strip('() ') for ts in m[cur+1:-1].split(";")]
+ par = m.find('(')
+ if cur < 0 and par < 0: return ([])
+ tps = [ts.strip('{}() ') for ts in m[max(cur,par):].split(";")]
return ([[t.strip() for t in ts.split(",")] for ts in tps])
def get_rels (self, nodes = []):
@@ -152,13 +152,10 @@
return (self.s.set_arity (rel, i))
def get_rel_names_arities (self):
- msig = "; ".join (self.s.msg ("GET SIGNATURE").split(','))
mrel = self.s.msg ("GET SIGNATURE REL" + (self._pos ()))
- m = mrel + (", ".join (msig.split (':')))
- if len(m) < 1: return ([])
- if len(mrel) < 1: m = m[2:]
- pair_strs = [s.strip() for s in m.split (';')]
- rels_ar_lst = [p.split(',') for p in pair_strs]
+ if len(mrel) < 1: return ([])
+ pair_strs = [s.strip() for s in mrel.split (',')]
+ rels_ar_lst = [p.split(':') for p in pair_strs]
rels = [(rl[0].strip(), int (rl[1].strip())) for rl in rels_ar_lst]
return ([r for r in set(rels)])
@@ -181,11 +178,11 @@
self.changes = 0 # increment on each change of model or rules
# Initialize the model and the rules.
- self.model = ModelClient (self, 0, 0)
- self.rules = [(ModelClient (self, i+1, 0), ModelClient (self, i+1, 1))
- for i in range(self.__no_of_rules ())]
+ self.model = ModelClient (self, ";MODEL", 0)
+ self.rule_names = self.__names_of_rules ()
+ self.rules = [(ModelClient (self, i, 0), ModelClient (self, i, 1))
+ for i in self.rule_names]
-
def __str__ (self):
return ("System")
@@ -203,9 +200,17 @@
def __no_of_rules (self):
"""Get number of rewrite rules from server."""
- i = self.msg ("GET RULE")
- return (int (i));
+ names_msg = self.msg ("GET RULE")
+ if len(names_msg.strip()) < 1: return(0)
+ names = [s.strip() for s in names_msg.split (';')]
+ return (int (len(names)));
+ def __names_of_rules (self):
+ """Get names of rewrite rules from server."""
+ names_msg = self.msg ("GET RULE")
+ if len(names_msg.strip()) < 1: return([])
+ return ([s.strip() for s in names_msg.split (';')])
+
def no_of_locs (self):
"""Get number of game locations from server."""
m = self.msg ("GET LOC").split("/")
@@ -307,65 +312,67 @@
return (m)
def add_rule (self):
- rule_no = len(self.rules) + 1
+ rule_name = str(len(self.rules) + 1)
+ self.rule_names.append(rule_name)
emptyr_str = " [||]->[||] with [] pre true inv true post true"
self.changes += 1
- self.msg ("SET RULE " + (str (rule_no)) + emptyr_str)
- rl = ModelClient (self, rule_no, 0)
- rr = ModelClient (self, rule_no, 1)
+ self.msg ("SET RULE " + rule_name + emptyr_str)
+ rl = ModelClient (self, rule_name, 0)
+ rr = ModelClient (self, rule_name, 1)
self.rules.append ((rl, rr))
- return (rule_no)
+ return (len(self.rules))
+
def get_conditions (self, i):
- m = self.msg ("GET RULE cond " + str(i))
+ m = self.msg ("GET RULE cond " + self.rule_names[i])
return ([c.strip() for c in m.split(";")])
def set_conditions (self, i, pre_s, inv_s, post_s):
self.changes += 1
- m = self.msg ("SET RULE cond " + str(i) + " " + pre_s +
+ m = self.msg ("SET RULE cond " + self.rule_names[i] + " " + pre_s +
" " + inv_s + " " + post_s)
return (m)
def get_emb_rels (self, i):
- m = self.msg ("GET RULE emb " + str(i))
+ m = self.msg ("GET RULE emb " + self.rule_names[i])
return (m)
def set_emb_rels (self, i, lst_s):
self.changes += 1
- m = self.msg ("SET RULE emb " + str(i) + " " + lst_s)
+ m = self.msg ("SET RULE emb " + self.rule_names[i] + " " + lst_s)
return (m)
def get_embeddings (self, i, elem):
- m = self.msg ("GET RULE assoc " + str(i) + " " + str(elem))
+ m = self.msg ("GET RULE assoc " + self.rule_names[i] + " " + str(elem))
return (m)
def set_embeddings (self, i, elem, lst_s):
self.changes += 1
- m = self.msg ("SET RULE assoc " + str(i) + " "+ str(elem) + " " + lst_s)
+ m = self.msg ("SET RULE assoc " + self.rule_names[i] + " "+ str(elem) + " " + lst_s)
return (m)
def get_update (self, i, elem, fun):
- m = self.msg ("GET RULE update " + str(i) + " "+ fun + " " + str(elem))
+ m = self.msg ("GET RULE update " + self.rule_names[i] + " "+ fun + " " + str(elem))
return (m)
def set_update (self, i, elem, fun, t):
self.changes += 1
- m = self.msg ("SET RULE update " + str(i) + " " +
+ m = self.msg ("SET RULE update " + self.rule_names[i] + " " +
fun + " " + str(elem) + " " + t)
return (m)
def get_dynamic (self, i, elem, fun):
- m = self.msg ("GET RULE dynamics "+ str(i) +" "+ fun + " " + str(elem))
+ m = self.msg ("GET RULE dynamics "+ self.rule_names[i] +" "+ fun + " " + str(elem))
return (m)
def set_dynamic (self, i, elem, fun, t):
self.changes += 1
- m = self.msg ("SET RULE dynamics "+ str(i) + " " +
+ m = self.msg ("SET RULE dynamics "+ self.rule_names[i] + " " +
fun + " " + str(elem) + " " + t)
return (m)
- def query (self, rule_id):
- msg = self.msg ("GET RULE " + (str (rule_id)) + " MODEL")
+ def query (self, rule_nm):
+ msg = self.msg ("GET RULE " + rule_nm + " MODEL")
if msg.find('->') < 0: return ([])
def make_match (m_str):
m = dict ()
@@ -375,16 +382,17 @@
return (m)
return ([make_match (m.strip()) for m in msg.split(';')])
- def apply_rule (self, rule_id, match, time, params):
+ def apply_rule (self, rule_nm, match, time, params):
match_s = ", ".join([str(l) + ": " + str(r) for (l,r) in match.items()])
param_s = ", ".join([str(p) + ": " + repr(v) for (p,v) in params])
- m = self.msg ("SET RULE "+ str(rule_id) + " MODEL " + match_s +
+ m = self.msg ("SET RULE "+ rule_nm + " MODEL " + match_s +
" " + repr(time) + " " + param_s)
shifts = dict ()
for s in [s.strip() for s in m.split(";")]:
seq = [e.strip() for e in s.split(",")]
- if not (seq[0] in shifts.keys()): shifts[seq[0]] = dict ()
- shifts[seq[0]][seq[1]] = [float(f) for f in seq[2:]]
+ if len(seq) > 2:
+ if not (seq[0] in shifts.keys()): shifts[seq[0]] = dict ()
+ shifts[seq[0]][seq[1]] = [float(f) for f in seq[2:]]
return (shifts)
def set_time (self, tstep, t):
@@ -422,7 +430,7 @@
file = open (file_name, 'r')
state = file.read ()
file.close ()
- state_str = " ".join (state.split ())
+ state_str = ("#"+file_name+"#") + "$".join (state.split ("\n"))
self.set_state (state_str)
def cur_move_touching (self, elem):
Modified: trunk/Toss/examples/Entanglement.toss
===================================================================
--- trunk/Toss/examples/Entanglement.toss 2010-12-02 22:51:40 UTC (rev 1214)
+++ trunk/Toss/examples/Entanglement.toss 2010-12-04 01:59:06 UTC (rev 1215)
@@ -1,50 +1,46 @@
-3: [ 1 | R { (1) } | vx { 1->0. }; vy { 1->0. }; x { 1->-13.2 }; y { 1->-8.8 } ] -> [ 1 | R { (1) } | vx { 1->0. }; vy { 1->0. }; x { 1->-8.8 }; y { 1->-1.1 } ] emb R, C with 1 <- 1
-dynamics
- vy(1)' = 0.;
- vx(1)' = 0.;
- y(1)' = 0.;
- x(1)' = 0.
-update
- vy(1) = 0.;
- vx(1) = 0.;
- y(1) = y(1);
- x(1) = x(1)
- pre true inv true post true; 2: [ 1, 2 | C { }; E { (1, 2) }; R { (1) }; _opt_C { (1) } | vx { 1->0., 2->0. }; vy { 1->0., 2->0. }; x { 1->-47.3, 2->9.9 }; y { 1->-19.8, 2->-20.9 } ] -> [ 1, 2 | C { }; E { (1, 2) }; R { (2) }; opt_C { (1) } | vx { 1->0., 2->0. }; vy { 1->0., 2->0. }; x { 1->-41.8, 2->14.3 }; y { 1->-15.4, 2->-13.2 } ] emb R, C with 2 <- 2, 1 <- 1
-dynamics
- vy(2)' = 0.;
- vy(1)' = 0.;
- vx(2)' = 0.;
- vx(1)' = 0.;
- y(2)' = 0.;
- y(1)' = 0.;
- x(2)' = 0.;
- x(1)' = 0.
-update
- vy(2) = 0.;
- vy(1) = 0.;
- vx(2) = 0.;
- vx(1) = 0.;
- y(2) = y(2);
- y(1) = y(1);
- x(2) = x(2);
- x(1) = x(1)
- pre true inv true post true; 1: [ 1, 2 | C { (2) }; R { (1) } | vx { 1->0., 2->0. }; vy { 1->0., 2->0. }; x { 1->-19.8, 2->-21.7229777685 }; y { 1->-18.7, 2->10.1373896253 } ] -> [ 1, 2 | C { (1) }; R { (1) } | vx { 1->0., 2->0. }; vy { 1->0., 2->0. }; x { 1->-5.5, 2->-6.92397351637 }; y { 1->-18.7, 2->5.9348344426 } ] emb C, R with 2 <- 2, 1 <- 1
-dynamics
- vy(2)' = 0.;
- vy(1)' = 0.;
- vx(2)' = 0.;
- vx(1)' = 0.;
- y(2)' = 0.;
- y(1)' = 0.;
- x(2)' = 0.;
- x(1)' = 0.
-update
- vy(2) = 0.;
- vy(1) = 0.;
- vx(2) = 0.;
- vx(1) = 0.;
- y(2) = y(2);
- y(1) = y(1);
- x(2) = x(2);
- x(1) = x(1)
- pre true inv true post true; < 0 : 0 PAYOFF 1: 0.; 0: 0. MOVES [3, t: 1. -- 1. -> 1]; [1, t: 1. -- 1. -> 1] >, < 1 : 1 PAYOFF 1: -1.; 0: 1. MOVES [2, t: 1. -- 1. -> 0] >; [ d4, a2, a1, b1, b2, e4, c2, c1, f4, d2, d1, f1, f2, g1, g2, h1, h2, e1, e2, i1, i2 | C { (d4); (e4); (f4) }; E { (a2, a1); (a2, b2); (a1, a2); (a1, b1); (b1, a1); (b1, b2); (b1, c1); (b2, a2); (b2, b1); (b2, c2); (c2, b2); (c2, c1); (c2, d2); (c1, b1); (c1, c2); (c1, d1); (d2, c2); (d2, d1); (d2, e1); (d1, c1); (d1, d2); (d1, e2); (f1, f2); (f1, g1); (f1, e1); (f2, f1); (f2, g2); (f2, e2); (g1, f1); (g1, g2); (g1, h1); (g2, f2); (g2, g1); (g2, h2); (h1, g1); (h1, h2); (h1, i1); (h2, g2); (h2, h1); (h2, i2); (e1, d2); (e1, f1); (e1, e2); (e2, d1); (e2, f2); (e2, e1); (i1, h1); (i1, i2); (i2, h2); (i2, i1) }; R { (e1) }; _opt_C { } | vx { d4->0., a2->0., a1->0., b1->0., b2->0., e4->0., c2->0., c1->0., f4->0., d2->0., d1->0., f1->0., f2->0., g1->0., g2->0., h1->0., h2->0., e1->0., e2->0., i1->0., i2->0. }; vy { d4->0., a2->0., a1->0., b1->0., b2->0., e4->0., c2->0., c1->0., f4->0., d2->0., d1->0., f1->0., f2->0., g1->0., g2->0., h1->0., h2->0., e1->0., e2->0., i1->0., i2->0. }; x { d4->100., a2->-50., a1->-50., b1->0., b2->0., e4->150., c2->50., c1->50., f4->200., d2->100., d1->100., f1->200., f2->200., g1->250., g2->250., h1->300., h2->300., e1->150., e2->150., i1->350., i2->350. }; y { d4->-150., a2->-100., a1->-50., b1->-50., b2->-100., e4->0., c2->-100., c1->-50., f4->-150., d2->-100., d1->-50., f1->-100., f2->-50., g1->-100., g2->-50., h1->-100., h2->-50., e1->-100., e2->-50., i1->-100., i2->-50. } ]; 0.; 0; r3: none, r2: none, r1: none; E: 2, C: 1, opt_C: 1, R: 1
+PLAYERS 1, 2
+RULE 1:
+ [ a1, a2 | C { (a2) }; R { (a1) } |
+ vx { a1->0., a2->0. }; vy { a1->0., a2->0. };
+ x { a1->-10., a2->-10. }; y { a1->-10., a2->10. } ]
+ ->
+ [ a1, a2 | C { (a1) }; R { (a1) } |
+ vx { a1->0., a2->0. }; vy { a1->0., a2->0. };
+ x { a1->-10., a2->-10. }; y { a1->-10., a2->10. } ]
+emb R, C
+RULE 2:
+ [ a1, a2 | C:1 { }; E { (a1, a2) }; R { (a1) }; _opt_C { (a1) } |
+ vx { a1->0., a2->0. }; vy { a1->0., a2->0. };
+ x { a1->-10., a2->10. }; y { a1->-10., a2->-10. } ]
+ ->
+ [ a1, a2 | C:1 { }; E { (a1, a2) }; R { (a2) }; _opt_C { (a1) } |
+ vx { a1->0., a2->0. }; vy { a1->0., a2->0. };
+ x { a1->-10., a2->10. }; y { a1->-10., a2->-10. } ]
+emb R, C
+RULE 3:
+ [ a1 | R { (a1) } |
+ vx { a1->0. }; vy { a1->0. }; x { a1->-10. }; y { a1->-10. } ]
+ ->
+ [ a1 | R { (a1) } |
+ vx { a1->0. }; vy { a1->0. }; x { a1->-10. }; y { a1->-10. } ]
+emb R, C
+LOC 0 {
+ PLAYER 1
+ PAYOFF {
+ 1: 0.;
+ 2: 0.
+ }
+ MOVES
+ [1 -> 1];
+ [3 -> 1]
+ }
+LOC 1 {
+ PLAYER 2
+ PAYOFF {
+ 1: 1.;
+ 2: -1.
+ }
+ MOVES
+ [2 -> 0]
+ }
+MODEL [ d4, a2, a1, b1, b2, e4, c2, c1, f4, d2, d1, f1, f2, g1, g2, h1, h2, e1, e2, i1, i2 | C { (d4); (e4); (f4) }; E { (a2, a1); (a2, b2); (a1, a2); (a1, b1); (b1, a1); (b1, b2); (b1, c1); (b2, a2); (b2, b1); (b2, c2); (c2, b2); (c2, c1); (c2, d2); (c1, b1); (c1, c2); (c1, d1); (d2, c2); (d2, d1); (d2, e1); (d1, c1); (d1, d2); (d1, e2); (f1, f2); (f1, g1); (f1, e1); (f2, f1); (f2, g2); (f2, e2); (g1, f1); (g1, g2); (g1, h1); (g2, f2); (g2, g1); (g2, h2); (h1, g1); (h1, h2); (h1, i1); (h2, g2); (h2, h1); (h2, i2); (e1, d2); (e1, f1); (e1, e2); (e2, d1); (e2, f2); (e2, e1); (i1, h1); (i1, i2); (i2, h2); (i2, i1) }; R { (e1) }; _opt_C:1 { } | vx { d4->0., a2->0., a1->0., b1->0., b2->0., e4->0., c2->0., c1->0., f4->0., d2->0., d1->0., f1->0., f2->0., g1->0., g2->0., h1->0., h2->0., e1->0., e2->0., i1->0., i2->0. }; vy { d4->0., a2->0., a1->0., b1->0., b2->0., e4->0., c2->0., c1->0., f4->0., d2->0., d1->0., f1->0., f2->0., g1->0., g2->0., h1->0., h2->0., e1->0., e2->0., i1->0., i2->0. }; x { d4->100., a2->-50., a1->-50., b1->0., b2->0., e4->150., c2->50., c1->50., f4->200., d2->100., d1->100., f1->200., f2->200., g1->250., g2->250., h1->300., h2->300., e1->150., e2->150., i1->350., i2->350. }; y { d4->-150., a2->-100., a1->-50., b1->-50., b2->-100., e4->0., c2->-100., c1->-50., f4->-150., d2->-100., d1->-50., f1->-100., f2->-50., g1->-100., g2->-50., h1->-100., h2->-50., e1->-100., e2->-50., i1->-100., i2->-50. } ]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|