Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active July 29, 2018 12:09
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/b64f0c809c008777cc7885ccead6b297 to your computer and use it in GitHub Desktop.
Save kenwebb/b64f0c809c008777cc7885ccead6b297 to your computer and use it in GitHub Desktop.
Ceptre - Blocks World
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Sun Jul 29 2018 08:08:41 GMT-0400 (Eastern Daylight Time)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Ceptre - Blocks World
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: b64f0c809c008777cc7885ccead6b297
Keywords:
My Notes
--------
July 25, 2018
The Ceptre specification is symbolic (ex: no "table", just predicates such as "on_table").
I'm choosing to implement the Xholon model using real-world objects (ex: "table").
Alternatively, I could choose to represent the Xholon model using symbolic objects (simple variables).
see ref [1]
------------------------------------------------------------------
block : type.
on block block : pred.
on_table block : pred.
clear block : pred.
arm_holding block : pred.
arm_free : pred.
stage blocks = {
pickup_from_block
: on X Y * clear X * arm_free -o clear Y * arm_holding X.
pickup_from_table
: on_table X * clear X * arm_free -o arm_holding X.
put_on_block
: arm_holding X * clear Y -o on X Y * clear X * arm_free.
put_on_table
: arm_holding X -o on_table X * clear X * arm_free.
% win_condition
% : on_table c * on b c * on a b * clear a * arm_free
% -o ().
}
#interactive blocks.
a : block.
b : block.
c : block.
context init =
{ on_table a, on_table b, on c a, clear c, clear b, arm_free }
#trace _ blocks init.
------------------------------------------------------------------
To run using the original Ceptre software:
-----------------------------------------
cd ~/ceptre
./ceptre-bin examples/blocks-world.cep
References
----------
(1) https://github.com/chrisamaphone/interactive-lp/blob/master/examples/blocks-world.cep
(2) Chris Martens thesis
p. 157-159 Example: Blocks World
blocks stacked on a table
robotic arm that can pick up blocks and set them down on top of one another or on the table
blocks are arranged in linear stacks with the table at the bottom
the arm always holds at most one block
there s a unique top block of every stack that is marked as "clear"
]]></Notes>
<_-.XholonClass>
<PhysicalSystem/>
<BlocksWorld/>
<block/> <!-- block is the only type defined in Ceptre -->
<blocks/>
<table/>
<arm/>
</_-.XholonClass>
<xholonClassDetails>
</xholonClassDetails>
<PhysicalSystem>
<BlocksWorld>
<blocks>
<block roleName="a"/>
<block roleName="b"/>
<block roleName="c"/>
</blocks>
<table/>
<arm/>
</BlocksWorld>
<!-- init = {...}. see ref [1] -->
<Context roleName="init"><Attribute_String><![CDATA[
on_table a, on_table b, on c a, clear c, clear b, arm_free
]]></Attribute_String></Context>
<!-- stage from ref [1]; rules -->
<CeptreJsonRulesEngineRecipeBook roleName="blocks" NOT_ExtraRHS="one,two,three"><Attribute_String><![CDATA[
stage blocks = {
pickup_from_block
: on X Y * clear X * arm_free -o clear Y * arm_holding X.
pickup_from_table
: on_table X * clear X * arm_free -o arm_holding X.
put_on_block
: arm_holding X * clear Y -o on X Y * clear X * arm_free.
put_on_table
: arm_holding X -o on_table X * clear X * arm_free.
% win_condition
% : on_table c * on b c * on a b * clear a * arm_free
% -o ().
}
]]></Attribute_String></CeptreJsonRulesEngineRecipeBook>
<Animate selection="#xhanim" xpath="./PhysicalSystem/BlocksWorld" duration="1" cssStyle=".d3cpnode circle {stroke-width: 0px;}" efParams="{&quot;selection&quot;:&quot;#xhanim&quot;,&quot;sort&quot;:&quot;disable&quot;,&quot;width&quot;:600,&quot;height&quot;:600,&quot;mode&quot;:&quot;tween&quot;,&quot;labelContainers&quot;:true,&quot;includeId&quot;:true,&quot;shape&quot;:&quot;circle&quot;,&quot;useIcons&quot;:false}"/>
</PhysicalSystem>
<blocksbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var me, beh = {
postConfigure: function() {
me = this.cnode.parent();
me.blockMap = {};
this.cnode.remove();
var node = me.first();
while (node) {
//me.blockArr.push(node); // cache the block node in case it's moved
me.blockMap[node.role()] = node;
node = node.next();
}
}
}
//# sourceURL=blocksbehavior.js
]]></blocksbehavior>
<Contextbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var me, blocknodes, tablenode, beh = {
postConfigure: function() {
me = this.cnode.parent();
blocknodes = me.xpath("../BlocksWorld/blocks");
tablenode = me.xpath("../BlocksWorld/table");
var str = me.first().text();
var arr = str.split(",");
arr.forEach(function(item) {
item = item.trim();
me.println(item);
beh.processItem(item);
});
this.cnode.remove();
me.first().remove();
//me.remove();
},
processItem: function(item) {
var arr = item.split(" ");
switch(arr[0]) {
case "on_table": // on_table a
this.processOnTable(arr);
break;
case "on":
//these are all "block block : pred."
this.processPred_bb(arr);
break;
default:
//me.println("UNHANDLED " + arr[0]); // no_pc
break;
}
},
processPred_bb: function(arr) {
// pred, block, block (ex: on c a) Note: c and a are reversed from what I think they should be
var pred = arr[0];
var bstr1 = arr[1];
var bstr2 = arr[2];
var bnode1 = blocknodes.blockMap[bstr1];
var bnode2 = blocknodes.blockMap[bstr2];
if ((!bnode1) || (!bnode2)) {
//if (!bnode1) {me.println(" NOpred1 " + bstr1);}
//if (!bnode2) {me.println(" NOpred2 " + bstr2);}
}
else {
bnode2.append(bnode1.remove());
}
},
processOnTable: function(arr) {
// on_table a
var bstr = arr[1];
var bnode = blocknodes.xpath("*[@roleName='" + bstr + "']"); // block
if (bnode) {
tablenode.append(bnode.remove());
}
}
}
//# sourceURL=Contextbehavior.js
]]></Contextbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Blocks World</title>
<rect id="PhysicalSystem/BlocksWorld" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>table</title>
<rect id="PhysicalSystem/BlocksWorld/table" 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