如何使用首次拟合算法将频率槽分配给python图中的需求?

问题描述

我有一个包含许多节点和链接的图形,而且我在图形中的两个节点(源和目标)之间有一些需求。我的目的是为图中的每个需求找到最佳路线,这是其中的最短路径。另外,我想为每个需求分配频率槽。实际上,图中的任何链接都包含插槽或频道,我想使用首次拟合算法将这些频率插槽分配给我的需求。
现在我通过对每个需求应用最短路径函数来为每个需求找到最佳路线。
我的问题是如何使用最适合算法为需求分配频道?
我试图这样做,这是我代码的一部分,但它对我不起作用,有人可以帮我做吗?
我使用以下来自 geeksforgeeks 网站的代码here
实际上在 geeksforgeeks 的这段代码中,我认为每个进程或需求只需要一个块或槽。但在我的问题中,每个流程或需求可能需要多个插槽。
如果我的解释不够,请在评论中告诉我。我在#comments 下面的代码块中解释了更多。谢谢。

for k in range(1,6,1)
   for path in k_shortest_paths(G,source,target,3,weight='weight'):
     if edge in edge_list  
       # edge_list is a list of my graph links that I defined it already in my code
       #define the slots in the link.here I have defined a vector in each link which has 250 slots
       f_channels = numpy.empty(250,dtype=object)
      else:
       f_channels = -1
        pass
      #define the required number of channels.rate is data rate of the demand which I've defined it 
      #before
      n=rate/k
      #first_fit algorithm
      # python3 implementation of First-Fit algorithm 

      # Function to allocate memory(frequency channels) to 
      # blocks as per First fit algorithm.in my problem block capacity is constant and each link has 250 
      #these blocks(slots). but in this code from geeksforgeeks each block can have different capacity. 
      def firstFit(blockSize,m,processSize,n): 
        # Stores block id of the 
        # block allocated to a process 
        allocation = [-1] * n 

        # Initially no block is assigned to any process 

        # pick each process and find suitable blocks 
        # according to its size ad assign to it 
        for i in range(n): 
          for j in range(m): 
            if blockSize[j] >= processSize[i]: 
              
              # allocate block j to p[i] process 
              allocation[i] = j 

              # Reduce available memory in this block. 
              blockSize[j] -= processSize[i] 

              break

        print(" Process No. Process Size     Block no.") 
        for i in range(n): 
          print(" ",i + 1,"        ",processSize[i],"      ",end = " ") 
          if allocation[i] != -1: 
            print(allocation[i] + 1) 
          else: 
            print("Not Allocated") 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)