Hello everyone.

So, I am trying to come up with an algorithm to do following:
I have total 12 cells that I need to fill until program stops. I have 3 rows and each row has 4 columns. As an example, let me illustrate this as in airplane. So you have 3 rows and each row has 4 columns and you have window/aisle seats. Each row will have a window seat, aisle seat, aisle seat and window seat (|WA AW| Just like seat arrangement in airplane). At each iteration (different set of passengers), there would be some number of passengers (between 1 and 12) and I need to seat them closest together possible (Seat together). And, I do this for next group (each iteration) until program stops (It will stop when I am done with every group). For example, I have 3 passengers (A,B,and C) and A wants to seat in Window, B wants to seat in Aisle and C wants to seat in Window. Assuming that all the seats (all 12) are available, I could place them like |A# BC| or |CB #A| and mark the seats dirty (so I donâ€™t pick same seats again for next passengers). And, I do this for next group (iteration).
I am not sure if this right forum, but if somebody can advise me how I should accomplish, I would really appreciate it.
Thanks.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Geekitygeek

You need to declare Two-Dim bool array (say 3 x 4).

As adatapost says, you can use a boolean array to mark the seats as dirty. As for finding the best match location for the group, one way would be to find all suitable locations for each person, then find all combinations of those possibilities. Then for each combination you can calculate a suitablity value by checking the distance between each seat. So if A and B are side by side, add 1 to suitability value, if they arent together then add 1 for each seat and 2 for each row apart they are.
EG:
AB #C

A:B = 1
B:C = 2
Suitability = 3

## #C
A# B#

A:B = 2
B:C = 3
suitablity = 5

## #C
#B ##
A# ##

A:B = 3
B:C = 4
suitablity = 7

not saying this is the best way, just the first one that came to mind.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.