Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active August 8, 2023 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwebb/8d8fdb1c3c935ffc9c995d4716044398 to your computer and use it in GitHub Desktop.
Save kenwebb/8d8fdb1c3c935ffc9c995d4716044398 to your computer and use it in GitHub Desktop.
Path Following Tree Builder - Config A
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Tue Aug 08 2023 12:49:55 GMT-0400 (GMT-04:00)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Path Following Tree Builder - Config A
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: 8d8fdb1c3c935ffc9c995d4716044398
Keywords:
My Notes
--------
7 August 2023
In this workbook I explore Config A, the simplest approach, from my notebook.
In fact, it's actually simpler than what I describe in the notebook.
I use DefaultContent instead of behavior
- so I can have same shared behavior for multiple different instances of PftbConfigA
TODO
- for the Cell Model
- also include the IH binary strings
- also include the two dictionaries
- these provide names
TODO
- DONE include an example of a complete JSON structure that includes all of this
- put it inside of a Xholon Attribute_String
### References
--------------
(1) see my notebook for 7 August 2023
Instead of "Path Following Tree Builder", I call these "Path Oriented Tree Builder"
I describe three configurations Config A|B|C
]]></Notes>
<_-.XholonClass>
<PhysicalSystem/>
<Pftb/>
<PathFollowingTreeBuilder superClass="Script">
<PftbConfigA/>
<PftbJSON/>
</PathFollowingTreeBuilder>
</_-.XholonClass>
<xholonClassDetails>
<Chameleon><Color>white</Color></Chameleon>
<PhysicalSystem><Color>white</Color></PhysicalSystem>
<Pftb><Color>white</Color></Pftb>
<PftbConfigA><Color>yellow</Color><DefaultContent><![CDATA[
var me, arr, ix, nodename, beh = {
postConfigure: function() {
me = this.cnode;
me.println(me.name());
arr = me.bstr.split(",");
ix = 0;
nodename = "Вузол"; // Ukrainian word for "Node", pronounced "Vuzol"
},
act: function() {
me.println(me.name());
if (ix < arr.length) {
this.build(arr[ix]);
ix++;
}
else {
me.remove();
}
},
build: function(bstr) {
me.println(bstr);
var node = me;
for (var i = 0; i < bstr.length; i++) {
var bit = bstr[i];
switch(bit) {
case "0":
if (!node.first()) {
node.append(`<${nodename}><Color>red</Color></${nodename}>`);
}
node = node.first();
break;
case "1":
if (!node.next()) {
node.after(`<${nodename}><Color>green</Color></${nodename}>`);
}
node = node.next();
break;
default: break;
}
}
}
}
//# sourceURL=PftbConfigA.js
]]></DefaultContent></PftbConfigA>
<PftbJSON><Color>yellow</Color><DefaultContent><![CDATA[
// TODO parse an Attribute_String that contains a JSON string
var me, arr, ix, nodename, jso, beh = {
postConfigure: function() {
me = this.cnode;
me.println(me.name());
// read the JSON
//const atstrnode = me.parent().first();
const json = me.parent().first().text();
me.parent().first().remove();
//me.println(json);
jso = $wnd.JSON.parse(json);
me.println(`model:${jso.model}\ndatetime:${jso.datetime}\ntimestep:${jso.timestep}`);
arr = jso.nleaves;
//arr = me.bstr.split(",");
ix = 0;
nodename = "Вузол"; // Ukrainian word for "Node", pronounced "Vuzol"
},
act: function() {
me.println(me.name());
if (ix < arr.length) {
this.build(arr[ix]);
ix++;
}
else {
// test find function for Hello World model
// me.println(`found: ${node.name()} ${node.textval}`);
var node = this.find("1");
this.fixPorts(node);
me.println(`found: ${node.name()} ${node.textval}`);
node = this.find("10");
this.fixPorts(node);
me.println(`found: ${node.name()} ${node.textval}`);
node = this.find("101");
this.fixPorts(node);
me.println(`found: ${node.name()} ${node.textval}`);
me.remove();
}
},
build: function(bstr) {
me.println(bstr);
var node = me;
var textval = "";
for (var i = 0; i < bstr.length; i++) {
var bit = bstr[i];
textval += bit;
nodename = jso.tprops[jso.nprops[textval].type].name;
switch(bit) {
case "0":
if (!node.first()) {
node.append(`<${nodename} textval="${textval}"><Color>red</Color></${nodename}>`);
}
node = node.first();
break;
case "1":
if (!node.next()) {
node.after(`<${nodename} textval="${textval}"><Color>green</Color></${nodename}>`);
}
node = node.next();
break;
default: break;
}
me.println(`${node.name()} ${node.textval}`);
// print the type name from nprops[node.textval].type -> tprops.name
me.println(jso.tprops[jso.nprops[node.textval].type].name); // this works
// TODO handle ports; example: "ports": {"0": "10"}
const ports = jso.nprops[node.textval].ports;
if (ports) {
node.portz = ports; // "ports" is a built-in Xholon function, so I use "portz" instead
// OR node.port(0, "10"); ??? remote node may not exist yet
console.log(node);
}
}
},
// find a node given its binary string
find: function(bstr) {
me.println(`finding: ${bstr}`);
var node = me;
for (var i = 0; i < bstr.length; i++) {
var bit = bstr[i];
switch(bit) {
case "0":
node = node.first();
break;
case "1":
node = node.next();
break;
default: break;
}
}
return node;
},
// fix ports after all nodes are built
fixPorts: function(node) {
const ports = node.portz; // note use of "portz"
// example: "ports": {"0": "10"}
if (ports) {
var portnum = 0;
var bstr = ports[portnum];
while(bstr) {
me.println(bstr);
var remoteNode = this.find(bstr);
node.port(portnum, remoteNode);
portnum++;
bstr = ports[portnum];
}
}
}
}
//# sourceURL=PftbJSON.js
]]></DefaultContent></PftbJSON>
</xholonClassDetails>
<PhysicalSystem>
<Pftb>
<PftbConfigA bstr="10110,1011101"/>
</Pftb>
<!--Cell Model - this generates the correct structure when compared with the original Cell Model-->
<Pftb>
<PftbConfigA bstr="100,10100,10101001111111111,1010101111111111"/>
</Pftb>
<Pftb>
<Attribute_String>{
"model": "Hello World",
"datetime": "Tue Aug 08 2023 08:02:56 GMT-0400 (GMT-04:00)",
"timestep": "0",
"comments": "KSW - I manually removed the bulk of the unnecessary nodes in tprops",
"nleaves": [
"101"
],
"tleaves": [
"000111110111111110",
"000111110111111111111111111111111111111111",
"00011111111110",
"0001111111111101011",
"000111111111110110",
"00011111111111011101111",
"000111111111111011111111101",
"00011111111111101111111111101",
"000111111111111011111111111101",
"000111111111111011111111111111",
"0001111111111111011111111",
"0001111111111111101",
"000111111111111111011110111",
"0001111111111111111011111111",
"000111111111111111110",
"0001111111111111111110",
"00011111111111111111110111",
"0001111111111111111111101",
"00011111111111111111111101",
"0001111111111111111111111010111",
"00011111111111111111111110110",
"00011111111111111111111110111101",
"00011111111111111111111110111110",
"000111111111111111111111101111110",
"000111111111111111111111101111111110111",
"00011111111111111111111110111111111100",
"0001111111111111111111111011111111110101",
"000111111111111111111111101111111111110",
"000111111111111111111111101111111111111",
"00011111111111111111111111101111",
"000111111111111111111111111110011",
"0001111111111111111111111111110",
"00011111111111111111111111111110",
"0001111111111111111111111111111101111111",
"000111111111111111111111111111111011010",
"0001111111111111111111111111111110110110111111111",
"00011111111111111111111111111111101111011",
"000111111111111111111111111111111011111111111",
"0001111111111111111111111111111111011",
"00011111111111111111111111111111111101",
"0001111111111111111111111111111111111011",
"00011111111111111111111111111111111111011111",
"000111111111111111111111111111111111111001111111111111111111111111111111111111111111111111111111101",
"000111111111111111111111111111111111111001111111111111111111111111111111111111111111111111111111111",
"00011111111111111111111111111111111111101111",
"00011111111111111111111111111111111111110",
"00100111",
"00101101",
"0010111110111",
"0010111111",
"001111"
],
"nprops": {
"1": {
"type": "0011"
},
"10": {
"type": "00111",
"ports": {
"0": "101"
}
},
"101": {
"type": "001111",
"ports": {
"0": "10"
}
}
},
"tprops": {
"0": {
"name": "XholonClass"
},
"00": {
"name": "XholonMechanism"
},
"000": {
"name": "XhMechanisms"
},
"0001": {
"name": "XholonMechanisms"
},
"00011": {
"name": "UserMechanisms"
},
"000111": {
"name": "UserMechanism"
},
"0001111": {
"name": "Annotation"
},
"00011111": {
"name": "Attribute"
},
"0010111111": {
"name": "TextTree"
},
"0011": {
"name": "HelloWorldSystem"
},
"00111": {
"name": "Hello"
},
"001111": {
"name": "World"
}
}
}</Attribute_String>
<PftbJSON/>
</Pftb>
</PhysicalSystem>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Path Following Tree Builder - Config A</title>
<rect id="PhysicalSystem/Pftb" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>PftbConfigA</title>
<rect id="PhysicalSystem/Pftb[2]" 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