Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active August 31, 2024 12:48
Show Gist options
  • Save kenwebb/d2eba24950bcd2f40f7bf6a5bf42cf59 to your computer and use it in GitHub Desktop.
Save kenwebb/d2eba24950bcd2f40f7bf6a5bf42cf59 to your computer and use it in GitHub Desktop.
Agent Trading
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Sat Aug 31 2024 08:47:38 GMT-0400 (Eastern Daylight Time)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Agent Trading
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: d2eba24950bcd2f40f7bf6a5bf42cf59
Keywords:
My Notes
--------
30 August 2024
In the Island Game, we want to introduce trading and dialogs between and amongst agents.
In this workbook, I explore the various ways of doing this.
- asynchronous messaging (spans two or more time steps
- synchronous messaging (two or more back and forth messages during the same timestep
TODO
- DONE use Interactions, and write out sequence diagrams (MSCs)
https://primordion.com/Xholon/gwt/Xholon.html?app=Agent+Trading&src=lstr&gui=clsc
https://primordion.com/Xholon/gwt/Xholon.html?app=d2eba24950bcd2f40f7bf6a5bf42cf59&src=gist&gui=clsc
### InteractionsViewer
title Agent Trading
To view sequence diagram, paste this text into http://www.websequencediagrams.com/
Created by: Xholon http://www.primordion.com/Xholon/
Date: 1725066161740 Fri Aug 30 21:02:41 GMT-400 2024
tradr_47->tradr_48: 101Aaa sends msg to Bbb
tradr_48->tradr_47: 101[object Object]
tradr_47->tradr_48: 101Aaa sends another ms
tradr_48->tradr_47: 101[object Object]
tradr_47->tradr_48: 102Aaa sends another ms
tradr_48->tradr_47: 102[object Object]
tradr_47->tradr_48: 103Aaa sends another ms
tradr_48->tradr_47: 103[object Object]
tradr_47->tradr_48: 104Aaa sends another ms
tradr_48->tradr_47: 104[object Object]
tradr_47->tradr_48: 105Aaa sends another ms
tradr_48->tradr_47: 105[object Object]
tradr_47->tradr_48: 106Aaa sends another ms
tradr_48->tradr_47: 106[object Object]
tradr_47->tradr_48: 107Aaa sends another ms
tradr_48->tradr_47: 107[object Object]
tradr_47->tradr_48: 108Aaa sends another ms
tradr_48->tradr_47: 108[object Object]
tradr_47->tradr_48: 109Aaa sends another ms
tradr_48->tradr_47: 109[object Object]
]]></Notes>
<_-.XholonClass>
<PhysicalSystem/>
<!-- a Trader exchanges requests, responses, information, objects, etc. with other Traders or trader subtypes -->
<Tradr superClass="Script">
<TrOne/>
<TrTwo/>
</Tradr>
<!-- a convenient spot where traders can congregate to explore trading approaches -->
<TradingStation/>
</_-.XholonClass>
<xholonClassDetails>
<!-- sync bounce messages back and forth in the same timestep until signal >= 110 -->
<Tradr><DefaultContent><![CDATA[
var me, other, signal, beh = {
postConfigure: function() {
me = this.cnode;
other = null;
signal = 101;
},
act: function() {
me.println(`I am tradr ${me.role()}`);
if (me.role() == "Aaa" && other == null) {
other = me.next();
me.println(`other is ${other.name()}`);
response = other.call(signal, "Aaa sends msg to Bbb", me);
me.println(response);
console.log(response);
}
while (me.role() == "Aaa" && signal < 110) {
response = other.call(signal, "Aaa sends another msg to Bbb", me);
response2 = `${me.role()} received response ${response.data.signal} ${response.data.data} from ${response.sender.role()}`;
me.println(response.data.data);
me.println(response2);
console.log(response2);
signal = response.data.signal + 1;
}
},
processReceivedSyncMessage: function(msg) {
var data = msg.data;
me.println(`tradr ${me.role()} has received data: |${msg.signal} ${msg.data}|`);
//return "stuff";
return {signal: msg.signal, data: "stuffin", receiver: msg.sender, sender: me};
}
}
//# sourceURL=Tradr.js
]]></DefaultContent></Tradr>
<!-- async -->
<TrOne><DefaultContent><![CDATA[
var me, beh = {
postConfigure: function() {
me = this.cnode;
me.other = me.xpath("../TrTwo");
me.println(`${me.name()} other is ${me.other.name()}`);
},
act: function() {
me.println(me.name());
me.other.msg(201, "testing 01", me);
},
processReceivedMessage: function(msg) {
me.println(`${me.name()} received msg |${msg.signal} ${msg.data}| from ${msg.sender.name()}`);
}
}
//# sourceURL=TrOne.js
]]></DefaultContent></TrOne>
<!-- async -->
<TrTwo><DefaultContent><![CDATA[
var me, beh = {
postConfigure: function() {
me = this.cnode;
me.other = me.xpath("../TrOne");
me.println(`${me.name()} other is ${me.other.name()}`);
},
act: function() {
me.println(me.name());
me.other.msg(203, "testing 03", me);
},
processReceivedMessage: function(msg) {
me.println(`${me.name()} received msg |${msg.signal} ${msg.data}| from ${msg.sender.name()}`);
}
}
//# sourceURL=TrTwo.js
]]></DefaultContent></TrTwo>
</xholonClassDetails>
<PhysicalSystem>
<TradingStation roleName="BytownMarket">
<Tradr roleName="Aaa"/>
<Tradr roleName="Bbb"/>
</TradingStation>
<TradingStation roleName="NewMall">
<TrOne roleName="Ccc"/>
<TrTwo roleName="Ddd"/>
</TradingStation>
<InteractionsViewer/>
</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>Block</title>
<rect id="PhysicalSystem/TradingStation" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Height</title>
<rect id="PhysicalSystem/TradingStation/Tradr" 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