\begin{vdm_al} ----------------------------------------------- -- Class: Traffic -- Description: Traffic contains the vehicles known by VeMo -----------------------------------------------
for v in vehicles do
( let vs = FindInRangeWithSameDirection(v,vehicles) in
inrange := inrange union vs;
);
ifcard inrange = 0 thenreturnfalse;
let avgspeed = AverageSpeed(inrange) in
( return avgspeed < Config`TrafficCongestionThreshold;
)
);
private AverageSpeed: setof Vehicle ==> nat
AverageSpeed(vs) ==
( dcl sumSpeed: nat := 0; forall v inset vs do
sumSpeed := sumSpeed + v.GetSpeed(); return (sumSpeed/card vs)
) precard vs <> 0; -- -- Functions definition section -- functions
-- compare the range of two vehicles public InRange : Vehicle * Vehicle -> bool
InRange(v1,v2) == let pos1 = v1.GetPosition(), pos2 = v2.GetPosition() in
pos1.inRange(pos2, Config`TrafficCongestionRange);
-- compare the range of a single vehicle to a set of vehicles moving in -- the same direction public FindInRangeWithSameDirection : Vehicle * seqof Vehicle
-> setof Vehicle
FindInRangeWithSameDirection(v ,vs) == let dir = v.GetDirection() in
{ ir | ir insetelems vs & v <> ir and dir = ir.GetDirection() and InRange(v,ir) = true }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.