Last active
July 21, 2023 15:50
-
-
Save kenwebb/b2c73fc2c2b14c7854631bdf9b99a50a to your computer and use it in GitHub Desktop.
Getting a cup of coffee - with Binary Tree focus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Results of running genBinaryLabelings.js for CSH nodes | |
string | |
------ | |
chameleon_0|1 | |
physicalSystem_45|10 | |
coffeeWorld_46|100 | |
kitchen_47|1000 | |
grinder_48|10000 | |
water_49|100001 | |
coffeeBeanStore_50|10001 | |
beans_51|100010 | |
brewedCoffeeStore_52|100011 | |
coffee_53|1000110 | |
Set <entries> nodeset | |
------------- | |
0: "1" | |
1: "10" | |
2: "100" | |
3: "1000" | |
4: "10000" | |
5: "100001" | |
6: "10001" | |
7: "100010" | |
8: "100011" | |
9: "1000110" | |
dictionary object (JSON) | |
----------------- | |
{ | |
"1": "chameleon_0", | |
"10": "physicalSystem_45", | |
"100": "coffeeWorld_46", | |
"1000": "kitchen_47", | |
"10000": "grinder_48", | |
"10001": "coffeeBeanStore_50", | |
"100001": "water_49", | |
"100010": "beans_51", | |
"100011": "brewedCoffeeStore_52", | |
"1000110": "coffee_53" | |
} | |
externals array | |
[ | |
"100001", | |
"100010", | |
"1000110" | |
] | |
size of full nodeset vs size of externals array | |
nodeset: 10 externals: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const LEFT = "0" | |
const RIGHT = "1" | |
const CSHROOT = "1" | |
const IHROOT = "0" | |
const ROOT = CSHROOT | |
//const root = xh.root() | |
//const ihroot = xh.root().xhc().parent(); // XholonClass | |
const root = ROOT == CSHROOT ? xh.root() : xh.root().xhc().parent() | |
console.log(ROOT) | |
console.log(root) | |
var str = "" | |
const nodeset = new Set() | |
var nodedict = {} | |
var externals = [] | |
// using role() functions - this works | |
//const setText = (node, str) => node.role(str) | |
//const getText = node => node.role() | |
// using text() functions - this works | |
//const setText = (node, str) => node.text(str) | |
//const getText = node => node.text() | |
// using textval functions - this works | |
const setText = (node, str) => node.textval = str | |
const getText = node => node.textval | |
setText(root, ROOT) | |
console.log(root) | |
const doNode = node => { | |
str = str + node.name() + "|" + getText(node) + "\n" | |
nodeset.add(getText(node)) | |
nodedict[getText(node)] = node.name() | |
if (node.first()) { | |
setText(node.first(), getText(node) + LEFT) | |
doNode(node.first()) | |
} | |
if ((node != root) && node.next()) { | |
setText(node.next(), getText(node) + RIGHT) | |
doNode(node.next()) | |
} | |
if (!node.first() && !node.next()) { | |
externals.push(getText(node)); | |
} | |
} | |
// code for IHROOT | |
if (ROOT == IHROOT) { | |
setText(root.first(), ROOT + LEFT) // skip XholonMechanism | |
setText(root.first().next(), ROOT + LEFT + RIGHT) // skip XholonViewer | |
setText(root.first().next().next(), ROOT + LEFT + RIGHT + RIGHT) | |
doNode(root.first().next().next()) // IH | |
} | |
else { | |
doNode(root) // CSH | |
} | |
console.log(str) // OK | |
console.log(nodeset) // OK | |
console.log(nodedict) // OK | |
console.log(externals) // OK | |
console.log(`nodeset: ${nodeset.size} externals: ${externals.length}`) | |
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Results of running genBinaryLabelings.js for IH types | |
string | |
------ | |
Chameleon|0011 | |
Quantity|00111 | |
PhysicalSystem|001111 | |
CoffeeWorld|0011111 | |
Location|00111111 | |
Kitchen|001111110 | |
Store|0011111101 | |
CoffeeBeanStore|00111111010 | |
BrewedCoffeeStore|001111110101 | |
Bank|00111111011 | |
Thing|001111111 | |
Coffee|0011111110 | |
Beans|00111111101 | |
Grinder|001111111011 | |
Water|0011111110111 | |
Money|00111111101111 | |
Set <entries> nodeset | |
------------- | |
0: "0011" | |
1: "00111" | |
2: "001111" | |
3: "0011111" | |
4: "00111111" | |
5: "001111110" | |
6: "0011111101" | |
7: "00111111010" | |
8: "001111110101" | |
9: "00111111011" | |
10: "001111111" | |
11: "0011111110" | |
12: "00111111101" | |
13: "001111111011" | |
14: "0011111110111" | |
15: "00111111101111" | |
dictionary object (JSON) | |
----------------- | |
{ | |
"0011": "Chameleon", | |
"00111": "Quantity", | |
"001111": "PhysicalSystem", | |
"0011111": "CoffeeWorld", | |
"00111111": "Location", | |
"001111110": "Kitchen", | |
"0011111101": "Store", | |
"00111111010": "CoffeeBeanStore", | |
"001111110101": "BrewedCoffeeStore", | |
"00111111011": "Bank", | |
"001111111": "Thing", | |
"0011111110": "Coffee", | |
"00111111101": "Beans", | |
"001111111011": "Grinder", | |
"0011111110111": "Water", | |
"00111111101111": "Money" | |
} | |
externals array | |
[ | |
"001111110101", | |
"00111111011", | |
"00111111101111" | |
] | |
size of full nodeset vs size of externals array | |
nodeset: 16 externals: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Fri Jul 21 2023 11:49:36 GMT-0400 (GMT-04:00)--> | |
<XholonWorkbook> | |
<Notes><![CDATA[ | |
Xholon | |
------ | |
Title: Getting a cup of coffee - with Binary Tree focus | |
Description: | |
Url: http://www.primordion.com/Xholon/gwt/ | |
InternalName: b2c73fc2c2b14c7854631bdf9b99a50a based on eff45f230c126738760f3498487e5d5b | |
Keywords: | |
My Notes | |
-------- | |
21 July 2023 | |
I have recently focused on representing a Xholon Binary Tree (BT) as sets of Binary Strings. | |
see: | |
- recent notes in my paper notebook | |
- JS code I've been using in Dev Tools (Firefox) | |
- recent JS files in | |
- ~/gwtspace/Xholon/Xholon/script/javascript | |
- such as: | |
btreeLabeling.js | |
binhexfuncs.js | |
TODO | |
- add additional files to this gist | |
genBinaryLabelings.js | |
... | |
- include only the BT structure, | |
and not Avatar and Animate that were in the original version of "Getting a cup of coffee" | |
- add new functions | |
- btleft, btright, xhfirst, xhnext, btparent, compose, pipe, etc. | |
- see btreeLabeling.js | |
- add one or more ports, as an example | |
### functions | |
// standard functions | |
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x) | |
const pipe = (...fns) => x => fns.reduce((y, f) => f(y), x) | |
// root, initial node | |
const root = "1" | |
// a set where all the nodes can live together in a convenient common container | |
const nodeset = new Set() | |
nodeset.add(root) | |
// constant values | |
const LEFT = "0" | |
const RIGHT = "1" | |
const UNIT = "" | |
// functions | |
const identity = node => node + UNIT | |
const height = node => node.length // TODO ??? | |
const isRoot = node => node == root | |
const bin2hex = bin => parseInt(bin, 2).toString(16) | |
const hex2bin = hex => parseInt(hex, 16).toString(2) | |
// BT functions | |
const btleft = node => node + LEFT | |
const btright = node => node + RIGHT | |
const btparent = node => node == root ? null : node = node.slice(0, -1); | |
// examples | |
const node01 = compose(btleft, btright, btleft, btleft)(root) | |
nodeset.add(node01) | |
console.log(node01) // "10010" | |
### My Old Notes | |
------------ | |
July 21, 2021 | |
see gist eff45f230c126738760f3498487e5d5b | |
###References | |
---------- | |
]]></Notes> | |
<_-.XholonClass> | |
<PhysicalSystem/> | |
<CoffeeWorld/> | |
<Location> | |
<Kitchen/> | |
<Store> | |
<CoffeeBeanStore/> | |
<BrewedCoffeeStore/> | |
</Store> | |
<Bank/> | |
</Location> | |
<Thing> | |
<Coffee/> | |
<Beans/> <!--<CoffeeBeans/>--> | |
<Grinder/> | |
<Water/> | |
<Money/> | |
</Thing> | |
</_-.XholonClass> | |
<xholonClassDetails> | |
</xholonClassDetails> | |
<PhysicalSystem> | |
<CoffeeWorld> | |
<Kitchen> | |
<Grinder/> | |
<Water state="cold"/> | |
</Kitchen> | |
<CoffeeBeanStore> | |
<Beans multiplicity="1"/> | |
</CoffeeBeanStore> | |
<BrewedCoffeeStore> | |
<Coffee state="brewed" multiplicity="1"/> | |
</BrewedCoffeeStore> | |
</CoffeeWorld> | |
</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>CoffeeWorld</title> | |
<rect id="PhysicalSystem/CoffeeWorld" fill="#98FB98" height="50" width="50" x="25" y="0"/> | |
<g> | |
<title>Kitchen</title> | |
<rect id="PhysicalSystem/CoffeeWorld/Kitchen" 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