Using FRP to model a road network with jams

I'm currently trying to understand arrows and FRP, and I came across a question that I cannot imagine in FRP, namely how to model a road network.

I thought that I could simulate a road network as arrows, where each arrow represents a segment of the road. It accepts car flows in places and times and produces the same type, albeit with different locations and times.

So far so good. But this model does not take into account that segments can jam. While each segment can respond well to intense traffic and delay cars more and more, the more it is overloaded, the less the backing effect, i.e. The jam will not extend back to other segments of the road.

I suspect that I am applying too much OO thinking here, instead of focusing on what needs to be calculated, but I cannot figure it out right in my head.

  • How to simulate a road network with arrows so that the effects of return water are taken into account?
+6
source share
1 answer

The problem is that in arrows and in FRP, the flow of information is generally unidirectional. Think of the FRP arrow as part of a digital circuit. The output of a circuit element does not depend on what is connected with it - it simply β€œoffers” a solution to someone who is interested in it. This is also described visually in the primitive signaling functions in the Yampa overview :

Yampa - signal functions

Your situation is different. The condition of the road segment depends on both the next and the previous segments - the cars go from the previous one, but if the cars cannot go to the next, they should stay. It's like a pipe with running water. If you close the pipe at its end, the water stops, and information about it spreads back through the pipe at the speed of sound in the water.

Thus, each segment of the road should have 2 entrances: one of them allows you to say how many cars the next segment can take, and how many cars fall on the previous segment (which should always be less than or equal to the number of cars the segment can take at the moment). This means that the FRP signal flow will be virtually circular. To do this, you need the loops shown in the last image in the above diagram, which are captured by a class of type ArrowLoop . Most likely, you will have a special snap function for road segments that will internally create the necessary loops. Please note that there must be a time delay in the cycle so that it does not diverge, which makes sense, since it takes some time to move from one segment to another.

(Perhaps I will answer an example if I have more time.)

+2
source

Source: https://habr.com/ru/post/987634/


All Articles