简化这些代码，你可以把一些对象比如sequence_group给拆开，但是保持算法原来的含义不变，方便我进行测试
def optimize_request_assignment(self, fast_instance_seqs: List[Tuple[DistserveSequenceGroup,float]], slow_instance_seqs: List[Tuple[DistserveSequenceGroup,float]],fast_instance_id:int,slow_instance_id:int,now:float):
        
        # print("fast_instance_seqs =", fast_instance_seqs, "\nslow_instance_seqs =", slow_instance_seqs, "\nfast_instance_id =", fast_instance_id, "\nslow_instance_id =", slow_instance_id, "\nnow =", now)
        
        init_fast_request_ids_set = set(seq_group.request_id for seq_group, _ in fast_instance_seqs)
        init_slow_request_ids_set = set(seq_group.request_id for seq_group, _ in slow_instance_seqs)
        
        # 初始化当前的序列
        fast_seqs = fast_instance_seqs.copy()
        slow_seqs = slow_instance_seqs.copy()
        optimal_fast_seqs = []
        optimal_slow_seqs = []
        
        min_slack_fast = fast_instance_seqs[0][1]
        min_slack_slow = slow_instance_seqs[0][1]
        max_sum = min_slack_fast + min_slack_slow
        
        send_slow2fast_seqs = []
        send_fast2slow_seqs = []
        
        now = time.time()
        
        for i in range(len(slow_seqs) - 1, -1, -1):
            candidate_from_slow2fast = slow_seqs[i:]
            new_slow_seqs = slow_seqs[:i]
            new_fast_seqs = candidate_from_slow2fast + fast_seqs
            
            # 升序排列
            new_fast_seqs = self.check_if_rebalance_available(new_fast_seqs,now)
            new_slow_seqs = self.check_if_rebalance_available(new_slow_seqs,now)
            
            if len(new_fast_seqs)==0 or len(new_slow_seqs)==0:
                
                continue
            
            new_min_slack_fast = new_fast_seqs[0][1]
            new_min_slack_slow = new_slow_seqs[0][1]
            
            if new_min_slack_fast + new_min_slack_slow > max_sum:
                optimal_fast_seqs = new_fast_seqs
                optimal_slow_seqs = new_slow_seqs
                max_sum = new_min_slack_fast + new_min_slack_slow
            
        # 在新的request放置下进行搜索
        if len(optimal_fast_seqs)!=0 and len(optimal_slow_seqs)!=0:
            fast_seqs = optimal_fast_seqs
            slow_seqs = optimal_slow_seqs
        
        for i in range(len(fast_seqs)-1):
            candidate_from_fast2slow = fast_seqs[:i]
            new_fast_seqs = fast_seqs[i:]
            new_slow_seqs = candidate_from_fast2slow + slow_seqs
            
            # 升序排列
            new_fast_seqs = self.check_if_rebalance_available(new_fast_seqs,now)
            new_slow_seqs = self.check_if_rebalance_available(new_slow_seqs,now)
            
            if len(new_fast_seqs)==0 or len(new_slow_seqs)==0:
                continue
            
            new_min_slack_fast = new_fast_seqs[0][1]
            new_min_slack_slow = new_slow_seqs[0][1]
            
            if new_min_slack_fast + new_min_slack_slow > max_sum:
                optimal_fast_seqs = new_fast_seqs
                optimal_slow_seqs = new_slow_seqs
                max_sum = new_min_slack_fast + new_min_slack_slow
        
        send_slow2fast_seqs = [(seq_group, fast_instance_id) for seq_group, _ in optimal_fast_seqs if seq_group.request_id in init_slow_request_ids_set]
        send_fast2slow_seqs = [(seq_group, slow_instance_id) for seq_group, _ in optimal_slow_seqs if seq_group.request_id in init_fast_request_ids_set]
               
        return send_fast2slow_seqs,send_slow2fast_seqs