3. More ElementsNow that we have been able to carry out our first simulation, and that we should also understand quite a bit the way the VS-pCoq Spy suggests us to define our problems, we should have a closer look at the rest of the elements. We will modify step by step the little example on the drawing area and in this way learn more about all elements of the VS-pCoq Spy. If you think the example is not realistic enough, you might try to follow some of the given examples. For more details about all the element, please look up their descriptions in the Reference Section. First of all, let's complete the introduction of the buttons. 3.1 Buttons (II)We had already a first look at the buttons some chapters ago, just before we tried our first simulation. Now let's discover all features of a button. Why do we need buttons? Because we must be able to generate messages during a simulation run. A button is a message translator. It can translate
The point which sends the outgoing messages is the pink point on the upper left corner of the button; pink, because the point is restricted to be used by message routes only. When you click with the mouse on the button's square shaped area during a simulation run, a message is generated and broadcast through the message route leaving the pink point; a message? We didn't talk much about messages yet, did we? A message is a character string that can be sent over message routes. The character string may contain anything even an empty string, if the message per se is what you want to be sent but the receiving elements don't understand everything. So make sure that your message can be understood by somebody in the system, when you think about what text you want to have broadcast by the button (we will explain what messages can be understood by what elements). If you send a "C" (don't send the quotation marks, please) to a point which happens to be a source, it will generate a gray car. If you send a "C1" to such a point, also a car will be generated, but the car will have an ID (identification) with value 1. Now, suppose you want to generate cars with ID 1 and cars with ID 2 in the same source. Therefore you should be able to send the commands "C1" or "C2" to the source point. You could do this by drawing two different buttons on the drawing area, one to send a "C1" and one to send a "C2" when you click on either one, and connect both to the point, which is the traffic source. This is not very elegant! A button is not really a single button, but a collection of up to 10 buttons. This allows you to generate different messages for the same message route in one and the same button element. Please add a button by opening the configuration panel and adding a button by pushing on one of the "ins" buttons you see. Write a "C1:10" into the first "Command"-field and a "C2:12" in the second one. Your drawing area will now look like this:
Steps, model 2 You might also write some characters into the "Text"-field for having them displayed on the button surface. By the way: the pink point is not the only point for message routes: there are more points, but "hidden" under the buttons! You don't believe me? Try it! Try to connect a message route to a simulation-active button surface, and not to the pink point. See? It works. What for can we use this feature? When a message arrives at such a "button point", it is regarded as being a mouse click on this button, no matter what message it is. By this you can translate every message into every other message. Delete all message routes to the button surface, except the one leaving the button at its pink point. Simulate it and watch the green and the red cars driving over the screen. 3.2 Special PointsWhen you connect message ways to streets, the points shared by both types of lines can take on special behaviors. There are
Interested in when a point becomes what? It's very easy.
Of course, a point can unite more than one of these properties a the same time; for example a point can be a street block and a bifurcation at the same time, or a street block and a source (which is not very useful), or even a street block and a detector, when a message way arrives and another message way leaves in the same point. A bifurcation is a rather complicated element, therefore it merits its own sub-title for discussing its behavior: 3.2.1 BifurcationsWhen a point is shared by three streets, it forms a bifurcation. There are bifurcations without any further definition needed (when it is clear for vehicles coming from any access street where to continue driving, as when two one-way streets flow together), and bifurcations needing an inner state. Add a street to the second point of the street drawn on the screen so that this point is transformed into a bifurcation:
Steps, model 3 As soon as the third line shares the bifurcation point, you will notice several changes: the point will change from a rectangle to a dot, it will take on a yellow color, and two of the three lines will be colored yellow in the vicinity of the point. These yellow lines indicate the actual position of the switch. If you open the configuration panel of the point, you find little radio buttons (with green lamps, when switched on) for changing the position of the switch from left to right. At the left of the radio buttons you can tell the bifurcation which state shall be considered to be "left" and which one "right". If the point (the bifurcation actually) receives the message "r" during simulation, it will switch to the right position, and with the message "l" to the left position.
Steps, model 4 How can we tell the point these messages? Right, define a new button, configure the button as two buttons and write in the field of the upper button a minuscule "l" for text and command and for the lower button a "r" at both places. For practice's sake change the reference corner of the pink point to "upper right". Connect the button to the bifurcation by a message way: Turn on the simulation and try switching the bifurcation to the left and to the right position. Generate cars and watch them being routed to the street determined by the bifurcation position. There are other ways of routing vehicles by a bifurcation without the need of the left-right-button. Remember, the cars have IDs 1 and 2, according to the message sent by the button? We want to use this information for routing the cars according to the identification number! When you open the configuration panel of the intersection, you find other check boxes than the ones for the bifurcation state. They have a red lamp inside when they are switched on. Push the button for "ID-selective". At the right of the button you must indicate which IDs shall be routed to the left side. All other IDs are routed to the right side. As there can be several IDs to be routed to the left side, the IDs have to be input in a set representation. Write "[1]" into the input field and leave the panel. The bifurcation position lines have disappeared because the bifurcation is kind of in both positions all the time, sole depending on the ID of the vehicle using it. The left-right-button has no more meaning. Turn the simulation on again and generate cars with IDs 1 and 2 and see them being routed into different streets. Finally a third way of routing cars is by probability. If you set the probability to 60% to the left maybe and push the appropriate radio button, each car arriving at the bifurcation is randomly routed to the left side or to the right side. This way of routing might be useful in larger systems if you don't want to decide by an ID at the source point where the destination of the vehicle is and where it should be routed through henceforth. Your routing decisions will be made locally at each bifurcation instead. 3.3 VehiclesAs mentioned, a vehicle is generated by a source point. You can generate different vehicle types with different IDs (identifications) and different colors. The type determines the length of the vehicle, the ID can be used for evaluation or for routing purposes, and the color is for your pleasure, that you can make your simulation full of colors no, maybe you would like to track by eye the different types of vehicles through the system. VS-pCoq Spy knows two different types of vehicles: cars (length or 5 meters) and trains (with a length of 14 meters for each carriage). Cars are little dots, and trains are rectangles. Normally you will use cars. If you want to show busses or trams in your system, use the train shape. You can attach several train carriages to each other. At the moment we are not interested in trains or in platoons (groups of cars attached to each other). There are two protocols about what vehicles are doing in the system: the waiting time protocol which is written for all vehicles with ID?0, and the measured protocol, which is written by special measurer elements. For details about the format please look them up in the Reference Section under "Protocol Format". 3.4 Traffic LightsMaybe we'd like to stop the traffic before the bifurcation (our little intersection)? We should use traffic lights for this purpose. Try it: generate a traffic light. You will see it neatly on the screen, showing a red state. This element, too, has a pink point. It is shown at the foot of the light pole. It is the communication port for switching the light by outside commands and for the light to tell its assigned street block to stop or to release the waiting traffic. How to tell the vehicles to respect this traffic light? Connect the light to a point on the street which becomes a street block through this operation. First of all we need an extra point on the street for this purpose. Of course we could use the same point as for the bifurcation, but this point would become a little bit overloaded. So let's use a new one for the light. Do you remember how to generate an extra point on a street? Choose the item "Points" from the "Drawing"-Pulldown menu, place the mouse on the line where you want to generate the point and click it. Connect the light by a message way to this point. You can always switch a light from red to green and vice versa by clicking on the light itself ("toggling" the light). But it is nicer to have a button where you can click on the appropriate area: Generate now a double button (or duplicate an existing one) and configure the button for messages being able to switch the light:
So may I suggest you to use the upper button for switching to red and the lower button for switching to green? Please write a text different from the command, e.g. "R" for red and "G" for green, and color the upper button red and the lower button green. Connect the button to the foot of the light by a message way:
Steps, model 5 Switch the simulation on. If you click on your "G"-button, the light will go from red to red-and-yellow and after a while to green. Click on the "R"-button, and the light will go back to yellow and then to red. Click simply on the traffic light, and you will toggle as well between the two states. Generate cars and see how they can be stopped in front of the street blocking point controlled by the traffic light. 3.4.1 A Simple Message ProcessingHow nice would it be if we could avoid pressing the left button all the time for generating new cars? Somehow we should be able to be lazily relaxed and just watch the simulation going on! We know that cars generate a message when driving over a detector. We further know that any message can trigger a mouse click when arriving on a message way connected to a hidden point under a button. Ok, then let's go and connect the sinks to the first button! Delete the button for switching the bifurcation to the left or right (and you will see that the button deletes the pink point, and because the pink point is starting point of a message way, the message way is deleted together with the point) and configure the bifurcation for routing all cars with ID=1 to the upper street and all cars with ID=2 to the lower one. Now: connect the upper sink my a message way to the upper area of the button you use for generating your cars. Then connect the lower sink to the lower area of this button. That's it switch the simulation on and generate cars by pushing the button manually!
Steps, model 6 You will see, as soon as a car leaves the system through a sink, a new car is generated at the source point. Why not two cars? We know that a detector always sends two messages per vehicle: a "1"-message and a "0"-message (arriving and departing). But the interval between these two messages equals exactly the length of the vehicle. You guess it: rounding problems! Change the maximum speed of the streets from 13m/s to 10m/s and start the simulation again: no rounding problems in this case! When the first car leaves the sink now, two new cars are generated at the source point. When this platoon leaves the system, three new cars are generated, because the first car leaves when the second car arrives, so that the latter command is ignored; and so on. Please avoid such a situation, because the simulation result is not exactly defined! We should use a message translator between the sink and the button for stopping either the "1"-message or the "0"-message. But before introducing such translators, we should have a look at a more important element for avoiding having to click the car generator buttons by hand: the source. 3.5 SourcesIt is annoying to click on a button for each vehicle to be generated. So why not introducing an automatic element, doing this for us? This kind of element is called a source. To state it clearly once more: a source does not generate vehicles, but a source generates commands automatically. These commands shall be sent to a source point in order to generate the vehicles.
Steps, model 7 As a source is an automatic button, the message sent by the source has to be configured. The default message is "C" and generates a white car without ID. Delete the message ways from the sink to the car generating buttons. Define a source next to this button, and a white square with an x-shaped cross will appear. Can you see the pink point? Connect it to the source point by a message way and switch on the simulation. You will see that from time to time there is a white car generated by the source point. The white car will drive to the right side at the bifurcation (make sure to have the traffic signal showing green), because its ID is not 1. You can still trigger your old cars with IDs 1 and 2 by clicking on the button. Clicking on the source has no effect. Switch off the simulation again and generate a second source next to the first one. Now configure the "command sent"-parameters (a field of the configuration panel) of one source to send the command "C1:10" and the other source to send "C2:12". Now your two sources can send the same commands as the buttons, and you will see during simulation that the cars will drive to the left and to the right side of the bifurcation according to their ID (shown in their color as well).
Steps, models 8 and 9 Sorry, you have just drawn the situation which is called "incorrect" in the above figure. Why incorrect? As you know, a vehicle is only generated by the source point, when there is enough space on the street to actually put the vehicle there. What happens now if source 2 sends its command right after source 1 and the previous car could not yet leave the vehicle generation area? The command of source 2 is ignored and no car is generated. As source points have no memory for remembering an old command that they were not able to carry out, this latter car will never be generated. This if for sure against the statistical properties of your source! If you want to avoid this error, re-draw the drawing area in the way shown at the "correct" side of the figure (delete the button now, as you don't need it any more for the moment). By joining the two streets, a bifurcation-like point is generated, but you will notice that the point does not change its color into yellow, as it should be for a good bifurcation. Do you know the reason for it? The bifurcation has no inner state, because there is nothing to switch from left to right. The vehicles drive always to the same street at the right side. The vehicles know how to squeeze at the bifurcation point. 3.5.1 Statistical PropertiesSources generate cars according to statistical properties. You can define them in the configuration panel. The most important parameter is the inter arrival time distribution function. The inter arrival time is the amount of time between the generation of two cars. In real traffic this function is mostly a Raleigh-distribution or anything Poisson-like for un-hindered traffic and anything else if the traffic is coming from other intersections. Mostly traffic in cities forms platoons. You can configure the source for generating platoons instead of single vehicles. The inter arrival time function will then determine the inter arrival times within a platoon. You will need some additional parameters for determining the inter arrival time between platoons, the platoon length, and a blurring factor of inter arrival times within a platoon. Please have a look at the "Source" term in the Reference Section for more details about the distribution functions. 3.6 TranslatorsOk, let's now introduce the translator. Translators translate messages arriving on a message way. Buttons can also translate messages arriving on a message way, but you cannot generate a message in a translator by a mouse click. The second point of difference is that a translator can split a message from one message way into two different message ways: A translator has one input point and two output points. Generate a translator on the screen. It has a triangle shape. The standard configuration is that the translator sends a message (without contents, an empty string) through the upper point if the input point receives a "1" and a message through the lower point if it receives a "0"-message. So let's use the translator for a repeating source:
Steps, model 10 Take out the source, move the button a bit to the left, add a point on the street in good distance after the source point, generate a translator, and connect the new point on the street by a message way to the translator's input and the translator's output by another message way to one of the points hidden under the button. Switch on the simulation. Once you have generated a car, as soon as the car drives over (actually leaves) the "detector" triggering the translator, another car is generated at the beginning of the street. If you switch the light to red, there will soon be a traffic jam and no more cars are generated. 3.7 BlocksLet us "abuse" the traffic light. We want to send only one car at a time over the intersection, and as soon as the car has left the intersection, we want to have the next car driving away. What shall we do? Let us connect the point street block, controlled by the traffic light, by a message way to the "R"-area of the button controlling to the traffic light. What will happen? Assuming green light, as soon as a car drives over the street block (which is at the same time a detector, because also a message way is leaving), the detector will generate a "1"- and a "0"-message which both switch the light to red (the second message is ignored, because the light is already showing yellow and therefore on the way to switch to red. Correct? Yes, but careful! As the button sends a message "H" to the light and the light transmits the message to the street block, the street block will transmit the message further, because there is a message way leaving (which is intended to transmit the detector signals, and not the light commands! The message way will now transmit a "H" information to the "R"-area of the button, and this message will again try to switch the signal to red! We must break up this circular message, and of course we use a translator for this purpose! Re-use the same translator from the last section, as it transmits only a "0" or a "1"-message, all light controlling messages are successfully stopped. Switch back the light when the car has passed the intersection, for example at the bendings of the leaving street. There is no need for a translator here as no message can arrive at the detector points.
Steps, model 11 It might be that you don't want to use the light for such a blocking function use a block! A block looks like a button with two sensitive areas, but one area is green and the other is red. If the green area is highlighted, the block is open, if the red area is highlighted, it is blocked. Pull the message way from the outer point ("the pink point") to the point which shall be blocked. Pull message ways to the inner points (hidden under the green and the red area) from the points on the streets who shall trigger the blocked and the un-blocked state. You may also click on the two areas of the block element during simulation for changing its state. Replace the previous construction by a block as shown in the next figure:
Steps, model 12 3.8 GatesLook at the inverse situation or better: invert the situation! Change the traffic flow so that the cars are coming from the right, driving towards the left (invert all streets, connect two buttons to the right end of the streets, and exchange blocking and releasing points of the block).
Steps, model 13 Let some cars drive towards the joining point of the streets. There will only be one car at a time in the three streets controlled by the block element, but you cannot control which car is next when several cars are lining up before the street blocks. The block should remember somehow which car was first. Let's construct a simple state machine for this purpose: 3.8.1 A State MachineLet us call the upper access road A and the lower one B. Our state machine shall contain the following informations:
The state machine shall have three local automata (having values 1 or 0) named A (for "A was first"), B (for "B was first") and W (for "also a car in the other access road). There are four possible signals, that might arrive at the state machine: a (for "car arrives in A"), b (for "car arrives in B"), a (for "car leaves A"), and b (for "car leaves B").
At the moment when we must decide which car shall have green next, the automata A and B will say it to us: either A is 1 or B, but never both. Thus our state machine is shown here at the right of the text. For the three automata we can use blocks, which are nothing else than flip-flops (if they are not counting!). The figure leads us to the following state diagram (note that there are many forbidden states as we use only 5 states out of 8 possible states):
From here we can derive the equations for the state transitions:
We use the block's "blocked" (red) state as "1" and the "open" (green) state as "0".
Steps, model 14 As the state machine only has memory 1, make sure that the detector for the "arriving"-message (a or b) is always blocked by the car, which has sent the last message, until this car will have sent its "leaving"-message ( a or b). A pattern of arriving messages "aa" or "bb" is not allowed (as well as aa or bb).Connect now the inputs a, b, a and b, as well as the outputs A and B to the original simulation situation: A and B decide now which access road will be next for letting a car drive away. During simulation you see the input- and output-states of the gates drawn on the points where the message paths end or start. If an input or output is height, the point is yellow, otherwise it is gray. Please enjoy your state machine for a while: that was hard work!
Steps, model 15 3.9 ControllersThis was exhausting! Be honest, do you think that you will ever need such a block-and-gate-construction for traffic control? I mean: street traffic control, not playing around with railways (see the example about a model railroad)? Yes and no. You might want to avoid two cars at the same time on a conflicting point of an intersection, but you never want them to drive as single cars: there should be either cars from access A or from access B. Let's draw two traffic lights instead of the automatic block, with its appropriate buttons. Create another button which produces the messages "A" and "B" which you send to a message translator: if an A arrives, light A is switched to green and light B to red; if a B arrives, vice versa.
Steps, model 16 Simulate it. You can switch the lights together with the "A-B"-button. You can still switch the lights separately, which leads to a forbidden state. Pull the street block of light A closer to the bifurcation (where the two streets flow together), pull it very close to the bifurcation and start the simulation again: switching from phase A to B is always ok, but when you switch from phase B to A there are still cars of phase B on the intersection when the cars of phase A arrive: we need some timing! We need a controller. Add a controller to the drawing area. Afterwards, choose the drawing element control path and pull them from the triangular points to the lights. Click carefully on the triangular points, they will expand. Choose the sub-point with name "L" (for "light") as start point for the control path. Don't connect them to the street blocks, but to the lights, because you want to see how the controller modifies you messages.
Steps, models 17 and 18 If you switch on the simulation now, there will be no difference to before, because the controller is in idle mode ("no supervision"). 3.9.1 Denying SupervisorConfigure the controller now. Open the configuration panel and push the button "Matrix Values" for configuring the clearing time matrix. The controller's phase "1" equals our access A. So write 2 seconds for the clearing time from phase 1 to phase 2 and 4 seconds from phase 2 to 1 (as the situation is not symmetrical). Leave the panel with "ok". Now configure some "Phase Parameters": choose for both phases the minimal green time as 3 seconds and the minimal red time as 3 seconds, too. Leave the panel with "ok" and choose the radio button for "denying supervision". Leave also this panel with "ok" and switch on the simulation. The "A-B"-button does not switch to green any more! Why? The commands are not conform with the clearing time restriction, because you try to switch one light to red and at the same time the other light to green. So only the "red"-command is accepted by the controller. Use the local buttons for every light, and find out how the controller checks the clearing times. As the controller is in denying mode, your command is blocked (or absorbed by the controller) when it is not correct. This is why we have to use control paths: when a message arrives at the end of one of the control paths, it is propagated backwards into the controller. If the message is incorrect at the present moment of time, it is thrown away; if it is correct, it is propagated further. Click the "A-B"-button again when both lights have been red for a while, and you will see that the controller accepts now your request for switching green the other light. 3.9.2 Correcting SupervisorConfigure the controller as a correcting supervisor now. Correcting means that the controller does the right message timing for you when it detects that your message is not possible at the present time of simulation. Push the "A-B"-button and see how the right timing for switching the lights is done by the controller. By the way, you don't need the "A-B"-button any more, because you can simply push the "green"-button of a light, and the controller switches the other light to red by itself. 3.9.3 Cyclic ControllerLet's use the controller in a right way: as a real controller and not simply as a supervisor. Configure it as a cyclic controller. You won't need the buttons for the traffic lights any more when the controller is actively controlling, because your commands will never be accepted by the control paths. So delete them. You must do the following steps for the cyclic controller definition:
Push the "configure cyclic control" button on the controller configuration panel. Work at first with the upper window, showing a grid. Push the mouse somewhere on the grid and paint a blue line while you keep the left mouse button pressed. Look for the ending point of the line while you keep the button pressed. Once you have released the button, you can erase the line by over-drawing it with another blue line. You can draw horizontal, vertical and diagonal lines. Try to paint the streets as they are on your basic drawing area. Now assign the phase numbers to the painted lines: click in the "phase number" window on phase 1, which will be framed by a green rectangle. When you paint now a line on the "phase pattern"-area, the line will be green. Paint the green line over the blue line where you want phase 1 to be highlighted. Click now on phase 2, and phase 1 will remain framed, but with a red rectangle. Red color is used for phases that are not active at the moment. Paint the lines for phase 2, then select the neutral space left of the phase number 1. This space will show a blue rectangle, as it was when you started painting the basic phase pattern. All lines assigned to phases will now be red, if you should have assigned a line to more than two phases (maybe the part where the traffic flows away after the intersection), such a line is painted yellow. Assign the patterns to the phases. As our intersection is very simple, a pattern equals to a phase (several phases form a pattern when they are always switched together as on bi-directional intersections). Select pattern number 1 and assign it to phase number one either by clicking to the phase number or to the line assigned to the phase number in the "phase pattern" painting area. Do the same for pattern 2. Click again on pattern 1 and stay with pattern 1 activated. Define now the cycle: click the right mouse button over the "cycle definition" window, and a pattern change line will appear. Drag the line to the point of time where you want your cycle to end (maybe at 30 seconds). Click with the left mouse button now, and the line will be stable. Click to pattern number 2 and generate a pattern change line in the same way maybe at the point for 15 seconds. That's it. Your cycle will start with pattern 1 and change to pattern 2 after 15 seconds. When the definition area ends, the cycle will start again (that's why it is called a cycle!). Simulate it! 3.9.4 Pattern Selection ControllerThe most efficient way of controlling is the Pattern Selection Control. As you have already defined the patterns, you could simulate right away but stop, don't forget to give the controller the appropriate feedback information! The VS-pCoq Spy uses a simple pattern selection method: count the cars for each pattern and look which pattern is the most efficient at the moment (where the most cars can drive over the intersection). If this is not the actual pattern, switch to that best pattern if it is twice as good as the actual pattern (this is to make the control stable). I know this control is somewhat dull, but it shows very nice results, in fact it is almost as good as the real adaptive control using Dynamic Programming and Branch-and-Bound. As the controller has to know how many cars there are at the moment in each access road, insert a point in each access road before the street block at the traffic light. Please, for "fairness" to the other phase, make the distances from that point to the street block around equally long. Connect these points with normal message ways to the triangular points of the controller: when the point will have expanded, choose the point "1" for ("first detector") don't forget to keep the mouse button pressed until you have chosen the final point for the message way. Tell the controller when a car will leave the intersection by connecting the street blocks by another message way to the expanded point "n" (for "last detector") of the controller. Configure the controller in "pattern selection" mode and switch on the simulation. See how the controller optimizes the passing of the intersection of cars you generate by the buttons?
Steps, model 19 3.10 MeasurersAs we have mentioned introducing vehicles, some data are collected for each vehicle with ID?0 and written into the protocol file. This might not satisfy you. If you are optimizing an intersection, you would like to have data from the point of view of the access road not only the vehicle. Therefor you can add some measurers to the drawing. Measurers look like timer clocks. The upper point is for switching them on (by an arriving detector message) and the lower point for switching off. At the point of switching the clock on, the time of the "1"- and the time of the "0" message is recorded, as well as for the point of switching off the clock. A measurer can handle arbitrary many cars. The evaluated data for each car is written into the protocol file (an entry with entry code "m") when the vehicle has passed completely the switch-off point. For example, measure the data about the controller queue for each phase (the moment the car announces itself to the controller until it sends it "leaving"-information). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|