Commit bedba911 authored by Hu Jintao's avatar Hu Jintao

csv功能

parent 75a1d0b1
package top.ninwoo.test.CsvMerge;
import top.ninwoo.test.doMap.DoMap;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Date;
public class GetTopo {
public static void main(String[] args){
String str;
String str1;
String str2;
//传输时间参数
str = ReadFile.date+" 5-00-00";
System.out.println(Arrays.deepToString(TopoRequire(str)));
//传输当前时间
Date current = new Date();
Date current1 = new Date(current.getTime()+ (long)DoMap.slot);
Date current2 = new Date(current1.getTime()+ (long)DoMap.slot);
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH-mm-ss");
str = sdf.format(current);
str1 = sdf.format(current1);
str2 = sdf.format(current2);
}
public static int[][] TopoRequire(String str) {
//网络信息表
NodeL[][] parse = ReadFile.parse();
LocalDate dateC = LocalDate.now();
ReadFile.date = dateC.getYear()+"-"+dateC.getMonthValue()+"-"+dateC.getDayOfMonth();
Long timeMillis= getTim(str);
int[][] topo = getTp(parse,timeMillis);
topo = reshape(topo);
// System.out.println(Arrays.deepToString(topo));
return topo;
}
private static int[][] reshape(int[][] topo) {
int[][] topos = new int[30][30];
for (int i =0;i<30;i++){
for (int j = 0;j<30;j++){
topos[i][j] = topo[i][j];
}
}
return topos;
}
public static Long getTim(String dateL){
long time = 0L;
SimpleDateFormat sDF = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
try {
time = sDF.parse(dateL).getTime();
} catch (ParseException e) {
e.printStackTrace();
}finally {
return time;
}
}
public static int[][] getTp(NodeL[][] parse,Long timeMillis) {
int high = parse.length;
int width = parse[0].length;
int[][] result = new int[high][width];
for (int i =0;i<high;i++){
for (int j = 0;j<width;j++){
NodeL tmp = parse[i][j];
while (tmp!=null){
if (tmp.start<=timeMillis && tmp.end>=timeMillis) {
result[i][j] = 1;
break;
}
tmp = tmp.next;
}
if (tmp==null) result[i][j]=0;
}
}
return result;
}
}
package top.ninwoo.test.CsvMerge;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Iterator;
public class ReadFile {
/*
* 拓扑连接信息存储于矩阵NodeLS,
*
* */
public static void main(String[] args){
LocalDate dateC = LocalDate.now();
date = dateC.getYear()+"-"+dateC.getMonthValue()+"-"+dateC.getDayOfMonth();
NodeL[][] parse = ReadFile.parse();
long timeMillis = System.currentTimeMillis();
System.out.print(timeMillis);
}
public static NodeL[][] parse(){
File csv = new File("leo72.csv");
// D:\LabratoryJavaPro\
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(csv));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String line = "";
String everyLine = "";
ArrayList<String> allString = new ArrayList<>();
//处理每行数据
try {
line=br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
while (line!=null){
everyLine = line;
String[] strings = everyLine.split(",");
for (String s: strings){
if (s.charAt(0)=='L'){
int count = 0;
StringBuffer str = new StringBuffer();
str.append('L');
for (int qq=1;qq<s.length();qq++){
if (s.charAt(qq)-'0'<10 && s.charAt(qq)-'0'>=0){
str.append(s.charAt(qq));
count++;
}
if (count==3) str.append(' ');
}
s = str.toString();
}
// System.out.println(s);
allString.add(s);
}
try {
line=br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
}
// System.out.println("csv表格中所有行数:"+allString.size());
//处理字符链表至矩阵链表
NodeL[][] nodeLS = new NodeL[6*12][6*12];
//定位矩阵索引位
Iterator<String> allSItr = allString.iterator();
//规避重复项
allSItr.next();
while (allSItr.hasNext()){
String next = allSItr.next();
//解析轨道行
if (next.charAt(0)=='L'){
//转化字符串为数字
String[] s = new String[2];
split(next,s);
//获取节点索引位置
int row = Integer.valueOf(s[0].substring(1));
int column = Integer.valueOf(s[1]);
//轨道面与节点编号转换公式
row = (row/100-1)*12+row%100-1;
column = (column/100-1)*12+column%100-1;
// 解析时间行
// 将读取数据转化为long型
NodeL tmp = null;
while (allSItr.hasNext()){
next = allSItr.next();
if (next.charAt(0)!='L'){
Long start = shift(next);
// System.out.println(start);
next = allSItr.next();
Long end = shift(next);
NodeL nodeL = new NodeL(start,end);
if (tmp ==null) nodeLS[row][column] = nodeL;
if (tmp!=null) tmp.next=nodeL;
tmp = nodeL;
}else break;
}
//显示赋值节点元素
/*System.out.print("拓扑第"+row+"行,第"+column+"列元素"+'\t');
NodeL show = nodeLS[row][column];
while (show!=null){
System.out.print("start="+show.start+" end="+show.end+'\t');
show = show.next;
}
System.out.println();*/
}
}
//填充链表
// System.out.println(nodeLS.);
return nodeLS;
}
private static void split(String next, String[] s) {
StringBuffer sbr = new StringBuffer(next);
int posi = 0;
int index = 0;
int start = 0;
for (;index<sbr.length();index++){
if (sbr.charAt(index)==' ')
{
s[posi++] = sbr.substring(start,index);
while (index<sbr.length() && sbr.charAt(index)==' ') index++;
start=index;
}
s[posi] = sbr.substring(start,index+1);
}
}
public static String date = "1970-1-2";
private static Long shift(String next) {
long time = 0L;
StringBuffer sbr = new StringBuffer(next);
for (int d= 0;d<sbr.length();d++){
if (sbr.charAt(d)==':') sbr.setCharAt(d,'-');
}
String dateL = date+" "+sbr;
SimpleDateFormat sDF = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
try {
time = sDF.parse(dateL).getTime();
} catch (ParseException e) {
e.printStackTrace();
}finally {
return time;
}
}
}
class NodeL{
public Long start;
public Long end;
public NodeL next = null;
public NodeL(Long start, Long end) {
this.start = start;
this.end = end;
}
}
\ No newline at end of file
package top.ninwoo.test.CsvMerge;
import top.ninwoo.test.doMap.DoMap;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import static top.ninwoo.test.CsvMerge.GetTopo.TopoRequire;
public class Wteg {
//获取当前3时隙拓扑
/**
* 先用SimpleDateFormat.parse() 方法将日期字符串转化为Date格式
* 通过Date.getTime()方法,将其转化为毫秒数
*/
public static double[][] getWteg() {
//传输时间参数
String str;
String str1;
String str2;
//测试时间
str = ReadFile.date+" 5-00-00";
int[][] topo = TopoRequire(str);
str1 = ReadFile.date+" 5-00-20";
int[][] topo1 = TopoRequire(str1);
str2 = ReadFile.date+" 5-00-40";
int[][] topo2 = TopoRequire(str2);
//动态获取当前时间topo
/* Date current = new Date();
Date current1 = new Date(current.getTime()+ (long)DoMap.slot);
Date current2 = new Date(current1.getTime()+ (long)DoMap.slot);
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH-mm-ss");
str = sdf.format(current);
str1 = sdf.format(current1);
str2 = sdf.format(current2);
int[][] topo = TopoRequire(str);
int[][] topo1 = TopoRequire(str1);
int[][] topo2 = TopoRequire(str2);*/
//获得单时隙连接矩阵 0或MAXWEIGHT
//等待下一时隙开始执行业务
int num = DoMap.num;
int MAXWEIGHT = DoMap.MAXWEIGHT;
double slot = DoMap.slot;
int dev = DoMap.dev;
double[][] slot1 = new double[num][num];
for(int i = 0;i<slot1.length;i++){
for(int j = 0;j<slot1.length;j++){
if (topo[i][j]==0){
if (i==j){
slot1[i][j]=0.0;
}else
slot1[i][j] = MAXWEIGHT;
}else{
slot1[i][j] = 500;
}
}
}
double[][] slot2 = new double[num][num];
for(int i = 0;i<slot2.length;i++){
for(int j = 0;j<slot2.length;j++){
if (topo1[i][j]==0){
if (i==j){
slot2[i][j]=0.0;
}else
slot2[i][j] = MAXWEIGHT;
}else {
slot2[i][j] = 500;
}
}
}
double[][] slot3 = new double[num][num];
for(int i = 0;i<slot3.length;i++){
for(int j = 0;j<slot3.length;j++){
if (topo2[i][j]==0){
if (i==j){
slot3[i][j]=0.0;
}else
slot3[i][j] = MAXWEIGHT;
}else {
slot3[i][j] = 500;
}
}
}
//生成相邻时隙矩阵
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;
}
}
package top.ninwoo.test.doMap;
import top.ninwoo.test.CsvMerge.Wteg;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -17,7 +19,7 @@ public class DoMap {
//最大权值
static final int MAXWEIGHT = 10000*1000;
public static final int MAXWEIGHT = 10000*1000;
/*
* 业务参数
......@@ -44,7 +46,7 @@ public class DoMap {
* 网络参数
*/
//设备数
static int num = 30;
public static int num = 30;
//设备计算能力参数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, 0.6924037701405794,
......@@ -52,11 +54,11 @@ public class DoMap {
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;
public static double slot = 20*1000;
//时隙数目
static int slotnum;
//网络节点数
static int dev;
public static int dev;
//初始化时延偏移量
//这里需要一个时钟输入
static double testLatency = 0;
......@@ -109,7 +111,14 @@ public class DoMap {
dev = num*slotnum;
n2 = dev - N_STABLE*slotnum;
//1组装最短路矩阵
double[][] edgeWeight = WTEG();
// double[][] edgeWeight = WTEG();
double[][] edgeWeight = Wteg.getWteg();
//最短路由矩阵
/*System.out.println("DoMap直连边权重");
System.out.println(Arrays.deepToString(edgeWeight));*/
......@@ -156,22 +165,22 @@ public class DoMap {
}
//3根据分配结果,回溯每一条路由
lastHop = pathRecord.lastHop;
for (int i = 0;i<link[0].length;i++){
int start = best_par.taskfinal[link[0][i]];
int end = best_par.taskfinal[link[1][i]];
while(lastHop[start][end] != 0){
/*if (lastHop[start][end] == start){
}else if(lastHop[start][end] == end){
route[i+1].push((lastHop[start][end])+1);
break;
}else{*/
route[i+1].push((lastHop[start][end])+1);
//route[i+1].push((lastHop[start][end]%num)+1);
end = lastHop[start][end];
}
}
// for (int i = 0;i<link[0].length;i++){
// int start = best_par.taskfinal[link[0][i]];
// int end = best_par.taskfinal[link[1][i]];
// while(lastHop[start][end] != 0){
// if (lastHop[start][end] == start){
//
// }else if(lastHop[start][end] == end){
// route[i+1].push((lastHop[start][end])+1);
// break;
// }else{
// route[i+1].push((lastHop[start][end])+1);
// //route[i+1].push((lastHop[start][end]%num)+1);
//
// end = lastHop[start][end];
// }
// }
/* System.out.println("--------------------------");
System.out.println("shortest route : ");*/
//输出最短路由[1, 2, 3, 3, 9, 16, 40]
......@@ -624,7 +633,7 @@ public class DoMap {
max_trans = Math.max(max_trans, transv);
}
}
compu[i] = nt[par.taskfinal[i]%num]*D[i];
compu[i] = D[i]/nt[par.taskfinal[i]%num];
accu[i] = compu[i] + max_trans;
//modify
if(accu[i] > (par.taskfinal[i]/num + 1)*slot) {
......
......@@ -119,6 +119,11 @@ public class Application implements ApplicationRunner {
//转发
newDataPackage.setPicture(picPara.removeFirst());
transferService.transferPackage(newDataPackage, newDataPackage.getNextSataHop(), time);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// }
} else {//仅作转发的节点
......
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