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 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 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 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
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 p2 = Point(p2.x(), p2.y()) circle = p.buffer(distance + 0.5)
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