当前位置: 首页>>代码示例>>Python>>正文


Python Rectangle.get_closest_diagonal方法代码示例

本文整理汇总了Python中rectangle.Rectangle.get_closest_diagonal方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.get_closest_diagonal方法的具体用法?Python Rectangle.get_closest_diagonal怎么用?Python Rectangle.get_closest_diagonal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rectangle.Rectangle的用法示例。


在下文中一共展示了Rectangle.get_closest_diagonal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_rectangles_by_path

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import get_closest_diagonal [as 别名]
 def add_rectangles_by_path(self, path1, path2, start_offset): 
       path_len = 0
       for p in path1:
         path_len += p.len
       # path_len -= start_offset
       first_shift = start_offset
       second_shift = 0 
       pos_first_path = 0
       pos_second_path = 0
       first_len = first_shift
      
       while first_len < path_len:
         ed1 = path1[pos_first_path]
         ed2 = path2[pos_second_path]
         rectangle = Rectangle(ed1,ed2)
         rectangle.add_diagonal(self.d, self.d + first_shift - second_shift)
         rect_diag = rectangle.get_closest_diagonal(self.d + first_shift - second_shift) 
         self.add_diagonal_and_conj(rect_diag)
         print "ADD DIAGS", rect_diag
         if ed2.len - second_shift < ed1.len - first_shift:
           pos_second_path += 1
           first_shift += ed2.len - second_shift
           first_len += ed2.len - second_shift
           second_shift = 0
         elif ed1.len - first_shift < ed2.len - second_shift:
           pos_first_path += 1
           first_len += ed1.len - first_shift
           second_shift += ed1.len - first_shift
           first_shift = 0
         else:
           first_len += ed1.len - first_shift
           pos_second_path += 1
           pos_first_path += 1
           first_shift = 0
           second_shift = 0
开发者ID:ablab,项目名称:rectangles,代码行数:37,代码来源:bigraph.py

示例2: choose_best_path

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import get_closest_diagonal [as 别名]
 def choose_best_path(self, paired_paths, rectangeles_set, diag1, diag2, d, added_paths):
     best_support = 0
     best_len = 10000
     best_rectangles = []
     best_diags = []
     best_path = paired_paths[0]
     best_not_supported = 0
       
     for paired_path in paired_paths:
       (path1, path2, path_len) = paired_path
       if paired_path in added_paths:
         continue
       first_shift = diag1.offseta
       second_shift = diag1.offsetb
       path1.append(diag2.rectangle.e1)
       path2.append(diag2.rectangle.e2)
       rectangles = []
       diags = []
       not_supported = []
       path_support = 0
       pos_first_path = 0
       pos_second_path = 0
       first_len = first_shift
       make_less_N50 = False
       while not make_less_N50 and first_len < path_len + diag2.offseta:
         ed1 = path1[pos_first_path]
         ed2 = path2[pos_second_path]
         rectangle = Rectangle(ed1,ed2)
         rectangle.add_diagonal(d, d + first_shift - second_shift)
         rect_diag = rectangle.get_closest_diagonal(d + first_shift - second_shift) 
         if (not (rect_diag.key1 == diag1.key1 and rect_diag.key2 == diag1.key2) and not(rect_diag.key1 == diag2.key1 and rect_diag.key2 == diag2.key2)):
           can_use = [diag1.key1, diag1.key2, diag2.key1, diag2.key2]
           if (rect_diag.key1 in self.vs and rect_diag.key1 not in can_use) or  (rect_diag.key2 in self.vs and rect_diag.key2 not in can_use):
             make_less_N50 = True
             continue
         diags.append(rect_diag)
         rectangles.append(rectangle)
         rectangeles_set.use_prd_diag(rect_diag)
         #if rect_diag.prd_support < 0.00001 and (ed2.len > 10 and ed1.len > 10):
         #  make_less_N50 = True
         #  continue
         path_support += rect_diag.prd_support 
         if ed2.len - second_shift < ed1.len - first_shift:
           pos_second_path += 1
           first_shift += ed2.len - second_shift
           first_len += ed2.len - second_shift
           if rect_diag.prd_support < 0.000000001:
             not_supported.append(ed2.len - second_shift)
           second_shift = 0
         elif ed1.len - first_shift < ed2.len - second_shift:
           pos_first_path += 1
           first_len += ed1.len - first_shift
           second_shift += ed1.len - first_shift
           if rect_diag.prd_support < 0.000000001:
             not_supported.append(ed1.len - first_shift)
           first_shift = 0
         else:
           first_len += ed1.len - first_shift
           pos_second_path += 1
           pos_first_path += 1
           first_shift = 0
           second_shift = 0
       if not make_less_N50 and path_len > 1 and  path_support / path_len < 1000 and  path_support / path_len > best_support:
         best_support = path_support 
         best_len = path_len
         best_rectangles = rectangles
         best_diags = diags
         best_path = (path1, path2, path_len)
         best_not_supported = not_supported
     return (best_support,best_len, best_rectangles, best_diags, best_path)
开发者ID:ablab,项目名称:rectangles,代码行数:72,代码来源:bigraph.py

示例3: delete_missing_loops

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import get_closest_diagonal [as 别名]
  def delete_missing_loops(self, DG_loops, K, L, threshold):
    begs_related_to_loop = dict()
    begin_loops = dict()
    end_loops = dict()
    for eeid1, (long_eid1, long_eid2, busheids, path, visited_vs) in DG_loops.items():
      for k, be in self.es.items():
        for diag in be.diagonals:
          rect = diag.rectangle
          eids = [rect.e1.eid, rect.e2.eid ]
          if rect.e1.eid not in busheids or rect.e2.eid not in busheids:
            continue
          for eid in eids:
            if eid not in busheids:
              continue
            if rect.e1.eid == long_eid1:
              if rect.e2.eid == long_eid1: 
                begin_loops[long_eid1] = (diag, be)
            if rect.e2.eid == long_eid2:
              if rect.e1.eid == long_eid2:  
                end_loops[long_eid1] = (diag, be)
            if eeid1 not in begs_related_to_loop:
              begs_related_to_loop[eeid1] = set()
            begs_related_to_loop[eeid1].add(be)
    diag_to_add = set()
    for eid, begs in begs_related_to_loop.items():
      (long_eid1, long_eid2, busheids, path, visited_vs)  =  DG_loops[eid]
      if len(begs) < 2:
        continue
      if eid not in begin_loops or eid not in end_loops:
        print "not find begin_end"
        continue
      begin_diag = begin_loops[eid][0]
      end_diag = end_loops[eid][0]
      path.append(end_loops[eid][0].rectangle.e1)
      first_shift = begin_diag.offseta
      second_shift = begin_diag.offsetb
      path_len = 0
      for e in path:
        path_len += e.len
      rectangles = []
      diags = []
      pos_first_path = 0
      pos_second_path = 0
      first_len = first_shift
      while first_len < path_len and pos_second_path < len(path):
        ed1 = path[pos_first_path]
        ed2 = path[pos_second_path]
        rectangle = Rectangle(ed1,ed2)
        rectangle.add_diagonal(self.d, self.d + first_shift - second_shift)
        rect_diag = rectangle.get_closest_diagonal(self.d + first_shift - second_shift) 
        rectangles.append(rectangle)
        diags.append(rect_diag)
        if ed2.len - second_shift < ed1.len - first_shift:
            pos_second_path += 1
            first_shift += ed2.len - second_shift
            first_len += ed2.len - second_shift
            second_shift = 0
        elif ed1.len - first_shift < ed2.len - second_shift:
            pos_first_path += 1
            first_len += ed1.len - first_shift
            second_shift += ed1.len - first_shift
            first_shift = 0
        else:
            first_len += ed1.len - first_shift
            pos_second_path += 1
            pos_first_path += 1
            first_shift = 0
            second_shift = 0
      for diag in diags:
        diag_to_add.add(diag)
        
      for bedge in begs:
        self.__remove_bedge__(bedge)
        self.__remove_bedge__(bedge.conj)
        
        for diag in bedge.diagonals:
          if diag.rectangle.e1.eid not in busheids or diag.rectangle.e2.eid not in busheids:
            diag_to_add.add(diag)
        
        if begin_diag in bedge.diagonals:
          for diag in bedge.diagonals:
            if diag == begin_diag:
              break
            diag_to_add.add(diag)
          
        elif end_diag in bedge.diagonals:
          bedge.diagonals.reverse()
          for diag in bedge.diagonals:
            if diag == end_diag:
              break
            diag_to_add.add(diag)

    for diag in diag_to_add:
          self.add_diagonal_and_conj(diag)
开发者ID:ablab,项目名称:rectangles,代码行数:96,代码来源:bigraph.py

示例4: delete_missing_loops

# 需要导入模块: from rectangle import Rectangle [as 别名]
# 或者: from rectangle.Rectangle import get_closest_diagonal [as 别名]
    def delete_missing_loops(self, DG_loops, K, L, threshold):
        if DG_loops == None:
            return
        begs_related_to_loop = defaultdict(set)
        begin_loops = dict()
        end_loops = dict()
        for k, be in self.es.items():
            for diag in be.diagonals:
                for eeid1, (long_eid1, long_eid2, busheids, path, visited_vs, all_paths) in DG_loops.items():
                    rect = diag.rectangle
                    if not set([rect.e1.eid, rect.e2.eid]) <= busheids:
                        continue
                    
                    if rect.e1.eid == long_eid1 and rect.e2.eid == long_eid1:
                        begin_loops[long_eid1] = (diag, be)
                    
                    if rect.e1.eid == long_eid2 and  rect.e2.eid == long_eid2:
                        end_loops[long_eid1] = (diag, be)                        
                    
                    begs_related_to_loop[eeid1].add(be)

        diag_to_add = []
        for eid, begs in begs_related_to_loop.items():
            (long_eid1, long_eid2, busheids, path, visited_vs, all_paths) = DG_loops[eid]
            path = self.choose_best_path(all_paths, long_eid1, long_eid2, begs)
            if len(begs) < 2:
                continue
            if eid not in begin_loops or eid not in end_loops:
                continue
            begin_diag = begin_loops[eid][0]
            if begin_diag.rectangle.e1.len < 2*self.d or len(path) < 1 or path[0] != begin_diag.rectangle.e1 or path[0].len < 2 * self.d:
                self.logger.info("BAD CASE " + str( eid)+ " " + str( begin_diag.rectangle.e1.len) + " " +str((long_eid1, long_eid2, busheids, path, visited_vs))) 
                continue
            end_diag = end_loops[eid][0]
            path.append(end_loops[eid][0].rectangle.e1)
            first_shift = begin_diag.offseta
            second_shift = begin_diag.offsetb
            
            path_len = reduce(lambda s, e: s + e.len, path, 0)           
            rectangles = []
            diags = []
            pos_first_path = 0
            pos_second_path = 0
            first_len = first_shift
            while first_len < path_len and pos_second_path < len(path):
                ed1 = path[pos_first_path]
                ed2 = path[pos_second_path]
                rectangle = Rectangle(ed1, ed2)
                rectangle.add_diagonal(self.d, self.d + first_shift - second_shift)
                rect_diag = rectangle.get_closest_diagonal(self.d + first_shift - second_shift)
                rectangles.append(rectangle)
                diags.append(rect_diag)
                if ed2.len - second_shift < ed1.len - first_shift:
                    pos_second_path += 1
                    first_shift += ed2.len - second_shift
                    first_len += ed2.len - second_shift
                    second_shift = 0
                elif ed1.len - first_shift < ed2.len - second_shift:
                    pos_first_path += 1
                    first_len += ed1.len - first_shift
                    second_shift += ed1.len - first_shift
                    first_shift = 0
                else:
                    first_len += ed1.len - first_shift
                    pos_second_path += 1
                    pos_first_path += 1
                    first_shift = 0
                    second_shift = 0
            
            diag_to_add.extend(diags)
            
            for bedge in begs:
                self.__remove_bedge_and_conj(bedge)
             
                for diag in bedge.diagonals:
                    if diag.rectangle.e1.eid not in busheids or diag.rectangle.e2.eid not in busheids:
                        diag_to_add.append(diag)

                if begin_diag in bedge.diagonals:
                    for diag in bedge.diagonals:
                        if diag == begin_diag:
                            break
                        diag_to_add.append(diag)

                elif end_diag in bedge.diagonals:
                    bedge.diagonals.reverse()
                    for diag in bedge.diagonals:
                        if diag == end_diag:
                            break
                        diag_to_add.append(diag)

        for diag in diag_to_add:
            self.add_diagonal_and_conj(diag)
开发者ID:Brainiarc7,项目名称:TS,代码行数:95,代码来源:bigraph.py


注:本文中的rectangle.Rectangle.get_closest_diagonal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。