\begin{vdm_al} ----------------------------------------------- -- Class: VDMController -- Description: VDMController main controller for the VDM system -----------------------------------------------
public addTrafficLight: TrafficLight ==> ()
addTrafficLight(light) ==
(
lights := lights munion {light.GetID() |-> light};
) pre light.GetID() notinsetdom lights and light.GetID() notinsetdom ctrlUnits;
public getController : nat ==> Controller
getController(id) ==
( return ctrlUnits(id);
) pre id insetdom ctrlUnits;
public getTrafficLight : nat ==> TrafficLight
getTrafficLight(id) ==
( return lights(id);
) pre id insetdom lights;
public Step: () ==> ()
Step() ==
(
CalculateInRange();
);
public CalculateInRange: () ==> ()
CalculateInRange() ==
( -- vehicles let units = rng ctrlUnits in -- for all units, find the ones in range. -- This could be optimized given that if one unit can see another unit, -- then they can see each other, no need to calculate the range again -- for units seeing each other. However this will be complex, given that -- one unit might have serveral units in its range that aren't in range -- of each other. forall unit inset units do
( let inrange = FindInRangeWithOppositeDirection(unit, units) in
( -- only request data, the way the loop is built will ensure that all -- units will request data. if(card inrange > 0) then forall oncomingVehicle inset inrange do
(
unit.AddTrafficData(oncomingVehicle.GetVehicleID()
,oncomingVehicle.GetTrafficData());
let vehicleDTO = unit.getVehicleDTO() in
oncomingVehicle.AddOncomingVehicle(vehicleDTO);
);
)
)
);
-- compare the range of a single vehicle/controller to a -- set of vehicles/controllers public FindInRange : Controller * setof Controller -> setof Controller
FindInRange(v, vs) == let inrange = { ir | ir inset vs & v <> ir and InRange(v,ir) = true } in
inrange;
-- compare the range of two vehicles/controllers public InRange : Controller * Controller -> bool
InRange(u1,u2) == let pos1 = u1.GetPosition(), pos2 = u2.GetPosition() in
pos1.inRange(pos2, Config`Range);
-- compare the range of a single vehicle/controller to a set of -- vehicles/controllers moving in the opposite direction public FindInRangeWithOppositeDirection : Controller * setof Controller
-> setof Controller
FindInRangeWithOppositeDirection(u ,us) == let dir = OppositeDirection(u.GetDirection()) in let inrange = { ir | ir inset FindInRange(u, us) & dir = ir.GetDirection()} in
inrange;
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.