Many times in my life I have participated in all kinds of events where each participant brings a portion of the food, and then everyone eats it together, in the style of a cooperative meal. Such as shared meals in kindergarten, class evenings at school, class Saturdays, barbecues with friends and family, in many events in the youth movement and recently even in events such as Bat Mitzvah and engagement. Usually, before such events, a message is sent in the WhatsApp group of the participants in the event and each participant slots himself into the dish he wants to bring to the event. I have always been disturbed by the lack of logic and equality in these divisions, there is always a situation where one participant who entered early brings a light dish (let's say a package of Hadaf forks) while a participant who entered a little late is destined to bring a hard dish (like meatballs). After several times I tried I organized a list that would be as logical and equitable as possible, without success and with much trouble, I realized that this problem is the kind of problem that computers can help humans solve. So I programmed a website that would answer this problem and make fair and logical lists for every occasion, at the user's request.
The main challenge I encountered on the site was building the best distribution model for each situation and implementing it in an appropriate algorithm. After receiving input from the user that includes all the dishes he wants to have at the event, the quantity of each dish, its price and the degree of difficulty of preparing and carrying the dish. After receiving this input, how to divide the portions according to the number of participants so that the distribution is as logical, fair and equitable as possible. On the one hand, logic must be maintained in the distribution, that is, the amount to bring for each dish should be reasonable, let's say it doesn't make sense for many participants to each bring one leftover, and it also doesn't make sense for a participant to bring 4 salads. On the other hand, one should strive for equality in the distribution, so that there is no situation where one user brings a cake and another participant brings HDF glasses. I faced this problem throughout the year (and more) that I worked on building the website, I solved problem after problem and progressed step by step towards a good distribution model more and more.
I used the NET 5.4 framework technology to build the website (with aspx pages) and the C # programming language to operate the server side of the pages on the website. I used the .NET framework data provider for SQL technology to manipulate the database.
The division model carried out in list.aspx.cs Key operations and concepts:
- Undivided portions: the portions in their "raw" state as entered by the user. Let's say he wants to have 6 rice pans at the event, so the undivided portion is 6 rice pans.
- Divided portions: the portions after the first distribution. According to the doge of 6 rice molds, now there will be six divided portions, each of which is a rice pattern, note: a divided portion can also include a side dish (max. 1) let's say one rice pattern + 50 cups of rice is one divided portion.
- The normal amount to bring: a number attached to each dish and expresses the normal/logical amount to bring the dish, regardless of the number of participants or the difficulty of the dish. Let's say for the chicken the attached number is 9, for the cups 50 and for the cake 1. In the case of a dish that is already sold by the site, the normal amount for the dish will be calculated by the average of all the quantities for bringing that were in the previous divisions on the site (artificial intelligence), while for the new dish on the site The user will be asked to enter the normal amount to bring the portion. The total difficulty: an operation that receives a portion divided by unit and returns an actual number that expresses the rating of the level of difficulty in bringing the portion, the larger the number, the more difficult it is to bring the portion. The rating is calculated as follows: 0.2quantity to bringprice per unit + 0.5difficulty of preparation + 0.3difficulty of carrying.
- The logic rating: an operation that accepts an array of divided packets and returns a real number that expresses the rating of the logic level of the division, the lower the number, the more logical the division is considered. The logic rating is calculated by a scheme of all the differences between the current amount of the dish and the normal amount for bringing it. The number is also normalized in relation to the difficulty of the dish (the price, the amount, the difficulty of carrying and the difficulty of preparation), because bringing more cake than the normal amount for bringing is no longer Makes more sense than bringing another glass beyond the normal amount to bring.
- The equality rating: an operation that receives an array of divided packets and returns an actual number expressing the equality level rating of the division, the lower the number, the more equal the division is considered. The equality rating is the total difficulty difference of the division, which is calculated as follows: each time you take two portions (in an array of divided portions arranged from hardest to easiest portion), the highest and the lowest, calculate the total difficulty difference between them and add to the total variable, then add to this variable Also the total difficulty differences between the second hardest course and the second easiest course, and then the third and so on.
- Trimming: An operation that accepts an array of divided packets and returns an array of divided packets minus one divided packet. The operation does not delete the divided portion but redistributes it among the other divided portions, let's say before the cut in the array there were 8 divided portions each including 7 schnitzels, so after the cut an array will be returned in which there are 7 portions and in each portion 8 schnitzels. The operation also selects the dish that will be the best in terms of ratings to cut.
- Expansion: The opposite action of reduction. An operation that receives an array of partitioned packets and returns an array of partitioned packets with one more partitioned packet. The operation does not add the divided portion out of nowhere, but redistributes the other divided portions so that there is another divided portion, let's say before the expansion in the array there were 7 divided portions, each including 8 schnitzels, so after the cut, an array will be returned in which there are 8 portions and in each portion 7 schnitzels. The operation also selects the dish that will be the best in terms of ratings to expand.
- Adding: an operation that receives an array of divided portions and returns an array of divided portions minus one divided portion and with another addition to an existing divided portion (a rice pan + 50 cups of HDF) the operation takes the easiest portion to bring in the array and adds it to the second lightest portion in the array. Let's say before additions In the array there were 10 divided portions, 8 of which are 7 schnitzels each and 2 of which are 50 cups each. So after the additions, an array will be returned in which there are 9 divided portions, 7 of which are 7 schnitzels each, 1 of which is 7 schnitzels + 50 cups and another 1 of which is 50 Cups. The action does not refer to ratings because: the logic rating is not affected by the action, and the equality rating is affected, but the best thing for him is to do what the action does (to add the easiest portion to the second easiest) so there is no need to check it.
- Expansion of additions: an operation that receives an array of divided packets and expands the additions in the array, like the operation expand only on the additions only.
First, the site divides the undivided portions into divided portions, only (without regard to the number of participants or the ratings) according to the normal amount to bring of each portion, let's say, from 30 birds, the normal amount is 8, this will become 4 divided portions 8 8 7 7 birds . After that, the website compares the number of portions to the number of participants as follows: If there are more portions than people, the site cuts as much as necessary (so that the amount of distributed portions equals the number of participants). And if there are more people than the portions, the site expands as much as necessary (so that the amount of distributed portions equals the number of participants). Check the logic rating and the equality rating and keep both ratings. After that you enter the loop, as long as the change is legal and improves the ratings (their amount is small) make the change. A change can be expansion and additions with the possibility of expanding additions and all sorts of other trivial things such as replacing additions, etc. This is how the final distribution array that the website outputs is obtained, an array of portions some of which have additions, the best distribution. After presenting the site's division to the user, the user can edit the division and correct things he doesn't like, and only then the division is saved in the database, so the site learns and improves with each division, and learns norms.