def getSums(self): # if self.sums is not None: # return self.sums sumLi1 = 0 sumLi2 = 0 sumLixi = 0 sumLiyi = 0 if self.iscolumnParent: # centerV = self.poly.centroid() # centerV = Pnt(centerV.x, centerV.y) # x = math.pow(self .poly.MaxCoords().x() - self.poly.MinCoords().x(), 1) # y = math.pow(self.poly.MaxCoords().y() - self.poly.MinCoords().y(), 1) # sumLi1 = x # sumLi2 = y # sumLixi += y * centerV.x() # sumLiyi += x * centerV.y() a = 0 else: for voileSkeleton in self.getAllVoiles(): centerV = voileSkeleton.poly.centroid() centerV = Pnt(centerV.x, centerV.y) x3 = math.pow(abs(voileSkeleton.vecLength.x()), 3) y3 = math.pow(abs(voileSkeleton.vecLength.y()), 3) sumLi1 += x3 sumLi2 += y3 sumLixi += y3 * centerV.x() sumLiyi += x3 * centerV.y() self.sums = sumLi1, sumLi2, sumLixi, sumLiyi return self.sums
def calculateFitnessWall(self, wallSkeleton): if wallSkeleton.evalData: return wallSkeleton.evalData size = 0 dis = 0 totalLengthX = abs(wallSkeleton.vecLength.x()) totalLengthY = abs(wallSkeleton.vecLength.y()) lengthX = 0 lengthY = 0 vec = Pnt(0, 0) for voileSkeleton in wallSkeleton.getAllVoiles(): # for voileSkeleton in voiles: # print ("looping") centerV = voileSkeleton.poly.centroid() centerV = Pnt(centerV.x, centerV.y) v = centerV - self.center vec += v * voileSkeleton.getLength() dis += distance(centerV, self.center) lengthX += voileSkeleton.getLengthX() lengthY += voileSkeleton.getLengthY() # length += (voileSkeleton.end - voileSkeleton.start) size += 1 wallSkeleton.evalData = EvaluationData(dis, size, totalLengthX, totalLengthY, lengthX, lengthY) sumLi1, sumLi2, sumLixi, sumLiyi = wallSkeleton.getSums() wallSkeleton.evalData.sumLiX = sumLi1 wallSkeleton.evalData.sumLiY = sumLi2 wallSkeleton.evalData.sumLixi = sumLixi wallSkeleton.evalData.sumLiyi = sumLiyi wallSkeleton.evalData.vecUni = vec return wallSkeleton.evalData
def _getTopLeftPoint(self): pnts = self.poly.points size = len(pnts) maxVec = None topPnt = None endPnt = None for index, pnt in enumerate(pnts): vec = pnts[(index + 1) % size] - pnt if not maxVec or maxVec.magn() < vec.magn(): maxVec = vec topPnt = pnt maxVec2 = None for index, pnt in enumerate(pnts): if pnt != topPnt: ePnt = pnts[(index + 1) % size] vec = ePnt - pnt if not maxVec2 or maxVec2.magn() < vec.magn(): maxVec2 = vec endPnt = ePnt # if maxVec.magn() - maxVec2.magn() > 0.1: # print "mVec: " + str(maxVec.magn()) + " mVec2: " + str(maxVec2.magn()) self.vecLength = maxVec self.vecWidth = endPnt - topPnt if self.vecWidth.magn() == 0: self.vecWidth = Pnt(0.00000001, 0.00000001) # print ("end", endPnt, "start", topPnt, "1", endPnt.x(), endPnt.y(), topPnt.x(), topPnt.y()) # for pnt in pnts: # print (pnt, pnt.x(), pnt.y()) # # print "ennnnnddddd" self.topLeftPnt = topPnt
def drawSkeleton(self, levelSkeleton): ellipses = [] if levelSkeleton in self.solutions: solution = self.solutions[levelSkeleton] polys = self.getPolygonsFromLevelSkeletons(solution.levelSkeleton) c1 = solution.levelSkeleton.getCenterFromSlab() c2 = solution.levelSkeleton.getCenterFromShear() print("point in draw: ", str(c2)) print("point in draw2: ", str(c1)) e1 = Ellip(c1, 0.4) e2 = Ellip(c2, 0.4) ells = [e1, e2] ellipses = [ ells, [QtGui.QColor(255, 0, 0), QtGui.QColor(0, 255, 0)] ] for box in solution.getValidVoilesBoxes(self.constraints['d']): polys[0].append( Poly([Pnt(pnt[0], pnt[1]) for pnt in box.exterior.coords])) q1 = QtGui.QColor(0, 255, 0) q1.setAlpha(20) polys[1].append(q1) for box in solution.getNonValidVoilesBoxes(self.constraints['d']): polys[0].append( Poly([Pnt(pnt[0], pnt[1]) for pnt in box.exterior.coords])) q1 = QtGui.QColor(255, 0, 0) q1.setAlpha(20) polys[1].append(q1) else: polys = self.getPolygonsFromLevelSkeletons(levelSkeleton) self.draw(polys, ellipses)
def getPolygonsFromLevelSkeletons(self, levelSkeleton): polygons = [ wallSkeleton.poly.copy() for wallSkeleton in levelSkeleton.wallSkeletons ] colors = [ Color(220, 220, 220) for wallSkeleton in levelSkeleton.wallSkeletons ] polygons += [ voileSkeleton.poly.copy() for wallSkeleton in levelSkeleton.wallSkeletons for voileSkeleton in wallSkeleton.getAllVoiles() ] colors += [ Color(255, 0, 0) for wallSkeleton in levelSkeleton.wallSkeletons for voileSkeleton in wallSkeleton.getAllVoiles() ] if not len(polygons): return polys = (polygons, colors) center = Pnt.createPointFromShapely( levelSkeleton.slabSkeleton.poly.centroid()) return polys
def getCenterFromShear(self): sumLiX = 0 sumLiY = 0 sumLixi = 0 sumLiyi = 0 nShears = 0 for wallSkeleton in self.wallSkeletons: sLiX, sLiY, sLixi, sLiyi = wallSkeleton.getSums() nShears += len(wallSkeleton.getAllVoiles()) sumLiX += sLiX sumLiY += sLiY sumLixi += sLixi sumLiyi += sLiyi x = 0 y = 0 if sumLiY != 0: x = sumLixi / sumLiY else: print("sumLiY is 0") if sumLiyi != 0: print("hummm error") if sumLiX != 0: y = sumLiyi / sumLiX else: print("sumLiX is 0") if sumLixi != 0: print("hummm error") cntr = Pnt(x, y) return cntr
def removeColumnIntersections(newWallSkeletons1,Columns): newWallSkeletons3 = [] newWallSkeletons33=copy.deepcopy(newWallSkeletons1) newWallSkeletons = [] toRemove = [] for column in Columns: pnts = column.exterior.coords Pnts = [] for i in range(len(pnts)): Pnts.append(Pnt(pnts[i][0], pnts[i][1])) ColumnWall = Poly(Pnts) for i in range(len(newWallSkeletons33)): wallskeleton = newWallSkeletons33[i] poly = wallskeleton.poly if poly.intersects(ColumnWall): if poly.intersection(ColumnWall).area() == poly.area():toRemove.append(wallskeleton) if poly.intersection(ColumnWall).area()!= poly.area(): wallsklts = LevelSkeleton.wallskeletonfromDif(poly,ColumnWall) newWallSkeletons33[i] = wallsklts[0] newWallSkeletons3.append(wallsklts[0]) if len(wallsklts) == 2: newWallSkeletons33.append(wallsklts[1]) newWallSkeletons3.append(wallsklts[1]) todelete = [] for column in Columns: pnts = column.exterior.coords Pnts = [] for i in range(len(pnts)): Pnts.append(Pnt(pnts[i][0], pnts[i][1])) ColumnWall = Poly(Pnts) for i in range(len(newWallSkeletons3)): wallskeleton = newWallSkeletons3[i] poly = wallskeleton.poly if poly.intersects(ColumnWall): intersection=poly.intersection(ColumnWall) if intersection != None: todelete.append(wallskeleton) for elmt in toRemove: if elmt in newWallSkeletons33: newWallSkeletons33.remove(elmt) for elmnt in newWallSkeletons33: if elmnt not in newWallSkeletons: newWallSkeletons.append(elmnt) for elmt in newWallSkeletons3: if elmt not in newWallSkeletons: newWallSkeletons.append(elmt) for wall in todelete: if wall in newWallSkeletons: newWallSkeletons.remove(wall) return newWallSkeletons
def getSums2(self, origin): if self.sums2 is not None: return self.sums2 sumLx3 = 0 sumLy3 = 0 sumX2Ly3 = 0 sumY2Lx3 = 0 for voileSkeleton in self.getAllVoiles(): centerV = voileSkeleton.poly.centroid() centerV = Pnt(centerV.x - origin.x(), centerV.y - origin.y()) Lx3 = math.pow(abs(voileSkeleton.vecLength.x()), 3) Ly3 = math.pow(abs(voileSkeleton.vecLength.y()), 3) sumLx3 += Lx3 sumLy3 += Ly3 sumX2Ly3 += Ly3 * math.pow(centerV.x(), 2) sumY2Lx3 += Lx3 * math.pow(centerV.y(), 2) self.sums2 = sumLx3, sumLy3, sumX2Ly3, sumY2Lx3 return self.sums2
def getSums(self): if self.sums is not None: return self.sums sumLi1 = 0 sumLi2 = 0 sumLixi = 0 sumLiyi = 0 for voileSkeleton in self.getAllVoiles(): centerV = voileSkeleton.poly.centroid() centerV = Pnt(centerV.x, centerV.y) x3 = math.pow(abs(voileSkeleton.vecLength.x()), 3) y3 = math.pow(abs(voileSkeleton.vecLength.y()), 3) sumLi1 += x3 sumLi2 += y3 sumLixi += y3 * centerV.x() sumLiyi += x3 * centerV.y() self.sums = sumLi1, sumLi2, sumLixi, sumLiyi return self.sums
def fixSegment(self, segment, slab_poly): e1, e2 = segment.End1.PntCoord, segment.End2.PntCoord pnt1 = Pnt(e1.x, e1.y) pnt2 = Pnt(e2.x, e2.y) end1 = pnt1.copy() end2 = pnt2.copy() if not pnt1.isInPolygon(slab_poly): end1 = self.get_closest_intersection(pnt1, pnt2, slab_poly) if not pnt2.isInPolygon(slab_poly): end2 = self.get_closest_intersection(pnt2, pnt1, slab_poly) if end1 is not None and end2 is None: print((e1.x, e1.y, e2.x, e2.y)) print("polygon") for pnt in slab_poly.points: print((pnt.x(), pnt.y())) raise Exception if end1 is None and end2 is not None: print((e1.x, e1.y, e2.x, e2.y)) print("polygon") for pnt in slab_poly.points: print((pnt.x(), pnt.y())) raise Exception # start # for poly # ('(-1.82486794037,-1.03558377118)', '(-5.12486794037,-1.03558377118)') # ('(-9.12486794037,-5.63558377118)', '(-9.12486794037,-0.960583771182)') # ('result', '(-9.12486794037,-1.03558377118)') # ('outcome', None) # ('(-1.82486794037,-1.03558377118)', '(-5.12486794037,-1.03558377118)') # ('(-9.12486794037,-0.960583771182)', '(-4.94986794037,-0.960583771182)') # ('result', 'None') # ('outcome', None) # ('(-1.82486794037,-1.03558377118)', '(-5.12486794037,-1.03558377118)') # ('(-4.94986794037,-0.960583771182)', '(-4.94986794037,-5.63558377118)') # ('result', '(-4.94986794037,-1.03558377118)') # ('outcome', None) # ('(-1.82486794037,-1.03558377118)', '(-5.12486794037,-1.03558377118)') # ('(-4.94986794037,-5.63558377118)', '(-9.12486794037,-5.63558377118)') # ('result', 'None') # ('outcome', None) # (-5.124867940372748, -1.0355837711820652, -1.824867940372748, -1.0355837711820652) # polygon # (-9.12486794037277, -5.63558377118204) # (-9.12486794037277, -0.9605837711820402) # (-4.949867940372769, -0.9605837711820402) # (-4.949867940372769, -5.63558377118204) if end1 is None or end1.minus(end2).magn() == 0: return None return Segment(EndOfSegment(end1.pnt), EndOfSegment(end2.pnt), segment.Open)
def wallskeletonfromDif(poly,ColumnWall): newWallSkeletons = [] polys = poly.difference(ColumnWall) if polys.geom_type == 'Polygon': pnts = polys.exterior.coords Pnts = [] for i in range(len(pnts)): Pnts.append(Pnt(pnts[i][0], pnts[i][1])) polygon = Poly(Pnts) if polygon.area() > 0: newWallSkeletons.append(LevelSkeleton.Addnewpolys(polygon)) if polys.geom_type == "MultiPolygon": polygons = polys.geoms for Polys in polygons: pnts = Polys.exterior.coords Pnts = [] for i in range(len(pnts)): Pnts.append(Pnt(pnts[i][0], pnts[i][1])) polygon = Poly(Pnts) if polygon.area() > 0: newWallSkeletons.append(LevelSkeleton.Addnewpolys(polygon)) return newWallSkeletons
def getShapeBasePolygon(shape): from Geometry.Geom2D import Pnt,Poly polygons = getPolygonesFromShape(shape) minZ = min([pnt.z for polygon in polygons for pnt in polygon.points]) # print "min z: " + str(minZ) for polygon in polygons: points = [] if polygon.isInPlaneXY(minZ): for pnt in polygon.points: points.append(Pnt(pnt.x, pnt.y)) return Poly(points) return None
def getSums2(self, origin): if self.sums2 is not None: return self.sums2 sumLx3 = 0 sumLy3 = 0 sumX2Ly3 = 0 sumY2Lx3 = 0 if self.iscolumnParent: centerV = self.poly.centroid() centerV = Pnt(centerV.x, centerV.y) x = math.pow(self.poly.MaxCoords().x() - self.poly.MinCoords().x(), 3) y = math.pow(self.poly.MaxCoords().y() - self.poly.MinCoords().y(), 3) sumLx3 = 0 sumLy3 = 0 sumX2Ly3 = 0 sumY2Lx3 = 0 else: for voileSkeleton in self.getAllVoiles(): centerV = voileSkeleton.poly.centroid() centerV = Pnt(centerV.x - origin.x(), centerV.y - origin.y()) Lx3 = math.pow(abs(voileSkeleton.vecLength.x()), 3) Ly3 = math.pow(abs(voileSkeleton.vecLength.y()), 3) sumLx3 += Lx3 sumLy3 += Ly3 sumX2Ly3 += Ly3 * math.pow(centerV.x(), 2) sumY2Lx3 += Lx3 * math.pow(centerV.y(), 2) self.sums2 = sumLx3, sumLy3, sumX2Ly3, sumY2Lx3 return self.sums2
def getSurrondingBox(self, d_ratio): if self.surrondingBox: return self.surrondingBox distance = 4 * d_ratio wid = Pnt(self.vecLength.y(), -self.vecLength.x()) wid = wid.copy().resize(distance) * 2 + wid.copy().resize( self.vecWidth.magn()) # leng = self.vecLength.copy().resize(distance)*2 + self.vecLength leng = self.vecLength center = self.topLeftPnt + self.vecLength / 2 + self.vecWidth / 2 pnt1 = center - leng / 2 - wid / 2 pnts = [pnt1, pnt1 + leng, pnt1 + leng + wid, pnt1 + wid] polyPnts = [[pnt.x(), pnt.y()] for pnt in pnts] polygon = Polygon(polyPnts) p = center - leng / 2 p = Point(p.x(), p.y()) p2 = center + leng / 2 p2 = Point(p2.x(), p2.y()) circle = p.buffer(distance + self.vecWidth.magn() / 2) circle2 = p2.buffer(distance + self.vecWidth.magn() / 2) result = polygon.union(circle).union(circle2) self.surrondingBox = result return result
def getShapeXYPlanePolygons(shape,minZ=None,maxZ=None): from Geometry.Geom2D import Pnt,Poly polygons = getPolygonesFromShape(shape) polys = [] # print "min z: " + str(minZ) for polygon in polygons: points = [] if polygon.isInPlaneXY(): if minZ is not None and polygon.points[0].z < minZ: continue if maxZ is not None and polygon.points[0].z > maxZ: continue for pnt in polygon.points: points.append(Pnt(pnt.x, pnt.y)) polys.append(Poly(points)) return polys
def getSurrondingBoxes(self, selected=None): if self.surrondingBoxes: return self.surrondingBoxes if selected is None: selected = [1, 1, 1, 1] distance = 4 distance2 = 1 wid = Pnt(self.vecLength.y(), -self.vecLength.x()) wid2 = wid.copy().resize(distance2) * 2 + wid.copy().resize( self.vecWidth.magn()) wid1 = wid.copy().resize(distance) * 2 + wid.copy().resize( self.vecWidth.magn()) # leng = self.vecLength.copy().resize(distance)*2 + self.vecLength leng = self.vecLength center = self.topLeftPnt + self.vecLength / 2 + self.vecWidth / 2 if selected[0]: wid = wid1 else: wid = wid2 pnt1 = center - leng / 2 - wid / 2 pnts = [pnt1, pnt1 + leng, pnt1 + leng + wid / 2, pnt1 + wid / 2] polygon = Polygon([[pnt.x(), pnt.y()] for pnt in pnts]) if selected[1]: wid = wid1 else: wid = wid2 pnt1 = center - leng / 2 + wid / 2 pnts = [pnt1, pnt1 + leng, pnt1 + leng - wid / 2, pnt1 - wid / 2] polygon2 = Polygon([[pnt.x(), pnt.y()] for pnt in pnts]) if selected[2]: d = distance else: d = distance2 p = center - leng / 2 p = Point(p.x(), p.y()) circle = p.buffer(d + self.vecWidth.magn() / 2) if selected[3]: d = distance else: d = distance2 p2 = center + leng / 2 p2 = Point(p2.x(), p2.y()) circle2 = p2.buffer(d + self.vecWidth.magn() / 2) result = [polygon, polygon2, circle, circle2] self.surrondingBoxes = result return result
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
class BoxSkeleton(PolySkeleton): def __init__(self, poly, pnts=None): super(BoxSkeleton, self).__init__(poly) if pnts: self.topLeftPnt, self.vecLength, self.vecWidth = pnts return self.topLeftPnt = Pnt self.vecLength = Pnt self.vecWidth = Pnt # if len(poly.points) != 4: # raise NotBoxError("not four points") # else: # pnts = poly.points # for p in pnts: # print p # vec1 = pnts[0] - pnts[1] # vec2 = pnts[3] - pnts[2] # threshold = vec1.magn()*0.1 # print ("vec1: "+str(vec1)+" vec2: "+str(vec2)) # if not (abs(vec1.x() - vec2.x()) <= threshold and abs(vec1.y()-vec2.y()) <= threshold): # raise NotBoxError("not parallel") self._getTopLeftPoint() def _getTopLeftPoint(self): pnts = self.poly.points size = len(pnts) maxVec = None topPnt = None endPnt = None for index, pnt in enumerate(pnts): vec = pnts[(index + 1) % size] - pnt if not maxVec or maxVec.magn() < vec.magn(): maxVec = vec topPnt = pnt maxVec2 = None for index, pnt in enumerate(pnts): if pnt != topPnt: ePnt = pnts[(index + 1) % size] vec = ePnt - pnt if not maxVec2 or maxVec2.magn() < vec.magn(): maxVec2 = vec endPnt = ePnt # if maxVec.magn() - maxVec2.magn() > 0.1: # print "mVec: " + str(maxVec.magn()) + " mVec2: " + str(maxVec2.magn()) self.vecLength = maxVec self.vecWidth = endPnt - topPnt if self.vecWidth.magn() == 0: self.vecWidth = Pnt(0.00000001, 0.00000001) # print ("end", endPnt, "start", topPnt, "1", endPnt.x(), endPnt.y(), topPnt.x(), topPnt.y()) # for pnt in pnts: # print (pnt, pnt.x(), pnt.y()) # # print "ennnnnddddd" self.topLeftPnt = topPnt def _getTopLeftPoint4(self): pnts = self.poly.points minXpnt = min(pnts, key=lambda p: p.x()) self.topLeftPnt = minXpnt index = 0 for pnt in pnts: if minXpnt == pnt: break index += 1 i1 = (index + 1) % 4 i2 = (index - 1) % 4 vec1 = pnts[i1] - minXpnt vec2 = pnts[i2] - minXpnt if vec1.magn() > vec2.magn(): self.vecWidth = vec2 self.vecLength = vec1 else: self.vecWidth = vec1 self.vecLength = vec2 def getWidth(self): return self.vecWidth.magn() def getHeight(self): return self.vecLength.magn()
def __init__(self, parent=None, wallShapes=None, slabShapes=None): super(Launcher, self).__init__() self.constraints = { "ecc_w": -0.5, "area_w": 1, "length_w": 1, "ratio": 1, "d": 1, } self.levels = Level.generateLevelsFromShapes(wallShapes, slabShapes) print("INFO INIT: DONE GENERATING LEVELS FROM SHAPES") self.levels.sort(key=lambda lvl: lvl.getHeight()) self.skeletonLevels = [ LevelSkeleton.createSkeletonFromLevel(level) for level in self.levels ] self.levelsHash = dict(list(zip(self.levels, self.skeletonLevels))) self.skeletonLevelsHash = dict( list(zip(self.skeletonLevels, self.levels))) print("INFO INIT: DONE GENERATING LEVELSKELETONS FROM LEVELS") baseSlabHeight = 0 for level in self.levels: if not len(self.levelsHash[level].getPolys() ): # or level.getHeight() <= 0: baseSlabHeight = level.getHeight() else: break for i, levelSkeleton in enumerate(self.skeletonLevels): prevLevels = self.skeletonLevelsHash[ levelSkeleton].getRightLowerLevels() if not prevLevels: continue prevLevels = [ self.levelsHash[level] for level in prevLevels if level.getHeight() > baseSlabHeight ] if not len(prevLevels): continue levelSkeleton.restrictLevelUsableWalls(prevLevels) self.storey_mode = False self.levels = [ level for level in self.levels if len(self.levelsHash[level].getPolys()) ] self.skeletonLevels = [ levelSkeleton for levelSkeleton in self.skeletonLevels if len(levelSkeleton.getPolys()) ] self.storeySkeletons = [] heights = [] for levelSkeleton in self.skeletonLevels: height = levelSkeleton.level.getHeight() if height not in heights: skeletons = [levelSkeleton] heights.append(height) for ls in self.skeletonLevels: if ls.level.getHeight() == height: skeletons.append(ls) self.storeySkeletons.append(StoreySkeleton(skeletons)) self.solutions = {} self.solutions = {} self.selectedRow = 1 self.pend = True # Vertical Loads Sdiv = SlabDivision(self.storeySkeletons[0]) # Sdiv.importWalls(self.skeletonLevels[0]) # Seg = Sdiv.createSlabSegments() # f2 = plt.figure(3,) # for segment in Sdiv.createSlabSegments(): # segment.End1.plotEnd() # segment.End2.plotEnd() # segment.PlotSeg() for room in Sdiv.rooms: # 0x7fd0cba0b9e0 > print(("room", room)) fig, ax = plt.subplots() color = (random(), random(), random()) color2 = (random(), random(), random()) for segment in room.get_segments(): e1, e2 = segment.End1.PntCoord, segment.End2.PntCoord pnt1 = Pnt(e1.x, e1.y) pnt2 = Pnt(e2.x, e2.y) c = color if pnt1.isInPolygon(room.slab_poly) else "r" segment.End1.plot(c, (fig, ax)) c2 = color if pnt2.isInPolygon(room.slab_poly) else "r" segment.End2.plot(c2, (fig, ax)) segment.plot(color, (fig, ax)) room.plot(color2, figax=(fig, ax)) # axes = ax.gca() ax.set_xlim([-10, 10]) ax.set_ylim([-8, 8]) plt.show()
fig.canvas.set_window_title(title + str(f)) ax = fig.add_subplot(111) for shape, c, a in zip(shapes, colors, alphas): xs, ys = shape.exterior.xy ax.fill(xs, ys, alpha=a, fc=c, ec=[0, 0, 0]) if __name__ == "__main__": # poly1 = Poly([Pnt(0, 1), Pnt(1, 0), Pnt(6, 5), Pnt(5, 6)]) # polys = [poly1] # plotPolys(polys,1) # poly2 = Poly([Pnt(1, 2), Pnt(2, 1), Pnt(7, 6), Pnt(6, 7)]) # polys = [poly2] # plotPolys(polys, 2) distance = 2 center = Pnt(1, 1) vecLength = Pnt(10, 1) wid = Pnt(vecLength.y(), -vecLength.x()) wid = wid.copy().resize(distance) * 2 + wid.copy().resize(1) # leng = self.vecLength.copy().resize(distance)*2 + self.vecLength leng = vecLength pnts = [] pnts.append(center - leng / 2 - wid / 2) pnts.append(pnts[0] + leng) pnts.append(pnts[1] + wid) pnts.append(pnts[0] + wid) polyPnts = [[pnt.x(), pnt.y()] for pnt in pnts] polygon = Polygon(polyPnts) p = center - leng / 2 p = Point(p.x(), p.y()) p2 = center + leng / 2
def calculateFitnessSolution(solution, constraints=None): levelSkeleton = solution.levelSkeleton wallEvaluator = WallEvaluator(levelSkeleton) if constraints is not None: rad_w, ecc_w, area_w, length_w = constraints['rad_w'], constraints['ecc_w'],\ constraints['area_w'], constraints['length_w'] else: rad_w, ecc_w, area_w, length_w = 0.5, -0.5, 1, 1 size = 0 dis = 0 totalX = 0 totalY = 0 lengthX = 0 lengthY = 0 needed = levelSkeleton.getVoileLengthNeeded(constraints['ratio']) centerV = levelSkeleton.slabSkeleton.poly.centroid() centerV = Pnt(centerV.x, centerV.y) vecUni = Pnt(0, 0) for wallSkeleton in levelSkeleton.wallSkeletons: # print "attached voiles : " + str(len(wallSkeleton.attachedVoiles)) evalData = wallEvaluator.calculateFitnessWall(wallSkeleton) d, s, lx, ly = evalData.dis, evalData.size, evalData.totalLengthX, evalData.totalLengthY dis += d size += s totalX += lx totalY += ly lengthX += evalData.lengthX lengthY += evalData.lengthY vecUni += evalData.vecUni cntr = levelSkeleton.getCenterFromShear() Rx, Ry = levelSkeleton.getTorsionalRadius(centerV) momentx, momenty = levelSkeleton.slabSkeleton.poly.momentX( ), levelSkeleton.slabSkeleton.poly.momentY() if momentx < 0 or momenty < 0: print((momentx, momenty)) eval(input()) radiuses = (Rx + Ry) / ( abs(Rx - Ry) + 0.000001 ) #abs(1-(Ry/(momentx+momenty))) + abs(1-(Rx/(momentx+momenty))) area = solution.getAreaCoveredBoxes(constraints['d']) coeffs = { 'rad': rad_w, 'sym': ecc_w, 'lengthShearX': length_w / 2., 'lengthShearY': length_w / 2., # 'overlapped': -1, # 'unif': 0, 'area': area_w } def getScoreLength(lengthA, total): if lengthA < needed: scoreLengthA = math.pow(lengthA / needed, 3) else: scoreLengthA = 1 - (lengthA - needed) / needed return scoreLengthA scoreLengthX = getScoreLength(lengthX, totalX) scoreLengthY = getScoreLength(lengthY, totalY) areaNorm = sum( voileSkeleton.getSurrondingBox(constraints['d']).area for wallSkeleton in levelSkeleton.wallSkeletons for voileSkeleton in wallSkeleton.getAllVoiles()) if areaNorm == 0: areaNorm = -1 ar = -1 else: ar = math.sqrt(areaNorm) fitV = { 'radX': Rx, 'radY': Ry, 'rad': radiuses, 'sym': max([0, distance(cntr, centerV) / ar]), 'lengthShearX': scoreLengthX, 'lengthShearY': scoreLengthY, 'unif': vecUni.magn(), 'area': area / levelSkeleton.getSlabArea(), 'overlapped': max([0, solution.getOverlappedArea(constraints['d']) / areaNorm]), 'lengthX': lengthX, 'lengthY': lengthY } fitness = 0 for key in coeffs: fitness += fitV[key] * coeffs[key] fitV['totalScore'] = fitness # fitness = fitV['area'] return fitV
def getCenterFromSlab(self): return Pnt.createPointFromShapely(self.slabSkeleton.poly.centroid())
def __init__(self, levelSkeleton): super(WallEvaluator, self).__init__() center = levelSkeleton.slabSkeleton.poly.centroid() self.center = Pnt(center.x, center.y)
def calculateFitnessSolution(solution, constraints=None, comb=[0, 0, 0, 0]): # ReserveWallS = [] # for wallskeleton in solution.levelSkeleton.wallSkeletons: # if wallskeleton.iscolumnParent: # ReserveWallS.append(wallskeleton) # for wallskeleton in ReserveWallS: solution.levelSkeleton.wallSkeletons.remove(wallskeleton) levelSkeleton = solution.levelSkeleton wallEvaluator = WallEvaluator(levelSkeleton) if constraints is not None: rad_w, ecc_w, area_w, length_w = constraints['rad_w'], constraints['ecc_w'],\ constraints['area_w'], constraints['length_w'] else: rad_w, ecc_w, area_w, length_w = 0, -0.5, 1, 1 size = 0 dis = 0 totalX = 0 totalY = 0 lengthX = 0 lengthY = 0 needed = levelSkeleton.getVoileLengthNeeded(constraints['ratio']) centerV = levelSkeleton.slabSkeleton.poly.centroid() centerV = Pnt(centerV.x, centerV.y) vecUni = Pnt(0, 0) for wallSkeleton in levelSkeleton.wallSkeletons: # print "attached voiles : " + str(len(wallSkeleton.attachedVoiles)) evalData = wallEvaluator.calculateFitnessWall(wallSkeleton) d, s, lx, ly = evalData.dis, evalData.size, evalData.totalLengthX, evalData.totalLengthY dis += d size += s totalX += lx totalY += ly if not wallSkeleton.iscolumnParent: lengthX += evalData.lengthX lengthY += evalData.lengthY vecUni += evalData.vecUni # print("columns direction length", toAddYneeded, toAddXneeded) # print("total here", lengthY, lengthX) cntr = levelSkeleton.getCenterFromShear() Rx, Ry = levelSkeleton.getTorsionalRadius(centerV) momentx, momenty = levelSkeleton.slabSkeleton.poly.momentX( ), levelSkeleton.slabSkeleton.poly.momentY() if momentx < 0 or momenty < 0: print((momentx, momenty)) eval(input()) # radiuses = (Rx + Ry)/(abs(Rx-Ry)+0.000001) #abs(1-(Ry/(momentx+momenty))) + abs(1-(Rx/(momentx+momenty))) rx = math.sqrt(momentx / levelSkeleton.slabSkeleton.poly.area()) # Torsional radius ry = math.sqrt(momenty / levelSkeleton.slabSkeleton.poly.area()) radiuses = (Rx / rx + Ry / ry) * 0.5 scoreDist = levelSkeleton.ScoreOfUnacceptableVoiles()[0] # scoreDist = 0 a = solution.getOverlappedArea(constraints['d']) effectiveArea = solution.getEffectiveArea() overlappedArea = solution.geteffectiveOverlappedArea(effectiveArea) ex = abs(cntr.x() - centerV.x()) ey = abs(cntr.y() - centerV.y()) coeffs = { 'rad': comb[2], 'sym': comb[0], 'lengthShearX': 0, 'lengthShearY': 0, 'overlapped': 0, # 'unif': 0, 'area': comb[1], 'distance': 0, 'distribution': comb[3], } # print('this combination is', comb) def getScoreLength(lengthA, total): if lengthA > needed: scoreLengthA = math.pow(needed / lengthA, 3) else: scoreLengthA = 1 - (needed - lengthA) / needed return scoreLengthA def getScoreArea(area, slabArea): if area: if area > 0.2 * slabArea: scoreArea = math.pow(0.02 * slabArea / area, 3) else: scoreArea = 1 - (0.2 * slabArea - area) / (0.2 * slabArea) return scoreArea else: return 0 def getScoreOverlapped(overlapped, totalArea): if totalArea >= overlapped: return 1 - overlapped / totalArea else: return 0 def getScoreSymEcc(ex, ey, Rx, Ry): if Ry == 0: Ry = 0.1 if Rx == 0: Rx = 0.1 return 0.5 * (2 - ex / (0.3 * Rx) - ey / (0.3 * Ry)) def getDistrubtionScore(lx, ly, LX, LY): if ly and lx: if ly > lx: s1 = abs(lx / ly) else: s1 = abs(ly / lx) else: s1 = -1 return s1 LX = levelSkeleton.slabSkeleton.poly.MaxCoords().x( ) - levelSkeleton.slabSkeleton.poly.MinCoords().x() LY = levelSkeleton.slabSkeleton.poly.MaxCoords().y( ) - levelSkeleton.slabSkeleton.poly.MinCoords().y() scoreLengthX = getScoreLength(lengthX, totalX) scoreLengthY = getScoreLength(lengthY, totalY) scoreArea = getScoreArea(effectiveArea, levelSkeleton.slabSkeleton.poly.area()) scoreOverlapped = getScoreOverlapped(overlappedArea, effectiveArea) SymScore = getScoreSymEcc(ex, ey, Rx, Ry) distributionScore = getDistrubtionScore(lengthX, lengthY, LX, LY) # print("\nscore length", scoreLengthX, scoreLengthY) # print("effective inslab area:", effectiveArea," score:", scoreArea) # print("overlapped area", overlappedArea," score:",scoreOverlapped) # print("eccentricty", SymScore) # print("Distance score", scoreDist) # print("radius score", radiuses) # print('distributionScore', distributionScore) areaNorm = sum( voileSkeleton.getSurrondingBox(constraints['d']).area for wallSkeleton in levelSkeleton.wallSkeletons for voileSkeleton in wallSkeleton.getAllVoiles()) if areaNorm == 0: areaNorm = -1 ar = -1 else: ar = math.sqrt(areaNorm) fitV = { 'radX': Rx, 'radY': Ry, 'rad': radiuses, 'sym': SymScore, #max([0,distance(cntr,centerV)/ar]), 'lengthShearX': scoreLengthX, 'lengthShearY': scoreLengthY, 'unif': vecUni.magn(), 'area': scoreArea, #area/levelSkeleton.getSlabArea(), 'overlapped': scoreOverlapped, 'lengthX': lengthX, 'lengthY': lengthY, 'distance': scoreDist, 'distribution': distributionScore } fitness = 0 for key in coeffs: # print("fitness of",key,':',fitV[key]*coeffs[key] ) fitness += fitV[key] * coeffs[key] fitV['totalScore'] = fitness return fitV