Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State machine for separate turning lanes. #567

Closed
kianzarrin opened this issue Nov 23, 2019 · 32 comments · Fixed by #755
Closed

State machine for separate turning lanes. #567

kianzarrin opened this issue Nov 23, 2019 · 32 comments · Fixed by #755
Assignees
Labels
enhancement Improve existing feature feature A new distinct feature LANE ROUTING Feature: Lane arrows / connectors
Milestone

Comments

@kianzarrin
Copy link
Collaborator

In #537 I implemented lane arrow separator to allocate dedicated turning lanes. The lane distribution is according the the number of turning lanes in each of the directions⬅️ ⬆️ ➡️. A more preference is given to the left and less preference is given to the right.

Now when segment has two lanes you automatically separate lanes to(right hand traffic): ⬅️ + ⬆️ || ➡️. This is good for quick-setup of timed traffic lights.
I think it would be nice to be able to switch to ⬅️ || ⬆️ + ➡️ after another alt+click on (#538 (comment) ). This would be good for a different setup kind of timed traffic light .

Screenshot (30)

because of a bug the LHD is the opposite way around (#564 (comment) ).
Screenshot (0)

The state machine can also dictate how the lanes are distributed. should we give preference to left in one state and preference to forward in another state? should this be in options menu? or should we keep things simple?

@kianzarrin kianzarrin added feature A new distinct feature triage Awaiting issue categorisation labels Nov 23, 2019
@kvakvs
Copy link
Collaborator

kvakvs commented Nov 23, 2019

State machine and example implementation of new Lane Arrows you can find here #391 . SM is just 1 module to drop into your TM:PE project.
The FSM (finite state machine) module is here https://github.com/kvakvs/Cities-Skylines-Traffic-Manager-President-Edition/blob/canvas-gui/TLM/TLM/Util/GenericFsm.cs
The usage is here https://github.com/kvakvs/Cities-Skylines-Traffic-Manager-President-Edition/blob/canvas-gui/TLM/TLM/UI/SubTools/LaneArrows/LaneArrowTool.cs

@kianzarrin
Copy link
Collaborator Author

State machine and example implementation of new Lane Arrows you can find here #391 .

Wow! That's so cool. In any case my FSM is mutually exclusive and is for the quick-edit feature.

@originalfoo
Copy link
Member

A more preference is given to the left and less preference is given to the right.

Using terms "left" and "right" will cause confusion due to different sides traffic can drive on (LHT/RHT, or RHD/LHD). Elsewhere we came up with following driving-side agnostic terms:

  • Nearside -- the left or right direction a vehicle can turn without crossing oncoming traffic
    • Example: The side you would exit on the highway
  • Farside -- the opposite direction to near side

When applying state machine it might be useful to think in those terms, rather than driving side specific "left/right".

For example: On a map where vehicles drive on the left, the nearside lane would be the left lane. The most common turning lane will likely be the nearside lane. In UK that would be left lane, in US it would be right lane.

@kianzarrin
Copy link
Collaborator Author

from #671 :

From steam user adam.ruscoe:

Not seen this noted as an "issue" on the thread as yet...
I love the ctrl click set everything to one lane per action, but on a two lane each way section, with driving set to the right hand side the mod currently sets the right hand lane as turn right, with the left hand lane being turn left and straight on.
Given than on a RHD road where you have priority you may have to wait to turn left, but don't wait to turn right or go straight on this seems incongruous with how it is mostly laid out in real life (and how I always lay out my cities in game)
Admittedly I've literally just downloaded it and come across this so there may be a setting somewhere I've missed, but as a default I can see that causing more issues than less.

Issue reported for STABLE v11.0
I've asked for screenshots and any other infos to be posted here.

@kianzarrin
Copy link
Collaborator Author

  1. When you are trying to open interlocking traffic jams its best to get as many cars out of the way as possible. turning right is easy so let's get rid of those cars first.
  2. Argument can be made that turning left is hard and going straight or turning right is easy so its better to do that first. I admit this is how it normally works in the world so I should probably made this one the default.

Its hard to know what to do when you have only two lanes but three directions! We really need a state machine.

@originalfoo
Copy link
Member

Generally with 2 lanes and 3 directions I'd have the turning lane go the way of the near-side turn.

Maybe an Alt key modifier that tells the applicator to use far-side lane instead?

@kianzarrin
Copy link
Collaborator Author

@aubergine10 so you didn't like the state-machine approach?

PS: now I remember why I made that decision! its particularly good for timed traffic lights to have extra right turn cycle.

@originalfoo
Copy link
Member

I think a state machine is required, it will help keep code sensible.

@kianzarrin
Copy link
Collaborator Author

  • if the number of source lanes is more than 3 and not multiple of 3, priority to have more lanes is: far turn, forward, near turn. (far turn is slowest so it gets more turn, in TTL near turn is green for 2 steps, so it needs less lanes)
  • if there are 2 source lanes, I do the opposite: near turn gets dedicated lane. (to get extra turn at TTL)

The question is in the lane arrow tool how the step machine should work?
approach 1:
state 1: TTL recommended (2 lanes: naer-side priority | 3+ lane:s Far-side priority)
state 2: alternate TTL *(2 lanes far-side priority | 3+ lanes forward-priority)
Ignore this if number of lanes is multiple of 3 on all node segments.
step 3: clear all values to default (or undo #568)

  • alternate TTL is when far turn gets a dedicated step, then straight and right are bundled together.

approach 2:
state 1: 2+ lanes => far side prioirty
state 2: 2 lanes => near side priority | priority 3+ lanes =>forward priority.
Ignore this if number of lanes is multiple of 3 on all node segments.
step 3: clear all values to default (or undo #568)

Approach 1 is more consistent if you have TTL while approach 2 is more consistent if you don't have TTL.

which one should I go for?

@originalfoo
Copy link
Member

Can we let user cycle through options?

For exmaple, if user gets far side turning lane, but they wanted nearside, they just repeat the applicator to get it's alternate result?

Similar to how Shift+S on lane connectors will cycle a segment node through a) all lanes ahead only, b) one side ahead only, c) other side ahead only

So an applicator starts with what it thinks is best, but if there are alternatives user can just repeat it to cycle them. Or add an Alt modifier to the applicator to alter it's decision making.

@originalfoo
Copy link
Member

Also, regarding the recent report linked above (#671) I don't think user was using TTL on that junction they were testing with.

@aruscoe
Copy link

aruscoe commented Feb 15, 2020

I'm the user who was quoted in #671 and I wasn't trying to create a TTL, it just seemed odd that the lane which had to turn against traffic was also being used the be a straight on lane.

kianzarrin commented 7 days ago
When you are trying to open interlocking traffic jams its best to get as many cars out of the way as possible. turning right is easy so let's get rid of those cars first.

I may not have played as much as some others, but on a RHD road where priority is set it tends to be nearside turning, straight on, offside turning in that order and by having OST and straight ahead in the same lane you're restricting the two slowest to sit until oncoming traffic clears
Unless the NST road is blocked you're clearing two directions by having NST and straight ahead, but that's just my preference.
As others have said, having it toggle is a good idea (or allow a preference setting in options)
Other than that your mod is the best in the game by far... Do agree we could do with a lot more capability in the rail sector, but then the game isn't geared up for that it seems

@originalfoo
Copy link
Member

OST = off side turn? = far-side turn?

@aruscoe
Copy link

aruscoe commented Feb 15, 2020

Yes. If you drive on the right then turning across the traffic, ie left
From what I've seen in game you're much more likely to have issues crossing oncoming traffic than anything else

@s2500111
Copy link

s2500111 commented Feb 24, 2020

When traffic is driving on the right, left turns are conflicting and should be separated over right turns (which conflicts only with pedestrians).

Would be even greater if you have both options, but separating left turns (or right turns for traffic driving on the left) is the reasonable first thing to do in 90% of all cases.

points of conflict

points of conflict 2

Red crosses in these pieces of paint art mark the conflict points, green arrows are free flowing directions, red arrows mark the direction which have to yield due to conflicts. Yellow arrow indicates possible obstructions, which you usually want to avoid.

@kianzarrin
Copy link
Collaborator Author

When dealing with interlocking gridlocks we want to get as many cars out of the gridlock as possible. Cars taking the short turn are easiest ones to pump out. Mixing it with going straight causes problems. Also if there is a timed traffic light right turn usually takes 2 steps so it should be separate.

In the real world I see slip lanes on the right. Well this game does not have slip-lanes but allocating dedicated right turn is the next best thing.

If the roads are not jammed and the objective is to reduce delay on a fast floating road, then your approach is the better one. then again in such situation not separating lanes at all might be the best approach.

@s2500111
Copy link

Right turn takes two steps? May you elaborate on that?

Afaik there are two problems with right turns in the game:

  • the corners are really sharp, leading to very slow right turns
  • there are way more pedestrians then I've ever seen IRL, which slows cars down significantly. This affects all directions without lights and all turns with lights

You also can add slip lanes, but they take a lot of time to set up, but work really well if you're doing it right.

Real gridlocks are often a problem caused by bad planning in the first place and mostly not solveable by any standard-lane-arrow config, so that should not be a concern at that point. In my experience, separated left turns are way more helpful then separating right turns, since - as stated before - combined straight and left turns result in chaos.

@s2500111
Copy link

I looked on some intersections in my city. I found not a single one with combined left turn and straight, but separated right turns. Most intersections also had no slip lanes.

You may notice, that pedestrian crossings are set a few meters back into the road, allowing for 1 to 3 right turning cars to clear the path for vehicles going straight. This is lacking in the game and may cause some problems that are not occurring in real life. On the other hand, the problems aren't that big, as I use the same design as in those screenshots in my game cities, which have always between 70 and 80% traffic flow.

The current design also doesn't go well with any traffic light pattern, since it isn't allowing protected left turns. Which leafs us with the 2 phase vanilla-options, were left turning traffic is obstructing vehicles going straight, leading to a lower capacity, or a 4 phase design, where every direction gets a phase. In this case - and only in this case - this setup makes sense, since right turning traffic is obstructed by pedestrians, while left turning and straight are not. But it's also not very efficient to do that at all and I've never seen it IRL ...

ex1
ex2
ex3
ex4
ex5
ex6
ex7

@aruscoe
Copy link

aruscoe commented Feb 25, 2020

When dealing with interlocking gridlocks we want to get as many cars out of the gridlock as possible. Cars taking the short turn are easiest ones to pump out. Mixing it with going straight causes problems.

OK, I'll answer this to the best of my knowledge...
Blockage by pedestrians is true of all directions so that should be set aside

Turning right : traffic can be obstructed only if the road to the right is gridlocked - 1 obstruction
Straight on : traffic can be obstructed only if the straight on road is gridlocked - 1 obstruction
Turning left : traffic can be obstructed if the road to the left is gridlocked, if the road coming in the opposite direction is gridlocked or if the road in the opposite direction is busy and flowing - 3 obstructions

Consider the SECOND car in a queue...
In a ┤┌ setup you have 1 obstruct to turn right but 4 to go straight on if the car in front is turning left
in a ┐├ setup the left hand lane has three possible obstructs but the right has a maximum of two

I agree with S250111 in that i don't have any junctions setup with straight on and "opposing turn" in the same lane

@kianzarrin
Copy link
Collaborator Author

@aruscoe when cars wait too long they give up and go through the junction and block it. so going stright

During timed traffic right right turn gets 2 cycles. So getting rid of these cars is easiest. Turning right is faster in general.

Straight on : traffic can be obstructed only if the straight on road is gridlocked - 1 obstruction

Cars turning left from opposite direction can block you. in CS they don't really follow the rules all too much!

I don't really care that much if it is the first cycle of state machine or second. @aubergine10 can we put this to vote?

@aruscoe
Copy link

aruscoe commented Feb 25, 2020

@kianzarrin

During timed traffic right right turn gets 2 cycles.

I don't use timed traffic lights in my cities as they never seem to work as expected, so I am talking about traffic flow on a non-lighted junction

Cars turning left from opposite direction can block you.

My original question stated that the road you're on has priority. Haven't seen cars passing stop or wait signs although on a non prioritized route you are correct, though in that case I would generally be setting the lanes so that conflicts are avoided (not expecting the mod to do this for me)

@s2500111
Copy link

Ok, so now you're more clear, we're talking about timed traffic lights as the reason for this.
In this case, cars turning right can go, if cars going straight are moving, or cars in the crossing road turn left. Which doesn't work, if they also go straight, because then right turning cars don't get two conflict free cycles. This only works, if you're able to separate the straight from the left turning lane. Also for this to be important, there needs to be a significant amount of cars turning right, which is pretty specific.

The standard case for main roads should always be the assumption, that the majority of cars are going straight on and only a few turn right or left onto minor roads. So getting people straight over a junction should be the main concern, since most cars should do that. In every other case, user input is required. At least for now, I can think of algorithmic approaches to solve this.
For getting as many people straight over a junction as possible, it is necessary to remove as many conflicts as possible. Right turns aren't a conflict with going straight, left turns are.
The solution is relatively easy: long (straight + right) phase, short protected left turn phase.

This feature shouldn't solve complex junctions, but rather make it easier to work with all the small intersections where the amount of traffic should not make manual optimization necessary. It should be using common best practice for traffic planning and not some specific case, which probably isn't applicable in the places where this feature is most useful.

@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Feb 25, 2020

@aruscoe I don't use timed traffic lights in my cities as they never seem to work as expected, so I am talking about traffic flow on a non-lighted junction

maybe you should try out the quick setup feature for timed traffic lights. It works!

@s2500111 Timed traffic lights quick-setup automatically fixes the lane arrows anyway so its unaffected by state machine.

It depends on the context. If I want to use it for cities that I build I would rather a dedicated left turn. if I want to fix other peoples gridlocked cities Id rather a dedicated right turn. But to be honest if there is that much traffic I am going to use 6 lane roads anyways!

So far all customers have complained about the current state of matters and customer is always right! but the problem is Customers who are happy with the current situation are not going to complain. I am worried once I make the changes there is going to be new people here advocating otherwise.

@aubergine10 You are good at customer relation. what do you think?

@originalfoo
Copy link
Member

I don't really care that much if it is the first cycle of state machine or second. @aubergine10 can we put this to vote?

Quick scan of google maps to check most common turning lanes for junctions without traffic lights:

  • Manchester, UK: Far-side
  • Berlin, Germany: Far-side
  • Ontario, USA: Far-side
  • Québec, Canada: Far-side
  • Bern, Switzerland: Far-side
  • Dubai, USA: Uhm...? I think they might have banned far-side turns, and women drivers.
  • Singapore: Far-side

By no means exhaustive, but it looks like far-side turns are most common dedicated turn lanes in that selection of cities.

I've not yet checked what situation is when there's traffic lights. I think with traffic lights there is an additional situation to factor, and that is whether "turn on red" is allowed. If so, a dedicated near-side turning lane would make it much easier for that traffic to flow when lights are red.

Also depends on number of lanes available? So states could be something like:

  1. Far-side only
  2. Near-side only
  3. Both far-side and near-side (if 3+ lanes)
  4. No dedicated turn lanes

It might be that we end up with some new mod options, such as:

-[ ] Prefer near-side turning lanes at junctions
-[ ] Prefer near-side turning lanes at traffic lights which allow turn on red

@s2500111
Copy link

It might be that we end up with some new mod options, such as:

-[ ] Prefer near-side turning lanes at junctions
-[ ] Prefer near-side turning lanes at traffic lights which allow turn on red

Seems like a good solution to me.

@originalfoo
Copy link
Member

There's some stuff here that might be relevant: #63 (comment)

Generally the far-side turn is unprotected (unless there's traffic lights or something to control flow of traffic); vehicles making unprotected turn will have to yield, creating a queue, so dedicated turning lanes are used to split that queue out of the main traffic.

img

@kianzarrin kianzarrin self-assigned this Feb 28, 2020
@kianzarrin
Copy link
Collaborator Author

I think my allocation of dedicated turning lanes is my post popular work so far! simple and effective. Its time to prioritize improving this.I guess it will take me half a day to (RHT):

  • two lane (each side) road: first phase, dedicated left | second phase, dedicated right turns.
  • 4 lanes or more (laneCount %3 !=0): first phase: prefer forward then left | second phase prefer left then forward.
  • the calculation for bus lanes will be separate than the calculations for normal lanes(ill post pic). this has been bothering some users.

@originalfoo
Copy link
Member

originalfoo commented Feb 28, 2020

laneCount %3 !=0

Is that faster than laneCount > 3 ?

@kvakvs
Copy link
Collaborator

kvakvs commented Feb 28, 2020

These two predicates have entirely different meaning.
lanecount %3 != 0 means that it will be true for 1 2 4 5 7 8 10 11+
lanecount > 3 will be true for 4 5 6 7 8 9 10 11 12+

@s2500111
Copy link

s2500111 commented Feb 28, 2020

I think we shouldn't extend the scope on roads wider then 3 or 4 lanes, since in these cases it really starts to depend on the environment and where routes go. In this case, >2 is better, since it handles all roads with enough lanes in the same manner.

Even though a completely automatic optimization of the lane arrows and traffic lights / priorities depending on the traffic volumes would be awesome.

@kianzarrin
Copy link
Collaborator Author

I already support roads 4+ lanes. The remainder goes to far turn. now with the state machine the remainder goes to straight lane.

@kianzarrin kianzarrin added LANE ROUTING Feature: Lane arrows / connectors enhancement Improve existing feature labels Feb 28, 2020
@kianzarrin
Copy link
Collaborator Author

I created issue #752 about what should happen on bus lanes. for the time being it will alternate in the state machine: mixed/separate calculations

@originalfoo originalfoo added this to the 11.2 milestone Mar 2, 2020
@originalfoo originalfoo modified the milestones: 11.2, 11.3 Mar 28, 2020
@originalfoo originalfoo modified the milestones: Planned stuff, 11.4.0 Apr 14, 2020
kianzarrin added a commit that referenced this issue Apr 14, 2020
fixes #567 dedicated turning lanes now has a state-machine of 2-states:
- 2 lanes: dedicated far turn | dedicated near turn
- 3+ lanes: favor left then forward | favor forward then left
- car+bus lanes: mix bus and car lanes | calculate bus arrows and car arrows separately

Notes:
- I moved code to dedicated UTIL class.
- I polished the code to use the same code path for near and far turns reducing code complexity.
@originalfoo originalfoo removed the triage Awaiting issue categorisation label Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve existing feature feature A new distinct feature LANE ROUTING Feature: Lane arrows / connectors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants