+ All Categories
Home > Science > Simulating Large-scale Aggregate MASs with Alchemist and Scala

Simulating Large-scale Aggregate MASs with Alchemist and Scala

Date post: 14-Apr-2017
Category:
Upload: danilo-pianini
View: 220 times
Download: 0 times
Share this document with a friend
40
Simulating Large-scale Aggregate MASs with Alchemist and Scala Roberto Casadei, Danilo Pianini , Mirko Viroli [email protected] {danilo.pianini, mirko.viroli}@unibo.it Alma Mater Studiorum—Universit` a di Bologna 10th International Workshop on Multi-Agent Systems and Simulation (MAS&S’16) September 14th, 2016 - Gdansk, Poland Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 1 / 30
Transcript
Page 1: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Simulating Large-scale Aggregate MASs with Alchemistand Scala

Roberto Casadei, Danilo Pianini, Mirko [email protected]

{danilo.pianini, mirko.viroli}@unibo.it

Alma Mater Studiorum—Universita di Bologna

10th International Workshop on Multi-Agent Systems and Simulation (MAS&S’16)September 14th, 2016 - Gdansk, Poland

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 1 / 30

Page 2: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Outline

1 Context and Motivation

2 Aggregate ProgrammingBasicsIn Scala

3 Alchemist

4 Example

5 Conclusion

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 2 / 30

Page 3: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Context and Motivation

Outline

1 Context and Motivation

2 Aggregate ProgrammingBasicsIn Scala

3 Alchemist

4 Example

5 Conclusion

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 3 / 30

Page 4: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Context and Motivation

Context: large scale situated systems

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 3 / 30

Page 5: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Context and Motivation

Motivation

Questions

What would be the single agent goal / plan / program?

How can we link agent behaviour with overall global effect?

Can we reach predictable levels of resiliency?

Which methods can support reuse and compositional behaviours?

A proper computational model

Hides complexity under the hood

Allows for describing the problem, not “hacking a solution”

A paradigm shift

Provide means for the designer to reason in terms of aggregate, ratherthan single agents

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 4 / 30

Page 6: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming

Outline

1 Context and Motivation

2 Aggregate ProgrammingBasicsIn Scala

3 Alchemist

4 Example

5 Conclusion

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 5 / 30

Page 7: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming Basics

Aggregate programming

Atomic manipulations of computational fields: a map Space ⇒ Value

neighborhood

device

Based on programming languages rather than frameworks

Complexity is offloaded to compilers and interpreters

Compositional by designBased on Field Calculus (functional with higher order)

Computational-round based modelClear operational semanticsMathematical proofs about soundness, consistency, type systems...

Novel abstractions, low level mechanisms ⇒ steep learning curve

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 5 / 30

Page 8: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

Scala

An attempt to address shortcomings and criticisms of Java

General purpose, multi-paradigm language

Very strong static typing

Compiles in JVM bytecode

Java interoperable

Nice support to DSL definition

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 6 / 30

Page 9: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

Basic constructs

trait Constructs {// Evolution over time (maintain state over rounds)def rep[A](init: A)(fun: (A) => A): A

// Share and gather information from neighborhooddef nbr[A](expr: => A): Adef foldhood[A](init: => A)(acc: (A,A)=>A)(expr: => A): A

// Domain restrictiondef branch[A](cond: => Boolean)(th: => A)(el: => A): A

// Access local and neighborhood sensorsdef sense[A](name: LSNS): Adef nbrvar[A](name: NSNS): A

}

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 7 / 30

Page 10: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

How it works: apply functions over fields

e(0, 1)

()0

1

+-

1-1

(ef 0 1)

ef

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 8 / 30

Page 11: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

How it works: evolution over time

rep(0) { x => x + 1 }

rep

0

(fun (x) (+ x 1))t

v0

t

v1

..(rep x 0 (+ x 1))

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 9 / 30

Page 12: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

How it works: gather data from neighborhood

nbr{ e }

nbr de

(nbr e)

φd=[d1→v1,..,dn→vn]

// A field of the number of neighboursfoldhood(0)(_+_){ nbr{ 1 } }

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 10 / 30

Page 13: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

How it works: domain restriction (distributed if)

branch ( e ) { channel() } { false }

if

eb

if

condthen

else

(if eb e false)

false

e

The channel computes in a different domain, but does not get disrupted!Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 11 / 30

Page 14: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

Get to the higher level

These are the very low level mechanisms

Upon them, three “building blocks” are defined

They can be leveraged to realise reusable, higher level algorithms

G: spreading

3

17

02

T: time decay

14

33

C: collecting

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 12 / 30

Page 15: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

Examples with G

// A field of the same valuedef broadcast[V](source: Boolean, field: V)

(implicit ev: OrderingFoldable[V]): V =G[V](source, field, x=>x, nbrRange())

// A field of distances from an area (linear gradient in space)def distanceTo(source: Boolean): Double =G[Double](source, 0, _ + nbrRange(), nbrRange())

// A field of the shortest distance between two areasdef distBetween(source: Boolean, target: Boolean): Double =

broadcast(source, distanceTo(target))

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 13 / 30

Page 16: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

Examples with G and C

// A field of the sum of a value across the whole networkdef summarize(sink: Boolean,

acc: (Double,Double)=>Double,local: Double,Null: Double): Double =

broadcast(sink, C(distanceTo(sink), acc, local, Null))

// A field of the average of a value across the whole networkdef average(sink: Boolean, value: Double): Double =

summarize(sink, (a,b)=>{a+b}, value, 0.0) /summarize(sink, (a,b)=>a+b, 1, 0.0)

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 14 / 30

Page 17: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Aggregate Programming In Scala

Examples with T

// A field of the time left to a certain momentdef timer[V](length: V)

(implicit ev: Numeric[V]) = T[V](length)

// A field holding a value until the timer goes, and another// value thereafterdef limitedMemory[V,T](value: V, expValue: V, timeout: T)

(implicit ev: Numeric[T]) = {val t = timer[T](timeout)(mux(ev.gt(t, ev.zero)){value}{expValue}, t)

}

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 15 / 30

Page 18: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Alchemist

Outline

1 Context and Motivation

2 Aggregate ProgrammingBasicsIn Scala

3 Alchemist

4 Example

5 Conclusion

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 16 / 30

Page 19: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Alchemist

A fast, biochemistry-inspired, discrete event (meta-)simulator

Presented first here at MAS&S in 2011 :)

Now a much more sophisticated tool

Written (mostly) in Java, simulation specifications in YAML

Based on an extended version of Gibson-Bruck’s kinetic Monte Carlo

Defines a set of abstract entities (with names inspired by chemistry),whose actual implementation is left to the so-called incarnations

Incarnations ready to use for:

The SAPERE EU Project [ZOA+15] (tuple manipulation in a chemicalfashion across networks)Protelis [PVB15] (Aggregate programming)Multicellular biological systems (working, but under development)

Scafi incarnation to be included soon

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 16 / 30

Page 20: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Alchemist

Typical simulated scenarios

Many, possibly mobile nodes

Non trivial environment setups

Screenshots

Plant images can be used as indoor scenarios

Support for simulating on OpenStreetMaps

Support for navigating nodes along streets pedestrian, bike, mountainbike, motorcycle or car streets

Support for GPS traces, with interpolation along streets

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 17 / 30

Page 21: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Alchemist

Alchemist distribution (shameless plug)

Visit alchemistsimulator.github.ioRunnable JARGuidesTutorial for Protelis at https://github.com/AlchemistSimulator/Protelis-Incarnation-tutorial

Gradle users

Import Alchemist from Maven Central in your build with:

compile 'it.unibo.alchemist:alchemist:+'

Maven users

Import Alchemist from Maven Central in your build with:

<dependency><groupId>it.unibo.alchemist</groupId><artifactId>alchemist</artifactId><version>LATEST</version>

</dependency>

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 18 / 30

Page 22: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Alchemist

Alchemist and Scafi

The Scafi incarnation is ready and working

Still, not distributed, we are waiting for Scafi to be released on MavenCentral

All the Alchemist major features are incarnation independent, and assuch available immediately

Write once, simulate and deploy

The simulator executes exactly the same Scafi code that will bedeployed

Of course you can still break the toy by referencing internal Alchemistentities from Scafi via Java interoperabilityBut there’s no cure for bad programming :)

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 19 / 30

Page 23: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Outline

1 Context and Motivation

2 Aggregate ProgrammingBasicsIn Scala

3 Alchemist

4 Example

5 Conclusion

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 20 / 30

Page 24: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Crowd sensing and warning

Real data from the Vienna City Marathon 2013

We want to realise a system (potentially full P2P) which is able todetect areas where there is a dangerous crowd in the making

We also want the system to warn those that have been close to suchareas for a while

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 20 / 30

Page 25: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Case Study: crowd safety in a mass event

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 21 / 30

Page 26: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Scafi code I

Define three crowding levels

val (high,low,none) = (2,1,0) // crowd level

Locally estimate crowd density

def unionHoodPlus[A](expr: => A): List[A] =foldhoodPlus(List[A]())(_++_){ List[A](expr) }

def densityEst(p: Double, range: Double): Double = {val nearby = unionHoodPlus(

mux (nbrRange < range) { nbr(List(mid())) } { List() })nearby.size / p / (Math.PI * Math.pow(range,2))

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 22 / 30

Page 27: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Scafi code II

Map each area to a danger level, depending on the average density sensedlocally

def managementRegions(grain: Double,metric: => Double): Boolean = S(gran,metric)

def dangerousDensity(p: Double, r: Double) = {val mr = managementRegions(r*2, () => { nbrRange })val danger = average(mr, densityEst(p, r)) > 2.17 &&summarize(mr, (_:Double)+(_:Double), 1 / p, 0) > 300

mux(danger){ high }{ low }}

S is a building block similar to G, C, and T that operates a division of thenetwork.

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 23 / 30

Page 28: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Scafi code III

Measure if the dangerous situation held for long enough

def recentTrue(state: Boolean, memTime: Double): Boolean = {branch(state) {true

}{limitedMemory[Boolean,Double](started, false, memTime)._1

}}

def crowdTracking(p: Double, r: Double, t: Double) = {val crowdRgn = recentTrue(densityEst(p, r)>1.08, t)branch(crowdRgn){ dangerousDensity(p, r) }{ none }

}

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 24 / 30

Page 29: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Scafi code IV

Warn users of those devices located near areas which have remainedcrowded for a long time

def crowdWarning(p: Double, r: Double,warn: Double, t: Double): Boolean = {

distanceTo(crowdTracking(p,r,t) == high) < warn}

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 25 / 30

Page 30: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Alchemist simulation code I

Describe the environment and its geometry

environment:type: OSMEnvironmentparameters: ["vcm.pbf","vcmuser.agt",12000]

positions:type: LatLongPosition

Describe the network connectivity model

network-model:type: EuclideanDistanceparameters: [100]

Select the incarnation

incarnation: scafi

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 26 / 30

Page 31: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Alchemist simulation code II

Select which events will run, and their time distributionpools:- pool: &program- time-distribution: 1

program: crowdWarning(0.005, 30, 60, 60)- pool: &move- time-distribution: 0.1type: Eventactions:

- type: GPSTraceWalker

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 27 / 30

Page 32: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Example

Alchemist simulation code III

Displace the network nodes and program them

displacements:- in:

type: Rectangleparameters: [1479, 48.17, 16.3, 0.09, 0.15]

programs:- *program- *move

contents: []

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 28 / 30

Page 33: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Conclusion

Outline

1 Context and Motivation

2 Aggregate ProgrammingBasicsIn Scala

3 Alchemist

4 Example

5 Conclusion

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 29 / 30

Page 34: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Conclusion

Conclusion I

Aggregate programming

A promising approach for engineering large, situated systems

A paradigm shift

Scafi

A Scala implementation of the field calculus

Strong, static type system

Complex behaviours can be expressed compositionally

Modern, concise, consistent syntax

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 29 / 30

Page 35: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Conclusion

Conclusion II

Contribution

We integrated Scafi (existing but very fresh Scala-based DSL for aggregateprogramming) and Alchemist (an existing simulator)

Scafi + Alchemist

Behaviour verification in articulated environment

Performance measurement

Parameter tuning

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 30 / 30

Page 36: Simulating Large-scale Aggregate MASs with Alchemist and Scala

References

References I

Danilo Pianini, Mirko Viroli, and Jacob Beal.Protelis: practical aggregate programming.In Proceedings of the 30th Annual ACM Symposium on Applied Computing, Salamanca,Spain, April 13-17, 2015, pages 1846–1853, 2015.

Franco Zambonelli, Andrea Omicini, Bernhard Anzengruber, Gabriella Castelli, FrancescoL. De Angelis, Giovanna Di Marzo Serugendo, Simon A. Dobson, Jose LuisFernandez-Marquez, Alois Ferscha, Marco Mamei, Stefano Mariani, Ambra Molesini, SaraMontagna, Jussi Nieminen, Danilo Pianini, Matteo Risoldi, Alberto Rosi, GraemeStevenson, Mirko Viroli, and Juan Ye.Developing pervasive multi-agent systems with nature-inspired coordination.Pervasive and Mobile Computing, 17:236–252, 2015.

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 30 / 30

Page 37: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Supplementary information

Implementation of G

def G[V](src: Boolean, field: V, acc: V=>V, metric: =>Double)(implicit ev: OrderingFoldable[V]): V =

rep( (Double.MaxValue, field) ){ // (distance,value)dv => mux(src) {

(0.0, field) // ..on sources} {

minHoodPlus { // minHood except myselfval (d, v) = nbr { dv }(d + metric, acc(v))

}}

}._2 // yielding the resulting field of values

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 30 / 30

Page 38: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Supplementary information

Implementation of C

def C[V](potential: V, acc: (V,V)=>V, local: V, Null: V)(implicit ev: OrderingFoldable[V]): V = {

rep(local){ v =>acc(local, foldhood(Null)(acc){mux(nbr(findParent(potential)) == mid()){

nbr(v)} {

nbr(Null)}

})}

}

def findParent[V](potential: V)(implicit ev: OrderingFoldable[V]): ID = {

mux(ev.compare(minHood{ nbr(potential) }, potential)<0 ){minHood{ nbr{ Tuple2[V,ID](potential, mid()) } }._2

}{ Int.MaxValue }}

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 30 / 30

Page 39: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Supplementary information

Implementation of T

def T[V](initial: V, floor: V, decay: V=>V)(implicit ev: Numeric[V]): V = {

rep(initial){ v =>ev.min(initial, ev.max(floor, decay(v)))

}}

def T[V](initial: V)(implicit ev: Numeric[V]): V = {

T(initial, ev.zero, (t:V)=>ev.minus(t, ev.one))}

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 30 / 30

Page 40: Simulating Large-scale Aggregate MASs with Alchemist and Scala

Supplementary information

Implementation of S

def S(grain: Double, metric: Double): Boolean =breakUsingUids(randomUid, grain, metric)

def breakUsingUids(uid: (Double,ID), grain: Double,metric: => Double): Boolean =

uid == rep(uid) { lead:(Double,ID) =>val acc = (_:Double)+metricdistanceCompetition(G[Double](uid==lead, 0, acc, metric),

lead, uid, grain, metric)}

def distanceCompetition(d: Double, lead: (Double,ID),uid: (Double,ID), grain: Double, metric: => Double) = {

val inf:(Double,ID) = (Double.PositiveInfinity, uid._2)mux(d > grain){ uid }{mux(d >= (0.5*grain)){ inf }{

minHood{mux(nbr{d}+metric>=0.5*grain){nbr{inf}}{nbr{lead}}}}

}}

Casadei, Pianini, Viroli (UniBo) Alchemist and Scafi 2016-09-14 MAS&S 30 / 30


Recommended