Full text
Title: Architectural Layout Design with Spectral Methods Author: Júlia Folguera Profitós Advisor: Dr. Jordi Cortadella Fortuny Department: Computer Science Academic year: 2019-2020 Master of Science in Advanced Mathematics and Mathematical Engineering
Universitat Polit`ecnica de Catalunya Facultat de Matem`atiques i Estad´ıstica Master in Advanced Mathematics and Mathematical Engineering Master’s thesis Architectural Layout Design with Spectral Methods J´ulia Folguera Profit´os Supervised by Dr. Jordi Cortadella Fortuny September, 2020
I would like to express my gratitude to Jordi Cortadella for his project proposal —which I have deeply enjoyed— his constant support and his help during the process. I would also like to thank and acknowledge my peers, my family and friends who have been cheering me up and giving me encouragement, not only in the making of this paper, but throughout my studies. A special thank you to Ana¨ıs, Sergi and Laia.
Abstract The design of a floor plan is an important phase of the design of an apartment, although it is very complex due to the quantity of variables involved. The mathematical version of this problem is the architectural layout problem which is an optimization problem that aims to find the best layout of a one-level apartment given an objective function. Since this problem is non-convex and high-dimensional, in this thesis, we will try to find a good initial input so that another algorithm can find a minimum as close as possible to the global minimum. To do so, first we will find the best positions of the centers of the rooms given the design and proximity relations between rooms set by the user using spectral graph drawing. Then, we will preprocess the result so that it can be used as an input of another algorithm. Keywords Floor plan, architectural layout, spectral methods, graph visualization, non-convex optimization 1
Contents 1 Introduction 3 2 Problem statement and graph model 5 3 Resolution of the problem 7 3.1 Initial guess: Rooms’ centers ................................. 8 3.1.1 Constraints ...................................... 13 3.2 Definition of the rooms’ walls ................................. 22 3.2.1 Finding the bounding box of minimum size ..................... 22 3.2.2 Minimizing the intersection .............................. 26 4 Example: A medium sized apartment 30 5 Conclusion and prespective 34 5.1 Future work .......................................... 34 5.2 Acquired knowledge ...................................... 34 A Proofs of propositions 36 B Program of the example of chapter 4 39 C Program to produce the no-intersection model of chapter 4 44 D Program to produce the minimum boundary box model of chapter 4 47 2
1. Introduction One of the most important aspects when designing an apartment is the design of its layout. It is a complex process, due to the quantity of variables that are involved in it, as well as the fact that not only technical objectives — such as maximizing the natural light in the living areas — are taken into account, but also aesthetic ones. In order to automate it, the problem has been mathematically modeled. It is called space layout planning, or floor planning and it is an optimization problem which objective is to find the best arrangement of a set of elements (the rooms) taking into account a given criteria. For instance, we could want to have an apartment with maximum natural light in the bedroom and kitchen, with the bathroom near the kitchen and with given areas for each of the rooms. To mathematically solve the problem, an objective function is put as the weighting of this parameters, and the problem is thus constructed as an optimization problem. This problem has been widely studied, giving rise to different approaches that will be later summarised. However, since the dimension of the variables is usually large and the problem non-convex, no good algorithm is known. The idea of this project came from paper [11], in which, given a graph topology, a gradient-descent algorithm is used to find a good minimum of a function, that summarizes and weights both the aesthetic and technical objectives; and an evolutionary algorithm is used to find the topology with the smallest minimum. However, in this project we take a different approach. Given an initial input (figure 1) that will establish some design preferences of proximity between rooms, we will construct a new graph with the best location of the centers of the rooms (figure 2). Then, we will proceed to find the best dimensions of the rooms (figure 3). Our objective is not to find a feasible floor plan, but to find a good initial input, given the designer objectives, so that another algorithm can find the local minimum to be as close as possible to the global optimum, producing for instance, figure 4. Figure 1: Initial topology graph Figure 2: Best location of the centers of the rooms 3
Layout optimization This implies that the numerator of the objective function is xT 1Lx1+xT 2Lx2. To simplify the denominator, X i<j (x(i)−x(j))2=1 2 n X i=1 n X j=1 x(i)2+x(j)2−2x(i)x(j)=1 2 2n n X i=1 x(i)2−2 n X i=1 n X j=1 x(i)x(j) =n n X i=1 x(i)2=nxTx Finally, the model explained at (1) can be expressed: minimize x1,x2∈Rn xT 1Lx1+xT 2Lx2 xT 1x1+xT 2x2 such that: xT 1x1=xT 2x2= 1 xT 1x2=xT 11n=xT 21n= 0 We only need one further change before solving the optimization problem, which is to use D-normalize vectors. As the numerator will tend to centralize higher degree vertices, the degree normalized denominator will help scatter them. The optimization problem is: minimize x1,x2∈Rn xT 1Lx1+xT 2Lx2 xT 1Dx1+xT 2Dx2 such that: xT 1Dx1=xT 2Dx2= 1 xT 1Dx2=xT 1D1n=xT 2D1n= 0 (2) We already have the optimization problem to be solved. The solution has to do with the eigenvectors of the Laplacian, and thus, we call this process spectral graph drawing. We need a prior result before finding the solution of the optmization problem. Lemma 3.1. Consider v1, ... , vp−1∈Rnand X ∈Rn×pa matrix whose columns are orthogonal. Then there exists a matrix Y whose columns are also orthogonal and holds: 1. For all 2≤k≤p, the column k of Y , Y kis orthogonal to v1, ... , vk−1. 2. For all n ×n matrix A, tr (XTAX) = tr (YTAY ). This lemma can be used to prove that the solution of the optimization problem is the two smallest generalized eigenvectors of (L,D), that is the xsuch that there exist λand xTL=λDx. Recall that we will order the eigenvectors according to their respective eigenvalues. Then if λ1≤ · · · ≤ λnwe will say that the smallest eigenvector is v1. A generalized version of our problem is: 10
Theorem 3.2. Consider a symmetric positive definite n×n matrix A and a diagonal positive definite matrix B∈Rn×nand p <n. The solution of the optimization problem minimize x1,...,xp∈Rn n P i=1 xT iAxi n P i=1 xT iBxi such that: xT 1Bx1=· · · =xT pBxp xT iBxj= 0 ∀1≤i,j≤p is the smallest generalized eigenvectors of (A,B). Now that we know why it is called spectral graph drawing, it would be useful to gather more knowledge about the Laplacian. Some of its properties are: 1. L is real symmetric, then it has neigenvalues and all of them are real and its eigenvectors are orthogonal. 2. The columns and files of the Laplacian sum 0, then L1n= 0, thus 1nis an eigenvector of Lwith eigenvalue 0. 3. The multiplicity of the eigenvalue 0 is the number of connected components and hence in our graphs will be one. 4. L is positive semidefinite so its eigenvalues are nonnegative. 5. The generalized eigenvalues of (L,D) are in [-1,1]. The generalized eigenvalues of (L,D) are the eigenvalues of D−1L. Then the result is due to the Gershgorin theorem, which states that the eigenvalues have to be in the discs of center the elements of the diagonal and radius the sum of the files without the diagonals. Finally another property that is held is: Proposition 3.3. The generalized eigenvectors of (L,D)are also the generalized eigenvectors of (A,D) with reverse order. Now we will derive a force algorithm. Deriving xTLx =P(i,j)∈Eωij (x(i)−x(j))2, ∂xTLx ∂x(i)= 2 X j:(i,j)∈E ωij (x(i)−x(j)) So the minimum is in x(i) = P j:(i,j)∈E ωij x(j) degi That means, the best location for iis at the centroid of its neighbors. The first algorithm seems to be created by Tutte and consists on move, at each iteration, all the vertices to the centroid of its neighbors. In 11
Layout optimization order to avoid degenerative solutions, a convex face of the drawing should be fixed. The algorithm presented on [8] does not need this special vertices, but takes into consideration that degenerate solutions should be avoided, that is, eigenvector 1nof degenerate eigenvalue 0. We avoid this one, imposing orthogonality against it. As we have seen, the solution to the problem is the generalized eigenvectors of (L,D), that is, xso that Lx =λDx, or λx=D−1Lx, that can be rewritten point to point as λx(i) = x(i)−P j:(i,j)∈E ωi,jx(j) degi So we have to move the vertexes that are in the center of the drawing, to the centroid of their neighbors; and the ones that are on the boundary of the drawing have to be shifted a little bit outside. As we have seen in proposition 3.3, we can swap Lfor A. But now we do not search for the smallest eigenvector, but for the biggest one, since the order is reversed. Then, the algorithm that helps finding the solution to the first axes, should be: x0such that xT 0D1n= 0n×n xi+1 =D−1Axi The process converges to the dominant eigenvector, that is, the one with the greatest eigenvalue, using the absolute value. But this could be either v2or vnand we want to converge to v2. Since the eigenvalues are in [−1, 1] we can find the eigenvectors of 1 2Id +D−1A In this way, the eigenvectors will be the same but the eigenvalues will be in [0, 1] and so the dominant will have to be v2. In fact, the dominant would be the eigenvalue 0, but as it is a degenerate one, we will omit it. On the other hand, it is not needed to impose orthogonality in each iteration, but because of the numerical stability, it is better to do so. The process described above is used for unidimensional drawing, but although we want a bidimensional drawing, the procedure is the same for the second axes. Instead of stopping the algorithm when the distance between points is too small, it is better to stop it when the change of direction is negligible. Finally the algorithm would be: 12
/∗N = number of v e r t i c e s , P = dimension of the drawing +1, i n our case 3 u = 3xN matrix with the e i g e n v e c t o r s . So we a l r eady have u [0]=1N. u1 , u2 = 2xN matrix with our computations ∗/ /∗To compute the top e i g e n v e c t o r s of (1/2)D−1A∗/ u2 [ 0 ] , u2 [1]= /∗Random i n i c i a l i z a t i o n ∗/ for ( i t e r =1; i t e r <1000 && ( prod [0] <tol | | prod [1] <t o l ) ; i t e r ++){ for ( i =0; i <(P−1); i++) u1 [ i ] = u2 [ i ] /∗D−o r t h o g o n a l i z e a g a i n st p re vi ou s veps ∗/ for ( i =0; i <(P−1); i ++){ for ( j =0; j<=i ; j++) u1 [ i ]=u1 [ i ]−u1[i]TDu[j] u[j]TDu[j] } /∗M u l t i p l y with 0 . 5 ( I+D−1A) ∗/ for ( i =0; i <(P−1); i++) u2 [ i ] = 1 2Id +D−1Au1[i] /∗Normalize∗/ for ( i =0; i <(P−1); i++) u2 [ i ] = u2 [ i ] / modul ( u2 [ i ] ) /∗Compute the dot product ∗/ for ( i =0; i <(P−1); i++) prod [ i ] = u1 [ i ]∗u2 [ i ] /∗Save the r e s u l t s ∗/ for ( i =0; i <(P−1); i++) u [ i +1] = u1 [ i ] } return u [ 1 ] , u [ 2 ] 3.1.1 Constraints As we have previously seen, the original algorithm is a force algorithm that converges to the eigenvectors of the graph. It consists of three parts that have been needed to adapt to apply the following constraints: 1. D-orthogonalization. This constraint is imposed on each iteration so as to add more information. 2. Multiplication for 1 2(Id +D−1M). So that it converges to the suitable eigenvector. 3. Normalization. Although it can be imposed at the end of the algorithm, it is imposed at each iteration so that the vectors do not explode. The result of this algorithm to a slightly more complex graph that the one of image 5without further constraints is: 13
Layout optimization Figure 7: The optimized graph (right) and the initial one (left) On what follows, we will revisit the constraints previously presented, and explain how each of the three parts have been adapted. Finally, an example of the graph 7with the given constraints will be shown. As we can see in figure 7, since vertices 7 and 9 have the same adjacencies, they are plotted at the same point. There are different solutions to this problem, from adding some constraint as the ones we will see to one of those points, to changing the adjacencies or adding extra repulsion to one of the points. The most difficult part to adapt is the first one, that is, to D-orthogonalize while maintaining the constraints. Two approaches have been developed to solve the problem, giving different results depending on the constraints. The first one will be explained later on and is a variation of the Gram-Schmidt method. The second is to model the optimization problem consisting in D-orthogonalising and minimising the distance to the non-orthogonal point. For instance in the case without any constraint, we would have to solve the following optimizaton problem: minimize ¯x,¯y∈Rn n X i=1 (¯x−x)2+ (¯y−y)2 such that: xTD1n=yTD1n=xTDy = 0 For any other constraint, you only need to add some other constraints to the problem. For instance, for the fixed points, you only need to not allow the movement of those anchored points, excluding them from the variables; for the alignment points, just force the corresponding components to be equal, and so on. The optimization problem is then solved by an NLP solver, giving a good result in a few seconds in each iteration, but slowing down all the process. In fact, in the prior optimization problem we are not minimizing the distance, but the square of it. The reason for this is that, although our solver, Couenne 14
can understand the absolute value, given its exotic behaviour, the runtime was excessive. To conclude, even though this D-orthogonalization gives better results in all of the cases except the fixed points constraint, we only use it to produce the final images. For each constraint, the result of using each of the two D-orthogonalization methods will be shown, and the differences compared. Fixed points. 1. D-orthonormalization. The algorithm uses Gram-Schmidt with the dot product defined as < x,y>=xTDy, but since this method does not maintain fixed coordinates, we need a modified version of this. First, suppose we want to orthogonalize xwith respect to y, where x=x1 x2, y=y1 y2, and x1∈ Rsare the coordinates that we do not want to modify. Then it is sufficient to apply the transformation: ¯y= y1 y2−yTDx xT 2Dx2x2! Check that ¯yis orthogonal to x: ¯yTDx =y1y2−yTDx xT 2D2x2x2D10 0D2x1 x2 =yT 1D1x1+yT 2D2x2−yTDx xT 2D2x2 x2D2y2 =yTDx −yTDx xT 2D2x2 x2D2y2= 0 Consider now that we also want to orthogonalize also z=z1 z2with respect to xand ¯y. The first guess we could make could be ¯z=f(z) = z1 z2−zTDx xT 2Dxx2x2−zTDy y2D2y2y2! But this does not result in an orthogonal vector, since ¯zTDx =−zTDy yT 2D2x2 (yT 2D2x2) ¯zTD¯y=−zTDx x2D2x2 (xT 2D2y2) Even so, the recursion z(k+1) =f2(z(k)) converges to ¯z, orthogonal vector to ¯yand x. z(k)TDx =(z(k)TDx)(yT 2Dx2)2 (yT 2D2y2)(xT 2D2x2)= ... = (zTDy)(yT 2D−2x2)2k (xT 2D2x2)k(yT 2D2y2)k Now, if we consider the dot product <x2,y2>=xT 2D2y2, it is held that (xT 2D2y2)2≤<x2,x2>< y2,y2>= (xT 2D2x2)(yT 2D2y2) and so x(k)TDx →0. Using the same procedure, one can also check 15
Layout optimization that x(k)TD¯y→0. In fact, this converge is really quick, usually taking two iterations at most. The algorithm to D-orthogonalize vector u1 with respect to u[0] and u[1] while maintaining fixed the components of u12and changing u11, is: for ( l =0; l<=j ; l ++) u11=u11−u1T 1D1u[l]1 u[l]T 1D1u[l]1u[l]1 for ( j =0; j<itermax and ( |res1|>tolerance or |res2|>t o l e r a n c e ) ; j ++){ for ( l =0; l <j ; l++) u11=u11−u1T 1D1u[l]1 u[l]T 1D1u[l]1u[l]1 res1=u1TD1N res2=u1TDu1 } 2. Multiplication for (Id +D−1M).No change has been needed besides not taking into account the result of the operation for the fixed coordinates. After the multiplication we have empirically found out that it works much better if we also orthogonalize. 3. Normalization: No modification has been needed, since what is important is the relative position with respect to the others points, but not the absolute position. The result of this method applied to the original graph but with the constraints that vertices 3 and 5 are adjacent to the north; 1 and 3 to the east; 2, 7 and 9 to the south, and 6 the the west, is: Figure 8: N, S, E and W are fixed points using the explained D-orthogonalization method (left) and the NLP model (right) Comparing the result of this method and the best optimum found when introducing directly all the variables and constraint to the solver Couenne they are just a bit different. However, if you compute each of the axis independently and compare them with the corresponding optimization model to the solver, you find that in each direction we have a global optimum. 16
No difference can be seen between the two images. However, the small differences make that our way of D-orthogonalize produce slightly better results than using the NLP solver in each iteration to D- orthogonalize. This was expected, as our method is an adaptation to the one given in paper [8]. If more iterations were done in the NLP solver method, the same results would be found. This will not be the case of any of the others constraints, in which using a optimization solver will lead to better and highly different results. Vertical/horitzontal alignment. 1. D-orthogonalization: The D-orthogonalization can move the points outside the line. Because of that, we D-orthogonalize considering the aligned points as fixed points. 2. Multiplication for 1 2(Id +D−1M):After multiplying, we look for the more adequate regression line. To do so, as it is an horizontal or vertical line, we only need to find the middle point between the other coordinates. After the multiplication we need to D-orthogonalize again. 3. Normalization: Since when normalizing the constraint is maintained, no further change is needed. Figure 9: Vertices 1, 3, 5 and 9 are aligned at the same horizontal line. Using fixed points D- orthogonalization (left) and NLP solver (right) We can see that the results are significantly different depending on which method we use, although applying an horizontal symmetry we can see that the distribution is not completely different. Also the result is better when using the NLP optimization method when D-orthogonalizing. The image of the global optimum found introducing the model to a solver is: 17
Layout optimization Figure 10: Global optimum with 1, 3, 5 and 9 aligned points. Clustering. The procedure to produce a cluster does not change any of the parts of the algorithm, but the graph to be introduced in it. The steps are: 1. Add a new vertex for each cluster, named Vc. 2. Add attractive forces between the vertices of the cluster and Vc. 3. Add repulsive forces between the vertices that are not in the cluster cand Vcand between attractors. 4. Apply the usual algorithm without further modifications. An example of this could be to cluster the first four vertices and the five last ones. The result of the algorithm is: Figure 11: Cluster of the fourth first and fifth last vertices. c1 and c2 are the attractors of each of the clusters. Fixed subgraph The set of points in the subgraph is addressed as if it was a rigid body. One can apply transformations to it, the same transformation for all of the points. 18
1. D-orthogonalize. Since in general we can not guarantee that the relations between the vertices are the ones defined by the subgraph, the algorithm addresses these points as fixed points. 2. Multiply by (1/2) Id +D−1A.The following proceeding is unidimensional so it has to be applied to each of the axes separately. We compute where each vertex should be placed, even the ones in the subgraph, but we do not move them. At the end, we compute which composition of transformations (homotheties, translations or rotations) makes the points before the multiplication be as close as possible to the points after the multiplication. Consider xthe vector with the initial coordinates and yafter the multiplication. We want to find ˆythat minimizes the distance to ywhile maintaining the relationships. The objective is to find ˆy=ax +bsuch that min (X i∈I (ˆy−y)2)= min a,b(X i∈I (ax +b−y)2) Where Iis the set of points on the subgraph. The solution to this problem is obviously the same as the solution to the problem of finding the best fitting line, that is, a=P i∈I (xi−¯x)(yi−¯y) P i∈I (xi−¯x)2,b= ¯y−a¯x Since we do the square of the remainder, we do not get the best option but just a good approximation. It is better to D-orthogonalize after multiplying so that it can converge better. 3. Normalization. No change to this part has been done, maintains the relation between vertices, is just to apply an homothety. An example of this constraint could be, for instance, to impose that vertex 7 has to be the midpoint of vertex 5 and 6. That could be the case in which we want a room, for example, a bathroom to be exactly between two other rooms, like a pair of bedrooms. The result of the algorithm is: Figure 12: Vertex 7 is the midpoint of 5 and 6. D-orthogonalizing using our algorithm (left) and D- orthogonalizing optimization model (right) The comparison with the global optimum obtained introducing the minimization problem to an NLP solver reveals that it is better to D-orthogonalize using an NLP solver. The global minimum is quite different from the others images. It is: 19
Layout optimization Introducing the described requirements into a model for the NLP solver, we get the global optimum in a small amount of time and it is the following: Figure 19: Solution to model of minimizing area of bounding box Some of the rooms that we preferred to be in contact in the graph preferences, do not touch, for instance rectangles 3 and 7, or on the contrary (rooms 5 and 8), but this can be corrected by changing the initial rectangle graph. On the other hand, the centers of the rooms of the final output are near the ones computed as initial output. So to summarise, it may be a good model if you do not have a prior boundary rectangle. 3.2.2 Minimizing the intersection Suppose now that we have a predefined boundary box, the space where we can construct the apartment, and we want to find an initial position with minimum intersection to introduce to a gradient based algorithm. Some of the constraints are the same as in the previous model, concretely the minimum area and the aspect ratio constraint. The non-intersection constraint has to be obviously eliminated. Finally, the relative position constraint has to be modified and a new constraint has to be added. Relative position: As most of the rectangles do intersect, they are neither on the left nor right, and we will have to consider the relative positions between the centers of the rectangles. We do not need to write the n(n−1) constraints, but only 2n: for each point we just consider the relative position between it and the nearest point on the right and upper. Boundary box: In this model we have a fixed rectangular boundary box and all rooms have to be inside it. If the boundary box is [Wd,Wu]×[Hd,Hu] then the constraint that has to be added for every i is: 26
Wd≤xi−0.5wi,xi+ 0.5wi≤Wu Hd≤yi−0.5hi,xi+ 0.5hi≤Hu Then we need to find the objective formula to minimize, that is, the area of intersection. Since the possible combinations that can have two rectangles that intersect are: Figure 20: Possible types of intersections between a pair of rectangles Let iand jbe two intersecting rectangles and let ibe on the left of j. Then the intersection can be expressed as: min {xi−xj+ 0.5 ∗(wi+wj), wi,wj}min {−|yi−yj|+ 0.5 ∗(hi+hj), hi,hj} But this function of computing the area of intersection has two big problems. First, it produces a greater than zero output when there is no intersection between the rectangles and second, it can not be model with simple functions without the use of maximum or minimum functions. Despite this, it can be simplified in such a way that it corrects the two problems: Iij = max{0, (xi−xj+ 0.5 ∗(wi+wj))}max{0, (−|yi−yj|+ 0.5 ∗(hi+hj))} Where the maximum is done to have an area of intersection 0 if rectangles do not intersect. Obviously, this does not compute the correct area of intersection, but it is a good enough approximation of it. This can be modeled as: 27
Layout optimization Ix ij ≥0 Ix ij ≥(xi−xj+ 0.5 ∗(wi+wj)) Iy ij ≥0 Iy ij ≥(−|yi−yj|+ 0.5 ∗(hi+hj)) Iij =Ix ij Iy ij Finally, the function to minimize is: I=X i:xi<xj Iij As an example of the output of the model, we have considered the same examples as before. The minimum areas of each room are set proportional to its degree in the graph. Finally, the height of the rectangle has been set to be at minimum a half and no more than three times its width. The global optimum of this optimization problem, computed with Couenne, is: Figure 21: Solution to the no intersection model This image is a good optimum but the layout is very different from the initial one and the properties may not be maintained. In order to correct this, we may add to the objective function a weighing of the square of the remainder, that is, k n X i=1 (xi−¯xi)2+ (yi−¯yi)2,k≥0 Where ¯x, ¯yare the solution to the layout of the centers of the rooms found in chapter 3.1; and k≥0 is the weighing we want to give to the proximity of the solution to the initial one. In the following images the problem with the same parameters as before is solved using a different weighing of the proximity function: 28
Figure 22: Solution to the no intersection model for k= 0.5 (left) and k= 1 (right) As we can see, as we put more importance to the proximity to the initial layout graph, the rectangles layout loses the rectangular structure but gains the resemblance to the initial graph. 29
Layout optimization 4. Example: A medium sized apartment Until now we have only presented a simple example used to illustrate the ideas we wanted to explain, but without any touch with real floor plans. In this chapter, however, we will take ideas from a real floor plan and compare the output obtained with our algorithms with the reality. The programs to produce the figures and results of this section are written in C and are in the appendixes B,Cand D. The apartment choosen was a 4-bedrooms apartment. Its owners asked for the following properties of the apartment: •The space that can occupy the apartment can have windows in any direction but in the south, although can only have terraces on the east or west. •we want the flat to have two separate spaces, one public with the kitchen, a studio, a dinning room and a terrace; and one more private with the bedrooms and a private studio. •We need 3 bedrooms. •We need 2 bathrooms, one to be used both for the family and their guests, and one next to the main bedroom. •We want the studio that is in the public space to be at the west space, so that it has better light at the afternoon. The other studio to be near the main bedroom. •We would prefer the living room to be at the east, so taht it has better light in the morning. •A terrace in each of the possible direction, (east and west). •Finally, the main bedroom to be at the east. This requirements can be mathematically modeled with the following constraints: 1. Add two fixed points. One on the right and one on the left. Add the following adjacencies: •East: The living room, one terrace, the main bedroom. •West: Studio, one terrace. 2. Add two clusters. One to cluster the private rooms and the other one the public ones. 3. Finally, restrict the main bedroom, another bedroom and both bathrooms to be horizontally aligned. In total, then, we have to construct a 15-vertices graph. The meaning of each vertex and the approximate area that occupy its corresponding room in the reality are: Vertex What Area Vertex What Area Vertex What Area 1 Bedroom 17 6 Priv. Studio 6 11 Studio 10 2 Main Br 21 7 Terrace W. 6.5 E East 3 Priv. Wc 6 8 Kitchen 13.5 W West 4 Bathroom 5 9 Living room 26 C1 cluster 1 5 Bedroom 8 10 Terrace E. 9 C2 cluster 2 30
After applying the algorithm described in section 3.1 with the previously described constraints, the graph obtained is: Figure 23: Output graph with the fixed points, W and E and the cluster attractos points, c1 and c2 As we can see, this graph is not very sparse, but follows all the conditions needed. Our algorithm output has a minimum near the global minimum. Instead of the value for the objective function, xTLx +yTLy as explained in chapter 3.1, that we get, 0.9776 the global minimum is less than 0.9072. In fact, the global minimum could not be found by our solver due to the time complexity. Although in this project we have not dealt with corridors, and they should be added a posteriori, in this example, and for visual purposes, we will set the second cluster to be the entrance hallway and the first to be a corridor. Different solutions for the problem of minimizing the intersection with different degrees of influence on the distance between the centers of the initial graph and the actual centers of the rectangle are: 31
Layout optimization Figure 24: Minimum intersection. Degree of influence of 0 (left), 0.5 (right) and 1 (lower) We could see that the approximated intersection areas was almost exact for all pairs of rectangles but for the case c1, c2. In this case the approximated value was double the currently one. The other model, which impose no intersection and minimizes the area of the bounding box, gives as a result: Figure 25: Minimum boundary box. The left image is produced using the initial rectangles as explained in chapter 3.2.1, that is, squares as large as possible, whereas the right one uses a slightly different initial rectangles, the ones that seemed better to us after different attempts. 32
None of the produced floor plans is feasible, although seems to be a good start of another algorithm, and is more or less similar to the real floor plan: Figure 26: Floor plan of a real apartment 33
Layout optimization 5. Conclusion and prespective In this project we have tried to give a good initial layout to solve the complex problem of floor planning. First, we have used spectral graph drawing in order to find the best location of the centers of the rooms given the design preferences. We have also adapted this algorithm to different requirements and constraints that could be encountered when planning an apartment. Although sometimes in this case we could not find the global minimum, in all the studied cases the difference was small enough. Two algorithms have been studied for the process of D-orthogonalization, since it is where the problems arises the most: if we orthogonalize using Gram-Schmidt, it seems that we are not looking at the entire set of feasible solutions, but on a subset of this, thus maybe not finding any minimum; whereas modelling the problem as an optimization one and solving it through some nonlinear solver, usually led to better results. After we have found the best layout of the centers of the rooms, we have created a pair of models to preprocess the data before applying another algorithm — that has not been developed in this project — that would find the minimum. In this way, we still can maintain the good properties created but minimize the intersection or the boundary box, depending on our needs. 5.1 Future work None of the results of our project is by itself a feasible floor plan, but it is one that, maintaining all our preferences, could be a good initial layout to another algorithm. This part should be further studied, comparing the results of our initial layout and other types of layouts, and weighing the aesthetics properties that have been created using the force algorithm. Another part that should be deeply studied is the model of the corridors. In this work, we have tried two approaches. The first, is to include in the design preferences the corridors, and require that every room is adjacent to its assign corridor. The second, is to use clusters, if needed, to group rooms to the same corridor. Another third option, that is used in some papers, is to find the minimal tree that goes through all the rooms of the graph. In this project we have not seen which method is better to use, and the answer may vary from problem to problem. 5.2 Acquired knowledge In this project I have been introduced to the problem of floor planning and also to graph drawing and spectral graph theory, which I did not know beforehand. I have also learned about NLP solvers and the modeling language AMPL, practising and learning about mathematical optimization. Nevertheless, the most challenging part was to think about the variations of the algorithms to better fit the new constraints and the examples, as well as solving some of the programming problems. 34
References [1] Scott A Arvin and Donald H House. Modeling architectural design objectives in physically based space planning. Automation in Construction, 11(2):213 – 225, 2002. ACADIA ’99. [2] Giuseppe Di Battista, Peter Eades, Roberto Tamassia, and Ioannis G. Tollis. Graph Drawing: Algorithms for the Visualization of Graphs, chapter 10. Prentice Hall PTR, USA, 1st edition, 1998. [3] Stephen Boyd and Lieven Vandenberghe. Convex Optimization, chapter 8. Cambridge University Press, USA, 2004. [4] Jose Duarte. Customizing mass housing : a discursive grammar for siza’s malagueira houses. European computer aided architectural design and education, 08 2005. [5] Kernighan B.W. Fourer R., Gay D.M. AMPL: A Mathematical Programing Language. Springer, 1989. [6] Goos Kant and Xin He. Two algorithms for finding rectangular duals of planar graphs. 790, 07 1994. [7] Michael Kaufmann and Dorothea Wagner. Drawing graphs. Methods and models, chapter 4, volume 2025. Springer, 01 2001. [8] Y. Koren. Drawing graphs by eigenvectors: theory and practice. Computers & Mathematics with Applications, 49(11):1867 – 1888, 2005. [9] Danny Lobos and Dirk Donath. The problem of space layout in architecture: A survey and reflections. Arquitetura Revista, 6:136–161, 12 2010. [10] Wenqi Huang Mao Chen. A two-level search algorithm for 2d rectangular packing problem. Computers & Industrial Engineering, 53(1):123 – 136, 2007. [11] Jeremy Michalek, R. Choudhary, and Panos Papalambros. Architectural layout design optimization. Engineering Optimization, 34:461–484, 09 2002. [12] Krishnendra Shekhawat. Algorithm for constructing an optimally connected rectangular floor plan. Frontiers of Architectural Research, 3(3):324 – 330, 2014. [13] Nitant Upasani, Krishnendra Shekhawat, and Garv Sachdeva. Automated generation of dimensioned rectangular floorplans. Automation in Construction, 113:103149, 2020. [14] Machi Zawidzki and Jacek Szklarski. Multi-objective optimization of the floor plan of a single story family house considering position and orientation. Advances in Engineering Software, 141:102766, 2020. 35
Layout optimization 166 167 for (i = 0; i < N; i ++) 168 mod = mod + v[i]*v[i]; 169 170 return sqrt (mod ); 171 } 172 173 /* Input: the boolean vectors of the aligned and fixed points , the coordinates of the points and the degree matrix 174 Output : u will be returned with the new D- orthogonal more nearer points */ 175 /* This function D- orthogonalize the points of u so that the distance between the introduced points and the orthogonal ones is minimum */ 176 void Dorton(int aligned [N], int fix [N], double u[P -1][ N], int D[N][N]){ 177 178 int i, k; /*k will be used to compute de constraints */ 179 double firstAligned; 180 char cou []= " ortonormal . mod ", csor []=" proau . out "; 181 FILE * orton , * cout ; 182 /* cou ( orton ) the model to introduce to the solver 183 csor ( cout ) where AMPL will write the solution to the optimization problem */ 184 185 orton = fopen (cou , "w"); 186 187 /* Defining the variables */ 188 for (i = 0; i < N; i ++) 189 if ( fix[i] == 0) 190 fprintf (orton , " var x%d:=% le ;\ nvar y%d :=% le ;\n" , i+1 , u [0][ i], i+1, u [1][i ]); 191 else 192 fprintf (orton , " param x%d :=% le ;\ nparam y %d :=% le ;\n" , i+1, u [0][ i], i+1, u [1][i ]); 193 194 /* Minimization objective */ 195 fprintf (orton , " minimize obj : 0"); 196 for (i = 0; i < N; i ++) 197 fprintf (orton , "+ (x%d - % le )^2 + (y%d - %le )^2", i+1, u [0][i], i+1, u [1][ i]); 198 199 /* Constraints */ 200 fprintf (orton , ";\ nsubject to c1: 0"); 201 for (i = 0; i < N; i ++) 202 fprintf (orton , " +% le *x%d" , D[i][i], i +1); 203 fprintf (orton , "=0;\ nsubject to c2 : 0"); 204 for (i = 0; i < N; i ++) 205 fprintf (orton , " +% le *y%d" , D[i][i], i +1); 206 fprintf (orton , "=0;\ nsubject to c3 : 0"); 207 for (i = 0; i < N; i ++) 208 fprintf (orton , "+%le*x%d*y%d", D[i][i], i+1, i+1); 209 fprintf (orton , "=0; "); 210 211 /* Aligned points: We search for the first aligned point of the vector aligned and then equal the other found with it */ 212 for (i = 0, k = 4, firstAligned = -1; i < N; i ++) { 213 if ( aligned [i] == 1) { 214 if (firstAligned == -1) 215 firstAligned = i; 216 }else { 217 fprintf (orton , " subject to c%d: y%d=y%d ;\ n" , k, (int)( num +1) , i+1) ; 218 k++; 42
219 } 220 } 221 222 /* Pass to Couenne */ 223 fclose ( orton ); 224 system(" ampl <couenC . run "); 225 226 /* Save the values */ 227 cout = fopen ( csor ,"r"); 228 for (i = 0; i < N; i ++) 229 fscanf ( cout , "%le %le", &u[0][i], &u [1][ i]); 230 fclose ( cout ); 231 } 43
Layout optimization C. Program to produce the no-intersection model of chapter 4 1#include < stdlib .h > 2#include < math.h> 3#include < stdio .h > 4#define N 13 5#define P 3 6 7/* input : a file ( points . out ) with the points obtained in the prior algorithm ( graph ) 8output : a file ( modelI . mod ) to introduce to Ampl and solve using couenne */ 9/* This program writes the . mod file to solve the minimizing intersection model */ 10 int main(void){ 11 12 int i, j, k, fx [N][N], fy[N][N], I, J; 13 double U[N ][2] , l[N], u[N], tolerance =1.e -5; 14 FILE * input , * output ; 15 char ent [] = " points . out ", sor []=" modelI . mod "; 16 int horizontalOrder [N] = {7, 11, 1, 8, 4, 5, 12, 13, 6, 3, 2, 9, 10}; 17 int verticalOrder [N] = {8 , 9, 11, 7, 10, 12, 6, 13 , 5, 1, 2, 3, 4}; 18 double A[N] = {17 , 21 , 6, 5, 8, 6, 6.5 , 13.5 , 26 , 9, 10, 10, 7.5}; /* Minimum area */ 19 int aligned [N ]={1 , 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0} 20 21 /* Open the files */ 22 input = fopen (ent , "r"); 23 output = fopen (sor , "w"); 24 25 /* As defined in the model , l * width <= heigh <= u* width */ 26 for(i = 0; i < N; i ++) { 27 l[i] = 0.5; 28 u[i] = 3.; 29 } 30 31 /* Defining variables */ 32 for (i = 0; i < N; i ++) { 33 /*U is the points defined by prior algorithm , we multiply them by the values that make the points to have the same modulum as in the real layout */ 34 fscanf ( input , "%le %le", &U[i ][0] , &U[i ][1]) ; 35 U[i ][0] = U[i ][0] * 18.4840235; U[i ][1] = U[i][1] * 9.83831153; 36 fprintf ( output , " var x%d :=% le ;\ nvar y %d :=% le ;\n" , i +1, U[i ][0] , i+1 , U [i ][1]) ; 37 fprintf ( output , " var h%d:=0.1 , >=1.;\ nvar w%d :=0.1 , >=1.;\ n", i+1 , i+1) ; 38 } 39 40 /* Definition of the parameters */ 41 for (i = 0; i < N; i ++) 42 fprintf ( output , " param A%d =% le ;\ nparam l%d =% le ;\ nparam u%d =% le ;\ n", i+1 , A[i], i +1, l[i], i+1, u[i]); 43 44 /* fx(i ,j) = 1 if j on the right of i*/ 45 /* fy(i ,j) = 1 if j above i*/ 46 for (i = 0; i < N; i ++) { 47 for (j = 0; j < N; j++) { 48 if ( fabs (U[i ][0] - U[j ][0]) < tolerance ) 49 fx[i][j] = 0; 44
50 else { 51 if(U[ i][0] < U[j ][0]) 52 fx[i][j] = 1; 53 else 54 fx[i][j] = -1; 55 } 56 if ( fabs (U[i ][1] - U[j ][1]) < tolerance ) 57 fy[i][j] = 0; 58 else { 59 if(U[ i][1] < U[j ][1]) 60 fy[i][j] = 1; 61 else 62 fy[i][j] = -1; 63 } 64 } 65 } 66 67 /* As explained we need the auxiliar Sxij and Syij . Sij = Sxij * Syij and Sij is an approximation of the intersection between i and j*/ 68 for (i = 0; i < N; i ++) { 69 for (j = 0; j < N; j++) { 70 if (fx [i][j] == 1) 71 fprintf ( output , " var S%do%d, >=0;\ nvar Sx%do%d, >=0;\ nvar Sy%do%d, >=0;\ n", i +1, j+1, i+1 , j+1 , i+1, j+1); 72 } 73 } 74 75 /* Objective function : The sum of the intersections , Sij */ 76 fprintf ( output , " minimize obj: "); 77 for (i = 0; i < N; i++) { 78 for (j = 0; j < N; j ++) { 79 if (fx [i][j] == 1) 80 fprintf ( output , "S%do%d + ", i+1, j+1); 81 } 82 } 83 for (i = 0; i < N; i++) { 84 if ( Aligned [i] == 1) 85 /* Aligned points can share the same x and y variable */ 86 fprintf ( output , " 1*(( x%d - %le)^2 + (y%d - %le)^2) + " , i+1, U[i][0] , 1, U[i ][1]) ; 87 else 88 fprintf ( output , " 1*(( x%d - %le)^2 + (y%d - %le)^2) + " , i+1, U[i][0] , i+1, U[i ][1]) ; 89 } 90 fprintf ( output , " 0;\n"); 91 92 /* Define the constraint to define the objective function */ 93 for (i = 0, k = 1; i < N; i ++) { 94 for (j = 0; j < N; j ++) { 95 if (fx [i][j] == 1) { 96 fprintf ( output , " subject to c%d: Sx% do %d >=( x%d -x%d +0.5* w%d +0.5* w%d) ;\ n" , k, i +1, j+1, i+1 , j+1 , i+1, j+1); 97 /*I,J is 0 (the first aligned point ) if the points are aligned . It ’s value if not */ 98 if ( aligned [i] == 1) I =0; 99 else I=i; 100 if ( aligned [j] == 1) J =0; 45
Layout optimization 101 else J=j; 102 fprintf ( output , " subject to c%d: Sy %do%d >=(% d) *( y%d -y%d) +0.5*( h%d+h%d);\ n", k +1, i+1, j+1 , fy[i][j], I+1, J+1, i+1, j+1) ; 103 fprintf ( output , " subject to c%d: S%do%d=Sx%do%d*Sy% do%d ;\n" , k+2 , i+1, j+1, i +1, j+1, i+1 , j+1); 104 k = k + 3; 105 } 106 } 107 } 108 109 /* such that */ 110 /* Can no go out from its boundary box */ 111 fprintf ( output , " subject to c%d: x%d +0.5* w%d <=7.56212223;\ nsubject to c%d: x%d -0.5* w%d >= -6.783;\ nsubject to c%d: y%d +0.5* h%d <=4.902;\ nsubject to c%d: y%d -0.5* h%d >= -5.624;\ n" , k, horizontalOrder [N -1] , H[N -1] , k+1 , horizontalOrder [0] , horizontalOrder [0] , k +2 , V[N -1] , V[N -1] , k+3 , V[0] , V [0]) ; 112 k = k + 4; 113 fprintf ( output , " subject to c%d: y%d +0.5* h%d <=4.902;\ nsubject to c%d: y%d +0.5* h%d <=4.902;\ nsubject to c%d: y%d +0.5* h %d <=4.902;\ n", k, 1, 1, k+1 , 1, 2, k+2 , 1, 3); 114 k = k + 3; 115 fprintf ( output , " subject to c%d: y%d +0.5* h%d <=4.902;\ nsubject to c%d: y%d +0.5* h%d <=4.902;\ n", k , 12, 12, k+1, 13, 13) ; 116 k = k + 2; 117 fprintf ( output , " subject to c%d: y%d +0.5* h%d >= -5.624;\ nsubject to c%d: y%d +0.5* h%d >= -5.624;\ nsubject to c%d: y%d +0.5* h%d = -5.624;\ nsubject to c%d: y%d +0.5* h%d >= -5.624;\ n" , k, 11, 11, k+1 , 12 , 12, k+2, 13, 13, k+3, 9, 9); 118 k = k + 4; 119 120 /* Maintain the order of the vertices */ 121 for (i = 0; i < (N -1) ; i ++) { 122 fprintf ( output , " subject to c%d: x%d <= x%d +0.005;\ n", k, horizontalOrder [i], horizontalOrder [i +1]) ; 123 k = k + 1; 124 if ( verticalOrder [i ]!=1 && verticalOrder [i ]!=2 && verticalOrder [i ]!=3 && verticalOrder [i ]!=4) { 125 fprintf ( output , " subject to c%d: y%d <= y%d +0.005;\ n", k, verticalOrder [i], verticalOrder [i +1]) ; 126 k = k+1; 127 } 128 } 129 130 /* Minimum area */ 131 for (i = 0; i < N; i++, k ++) 132 fprintf ( output , " subject to c%d: h%d*w%d >= A%d ;\ n" , k, i+1, i+1, i+1) ; 133 134 /* Aspect ratio */ 135 for (i = 0; i < N -2; i++, k++) 136 fprintf ( output , " subject to c%d: h%d <= w%d*u%d ;\ n" , k, i+1, i+1, i+1) ; 137 138 return 0; 139 } 46
D. Program to produce the minimum boundary box model of chapter 4 1#include < stdlib .h > 2#include < math.h> 3#include < stdio .h > 4#define N 13 5#define P 3 6 7/* input : a file ( points . out ) with the points obtained in the prior algorithm ( graph ) 8output : a file ( modelBB . mod) to introduce to Ampl and solve using couenne */ 9/* This program writes the . mod file to solve the minimizing boundary box model */ 10 int main(void){ 11 12 int i, j, k; 13 double U[N ][2] , l[N], u[N]; 14 double A[N] = {17 , 21 , 6, 5, 8, 6, 6.5 , 13.5 , 26 , 9, 10, 10, 7.5}; 15 FILE * input , * output ; 16 char ent [] = " points . out ", sor [] = " modelBB . mod "; 17 /* squareSide is the initial side of the squares defined by the user . 18 horizontal / verticalOrder is the pairs of order without repetition 19 firstLastVert / Horitz are all the combinations of abovemost , lowestmost pairs and rightmost leftmost pairs */ 20 double squareSide [N] = {1.4225288 , 0.8133418 , 0.8133418 , 1.4140854 , 0.8200969 , 0.50186972 , 3.756937 , 0.955928 , 2.9424982 , 4.012473 , 0.955928 , 0.50186972 , 2.9424982}; 21 int horizontalOrder [25][2] = { {1 ,4} , {1 ,5} , {1 ,12} , {2 ,10} , {3 ,2} , {3 ,9} , {4 ,3} , {4 ,6} , {5 ,6} , {5 ,3} , {6 ,2} , {6 ,9} , {7 ,1} , {7 ,11} , {8 ,12} , {8 ,5} , {8 ,9} , {9 ,10} , {11 ,12} , {11 ,13} , {11 ,4} , {11 ,8} , {12 ,3} , {12 ,6} , {13 ,9} }; 22 int verticalOrder [17][2] = { {1 ,5} , {2 ,5} , {3 ,5} , {4 ,5} , {5 ,12} , {5 ,6} , {6 ,7} , {6 ,13} , {6 ,10} , {6 ,9} , {6 ,11} , {12 ,7} , {12 ,13} , {12 ,9} , {12 ,10} , {12 ,11} , {13 ,8} }; 23 int firstLastVert [20][2] = { {1 ,7} , {1 ,8} , {1 ,9} , {1 ,10} , {1 ,11} , {2 ,7} , {2 ,8} , {2 ,9} , {2 ,10} , {2 ,11} , {3 ,7} , {3 ,8} , {3 ,9} , {3 ,10} , {3 ,11} , {4 ,7} , {4 ,8} , {4 ,9} , {4 ,10} , {4 ,11} }; 24 int firstLastHoritz [1][2] = { {7 ,10} }; 25 26 /* Open the files */ 27 input = fopen (ent , "r"); 28 sortida = fopen ( sor , "w"); 29 30 /* As defined in the model , l * width <= heigh <= u* width */ 31 for (i = 0; i < N; i ++) { 32 l[i] = 0.5; 33 u[i] = 3.; 34 } 35 36 /* Defining variables */ 37 for (i = 0; i < N; i ++) { 38 /*U is the points defined by prior algorithm , we multiply them by the values that make the points to have the same modulum as in the real layout */ 39 fscanf ( input , "%le %le", &U[i ][0] , &U[i ][1]) ; 40 U[i ][0] = U[i ][0] * 18.4840235; U[i ][1] = U[i][1] * 9.83831153; 41 fprintf ( output , " var x%d:=% le , <=10, >= -10;\ nvar y%d:=% le , <= 10, >= -10;\n", i 47
Layout optimization +1 , U[i ][0] , i+1 , U[i ][1]) ; 42 fprintf ( output , " var h%d:=% le , >=1.5;\ nvar w%d:=% le , >=1.5;\n" , i+1 , squareSide [i ], i+1 , squareSide [i]); 43 } 44 45 /* Definition of the parameters */ 46 for (i = 0; i < N; i ++) 47 fprintf ( output , " param A%d =% le ;\ nparam l%d =% le ;\ nparam u%d =% le ;\ n", i+1 , A[i], i +1, l[i], i+1, u[i]); 48 49 /* Objective function */ 50 fprintf ( output , " var Ob ;\ n"); 51 fprintf ( output , " minimize obj : Ob ;\ n"); 52 53 /* Constraints for the objective function ( minimizing the area using the maximum length and width with the ordering ) */ 54 for (i = 0, k = 1; i < 1; i ++) { 55 for (j = 0; j < 20; j++, k++) 56 fprintf ( output , " subject to c%d: Ob >=( x%d+w%d /2-x%d+w%d /2) *(y%d+h%d/2 -y%d+h%d /2) ;\ n", k, firstLastHoritz [i][1] , firstLastHoritz [i][1] , firstLastHoritz [i ][0] , firstLastHoritz [i ][0] , firstLastVert [j][0] , firstLastVert [j ][0] , firstLastVert [j ][1] , firstLastVert [j ][1]) ; 57 } 58 59 /* Minimum area */ 60 for (i = 0; i < N; i++, k++) 61 fprintf ( output , " subject to c%d: h%d*w%d >= A%d ;\ n" , k, i+1, i+1, i+1) ; 62 63 /* Apect ratio */ 64 for(i = 0; i < N; i++, k = k+2) 65 fprintf ( output , " subject to c%d: l%d*w%d <= h%d ;\ nsubject to c %d: h%d <= w%d*u%d ;\ n", k, i+1 , i+1 , i+1, k+1 , i+1, i+1, i +1); 66 67 /* No intersection ( first horizontal then vertical ) */ 68 for (i = 0; i < 25; i++, k++) 69 fprintf ( output , " subject to c%d: x%d +0.5* w%d <= x%d -0.5* w%d ;\ n" , k, horizontalOrder [i][0] , horizontalOrder [i][0] , horizontalOrder [i ][1] , horizontalOrder [i ][1]) ; 70 for (i = 0; i < 17; i++, k++) 71 fprintf ( output , " subject to c%d: y%d -0.5* h%d >= y%d +0.5* h%d ;\ n" , k, verticalOrder [i ][0] , verticalOrder [i][0] , verticalOrder [i][1] , verticalOrder [i ][1]); 72 73 return 0; 74 } 48