Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Distributed Computing and Network Fusion System
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WirelessInformationCollaborate
Distributed Computing and Network Fusion System
Commits
a86f0292
Commit
a86f0292
authored
Aug 12, 2020
by
ymwang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加云计算模块
parent
4c780f1e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
782 additions
and
0 deletions
+782
-0
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopo.java
...main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopo.java
+89
-0
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopoUnit.java
.../java/top/ninwoo/weixingsim/dynamicNet/CycleTopoUnit.java
+91
-0
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/DoMap.java
...src/main/java/top/ninwoo/weixingsim/dynamicNet/DoMap.java
+278
-0
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/InterSlotDijstraV2.java
.../top/ninwoo/weixingsim/dynamicNet/InterSlotDijstraV2.java
+158
-0
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/TimeExpanGraph.java
...java/top/ninwoo/weixingsim/dynamicNet/TimeExpanGraph.java
+166
-0
No files found.
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopo.java
0 → 100644
View file @
a86f0292
package
top.ninwoo.weixingsim.dynamicNet
;
import
top.ninwoo.weixingsim.sateTopology.entity.SimData
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.ToponetImpl
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.WeixingImpl
;
import
java.io.File
;
import
java.util.*
;
public
class
CycleTopo
{
public
static
void
main
(
String
[]
args
)
{
cycleTp
();
}
public
static
HashMap
<
Integer
,
double
[][]>
cycleTp
(){
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"D:\\project\\topusim_1.txt"
);
//D:\LabratoryJavaPro\codingDownload\latestCoding\
List
<
WeiXingData
>
wxData
=
null
;
{
try
{
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
//初始topo
double
[][]
toponet
=
tp
.
getWeightedTopology
(
wxData
,
sd
);
//去掉ovs
double
[][]
topoNet
=
new
double
[
10
][
10
];
for
(
int
i
=
0
;
i
<
topoNet
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
i
][
j
]
=
toponet
[
i
][
j
];
}
}
HashMap
<
Integer
,
double
[][]>
TopoStore
=
new
HashMap
<>();
TopoStore
.
put
(
0
,
topoNet
);
for
(
int
i
=
1
;
i
<
sd
.
getZhouqi
()/
sd
.
getJiange
();
i
++)
{
int
time
=
i
*
sd
.
getJiange
();
List
<
WeiXingData
>
changetp
=
wx
.
changeTopo
(
wxData
,
time
);
double
[][]
changeTopo
=
tp
.
getWeightedTopology
(
changetp
,
sd
);
//去掉ovs
for
(
int
k
=
0
;
k
<
topoNet
.
length
;
k
++){
for
(
int
j
=
0
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
k
][
j
]
=
changeTopo
[
k
][
j
];
}
}
for
(
int
k
=
0
;
k
<
topoNet
.
length
;
k
++){
for
(
int
j
=
k
+
1
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
k
][
j
]
=
topoNet
[
j
][
k
];
}
}
TopoStore
.
put
(
i
,
topoNet
);
}
int
count
=
0
;
int
count2
=
-
1
;
Iterator
<
Map
.
Entry
<
Integer
,
double
[][]>>
iterator
=
TopoStore
.
entrySet
().
iterator
();
while
(
iterator
.
hasNext
()){
double
[][]
value
=
iterator
.
next
().
getValue
();
for
(
int
i
=
0
;
i
<
value
.
length
;
i
++){
if
(
i
>
0
){
boolean
equals
=
Arrays
.
equals
(
value
[
i
],
topoNet
[
i
]);
count
+=
(
equals
?
1
:
0
);
}
for
(
int
j
=
0
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
i
][
j
]
=
value
[
i
][
j
];
}
}
for
(
int
k
=
0
;
k
<
topoNet
.
length
;
k
++){
for
(
int
j
=
k
+
1
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
k
][
j
]
=
topoNet
[
j
][
k
];
}
}
if
(
count
!=
30
){
count2
++;
}
System
.
out
.
println
(
Arrays
.
deepToString
(
topoNet
));
System
.
out
.
println
(
"========================================="
);
System
.
out
.
println
(
count2
);
}
return
TopoStore
;
}
}
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/CycleTopoUnit.java
0 → 100644
View file @
a86f0292
package
top.ninwoo.weixingsim.dynamicNet
;
import
top.ninwoo.weixingsim.sateTopology.entity.SimData
;
import
top.ninwoo.weixingsim.sateTopology.entity.WeiXingData
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.ToponetImpl
;
import
top.ninwoo.weixingsim.sateTopology.service.impl.WeixingImpl
;
import
java.io.File
;
import
java.util.*
;
public
class
CycleTopoUnit
{
public
static
void
main
(
String
[]
args
)
{
cycleTpE
();
}
public
static
HashMap
<
Integer
,
double
[][]>
cycleTpE
(){
//从文本中获取卫星的数据
WeixingImpl
wx
=
new
WeixingImpl
();
ToponetImpl
tp
=
new
ToponetImpl
();
SimData
sd
=
new
SimData
();
//tp.delHistory();
File
file
=
new
File
(
"D:\\project\\topusim_1.txt"
);
//D:\LabratoryJavaPro\codingDownload\latestCoding\
List
<
WeiXingData
>
wxData
=
null
;
{
try
{
wxData
=
wx
.
iniTopo
(
file
,
sd
.
getZhouqi
());
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
}
//初始topo
int
[][]
toponet
=
tp
.
getTopology
(
wxData
,
sd
);
//去掉ovs
double
[][]
topoNet
=
new
double
[
6
][
6
];
//卫星节点数目 卫星组成的网络拓扑
for
(
int
i
=
0
;
i
<
topoNet
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
i
][
j
]
=
toponet
[
i
][
j
];
}
}
HashMap
<
Integer
,
double
[][]>
TopoStore
=
new
HashMap
<>();
TopoStore
.
put
(
0
,
topoNet
);
for
(
int
i
=
1
;
i
<
sd
.
getZhouqi
()/
sd
.
getJiange
();
i
++)
{
int
time
=
i
*
sd
.
getJiange
();
List
<
WeiXingData
>
changetp
=
wx
.
changeTopo
(
wxData
,
time
);
int
[][]
changeTopo
=
tp
.
getTopology
(
changetp
,
sd
);
//去掉ovs
for
(
int
k
=
0
;
k
<
topoNet
.
length
;
k
++){
for
(
int
j
=
0
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
k
][
j
]
=
changeTopo
[
k
][
j
];
}
}
for
(
int
k
=
0
;
k
<
topoNet
.
length
;
k
++){
for
(
int
j
=
k
+
1
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
k
][
j
]
=
topoNet
[
j
][
k
];
}
}
TopoStore
.
put
(
i
,
topoNet
);
}
int
count
=
0
;
int
count2
=
-
1
;
Iterator
<
Map
.
Entry
<
Integer
,
double
[][]>>
iterator
=
TopoStore
.
entrySet
().
iterator
();
while
(
iterator
.
hasNext
()){
double
[][]
value
=
iterator
.
next
().
getValue
();
for
(
int
i
=
0
;
i
<
value
.
length
;
i
++){
if
(
i
>
0
){
boolean
equals
=
Arrays
.
equals
(
value
[
i
],
topoNet
[
i
]);
count
+=
(
equals
?
1
:
0
);
}
for
(
int
j
=
0
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
i
][
j
]
=
value
[
i
][
j
];
}
}
for
(
int
k
=
0
;
k
<
topoNet
.
length
;
k
++){
for
(
int
j
=
k
+
1
;
j
<
topoNet
.
length
;
j
++){
topoNet
[
k
][
j
]
=
topoNet
[
j
][
k
];
}
}
if
(
count
!=
30
){
count2
++;
}
System
.
out
.
println
(
Arrays
.
deepToString
(
topoNet
));
System
.
out
.
println
(
"========================================="
);
System
.
out
.
println
(
count2
);
}
return
TopoStore
;
}
}
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/DoMap.java
0 → 100644
View file @
a86f0292
package
top.ninwoo.weixingsim.dynamicNet
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.Stack
;
import
static
top
.
ninwoo
.
weixingsim
.
dynamicNet
.
CycleTopoUnit
.
cycleTpE
;
/**
* 求某一数据量下的最佳映射结果和业务处理时延
* 输出最佳粒子的位置和适应度值
* 目前只允许计算过程跨单时隙
* @jthu
*/
public
class
DoMap
{
//最大权值
static
final
int
MAXWEIGHT
=
10000
*
1000
;
/*
* 业务参数
*/
//数据量MB?
static
double
D
=
4
;
//子任务数
static
int
c
=
7
;
//8
//子任务依赖关系 边
static
int
[][]
link
=
{{
0
,
0
,
1
,
2
,
3
,
4
,
5
},
{
1
,
2
,
3
,
4
,
5
,
5
,
6
}};
//
//固定映射任务数==起始任务+终止任务
static
final
int
C_STABLE
=
2
;
//实际需映射任务数
static
int
n1
=
c
-
C_STABLE
;
/*
* 网络参数
*/
//设备数
static
int
num
=
6
;
//设备计算能力参数s GB/s
static
double
[]
nt
=
{
1.112341341313
,
0.5196272109574349
,
0.675827555541419
,
0.7637869915859579
,
0.7998320296858645
,
0.638652700648973
,
0.6396760676518485
,
0.5615337810185533
,
0.6356797503522186
,
0.8266103444996542
};
//30节点
/*static double[] nt = {1.112341341313, 0.5196272109574349, 0.675827555541419, 0.7637869915859579, 0.7998320296858645,
0.638652700648973, 0.6396760676518485, 0.5615337810185533, 0.6356797503522186, 0.8266103444996542, 0.6924037701405794,
0.9371892689614395, 0.6949256728585527, 0.6212614126622614, 0.6318393608430264, 0.7494680794385384, 0.9983949989039682,
0.5610722256465777, 0.6415780028672076, 0.9371892689, 0.5269659075274151, 0.8219152161388867, 0.5815463889106197,
0.8431429542046349, 0.31386253514456774, 0.6045132365410817, 0.8102279249524735, 0.47057296148341216, 0.8529743685059654, 0.8177711194660409}; //30节点*/
//时隙大小
static
double
slot
=
20
*
1000
;
//时隙数目
static
int
slotnum
;
//网络节点数
static
int
dev
;
//初始化时延偏移量
//这里需要一个时钟输入
static
double
testLatency
=
0
;
//固定映射设备数==起始设备+终止设备
static
final
int
N_STABLE
=
2
;
//实际可映射设备数
static
int
n2
;
//单时隙可映射设备数
static
int
mapdev
=
num
-
N_STABLE
;
/*
* BPSO参数
*/
//粒子群规模
static
int
n
=
1000
;
//种群迭代次数
static
int
k
=
500
;
//惯性权重,加速因子1,2
static
double
s
=
1.5
;
static
int
c1
=
1
;
static
int
c2
=
1
;
public
static
void
main
(
String
[]
args
)
{
doMapApp
();
}
//节点最终分配结果
public
static
int
[]
result
=
new
int
[
c
];
//节点间最短路由
public
static
Stack
[]
route
=
new
Stack
[
link
[
0
].
length
+
1
];
//业务发起时刻
public
static
long
startT
;
//传输时延约束
public
static
LinkedList
<
Double
>
list
=
new
LinkedList
<>();
public
static
void
doMapApp
()
{
for
(
slotnum
=
1
;
slotnum
<=
3
;
slotnum
++){
//slotnum = 3;
dev
=
num
*
slotnum
;
//10个卫星节点,3个时隙,则共有10*3个卫星节点
n2
=
dev
-
N_STABLE
*
slotnum
;
//n2实际可映射的节点
//组装最短路矩阵
double
[][]
edgeWeight
=
WTEG
();
System
.
out
.
println
(
"大矩阵是:"
);
for
(
int
i
=
0
;
i
<
edgeWeight
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
edgeWeight
[
0
].
length
;
j
++)
{
System
.
out
.
print
(
edgeWeight
[
i
][
j
]+
" "
);
}
System
.
out
.
println
();
}
//最短路由矩阵
InterSlotDijstraV2
dijs
=
new
InterSlotDijstraV2
(
num
,
slot
);
InterSlotDijstraV2
.
pathRecord
pathRecord
=
dijs
.
dijstra
(
edgeWeight
,
testLatency
);
double
[][]
lt
=
pathRecord
.
pathWeight
;
for
(
int
i
=
0
;
i
<
lt
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
lt
.
length
;
j
++){
lt
[
i
][
j
]
*=
D
;
}
}
/*System.out.println("最短路由");
System.out.println(Arrays.deepToString(lt));*/
for
(
int
i
=
0
;
i
<
nt
.
length
;
i
++)
{
nt
[
i
]
=
(
D
*
1000
)
/
nt
[
i
];
}
}
}
private
static
double
[][]
WTEG
()
{
//获取当前3时隙拓扑
/**
* 先用SimpleDateFormat.parse() 方法将日期字符串转化为Date格式
* 通过Date.getTime()方法,将其转化为毫秒数
*/
String
date
=
"2019-01-01 00-00-00"
;
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH-mm-ss"
);
//24小时制
long
time
=
0
;
try
{
time
=
simpleDateFormat
.
parse
(
date
).
getTime
();
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
int
slotKey
=
(
int
)
((((
System
.
currentTimeMillis
()-
time
)/
20
/
1000
)-
1
)%
300
+
1
);
startT
=
((
System
.
currentTimeMillis
()-
time
)/
20000
+
1
)*
20000
;
//HashMap<Integer, double[][]> cycleTp = cycleTp();
HashMap
<
Integer
,
double
[][]>
cycleTp
=
cycleTpE
();
//获得单时隙连接矩阵 0或MAXWEIGHT
//等待下一时隙开始执行业务
/* double[][] currentTp = cycleTp.get((slotKey)%300+1);
double[][] slot1 = new double[num][num];*/
double
[][]
currentTp
=
cycleTp
.
get
((
slotKey
)%
300
+
1
);
double
[][]
slot1
=
new
double
[
num
][
num
];
//10*10的矩阵图
System
.
out
.
println
(
"1:"
+(
slotKey
)%
300
+
1
);
for
(
int
i
=
0
;
i
<
currentTp
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
currentTp
[
0
].
length
;
j
++)
{
System
.
out
.
print
(
currentTp
[
i
][
j
]+
" "
);
}
System
.
out
.
println
();
}
//int[][] slot1 = new int[num][num]; //10*10的矩阵图
/* for(int i = 0;i<slot1.length;i++){
for(int j = 0;j<slot1.length;j++){
if (currentTp[i][j]==0.0){
if (i==j){
slot1[i][j]=0.0;
}else
slot1[i][j] = MAXWEIGHT;
}else{
slot1[i][j] = 10e5/currentTp[i][j];
}
}
}*/
for
(
int
i
=
0
;
i
<
slot1
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot1
[
0
].
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot1
[
i
][
j
]=
0
;
}
else
slot1
[
i
][
j
]
=
MAXWEIGHT
;
}
else
{
//slot1[i][j] = 10e5/currentTp[i][j];
}
}
}
/*System.out.println("第一个时隙的网络拓扑:"+Arrays.deepToString(slot1));
System.out.println(slot1.length);
System.out.println(slot1[0].length);
System.out.println("第一个时隙的网络拓扑:");
for (int i = 0; i < slot1.length; i++) {
for (int j = 0; j < slot1[0].length; j++) {
System.out.print(slot1[i][j]+" ");
}
System.out.println();
}*/
currentTp
=
cycleTp
.
get
((
slotKey
)%
300
+
1
);
System
.
out
.
println
(
"2:"
+(
slotKey
)%
300
+
2
);
double
[][]
slot2
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
slot2
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot2
.
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot2
[
i
][
j
]=
0.0
;
}
else
slot2
[
i
][
j
]
=
MAXWEIGHT
;
}
else
{
slot2
[
i
][
j
]
=
10
e5
/
currentTp
[
i
][
j
];
}
}
}
currentTp
=
cycleTp
.
get
((
slotKey
)%
300
+
1
);
double
[][]
slot3
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
slot3
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot3
.
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot3
[
i
][
j
]=
0.0
;
}
else
slot3
[
i
][
j
]
=
MAXWEIGHT
;
}
else
{
slot3
[
i
][
j
]
=
10
e5
/
currentTp
[
i
][
j
];
}
}
}
//生成相邻时隙矩阵
double
[][]
neighbor
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
neighbor
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
neighbor
.
length
;
j
++){
if
(
i
==
j
){
neighbor
[
i
][
j
]
=
slot
;
}
else
{
neighbor
[
i
][
j
]
=
MAXWEIGHT
;
}
}
}
//生成其余时隙矩阵
double
[][]
nonNeighbor
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
nonNeighbor
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
nonNeighbor
.
length
;
j
++){
nonNeighbor
[
i
][
j
]
=
MAXWEIGHT
;
}
}
//组装连接矩阵
double
[][]
edgeWeight
=
new
double
[
dev
][
dev
];
for
(
int
i
=
0
;
i
<
edgeWeight
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
edgeWeight
.
length
;
j
++){
if
(
i
>=
0
&
i
<
num
&
j
>=
0
&
j
<
num
)
{
edgeWeight
[
i
][
j
]
=
slot1
[
i
][
j
];
}
else
if
(
i
>=
num
&
i
<
2
*
num
&
j
>=
num
&
j
<
2
*
num
)
{
edgeWeight
[
i
][
j
]
=
slot2
[
i
%
num
][
j
%
num
];
}
else
if
(
i
>=
2
*
num
&
i
<
3
*
num
&
j
>=
2
*
num
&
j
<
3
*
num
)
{
edgeWeight
[
i
][
j
]
=
slot3
[
i
%
num
][
j
%
num
];
}
else
if
((
i
>=
0
&
i
<
num
&
j
>=
num
&
j
<
2
*
num
)
||
(
i
>=
num
&
i
<
2
*
num
&
j
>=
2
*
num
&
j
<
3
*
num
)){
edgeWeight
[
i
][
j
]
=
neighbor
[
i
%
num
][
j
%
num
];
}
else
{
edgeWeight
[
i
][
j
]
=
nonNeighbor
[
i
%
num
][
j
%
num
];
}
}
}
return
edgeWeight
;
}
}
\ No newline at end of file
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/InterSlotDijstraV2.java
0 → 100644
View file @
a86f0292
package
top.ninwoo.weixingsim.dynamicNet
;
public
class
InterSlotDijstraV2
{
public
static
void
main
(
String
[]
args
)
{
double
[][]
edgeWeight
=
new
double
[][]
{
{
0
,
96
,
157
,
100
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
},
{
371
,
0
,
163
,
MAXWEIGHT
,
100
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
},
{
84
,
395
,
0
,
MAXWEIGHT
,
MAXWEIGHT
,
100
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
0
,
8
,
1
,
100
,
MAXWEIGHT
,
MAXWEIGHT
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
5
,
0
,
1
,
MAXWEIGHT
,
100
,
MAXWEIGHT
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
5
,
5
,
0
,
MAXWEIGHT
,
MAXWEIGHT
,
100
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
0
,
46
,
83
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
25
,
0
,
55
},
{
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
MAXWEIGHT
,
35
,
18
,
0
}};
int
num
=
3
;
double
slot
=
100
;
double
testLatency
=
0
;
InterSlotDijstraV2
di
=
new
InterSlotDijstraV2
(
num
,
slot
);
di
.
dijstra
(
edgeWeight
,
testLatency
);
}
/* //最短路矩阵
double [][] pathWeight;
//*/
//设备数目
int
num
;
//时隙值
double
slot
;
//最大权值
static
final
int
MAXWEIGHT
=
10000
*
1000
;
public
InterSlotDijstraV2
(
int
num
,
double
slot
)
{
// TODO Auto-generated constructor stub
this
.
num
=
num
;
this
.
slot
=
slot
;
}
//最短路径算法
public
pathRecord
dijstra
(
double
[][]
edgeWeight
,
double
testLatency
)
{
pathRecord
pathRecord
=
new
pathRecord
();
//存放上一条路径
pathRecord
.
lastHop
=
new
int
[
edgeWeight
.
length
][
edgeWeight
.
length
];
//存放最短路径
pathRecord
.
pathWeight
=
new
double
[
edgeWeight
.
length
][
edgeWeight
.
length
];
for
(
int
i
=
0
;
i
<
edgeWeight
.
length
;
i
++)
{
singlePointDijstra
(
edgeWeight
,
i
,
testLatency
,
pathRecord
.
lastHop
[
i
],
pathRecord
.
pathWeight
[
i
]);
/* for(int j = 0; j < edgeWeight.length; j++) {
pathWeight[i][j] = singleRowWeight[j];
// System.out.print(pathWeight[i][j]+""+'\t');
}*/
// System.out.println('\n');
}
// System.out.println(Arrays.deepToString(pathRecord.pathWeight));
//上一跳路由矩阵
/*System.out.println("上一跳路由矩阵");
System.out.println(Arrays.deepToString(pathRecord.lastHop));*/
// System.out.println(Arrays.deepToString(pathWeight));
return
pathRecord
;
}
//单点最短路算法
private
double
[]
singlePointDijstra
(
double
[][]
edgeWeight
,
int
point
,
double
testLatency
,
int
[]
lastHopi
,
double
[]
pathWeighti
)
{
/* //存放最短路径
double [] singleRowWeight = new double [edgeWeight.length];*/
//存放已求得最短路径节点
boolean
[]
isVisited
=
new
boolean
[
edgeWeight
.
length
];
//初始化
for
(
int
j
=
0
;
j
<
edgeWeight
.
length
;
j
++)
{
if
(
edgeWeight
[
point
][
j
]!=
MAXWEIGHT
&&
edgeWeight
[
point
][
j
]!=
slot
)
{
if
((
edgeWeight
[
point
][
j
]+
testLatency
)
<=
slot
)
{
pathWeighti
[
j
]
=
edgeWeight
[
point
][
j
]
+
testLatency
;
}
else
{
pathWeighti
[
j
]
=
MAXWEIGHT
;
}
}
else
{
pathWeighti
[
j
]
=
edgeWeight
[
point
][
j
];
}
}
isVisited
[
point
]
=
true
;
//遍历所有节点
for
(
int
j
=
0
;
j
<
edgeWeight
[
point
].
length
;
j
++)
{
//遍历下一节点
int
index
=
MAXWEIGHT
;
index
=
nextPoint
(
pathWeighti
,
index
,
isVisited
,
edgeWeight
);
if
(
index
==
MAXWEIGHT
)
{
break
;}
isVisited
[
index
]
=
true
;
//更新以下一节点中转的全局最短路
pathWeighti
=
updateSRW
(
edgeWeight
,
pathWeighti
,
point
,
index
,
isVisited
,
lastHopi
);
}
return
pathWeighti
;
}
//遍历下一节点
private
int
nextPoint
(
double
[]
singleRowWeight
,
int
index
,
boolean
[]
isVisited
,
double
[][]
edgeWeight
)
{
double
min
=
0
;
for
(
int
j
=
0
;
j
<
edgeWeight
.
length
;
j
++)
{
if
(
isVisited
[
j
]
==
false
)
{
if
(
singleRowWeight
[
j
]
!=
0
&&
min
==
0
&&
singleRowWeight
[
j
]
!=
MAXWEIGHT
)
{
min
=
singleRowWeight
[
j
];
index
=
j
;
}
if
(
singleRowWeight
[
j
]
<
min
)
{
min
=
singleRowWeight
[
j
];
index
=
j
;
}
}
}
return
index
;
}
//更新以下一节点中转的全局最短路
private
double
[]
updateSRW
(
double
[][]
edgeWeight
,
double
[]
singleRowWeight
,
int
point
,
int
index
,
boolean
[]
isVisited
,
int
[]
lastHopi
)
{
double
temp
=
singleRowWeight
[
index
];
for
(
int
k
=
0
;
k
<
edgeWeight
.
length
;
k
++)
{
if
(
isVisited
[
k
]
==
false
)
{
if
((
index
+
num
)
==
k
)
{
if
(
(
k
/
num
-
point
/
num
)*
slot
<
singleRowWeight
[
k
])
{
singleRowWeight
[
k
]
=
(
k
/
num
-
point
/
num
)*
slot
;
lastHopi
[
k
]
=
index
;
}
}
else
{
if
((
temp
+
edgeWeight
[
index
][
k
])<=
(
k
/
num
-
point
/
num
+
1
)*
slot
&&
(
temp
+
edgeWeight
[
index
][
k
])
<
singleRowWeight
[
k
])
{
singleRowWeight
[
k
]
=
temp
+
edgeWeight
[
index
][
k
];
lastHopi
[
k
]
=
index
;
}
}
}
}
return
singleRowWeight
;
}
class
pathRecord
{
//最短路矩阵
double
[][]
pathWeight
;
//上一跳矩阵
int
[][]
lastHop
;
public
pathRecord
()
{
}
}
}
apps/cnf-distributed-file-transfer/dfs-transfer-topology/src/main/java/top/ninwoo/weixingsim/dynamicNet/TimeExpanGraph.java
0 → 100644
View file @
a86f0292
package
top.ninwoo.weixingsim.dynamicNet
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.Stack
;
import
static
top
.
ninwoo
.
weixingsim
.
dynamicNet
.
CycleTopoUnit
.
cycleTpE
;
public
class
TimeExpanGraph
{
/*
* 网络参数
*/
//设备数
static
int
num
=
30
;
//时隙大小
static
double
slot
=
20
*
1000
;
//时隙数目
static
int
slotnum
;
//网络节点数
static
int
dev
;
public
static
void
main
(
String
[]
args
)
{
doMapApp
();
}
//业务发起时刻
public
static
long
startT
;
public
static
void
doMapApp
()
{
for
(
slotnum
=
1
;
slotnum
<=
3
;
slotnum
++)
{
dev
=
num
*
slotnum
;
//10个卫星节点,3个时隙,则共有10*3个卫星节点
//组装最短路矩阵
double
[][]
matrixGraph
=
MatrixGraph
();
System
.
out
.
println
(
"大矩阵是:"
);
for
(
int
i
=
0
;
i
<
matrixGraph
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
matrixGraph
[
0
].
length
;
j
++)
{
System
.
out
.
print
(
matrixGraph
[
i
][
j
]+
" "
);
}
System
.
out
.
println
();
}
//最短路由矩阵
}
}
private
static
double
[][]
MatrixGraph
()
{
//获取当前3时隙拓扑
/**
* 先用SimpleDateFormat.parse() 方法将日期字符串转化为Date格式
* 通过Date.getTime()方法,将其转化为毫秒数
*/
String
date
=
"2019-01-01 00-00-00"
;
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH-mm-ss"
);
//24小时制
long
time
=
0
;
try
{
time
=
simpleDateFormat
.
parse
(
date
).
getTime
();
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
int
slotKey
=
(
int
)
((((
System
.
currentTimeMillis
()-
time
)/
20
/
1000
)-
1
)%
300
+
1
);
startT
=
((
System
.
currentTimeMillis
()-
time
)/
20000
+
1
)*
20000
;
HashMap
<
Integer
,
double
[][]>
cycleTp
=
cycleTpE
();
//获得第1个时隙的连接矩阵 0或1
double
[][]
currentTp
=
cycleTp
.
get
((
slotKey
)%
300
+
1
);
double
[][]
slot1
=
new
double
[
num
][
num
];
//10*10的矩阵图
for
(
int
i
=
0
;
i
<
slot1
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot1
[
0
].
length
;
j
++){
slot1
[
i
][
j
]
=
currentTp
[
i
][
j
];
}
}
/*for(int i = 0;i<slot1.length;i++){
for(int j = 0;j<slot1[0].length;j++){
if (currentTp[i][j]==0){
if (i==j){
slot1[i][j]=0;
}else
slot1[i][j] = 0;
}else{
slot1[i][j] = currentTp[i][j];
}
}
}*/
//获得第2个时隙的连接矩阵
currentTp
=
cycleTp
.
get
((
slotKey
)%
300
+
2
);
double
[][]
slot2
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
slot2
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot2
.
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot2
[
i
][
j
]=
0.0
;
}
else
slot2
[
i
][
j
]
=
0
;
}
else
{
slot2
[
i
][
j
]
=
currentTp
[
i
][
j
];
}
}
}
//获得第3个时隙的连接矩阵
currentTp
=
cycleTp
.
get
((
slotKey
)%
300
+
3
);
double
[][]
slot3
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
slot3
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
slot3
.
length
;
j
++){
if
(
currentTp
[
i
][
j
]==
0
){
if
(
i
==
j
){
slot3
[
i
][
j
]=
0.0
;
}
else
slot3
[
i
][
j
]
=
0
;
}
else
{
slot3
[
i
][
j
]
=
currentTp
[
i
][
j
];
}
}
}
//生成相邻时隙矩阵
double
[][]
neighbor
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
neighbor
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
neighbor
.
length
;
j
++){
if
(
i
==
j
){
neighbor
[
i
][
j
]
=
1
;
}
else
{
neighbor
[
i
][
j
]
=
0
;
}
}
}
//生成其余时隙矩阵
double
[][]
nonNeighbor
=
new
double
[
num
][
num
];
for
(
int
i
=
0
;
i
<
nonNeighbor
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
nonNeighbor
.
length
;
j
++){
nonNeighbor
[
i
][
j
]
=
0
;
}
}
//组装连接矩阵
double
[][]
edgeWeight
=
new
double
[
dev
][
dev
];
for
(
int
i
=
0
;
i
<
edgeWeight
.
length
;
i
++){
for
(
int
j
=
0
;
j
<
edgeWeight
[
0
].
length
;
j
++){
if
(
i
>=
0
&
i
<
num
&
j
>=
0
&
j
<
num
)
{
edgeWeight
[
i
][
j
]
=
slot1
[
i
][
j
];
}
else
if
(
i
>=
num
&
i
<
2
*
num
&
j
>=
num
&
j
<
2
*
num
)
{
edgeWeight
[
i
][
j
]
=
slot2
[
i
%
num
][
j
%
num
];
}
else
if
(
i
>=
2
*
num
&
i
<
3
*
num
&
j
>=
2
*
num
&
j
<
3
*
num
)
{
edgeWeight
[
i
][
j
]
=
slot3
[
i
%
num
][
j
%
num
];
}
else
if
((
i
>=
0
&
i
<
num
&
j
>=
num
&
j
<
2
*
num
)
||
(
i
>=
num
&
i
<
2
*
num
&
j
>=
2
*
num
&
j
<
3
*
num
)){
edgeWeight
[
i
][
j
]
=
neighbor
[
i
%
num
][
j
%
num
];
}
else
{
edgeWeight
[
i
][
j
]
=
nonNeighbor
[
i
%
num
][
j
%
num
];
}
}
}
return
edgeWeight
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment