[Idea] How to solve the AI problem

(previously 'DEVELOPER') Private forum for registered community members. To register, please visit www.prison-architect.com/register.

Moderator: NBJeff

sebastiannielsen
level2
level2
Posts: 79
Joined: Wed Sep 24, 2014 2:01 am

[Idea] How to solve the AI problem

Postby sebastiannielsen » Mon Oct 13, 2014 1:08 am

I have a idea how the game could solve these AI problems with Cooks, kitchens, yards and such that causes prisoners to run over the whole map for the "incorrect" canteen:


Here, im going to present a different proximity idea for Rooms than for Objects.
Since, in 100 % of cases, it would be smarter for a prisoner, to select the room that he is allowed to visit, NEAREST to his own assigned cell, this calculation could be done once and then saved in the data for that specific prisoner.

This means, for rooms, we could do a more Heavy calculation, it does not matter if the calculation takes a second or two, because they are rarely done.

This data, needs to be calculated for ALL rooms, for a specific prisoner, everytime a:
Prisoner is taken into the prison.
A prisoner's cell is reassigned (by clicking the prisoner and right clicking in a new cell).
The prisoner gets a new cell for some other reason, for example you deassign a occupied cell.
Each time a prisoner gets a new security level, either manually by player changing it, or automatically via certain misconducts.

So for example, everytime a prisoner arrives, the game should calculate these rooms NEAREST to prisoner's cell, with a security level matching the prisoner:
Workshop
Kitchen
Yard
Storage
Deliveries
Export
Garbage
Infirmary
Shower
Canteen
Laundry
Visitation room


This data, needs to be calculated for ALL prisoners, but for a specific room, everytime a:
room is deassigned. (Eg you use the room tool and right click to remove a room or parts of it)
room is assigned. (Eg you use the room tool and draw a Square to make a room)
A room becomes unuseable or useable. (room requirements)
A rooms security level is changed using the deployment tool

So for example, if you remove a shower room, then the game should recalculate the nearest shower room for all prisoners, so once its shower regime, the prisoner should select the shower room nearest to his cell.
Or if a prisoner gets sick or injured, the prisoner, should go to the infirmary nearest to his cell. (not nearest to his current location).
Same with overdose, the guard should take the prisoner to the infirmary that is nearest to the prisoner's cell.
That is the most logic situation.
Basically, the prisoner has a infirmary he "belongs to", same with Everything else.

Since all prisoners now "belong" to a canteen, then it would be easy for the game to calculate how much food each canteen should get.

Same here with kitchens. For kitchens the game could calculate the nearest canteen. And then that canteen "belongs" to that kitchen. Eg, that kitchen will never do food for canteens not "belongning" to that kitchen.
(but of course, multiple canteens should be able to belong to one kitchen, but not the other way around, one canteen should NOT be able to have multiple kitchens).

Same with visitors. Visitors should then select the visitation room that is nearest to the prisoner's cell. Does not neccessary need to be the nearest table, just the nearest visitation room to the prisoner's cell.



For objects, it would be smartest to calculate the shortest path to nearest object, based on prisoners CURRENT position.
BUT if the regime or condition requires the prisoner to go to, or be escorted, to a specific room, it should take precendence, eg a injured prisoner will not go to the nearest Medical bed, instead it will go to the infirmary nearest to his cell, then he will take the nearest bed (that is vacant of course) from here.


Also for objects, there should be logic so occupied objects are ignored completely, so if there is 2 showers, one is occupied, the other prisoner should not wait for that shower to be vacant, instead the prisoner should select the shower that is vacant from the beginning. (and if other prisoner did select a occupied shower, he should recalculate the selection)



Another idea:
Anything that is placed inside a cell should be strictly private to the prisoner who has that item in the cell. Prisoners should never ever run into other's cell to for example Watch TV.

And anything in a prisoners cell should take precendence when the prisoner does have FreeTime, eg, if the prisoner wants to Watch TV, and he has a TV in his cell, he should Always aim for his cell TV instead of occupying a TV in the canteen, even if the canteen TV is closer. Same with showers, pool tables, exercise Machines, phones, chairs and such.
BGK
level1
level1
Posts: 13
Joined: Mon Sep 29, 2014 11:36 pm
Location: France

Re: [Idea] How to solve the AI problem

Postby BGK » Mon Oct 13, 2014 2:02 am

The problem with this idea is that it can only work if the prisoner is in his cell whenever he needs to go somewhere, and that's not the case.
As soon as the prisoner move somewhere, like going in a workshop, going in the infirmary to get healed, being taken to the security room for interrogations (CI) and so on, the calculations need to be reprocessed:

Let's say the prisoner is in his cell, freetime comes. He want to exercise, so he heads to the nearest yard (from his cell). Now eat time comes, so he need to go to the canteen. What if the nearest canteen from his cell isn't the nearest canteen from where the prisoner is now located?
So you can either make the calculations in real time to correct it, but in this case the whole purpose of those calculations is lost (meal already ready in the other canteen for example); or you stay with the static calculations meaning that you can't say if the prisoner will head for the nearest room available (from where he is).

Depending on the prison layout, the outcome of applying this idea could range from a well optimized AI to a complete disaster.
sebastiannielsen
level2
level2
Posts: 79
Joined: Wed Sep 24, 2014 2:01 am

Re: [Idea] How to solve the AI problem

Postby sebastiannielsen » Mon Oct 13, 2014 3:52 am

BGK: Even if it would be a Little longer to his canteen, it would still be a better option to have that the prisoner selects his canteen nearest to his cell with regards that most of the time, the prisoner is in the near vicinity of his cell.

Many prisons also evolve around different "wings" and these "wings" might share a yard, thus it would still not be a good idea to let a prisoner go to the nearest canteen from his current position because then he walk into a completely unrelated building.
So I Think, still it would be best to assign ROOMS (even security room and such) based on the location of the prisoner's cell.
The good thing with such static calculations is that they can be a bit heavier as said, and more correct based on Walking distance/pathfinding instead of "air distance".

A example of calculation could be done in this way:
Calculate the nearest canteen from cell based on air distance, This are calculated using number of Squares from cell center to nearest canteen boundary.
Then calculate the next nearest canteen from cell based on air distance.
After this, do a Walking pathfind to both these canteens and find out which is nearest Walking distance.
If the first canteen is deemed nearest, stop here and assign the first canteen to prisoner.
If the second canteen is deemed nearest or both canteens have same air distance, remove the canteen from the list of possible candidate canteen for this prisoner, which has a longer Walking distance. (This means that there might be a third canteen which has a shorter Walking distance than the first/second)
Redo the calculation for the third nearest canteen and then "compare" it to the first or second canteen.
Repeat until you get a canteen whose Walking distance is longer.
Select the canteen with shorter Walking distance.
Save in prisoners datatable.

However, objects could be calculated based on distance in realtime based on where prisoner is, so if its freetime, he would select the nearest exercise machine (unless he have a exercise machine on his cell, then he would prioritize that) or TV, pool table or whatever he wants to use.


Since all rooms is then selected based on cell vicinity, then he would Always be sufficently near his cell so he could select the next room based on cell vicinity.
dooferorg
level1
level1
Posts: 24
Joined: Mon Aug 11, 2014 8:40 pm

Re: [Idea] How to solve the AI problem

Postby dooferorg » Mon Oct 13, 2014 4:41 am

I like that idea of having a prisoner 'belong' to his local rooms and so he will use those amenities. Certainly don't want them just picking the nearest to their position or a random one.
BGK
level1
level1
Posts: 13
Joined: Mon Sep 29, 2014 11:36 pm
Location: France

Re: [Idea] How to solve the AI problem

Postby BGK » Mon Oct 13, 2014 7:33 pm

To be honest, I actually find your idea to be pretty neat and well imagined for regular, conventional prison layout. Problem is, I pretty much summarized the concerns I have about it:
BGK wrote:Depending on the prison layout, the outcome of applying this idea could range from a well optimized AI to a complete disaster.


I don't think that it's smart to design a AI based on the assumption that it will work quite alright for conventional layouts, but rather horrible for highly custom/non-conventional layouts, especially since this game is somewhat advertised as sand-boxy.

In my opinion, the AI should be very "general purpose", meaning it shouldn't be that optimized, but could work alright for almost any layout/situation.
However players should have the tools to heavily customize this AI, like setting preferred room destination for prisoners in cell blocks, setting the number of desired cooks in kitchens, either statically or through a distribution percentage, be able to set how many meals should be prepared either statically, or through highly custom rules using math operands and keywords like {number of prisoners in area [#area]} + {occupied cells in cell-block[#CB1,#CB3,#CB7]} - {meals planned in kitchen [#Kitchen5]} - {total prisoners[med,max]} - {prisoners in solitary zone {#SZ2,#SZ8]} + {5 * total prisoners [min,PC] /100}.
Laundries should be connected to cell blocks with a system like the one for logic circuits, so the player can manually set relations between laundry rooms and cell blocks.
Well, you get the idea.. Yeah, highly "custom".
Also some presets should be available for easy setup, especially for early game.

Don't get me wrong, I really think your idea is nice for 90% of layouts, and would be an nice upgrade for many prisons. I just think that's not the best approach for this game.

Also, I encourage you to continue to provide explications and arguments because that's a rather important subject for this game, and I think many people would eventually agree with you or would be interested to see additional information on this idea of yours.

Apologies for the mediocre English, but I guess you got the general idea of my thoughts.
TechyBen
level0
Posts: 1
Joined: Mon Sep 22, 2014 10:28 pm

Re: [Idea] How to solve the AI problem

Postby TechyBen » Mon Oct 13, 2014 9:10 pm

Not wanting to mention that "other" game as my first post. But have you seen how they do it?
They zone off each part of the map into a grid. That way the AI search down a tree that gets more detailed as it goes. They only have to search for the "grid" first, then the "room" then the "item in the room". It's much quicker than searching all items on the map for every path finding request. They only need to search every grid (for example 100 grid boxes) then every room in that grid (for example 4 rooms) then each item in that room (for example 20 items). That's much quicker than 100*4*20= 8000 items searched for every time they path find.
djdunn
level1
level1
Posts: 14
Joined: Sat Nov 13, 2010 10:25 am

Re: [Idea] How to solve the AI problem

Postby djdunn » Wed Oct 15, 2014 11:22 pm

Simplest way to make the kitchens work without a whole lot of fancy and complicated formulea is to

1) allow the attaching of canteens to kitchens,
2) kitchens only cook enough food to fill up each serving table in the assigned canteens once per meal
3) each kitchen only orders enough food for the entire day once + a small % extra since some is usually dropped on the floor or whatever
4) distribute cooks to each kitchen depending on the % of serving tables each kitchen cooks, so 10 cooks 10 serving tables, 2 kitchens, 1 kitchen cooks food for 2 serving tables, 1 kitchen cooks food for 8 serving tables, the later gets 8 cooks the former gets 2.

this way you don't need to be a math major or go to college to figure out how to work the kitchens.

this way nothing is changed based on food variety or quantity, quantity just changes how much each prisoner gets from the serving tables and variety is the same it is now.

your not counting prisoners cell blocks or changing the formula based on if its min med max or supermax number of kitchens or anything of the like. each kitchen just orders, cooks and serves food to assigned serving tables. And its simple for the player to understand, attach canteen to kitchen check, serving tables check, need more food build more serving tables, food not getting cooked fast enough more cooks/cookers, food sitting on floor more fridges. Simple low learning curve player watches a meal and says hey 1 cooker and 1 cook is way not enough to cook food for 300 people... maybe i should add more cookers and cooks. hey theres not enough food being served in the canteen, maybe i should add another serving table since this table looks full and its not enough food for everyone that comes here.

best part is it doesn't matter how many kitchens there are, since all the food is delivered once per day and tagged for a specific kitchen there's no complex calculations that get more complex with each added kitchen
sebastiannielsen
level2
level2
Posts: 79
Joined: Wed Sep 24, 2014 2:01 am

Re: [Idea] How to solve the AI problem

Postby sebastiannielsen » Thu Oct 16, 2014 3:21 pm

BGK:
Yes, certain rare non-symmetrical layouts like this:

SS##################CC
SS##################CC
CC
CC
##
##
##
##
##

S = security
C = canteen
# = cell

Then inmates belongning to the leftmost half of the horizantal cellblock, will of course select the canteen belonging to the vertical cell block, according to my AI area.

BUT, you could easly solve this by simply zoning off security as staff only, or assign the vertical and horizontal canteen+cellblock to different security levels.
Thus there will not be any viable path for prisoners in the H-block to use the canteen in V-block, thus they will select the next nearest canteen which is the one at the end of the H-block.


So there is already customization options for directing prisoners to the rooms you want them to be in.
And if you get a Little minor problem with the AI selecting incorrect rooms, you could easly virtually "extend" the walkway by adding doors or corridors that extend the Walking time, thus the way to your "preferred" room will be shorter.


Still, the Point I want to make, is that if a prisoner selects a commodity (room) that is nearest to his CURRENT location, it will almost certainly result in that his walkway when he should return to his cell, be much longer, than if he select a Little bit longer path to his commodity that is local to his cell block.
However, for objects, "nearest to current location" work very well since the prisoner can use multiple objects in the same room in succession, and do not need to run to the object nearest to his cell. (of course, during freetime its optimal if the prisoner selects the objects in his cell)

Prioritizing "own" objects in cell could be a trait of the prisoner too, so prisoners who have a "privacy" need (even if the need is currently 0, I mean if he will buildup privacy need if he dont get privacy) will prioritize objects in their own cell, while prisoners without any privacy need at all (those prisoners who can live with being a holding cell all their prison time) will prefer "public" objects.


This could also be added to the route calculation, so if a prisoner is long from his cell, he will still prefer a "public" nearest object regardless of prioritazion. This could be solved with lets say a 50 % "discount" on the route length on AI pathfinding, for objects in his cell.
So a Privacy-aware prisoner who has a TV in cell and is in common room with a TV. Then it AI pathfind to nearest TV in room and pathfind to nearest TV in his cell. Then you do a discount 50% on the walkway to cell, and then execute the nearest path.
minicrafter8401PA
level1
level1
Posts: 16
Joined: Thu May 22, 2014 8:18 pm
Location: A Computer

Re: [Idea] How to solve the AI problem

Postby minicrafter8401PA » Fri Oct 17, 2014 5:21 pm

It could be better it we could a sections tool in deployment, it disregard security levels, where you can assign a cell block to a certain canteen.

Return to “Community Members”

Who is online

Users browsing this forum: No registered users and 17 guests