Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Island Bigraph3 - Experiment 0
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Thu Aug 01 2019 13:35:05 GMT-0400 (Eastern Daylight Time)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Island Bigraph3 - Experiment 0
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: 7b2e6eab4e709d9d882c11b6ef822c04 based on f77e463b1fd97ac23197e5cd48ea5468
Keywords:
My Notes
--------
July 28, 2019
http://127.0.0.1:8888/Xholon.html?app=Island+Bigraph3+-+Experiment+0&src=lstr&gui=clsc&jslib=BigraphParser
http://127.0.0.1:8888/Xholon.html?app=Island+Bigraph3+-+Experiment+0&src=lstr&gui=none&jslib=BigraphParser
notes from Jen and Ken meeting (July 18, 2019)
------------------------------
- create case A and case B, and then measure something
- ex: try two different environment layouts, and measure and compare how much agents are using the things on the island
- measure how long an agent survives
- agent survival depends on:
- what is in the environment, and
- agent capabilities such as: ability to move, to detect food vs non-food, to eat, to see/detect other objects, etc.
- we can vary the number of agents
- measure:
- when an agent is able to increase its energy level
- baseline goal of an agent is to survive
- the only way to survive is to eat food for energy
- vary the agent movement strategies
- simplest: no movement
- simple: continuous movement in a single direction (deterministic)
- simple: random movement (stochastic)
- other, increasingly complex, movement strategies
- use a round island in a square grid
- provide a definition for what we mean by "round"
- Xholon provides a framework that can scale upwards from the simplest case to arbitrarily complex cases
Bigraph notation based on Binary Tree numbering
-----------------------------------------------
# Space instance; this is a Bigraph root
#VB = {s},
VB = {1},
# FieldRow instances - there are 4 rows
#VB = {r1,r2,r3,r4},
VB = {11,110,1100,1000},
VB = {11[0,3]},
# grid cells - there are 4 * 4 = 16 of these
#VB = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
VB = {111,1110,11100,111000,...},
VB = {11[0,3].1[0,3]},
# Subjects of an experiment
VB = {a,b,c},
# food
VB = {jb1},
github Revisions (Island Bigraph3 - Experiment 0)
----------------
1. initial commit to github
2. added InternalName 7b2e6eab4e709d9d882c11b6ef822c04
other enhancements
3-7. other enhancements
the current state of model development is:
- 16 grid cells
- there are 3 Subject nodes: a b c
- each Subject starts with 60 energy units
- Subjectbehavior is a JavaScript behavior for Subject nodes
- a has no movement, and uses 1 energy unit per time step
- b moves in a straight line, and uses 2 energy units per time step
- c moves randomly, and uses 3 energy units per time step
- the simulation lasts for 60 time steps
- a line graph is written at the end, showing changing energy levels for each Subject
- food is a source of energy
- there is no food in the environment, so each Subject is dead by the end of the simulation
8. add Subject (agent) capabilities:
- detect other objects (siblings) co-existing within the same grid cell; detect sibling
- distinguish food from non-food objects; distinguish sibling
- food is a co-existing object that is not the same type as the Subject (not another Subject), and has an energy value greater than 0
- eat food items; eat sibling
as of yet, there is no food in the environment, so these are just capabilities
9. place food in each grid cell, or at least in some grid cells
I have placed a single JuicyBerry bush? at a single grid cell, with an energy level of 10 (≡ 10 berries)
so there are 10 energy (food) units available amongst the three subjects
where the bush is located advantages or disadvantages each of the subjects
References
----------
(1)
]]></Notes>
<_-.XholonClass>
<TheSystem/>
<BigraphParser superClass="script"/>
</_-.XholonClass>
<xholonClassDetails>
<BigraphParser><DefaultContent>@BigraphParser</DefaultContent></BigraphParser>
<Avatar><Color>rgba(200,0,0,1.0)</Color></Avatar>
</xholonClassDetails>
<TheSystem>
<Bigraph roleName="0" flatten="false" savedata="true"><Attribute_String><![CDATA[
B = (VB,EB,PB,ctrlB,prntB,linkB) : 〈m,X〉 → 〈n,Y〉,
m=1, X=∅, n=1, Y={},
Σ = ( {Space,FieldRow,OceanCell,CoastCell,LandCell,Subject,JuicyBerry}, {(Space,0),(FieldRow,0),(OceanCell,4),(CoastCell,4),(LandCell,4),(Subject,0), (JuicyBerry,0)} ),
# names of Java implementation classes
Σ_implName = ( { org.primordion.xholon.base.GridEntity}, { (Space,org.primordion.xholon.base.GridEntity),(FieldRow,org.primordion.xholon.base.GridEntity),(OceanCell,org.primordion.xholon.base.GridEntity),(CoastCell,org.primordion.xholon.base.GridEntity),(LandCell,org.primordion.xholon.base.GridEntity) } ),
# xhTypes
Σ_xhType = ( {XhtypeGridEntity, XhtypeGridEntityActivePassive, XhtypePurePassiveObject}, {(Space,XhtypeGridEntity), (FieldRow,XhtypeGridEntity), (OceanCell,XhtypeGridEntityActivePassive), (CoastCell,XhtypeGridEntityActivePassive), (LandCell, XhtypeGridEntityActivePassive), (Subject,XhtypePurePassiveObject) } ),
# Space instance; this is a Bigraph root
VB = {s},
# FieldRow instances - there are 4 rows - this is an ordered collection, hence a tuple rather than a set, but for now I continue to use the brackets {} which usually designate a set
VB = {r1,r2,r3,r4},
# grid cells - there are 4 * 4 = 16 of these - this is an ordered collection, hence a tuple rather than a set, but for now I continue to use the brackets {} which usually designate a set
VB = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16},
# Subjects of an experiment
VB = {a,b,c},
# food
VB = {jb1},
# edges
EB = ∅,
# ports 4 ports for each of the 12 grid cell nodes
PB={p(1,1),p(1,2),p(1,3),p(1,4)},
PB={p(2,1),p(2,2),p(2,3),p(2,4)},
PB={p(3,1),p(3,2),p(3,3),p(3,4)},
PB={p(4,1),p(4,2),p(4,3),p(4,4)},
PB={p(5,1),p(5,2),p(5,3),p(5,4)},
PB={p(6,1),p(6,2),p(6,3),p(6,4)},
PB={p(7,1),p(7,2),p(7,3),p(7,4)},
PB={p(8,1),p(8,2),p(8,3),p(8,4)},
PB={p(9,1),p(9,2),p(9,3),p(9,4)},
PB={p(10,1),p(10,2),p(10,3),p(10,4)},
PB={p(11,1),p(11,2),p(11,3),p(11,4)},
PB={p(12,1),p(12,2),p(12,3),p(12,4)},
PB={p(13,1),p(13,2),p(13,3),p(13,4)},
PB={p(14,1),p(14,2),p(14,3),p(14,4)},
PB={p(15,1),p(15,2),p(15,3),p(15,4)},
PB={p(16,1),p(16,2),p(16,3),p(16,4)},
ctrlB = {(s,Space)},
ctrlB = {(r1,FieldRow), (r2,FieldRow), (r3,FieldRow), (r4,FieldRow)},
# product of 2 sets, pairs, gridcell x type
ctrlB = {(1,OceanCell),(2,CoastCell),(3,CoastCell),(4,OceanCell),(5,OceanCell),(6,LandCell),(7,LandCell),(8,CoastCell),(9,OceanCell),(10,LandCell),(11,LandCell),(12,OceanCell),(13,OceanCell),(14,CoastCell),(15,CoastCell),(16,OceanCell)},
ctrlB = {(a,Subject),(b,Subject),(c,Subject)},
ctrlB = {(jb1,JuicyBerry)},
# parent relations
prntB = { (r1,s), (r2,s), (r3,s), (r4,s) },
# product of 2 sets, pairs, gridcell x row
prntB = {(1,r1),(2,r1),(3,r1),(4,r1),(5,r2),(6,r2),(7,r2),(8,r2),(9,r3),(10,r3),(11,r3),(12,r3),(13,r4),(14,r4),(15,r4),(16,r4)},
# Subject nodes
prntB = {(a,6),(b,6),(c,6)},
# food note the big difference between having the JuicyBerry at grid cell 6 7 or 10
prntB = {(jb1,7)},
# links port 1 port 2 port 3 port 4
# ----------- ----------- ----------- -----------
linkB = { (p(1,1),13), (p(1,2), 2), (p(1,3), 5), (p(1,4), 4) },
linkB = { (p(2,1),14), (p(2,2), 3), (p(2,3), 6), (p(2,4), 1) },
linkB = { (p(3,1),15), (p(3,2), 4), (p(3,3), 7), (p(3,4), 2) },
linkB = { (p(4,1),16), (p(4,2), 1), (p(4,3), 8), (p(4,4), 3) },
linkB = { (p(5,1), 1), (p(5,2), 6), (p(5,3), 9), (p(5,4), 8) },
linkB = { (p(6,1), 2), (p(6,2), 7), (p(6,3),10), (p(6,4), 5) },
linkB = { (p(7,1), 3), (p(7,2), 8), (p(7,3),11), (p(7,4), 6) },
linkB = { (p(8,1), 4), (p(8,2), 5), (p(8,3),12), (p(8,4), 7) },
linkB = { (p(9,1), 5), (p(9,2),10), (p(9,3),13), (p(9,4),12) },
linkB = { (p(10,1),6), (p(10,2),11),(p(10,3),14), (p(10,4),9) },
linkB = { (p(11,1),7), (p(11,2),12),(p(11,3),15), (p(11,4),10)},
linkB = { (p(12,1),8), (p(12,2),9), (p(12,3),16), (p(12,4),11)},
linkB = { (p(13,1),9), (p(13,2),14),(p(13,3),1), (p(13,4),16) },
linkB = { (p(14,1),10),(p(14,2),15),(p(14,3),2), (p(14,4),13) },
linkB = { (p(15,1),11),(p(15,2),16),(p(15,3),3), (p(15,4),14) },
linkB = { (p(16,1),12),(p(16,2),13),(p(16,3),4), (p(16,4),15) },
# grid cell symbols, that correspond to OceanCell CoastCell LandCell
_Symbol = ({.,C,L}, {(OceanCell,.),(CoastCell,C),(LandCell,L)});
# colors
_Color = ({rgba(255|255|255|0.5), rgba(255|255|255|0.9), #171c8f, #d0c883, PaleGoldenRod,indigo,RoyalBlue,rgba(255|165|0|0.8), Violet}, {(Space,rgba(255|255|255|0.5)), (FieldRow,rgba(255|255|255|0.9)), (OceanCell,#171c8f), (CoastCell,#d0c883), (LandCell,PaleGoldenRod), (Subject,rgba(255|165|0|0.8)), (JuicyBerry,Violet)}),
# symbols
_Symbol=({SmallRectangle,SmallCircle}, {(Subject,SmallRectangle), (JuicyBerry,SmallCircle)}),
# energy
$energy = ({60,1},{(a,60),(b,60),(c,60), (jb1,10)}),
# GridGenerator
_shouldBuildXhc=false,
_shouldBuildCsh=false,
_gridType=Gvt,
_gridViewerParams=(TheSystem/Bigraph/Space,50,Island Viewer,true),
_cellsCanSupplyOwnColor=true,
_GridGenerator=(_gridType,_columnColor,_gridViewerParams,_cellsCanSupplyOwnColor,_shouldBuildXhc,_shouldBuildCsh),
# mapping from a set of keyboard key names to a set of Avatar actions
_keys={UP,RIGHT,DOWN,LEFT},
_actions={go link0,go link1,go link2,go link3},
_AvatarKeyMap={(UP,go link0),(RIGHT,go link1),(DOWN,go link2),(LEFT,go link3)},
]]></Attribute_String>
<BigraphParser/>
</Bigraph>
<script><![CDATA[
// create a line chart that plots the changing energy level of the experiment Subject(s)
const chartRoot = this.parent().xpath("Bigraph/descendant::Subject/..");
var service = $wnd.xh.service("XholonHelperService");
var dpp = " Island Bigraph3 - Experiment 0,Time (timestep),Energy level,./statistics/,stats,1,WRITE_AS_INT";
var mode = "new";
var dp = "google2"; // gnuplot google2
var plotStr = '<Plot mode="' + mode + '" dataPlotter="' + dp + '" dataPlotterParams="' + dpp + '"/>';
//chartRoot.println(plotStr);
service.call(-2013, plotStr, chartRoot);
]]></script>
<Animate duration="0.25" selection="#xhanim" xpath="./TheSystem/Bigraph" cssStyle=".d3cpnode circle {stroke-width: 0.5px;}" efParams="{&quot;selection&quot;:&quot;#xhanim&quot;,&quot;sort&quot;:&quot;disable&quot;,&quot;width&quot;:700,&quot;height&quot;:700,&quot;mode&quot;:&quot;tween&quot;,&quot;labelContainers&quot;:true,&quot;includeClass&quot;:true,&quot;includeId&quot;:true,&quot;shape&quot;:&quot;circle&quot;}"/>
</TheSystem>
<TheSystembehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var me, beh = {
postConfigure: function() {
// move the system Avatar to the first grid cell by following a path downwards in the Place Graph, do not make the Avatar visible, and start the application
const ava = $wnd.xh.avatar();
ava.action("enter;enter;enter;enter;enter;start");
// the model will run for ten time steps
$wnd.xh.param("MaxProcessLoops","60");
}
}
//# sourceURL=TheSystembehavior.js
]]></TheSystembehavior>
<Subjectbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
const TYPE_NONFOOD = 0;
const TYPE_FOOD = 1;
var sbjct, sbjctname, beh = {
postConfigure: function() {
sbjct = this.cnode.parent();
$wnd.xh.root().append(this.cnode.remove());
sbjct.val(sbjct["energy"]); // plotter needs this
sbjctname = sbjct.xhc().name() + " " + sbjct.role();
sbjct.println(sbjctname + " has energy level " + sbjct["energy"] + ".");
},
act: function() {
if (sbjct["energy"] > 0) {
this.move();
var sibling = this.detectSibling();
if (sibling) {
sbjct.println("found sibling");
var siblingType = this.distinguishSibling(sibling);
sbjct.println("Sibling Type is " + siblingType);
if (siblingType == TYPE_FOOD) {
this.eatSibling(sibling);
sbjct.println("yumm");
}
}
sbjct["energy"] = sbjct["energy"] - 1;
sbjct.val(sbjct["energy"]); // plotter needs this
sbjct.println(sbjctname + " has energy level " + sbjct["energy"] + ".");
if (sbjct["energy"] == 0) {
sbjct.println(sbjctname + " is dead.");
}
}
if (sbjct["energy"] < 0) {
// fix a Subject whose energy value has become negative
sbjct["energy"] = 0;
sbjct.val(sbjct["energy"]);
}
},
move: function() {
sbjct.println(sbjct.name() + " is moving ...");
switch (sbjct.role()) {
case "a":
// no movement
break;
case "b":
// movement in a single direction (deterministic)
var nextCell = sbjct.parent().next();
if (nextCell == null) {
nextCell = sbjct.parent().parent().first();
}
nextCell.append(sbjct.remove());
sbjct["energy"] = sbjct["energy"] - 1; // deterministic movement costs one extra energy unit
break;
case "c":
// random movement (stochastic)
var direction = Math.floor(Math.random() * 4);
var nextCell = sbjct.parent().port(direction);
nextCell.append(sbjct.remove());
sbjct["energy"] = sbjct["energy"] - 2; // stochastic movement costs two extra energy units
break;
default:
break;
}
},
detectSibling: function() {
return sbjct.prev() || sbjct.next();
},
distinguishSibling: function(node) {
if (node.xhc().name() == sbjct.xhc().name()) {return TYPE_NONFOOD;}
if (!node["energy"]) {return TYPE_NONFOOD;}
return TYPE_FOOD;
},
eatSibling: function(node) {
sbjct["energy"] += 1;
node["energy"] -= 1;
}
}
//# sourceURL=Subjectbehavior.js
]]></Subjectbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<!--<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Bigraph</title>
<rect id="TheSystem/Bigraph" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Space</title>
<rect id="TheSystem/Bigraph/Space" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
</g>
</g>
</svg>-->
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.