如何解决如何使用首次拟合算法将频率槽分配给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 举报,一经查实,本站将立刻删除。