-
Notifications
You must be signed in to change notification settings - Fork 4
/
Serialization to Json.gaml
71 lines (60 loc) · 1.8 KB
/
Serialization to Json.gaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Name: Json
* Shows how to transform GAML values into JSON objects
* Author: A. Drogoul
* Tags: Serialization, JSON
*/
model Json
global {
init {
write (from_binary(to_binary([1,2,4])) = [1,2,4]);
write "Simple values";
write "------------- TO JSON";
write sample(to_json(1));
write sample(to_json(1.24));
write sample(to_json("a string"));
write sample(to_json(date(0)));
write sample(to_json(#blue));
write sample(to_json(font("Helvetica")));
write sample(to_json({20,10}));
write "------------- From JSON";
write (from_json(to_json(1,true)));
write (from_json(to_json(1.24,true)));
write (from_json(to_json("a string",true)));
write (from_json(to_json(date(0),true)));
write (from_json(to_json(#blue,true)));
write (from_json(to_json(font("Helvetica"),true)));
write (from_json(to_json({20,10},true)));
write "Lists";
write "------------- TO JSON";
write(to_json([1,2,3,4,5],true));
write(to_json(["a",2,"aa",4,5.2],true));
write "------------- FROM JSON";
write(from_json(to_json([1,2,3,4,5],true)));
write(from_json(to_json(["a",2,"aa",4,5.2],true)));
write "Maps";
write "------------- TO JSON";
write(to_json(["a"::2,"b"::4],true));
write(to_json([123::43,234::#green],true));
write "------------- FROM JSON";
write(from_json(to_json(["a"::2,"b"::4],true)));
write(from_json(to_json([123::43,234::#green],true)));
write "Other data structures";
write "-------------";
write(to_json(23::34,true));
//write(to_json([123::43,234::#green],true));
write(to_json({2,2} matrix_with 10,true));
//write(to_json(circle(10),true));
write "Agents";
write "-------------";
create sp number: 2 ;
sp[0].friend <- sp[1];
sp[1].friend <- sp[0];
write(to_json(sp.population,true));
}
}
species sp
{
sp friend;
}
experiment "Run me";