arislancrescent / CS-EnhancedHearseAI

Cities: Skylines :: [ARIS] Enhanced Hearse AI :: Oversees death services to ensure that hearses are dispatched in an efficient manner.
MIT License
4 stars 8 forks source link

AI trying serve weird places #2

Open AngelCry opened 9 years ago

AngelCry commented 9 years ago

i can confirm that (small) issue, explained in steam, about weird places, which AI trying to serve. actually i found it while trying make same AI for ambulance. at first i think is i do something wrong while changing source but later i investigate hearses do same sometimes. may be just add checks like IsResidentialBuilding from SkylinesOverwatch? btw i not sure about full list of building types which need to be served (is residental, comercial, industrial for sure, but also things like parks have dead bodies from time to time) Add: after some more investigations i found all weird places coming from checkup list. now i trying understand what logic in this two lists (pickup and checkup). i see check IsBuildingWithDead for pickup list while checkup list dont have it, but is not clear for me, if is intended or not

arislancrescent commented 9 years ago

Oh, the checkup list... That could definitely be part of the problem. So, if there are no corpses within the primary and secondary pickup zones, the hearses will go on patrol. All that means is they go to a random building within the primary zone to check on them. I can see how an electric pole might get picked for this purpose.

With that said, people are reporting that the hearses are simply ignoring corpses within the zones, and going only to those weird places. That won't be due to this checkup list. The only way for checkup buildings to come into play is when the AI can't assign a pickup building from the primary and secondary zones. I can't reproduce this issue. So, it's a lot of shooting in the dark right now.

AngelCry commented 9 years ago

yes, by the way how checkup coded i dont see if it can force hearses to ignore corpses. i just found why hearses pick weird places and confirm this part of sbroadbent message. btw i think exclude this places good idea anyway, even if is not affect efficiency to much - at least because this places have no name, so they looks weird. as you can see in my repo, for myself i try limit checkup by industrial, commercial, residental and office building - works good for me. another thing - looks like AI still need some tweaks. something about pathfinding and/or how they choose target. at first, to be clear, i want to say this thing may come because i use alot one-way roads in my city, but anyway. by watching hearses i notice they may become unable reach target just because they change target before they come to any. i been watching one hearse for about few minutes, how is drive in circles and change target all the time. sadly in this case i feel too weak to make any tweaks by myself. again, i think is not very common and appears only in certain design, like my one, where one-way roads paved in circle (by purpose, i found is good for traffic in general) but is can be one of the reasons for reports about ignore. i nearly sure, this two things not related to each other, people who reporting can just feel like hearses ignore corpses because those places (i.e. they see some of them going to check Electricity Pole and see some corpses not picked up for long time).

arislancrescent commented 9 years ago

I'm actually not sure the hearses are truly ignoring corpses, or just people thinking they are. Just because a hearse drives past a corpse, it doesn't mean the hearse didn't try to pick it up. What happens is that there's probably another hearse close by that claimed it. If this hearse ignores the claim and picks it up anyway, you will end up causing a reroute for the other hearse. This was the original behavior for the mod, but have proven to be very problematic after awhile, e.g., a string of hearses all following each other. What is possible that, soon after this hearse passes the corpse, the other hearse got rerouted anyway for an unclaimed corpse that's on its way. This is very efficient; however, it has a potential side effect: If the hearse had only one slot left, the new corpse will fill that, which causes the hearse to return home. The end result is the original corpse not being picked up.

As for the AI for choosing targets, this would be very difficult to optimize beyond what it is now, without incurring huge performance issues. Ideally, the hearses should select targets based on how far the target is through the road network. This requires pathfinding. Pathfinding is a very very expensive call. CO didn't want periodical pathfinding on vehicles to avoid traffic because the call is very expensive. Can you imagine how bad it would be to constantly pathfind per hearse on all potential targets? Even on the most powerful computer, you'd be lucky to get a few frames per second with an algorithm like that. So, to avoid that, the general technique is to use bee-line distance, i.e., the straight distance between the vehicle and the target. This is a very simple calculation. It's not perfect, but it is better than no rerouting at all and having the hearses travel across the city for just one corpse. I improved it more by using a bee-line in conjunction to vehicle bearing and vehicle heading. This reduces the chances that a hearse would make u-turns. But beyond this, I'm not sure it would be possible.

The thing is I think a lot of people thinking the hearses are ignoring corpses are simply perceiving it that way. In other words, the hearses are fine and efficient on a citywide scale, but people are too focused on one particular hearse. There's a trade off between citywide efficiency and per-hearse efficiency. If I make the AI optimize for per-hearse, citywide efficiency would suffer big time. Similarly, too many people are focusing on the buildings with the death icons, and not realizing that buildings without those floating icons have corpses too. When I optimized the hearses for getting rid of those icons, the entire situation became significantly worse. The same goes for the weird names. If a hearse is checking on an electricity pole, that means there are no other corpse to pick up. It won't affect anything other than what the player sees.

So, I need to be very careful about what I change. If I simply follow what people are saying, the mod will become objectively less efficient, even if it's perceived to be better in the short term. There are a few real problems with the mod that I'm focusing on. I'll wait on the rest until I have very convincing evidence that something is truly wrong, instead of just misunderstandings like those that I have mentioned.

On Mon, May 18, 2015 at 2:03 AM, AngelCry notifications@github.com wrote:

yes, by the way how checkup coded i dont see if it can force hearses to ignore corpses. i just found why hearses pick weird places and confirm this part of sbroadbent message. btw i think exclude this places good idea anyway, even if is not affect efficiency to much - at least because this places have no name, so they looks weird. as you can see in my repo, for myself i try limit checkup by industrial, commercial, residental and office building - works good for me. another thing - looks like AI still need some tweaks. something about pathfinding and/or how they choose target. at first, to be clear, i want to say this thing may come because i use alot one-way roads in my city, but anyway. by watching hearses i notice they may become unable reach target just because they change target before they come to any. i been watching one hearse for about few minutes, how is drive in circles and change target all the time. sadly in this case i feel too weak to make any tweaks by myself. again, i think is not very common and appears only in certain design, like my one, where one-way roads paved in circle (by purpose, i found is good for traffic in general) but is can be one of the reasons for reports about ignore. i nearly sure, this two things not related to each other, people who reporting can just feel like hearses ignore corpses because those places (i.e. they see some of them going to check Electricity Pole and see some corpses not picked up for long t ime).

— Reply to this email directly or view it on GitHub https://github.com/arislancrescent/CS-EnhancedHearseAI/issues/2#issuecomment-102871975 .

AngelCry commented 9 years ago

heh, yep, i already know how what people say may differ from what happen actually :smile: anyway, exclude electric poles and such will be safe, cuz it cant be abandoned in any case. also checkup such places can affect efficiency a bit - in cases, when some of those places are far from most buildings, so hearse need some time to make his way back. though i agree is small bit. as for choosing targets and rerouting - target can be changed only in case when one of target picked up and rerouting happen? if so, i dont see how it can be optimised as well. actually i have one thing in my head, just not sure if is make something better and if is possible at all. i mean split hearses in some groups, by how far they from each other, so rerouting will happen for those small group, not for entire hearses pool. also hearses who choose picked up target need to be rerouted anyway, even far ones. so look like implementing such thing require additional checks/calculations and may hit performance too much, to be usable. as for me, most hard part in modding/testing - is understanding what going on in general. like i see how hearse change target for each few seconds, but dont see why is happen. to be able see it, i need out alot debug info but even when i try just print checkups, fps has been dropped beyond usable :laughing: anyway, thanks for such good mods, with ambulances now i have all services working as good as is possible (i never have any problems with police or firetrucks). next thing i looking for - is a way to restrict cims from visit schools (based on districts as example) but by fast look through available functions/properties i dont found any way to do so. may be you have some idea? PS. while ambulances are done, i wont release it on Steam anyway, so feel free to grab and release it by self if you like (i know you planning make other AIs, but dont know if is will have same logic as hearses)

arislancrescent commented 9 years ago

Just an update, I have been working on a more advanced hearse AI over the past week or so. This new one is being tested right now. It corrects several issues we have talked about here:

Once everything is fully tested, I will update the workshop item and then start making the other AIs that also use this logic.