Exemplo n.º 1
0
    def placePoly(self,index):
        '''
        放置某一个index的形状进去
        '''
        adjoin=self.polygons[index]
        ifp=self.getInnerFitRectangle(self.polygons[index])
        differ_region=Polygon(ifp)
        multi=True
        if multi==True:
            if self.choose_nfp==True and index>8:
                target_polygon=self.polygons[index-8:index]
                bottom_height=self.getMinTop(target_polygon)+300
                differ_region=differ_region.difference(Polygon([[0,0],[self.width,0],[self.width,bottom_height],[0,bottom_height]]))
            else:
                target_polygon=self.polygons[0:index]
            tasks=[(main,adjoin) for main in target_polygon]
            res=pool.starmap(NFP,tasks)
            for item in res:
                nfp=item.nfp
                differ_region=differ_region.difference(Polygon(nfp))
        else:
            for main_index in range(0,index):
                main=self.polygons[main_index]
                nfp=NFP(main,adjoin).nfp
                differ_region=differ_region.difference(Polygon(nfp))

        # print(differ_region)
        differ=GeoFunc.polyToArr(differ_region)

        differ_index=self.getBottomLeft(differ)
        refer_pt_index=GeoFunc.checkTop(adjoin)
        GeoFunc.slideToPoint(self.polygons[index],adjoin[refer_pt_index],differ[differ_index])        
Exemplo n.º 2
0
 def MinimizeOverlap(self, oris, v, o):
     '''
     oris: 允许旋转的角度集合
     v: 多边形位置 实际已通过self.polygons得到
     o: 旋转的角度 后期可考虑把多边形封装成类
     '''
     n_polys = self.n_polys
     it = 0
     fitness = 999999
     while it < self.n_mo:
         Q = np.random.permutation(range(n_polys))
         for i in range(n_polys):
             curPoly = self.polygons[Q[i]]
             # 记录原始位置
             top_index = GeoFunc.checkTop(curPoly)
             top = list(curPoly[top_index])
             F = self.evaluate(Q[i])  # 以后考虑旋转
             print('F of', Q[i], ':', F)
             v_i = self.CuckooSearch(Q[i])
             self.evaluate(Q[i], v_i)
             F_new = v_i.getF()
             print('new F of', Q[i], ':', F)
             if F_new < F:
                 print('polygon', Q[i], v_i.getXY())
             else:
                 # 平移回原位置
                 GeoFunc.slideToPoint(curPoly, curPoly[top_index], top)
         fitness_new = self.evaluateAll()
         if fitness_new == 0:
             return it  # 可行解
         elif fitness_new < fitness:
             fitness = fitness_new
             it = 0
         self.updatePenalty()
         it = it + 1
     return it
Exemplo n.º 3
0
 def slidePolytoMe(self, poly):
     top_index = GeoFunc.checkTop(poly)
     top = poly[top_index]
     GeoFunc.slideToPoint(poly, top, self.getXY())