HandoverExperiment.java
5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.example.mina.client.experiment;
import com.example.mina.client.base.Experiment;
import com.example.mina.client.base.ExperimentOptions;
import com.example.mina.client.base.MatrixClient;
import com.example.mina.client.base.MatrixCommand;
import com.example.mina.client.base.MatrixConstants;
import com.example.mina.client.base.StationPair;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.CollectionUtils;
public class HandoverExperiment extends Experiment {
public HandoverExperiment(MatrixClient client, ExperimentOptions options) {
super(client, options);
}
@Override
public String getExperimentName() {
return MatrixConstants.EXPERIMENT_HANDOVER;
}
@Override
public void schedule() {
List<StationPair> pairs = options.getPairs();
if (CollectionUtils.isEmpty(pairs)) {
return;
}
StationPair one = pairs.get(0);
if (one == null || one.getInList() == null) {
return;
}
// 输入端口的个数
int inSize = one.getInList().size();
if (inSize < 2) {
return;
}
// 循环次数
Integer count = options.getMaxIterCount();
if (count == null || count < 1) {
return;
}
Integer step = options.getStep();
Integer endAttenuation = options.getEndAttenuation();
int dynamicCont = endAttenuation / step;
if (step == null || step <= 0) {
return;
}
for (int i = 0; i < count; i++) {
// 输入端口只有 2 个
if (inSize == 2) {
for (int k = 0; k <= dynamicCont; k++) {
int dynamic = step * k;
List<MatrixCommand> commandList = new ArrayList<>();
for (StationPair pair : pairs) {
Integer out = pair.getOut();
Integer inOne = pair.getInList().get(0);
Integer inTwo = pair.getInList().get(1);
MatrixCommand commandOne = MatrixCommand.builder().command(MatrixConstants.COMMAND_SET_ATTN)
.col(inOne).row(out).attn(dynamic).build();
MatrixCommand commandTwo = MatrixCommand.builder().command(MatrixConstants.COMMAND_SET_ATTN)
.col(inTwo).row(out).attn(endAttenuation - dynamic).build();
commandList.add(commandOne);
commandList.add(commandTwo);
}
commandList.forEach(this::sendCommand);
commandList.clear();
try {
Thread.sleep(options.getPeriod() * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} else {
// 输入端口大于 2
// 行数
int rowCount = 1 + inSize * dynamicCont;
// 动态衰减值 矩阵
int[][] attenuation = new int[rowCount][inSize];
// 当前动态输入端口指针
int current = 0;
for (int k = 0; k < rowCount; k++) {
// 动态衰减值
int dynamic = step * (k != 0 && k % dynamicCont == 0 ? dynamicCont : k % dynamicCont);
for (int j = 0; j < inSize; j++) {
if (j == current && j != inSize - 1) {
attenuation[k][j++] = dynamic;
attenuation[k][j] = endAttenuation - dynamic;
} else if (j == current && j == inSize - 1) {
attenuation[k][j] = dynamic;
attenuation[k][0] = endAttenuation - dynamic;
} else {
attenuation[k][j] = endAttenuation;
}
}
// 一轮衰减完成后,当前动态输入端口指针 加 1
if (k != 0 && k % dynamicCont == 0) {
current++;
}
}
for (int x = 0; x < rowCount; x++) {
// 当前行 --> 时间点,需要发送的 命令
List<MatrixCommand> commandList = new ArrayList<>();
for (int y = 0; y < inSize; y++) {
int att = attenuation[x][y];
for (StationPair pair : pairs) {
Integer out = pair.getOut();
Integer in = pair.getInList().get(y);
commandList.add(MatrixCommand.builder().command(MatrixConstants.COMMAND_SET_ATTN)
.col(in).row(out).attn(att).build());
}
}
commandList.forEach(this::sendCommand);
// 发送完成后,清空集合。
commandList.clear();
try {
Thread.sleep(options.getPeriod() * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
try {
Thread.sleep(options.getPause() * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}