CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
571 stars 85 forks source link

More parking AI pondering #551

Open originalfoo opened 4 years ago

originalfoo commented 4 years ago

Purpose of this issue is to try and collate a set of tasks relating to desired rethink about how we approach parking AI.

There is a flowchart in old TMPE wiki which gives some idea of how current parking AI works, but might be missing some details (eg. the need for pedestrian access to a parking spot).

This issue should be considered DRAFT status, it is not yet ready for actionable tasks.

Annoyances:

Some suggestions, for discussion, are listed below.

Parking grid

Like vehicle grid, but for parking. #346

Random thought: Investigate the 'parked car juggling' mentioned above - how does game so quickly relocate all those cars to parking spaces? Is there already a parking grid?

Routes as building collections

Named road routes could act as collections of buildings connected to the route.

A building is considered connected if it is within 2 zone squares of a segment on the route, and roughly level with that segment (1 zone square vertically?).

It would be useful to have some way to visualise connected segments. For example, click a building on the map and the connected segments become highlighted.

Car parks

As far as I can tell, we currently treat all parking slots within buildings the same; the AI treats a parking space in a residential building the same as a parking space in a big car park.

If we can identify car parks, we can treat them differently.

Random idea: Maybe ratio of parking slots to employee/resident count could be a viable indicator for car parks?

Park and Ride

See also: https://github.com/krzychu124/Cities-Skylines-Traffic-Manager-President-Edition/issues/47#issuecomment-461817451

Think lane connector tool, but for parking.

Each building gets default connections to nearby car parks. User can customise by adding/removing connections.

Also, each building is connected to one or more routes (see "Routes as building collections" above) which gives us a list of desirable parking lanes and also potential parking slots in buildings along those routes.

Parking reservation

See also: #231

Define a threshold that can be used to differentiate "short" vs. "long" journey, "as the crow flies", to the destination that will require parking.

For example, I'm driving to train station to catch train; I'll need to park. If I'm only a few miles away, I likely know good parking spots, so I head for the parking, not the station. If it's a longer distance, I'm less likely to know where to park, so I head for the station and search for parking once I get there.

Issue her though, is that if they've not pre-reserved parking, they will often drive past several parking places before arriving at destination, and only then go hunting for parking. So ideally path finder needs to say "if parking not yet reserved, and I'm within X range of destination, keep an eye out for parking spaces"

Parking Permits

Who can park there?

Having some control over who can park in a given building / slot / lane might be useful.

Could have some defaults based on building type?

This would help simplify car journeys by minimising pedestrian travel component of the route due to higher percentage of cims parking at the destination building. It would push PT parking in to more general parking areas, such as parking lanes and car parks.

The feature could be extended, via user interaction, to parking lanes too. For example, in residential roads I could set the parking lanes to "Residents only", preventing PT users (in particular) from swamping residential areas.

PT specific stuff

If a cim can't park near their chosen PT stop, what should they do?

Also, we need better way to alert user to fact that people are struggling to park near a given PT stop. While we can look at the info views, that's something we often forget to do. Could we show a notification bubble over PT stops that don't have enough general-use parking? Maybe angry commuters could chirp their discontent (naming station or road name or district as applicable)?

This stuff could be extended to all parking purposes. For example, I'm travelling home but can't find anywhere to park near home - what happens?

krzychu124 commented 2 years ago

work-in-progress parking props overlay prototype:

image

Basic stats about in-range parking spots image

originalfoo commented 2 years ago

freaking awesome!!!

Edit: How does it look on multistory car park assets? :)

originalfoo commented 2 years ago

BTW, that would be super-useful in Traffic Info View.

Also, UI suggestion: Free spaces could be green and filled in to make them more visually distinct from "taken" parking spaces.

Another thing I notice recently, btw, is that some assets have multiple parking spaces directly on top of each other; not sure if that will causse any problems? I think it was one or both of these - the result is cars parking on top of each other:

I ended up having to remove the superflous parking spaces using BOB mod.

krzychu124 commented 2 years ago

I don't have any in that city but overlays are rendered at correct height😄 As a part of overlay improvements I'll try to render 3d boxes

With regards to parking spaces on top of each other... if a car will park on it the other parking spot won't be available since CheckOverlap function will fail (3d box area to fit the vehicle won't have enough space).

Btw, have you noticed that with TM:PE and ParkingAI we don't see cars with trailers?

originalfoo commented 2 years ago

With regards to parking spaces on top of each other... if a car will park on it the other parking spot won't be available since CheckOverlap function will fail (3d box area to fit the vehicle won't have enough space).

Is that in new code or existing code? Because I only noticed problem with those buildings because cars had parked on top of each other; the superfluous parking spaces weren't perfectly aligned, there was a slight offset if that makes any difference?

Btw, have you noticed that with TM:PE and ParkingAI we don't see cars with trailers?

I see cars with trailers, but when car parks the trailer dissapears. I guess if the trailer was retained the vehicle would need to use roadside parking or we'd need some "long parking slot" assets heh.

krzychu124 commented 2 years ago

Is that in new code or existing code? Because I only noticed problem with those buildings because cars had parked on top of each other; the superfluous parking spaces weren't perfectly aligned, there was a slight offset if that makes any difference?

Ok, I've checked the source and it seems that misalignment may cause that issue, since calculations are not super accurate

I see cars with trailers, but when car parks the trailer dissapears. I guess if the trailer was retained the vehicle would need to use roadside parking or we'd need some "long parking slot" assets heh.

That would look cool and also only tourists use cars with trailer (see _ResidentAI GetVehicleInfoPatch).

DaEgi01 commented 2 years ago

wow, pretty cool man!!

originalfoo commented 2 years ago

My cims created a 6 wheel mashup of a VW Camper van and a Dodge Ram in the supermarket car park.

image

krzychu124 commented 2 years ago

So here is that situation with overlapping parking spots/decals?

originalfoo commented 2 years ago

Yup, two parking spots one on top of the other. It's one of the "Big Parking Lot Roads" assets this time.

krzychu124 commented 2 years ago

@aubergine10 while debugging #1527 I noticed something that may require a discussion:

Should we try to make them actually usable? I think that one or two patches and I could assign them either to nearest building or even better to the painted district (will be the cleanest and probably the fastest option). If too complex to store calculated inf it could be done on load (after short round of time measuring benchmarks).

I see it as background process (could be woken up on demand), reacts on change of painted district area and could try to collect standalone props (maybe even mark as occupied if any) then we could use that "collection" and pick random parking prop when cim wants to go to target building which is located within the area of painted district. I already have some tools to visualize things like parking occupancy so could be a nice addition to districts info-view with help of upcoming Overlay Manager

What do you think? @chameleon-tbn any thoughts?

originalfoo commented 2 years ago

Do people use the raw props in-game? Would it be better to have part of the new parking overlay highlight them on the map so user knows where they are and can replace them with building-based parking spaces?

IMO if we were going to make props work, the time would be better spent on making seating props work - particularly on paths, quays, or in parks, etc.

krzychu124 commented 2 years ago

IMO if we were going to make props work, the time would be better spent on making seating props work - particularly on paths, quays, or in parks, etc.

They are not working because of the same reason - they are not a part of any building and cims require special state to use them. Good idea actually... why no one tried that yet? 😂 Is there any issue for that (here or in other repo (?wish list))? I thought about props because still no mod extending the building limit as opposed to props and I'm not saying that anyone should swap building parking spaces in favor of parking decals. Additionally with a little fiddling PO'ed parking props(decals) could be used too so totally outside game limits. It's just a matter of good enough, flexible structure for fast querying/spatial search.

lokpro commented 2 years ago

I am just sharing.

I am a user, not a dev of any mod. I can code, but don't know how nor have time to start.

chameleon-tbn commented 2 years ago

BOB is with next Version Not Only able exchange the decals but to add new ones to Buildings and Networks. Within this process we will also work on functionality....

Invisible markers should be also just as addable as any other prop - that's the plan! And I suspect algernon is already well ahead of this compared to TMPE , anyway. :)

originalfoo commented 2 years ago

Being able to add/move/remove markers within buildings will be awesome! But I think that's different to what @krzychu124 was considering - the placement of "raw" makers anywhere on the map (I just realised another issue there is can cars reach those markers?).

I just had another idea - why not making it possible to have functional parking markers in network segments (lane props)?

For example, a segment replaces it's normal parking lanes with parking markers. I can now do all sorts of crazy stuff with BOB, for example:

chameleon-tbn commented 2 years ago

Once we have in the add props (single instances - we are atm in the last step of dev for that) we can do same for single segment instead of all of the same road. Then you can just forbid parking with TMPE and add working parking decals in the angle and position you want with BOB... paint with IMT or add marking decald... Globally we can already do this...

I know that placing everywhere would be an option... but afaik adding it to a network or building is the better way for the game. BOB also can exchange globally trees and props and even resize them globally... so even a placement of a working marker would just match into BOB imho

krzychu124 commented 2 years ago

After another round of debugging I noticed potential problem related to parking spot search:

image

It can search even further down right bottom instead of trying roads above the building

Similar weird selection is in below configuration of target building and two-way roads with roadside parking (orange). Green lanes are always selected first then usually car is going around searching the parking lane located at bottom right segments relative to vehicle current position and target building 🤷‍♂️ image

I think it might be caused by spiral loop traversing segments always clockwise so I think we should create second variant of spiral and just randomize it like randomizer.Int32(2) == 0 ? CW : CCW so it should start distributing parked cars more evenly which in turn should greatly speed up searching for free parking spot.

I'll do few isolated tests but this problem might explain why they go around target building multiple times skipping a lot of potentially empty spots/parking lanes. Another problem is with search time for building parking prop. I'm experimenting with randomization based on Simulation accuracy settings but maybe we should add new dropdown dedicated for ParkingAI accuracy and try to optimize existing code around that setting?

originalfoo commented 2 years ago

randomize it like randomizer.Int32(2) == 0 ? CW : CCW

Would it be faster to use vehicle ID, eg. (vehicleId & 1) == 0 ? CW : CCW? The vehicle ids are already effectively randomised by vanilla code.

Another problem is with search time for building parking prop

Is it using the building grid? I noticed that buildings have a Flags2 which is hardly used - maybe use two bits, one to indicate building has no parking props, the other to indicate it does have parking props... if neither bit set, it's not been scanned yet, otherwise you can know quickly if a building contians parking props prior to iterating it's props array. Might have issues with BOB mod if suddenly props / probability changes for a building, but that's on user-interaction and so possibly something we could deal with?

krzychu124 commented 2 years ago

(vehicleId & 1) == 0 ? CW : CCW

So for one vehicle trying 10 times it will always search either CW or CCW 🤔

Is it using the building grid?

Yes.

I noticed that buildings have a Flags2 which is hardly used - maybe use two bits, one to indicate building has no parking props, the other to indicate it does have parking props...

I'm talking about building that contains parking props - there is already available info.

The thing is a function searching for props is trying to find closest prop - with a lot of props occupied it may take ages (few ms) to search the area (each step sim is simulating 4095 cim instances - may create huge lags or stuttering since search is on sim thread)

Important thing: It always search for roadside parking then building prop and after that compares distance and usually takes the closer one (slightly randomized by GlobalConfig values). Searching for space on such lanes is usually at least 10x faster compared to searching for building prop -> parking lots contain a lot of buildings to check and info about parking spot is not so useful if there is no additional info about remaining spots. Spiral loop grid cell is big enough for >10 buildings but only one or two segments will fit. I'm pretty sure I saw TODO to randomize search based on SimAccuracy.