Distribution of an adjacent place on a place map

I need to write an algorithm for assigning adjacent places on a place map. For example: distribution of seats in a stadium. A site map can be thought of as a 2-dimensional array of N rows and columns M. The system must assign adjacent seats for orders that are made together. Since the place map is not displayed for the user, the system should automatically assign available places corresponding to each purchase. In addition to this, he must do so in such a way that the holes / gaps in the seats are minimized.

+4
source share
4 answers

Finding the perfect NP-hard solution. Look at the equivalent language issue:
L={((x1,x2,...,xk),n,m)} where xi is the number of tickets booked, and n, m are the stadium sizes.

We show Partition <= (P) L, and thus this problem is NP-Hard, and a polynomial solution for it is unknown.

Proof
let S=(x1,x2,..,xk) is the input for the partition problem, and let sum=x1+...+xk
Look at the following abbreviation:

 Input: S=(x1,...,xk) Output:((x1,...,xk),sum/2,2) 

Correctness: If S has a partition, let it be S1=(x_i1,x_i2,...,x_it) , then by the definition of the partition x_i1+...+x_it=sum/2 , and therefore we can insert x_i1,..,x_it to the first line, and the rest to the second line, and therefore ((x1,...,xk),sum/2,2) in L
If ((x1,...,xk),sum/2,2) is in L, then by definition there are t orders, so x_i1,x_i2,...,x_it forms the perfect first row and, therefore, x_i1+x_i2+...+x_it=sum/2 , and therefore is a valid partition and S is in the partition task

Conclusion: Since L is NP-Hard, and the problem you are looking for is an optimization problem for this language, there is no known polynomial solution for it. For an exact solution, you can use backtracking [check all the possibilities and choose the best], but it will take a lot of time or you can fight for a heuristic solution, for example greedy , but it will not be optimized.

EDIT: Trackback solution [pseudo code]:

 solve(X,n,m): global bestVal <- infinity global bestSol <- null solve(X,new Solution(n,m)) solve(X,solution): if (X is empty): gaps <- solution.numGaps() if (gaps < bestVal): bestVal <- gaps bestSol <- solution return temp <- X.first X.removeFirst() for i from 0 to m: solution.addToLine(i,temp) solve(X,solution) solution.removeFromLine(i,temp) X.addFirst(temp) 

Assuming Solution is an implemented class, and for an illegal solution (i.e. too many people on one line] numGaps() == infinity

+4
source

Note

This is usually not a problem, because if you can sell all your tickets, then the last buyers will either compromise, or tear their orders into separate orders, or withdraw them, as well as allow other buyers with different requirements for the size of the order to buy the remaining seats.

In addition, people like to choose places. If you want to prohibit this option, they may not buy tickets at all.

Please note that if buyers do not have control over their seats, you can also give them a code and transfer this code to a specific place after all tickets have been sold.

The answer to the problem:

Each row has m places. We assume that the largest reservation is m (otherwise, we will have to split it into several orders).

First, we must model the discrete probability distribution function for the reservation size. This can be built on the basis of data from previous events. (A more advanced model can take into account the type of event, the time of the event, etc.). We call this function f (b)

It is trivial that the best strategy would be to fill out the lines from left to right (or from right to left) and not leave empty spaces - which would only lead to big restrictions.

Suppose the stadium contains one row. We can calculate the probability of filling the entire line by listing all possible reservation sizes. We can use the proposed method here for listing, multiplying each size of the armor with its probability and summing it.

Now suppose that there are 2 rows in the stadium and that the first armor size was 3. Now there is a row with empty seats and another row with m-3 empty seats. The second reservation size is 4. Now we can compare the probability of filling a row (m-4) of seats and the probability of filling a row (m-3-4) of seats. We will accordingly designate places for the current reservation.

Of course, the probability of filling an empty string is 1, and after filling it should be removed from the list of unfilled lines.

In general, for each reservation we can assign it to the line so that the probability of its filling (after appointment) is maximized.

Note that, given f (b), all of these probabilities can be pre-calculated for any constant between 1 and m.

0
source

You should look at memory allocation algorithms for operating systems. This best models your problem. you should focus on algorithms that minimize fragmentation.

0
source

I like the last one. He is very right in the simplest sense. For speed, a probability map test is a great way to fill in lines. But he lacks a few elements. Are you worried if the parties are divided into several places? How about cancellation and refund? Look at the problem a little differently. There are 3 possible states, not 2. M empty spaces, in R Rows, each with three possible states: vacant, filled, canceled, where Canceled has an adjusted probability. How do you deal with this? You can increase the probability of filling out cancellations or refunds by setting them as a new row, all with N places, with a probability of 1 to fill sets from 1 to N places, and you can further increase the probability of filling all places by limiting the probable lot size for N> 2 to batch size> 2, but less than N.

Another way is to use a card. To illustrate this, create a table of small squares relative to the place. now isolate areas and connect them with external lines. These are your rows and columns. put a letter in each local place to indicate availability. Now create a database that references this file. You can add a section in which you determine the number of seats in the row, and then identify the ticket number for the venue based on this, and you can run simple tests to fill the seats. This will โ€œMinimizeโ€ the gaps, but probably will not completely eliminate them. If, like me, you work with showpeople \ entertainers \ musicians and venues, mapping is key. The main group I work with is small and has a loyal, but constantly changing following. This is a program for children, community communication and a performance group in one. The problem I had was that many people wanted to sit with friends, etc. So I came up with a plan with several tickets \ ROW \ TABLE. How do you deal with this? For each unit that you do, you must make a position in your programming. Rows and columns are good for work. We will start there. With tables, put them in rows and columns, and you can beautifully cut them. It may not be perfect, but it works, with a little tweaking for each shared unit.

Consider this ... just enter your places from left to right. Follow this pattern when actually assigning seats to a ticket: For a column, row a go left-> right (which fills the seats in a straight line) row b goes right-> left (now follow the math below) do the same for each column ( think of it as a place in the Carnegie Hall, where each column has passages on each side and goes in several rows). The math for each row in the column is pretty simple. Take full places in even lines for group orders: If partysize> elseSeatsInRow mult seat # _in_row is -1, then add # _Normal = S to place (where S is place # _within_row), if S * -1> 0, S * - 1 = S endif, so the venue is filled with a group and one, holding the parties together. Now, to throw you through a few more cycles ...... Say that you adjust prices every 15 rows or so, then higher price areas can fill up more slowly, so you can add incentives, but only for these areas or adjust incentives for each area and the number of tickets available in that area, and so on. Now add the ability to check other pricing areas for the remaining places to place the group (remember that they just have to be in the same area, and they will still be sitting next to each other, I would focus on the columns to save time, but for each of them), and now you can even send a request to fill in the empty seats in more expensive areas at a lower price, just to fill the meeting place in the immediate vicinity of the show and keep people happy with their priya firs. Now for the choice ...... you may have people who choose their place, if there is a place to sit. In the situation I'm going to, the venues change like a date, so I have to bend this algorithm for all this. Mostly, speaking is charity work, and people are parents, friends, community members, etc., who know the groups that perform and know each other. If they know where someone is sitting, they will want to be around. Get the number of tickets they want, and show off areas with lots of seats available at will; you can even go either row-wise or column-wise (to use your seat-filling example, carnegie has several sets of aisles that separate the column between the rows, so you can either change the column or just continue working with the truck as young Mr. Simpson will say: โ€œAye Karumba!โ€, each of which has different design layouts, if you change, you need to make a plan for your databases and work with it, this model is flexible, since it can be configured for several diagrams) in anyway to be right Use it in an original way: use the original test to go in a straight line (here you can select the column and row of your buddies, then check the column and then adjacent columns for the same rows where seat number is checked for proximity, use the math from the original proximity keeper above, if friends are on the left, check the left column on the right seat #, if friends are on the right, check the right column on the left seat # and even compare the cancellations discussed later, the operands of the original test can simply be swapped, or you can flip b, etc.) if you select the areas in which places are open, then enter the number of them, and then select only the remaining areas in which there are many suitable places (run the test on 2 or more lines if necessary, again the same tests as above are implemented in the rows of the column), they will most likely sit together if you performed the above test correctly, but in the worst case they will be located as close as possible (and how often this test passes, a? You can offer it as an option with a special price as long as you have a place to fill, but logically, you should put the cap on partysize, which will be placed in this secondary location, and this will most likely fail more often, so how do you get closer to your show. Now comes the fun part, clearing the spaces. Some people walk the deer or are probably late because they are at work or in traffic and want to catch a show or see how their child put on a ridiculous performance of peter pan. If your free space in any particular row or column is 1, and there are no more places around it (what should happen if people cancel), or you have canceled the whole group, you need to return them to the sorting hat. There are several ways. You can create a large number of seats for each section and work with it, but it may be better to simply open a new list to keep small arrays of neighboring seats that can fill the seats in your main; alternatively, you can create a seating text file for the card, marking each seat as free, full, canceled and save the canceled group pointers, then check the cancellation mapping after each cancellation and create separate mappings for different group sizes that contain lists of seats for each size. You can name the cards using the VenueTitle_Cancel_GroupSize object, and then encode the test to check all the cards where GroupSize> = for your new group. This makes it difficult to find your buddies because you have a new test, but you can use the same preliminary tests to align them to scan available seats and draw: check if there are any cancellations, check the number of adjacent seats for each cancellation (how many in the new group? will they be placed in the cancellation slot? Offer them a discount on the remaining places in the cancellation slot and then process all this data) ...... This is not quite an algorithm, not even close, just a mental design for a problem with ton base arithmetic the IF test, which should work like lightning, but you can divide these tests, separating machines that run them, and wait for the return of all the processes, and then add the results together, etc. (old multi-processor polling of a remote file, database query software located on remote computers, with newer servers, you can run the test faster by linking them together in XSERVE and setting up multi-network farms that process data with less u nits that process your web interface).

Planning: Find out how to divide places (places), then find out how to calculate the number of sections \ places and how to evaluate tickets, and then find out if you want people to choose their price using an interactive or simplified view. With a lot of interaction, you may encounter several spaces. If there are several of them, you can have price reductions or special invitations to interested parties, etc. With listings on places. This allows you to maximize your venue and offer options that maximize your satisfaction. I'm not sure what caused this algorithm, but using bubble sorting, a database or something like that, you can set your own values โ€‹โ€‹for ticket sales and all the information you need when booking. This allows the cancellation to be treated as a separate element, but LINKED, set flags and re-add data for operations that prevent excessive or unproven. The main way to do this: if you book, you will get time stamps for each of the last transactions, N + 1 (where N is the number of transactions with overexposure), and each after the last reservation (which filled the place or just under) will be installed in a new table with the same transaction information, after which they will be checked to see if they still fit, and if not, they will be returned, sent via email and / or using phonecalled. This way you can check the number of seats available and see if anyone wants to cut back on their batch. You can also offer them new offers by exporting your information to a new spreadsheet for the CMS and keeping them happy. This is a lot of work, but this method can run several parallel tests if configured and processed correctly. This is probably a long and boring answer, but the credit belongs to Lior, who usually used the test. This is just my long program to maximize if you have the processing power and time to create the code.

-1
source

Source: https://habr.com/ru/post/1379848/


All Articles