'Finds optimized order of the nodes within their ranks using median heuristic'

def order_in_rank(self):

    self.make_chain()
    self.preprocess_order()
    self.order = {}
    max_rank = max(map((lambda x: x), self.levels.keys()))
    for i in range((max_rank + 1)):
        self.order[i] = 0
    self.init_order(self.start, self.result[self.start]['x'])
    for level in self.levels:
        self.levels[level].sort((lambda x, y: cmp(self.result[x]['y'], self.result[y]['y'])))
    self.order_heuristic()
    self.process_order()
