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
DEVS Integrator – alternative representation of continuous
systems with discrete events
rate
varGen
in
out
sum
out
pulses
Instead of summing up pulses, the integrator
Receives the fate and adds quanta on its own
– with internal transition function
Ratefn
in
out
Ratefn
Integrator
out
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.
rate
Converting from sum to integrate
rate
varGen
Ratefn1
rate
varGen
out
Ratefn =
Ratefn1
+Ratefn2
Ratefn2
Combining rateFns for the same sum into one equivalent
Continuous Integration concepts and Differential Equations
input
contents = input dt
d s(t) / dt = x(t)
x
x
q
y(t) = s(t).
x(t)
y
y(t)
x(t)
t
x
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))
s
x
f1
s
x
f2
d s1 /dt
s1
d s2 /dt
s2
d sn /dt
sn
...
s
x
fn
Mapping Differential Equation Models into DEVS
Integrator Models
in x
newInp x
out =s
0
x
s
x
f1
s
x
f2
d s1/dt
d s2/dt
in x
newInp x
s1
fn
d sn/dt
s =s+qleft
ta=|q/inp|
qleft =q
s2
s s+e*inp
qleft =qleft - |e*inp|
ta = |qleft/newInp|
...
s
x
ta=|q/inp|
qleft =q
out =s+qleft
sn
DEVS Integrator
DEVS
instantaneous
function
x
s
x
f1
s
x
f2
F
d s 1/dt
d s 2/dt
F
...
s
x
fn
F
d s n/dt
DEV
S
s2
DEV
S
s1
DEV
S
sn
One Dimensional Integrator: Internal Transition /Output Generation
-integrator reaches predicted threshold and generates this threshold as output; the
integrator predicts its next boundary crossing.
output=
s+qleft;
output
output
Generate output
threshold level
q
Time advance =
|qLeft/lastInput)|
s
time
s’
Make a transition
state s = s + qLeft
qleft = quantum;
q
input>0
ta(s) = |quantum/input|
Onde Dim Integrator
uses input (derivative)
to predict next boundary
crossing
input<0
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
Residual: QuantumLeft Method:-limits time to next output by reducing
quantumLeft with each external input.
input
quantization.
oneDFrom2D
Int
Make a transition
s = s + e*lastInput;
qleft =qleft - |e*lastiinp|
lastInput = input;
ta = |qleft/input|
inp>0
q
s
s s+e*lastInp
qleft =qleft - |e*lastInp|
inp<0
ta = |qleft/nput|
elapsed
time, e
Time advance, ta
e
time of last
event
time of current
external event
First Order Integrator
uses last input
(derivative) to update
to current state
Residual: QuantumLeft Method:
sigma = |qleft/inp|
qleft =qleft - |e*inp|
qleft =qleft – e*qleft/sigma
=qleft (1– e*sigma)
Second order system
instantaneous
function
(identity)
in
in
out
out
dv/dt = a
ds/dt = v
input (a =
acceleration)
a
f(a,v,s)
-b*v
-a*s
output
(v =
velocity)
v
output
(s
=position)
friction (air
resistance,
damping)
restoring force
(k = spring
constant)
s
dv/dt = a – b*v – k*s = f(a,v,s)
ds/dt = v
Bunjee jumper modeled by a second order system
0
a
f(a,v,s)
v
s
-b*v
F ( s ) K ( s L) if
0
s L
otherwise
The spring restoring force
Only takes effect when
The jumper reaches the
stretch length L
s
dv/dt = a – b*v - F(s) = f(a,v,s)
ds/dt = v
L
Composite 1D integrator: encapsulates both position and
velocity in one atomic model; updates both components at once.
oneDCompInt
in
out
input
(acceleration)
sate.s
state = (s,v)
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
Modeling a one dimensional car
accelerate:
out
dv/dt = f(a,v)
(v,a > 0)
ds/dt = v
speed bounded:
f(a,v)
= a if v < vmax
v goes to 0
= 0 else
brake:
dv/dt = - b*v (b>0)
ds/dt = v
(dv/dt = 0 implies v => 0)
accelerate
brake
Class Vector
public double dotProd(vect2DEnt v){
return x*v.x + y*v.y;
}
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 perpendicular(){
return new vect2DEnt(-y,x);
}
public vect2DEnt scalarMult(double d){
return new vect2DEnt(x*d,y*d);
}
public vect2DEnt add(double x, double y){
return new vect2DEnt(this.x+x,this.y+y);
}
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 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);
quantizatio
}
n
vector2DEn
t
public vect2DEnt normalize(){
double norm = norm();
if (norm == 0)
return ZERO;
else return new vect2DEnt(x/norm,y/norm);
}
vect2DEnt.ZERO
v = new vect2DEnt(1,1)
v.add( new vect2DEnt(1,1-))
v’.y
v.y
Check: v.perpendicular().dotProd(v) = 0
new vect2DEnt(1-,1)
v.perpendicular)
v.x
v.dotProd(v’)
v.scalarMult(d))
v.norm()
v’.x
Check:
v.normalize() .norm() = 1
v.perpenducar().norm() =v.norm();
v.scalarMult(d).norm() = d*norm()
2 Dimentional Integrator -Internal Transition /Output Generation -integrator reaches predicted state and generates this state as output;
the integrator predicts its next state.
timeAdvance
= quantum/input.norm()
output=
nextstatel
input vector
Generate output
quantum is a radius
quantizatio
n
twoDint
s
s’
Make Transition;
sigma = timeAdvance(quantum);
remainingQuant = quantum;
nextState = state.add(input.scalarMult(sigma));
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.
input
Make a transition
state =state.add(lastInput.scalarMult(e))
lastInput = input;
quantumLeft -=
lastInput.scalarMult(e).norm()
ta = quantumLeft/input.norm();
elapsed
time, e
Time advance, ta
Input arrives after e
update state by
vector adding
lastInput*e
quantumLeft -=
lastInput.scalarMult(e).n
orm()
ta = quantumLeft
/input.norm()
Pursuer Evader – vehicles controlled by perceiving agents
• evader moves
perpendicular to
line joining vehicles
• pursuer moves
in direction of
line joining vehicles
• agents send position
updates at their
quantum threshold
crossings
larger quantum size for
an agent gives it the advantage
over its opponent
Pursuer Evader (cont’d)
•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
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);
}
}
Class VectAim – computes time of intersection, and
the velocity required to intersect in a given time, with
a moving target
let vect = vect2DEnt
public boolean vect ::sameDir (vect v): has my direction
p
v
public static double timeToIntersect (vect p,vect v): if v is in same
to intersect:
v must be in same
direction from origin
as p
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));}
will (v1,p1)
collide with
v1
(v2,p2)?
v2
p1
p2
public static vect dir (vect p1,vect p2p)
//the direction from p1 to p2p
{return p2p.subtract(p1).normalize();}
v2’=v1-v2
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);
?
v2
vect dir = dir(p1,p2p);
double speed = speed(p1,p2p,ta);
return dir.scalarMult(speed);
}
p1
p2
p2’ = p2-p1
• 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
Missiles– pursuer uses sensing and time-critical
prediction to continually re-aim for target
•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 which
continually checks for intersection
of trajectories
}
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);
dumb pursuer
smart pursuer
3
Bird flocking behavior
vehicleSpace
vehicles
• Start with vehicleSpace which is the coupled model for
Pursuer-Evader.
• Modify it as described below.
• flockSpace contains any number of birds with all-to-all
coupling of “out” to “in”.
• birdDriver moves toward a desiredPosition that is a
combination of the positions of the other birds as shown below.
• a lead bird provides direction and speed
cellGridPlot
same as
vehicleSpace
except for
multiple birds
vehicle
flockSpace
driver
vehicleDyn
birds
cellGridPlot
bird
same as vehicle
except for driver
birdDriver
vehicleDyn
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
Bird flocking behavior
Problem: For 6 birds find value of threshold that keeps flock
closest together while following lead bird
Bird location:
start with lead bird
named “bird_0”,
heading diagonally NE
start in SW corner –
birds are horizontally
arrayed with
spacing of 10
Motion Plot 15 draws
the current location of all
birds, the leader’s color is
red. The number, 15,
indicates the threshold
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.
class flockSpace(..) allows simulations with different thresholds and a different number of
birds. The values can be set calling the constructor.
Define an experimental frame to measure flock
coherence and lead following
Transducer to
measure
coherence and
lead following
birdPos
birdPos
birdPos
lead birdPos
center of
mass
birdPos
birdPos
birdPos
distance
to lead
bird
enclosing
radius
center of mass (w/o lead bird)
= sum of all position vectors /number of birds
enclosingRadius = max distance of all birds from center
distanceToLead bird = |lead position – center|
measure of coherence+close following
= w1*enclosingRadius +w2*distanceToLead Bird
where w1,w2 can be chosen to weight coherence vs close 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();
}}
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();
}
Results of some representative threshold settings
threshold = 0
threshold = 22
threshold = 60
enclosing
radius
distance
to lead
bird
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.
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).
Breadth of
Optimum
Run alternative
experiments in
parallel
Optimum
Threshold = 25
© Copyright 2026 Paperzz