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