我正在寻找能够在N个相同处理器中找到任务计划的最佳解决方案的精确算法。
此算法的时间并不重要,最重要的是一个最佳解决方案(最后一个任务完成时所有处理器的最小时间)。
理论上,描述该算法的方程如下: P || Cmax
如果有人有算法(尤其是Java)或伪代码,我会很乐意寻求帮助。
我尝试编写我自己的确切算法但是id不起作用:(。在下面的代码中,permUtil是一个对应于排列的类。
方法args:
- 任务 - >索引识别任务和值时间的所有任务
- op - >分配处理器(分配任务的处理器)
//我们有一个全局数组操作符处理器proc,其中index是identity,value是此处理器上的任务调度时间
public void schedule(Byte[] tasks, int op)
{
PermUtil<Byte> permA = new PermUtil<Byte>(tasks);
Byte[] a;
// permutation of all tasks
while ((a = permA.next()) != null)
{
// assign tasks
for(int i=1; i< a.length; i++)
{
// get the b set from i to end
Byte[] b = Arrays.copyOfRange(a, i, a.length);
// all permutations off b set
PermUtil<Byte> permB = new PermUtil<Byte>(b);
while ((b = permB.next()) != null)
{
// task on assign processor
proc[op] = sum(Arrays.copyOfRange(a, 0, i));
if (op < proc.length)
schedule(b, ++op);
else
{
proc[++op] = sum(b);
}
}
}
}
}
答案 0 :(得分:2)
这是迭代所有可能任务的蓝图。
在实际实施中,您应该将long
替换为BigInteger
,
并将数组初始化移到内部循环之外。
public void processOne(int nProcs, int nTasks, int[] assignment) {
/* ... */
}
public void checkAll(int nProcs, int nTasks) {
long count = power(nProcs, nTasks);
/* Iterate over all the possible assignments */
for (long j = 0; j < count; j++) {
int[] assignment = new int[nTasks];
for (int i = 0; i < nTasks; i++)
assignment[i] = (int) (j / power(nProcs, i) % nProcs);
processOne(nProcs, nTasks, assignment);
}
}
诀窍是对数字中的赋值进行编码。由于作业代表nTasks
个决策,每个作品都有nProcs
个结果,因此可以将其视为基数nProcs
中具有nTasks
个数字的数字。每个这样的数字对应于有效的分配,并且每个分配在该范围内具有唯一的数字。迭代所有赋值很容易,因为我们基本上迭代了一系列整数。
您所要做的就是填写processOne(int, int, int[])
函数,这应该是相当简单的。