<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/wb/ (C) Ken Webb Mon May 28 2012 10:43:13 GMT-0400 (EDT)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: John Baez on Petri Nets
Description:
Url: http://johncarlosbaez.wordpress.com/2011/01/18/petri-nets/
InternalName:
YoutubeId:
Keywords:
My Notes **May 27 2012**
--------
This workbook contains an implementation of a Petri Net described by John Baez ::
http://johncarlosbaez.wordpress.com/2011/01/18/petri-nets/
It reuses the structure and SVG image I previously developed for a Java version of this Petri Net app ::
http://www.primordion.com/Xholon/jnlp/
How to run the Petri Net app ::
Click the Run button above.
The initial configuration will display, with C O2 NaOH HCL each having one token.
Click the Pause button in the overlay, to unpause the app and start it running.
The initial configuration will proceed to its final stable state, with CO2 H2O NaCL each having one token.
Click on any of the 8 yellow compounds in the graphic, to toggle whether or not it has a token.
When both inputs to a reaction (blue squares) are selected, the reaction will take place.
All of the code for this app is contained within the various editors on this page. This includes the XML structure, the JavaScript/jQuery behaviors, and the source for the SVG graphic.
How to edit the code for this app ::
Scroll down to any of the editors on this page.
Change something.
Run or Refresh the app.
Of course, arbitrary changes will cause the app to not work anymore. One simple edit is to change the colors of the shapes in the SVG graphic. For example, yellow is "fill:#ffff00;". To change this to pink, use "fill:#ffc0cb;". For other colors, look at ::
http://www.w3schools.com/cssref/css_colornames.asp
]]></Notes>
<script implName="lang:python:inline:"><![CDATA[
print "Petri Nets"
]]></script>
<script implName="lang:javascript:inline:"><![CDATA[
print("\nPetri Nets");
]]></script>
<_-.XholonClass>
<!-- types of domain objects -->
<TheSystem/>
<!-- chemical compounds (Petri Net states) -->
<Compound>
<C/>
<O2/>
<CO2/>
<NaOH/>
<NaHCO3/>
<HCl/>
<H2O/>
<NaCl/>
</Compound>
<Compounds/>
<!-- chemical reactions (Petri Net transitions) -->
<Reaction>
<Rone/>
<Rtwo/>
<Rthree/>
</Reaction>
<Reactions/>
</_-.XholonClass>
<xholonClassDetails>
<Reaction xhType="XhtypePureActiveObject"/>
<Rone>
<port name="port0" index="0" connector="#xpointer(ancestor::TheSystem/Compounds/C)"/>
<port name="port1" index="1" connector="#xpointer(ancestor::TheSystem/Compounds/O2)"/>
<port name="port2" index="2" connector="#xpointer(ancestor::TheSystem/Compounds/CO2)"/>
</Rone>
<Rtwo>
<port name="port0" index="0" connector="#xpointer(ancestor::TheSystem/Compounds/NaOH)"/>
<port name="port1" index="1" connector="#xpointer(ancestor::TheSystem/Compounds/CO2)"/>
<port name="port2" index="2" connector="#xpointer(ancestor::TheSystem/Compounds/NaHCO3)"/>
</Rtwo>
<Rthree>
<port name="port0" index="0" connector="#xpointer(ancestor::TheSystem/Compounds/HCl)"/>
<port name="port1" index="1" connector="#xpointer(ancestor::TheSystem/Compounds/NaHCO3)"/>
<port name="port2" index="2" connector="#xpointer(ancestor::TheSystem/Compounds/H2O)"/>
<port name="port3" index="3" connector="#xpointer(ancestor::TheSystem/Compounds/NaCl)"/>
<port name="port4" index="4" connector="#xpointer(ancestor::TheSystem/Compounds/CO2)"/>
</Rthree>
<Compound xhType="XhtypePurePassiveObject"/>
</xholonClassDetails>
<TheSystem>
<Compounds>
<C>1</C>
<O2>1</O2>
<NaOH>1</NaOH>
<CO2>0</CO2>
<HCl>1</HCl>
<NaHCO3>0</NaHCO3>
<H2O>0</H2O>
<NaCl>0</NaCl>
</Compounds>
<Reactions>
<Rone/>
<Rtwo/>
<Rthree/>
</Reactions>
</TheSystem>
<Blockbehavior implName="lang:python:inline:"><![CDATA[
]]></Blockbehavior>
<Blockbehavior implName="lang:javascript:inline:"><![CDATA[
]]></Blockbehavior>
<TheSystembehavior implName="lang:webEditionjs:inline:"><![CDATA[
function postConfigure() {
this.application('setConfigParam', 'TimeStepInterval', 500);
}
]]></TheSystembehavior>
<Reactionsbehavior implName="lang:webEditionjs:inline:"><![CDATA[
function act() {
if (this.application('getTimeStep') == 0) {
var svg = $($('div#mySVGDiv > object')[0].contentDocument.getElementsByTagNameNS(svgns, 'svg')[0]);
this.data('paths', svg.children('g').children('path[id^="Compounds"]'));
}
var paths = this.data('paths');
this.siblings().each( function () {
var reaction = $(this);
reaction.bindPorts(reaction);
if ((reaction.port0.attr('val') == 1) && (reaction.port1.attr('val') == 1)) {
paths.filter('path[id$="/' + reaction.port0.getXhcName() + '"]').click();
paths.filter('path[id$="/' + reaction.port1.getXhcName() + '"]').click();
if (reaction.port2.attr('val') == 0) {
paths.filter('path[id$="/' + reaction.port2.getXhcName() + '"]').click();
}
if (reaction.port3 && reaction.port3.attr('val') == 0) {
paths.filter('path[id$="/' + reaction.port3.getXhcName() + '"]').click();
}
if (reaction.port4 && reaction.port4.attr('val') == 0) {
paths.filter('path[id$="/' + reaction.port4.getXhcName() + '"]').click();
}
}
});
}
]]></Reactionsbehavior>
<Compoundsbehavior implName="lang:webEditionjs:inline:"><![CDATA[
function act() {
var compounds = this.parent();
if (this.application('getTimeStep') == 0) {
var svg = $($('div#mySVGDiv > object')[0].contentDocument.getElementsByTagNameNS(svgns, 'svg')[0]);
var paths = svg.children('g').children('path[id^="Compounds"]');
paths.bind( 'click', function() {
var thisPath = $(this);
var xhcName = thisPath.attr('id').substring(10);
var node = compounds.children('.' + xhcName);
var svgId = null;
switch (xhcName) {
case 'NaOH': svgId='tspan4014'; break;
case 'HCl': svgId='tspan4018'; break;
case 'C': svgId='tspan4022'; break;
case 'O2': svgId='tspan4026'; break;
case 'CO2': svgId='tspan4030'; break;
case 'NaHCO3': svgId='tspan4034'; break;
case 'H2O': svgId='tspan4038'; break;
case 'NaCl': svgId='tspan4042'; break;
default: break;
}
var tspan = svg.children('g').children('text').children('tspan#' + svgId);
if (node.attr('val') == 0) {
node.attr('val', 1);
tspan.text('\u2B24');
}
else {
node.attr('val', 0);
tspan.text(' ');
}
});
paths.click();
paths.click();
}
}
]]></Compoundsbehavior>
<TheSystembehavior implName="lang:bsh:inline:"><![CDATA[
]]></TheSystembehavior>
<Blockbehavior implName="lang:jruby:inline:"><![CDATA[
]]></Blockbehavior>
<Blockbehavior implName="lang:groovy:inline:"><![CDATA[
]]></Blockbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg id="svg2" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" height="162" width="474" version="1.1" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
<metadata id="metadata7">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<g id="layer1" transform="translate(-120.16872,-87.928404)">
<path id="Compounds/C" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#ffff00;" d="m190.35,72.638c0,8.8177-7.1482,15.966-15.966,15.966-8.8177,0-15.966-7.1482-15.966-15.966,0-8.8177,7.1482-15.966,15.966-15.966,8.8177,0,15.966,7.1482,15.966,15.966z" transform="translate(-37.737533,33.334532)"/>
<text id="text3071" style="font-size:14px;font-family:Arial;writing-mode:lr-tb;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;" xml:space="preserve" y="105.26507" x="155.09712"><tspan id="tspan3073" x="155.09712" y="105.26507">C</tspan></text>
<path id="path3831" d="m304.31,116.83,31.761,31.855,0.71343-0.70073,3.4909,4.9813-4.9178-3.5799,0.71344-0.70072" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;"/>
<path id="Compounds/NaOH" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#ffff00;" d="m190.35,72.638c0,8.8177-7.1482,15.966-15.966,15.966-8.8177,0-15.966-7.1482-15.966-15.966,0-8.8177,7.1482-15.966,15.966-15.966,8.8177,0,15.966,7.1482,15.966,15.966z" transform="translate(120.26247,33.334532)"/>
<path id="Compounds/HCl" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#ffff00;" d="m190.35,72.638c0,8.8177-7.1482,15.966-15.966,15.966-8.8177,0-15.966-7.1482-15.966-15.966,0-8.8177,7.1482-15.966,15.966-15.966,8.8177,0,15.966,7.1482,15.966,15.966z" transform="translate(276.26247,33.334532)"/>
<path id="Compounds/H2O" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#ffff00;" d="m190.35,72.638c0,8.8177-7.1482,15.966-15.966,15.966-8.8177,0-15.966-7.1482-15.966-15.966,0-8.8177,7.1482-15.966,15.966-15.966,8.8177,0,15.966,7.1482,15.966,15.966z" transform="translate(402.26247,33.334532)"/>
<path id="path3827" d="m293.71,168.28,40,0,0-1,6,1-6,1,0-1" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;"/>
<path id="Compounds/CO2" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#ffff00;" d="m190.35,72.638c0,8.8177-7.1482,15.966-15.966,15.966-8.8177,0-15.966-7.1482-15.966-15.966,0-8.8177,7.1482-15.966,15.966-15.966,8.8177,0,15.966,7.1482,15.966,15.966z" transform="translate(103.67454,95.868767)"/>
<path id="path3839" d="m451.71,168.28,40,0,0-1,6,1-6,1,0-1" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;"/>
<path id="Compounds/NaHCO3" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#ffff00;" d="m190.35,72.638c0,8.8177-7.1482,15.966-15.966,15.966-8.8177,0-15.966-7.1482-15.966-15.966,0-8.8177,7.1482-15.966,15.966-15.966,8.8177,0,15.966,7.1482,15.966,15.966z" transform="translate(261.67454,95.868767)"/>
<path id="Compounds/O2" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#ffff00;" d="m190.35,72.638c0,8.8177-7.1482,15.966-15.966,15.966-8.8177,0-15.966-7.1482-15.966-15.966,0-8.8177,7.1482-15.966,15.966-15.966,8.8177,0,15.966,7.1482,15.966,15.966z" transform="translate(-37.737533,158.83465)"/>
<path id="path3835" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;" d="m528.76,183.6,31.761,31.855,0.71343-0.70073,3.4909,4.9813-4.9178-3.5799,0.71344-0.70072"/>
<path id="Compounds/NaCl" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#ffff00;" d="m190.35,72.638c0,8.8177-7.1482,15.966-15.966,15.966-8.8177,0-15.966-7.1482-15.966-15.966,0-8.8177,7.1482-15.966,15.966-15.966,8.8177,0,15.966,7.1482,15.966,15.966z" transform="translate(402.26247,158.83465)"/>
<rect id="Reactions/Rone" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#00ffff;" height="30.688" width="30.688" y="153.37" x="184.54"/>
<rect id="Reactions/Rtwo" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#00ffff;" height="30.688" width="30.688" y="153.37" x="340.54"/>
<rect id="Reactions/Rthree" style="opacity:0.9;stroke-dashoffset:0;stroke:#000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:1;fill:#00ffff;" height="30.688" width="30.688" y="153.37" x="498.54"/>
<text id="text3095" style="font-size:14px;font-family:Arial;writing-mode:lr-tb;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;" y="105.26507" x="231.09712" xml:space="preserve"><tspan id="tspan3097" y="105.26507" x="231.09712">NaOH</tspan></text>
<text id="text3099" style="font-size:14px;font-family:Arial;writing-mode:lr-tb;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;" xml:space="preserve" y="105.26507" x="403.09711"><tspan id="tspan3101" x="403.09711" y="105.26507">HCl</tspan></text>
<text id="text3103" style="font-size:14px;font-family:Arial;writing-mode:lr-tb;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;" y="105.26507" x="529.09711" xml:space="preserve">H<tspan id="tspan4048" style="font-size:10px;font-family:Arial;writing-mode:lr-tb;baseline-shift:sub;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;">2</tspan> O</text>
<text id="text3107" style="font-size:14px;font-family:Arial;writing-mode:lr-tb;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;" xml:space="preserve" y="151.71126" x="278.20471">CO<tspan id="tspan4046" style="font-size:10px;font-family:Arial;writing-mode:lr-tb;baseline-shift:sub;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;">2</tspan></text>
<text id="text3111" style="font-size:14px;font-family:Arial;writing-mode:lr-tb;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;" y="151.71126" x="404.20471" xml:space="preserve">NaHCO<tspan id="tspan4050" style="font-size:10px;font-family:Arial;writing-mode:lr-tb;baseline-shift:sub;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;">3</tspan></text>
<text id="text3115" style="font-size:14px;font-family:Arial;writing-mode:lr-tb;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;" y="247.09184" x="155.45406" xml:space="preserve">O<tspan id="tspan4044" style="font-size:10px;font-family:Arial;writing-mode:lr-tb;baseline-shift:sub;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;">2</tspan></text>
<text id="text3119" style="font-size:14px;font-family:Arial;writing-mode:lr-tb;fill:#000000;letter-spacing:0px;text-anchor:start;line-height:125%;word-spacing:0px;font-stretch:normal;font-variant:normal;font-weight:bold;font-style:normal;text-align:start;" y="247.50653" x="530.39899" xml:space="preserve"><tspan id="tspan3121" y="247.50653" x="530.39899">NaCl</tspan></text>
<text id="text4012" style="font-size:14px;font-family:Bitstream Vera Sans;letter-spacing:0px;line-height:125%;word-spacing:0px;font-weight:normal;font-style:normal;fill:#000000;" xml:space="preserve" y="109.60902" x="286.80908"><tspan id="tspan4014" x="286.80908" y="109.60902">⬤</tspan></text>
<text id="text4016" style="font-size:14px;font-family:Bitstream Vera Sans;letter-spacing:0px;line-height:125%;word-spacing:0px;font-weight:normal;font-style:normal;fill:#000000;" y="109.60902" x="442.80908" xml:space="preserve"><tspan id="tspan4018" y="109.60902" x="442.80908">⬤</tspan></text>
<text id="text4020" style="font-size:14px;font-family:Bitstream Vera Sans;letter-spacing:0px;line-height:125%;word-spacing:0px;font-weight:normal;font-style:normal;fill:#000000;" y="109.60902" x="128.80907" xml:space="preserve"><tspan id="tspan4022" y="109.60902" x="128.80907">⬤</tspan></text>
<text id="text4024" style="font-size:14px;font-family:Bitstream Vera Sans;letter-spacing:0px;line-height:125%;word-spacing:0px;font-weight:normal;font-style:normal;fill:#000000;" xml:space="preserve" y="235.10915" x="128.80907"><tspan id="tspan4026" x="128.80907" y="235.10915">⬤</tspan></text>
<text id="text4028" style="font-size:14px;font-family:Bitstream Vera Sans;letter-spacing:0px;line-height:125%;word-spacing:0px;font-weight:normal;font-style:normal;fill:#000000;" y="172.14326" x="270.22113" xml:space="preserve"><tspan id="tspan4030" y="172.14326" x="270.22113"> </tspan></text>
<text id="text4032" style="font-size:14px;font-family:Bitstream Vera Sans;letter-spacing:0px;line-height:125%;word-spacing:0px;font-weight:normal;font-style:normal;fill:#000000;" xml:space="preserve" y="172.14326" x="428.22113"><tspan id="tspan4034" x="428.22113" y="172.14326"> </tspan></text>
<text id="text4036" style="font-size:14px;font-family:Bitstream Vera Sans;letter-spacing:0px;line-height:125%;word-spacing:0px;font-weight:normal;font-style:normal;fill:#000000;" xml:space="preserve" y="109.60902" x="568.80908"><tspan id="tspan4038" x="568.80908" y="109.60902"> </tspan></text>
<text id="text4040" style="font-size:14px;font-family:Bitstream Vera Sans;letter-spacing:0px;line-height:125%;word-spacing:0px;font-weight:normal;font-style:normal;fill:#000000;" y="235.10915" x="568.80908" xml:space="preserve"><tspan id="tspan4042" y="235.10915" x="568.80908"> </tspan></text>
<path id="path3043" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;" d="m215.71,168.28,40,0,0-1,6,1-6,1,0-1"/>
<path id="path3825" d="m148.62,220.18,31.035-31.339-0.70571-0.7085,4.9567-3.5258-3.5453,4.9428-0.70571-0.70851" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;"/>
<path id="path3829" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;" d="m148.38,117.04,31.761,31.855,0.71343-0.70073,3.4909,4.9813-4.9178-3.5799,0.71344-0.70072"/>
<path id="path3833" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;" d="m529.72,153.41,31.035-31.339-0.70571-0.7085,4.9567-3.5258-3.5453,4.9428-0.70571-0.70851"/>
<path id="path3837" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;" d="m371.3,168.28,42,0,0-1,6,1-6,1,0-1"/>
<path id="path3841" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;" d="m462.31,116.83,31.761,31.855,0.71343-0.70073,3.4909,4.9813-4.9178-3.5799,0.71344-0.70072"/>
<path id="path3843" style="stroke-linejoin:round;stroke:#000000;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-width:0.80000001;fill:#000000;" d="m277.71,190.81-0.99998-0.004,1.0236-5.996,0.97642,6.0039-1-0.004"/>
<path id="path3845" style="stroke-linejoin:miter;stroke:#000000;stroke-linecap:butt;stroke-width:0.86793822px;fill:none;" d="m512.94,184.34c21.2,63.18-242.11,66.456-234.99,1.4554"/>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
All original content Copyright © 2012 Ken Webb