Commit e5b5eadb authored by Hu Jintao's avatar Hu Jintao

测试转发功能融合

parent fbbafe90
...@@ -66,7 +66,7 @@ public class BisheTestMain implements ApplicationRunner { ...@@ -66,7 +66,7 @@ public class BisheTestMain implements ApplicationRunner {
result = doMap.result; result = doMap.result;
flag = repetition(result); flag = repetition(result);
} }
System.out.println("optimal mapping scheme"+Arrays.toString(result));
DataPackage dataPackage = new DataPackage(); DataPackage dataPackage = new DataPackage();
//路径表 //路径表
......
...@@ -133,9 +133,9 @@ public class DoMap { ...@@ -133,9 +133,9 @@ public class DoMap {
DoMap doMap = new DoMap(); DoMap doMap = new DoMap();
Par best_par = doMap.main_bpso(k, c, dev, n1, n2, D, lt, nt, link, n, s, c1, c2, num, slot, mapdev); Par best_par = doMap.main_bpso(k, c, dev, n1, n2, D, lt, nt, link, n, s, c1, c2, num, slot, mapdev);
if (best_par.fit != 0){ if (best_par.fit != 0){
//System.out.println(1 / best_par.fit); System.out.println(1 / best_par.fit);
/* System.out.println(Arrays.toString(best_par.task)); System.out.println(Arrays.toString(best_par.task));
System.out.println(Arrays.toString(best_par.taskfinal));*/ System.out.println(Arrays.toString(best_par.taskfinal));
//赋值节点映射结果 //赋值节点映射结果
int itemp = 0; int itemp = 0;
for (int a:best_par.taskfinal for (int a:best_par.taskfinal
...@@ -474,60 +474,63 @@ public class DoMap { ...@@ -474,60 +474,63 @@ public class DoMap {
*/ */
// boolean flag = true; // boolean flag = true;
// while (flag) { // while (flag) {
for (int i = 0; i < nn; i++) { // while (true) {
//更新速度 for (int i = 0; i < nn; i++) {
par.v[i] = s * par.v[i] + c1 * random.nextDouble() * (best_par.bestx[i] - par.x[i]) + c2 * random.nextDouble() * (par.bestx[i] - par.x[i]); //更新速度
if (par.v[i] > 1) { par.v[i] = s * par.v[i] + c1 * random.nextDouble() * (best_par.bestx[i] - par.x[i]) + c2 * random.nextDouble() * (par.bestx[i] - par.x[i]);
par.v[i] = 1; if (par.v[i] > 1) {
} par.v[i] = 1;
if (par.v[i] < -1) { }
par.v[i] = -1; if (par.v[i] < -1) {
} par.v[i] = -1;
} }
//更新位置
int maxIndex=0;//假设第一个元素为最大值 那么下标设为0
for(int i =0;i<par.v.length-1;i++){
if(par.v[maxIndex]<par.v[i+1]){
maxIndex=i+1;
}
}
for (int i = (maxIndex/n2)*n2;i<(maxIndex/n2+1)*n2;i++){
if (i == maxIndex){
par.x[i] = 1;
}else{
par.x[i] = 0;
} }
} //更新位置
int maxIndex = 0;//假设第一个元素为最大值 那么下标设为0
/* boolean flag2 = true; for (int i = 0; i < par.v.length - 1; i++) {
for (int i = 0; i < nn; i += n2) { if (par.v[maxIndex] < par.v[i + 1]) {
int sum = 0; maxIndex = i + 1;
for (int j = 0; j < n2; j++) { }
sum += par.x[i + j];
} }
if (sum != 1) { for (int i = (maxIndex / n2) * n2; i < (maxIndex / n2 + 1) * n2; i++) {
flag2 = false; if (i == maxIndex) {
break; par.x[i] = 1;
} else {
par.x[i] = 0;
}
} }
}
if (!flag2) {
continue;
}*/
// flag = false;
//extract 提取映射结果 /* boolean flag2 = true;
par.task[0] = 0; for (int i = 0; i < nn; i += n2) {
par.task[c - 1] = dev - 1; int sum = 0;
int index = 1; for (int j = 0; j < n2; j++) {
for (int i = 0; i < n1 * n2; i += n2) { sum += par.x[i + j];
for (int j = 0; j < n2; j++) { }
if (par.x[i + j] == 1) { if (sum != 1) {
par.task[index] = num*(j/mapdev) +(j%mapdev) + 1; flag2 = false;
index++;
break; break;
} }
} }
} if (!flag2) {
continue;
}*/
// flag = false;
//extract 提取映射结果
par.task[0] = 0;
par.task[c - 1] = dev - 1;
int index = 1;
for (int i = 0; i < n1 * n2; i += n2) {
for (int j = 0; j < n2; j++) {
if (par.x[i + j] == 1) {
par.task[index] = num * (j / mapdev) + (j % mapdev) + 1;
index++;
break;
}
}
}
isRepitition(par.task);
// }
//排序 //排序
int temp; int temp;
for(int p = 0; p<(c-1); p++) { for(int p = 0; p<(c-1); p++) {
...@@ -548,6 +551,14 @@ public class DoMap { ...@@ -548,6 +551,14 @@ public class DoMap {
} }
} }
private void isRepitition(int[] task) {
for (int i = 1;i<task.length-1;i++){
for (int j = i+1;j<task.length-1;j++){
if (task[i]==task[j] && task[j]%30<29) task[j]+=1;
}
}
}
// } // }
/** /**
* 计算适应度值 * 计算适应度值
......
...@@ -5,6 +5,4 @@ bishe: ...@@ -5,6 +5,4 @@ bishe:
cloud-url: 192.168.31.198:9091 cloud-url: 192.168.31.198:9091
# cloud-url: 192.168.31.198:9090 # cloud-url: 192.168.31.198:9090
slot=20000 slot: 20000
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment