From 5043dd13fd63d5328e0843bb616a7e2a878ad5a8 Mon Sep 17 00:00:00 2001 From: AlexZangerle Date: Mon, 19 Jan 2026 12:56:11 +0100 Subject: [PATCH 1/4] feat: add chameneos example --- chameneos/chameneos.pkl | 53 +++++++++++++++++++++++++++++++++++++++++ chameneos/main.pkl | 14 +++++++++++ chameneos/mall.pkl | 53 +++++++++++++++++++++++++++++++++++++++++ chameneos/services.pkl | 4 ++++ 4 files changed, 124 insertions(+) create mode 100644 chameneos/chameneos.pkl create mode 100644 chameneos/main.pkl create mode 100644 chameneos/mall.pkl create mode 100644 chameneos/services.pkl diff --git a/chameneos/chameneos.pkl b/chameneos/chameneos.pkl new file mode 100644 index 0000000..8c4e0e2 --- /dev/null +++ b/chameneos/chameneos.pkl @@ -0,0 +1,53 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +sm = new csml.StateMachine { + transient { + ["chameneosId"] = "std:getUniqueId()" + ["color"] = "std:getRandomColor()" + ["individualMeetingCounter"] = "0" + } + states { + ["requestingPartner"] = new csml.Initial { + entry { + new csml.Raise { + event = new csml.Global { + topic = "requestingPartner" + data { ["chameneosId"] = "chameneosId"; ["chameneosColor"] = "color" } + } + } + } + on { + ["matchMade"] = new csml.Transition { + to = "matchFound" + iif = "$chameneos == chameneosId" + } + ["change"] = new csml.Transition { + to = "requestingPartner" + iif = "$partner == chameneosId" + do { + new csml.Eval { expression = "color = std:complement(color, $color)" } + new csml.Eval { expression = "individualMeetingCounter = individualMeetingCounter + 1" } + } + } + ["done"] = new csml.Transition { + to = "done" + } + } + } + ["matchFound"] = new csml.State { + entry { + new csml.Eval { expression = "color = std:complement(color, $color)" } + new csml.Eval { expression = "individualMeetingCounter = individualMeetingCounter + 1" } + new csml.Raise { + event = new csml.Global { + topic = "change" + data { ["partner"] = "$partner"; ["color"] = "color" } + } + } + } + always { new csml.Transition { to = "requestingPartner" } } + } + ["done"] = new csml.Terminal {} + } +} diff --git a/chameneos/main.pkl b/chameneos/main.pkl new file mode 100644 index 0000000..cf5bda8 --- /dev/null +++ b/chameneos/main.pkl @@ -0,0 +1,14 @@ +amends + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +import "chameneos.pkl" +import "defs.pkl" +import "mall.pkl" + +version = "4.0.0" +stateMachines { + ["mall"] = mall.sm + for (_def in defs.chameneos) { + [_def] = chameneos.sm + } +} diff --git a/chameneos/mall.pkl b/chameneos/mall.pkl new file mode 100644 index 0000000..283863b --- /dev/null +++ b/chameneos/mall.pkl @@ -0,0 +1,53 @@ +import + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + +sm = new csml.StateMachine { + transient { + ["waitingList"] = "[...]" + ["meetingCounter"] = "0" + } + states { + ["waitingForChameneos"] = new csml.Initial { + on { + ["requestingPartner"] = new csml.Transition { + to = "waitingForChameneos" + iif = "waitingList.isEmpty() && meetingCounter < 1000000" + do { + new csml.Eval { + expression = "waitingList = std:addToList(\("waitingList"), $chameneosId)" + } + } + or = "scheduleMeeting" + } + } + } + ["scheduleMeeting"] = new csml.State { + always { + new csml.Transition { + to = "waitingForChameneos" + iif = "!waitingList.isEmpty() && meetingCounter < 1000000" + do { + new csml.Eval { expression = "meetingCounter = meetingCounter + 1" } + new csml.Raise { + event = new csml.Global { + topic = "matchMade" + data { + ["chameneos"] = "waitingList.get(0)" + ["partner"] = "$chameneosId" + ["color"] = "$chameneosColor" + } + } + } + new csml.Eval { expression = "waitingList = std:removeFirst(\("waitingList"))" } + } + or = "done" + } + } + } + ["done"] = new csml.Terminal { + entry { + new csml.Raise { event = new csml.Global { topic = "done" } } + } + } + } +} diff --git a/chameneos/services.pkl b/chameneos/services.pkl new file mode 100644 index 0000000..07c151f --- /dev/null +++ b/chameneos/services.pkl @@ -0,0 +1,4 @@ +amends + "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" + +bindings {} From 9eb063ba8f3326ed4a5241da2e727ccf9001fcfa Mon Sep 17 00:00:00 2001 From: AlexZangerle Date: Wed, 28 Jan 2026 11:00:35 +0100 Subject: [PATCH 2/4] fix: remove use of std functions from chameneos example --- chameneos/chameneos.pkl | 23 +++++++++++++++++------ chameneos/defs.pkl | 8 ++++++++ chameneos/main.pkl | 4 ++-- chameneos/mall.pkl | 8 ++++---- 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 chameneos/defs.pkl diff --git a/chameneos/chameneos.pkl b/chameneos/chameneos.pkl index 8c4e0e2..3559263 100644 --- a/chameneos/chameneos.pkl +++ b/chameneos/chameneos.pkl @@ -1,10 +1,15 @@ import "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" -sm = new csml.StateMachine { +import "defs.pkl" + +function complement(myColor: String, otherColor: String): String = + defs.colorComplementMap[myColor][otherColor] + +function createChameneos(id: Int) = new csml.StateMachine { transient { - ["chameneosId"] = "std:getUniqueId()" - ["color"] = "std:getRandomColor()" + ["chameneosId"] = "\(id)" + ["color"] = "std:takeRandom([1,2,3,...])" ["individualMeetingCounter"] = "0" } states { @@ -26,7 +31,10 @@ sm = new csml.StateMachine { to = "requestingPartner" iif = "$partner == chameneosId" do { - new csml.Eval { expression = "color = std:complement(color, $color)" } + new csml.Eval { + expression = + "color = (function (x,y) { if (x == y) {x} else {x ^ y} })(color, $color)" + } new csml.Eval { expression = "individualMeetingCounter = individualMeetingCounter + 1" } } } @@ -37,7 +45,6 @@ sm = new csml.StateMachine { } ["matchFound"] = new csml.State { entry { - new csml.Eval { expression = "color = std:complement(color, $color)" } new csml.Eval { expression = "individualMeetingCounter = individualMeetingCounter + 1" } new csml.Raise { event = new csml.Global { @@ -45,8 +52,12 @@ sm = new csml.StateMachine { data { ["partner"] = "$partner"; ["color"] = "color" } } } + + new csml.Eval { + expression = "color = (function (x,y) { if (x == y) {x} else {x ^ y} })(color, $color)" + } } - always { new csml.Transition { to = "requestingPartner" } } + always { new csml.Transition { to = "requestingPartner"; iif = "color < 4"; or = "done" } } } ["done"] = new csml.Terminal {} } diff --git a/chameneos/defs.pkl b/chameneos/defs.pkl new file mode 100644 index 0000000..65d735c --- /dev/null +++ b/chameneos/defs.pkl @@ -0,0 +1,8 @@ +chameneos = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) + +colorComplementMap = + Map( + "RED", Map("RED", "RED", "YELLOW", "BLUE", "BLUE", "YELLOW"), + "YELLOW", Map("RED", "BLUE", "YELLOW", "YELLOW", "BLUE", "RED"), + "BLUE", Map("RED", "YELLOW", "YELLOW", "RED", "BLUE", "RED") + ) diff --git a/chameneos/main.pkl b/chameneos/main.pkl index cf5bda8..01777ba 100644 --- a/chameneos/main.pkl +++ b/chameneos/main.pkl @@ -8,7 +8,7 @@ import "mall.pkl" version = "4.0.0" stateMachines { ["mall"] = mall.sm - for (_def in defs.chameneos) { - [_def] = chameneos.sm + for (c in defs.chameneos) { + [c.toString()] = chameneos.createChameneos(c) } } diff --git a/chameneos/mall.pkl b/chameneos/mall.pkl index 283863b..b22c650 100644 --- a/chameneos/mall.pkl +++ b/chameneos/mall.pkl @@ -11,10 +11,10 @@ sm = new csml.StateMachine { on { ["requestingPartner"] = new csml.Transition { to = "waitingForChameneos" - iif = "waitingList.isEmpty() && meetingCounter < 1000000" + iif = "waitingList.isEmpty() && meetingCounter < 20000" do { new csml.Eval { - expression = "waitingList = std:addToList(\("waitingList"), $chameneosId)" + expression = "waitingList = waitingList + [$chameneosId]" } } or = "scheduleMeeting" @@ -25,7 +25,7 @@ sm = new csml.StateMachine { always { new csml.Transition { to = "waitingForChameneos" - iif = "!waitingList.isEmpty() && meetingCounter < 1000000" + iif = "!waitingList.isEmpty() && meetingCounter < 20000" do { new csml.Eval { expression = "meetingCounter = meetingCounter + 1" } new csml.Raise { @@ -38,7 +38,7 @@ sm = new csml.StateMachine { } } } - new csml.Eval { expression = "waitingList = std:removeFirst(\("waitingList"))" } + new csml.Eval { expression = "waitingList = waitingList - [waitingList.get(0)]" } } or = "done" } From 7039ba067a0bb105826da4d431369498c2d70f4f Mon Sep 17 00:00:00 2001 From: AlexZangerle Date: Thu, 29 Jan 2026 09:46:32 +0100 Subject: [PATCH 3/4] fix: optimize evals in chameneos example --- chameneos/chameneos.pkl | 6 +++--- chameneos/mall.pkl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/chameneos/chameneos.pkl b/chameneos/chameneos.pkl index 3559263..0e1313d 100644 --- a/chameneos/chameneos.pkl +++ b/chameneos/chameneos.pkl @@ -35,7 +35,7 @@ function createChameneos(id: Int) = new csml.StateMachine { expression = "color = (function (x,y) { if (x == y) {x} else {x ^ y} })(color, $color)" } - new csml.Eval { expression = "individualMeetingCounter = individualMeetingCounter + 1" } + new csml.Eval { expression = "++individualMeetingCounter" } } } ["done"] = new csml.Transition { @@ -45,7 +45,7 @@ function createChameneos(id: Int) = new csml.StateMachine { } ["matchFound"] = new csml.State { entry { - new csml.Eval { expression = "individualMeetingCounter = individualMeetingCounter + 1" } + new csml.Eval { expression = "++individualMeetingCounter" } new csml.Raise { event = new csml.Global { topic = "change" @@ -57,7 +57,7 @@ function createChameneos(id: Int) = new csml.StateMachine { expression = "color = (function (x,y) { if (x == y) {x} else {x ^ y} })(color, $color)" } } - always { new csml.Transition { to = "requestingPartner"; iif = "color < 4"; or = "done" } } + always { new csml.Transition { to = "requestingPartner" } } } ["done"] = new csml.Terminal {} } diff --git a/chameneos/mall.pkl b/chameneos/mall.pkl index b22c650..5b6134e 100644 --- a/chameneos/mall.pkl +++ b/chameneos/mall.pkl @@ -14,7 +14,7 @@ sm = new csml.StateMachine { iif = "waitingList.isEmpty() && meetingCounter < 20000" do { new csml.Eval { - expression = "waitingList = waitingList + [$chameneosId]" + expression = "waitingList += [$chameneosId]" } } or = "scheduleMeeting" @@ -27,7 +27,7 @@ sm = new csml.StateMachine { to = "waitingForChameneos" iif = "!waitingList.isEmpty() && meetingCounter < 20000" do { - new csml.Eval { expression = "meetingCounter = meetingCounter + 1" } + new csml.Eval { expression = "++meetingCounter" } new csml.Raise { event = new csml.Global { topic = "matchMade" @@ -38,7 +38,7 @@ sm = new csml.StateMachine { } } } - new csml.Eval { expression = "waitingList = waitingList - [waitingList.get(0)]" } + new csml.Eval { expression = "waitingList -= [waitingList.get(0)]" } } or = "done" } From 174ab436cc333bbeb708b52931775c4989121a29 Mon Sep 17 00:00:00 2001 From: AlexZangerle Date: Sun, 1 Feb 2026 13:45:42 +0100 Subject: [PATCH 4/4] feat: update chameneos example --- chameneos/chameneos.pkl | 15 ++++----------- chameneos/defs.pkl | 8 +------- chameneos/main.pkl | 23 +++++++++++++++++++---- chameneos/mall.pkl | 4 ++-- chameneos/services.pkl | 2 +- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/chameneos/chameneos.pkl b/chameneos/chameneos.pkl index 0e1313d..ce36e8a 100644 --- a/chameneos/chameneos.pkl +++ b/chameneos/chameneos.pkl @@ -1,14 +1,8 @@ import - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" -import "defs.pkl" - -function complement(myColor: String, otherColor: String): String = - defs.colorComplementMap[myColor][otherColor] - -function createChameneos(id: Int) = new csml.StateMachine { +sm = new csml.StateMachine { transient { - ["chameneosId"] = "\(id)" ["color"] = "std:takeRandom([1,2,3,...])" ["individualMeetingCounter"] = "0" } @@ -25,11 +19,9 @@ function createChameneos(id: Int) = new csml.StateMachine { on { ["matchMade"] = new csml.Transition { to = "matchFound" - iif = "$chameneos == chameneosId" } ["change"] = new csml.Transition { to = "requestingPartner" - iif = "$partner == chameneosId" do { new csml.Eval { expression = @@ -49,8 +41,9 @@ function createChameneos(id: Int) = new csml.StateMachine { new csml.Raise { event = new csml.Global { topic = "change" - data { ["partner"] = "$partner"; ["color"] = "color" } + data { ["color"] = "color" } } + target = "$partner" } new csml.Eval { diff --git a/chameneos/defs.pkl b/chameneos/defs.pkl index 65d735c..0f3ebe5 100644 --- a/chameneos/defs.pkl +++ b/chameneos/defs.pkl @@ -1,8 +1,2 @@ -chameneos = List(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) +chameneos = List("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven") -colorComplementMap = - Map( - "RED", Map("RED", "RED", "YELLOW", "BLUE", "BLUE", "YELLOW"), - "YELLOW", Map("RED", "BLUE", "YELLOW", "YELLOW", "BLUE", "RED"), - "BLUE", Map("RED", "YELLOW", "YELLOW", "RED", "BLUE", "RED") - ) diff --git a/chameneos/main.pkl b/chameneos/main.pkl index 01777ba..f35ae77 100644 --- a/chameneos/main.pkl +++ b/chameneos/main.pkl @@ -1,14 +1,29 @@ amends - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" import "chameneos.pkl" import "defs.pkl" import "mall.pkl" version = "4.0.0" -stateMachines { - ["mall"] = mall.sm +collaborativeStateMachine { + stateMachines { + ["mall"] = mall.sm + ["chameneos"] = chameneos.sm + } +} +instantiate { + ["mall"] = "mall" + for (c in defs.chameneos) { + [c] = "chameneos" + } +} +instanceData { for (c in defs.chameneos) { - [c.toString()] = chameneos.createChameneos(c) + [c] { + ["chameneosId"] = "'\(c)'" + } } } + +instanceSubscriptions {} diff --git a/chameneos/mall.pkl b/chameneos/mall.pkl index 5b6134e..fe3eb81 100644 --- a/chameneos/mall.pkl +++ b/chameneos/mall.pkl @@ -1,5 +1,5 @@ import - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/csml.pkl" sm = new csml.StateMachine { transient { @@ -32,11 +32,11 @@ sm = new csml.StateMachine { event = new csml.Global { topic = "matchMade" data { - ["chameneos"] = "waitingList.get(0)" ["partner"] = "$chameneosId" ["color"] = "$chameneosColor" } } + target = "waitingList.get(0)" } new csml.Eval { expression = "waitingList -= [waitingList.get(0)]" } } diff --git a/chameneos/services.pkl b/chameneos/services.pkl index 07c151f..7459387 100644 --- a/chameneos/services.pkl +++ b/chameneos/services.pkl @@ -1,4 +1,4 @@ amends - "https://raw.githubusercontent.com/CollaborativeStateMachines/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" + "https://raw.githubusercontent.com/Frnd-me/Cirrina/refs/heads/develop/src/main/resources/pkl/csm/bindings.pkl" bindings {}