chapter 8 the devs integrator: motion in space from pulse-based to quantum-based integrators mapping...

23
Chapter 8 The DEVS Integrator: Motion in Space From pulse-based to quantum-based integrators Mapping Ordinary Differential Equations into DEVS one-D DEVS Integrators two-D DEVS integrators Second Order Systems • Vectors Motion in Space Examples – Pursuer Evader, Bird Flocking

Upload: ross-baker

Post on 13-Dec-2015

225 views

Category:

Documents


3 download

TRANSCRIPT

Chapter 8 The DEVS Integrator: Motion in Space

• From pulse-based to quantum-based integrators• Mapping Ordinary Differential Equations into

DEVS• one-D DEVS Integrators• two-D DEVS integrators • Second Order Systems• Vectors• Motion in Space• Examples – Pursuer Evader, Bird Flocking

varGenrate out

sum

in out

pulsesRatefn

Ratefnout

Integrator

in out

rate

Instead of summing up pulses, the integratorReceives the fate and adds quanta on its own – with internal transition function

When the rate changes, the Ratefn tells the integrator the new rate and it updates its sum based on the old rate and elapsed time.

varGenrate

Ratefn1

varGenrate

Ratefn2

Ratefn = Ratefn1+Ratefn2

out

Converting from sum to integrate

Combining rateFns for the same sum into one equivalent

DEVS Integrator – alternative representation of continuous systems with discrete events

x qd s(t) / dt = x(t)

y(t) = s(t).

Continuous Integration concepts and Differential Equations

d s1(t)/dt = f1(s1(t), s2(t), ..., sn(t), x1(t), x2(t),..., xm(t))d s2(t)/dt = f2(s1(t), s2(t), ..., sn(t), x1(t), x2(t),..., xm(t))

...d sn(t)/dt = fn(s1(t), s2(t), ..., sn(t), x1(t), x2(t),..., xm(t))

input

contents = input dt

x

x(t)

y

t

x(t)y(t)

d s1 /dt s1f1x

d s2 /dt s2f2

d sn /dt snf n

sx

sx

sx

...

d s1/dt s1f1x

d s2/dt s2f2

d sn/dt snfn

sx

sx

sx

...

d s1/dt s1f1x

d s2/dt s2f2

d sn/dt snfn

sx

sx

sx

...

DEVSDEVS

DEVS

F

F

F

Mapping Differential Equation Models into DEVS Integrator Models

DEVSinstantaneous

function

DEVS Integrator

in xnewInp x

0

out =s

in xnewInp x

ta=|q/inp|qleft =q

out =s+qleft

ta=|q/inp|

qleft =q

s =s+qleft

s s+e*inpqleft =qleft - |e*inp|ta = |qleft/newInp|

One Dimensional Integrator: Internal Transition /Output Generation -- integrator reaches predicted threshold and generates this threshold as output; the integrator predicts its next boundary crossing.

s

Generate output

output=s+qleft;

Make a transitionstate s = s + qLeftqleft = quantum;

s’

Time advance = |qLeft/lastInput)|

time

threshold level

output

input>0

input<0

q

ta(s) = |quantum/input|Onde Dim Integratoruses input (derivative) to predict next boundary crossing

q

output

input

One Dimensional Integrator: Response to External Input – an integrator receives a new input, updates its state, predicts a next state and reschedules itself accordingly to reach the next threshold

Time advance, ta

Make a transitions = s + e*lastInput; qleft =qleft - |e*lastiinp|lastInput = input; ta = |qleft/input|

elapsedtime, e q

e

inp>0

inp<0

s

First Order Integratoruses last input (derivative) to update to current statetime of last

event

time of current external event

quantization.oneDFrom2D

Int

Residual: QuantumLeft Method:sigma = |qleft/inp|qleft =qleft - |e*inp|qleft =qleft – e*qleft/sigma =qleft (1– e*sigma)

s s+e*lastInpqleft =qleft - |e*lastInp|

ta = |qleft/nput|

Residual: QuantumLeft Method:--limits time to next output by reducing quantumLeft with each external input.

out

Second order system

output(v =

velocity)

input (a = acceleration) output

(s =position)

in outin

dv/dt = a

ds/dt = v

instantaneous function (identity)

restoring force (k = spring constant)

a s

dv/dt = a – b*v – k*s = f(a,v,s)

ds/dt = v

friction (air resistance, damping)

-b*v

-a*s

vf(a,v,s)

Bunjee jumper modeled by a second order system

a s

dv/dt = a – b*v - F(s) = f(a,v,s)

ds/dt = v

-b*v

vf(a,v,s)

The spring restoring forceOnly takes effect whenThe jumper reaches the stretch length Lotherwise

LsifLsKsF

0

)()(

s

0

L

oneDCompIntout

Composite 1D integrator: encapsulates both position and velocity in one atomic model; updates both components at once.

in

state = (s,v)

input (acceleration)

sate.s

after elapsed time, e, update both s and v

s = s + v*e, v = v+ a*e ta = min {q/a, 10q/v}

dv/dt = a – b*v – k*s

ds/dt = v

out

Modeling a one dimensional car

accelerate:

dv/dt = f(a,v)

(v,a > 0)

ds/dt = v

brake:

dv/dt = - b*v (b>0)

ds/dt = v

(dv/dt = 0 implies v => 0)

brakeaccelerate

speed bounded:

f(a,v) = a if v < vmax

= 0 else v goes to 0

public class vect2DEnt extends entity {public double x,y;

public static vect2DEnt ZERO = new vect2DEnt(0,0);

public vect2DEnt(double x, double y){super("vect2DEnt");this.x = x;this.y = y;}

public vect2DEnt add(double x, double y){return new vect2DEnt(this.x+x,this.y+y);}

public vect2DEnt add(vect2DEnt v){return add(v.x,v.y);}

public void addSelf(vect2DEnt v){x += v.x;y += v.y;}

public vect2DEnt subtract(vect2DEnt v){return add(-v.x,-v.y);}

public double dotProd(vect2DEnt v){return x*v.x + y*v.y;}

public vect2DEnt perpendicular(){return new vect2DEnt(-y,x);}

public vect2DEnt scalarMult(double d){return new vect2DEnt(x*d,y*d);}

public vect2DEnt maxLimit(double max){if (norm() <= max)return this;else{vect2DEnt na = normalize();return na.scalarMult(max);}}public double norm(){return Math.sqrt(x*x + y*y);}

public vect2DEnt normalize(){double norm = norm();if (norm == 0)return ZERO;else return new vect2DEnt(x/norm,y/norm);}

Class Vector

quantizationvector2DEn

t

v = new vect2DEnt(1,1)

vect2DEnt.ZERO

v.add( new vect2DEnt(1,1-))

v.perpendicular)

new vect2DEnt(1-,1)Check: v.perpendicular().dotProd(v) = 0

v.x v’.x

v.dotProd(v’)

v.y

v’.y

v.scalarMult(d)) v.norm()

Check: v.normalize() .norm() = 1v.perpenducar().norm() =v.norm();v.scalarMult(d).norm() = d*norm()

Generate output

output=nextstatel

s s’

Make Transition; sigma = timeAdvance(quantum); remainingQuant = quantum; nextState = state.add(input.scalarMult(sigma));

quantum is a radius

timeAdvance = quantum/input.norm()

input vector

2 Dimentional Integrator -Internal Transition /Output Generation -- integrator reaches predicted state and generates this state as output; the integrator predicts its next state.

quantization

twoDint

Time advance, ta

input

Make a transitionstate =state.add(lastInput.scalarMult(e))lastInput = input; quantumLeft -=lastInput.scalarMult(e).norm() ta = quantumLeft/input.norm();

Response to External Input – an integrator receives a new input, updates its state, predicts the next state and reschedules itself to reach the next state.

elapsedtime, e

update state by vector adding

lastInput*e

ta = quantumLeft/input.norm()

Input arrives after e

quantumLeft -=lastInput.scalarMult(e).

norm()

Pursuer Evader – vehicles controlled by perceiving agents

• evader movesperpendicular toline joining vehicles

• agents send positionupdates at theirquantum thresholdcrossings• pursuer moves

in direction ofline joining vehicles

larger quantum size foran agent gives it the advantageover its opponent

•pursuer’s acceleration vector is the difference between its position and the desiredPosition coming in from evader

•evader’s acceleration vector is perpendicular to its difference vector

Pursuer Evader (cont’d)

public class driver extends ViewableAtomic{

protected vect2DEnt position, desiredPosition, difference;protected double tolerance = 2,maxPos = 100;

public void deltext(double e ,message x){Continue(e);

for (int i=0; i< x.getLength();i++){ if (messageOnPort(x,"position",i)) { entity en = x.getValOnPort("position",i); position = vect2DEnt.toObject(en); position.addSelf(new vect2DEnt(r.uniform(-10,10),r.uniform(-10,10))); } else if (messageOnPort(x,"desiredPosition",i)) { entity en = x.getValOnPort("desiredPosition",i); desiredPosition = vect2DEnt.toObject(en); } } difference = desiredPosition.subtract(position); if (name.startsWith("evade")) difference = difference.perpendicular(); if (difference.norm()<= tolerance) holdIn("doBrake",0); else holdIn("doAccel",0); }}

let vect = vect2DEnt public boolean vect ::sameDir (vect v): has my direction

public static double timeToIntersect (vect p,vect v): if v is in same

direction as p then return p.norm()/v.norm(), else infinity

public static double timeToIntersect (vect p1,vect p2, vect v1,vect v2){return timeToIntersect(p2.subtract(p1),v1.subtract(v2)); //note sign diff}public static vect predictLoc (vect p2, vect v2,double ta): //predict the location vehicle will be in time ta{return p2.add(v2.scalarMult(ta));}

public static vect dir (vect p1,vect p2p)//the direction from p1 to p2p{return p2p.subtract(p1).normalize();}

public static double speed (vect p1,vect p2p,double ta)//the speed required to reach p2p from p1 in time ta{return p2p.subtract(p1).norm()/ta;}

public static vect aim (vect p1,vect p2, vect v2,double ta)//the velocity required to intersect with target (p2,v2) in time ta{vect p2p = predictLoc (p2, v2,ta);vect dir = dir(p1,p2p);double speed = speed(p1,p2p,ta);return dir.scalarMult(speed);}

Class VectAim – computes time of intersection, and the velocity required to intersect in a given time, with a moving target p

v

p1 p2

p2’ = p2-p1

v1 v2

v2’=v1-v2

to intersect:v must be in same

direction from origin as p

• place the origin at p1• p2’ = p2-p1 is location of p2 in this frame• v2’ = v1-v2 is the relative velocity aiming at p2• for the relative velocity v1’ to be in the direction of p2’, the perpendicular components must cancel

p1 p2

? v2

will (v1,p1) collide with

(v2,p2)?

smart pursuerdumb pursuer

•dumb pursuer – flies fixed trajectory toward target

•smart pursuer -- adjusts velocity to intersect with target’s predicted trajectory in a given time. The time left is reduced as time passes without reaching target

• target has collision detector whichcontinually checks for intersectionof trajectories

Missiles– pursuer uses sensing and time-critical prediction to continually re-aim for target

}Pursuer uses this logic:if (myPos.subtract (otherPos).norm() < takeEffectDist){ vect vHit = vectAim.aim (myPos, otherPos, otherVel, Math.max (1,timeLeft));

difference = vHit.subtract (myVel). scalarMult (power);

holdIn("doAccel",0);

Bird flocking behavior

bird

birds

birdDriver vehicleDyn

flockSpace

cellGridPlot

same as vehicle except for

driver

same as vehicleSpace

except for multiple birds

driver

vehicle

vehicles

vehicleDyn

vehicleSpace

cellGridPlot

• Start with vehicleSpace which is the coupled model forPursuer-Evader.• Modify it as described below.• flockSpace contains any number of birds with all-to-allcoupling of “out” to “in”.• birdDriver moves toward a desiredPosition that is acombination of the positions of the other birds as shown below.• a lead bird provides direction and speed

define birdDriver by adapting driver as follows: when receive a bird’s position: if (it is farther from me than a threshold){ desiredPosition = 0.5*(desiredPosition + bird’s position) difference = desiredPosition - position If (name.startsWith("bird_0")) difference = difference + vector in direction NE with magnitude = 100(ALL OTHER ASPECTS OF driver REMAIN THE SAME)

NOTE: all operations use

Vect2DEnt

3

Bird flocking behavior

class flockSpace(..) allows simulations with different thresholds and a different number of birds. The values can be set calling the constructor.

Motion Plot 15 draws the current location of all birds, the leader’s color is red. The number, 15, indicates the threshold

Bird location:

start in SW corner – birds are horizontally

arrayed withspacing of 10

start with lead bird named “bird_0”,

heading diagonally NE

Problem: For 6 birds find value of threshold that keeps flock closest together while following lead bird

Note that all birds have the same information processing algorithm – they cannot distinguish among themselves (in particular, the lead bird is not explicitly known to the others.

birdPos

birdPos

birdPos

birdPos

birdPos

birdPos

lead birdPos

center ofmass

center of mass (w/o lead bird) = sum of all position vectors /number of birdsenclosingRadius = max distance of all birds from centerdistanceToLead bird = |lead position – center|

measure of coherence+close following = w1*enclosingRadius +w2*distanceToLead Birdwhere w1,w2 can be chosen to weight coherence vs close following

class centerFn extends Queue{public vect2DEnt sum,avg; public centerFn(int numElements){super();….}public void addVoldVnew(vect2DEnt vold ,vect2DEnt vnew){remove(vold);add(vnew);if (size()>numElements)remove();computeSum();computeMax();}

Define an experimental frame to measure flock coherence and lead following public class centerTrans extends realDevs{

protected centerFn cs;

public void deltext(double e,message x){ Continue(e); if (phaseIs("passive")) for (int i = 0; i < x.getLength(); i++) if (messageOnPort(x, "inOldNewPos", i)) { Pair p = (Pair)x.getValOnPort("inOldNewPos", i); cs.addVoldVnew(p); holdIn("output",0); } else if (messageOnPort(x, "inLead", i)) { entity en = x.getValOnPort("inLead", i); vect2DEnt leadPos = vect2DEnt.toObject(en); leadDist = leadPos.subtract(cs.center()).norm(); passivate(); }}

enclosing radius

distanceto lead bird

Transducer to measure coherence and lead following

distanceto lead bird

enclosing radius

Results of some representative threshold settings

threshold = 0threshold = 22 threshold = 60

for small threshold, birds stay close together but lose the signal of the lead bird’s direction

for large threshold, birds can pick up the lead bird’s signal only after large distrance.

Optimum Threshold = 25

Breadth ofOptimum

Parallel Simulation Coupled Model for Optimization Study

equally weighted sum of radius and distance to lead bird

class flockSpaceOpt(..) allows simulations of flockSpaces with different thresholds at the same time and displays the values of the means (the current and the total).

Run alternative experiments in

parallel