Results 1 to 9 of 9

Thread: Searching a seating map for the largest group

  1. #1

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747

    Searching a seating map for the largest group

    I am currently working on a ticketing kind of application

    and one of the desired features, is searching a bay of seats for the largest group.

    so im wondering are there any kind of algorithms or whatever that searches over a 2d graph and can spit out the largest group of available seats?

    any tips welcome

    thanks

  2. #2
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    how big is this place? cant the user just look at the grid and see what area is the biggest?

  3. #3

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    nope, itd also be good 2 list all available groups of 6 for example.

    say 40, 000 seats, each bay has a map. so instead of hte user having 2 look at every bay, they can just use this.

    (to be honest i think its kinda silly, but this is what they want!)

  4. #4
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking No worries

    Obviously, you want to find all possibilities, you you're going to have to at least check every one even in the fastest case.
    Ad you can do this.
    Assuming you only want 6 in the same row, not 6 in a column, do this:

    Algorithm:
    Code:
    int NUM_FREE = 0;
    for(row = 0; row < NUM_ROWS; row++)
    {
        NUM_FREE = 0;
        for(col = 0; col < NUM_COLS; col++)
        {
          if(seat.isempty())
            NUM_FREE++
          else
            NUM_FREE = 0;
          if(NUM_FREE >= TARGET_SIZE)
            Is_free[row][col] = true;
        }
    }
    (p.s. please excuse the C++ code)

    After this, if the seat row x column c is the right-most in a group of TARGET_SIZE empty seats, then Is_Free[x][y] = true;
    sql_lall

  5. #5

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    ohhh no, i mean BLOCK like find a block of 4 in this map

    X 0 0 X 0
    0 0 0 X 0
    X X 0 X X

    for example there is a block of 4. two in top row seat 2, 3, then in second row seat 2, 3.

    tis a biatch i know

  6. #6
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking hmm...

    Well, can the block be any shape, or do they have to be rectangles?.
    Otherwise you could flood-fill the free seats, and any set which has more than TARGET_SEATS seats is a block
    sql_lall

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    make an array holdin the column height of empty seats with the length of a row, an array holding the position of latest occurrance of each column height in the current row, and three temporary variables holding the area, width and height of the so far largest block
    now for each row, for each column,
    - set at the row position in the first array, 0 if the seat is booked, otherways add one - this is the height of the empty column here.
    - if the height was larger than the previous one, set at each index from the previous height+1 to the current height, in the second array, the row position - this will allow fast tracing back the largest block of specified height, for all blocks that fits in the new open area.
    - if the height was smaller than the previous one, or if you've hit end of the row, calculate the block sizes for all blocks with height from the previous one's to and without the current height, by multiplying the height with the difference between the current row position and the one found in the second array(by specified height). If you've got a new record, update the temp vars.
    keep iterating, each time you get more room their position is put down and each time you get less room, the block sizes are calculated. Hope you get the idea.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    here's an illustration, just in case:
    Code:
    122210
    xxooxx
    xoooox
    ooO
    height increasing to 3, set heights[3]=2 (position). If raised more, remember to put them all to 2.
    
    123310
    xxooxx
    xoooox
    ooooO
    
    height dropping to 2, calculate 3*(4-heights[3])=6. if drops more remember to calculate for all dropped heights
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    I have one possible idea.

    Are you suffieciently familier with masks and binary/boolean logic?

    One method might be to use a "mask" shaped to the block size and shap of the disired area and the compaire the two


    000
    000
    000
    010


    where 0 is the seat layout required.


    1001001010
    1100011100
    1000000011
    1000000011
    1001001111
    1110011010
    1111111111
    0101010101

    is a map of seats where 1=taken 0=spare

    now as I understand it you are looking for this result

    000
    000
    000
    000


    indicating that full seets are full and emty seats required are empty. You would have to be carefull of making the "full area" too big but in priciple you could then search for any pattern untill you found a match.

    the search pattern would be:

    top left coner, test, LOOP: move one step to right, test END LOOP;

    On All=0 do this
    ....

    etc.

    It's kinda like pattern matching basicly.
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width