Actors for Behavioural Simulation

64
Actors for Behavioural Simulation Tony Clark Sheffield Hallam University, UK [email protected] Work in collaboration with: Vinay Kulkarni, Souvik Barat Tata Consultancy Services Research, India [email protected], [email protected] Balbir Barn, Middlesex University, UK [email protected] March 9, 2017

Transcript of Actors for Behavioural Simulation

Page 1: Actors for Behavioural Simulation

Actors for Behavioural Simulation

Tony ClarkSheffield Hallam University, UK

[email protected]

Work in collaboration with:

Vinay Kulkarni, Souvik BaratTata Consultancy Services Research, India

[email protected], [email protected]

Balbir Barn, Middlesex University, [email protected]

March 9, 2017

Page 2: Actors for Behavioural Simulation

System Models

I Goals g : (M1, . . . ,Mk)→ {true, false}Example: Profit is increasing.

I Goals can be decomposed: g1 & g2 ⇒ gExample: Decreasing costs and increasing sales produceincreasing profit.

I Measures m : ([V1], . . . , [Vn])→ MExample: Profit is calculated in terms of costs and sales overtime.

I Properties p : N → VExample: Costs at a given time.

I System structures: ({g1, . . .}, {m1, . . .}, {p1 . . .})Problem: How to construct these structures?

Page 3: Actors for Behavioural Simulation

System Models

I Goals g : (M1, . . . ,Mk)→ {true, false}Example: Profit is increasing.

I Goals can be decomposed: g1 & g2 ⇒ gExample: Decreasing costs and increasing sales produceincreasing profit.

I Measures m : ([V1], . . . , [Vn])→ MExample: Profit is calculated in terms of costs and sales overtime.

I Properties p : N → VExample: Costs at a given time.

I System structures: ({g1, . . .}, {m1, . . .}, {p1 . . .})Problem: How to construct these structures?

Page 4: Actors for Behavioural Simulation

System Models

I Goals g : (M1, . . . ,Mk)→ {true, false}Example: Profit is increasing.

I Goals can be decomposed: g1 & g2 ⇒ gExample: Decreasing costs and increasing sales produceincreasing profit.

I Measures m : ([V1], . . . , [Vn])→ MExample: Profit is calculated in terms of costs and sales overtime.

I Properties p : N → VExample: Costs at a given time.

I System structures: ({g1, . . .}, {m1, . . .}, {p1 . . .})Problem: How to construct these structures?

Page 5: Actors for Behavioural Simulation

System Models

I Goals g : (M1, . . . ,Mk)→ {true, false}Example: Profit is increasing.

I Goals can be decomposed: g1 & g2 ⇒ gExample: Decreasing costs and increasing sales produceincreasing profit.

I Measures m : ([V1], . . . , [Vn])→ MExample: Profit is calculated in terms of costs and sales overtime.

I Properties p : N → VExample: Costs at a given time.

I System structures: ({g1, . . .}, {m1, . . .}, {p1 . . .})Problem: How to construct these structures?

Page 6: Actors for Behavioural Simulation

System Models

I Goals g : (M1, . . . ,Mk)→ {true, false}Example: Profit is increasing.

I Goals can be decomposed: g1 & g2 ⇒ gExample: Decreasing costs and increasing sales produceincreasing profit.

I Measures m : ([V1], . . . , [Vn])→ MExample: Profit is calculated in terms of costs and sales overtime.

I Properties p : N → VExample: Costs at a given time.

I System structures: ({g1, . . .}, {m1, . . .}, {p1 . . .})Problem: How to construct these structures?

Page 7: Actors for Behavioural Simulation

Simulations and Decision Support

Page 8: Actors for Behavioural Simulation

System Dynamics

https://commons.wikimedia.org/w/index.php?curid=7240226(Patrhoue)

Page 9: Actors for Behavioural Simulation

Incremental Decision Making: A Requirement for Search

Page 10: Actors for Behavioural Simulation

Carnegie: Incompleteness and Sense Making

Page 11: Actors for Behavioural Simulation

Simulation Approaches

Page 12: Actors for Behavioural Simulation

Simulation Method

Page 13: Actors for Behavioural Simulation

A Computational Basis for Simulation

Page 14: Actors for Behavioural Simulation

ESL Architecture

Page 15: Actors for Behavioural Simulation

The ESL Language: Factorial

type Customer = Act { Value( I n t ) };type Fact = Act{ Get( Int ,Customer) };

act fact ::Fact {Get(0,c ::Customer) → c ← Value (1);Get(n :: Int ,c ::Customer) →

l e t cc ::Customer = new cust(n,c)i n s e l f ← Get(n-1,cc)

}

act cust(n :: Int ,c ::Customer) ::Customer {Value(m :: I n t ) c ← Value(n*m)

}

act main ::Customer {f ::Fact = new fact;computeFact(n :: I n t ) ::Void = f ← Get(n, s e l f );→ {

computeFact (6);computeFact (6);computeFact (6)

}Value(n :: I n t ) → print[ I n t ](n)

}

Page 16: Actors for Behavioural Simulation

Visualization

Page 17: Actors for Behavioural Simulation

The ESL Language: Dining Philosophers

eat() ::Void = f o r x :: I n t i n 0.. random(eatTime) do {}think() ::Void = f o r x :: I n t i n 0.. random(thinkTime) do {}

act philosopher(i :: Int ,left ,right ::Chopstick) ::Philosopher {Time(n :: I n t ) when n < timeLimit → {

think();grab (left.active ,right.active) {

eat()}

}}act chop ::Chopstick {

expor t active;active ::Bool = false

}

chops ::[Chopstick] = [ new chop | i :: I n t ← 0..(max -1) ];

philosophers ::[Philosopher] =[ new philosopher(i,nth(chops ,i),nth(chops ,(i+1)%max)) |

i :: I n t ← 0..(max -1) ];

act main ::Main {Time(n :: I n t ) when n > timeLimit → {

edb ← Filmstrip(’Philosophers ’,getFilmstrip ());stopAll ()

}}

Page 18: Actors for Behavioural Simulation

Philosopher Histories

Page 19: Actors for Behavioural Simulation

Traffic and Adaptive Behaviour

Nils Bulling, Mehdi Dastani, and Max Knobbout. Monitoring Norm

Violations in Multi-Agent Systems. International Foundation for

Autonomous Agents and Multiagent Systems, 2013.

Page 20: Actors for Behavioural Simulation

The ESL Language: Traffic Monitors

act light(colour ::Str ) ::TrafficLight {expor t colour , change;change () ::Void =

case colour {’RED ’ → colour := ’GREEN ’;’GREEN ’ → colour := ’RED ’

}}

act approach(id ::Str ,light ::TrafficLight ,isCar :: I n t ) ::Approach {cars :: I n t = 0;Move →

i f light.colour=’GREEN ’ and cars >0 then s e l f ← DeQueue;DeQueue →

cars := cars - 1;Queue →

cars := cars + 1Time(n :: I n t ) →

probab ly (isCar) s e l f ← Queue e l s e s e l f ← Move};

l1 ::TrafficLight = new light(’RED ’);l2 ::TrafficLight = new light(’GREEN ’);left ::Approach = new approach(’left ’,l1 ,10);right ::Approach = new approach(’right ’,l2 ,20);

westEast ()= i f l2.colour=’RED ’ then {l2.change ();l1.change ()}eastWest ()= i f l1.colour=’RED ’ then {l1.change ();l2.change ()}

Page 21: Actors for Behavioural Simulation

Traffic Filmstrip

Prioritise East West

Page 22: Actors for Behavioural Simulation

Traffic Filmstrip

West East If Nothing Waiting

Page 23: Actors for Behavioural Simulation

Traffic Filmstrip

West East Must Not Build Up

Page 24: Actors for Behavioural Simulation

Traffic Filmstrip

Back to Equilibrium

Page 25: Actors for Behavioural Simulation

Monitor Actors

Page 26: Actors for Behavioural Simulation

Monitor Actors

Page 27: Actors for Behavioural Simulation

Monitor Actors

Page 28: Actors for Behavioural Simulation

Monitor Actors

Page 29: Actors for Behavioural Simulation

Monitor Language

p,q ::= monitors.n a named monitor.

| ε holds for any history.| 2(p) holds when p holds at all times.| µ(λ(n)p) recursive definitions: [µ(λ(n)p)/n]p| p;q holds when p and q both hold now.| p|q holds when p or q (or both) holds now.| p ⊕ q holds when p or q (not both) holds now.| p ⇒ q if p holds then q must hold now.| N(p) holds when p holds for time now + 1.| P(p) holds when p holds for time now - 1.| ?(c) holds when the condition c is true now.| ! (a) always holds and performs action a.| p ↑ q splits two merged histories.| p ↓ q (re)merges two split histories.

Actors controlled by monitor rules: p ⇒ !(a)

Tony Clark, Vinay Kulkarni, Souvik Barat, Balbir Barn. Actor Monitors

for Adaptive Behaviour. ISEC 2017. pp. 85--95

Page 30: Actors for Behavioural Simulation

Traffic Monitor

1P0(p) = p2Pn(p) = p;P(Pn-1(p))3

42(PmaxQDuration(?(gre(maxQSize))) ↑ ε ⇒ ! (westEast) ⊕5

6ε ↑ ?(gre(0)) ⇒ ! (eastWest) ⊕7

8?(gre(0)) ↑ ε ⇒ ! (westEast) ⊕9

10ε)

Page 31: Actors for Behavioural Simulation

ESL Monitor Types

type Mtd[T] = Act {export history ::[T];Time( I n t )

}

data Tree[T] = Leaf(T) | Pair(Tree[T],Tree[T])

data MTree[T] = Tree(Mtd[T])

history[T](t ::MTree[T]) ::Tree[[T]] =case t {

Leaf(a ::Mtd[T]) → Leaf(a.history);Pair(left ::MTree[T],right ::MTree[T]) →

Pair(history[T](left),history[T](right))}

type Fail = () → Void

type Mtr[T] = rec M. Act {Check(Mtd[T], Int ,M,Fail);Time( I n t )

}

Page 32: Actors for Behavioural Simulation

ESL Monitor Definitions

act ε [T] ::Mtr[T] {

Check(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →s ← Check(a,c, s e l f ,f)

}

idle[T] ::Mtr[T] = new nothing[T]()

Page 33: Actors for Behavioural Simulation

ESL Monitor Definitions

act ! [T]( command ::() → Void) ::Mtr[T] {

Check(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →{

command ();

s ← Check(a,c,idle[T],f)

}

}

Page 34: Actors for Behavioural Simulation

ESL Monitor Definitions

act (_;_)[T](p ::Mtr[T],q ::Mtr[T]) ::Mtr[T] {Check(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →

p ← Check(a,c,new (q;s),f)}

act (_⊕_)[T](p ::Mtr[T],q ::Mtr[T]) ::Mtr[T] {Check(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →

p ← Check(a,c,s,λ() ::Void q ← Check(a,c,s,f))}

act (_|_)[T](p ::Mtr[T],q ::Mtr[T]) ::Mtr[T] {Check(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) → {

p ← Check(a,c,s,f);q ← Check(a,c,s,f)

}}

Page 35: Actors for Behavioural Simulation

ESL Monitor Definitions

minLength[T](t ::Tree[T]) :: I n t =case t {

Leaf(l ::[T]) → length[T](l);Pair(left ::Tree[T],right ::Tree[T]) →

min(minLength[T](left),minLength[T]( right))}

treeNth[T](t ::Tree[T],n :: I n t ) ::Tree[T] =case t {

Leaf(l ::[T]) → nth[T](l,n);Pair(left ::Tree[T],right ::Tree[T]) →

Pair(treeNth[T](left ,n),treeNth[T](right ,n))}

act ?[T](pred ::(Tree[T]) → Bool) ::Mtr[T] {Check(t ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →

i f minLength[T]( history(t)) > cthen {

i f pred(treeNth[T]( history(t),c))then s ← Check(t,c,idle[T],f)e l s e f()

} e l s e s e l f ← Check(t,c,s,f)}

Page 36: Actors for Behavioural Simulation

ESL Monitor Definitions

act µ[T](g ::(Mtr[T]) → Mtr[T]) ::Mtr[T] {Check(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →

g(new rec [T](g)) ← Check(a,c,s,f)}

2[T](p ::Mtr[T]) ::Mtr[T] =new µ[T](λ(q ::Mtr[T]) ::Mtr[T]

new seq[T](p,new N[T](q)))

act N[T](p ::Mtr[T]) ::Mtr[T] {Check(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →

p ← Check(a,c+1,s,f)}

act P[T](p ::Mtr[T]) ::Mtr[T] {Check(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →

p ← Check(a,c-1,s,f)}

act (_ ⇒ _)[T](p ::Mtr[T],q ::Mtr[T]) ::Mtr[T] =Check(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →

p ← Check(a,c,new (q;s),λ() ::Void s ← Check(a,c,idle[T],f)

}

Page 37: Actors for Behavioural Simulation

ESL Monitor Definitions

act (_↑_)[T](p ::Mtr[T],q ::Mtr[T]) ::Mtr[T] {Check(t ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →

case t {Pair[T](t1 ::MTree[T],t2 ::MTree[T]) →

l e t j ::Mtr[T] = new (t1 ↓ t2)i n {

p ← Check(t1,c,j,f);q ← Check(t2,c,j,f)

}}

}

act (_↓_)[T](t1 ::MTree[T],t2 ::MTree[T]) ::Mtr[T]{done ::Bool = falseCheck(a ::MTree[T],c :: Int ,s ::Mtr[T],f ::Fail) →

i f not(done)then done := truee l s e s ← Check(Pair(t1,t2),c,s,f)

}

Page 38: Actors for Behavioural Simulation

Traffic Sequence Diagram

Page 39: Actors for Behavioural Simulation

Shopping Simulation

Peer-Olaf Siebers and Uwe Aickelin. A first approach on modelling staff

proactiveness in retail simulation models. J. Artificial Societies and

Social Simulation, 14(2), 2011.

Page 40: Actors for Behavioural Simulation

Actor Structure Models: Shop Simulation

Page 41: Actors for Behavioural Simulation

Actor Behaviour Models: Customer

Page 42: Actors for Behavioural Simulation

Visualisation of Results

Simulation execution produces a history.

Page 43: Actors for Behavioural Simulation

History Query Language

rule ::= fact ← element , . . .element ::=

fact

| acto r (id,behaviour ,time)| send(source ,target ,message ,time)| s t a t e (id,name ,value ,time)| next [element]| prev [element]| always [element]| e v en t ua l l y [element]| past [element]| s t a r t| end| f o r a l l [element ](value ,value)

Page 44: Actors for Behavioural Simulation

Query Language: Typed Relational Programming

append[T] :: ([T],[T],[T]);

append[T]([],l,l) ← !;

append[T]([x|l1],l2 ,[x|l3]) ←append[T](l1,l2 ,l3);

length[T] :: ([T], I n t );

length[T]([] ,0);

length[T]([_ | l],n) ←length[T](l,m),

n := m + 1;

Page 45: Actors for Behavioural Simulation

Query Language: Processing Histories

allActors :: ([Actor( Int ,Str )]);

allActors ([]) ← end, !;

allActors(actors) ←f o r a l l [ acto r (id,beh ,_)](Actor(id ,beh),actors ’),next [allActors(actors ’’)],append[Actor( Int ,Str )](actors ’,actors ’’,actors);

customers :: ([ I n t ]);

customers(cs) ←f o r a l l [ e v en t ua l l y [ acto r (a,’customer ’,_)]](a,cs);

Page 46: Actors for Behavioural Simulation

Query Language: Customers With No Sales

noSales :: ([ I n t ]);noSales(cs ’’) ←

customers(cs),makesPurchase(cs ,cs ’),removeAll[ I n t ](cs’,cs,cs ’’);

makesPurchase :: ([ I n t ],[ I n t ]);makesPurchase ([] ,[]);

makesPurchase ([c | cs],[c | cs ’]) ←makePurchase(c), !,makesPurchase(cs ,cs ’);

makesPurchase ([_ | cs],cs ’) ←makesPurchase(cs ,cs ’);

makePurchase :: ( I n t );makePurchase(c) ←

e v en t ua l l y [ send(_,c,SaleConcluded ,_)];

Page 47: Actors for Behavioural Simulation

Query Language: Detecting Raids

raid :: ([ I n t ],union { NoRaid (), Raid([ I n t ])});

raid(assistants ,Raid(times ’)) ←f o r a l l [ // get the assistant actors . . .

e v en t ua l l y [ acto r (a,’assistant ’,_)]](a,assistants),f o r a l l [ // times when they are all occupied . . .

e v en t ua l l y [allHelping(assistants ,time)]](time ,times), !;

raid([], NoRaid);

allHelping ::([ I n t ],[ I n t ]);

allHelping ([],_);

allHelping ([a|as],t) ←s t a t e (a,’advising ’,Ref(_),t),allHelping(as,_);

Page 48: Actors for Behavioural Simulation
Page 49: Actors for Behavioural Simulation
Page 50: Actors for Behavioural Simulation
Page 51: Actors for Behavioural Simulation
Page 52: Actors for Behavioural Simulation
Page 53: Actors for Behavioural Simulation
Page 54: Actors for Behavioural Simulation
Page 55: Actors for Behavioural Simulation
Page 56: Actors for Behavioural Simulation
Page 57: Actors for Behavioural Simulation
Page 58: Actors for Behavioural Simulation
Page 59: Actors for Behavioural Simulation
Page 60: Actors for Behavioural Simulation
Page 61: Actors for Behavioural Simulation
Page 62: Actors for Behavioural Simulation
Page 63: Actors for Behavioural Simulation

Selected Publications

I Tony Clark, Vinay Kulkarni, Souvik Barat, Balbir Barn: Actor Monitors for Adaptive

Behaviour. Proceedings of the 10th Innovations in Software Engineering Conference, ISEC

2017: 85-95

I Souvik Barat, Vinay Kulkarni, Tony Clark, and Balbir Barn. A Simulation-based Aid for

Organisational Decision-making.In Proceedings of the 11th International Joint Conference

on Software Technologies. 2016.

I Souvik Barat, Vinay Kulkarni, Tony Clark, Balbir Barn: Enterprise Modeling as a Decision

Making Aid: A Systematic Mapping Study. PoEM 2016: 289-298

I Vinay Kulkarni, Souvik Barat, Tony Clark, and Balbir Barn. Toward overcoming accidental

complexity in organisational decision-making. In Model Driven Engineering Languages and

Systems (MODELS), 2015 ACM/IEEE 18th International Conference on, pages 368-377. IEEE,

2015.

I Vinay Kulkarni, Souvik Barat, Tony Clark, Balbir Barn: A Wide-Spectrum Approach to

Modelling and Analysis of Organisation for Machine-Assisted Decision-Making. EOMAS@CAiSE

2015: 87-101

I Vinay Kulkarni, Souvik Barat, Tony Clark, Balbir Barn: Using simulation to address

intrinsic complexity in multi-modelling of enterprises for decision making. SummerSim

2015: 9:1-9:11

I Balbir Barn, Tony Clark, and Vinay Kulkarni. Can organisational theory and multi-agent

systems influence next generation enterprise modelling? In International Conference on

Software Technologies, pages 202-216. Springer, 2014.

I Vinay Kulkarni, Tony Clark, Souvik Barat, Balbir Barn: Model Based Enterprise Simulation

and Analysis - A Pragmatic Approach Reducing the Burden on Experts. ER Workshops 2014:

3-12

Page 64: Actors for Behavioural Simulation

Get Involved

http://tonyclark.github.io/ESL/