Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active December 26, 2017 19:28
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/0fb6d386d911da8216461fde77713142 to your computer and use it in GitHub Desktop.
Save kenwebb/0fb6d386d911da8216461fde77713142 to your computer and use it in GitHub Desktop.
Buttons and Threads with Containment
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Tue Dec 26 2017 14:28:19 GMT-0500 (EST)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Buttons and Threads with Containment
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: 0fb6d386d911da8216461fde77713142 based on 32b2ecdbb0c7d0e945bcdfdd6a7dca05
Keywords:
My Notes
--------
December 26, 2017
To produce the SVG line chart:
- run the model for 2000+ time steps
- copy the data from the "out" tab
- paste the data into a LibreOffice Calc spreadsheet, as 2 comma-delimited columns
- create a chart - XY (Scatter) Lines Only
- select the 2 ranges
- if necessary, reverse the ranges of the X and Y data
- add titles to the chart
- export the chart in SVG format
- paste the SVG content into this workbook
References
----------
(1) Watts (2003), Six Degrees, p. 44
]]></Notes>
<_-.XholonClass>
<PhysicalSystem/>
<Button/>
<Buttons/>
<Component/>
<Components/>
</_-.XholonClass>
<xholonClassDetails>
</xholonClassDetails>
<PhysicalSystem>
<Buttons>
<Button multiplicity="1000"/>
</Buttons>
<Components>
<!-- at runtime, Component nodes will be added here -->
</Components>
</PhysicalSystem>
<Buttonsbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var me, buttonArr, buttonCount, edgeCount, componentsNode, beh = {
postConfigure: function() {
me = this.cnode.parent();
buttonArr = [];
componentsNode = me.next();
var button = me.first();
while (button && button.xhc().name() == "Button") {
button.thread = [];
buttonArr.push(button);
button = button.next();
}
buttonCount = buttonArr.length; // total number of buttons/nodes (a constant)
edgeCount = 0; // total number of directed threads/edges between buttons/nodes
$wnd.console.log(buttonArr);
$wnd.xh.root().append(this.cnode.remove());
},
act: function() {
var button1 = buttonArr[$wnd.Math.floor($wnd.Math.random() * buttonCount)];
var button2 = buttonArr[$wnd.Math.floor($wnd.Math.random() * buttonCount)];
if ((button1 != button2) && (button1.thread.indexOf(button2) == -1)) {
var componentNode = null;
if ((button1.parent().xhc().name() == "Buttons") && (button2.parent().xhc().name() == "Buttons")) {
componentsNode.append("<" + "Component/>");
componentNode = componentsNode.last();
componentNode.append(button1.remove());
componentNode.append(button2.remove());
}
else if ((button1.parent().xhc().name() == "Component") && (button2.parent().xhc().name() == "Buttons")) {
button1.parent().append(button2.remove());
}
else if ((button1.parent().xhc().name() == "Buttons") && (button2.parent().xhc().name() == "Component")) {
button2.parent().append(button1.remove());
}
else if (button1.parent() != button2.parent()) {
// move all buttons from button2 component to button1 component
var button1Component = button1.parent();
var button2Component = button2.parent(); //component;
var buttonn = button2Component.first();
while (buttonn) {
var nextButtonn = buttonn.next();
button1Component.append(buttonn.remove());
buttonn = nextButtonn;
}
if (button2Component.xhc().name() != "Component") {
me.println(button2Component.name());
}
button2Component.remove();
}
else {
// both buttons are in the same existing component
}
button1.thread.push(button2);
edgeCount++;
var lcarr = this.findLargestComponent();
var lcsize = lcarr[0];
var lccount = lcarr[1];
// double the edge count to convert from directed to undirected links
me.println((lcsize / buttonCount) + "," + ((edgeCount * 2) / buttonCount));
}
},
findLargestComponent: function() {
var cnodeCount = 0;
var maxCnode = null;
var maxCnodeSize = 0;
var cnode = componentsNode.first();
while (cnode) {
cnodeCount++;
var count = this.countChildren(cnode);
if (count > maxCnodeSize) {
maxCnode = cnode;
maxCnodeSize = count;
}
cnode = cnode.next();
}
return [maxCnodeSize, cnodeCount];
},
countChildren: function(p) {
var count = 0;
var child = p.first();
while (child) {
count++;
child = child.next();
}
return count;
},
calcAverageLinksPerNode: function() {
return 0;
}
}
//# sourceURL=Buttonsbehavior.js
]]></Buttonsbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Buttons</title>
<rect id="PhysicalSystem/Buttons" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Button</title>
<rect id="PhysicalSystem/Buttons/Button" 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