Exemple #1
0
 def columnSearch(self):
     self.potentialColumns, self.haxes, self.vaxes = WallSkeleton.Columns(
         self.skeletonLevels, 0)
     axes = [self.haxes, self.vaxes]
     nlvls = len(self.skeletonLevels)
     self.axesSolution = tabu_search(self.potentialColumns,
                                     axes,
                                     self.skeletonLevels[nlvls -
                                                         1].slabSkeleton,
                                     limit=20)
     print("Haxis solution:")
     for axis in self.axesSolution.axes[0]:
         print(axis.bounds)
     print("Vaxis solution:")
     for axis in self.axesSolution.axes[1]:
         print(axis.bounds)
     Columns = []
     for Haxis in self.axesSolution.axes[0]:
         for Vaxis in self.axesSolution.axes[1]:
             column = linestring.BaseGeometry.intersection(Haxis, Vaxis)
             if column not in Columns: Columns.append(column)
     Distances = WallSkeleton.ColumnDistances(Columns)
     for i in range(len(Columns)):
         print("Distance of the column", i, "(", Columns[i].x, Columns[i].y,
               ")", Distances[0][i], Distances[1][i])
     print("Total Height here:", self.totalHeight)
     self.Columns, self.ColumnsLength = LevelSkeleton.CreateColumnShapes(
         Distances, self.totalHeight, Columns)
     for Column in self.Columns:
         # VDim = round(Column.poly.MaxCoords().y()-Column.poly.MinCoods().y())
         # Hdim = round(Column.poly.MaxCoords().x()-Column.poly.MinCoods().x())
         print("Column:", Column.centroid, "Vdim:", Column.bounds)
Exemple #2
0
def mergeWalls(wallSkeleton1, wallSkeleton2):
    #select random space from both walls
    voiles1 = wallSkeleton1.getVoilesBetween()
    voiles2 = wallSkeleton2.getVoilesBetween()
    resVoiles = mergeVoiles(voiles1, voiles2)
    resWall = WallSkeleton(wallSkeleton1.poly.copy())
    for voile in resVoiles:
        resWall.attachVoile(voile)
    return resWall
Exemple #3
0
    def restrictLevelUsableWalls(self, levelSkeletons):
        restrictWalls = []
        for levelSkeleton in levelSkeletons:
            toAdd = []
            upperLvlsPolys = [
                lvl.level.slab.getBasePolygon().poly for lvl in levelSkeletons
                if lvl.level.getHeight() > levelSkeleton.level.getHeight()
            ]
            upperPoly = cascaded_union(upperLvlsPolys)
            for wallSkeleton in levelSkeleton.wallSkeletons:
                intersection = wallSkeleton.poly.poly.intersection(upperPoly)
                if type(
                        intersection
                ) is not Polygon or intersection.area != wallSkeleton.poly.area(
                ):
                    toAdd.append(wallSkeleton)
            restrictWalls += toAdd
        resultWalls = []
        for wallSkeleton in restrictWalls:
            for wallSkeleton2 in self.wallSkeletons:
                intersection = wallSkeleton.poly.intersection(
                    wallSkeleton2.poly)
                if intersection:
                    resultWalls.append(WallSkeleton(intersection))

        self.wallSkeletons = resultWalls
Exemple #4
0
    def createNewSkeletonfromLevel(level,SolutionAxes):
        slabSkeleton = SlabSkeleton.createSkeletonFromSlab(level.slab)
        wallSkeletons = []
        lowerlevel = level.getLowerLevel()
        lowZ = None if lowerlevel is None else lowerlevel.slab.getHighestZ()
        print("for ", level, "lowz is: ", lowZ)
        test=False
        if lowZ is None:
            lowZ = 0
        for axis in SolutionAxes.axes[0]:
            print("here axis",axis.coords[0][1])
        for wall in level.walls:
            wallSkeletons += WallSkeleton.createSkeletonsFromWall(wall,
                                                                  lowZ,
                                                                  level.slab.getLowestZ())
        # for wall in level.walls:
        #     wallSkeleton = WallSkeleton.createSkeletonFromWall(wall)
        #     x = round(wallSkeleton.poly.centroid().x,2)
        #     y = round(wallSkeleton.poly.centroid().y,2)

            # for axis in SolutionAxes.axes[0]:
            #     if y==axis.coords[0][1]:
            #         wallSkeletons += WallSkeleton.createSkeletonsFromWall(wall,
            #                                                               lowZ,
            #                                                               level.slab.getLowestZ())
            #         test = True
            # for axis in SolutionAxes.axes[1]:
            #     if x==axis.coords[0][0]:
            #         # print("I am here Vertical",mid,"\n",axis)
            #         wallSkeletons += WallSkeleton.createSkeletonsFromWall(wall,
            #                                                               lowZ,
            #                                                               level.slab.getLowestZ())
            #         test = True
            # if test == False: level.walls.remove(wall)
        return LevelSkeleton(wallSkeletons, slabSkeleton, level)
Exemple #5
0
 def createSkeletonFromLevel(level):
     slabSkeleton = SlabSkeleton.createSkeletonFromSlab(level.slab)
     wallSkeletons = []
     lowerlevel = level.getLowerLevel()
     lowZ = None if lowerlevel is None else lowerlevel.slab.getHighestZ()
     for wall in level.walls:
         wallSkeletons += WallSkeleton.createSkeletonsFromWall(
             wall, lowZ, level.slab.getLowestZ())
     # wallSkeletons = [WallSkeleton.createSkeletonFromWall(wall) for wall in level.walls]
     return LevelSkeleton(wallSkeletons, slabSkeleton, level)
Exemple #6
0
    def showLowerFun(self):
        if self.selectedRow is not None:
            from matplotlib import pyplot as plt
            levelSkeleton = self.skeletonLevels[self.selectedRow]
            if levelSkeleton in self.solutions:
                levelSkeleton = self.solutions[levelSkeleton].levelSkeleton
            polys, colors = self.getPolygonsFromLevelSkeletons(levelSkeleton)
            colors = [[c.red() / 255.,
                       c.green() / 255.,
                       c.blue() / 255., 0.8] for c in colors]
            c = colors[-1]
            # Plotter.plotPolys(polys, self.selectedRow, "plan", colors)
            # plt.savefig('try1.png', bbox_inches='tight')
            polys = [poly.poly for poly in polys]
            alphas = [1 for poly in polys]
            c1 = levelSkeleton.getCenterFromSlab()
            c2 = levelSkeleton.getCenterFromShear()
            polys += [
                Point(c1.x(), c1.y()).buffer(0.1),
                Point(c2.x(), c2.y()).buffer(0.1)
            ]
            colors += [[0, 1, 0], [1, 0, 0]]
            alphas += [1, 1]
            # Plotter.plotShapely(polys, colors, alphas, 30, title="plan")
            boxes = [
                voileSkeleton.getSurrondingBox(self.constraints['d'])
                for wallSkeleton in levelSkeleton.wallSkeletons
                for voileSkeleton in wallSkeleton.getAllVoiles()
            ]

            polys += boxes
            alphas += [0.2 for poly in boxes]

            PotentialColumns, haxes, vaxes = WallSkeleton.Columns(
                self.skeletonLevels, self.selectedRow)
            for PotentialColumn in PotentialColumns:
                polys += [
                    Point(PotentialColumn.x, PotentialColumn.y).buffer(0.1)
                ]
                colors += [[1, 0, 0]]
                alphas += [1, 1]
            axes = haxes + vaxes

            for column in self.Columns:
                polys += [column]
                colors += [[1, 0, 0]]
                alphas += [1, 1]
            Plotter.plotShapely(polys, colors, alphas, 20)
            for axe in axes:
                plt.plot(*axe.xy, color='red', linestyle='dashed', linewidth=1)
            plt.show()
Exemple #7
0
def crossWalls(wallSkeleton1, wallSkeleton2, crossPoint=0.5):
    print "cross Point: " + str(crossPoint)
    #select random space from both walls
    voiles1 = wallSkeleton1.getVoilesBetween(0, crossPoint)
    voiles2 = wallSkeleton2.getVoilesBetween(crossPoint, 1)
    resVoiles = mergeVoiles(voiles1, voiles2)
    resWall1 = WallSkeleton(wallSkeleton1.poly.copy())
    for voile in resVoiles:
        resWall1.attachVoile(voile)

    voiles1 = wallSkeleton2.getVoilesBetween(0, crossPoint)
    voiles2 = wallSkeleton1.getVoilesBetween(crossPoint, 1)
    resVoiles = mergeVoiles(voiles1, voiles2)
    resWall2 = WallSkeleton(wallSkeleton1.poly.copy())
    for voile in resVoiles:
        resWall2.attachVoile(voile)
    return resWall1, resWall2
Exemple #8
0
    def removeUnwantedWalls(LevelSkeletons,SolutionAxes,Columns):
        for levelSkeleton in LevelSkeletons:
            newWallSkeletons1 = []
            newWallSkeletons4 = []
            print("number of level", LevelSkeletons.index(levelSkeleton))
            for wallskeleton in levelSkeleton.wallSkeletons:
                y = round(wallskeleton.poly.centroid().y, 2)
                x = round(wallskeleton.poly.centroid().x, 2)
                print("here wall ",levelSkeleton.wallSkeletons.index(wallskeleton),":",x,y)
                for axis in SolutionAxes.axes[0]:
                    # print("here axis:",axis)
                    if y==axis.coords[0][1] :
                        newWallSkeletons1.append(wallskeleton)
                        # print("added horizontal")
                for axis in SolutionAxes.axes[1]:
                    if x==axis.coords[0][0] :
                        newWallSkeletons1.append(wallskeleton)
                # if not test: levelSkeleton.wallSkeletons.remove(wallskeleton)
            for wallsklt in LevelSkeleton.removeColumnIntersections(newWallSkeletons1,Columns):
                newWallSkeletons4.append(wallsklt)

            for Column in Columns:
                pnts = Column.exterior.coords
                Pnts = []
                for i in range(len(pnts)): Pnts.append(Pnt(pnts[i][0], pnts[i][1]))
                wall = Poly(Pnts)
                wallsklt = WallSkeleton.createSkeletonFromPoly(wall)
                wallsklt.iscolumnParent = True
                newWallSkeletons4.append(wallsklt)

            NewWallSkeletons = []
            for wall in newWallSkeletons4:
                if wall not in NewWallSkeletons: NewWallSkeletons.append(wall)
            levelSkeleton.wallSkeletons = copy.deepcopy(NewWallSkeletons)


        return LevelSkeletons
Exemple #9
0
 def Addnewpolys(polygon):
     newwallsklt = WallSkeleton.createSkeletonFromPoly(polygon)
     return newwallsklt
Exemple #10
0
    def multiSearch(self):
        def mygen2():
            c = {
                "rad_w": 0,
                "ecc_w": -0.5,
                "area_w": 3,
                "length_w": 1,
                "ratio": 1,
                "d": 1,
            }
            area_w = [0.1, 0.5, 1, 1.5, 2]
            length_w = [0.1, 0.5, 1, 1.5, 2]
            for aw in area_w:
                c['area_w'] = aw
                yield c
            c['area_w'] = 1
            for lw in length_w:
                c['length_w'] = lw
                yield c

        def mygenprov():
            c = {
                "rad_w": 0,
                "ecc_w": 0.5,
                "area_w": 5,
                "length_w": 0,
                "ratio": 1,
                "d": 1,
            }
            yield c

        def mygen():
            c = {
                "rad_w": 1,
                "ecc_w": -0.5,
                "area_w": 1,
                "length_w": 5,
                "ratio": 1,
                "d": 1,
            }
            area_w = [1.5, 2, 3, 4, 10]
            d_ratios = [0.25, 0.5, 0.75]
            for d in d_ratios:
                c['d'] = d
                for w in area_w:
                    c['area_w'] = w
                    yield c
                    break
                break

        count = 1
        for consts in mygenprov():
            dirname = 'savedWrong/constraints' + str(count) + '/'
            if not os.path.exists(dirname):
                os.makedirs(dirname)
            open(
                dirname + 'constraints.txt',
                'w').write("Torsional radius weight: " + str(consts['rad_w']) +
                           "Eccentricity weight: " + str(consts['ecc_w']) +
                           "\nShear Wall length weight: " +
                           str(consts['length_w']) +
                           "\nShear Wall cover area weight: " +
                           str(consts['area_w']))
            self.constraints = consts
            self.init_skeletons(ind=1)
            self.solutions = {}
            froot = dirname + '/'
            if not os.path.exists(froot):
                os.makedirs(froot)
            f = open(froot + 'Scores.txt', 'w')
            scores = []
            for levelSkeleton in self.skeletonLevels[::-1]:
                if self.skeletonLevels.index(levelSkeleton) == len(
                        self.skeletonLevels) - 1:
                    self.ColumnsVoileSkeleton = WallSkeleton.ColumnToVoile(
                        self.Columns, levelSkeleton.wallSkeletons)
                    levelSkeleton.addColumnsAsVoiles(self.ColumnsVoileSkeleton)

                level = self.skeletonLevelsHash[levelSkeleton]
                prevs = [
                    self.solutions[self.levelsHash[p]].levelSkeleton
                    for p in level.getUpperLevels()
                    if self.levelsHash[p] in self.solutions
                ]
                print(("PREVS LENGTH IS", len(prevs)))

                if len(prevs):
                    levelSkeleton.copyLevelsVoiles(prevs)
                i = self.skeletonLevels.index(levelSkeleton)
                distributionScore = 0.6
                SYM = 0
                # overlapscore = 1
                j = 1

                w = [0.5, 1, 1.5, 2]
                combs = []
                [combs.append(p) for p in itertools.product(w, repeat=4)]
                # combs = [[1,0.5,1,2]]
                l = 1
                for comb in combs:
                    print('Progress', l / len(combs) * 100, '%', '_', l)
                    l = l + 1
                    # while j==1 :

                    solution = None

                    for i in range(1):

                        if self.skeletonLevels.index(levelSkeleton) == len(
                                self.skeletonLevels) - 1:
                            while True:
                                try:
                                    solution = search(
                                        levelSkeleton,
                                        filename="leve" + str(i),
                                        constraints=self.constraints,
                                        Comb=comb)
                                except:
                                    continue
                                break
                        else:
                            LS = self.skeletonLevels[len(self.skeletonLevels) -
                                                     1]
                            solution = self.solutions[LS]
                        fitness = solution.getFitness(
                            constraints=self.constraints)
                        scores.append([
                            fitness['sym'], fitness['area'], fitness['rad'],
                            fitness['distribution'], fitness['totalScore']
                        ])
                        distributionScore = fitness['distribution']
                        SYM = fitness['sym']
                        print('result gave ', distributionScore, SYM)
                        # j = 2

                    # overlapscore = fitness['overlapped']
                    # print("here condition out", distributionScore, overlapscore )
                self.solutions[levelSkeleton] = solution
            for l in range(len(scores)):
                if (l % 2) == 0:
                    score = scores[l]
                    f.write(
                        str(score[0]) + "/" + str(score[1]) + "/" +
                        str(score[2]) + "/" + str(score[3]) + "/" +
                        str(score[4]) + "\n")
            self.saveSkeletons(dirname)
            count += 1