Exemple #1
0
 def createRandomVoileFromRatio(self, ratio):
     if ratio >= 1:
         return VoileSkeleton(self, 0, self.vecLength.magn())
     length = self.vecLength.magn() * ratio
     leftLength = self.vecLength.magn() - length
     move = random.uniform(0, leftLength)
     return VoileSkeleton(self, move, move + length)
Exemple #2
0
def mutateWall(wallSkeleton, positive=True, mutationSize=1):
    if WallSkeleton.miniVoileLength > wallSkeleton.vecLength.magn():
        return
    # wallSkeleton.reInitFitness()
    if positive or len(wallSkeleton.attachedVoiles) == 0:
        r = random.uniform(0, 1)
        if r < 0.5 or len(
                wallSkeleton.attachedVoiles) == 0:  #add new shear wall
            if wallSkeleton.vecLength.magn() == WallSkeleton.miniVoileLength:
                start = 0
                end = wallSkeleton.vecLength.magn()
            else:
                start = int(
                    random.uniform(
                        0,
                        wallSkeleton.vecLength.magn() -
                        WallSkeleton.miniVoileLength))
                end = start + WallSkeleton.miniVoileLength
            wallSkeleton.attachVoile(VoileSkeleton(wallSkeleton, start, end))
        else:  # change shear wall size
            rand = int(
                random.uniform(0,
                               len(wallSkeleton.attachedVoiles) - 0.1))
            selectedVoile = wallSkeleton.getVoile(rand)
            start = selectedVoile.start
            end = selectedVoile.end
            if r < 0.75:
                start = max(0,
                            start - mutationSize * WallSkeleton.discreteFactor)
            else:
                end = min(wallSkeleton.vecLength.magn(),
                          end + mutationSize * WallSkeleton.discreteFactor)

            v = VoileSkeleton(wallSkeleton, start, end)
            wallSkeleton.attachVoile(v)
    else:
        r = random.uniform(0, 1)
        if r < 0.5:  # remove shear wall
            rand = int(
                random.uniform(0,
                               len(wallSkeleton.attachedVoiles) - 0.1))
            wallSkeleton.removeVoile(rand)
        else:  # change shear wall size
            rand = int(
                random.uniform(0,
                               len(wallSkeleton.attachedVoiles) - 0.1))
            selectedVoile = wallSkeleton.getVoile(rand)
            start = selectedVoile.start
            end = selectedVoile.end
            if r < 0.75:
                start = start + mutationSize * WallSkeleton.discreteFactor
            else:
                end = end - mutationSize * WallSkeleton.discreteFactor
            wallSkeleton.removeVoile(rand)
            if end - start >= WallSkeleton.miniVoileLength:
                v = VoileSkeleton(wallSkeleton, start, end)
                wallSkeleton.attachVoile(v)
Exemple #3
0
 def getVoilesBetween(self, mini=0, maxi=1):
     mini = mini * self.vecLength.magn()
     maxi = maxi * self.vecLength.magn()
     newVoiles = []
     for voile in self.attachedVoiles:
         if mini <= voile.start < maxi:
             newVoiles.append(
                 VoileSkeleton(self, voile.start, min(maxi, voile.end)))
         elif voile.start <= mini < voile.end:
             newVoiles.append(
                 VoileSkeleton(self, mini, min(maxi, voile.end)))
     return newVoiles
Exemple #4
0
    def createRandomVoilesFromLengthNeeded1(self, totalLength, needed):
        lengthDiscreted = self.vecLength.magn() / WallSkeleton.discreteFactor
        minVoileLen = WallSkeleton.miniVoileLength / WallSkeleton.discreteFactor
        voiles = []
        start = 0
        i = 0
        proba = needed / totalLength
        lengthCreated = 0
        while i < int(lengthDiscreted - minVoileLen):
            # for i in range(int(lengthDiscreted-minVoileLen)):

            rand = random.uniform(0, 1)
            if rand <= proba:
                needed -= minVoileLen
                totalLength -= minVoileLen
                i += minVoileLen
                end = start + WallSkeleton.miniVoileLength
                while random.uniform(0,
                                     1) <= proba and i < int(lengthDiscreted):
                    needed -= 1
                    totalLength -= 1
                    end += WallSkeleton.discreteFactor
                    i += 1

                voiles.append(VoileSkeleton(self, start, end))
                lengthCreated += (end - start)
                start = end

            start += WallSkeleton.discreteFactor
            totalLength -= 1
            i += 1

        return lengthCreated, voiles
Exemple #5
0
def mergeVoile(voiles, voile):
    i = 0
    toDelete = []
    for v in voiles:
        if v.start <= voile.start < v.end:
            # voiles.remove(v)
            # del voiles[i]
            toDelete.append(i)
            voile = VoileSkeleton(v.parentWall, v.start, max(v.end, voile.end))
            # return mergeVoile(voiles,v)
        elif voile.start <= v.start < voile.end:
            # voiles.remove(v)
            # del voiles[i]
            toDelete.append(i)
            voile = VoileSkeleton(v.parentWall, voile.start,
                                  max(v.end, voile.end))
            # return mergeVoile(voiles,v)
        i += 1
    for i in sorted(toDelete, reverse=True):
        del voiles[i]
    voiles.append(voile)
    return voiles
Exemple #6
0
    def ColumnToVoile(ColumnPolys, wallSkeletons):
        voiles = []
        for Column in ColumnPolys:
            pnts = Column.exterior.coords
            x = round(Column.centroid.x, 2)
            y = round(Column.centroid.y, 2)
            end1 = round(pnts[1][0] - pnts[0][0], 2)
            end2 = round(pnts[3][1] - pnts[0][1], 2)
            if end1 > end2: end = end1
            else: end = end2
            for wall in wallSkeletons:
                X = round(wall.poly.centroid().x, 2)
                Y = round(wall.poly.centroid().y, 2)
                dim1 = abs(wall.poly.MinCoords().x() -
                           wall.poly.MaxCoords().x())
                dim2 = abs(wall.poly.MinCoords().y() -
                           wall.poly.MaxCoords().y())
                if X == x and Y == y:
                    if dim1 > 0.2 and dim2 > 0.2:
                        voile = VoileSkeleton(wall, 0, end)
                        voiles.append(voile)

        return voiles
Exemple #7
0
    def createRandomVoilesFromLengthNeeded2(self, totalLength, needed):
        lengthDiscreted = self.vecLength.magn() / WallSkeleton.discreteFactor
        if totalLength <= 0 or needed <= 0 or lengthDiscreted < 1:
            return 0, []
        proba = min([needed / totalLength, 1])
        # if lengthDiscreted < 1:
        #     if random.uniform(0,1) < proba:
        #         return self.vecLength.magn(),[VoileSkeleton(self,0,self.vecLength.magn())]
        #     return 0,[]
        minVoileLen = WallSkeleton.miniVoileLength / WallSkeleton.discreteFactor
        voiles = []

        lengthCreated = 0
        n = numpy.random.binomial(lengthDiscreted, proba)
        length = n * WallSkeleton.discreteFactor
        listToAdd = []
        while length >= WallSkeleton.miniVoileLength:
            mean = WallSkeleton.optimumVoileLength
            dev = max([
                WallSkeleton.maxVoileLength - mean,
                mean - WallSkeleton.miniVoileLength
            ])
            toAdd = numpy.random.normal(mean, dev)
            toAdd = min([
                max([toAdd, WallSkeleton.miniVoileLength]),
                WallSkeleton.maxVoileLength
            ])
            listToAdd.append(toAdd)
            lengthCreated += toAdd
            length -= toAdd
        # first voile start from 0
        s, e = 0, self.vecLength.magn()
        left = max([0, self.vecLength.magn() - lengthCreated])
        lengthCreated = 0
        if random.uniform(0, 1) < WallSkeleton.startFromZeroProba:
            if len(listToAdd) > 0:
                end = min([listToAdd[0], self.vecLength.magn()])
                voile = VoileSkeleton(self, 0, end)
                del listToAdd[0]
                voiles.append(voile)
                s = end
                lengthCreated += voile.getLength()
        if random.uniform(0, 1) < WallSkeleton.startFromZeroProba:
            if len(listToAdd) > 0:
                start = max([0, self.vecLength.magn() - listToAdd[0]])
                voile = VoileSkeleton(self, start, self.vecLength.magn())
                del listToAdd[0]
                voiles.append(voile)
                e = start
                lengthCreated += voile.getLength()

        while s < e and len(listToAdd) > 0:
            leave = random.uniform(0, left)
            left = max([0, left - leave])
            start = s + leave
            end = min([start + listToAdd[0], e])
            if end - start > self.vecLength.magn():
                print(("ERROR FROM WALL SKELETON RANDOM", end - start,
                       self.vecLength.magn(), left, start, end, s, leave))
            voile = VoileSkeleton(self, start, end)
            voiles.append(voile)
            s = end
            lengthCreated += voile.getLength()
            del listToAdd[0]

        return lengthCreated, voiles