Efficient Optimal Greedy Algorithms for Room Allocation VALENTINA C IRIANI Università di Pisa, Italy NADIA P ISANTI Università di Pisa, Italy A NNA B ERNASCONI Università di Pisa, Italy Abstract In this paper we address the problem of allocating rooms among people in a suitable topology of corridor with some contraints of undesired neighborhood. People are partitioned into families, and we consider both internal crashes (sharing a room with someone belonging to a different family), and external crashes (being in a room next to, or in front of someone belonging to a different family). The goal is to minimize a suitably defined weight of such crashes. We give polynomial time algorithms for several cases of increasing difficulty, including the one where k people (with k any given constant) have to fit into one room. Finally, we give a 4 3 approximation for the case with both double and triple rooms. Introduction Assume you are the director of a research department, or any other institution collecting people subdivided into groups organized into hierarchies, and with the unavoidable dose of bad relations among groups. Suppose you get a brand new building where you have to move the whole department. This news is not at all as good as it looks like, as now the troubles come: you must allocate rooms among people, avoiding that groups that are in bad relation happen to be in the neighborhood of each other. This paper addresses this problem by formalizing some cases of increasing difficulty, and providing polynomial time consuming algorithms for their optimal solutions. Section 1 introduces preliminary definitions. In Section 2 a first simple version of the problem is addressed, and a linear time algorithm is provided for its solution. In Section 3 the constraint of fitting more than one person into one room is introduced. First, in Section 3.1, we consider the basic case 1 2 Proceedings in Informatics of grouping people into rooms minimizing only the weight of internal crashes, that is costs due to undesired roommates. The algorithm we suggest finds an optimal room allocation in O n logn time and linear space. Second, in Section 3.2, the costs of both undesired roommates and undesired room-neighbords are minimized, and again a O n logn time optimal solution is provided for the case with shared double rooms. Section 4 introduces some extensions to the problem: Section 4.1 extends the problem of Section 3.2 to the case of triple rooms, and shows how in general the problem is solvable in O n logk logn time when k people have to fit into one room. Section 4.2 addresses the case in which there are some persons that have to share double rooms and others that share triple rooms. Here the problem becomes more difficult and, in fact, the strategy applied to the previous cases fails to find an optimal solution. Nevertheless, we prove that it provides a polynomial time 4 3-approximation. We are not aware of previous work on allocation problems defined as in this paper. 1 Preliminary definitions The bottom line of all the problems we are going to address is the one of allocating rooms among people minimizing a suitably defined parameter that measures undesired neighborhoods. Assume there are n persons p 1 pn . These persons have different positions within the institution, and their opinions count proportionally to their power. Hence, to each person pi we associate a weight wi , which is a non negative integer. Rooms are arranged along a corridor of a suitable length, such that at each point of the corridor there is a room per side, and the two sides are symmetrical. Formally, Definition 1 A corridor of length m is a 2 m matrix C . To each entry of the matrix we associate a room. Intuitively, the matrix C represents a corridor where room C1 j is in front of room C2 j for all 1 j m, and room Ci j (i 1 2) is located between room Ci j 1 and room Ci j 1 for 1 j m. The corridor is shown in Figure 1. Definition 2 We say that room Ca b and Ca b are neighbor if a a and b b 1, or if a a and b b . For example, in Figure 1, the neighbors of room C1 j are C2 j , C1 j 1 , and C1 j 1 . Definition 3 Given two persons pi and p j , we say that they are compatible if a neighborhood between them creates no problem. They are incompatible otherwise. Ciriani et al.: Efficient Optimal Greedy Algorithms for Room Allocation C[1,1] C[1,2] C[1,j-1] C[1,j] C[1,j+1] C[1,m-1] C[1,m] C[2,1] C[2,2] C[2,j-1] C[2,j] C[2,j+1] C[2,m-1] C[2,m] 3 Figure 1: A corridor It is reasonable to assume that the compatibility relation is reflexive, symmetric, and transitive. As a consequence, we have that persons are partitioned into equivalence classes of compatibility, which we will call f amilies.. A room allocation is an assignment of rooms to people such that to one person is assigned exactly one room. Definition 4 If pi and p j are in two neighbor rooms and they are not compatible, we say that there is a external crash c. The weight of this crash is wc wi w j . Finally, we define the parameter that will measure the badness of a room allocation. Definition 5 Given n people with their weights, and a room allocation among them in a corridor, we define the cost : of the room allocation as the sum of all crashes’ weights along the corridor, that is : ∑ wc c corridor In the next sections we will address various formalization of the room allocation problem. Basically, they differ depending on how many people have to fit into one room. For all of them, the goal is to find the room allocation that minimizes : . 2 Linear solution if n 2m Let us first assume that there are enough rooms so that everybody can have his own one. This means, since the corridor contains 2m rooms, that there are at most 2m persons, that is n 2m. Since the existence of extra rooms is unlikely to happen, we assume that n 2m if n is even, and n 2m 1 if n odd. Let us first consider the case of n being an even number. We give no limit to the number of different positions that the people have, that is to the number of different weights 4 Proceedings in Informatics they can be affected to (besides that they are at most n, of course). We can observe that, since : is defined as the sum of single crashes, and each crash is defined as the sum of the weights of persons involved, we have that : is just the sum of the weights of all members of each family exposed to external crashes. Therefore, minimizing : equals minimizing the number and weights of crashes of each single family independently. Formally Proposition 1 Let F be the set of all families, and : F be the sum of the weights of the members of a family F that are exposed to crashes. We have that min : ∑ min : F F F Thus, let us consider the problem of minimizing : F for each family F . Such minimization depends on the topology of the corridor and on the parity of the number of members of F . First of all, we can observe that people belonging to the same family are always placed close to each other in an optimal solution. This holds because they give no crash between each other, and hence their neighboring has zero cost. More precisely, we have that if a family has an even number of memberss 2n 1 , then it should be arranged in the following way in the shape of a rectangular: C1 i C1 i 1 C1 i n1 1 C2 i C2 i 1 C2 i n1 1 In fact, in this case there are at most four members of the family involved in exactly four external crashes. Namely, the person in room C1 i crashes with the person in room C1 i 1 . The person in room C2 i crashes with the one in room C2 i 1 , and the same holds for the two right extremes of the family. It is straightforward to verify that any other arrangement of an even size family results in more than four external crashes. For analogous reasons, if the family has an odd number 2n1 1 of members, then it should be arranged in the shape of a mobile telephone: C1 i C1 i 1 C1 i n1 1 C2 i C2 i 1 C2 i n1 1 C2 i n1 (where we will refer to room C2 i n1 as the antenna), or equivalently the symmetrical one (with the antenna-room in corridor 1). In this case there are again at most four persons involved in external crashes, but there are five crashes. In fact the person in the antenna-room C2 i n1 crashes twice: one with the person in room C2 i n1 1 and one with the person in room C1 i n1 . Ciriani et al.: Efficient Optimal Greedy Algorithms for Room Allocation 5 These two shapes are those that minimize the number of possible external crashes, respectively for even and odd size families. This observation is the key point of the linear solution we are going to suggest for this problem. Since n is an even number, there will be an even number of odd size families. Two of them together (with the antennae in front of each other in different sides of the corridor) result in an overall rectangular shape. What our algorithm actually does is to pair two by two all the odd size families. As above, observe that any other arrangment different from the rectangular one, has at least 6 external crashes. For instance, an alternative to rectangles are shapes that we name double antenna mobile telephones, that is on both sides we have an antenna, which makes three crashes per side. Any other even more degenerate arrangement (e.g., all persons at the same side of the corridor) gives a number of crashes that is no less than 6. Therefore both a pair of odd size families and an even size family have a rectangular shape, and the whole problem becomes to optimally arrange the rectangles. Notice that, once we have chosen the two rectangles to be placed at the borders of the corridor (we will see later how this choice should be done), the value of : does not depend on the order of the rectangles along the corridor. Thus, we propose the following general strategy: Step 1 For each family F , find the 4 members of minimal weights. Let them be F1 , F2 , F3 , F4 , and let wF1 wF2 wF3 wF4 be their weights. Moreover: let Ftot wF1 wF2 exposed to crashes; wF3 wF4 be the total weight of members of a family let Fmin wF1 be the weight of the member that in odd size families will be placed in the antenna-room, which will crash twice with the neighbors; finally let Fb wF3 wF4 . The two families L and R with highest values of Fb will be placed at the left and right ends of the corridor. Let them be denoted as border families. Step 2 Once the border families have been designated, we can place all the other families in any way. Correctness of Step 2 comes from the observations that, no matter how we place the families, we have that min : F Ftot Ftot if F is an even size family Fmin if F is an odd size family As a consequence the total cost of crashes of an optimal solution will be min : ∑ Fitot Fi ∑ odd Fi Fimin Lb Rb 6 Proceedings in Informatics In fact, each one of the 4 minimal weighted members of each family will have a crash, and it will contribute with its weight to the total cost. Moreover, for odd size families, the least important member will add once more its weight to the cost as it will crash twice with neighbors. Finally, the weights of the members that are placed at the borders of the corridor have to be subtracted as they will not crash with anybody. They correspond to the Fb values of the border families L and R . If there are families with less than 4 members, then particular care has to be taken: Let family F contain 3 persons with weights wF1 we will have Ftot wF1 wF2 wF3 , Fb wF2 wF1 wF2 , since F1 and F2 will crash twice. wF2 wF3 . In this case, wF3 , and finally Fmin If a family F has size 2, then its two members, with weights wF1 wF2 , will play both the role of F1 and F2 , and the one of F3 and F4 , respectively, because they will both crash twice (or only once if they are at the border). That is, we must set Ftot 2 wF1 wF2 , and Fb wF1 wF2 . The value of Fmin is not interesting for even size families. Finally, let a family F have size 1. Its unique member f will necessarily be an antenna-person, and hence its contribution to the total cost might be high if the weight w f of such person is high. In order to count this, and in order to still consider the possibility of placing it at the border (see Proposition 2), we must set Ftot 2w f , Fmin w f , and finally Fb w f . For families of size 2 and 3, the assignments to the parameters given above are enough to let them be optimally placed using the algorithm as for the case of families of size 4 or more. On the other hand, family of size 1 require particular care concerning their placement at the border of the corridor, as this implies a second family being border at the same end of the corridor. This issue is addressed in the following proposition, where we assume that there is only one family of size 1 (the result can be extended to the case of more size 1 families). Proposition 2 Let U be a family of size 1, such that Ub is maximum, let F be the odd size family with F4 maximum, and let G be the family with the third maximum value of Gb . Finally, let H be the one with the second maximum value of Hb . We have that in the optimal solution, one border will be occupied by the family H , while for the other border we can have two possibilities. If Umin Fmin Gb U and F are placed at the other border in the following way: U F F F F F Ciriani et al.: Efficient Optimal Greedy Algorithms for Room Allocation 7 Otherwise, G will be the second border family. Proof Let us first consider the case where F and G are the same family. There are two possible allocations: 1. The first allocation is U F3 F2 F4 F1 , is given by Ftot and its cost, i.e., its contribution to : 2 Umin . 2. The second possible allocation is and its cost is given by 2wF1 F4 F3 wF2 F2 F1 U 3 Umin . Thus the thesis directly follows by comparing the costs of the two possible allocations. Now suppose that F and G are two different families, with G an even size family (the odd size case is analogous). We have to compare the cost of the two possible allocations. 1. The first allocation is U F3 F2 F4 F1 and its cost is given by Ftot 2 Umin G1 G3 G2 G4 Gtot . 2. The second possible allocation is G4 G3 and its cost is Fmin G1 G2 Ftot 3 Umin F1 F2 G F3 F4 U G w1 Thus the thesis directly follows (note that Gtot w2 . G w1 G w2 Gb ). We finally have to consider what happen when n is an odd number. In this case there will be an empty room left, which can be used to avoid three conflicts. Observe that, in order to minimize : , we should use the empty room to transform an odd size family into an even size one. Of course, we could also transform an even family into an odd one, but this is not convenient. Thus, let 8 Proceedings in Informatics O be an odd size family, and F any family. We can allocate the empty room as follows: O2 O3 O4 F4 O1 F 3 and the total gain will be wO4 wO1 wF4 . Therefore we have to choose the odd size family O that maximizes wO4 wO1 and, among the families left, the one with wF4 maximum. Note that we can also have the following allocation O4 F4 O3 U 1 F 3 where U is a family of size one. In this case, the total gain is wO4 wU wF4 , 1 which should be compared with the previous value in order to choose the most convenient solution. Note that in making such a choice, one should also take into account the border families. We now show that the solution we suggested takes a time that is linear in the number n of people. We have, say, p families each one having size n i with i 1 p and n1 n p n. Searching within the ith family the 4 members with lower weight can clearly be done in O ni . Assigning values to the parameters Fb , Ftot , and Fmin can be done at the same time on the fly. This gives an overall O n time for computing them all. In order to generate an optimal solution, one has just to assign families to the border (which takes linear time), find an appropriate place for the empty room (which again takes linear time) and then make the random choice of how to place the rest, which can be done in O n time. In summary, computing a solution which minimizes the cost : takes linear time. It is straightforward to see that also the space complexity is linear. 3 Sharing rooms Unfortunately, most of the times, there are not enough rooms, that is n 2m. As a consequence, somebody has to forget about single rooms. In brief, people with low power have to share rooms with colleagues. If the colleague is a compatible one, then this is after all fine, but if it happens to be an incompatible one, then we have a new type of crash internal to the room. Let us name it internal crash. This section addresses the issue of internal crashes, assuming that they have the same cost as the external ones. That is, if i and j belonging to different families share a room, we have to add the extra costs wi w j to the overall cost of the room allocation : . In Section 3.1, we will show and solve the simple case where only internal conflicts are taken into account. In Section 3.2, both internal and external crashes are counted. Ciriani et al.: Efficient Optimal Greedy Algorithms for Room Allocation 9 3.1 Counting only internal crashes We assume to have the same corridor as in Section 2, but here we have shortage of rooms. Suppose without loss of generality that there are three kind of positions in the Institute. For example, in a University, we might have professors, lecturers, and PhD students. Being the head of the Institute a professor, and his wife a lecturer, and since their children are not PhD students, at least not yet, he decides that professors have the right for single rooms, lectures have to share double rooms, and PhD students are collected into triple rooms. We assume, without loss of generality, that internal crashes cost the same as external ones. Here we have to distinguish 6 types of families, Ti j , for i 0 1 and j 0 1 2. Definition 6 A family is of type Ti j if it has i mod 2 lecturers, and j mod 3 PhD students. In general, if there are p different kind of positions, and each one is grouped into rooms made of ci persons (1 i p), then we have as many types of families as the product of all ci ’s such that ci 1 for all 1 i p. In all cases, scanning all people and classifying families can be done again in O n time. For each family of type Ti j , we look for the i mod 2 lecturers and the j mod 3 PhD students of lower weight. We name them spare members. Their detection can also be done on the fly while scanning the people. We will see that, no matter how we arrange the people in the room, we have that the contribution of each family to the cost : depends on such weights only. We allocate the rooms among the families in the following way. People that share the room with colleagues of the same family, or that have the right for a single room, can be in any room, since they do not contribute to : . We are then left with the problem of allocating rooms to lectures and PhD students that have to share rooms with incompatible colleagues. The only way to allocate rooms among these lectures is to pair couple of them into a room. The room allocation among PhD students requires more care. Intuitively, the two spare PhD students of a family of type Ti2 should be in the same room, as long as possible. Unfortunately, there are cases (when we have more T i2 families than Ti1 ) in which we are forced to different arrangements. Let d and s be the number of families of type Ti2 and Ti1 , respectively. Let wL be the minimum weight of 1 2 the lectures in a family, and let wS and wS be the two lowest weights of the students. For the arrangement in students rooms, we can make min d s rooms each one containing the 2 spare students of a family of type Ti2 (those of minimum weight, of course), and the 1 spare student (the one of minimum weight) of a family of type Ti1 . After that, we have two cases: 1. If d s, then we might have spare students of Ti1 families left. Here we just group them in the remaining rooms. As a consequence, we can have triple rooms occupied by students from three different families of type T i1 . 10 Proceedings in Informatics 2. If d s, then some students of families of type Ti2 must be separated. In order to keep the cost of conflicts low, we perform the minimum number of separations among couple of students of minimum weight. We take the d 1 2 s 3 families of type Ti2 with the minimum values of wS wS (w.l.o.g. we assume that d s 3 is an integer), we separate the two students and we consider them as students from families of type Ti1 . We can now proceed as in case 1. Let us now evaluate the contribution : F of a single family F to the cost : of the room allocation. For each family, : F is given by the sum of two quantities: WL and WS , which represent the cost of internal conflicts of lectures and PhD students, respectively. We have WL 0 wL if F is of type T0 j if F is of type T1 j and if F if F if F if F 0 1 2wS 1 2 wS wS 1 2 2wS 2wS WS is of type Ti0 is of type Ti1 is of type Ti2 and the students are not separated is of type Ti2 and the students are separated Hence we have that an optimal solution can be found in time O n d logd because in the worst case (d s), the d Ti2 families must be sorted according to 1 2 the values of wS wS . Notice that this algorithm can be generalized to the case of more than three different positions (professor, lecturer and PhD student in this section) that people can cover. Moreover, if we give internal conflict a k times higher cost than to external one (k can be any constant), then this method could be still applied, and only the final cost suitably computed in a different way. 3.2 Counting internal and external crashes We now join the problems of internal and external crashes counting. Assume that there are only two kind of positions: those (say professors) that are in single rooms, and those (say students) that have to share double rooms. The weight of each room is given by the sum of the weights of its occupants. Note that if the people sharing a room come from the same family, we can consider the shared room as a single one. The corridor is the same as in the previous sections. We consider again the cost of internal crashes as being the same as the one of external ones (here, as in the previous section, everything could be generalized to the case of internal cost being k times more expensive than external one). Since we are back to consider Ciriani et al.: Efficient Optimal Greedy Algorithms for Room Allocation 11 external crashes, we need to take into account whether the number of rooms occupied by a family is odd or even. Moreover, in order to see which families are forced to share rooms with others, we have to check whether they have an even or an odd number of students. Hence, there are 4 types of families: Ev0 A family is of type Ev0 if it occupies an even number of rooms, and it has an even number of students. An Ev0 family has no internal crashes, and for as much as it concerns external crashes, it is as an even size family of Section 2, that is, it is optimally arranged as a rectangular and it has 4 external crashes. Ev1 A family is of type Ev1 if it occupies an even number of rooms (one might be not completely occupied) and it has an odd number of students. For such families, in one of the rooms there is a student sharing a room with a student of another family, which gives one internal crash. Moreover, there are 6 external crashes, because the shared room placed at one of the sides causes one extra crash with respect to the borders of families like those of type Ev0. It is easy to observe that the number of external crashes would grow if the shared room would be placed at the internal of the area assigned to the family rather than at one side. Od0 A family is of type Od0 when it occupies an odd number of rooms, and it has an even number of students. These families do not have internal crashes, and their treatment in terms of external crashes can be like the one of odd size families of Section 2, that is they give 5 external crashes. Od1 A family is of type Od1 if it has an odd number of both rooms (one might not be completely occupied) and students. These families have one internal crash, and 6 external ones, like in the Ev1 case. From the crash counting of the four types of families, it results that Ev0 and Od0 families are the “cheapest” ones, as they give no internal crashes and moreover they are those minimizing external crashes as well. In brief, we have again that antenna-people are those causing many crashes, and this is even stronger when we have shared rooms. This observation motivates our choice to pair families as much as possible in such a way that the result has a rectangular shape with no shared room at the border, namely a superfamily having the shape of an Ev0 family. In alternative, we can build superfamilies that have the shape of an Od0 family (which, as we have seen, gives the second better choice). After we have built these superfamilies from Ev1 and Od1 families, we are left with only Ev0 and Od0 (super)families, and from Section 2 we know how to solve the problem. Note that, in order to keep the cost : minimum, we have to order Od1 and Ev1 families according to the weights of their components (in the sequel we will specify the ordering criteria). Therefore, our algorithm performs as follows: as 12 Proceedings in Informatics much as there are both Ev1 and Od1 families, place them next to each other in the following way. Let x denote members of an Ev1 family, and o be those in the Od1 one. Each pair of square brackets represents a room: o o o xo x o x x x x (1) These two families together give an Ev0 type superfamily. Similarly to Section 2, let us introduce some notation concerning the weights of members of a family F . wF denotes the weight of the minimum weight student SF of families of type Ev1 and Od1. Let wF1 wF2 wF3 wF4 be the weights of the four members F1 , F2 , F3 , F4 of minimum weight of the family (not considering the student SF for families of type Ev1 and Od1). Let Ftot Let Fmin wF1 wF2 wF3 wF4 . wF1 . Proposition 3 The pairing of an Ev1 family E , and an Od1 family O costs Etot Otot Emin 3wO 2wE , and the only way to pair them is as described in (1). Proof Note that E and O can be viewed as families of type Od0 and Ev0, respectively, if we do not consider the students SE and SO . Thus the cost of the superfamily resulting by such pairing is given by the sum of the external conflicts of E and O (view as Od0 and Ev0 families, respectively), plus the cost on the internal conflict between SE and SO , plus the cost of the external conflict due to the shared room: Etot and the thesis follows. Emin Otot wE wO 2wO wE Once all possible such pairing are done, we are left with either only Ev1 families, or with only Od1 ones (we remind that for the moment we are not placing Ev0 and Od0 families). At this point, we have to pair either two Ev1 families, or two Od1 ones. In both cases, the results is an Od0 superfamily, as the following propositions show. Proposition 4 Let A and B be two Ev1 families, and let their members be denoted by a’s and b’s, respectively. Let A be the family such that w A wB . The cheapest way to pair them is the following a a a a b b a ab b b b Ciriani et al.: Efficient Optimal Greedy Algorithms for Room Allocation and this pairing costs Btot Atot Amin Bmin 3wA 13 2wB . Proof There are two different ways of pairing A and B : a a a a b b a ab b (2) b b b (3) a a b a ab b b b a a Pairing (2) costs Atot Amin Btot Bmin wA wB 2wA wB Bmin Atot Amin wB wA 2wB wA Pairing (3) costs Btot Since by hypothesis wA wB , the most convenient pairing is (2). Analogously, for a pairing of Od1 families, we have the following Proposition 5 Let A and B be two Od1 families. Let A be the family such that B wB w , then the cheapest way to pair them is wA wA B 2 wA w1 2 1 a a and this pairing costs Btot b b b wA 1 Atot a b b a ab b wA 2 3wB 2wA . Proof There are again two different ways of pairing A and B : a a b b a b b a ab b b a a b ba a a a a (4) b b b (5) Pairing (4) costs Atot Btot wB1 wB2 wA wB 2wA wB Atot wA 1 wA 2 wB wA 2wB wA Pairing (5) costs Btot Since by hypothesis wA 1 is (4). wA 2 wA wB1 wB2 wB , the most convenient pairing 14 Proceedings in Informatics From the proofs of Propositions 4 and 5, it follows that the shapes of the superfamilies are chosen according to the weights of some of their components. Therefore, at the beginning of the algorithm, we must order Ev1 and Od1 families according to wF and wF1 wF2 wF , respectively. We then pair families of maximum weight according to Proposition 3, and the remaining families according to Proposition 4 and 5. Summing up, our algorithm computes all values of the minimal weighted members of all families, and the values of Ftot and wF . This can be done in O n time as well as the computation of members that classifies them into Ev0 1 or Od0 1 families. After that, it orders Ev1 and Od1 families, and then starts the pairing phase that brings us to have only Ev0 and Od0 (super)families. Finally, we solve the instance we are left with as in Section 2. The overall algorithm thus requires O n logn computational time. 4 Further complications 4.1 Sharing triple rooms In this case we have to consider 6 different types of families (analogously to Section 3.2): Ev0, Ev1, Ev2, Od0, Od1, Od2. Again the idea is that of building superfamilies of type Ev0 first, and then some of type Od0. We can obtain Ev0 superfamilies by pairing Od2 and Ev1 families, or Od1 and Ev2 ones. Since this is the cheapest possible pairing, we have to perform it as long as possible, by choosing the families with maximum weight members. After this first step, we have to deal with four distinct cases: 1. If the remaining families are of type Od1 and Od2, we can pair them to obtain Od0 superfamilies, until we are left with only Od1 or only Od2 families. 2. If the remaining families are of type Ev1 and Ev2, we can pair them to obtain Od0 superfamilies, until we are left with only Ev1 or only Ev2 families. 3. If the remaining families are of type Ev1 and Od1, we can join three of them with the same strategy of Section 3.1. 4. If the remaining families are of type Ev2 and Od2, some persons from the same family must be separated. Again we follow the strategy of Section 3.1. After this second step we are left with Ev0, Od0 (super)families, and with families of at most one of the remaining types. As usual we proceed like in Section 3.1. Summing up the algorithm consists of three steps, each one of computational cost O n logn . Ciriani et al.: Efficient Optimal Greedy Algorithms for Room Allocation 15 We can follow the same strategy to solve the problem in which k, instead of three, PhD students have to share a room. It is easy to verify that the number 2, and the overall computational cost is of steps now becomes log k 1 O n logk logn . 4.2 Sharing double and triple rooms We now consider a more general case, which summarizes all the previous situations, namely the case in which professors have the right for single rooms, lectures have to share double rooms, PhD students are collected into triple rooms, and we count both internal and external conflicts. There are 12 different types of families: Evi j and Odi j with i 0 1 and j 0 1 2, where a family is of type Evi j (Odi j) iff it has i mod 2 lecturers, j mod 3 students, and it occupies and even (odd) number of possibly incomplete rooms. For each type we can identify a local room allocation that minimizes the number of external conflicts. Unfortunately, the strategy applied to the previous cases fails here, since the shapes of the optimal arrangments of single families do not always fit into each other (unlike the situation studied in Section 3.2). In fact we have four types of families, which have to share both double and triple rooms: Ev11, Ev12, Od11 and Od12, and for all but one of them (Od11), the optimal local allocation is such that the two shared rooms are located at different borders. On the contrary, in the locally optimal shape of Od11 the two shared rooms are located at the same border. Thus, the direct generalization of the algorithm described in Section 3.2 fails in reaching the optimal solution. Nevertheless, we can prove that it provides a 4/3-approximation. The idea is to apply the algorithms described in Sections 3.2 and 4.1 separately at each border. Families with only one shared room can be processed exactly with these algorithms. Thus, we proceed as follows. We pair two-shared-rooms families as long as possible. We are then left with one or more two-shared-rooms superfamilies, and we can proceed applying the previous algorithms at the borders of these superfamilies. The only problem is given by Od11 families, whose minimum cost shape presents the two shared rooms at the same border. In order to apply the above strategy, we then have to choose a different shape for these families. Note that this is the only case in which the cost of the room allocation given by our algorithm may differ from the optimal cost. The overall computational cost is again O n logn . We finally prove the following proposition: Proposition 6 The above algorithm is a 4/3-approximation. Proof [Sketch] The difference between the cost of the shape of each Od11 family O chosen by the algorithm and the corresponding optimal one is given by O 2 O1 , 16 Proceedings in Informatics where O1 and O2 are the member of O with the two minimum weights. Therefore the solution of the algorithm costs OPT ∑O Od11 f amilies O2 O1 , where OPT denotes the cost of the optimal solution. Since the cost of the optimal shape of the Od11 family O is greater than 3O 1 3O2 , the thesis easily follows. Conclusions and further work The problem of room allocation with only single rooms and counting only external crashes, addressed in Section 2, can be viewed in the following way: min XQX ∑i Xi j 1 ∑ j Xi j 1 Xi j 0 1 where Xi j 1 if room j is allocated to the person i, and it is Xi j 0 otherwise. The constraints ∑i Xi j 1 and ∑ j Xi j 1 ensure that there is a one-to-one correspondance between rooms and people. The matrix Q is defined in the following way: Qi jhk 0 0 wi wh if k j N if k j N and i and h belong to the same family if k j N and i and h do not belong to the same family. where k i N iff rooms i and k are neighbor. This is a special case of a quadratic assignment problem (QAP, see [3, 2, 1]). The QAP is in general computationally difficult, and considered as one of the hardest discrete optimization problems to solve to optimality. For some special cases, it has been shown that polynomial solutions exist (see [3, 2, 1]). To our knowledge, there are no published proofs that the problem in the version shown above, and solved in linear time in Section 2, is polynomial. Therefore, it is worth to investigate whether our linear solution can determine a new class of QAP that result in polynomially solvable problems. Another interesting question is that of understanding the complexity of the problem studied in Section 4.2. We conjecture that it is NP-hard. Acknowledgments We thank Antonio Frangioni for interesting discussions about quadratic assignment problems. Ciriani et al.: Efficient Optimal Greedy Algorithms for Room Allocation 17 References [1] G ALLO , G., AND S IMEONE , B. Optimal grouping of researchers into departments. Ricerca Operativa, 57 (1991), 45–69. [2] M ALUCCELLI , F. A polynomially solvable class of Quadratic SemiAssignment Problems. European Journal of Operational Research, 91 (1996), 619–622. [3] PARDALOS , P. N., R ENDL , F., AND W OLKOWICZ , H. The Quadratic Assignment Problem: A Survey and Recent Developments. DIMACS Series in Discrete Mathematics and Theoretical Computer Science 16 (1994), 1–41.
© Copyright 2025 Paperzz