Commit b65532d4 authored by jthu's avatar jthu

重新添加路径计算module群 更新

parent c764f986
...@@ -36,4 +36,12 @@ public class CnfData implements Serializable { ...@@ -36,4 +36,12 @@ public class CnfData implements Serializable {
private String endSateHop; private String endSateHop;
//源节点 //源节点
private String oriSateHop; private String oriSateHop;
//任务发起时刻
private long time;
//时隙大小
private long gap = 20000;
//卫星数目
private int sataNum = 10;
//阈值设定
private double size;
} }
...@@ -18,11 +18,19 @@ ...@@ -18,11 +18,19 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId> <artifactId>spring-boot-autoconfigure</artifactId>
<version>2.3.7.RELEASE</version> <version>2.1.1.RELEASE</version>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
...@@ -34,6 +42,10 @@ ...@@ -34,6 +42,10 @@
<version>1.3.2</version> <version>1.3.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>top.ninwoo</groupId>
<artifactId>cnf-client-starter</artifactId>
</dependency>
</dependencies> </dependencies>
......
package top.ninwoo.cloud.config;
import lombok.Data;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "bps")
@Component
@Data
@ToString
public class BpsoConfig {
//
public String n;
//
public String k;
}
package top.ninwoo.cloud.config; package top.ninwoo.cloud.config;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@Configuration //@Configuration
public class RestConfig { public class RestConfig {
private ApplicationContext applicationContext = null; private ApplicationContext applicationContext = null;
@Bean // @Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory) { public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
return new RestTemplate(factory); return new RestTemplate(factory);
} }
@Bean // @Bean
ClientHttpRequestFactory simpleClientHttpRequestFactory() { ClientHttpRequestFactory simpleClientHttpRequestFactory() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setReadTimeout(20000); factory.setReadTimeout(20000);
......
...@@ -2,6 +2,7 @@ package top.ninwoo.cloud.controller; ...@@ -2,6 +2,7 @@ package top.ninwoo.cloud.controller;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -15,6 +16,8 @@ import javax.annotation.Resource; ...@@ -15,6 +16,8 @@ import javax.annotation.Resource;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.io.*; import java.io.*;
import java.text.ParseException; import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -27,53 +30,84 @@ public class DataCtrl { ...@@ -27,53 +30,84 @@ public class DataCtrl {
@Autowired @Autowired
DbcTrans dbcTrans; DbcTrans dbcTrans;
private long starTime;
@Resource @Resource
private RestTemplate restTemplate; private RestTemplate restTemplate;
@RequestMapping(value = "/cpcTrans",method = RequestMethod.GET) @RequestMapping(value = "/cpcTrans",method = RequestMethod.GET)
public String upload() { public String Cpcupload() {
return "cpcTrans"; return "cpcTrans";
} }
@RequestMapping(value = "/cpcTrans") @RequestMapping(value = "/cpcTrans")
@ResponseBody @ResponseBody
public String CpcTrans(@RequestParam("file") MultipartFile file, @RequestParam("fileId") String fileId) { public String CpcTrans(@RequestParam("file") MultipartFile file, @RequestParam("path_1") String path_1,@RequestParam("path_2") String path_2,@RequestParam("func") String fun) {
if(!file.isEmpty()){ if(!file.isEmpty()){
try { try {
//包装图片 //包装图片
Picture picture = cpcTrans.packagePic(ImageIO.read(file.getInputStream()), fileId); Picture picture = cpcTrans.packagePic(ImageIO.read(file.getInputStream()));
//包装数据包 //包装数据包
LinkedList<CnfData> cnfData = cpcTrans.packageData(picture); //得到链路图
int length = path_2.length();
int func_length = fun.length();
int[] func = new int[func_length];
int[][] link = new int[2][length];
for(int i=0; i<length; i++) {
link[0][i] = path_1.charAt(i) - '0';
}
for(int i=0; i<length; i++) {
link[1][i] = path_2.charAt(i) - '0';
}
for(int i=0; i<length; i++) {
func[i] = fun.charAt(i) - '0';
}
LinkedList<CnfData> cnfData = cpcTrans.packageData(picture,link,func);
//发送 //发送
for (CnfData data : cnfData) { for (CnfData data : cnfData) {
cpcTrans.sendData(data, data.getNextIPHop()); cpcTrans.sendData(data, data.getNextIPHop());
} }
} catch (FileNotFoundException e) {
e.printStackTrace();
return "上传失败," + e.getMessage();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return "上传失败," + e.getMessage(); return "上传失败," + e.getMessage();
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
return "上传成功!"; return "上传成功!";
} else { } else {
return "上传失败,因为文件是空的."; return "上传失败,因为文件是空的.";
} }
} }
@RequestMapping(value = "/dbcTrans",method = RequestMethod.GET)
public String Dbcupload() {
return "dbcTrans";
}
@PostMapping(value = "/dbcTrans") @PostMapping(value = "/dbcTrans")
@ResponseBody @ResponseBody
public String DbcTrans(@RequestParam("file") MultipartFile file, @RequestParam("fileId") String fileId) { public String DbcTrans(@RequestParam("file") MultipartFile file, @RequestParam("fileId") String fileId, @RequestParam("size") double size) {
if(!file.isEmpty()){ if(!file.isEmpty()){
try { try {
Date time = new Date();
starTime = time.getTime();
System.out.println("开始分散计算: " + starTime);
//包装图片 //包装图片
Picture picture = dbcTrans.packagePic(ImageIO.read(file.getInputStream()), fileId); Picture picture = dbcTrans.packagePic(ImageIO.read(file.getInputStream()));
//包装数据包 //包装数据包
LinkedList<CnfData> cnfData = dbcTrans.packageData(picture); LinkedList<CnfData> cnfData = dbcTrans.packageData(picture,"sate1");
//发送 //发送
for (CnfData data : cnfData) { for (CnfData data : cnfData) {
data.setTime(starTime);
data.setSize(size);
System.out.println(data.getGap());
dbcTrans.sendData(data, data.getNextIPHop()); dbcTrans.sendData(data, data.getNextIPHop());
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
...@@ -91,9 +125,19 @@ public class DataCtrl { ...@@ -91,9 +125,19 @@ public class DataCtrl {
} }
} }
@GetMapping(value = "/getImg") @RequestMapping(value = "/cpcDownload",method = RequestMethod.GET)
public String Cpcdownload(Model model) {
GetCpcImg();
model.addAttribute("fileName", "cpc_images/sate11-0.jpg");
return "cpcDownload";
}
@GetMapping(value = "/getcpcImg")
@ResponseBody @ResponseBody
public String GetAllImg(){ public String GetCpcImg(){
FindServiceImpl findService = new FindServiceImpl(); FindServiceImpl findService = new FindServiceImpl();
ConcurrentHashMap<String, String> ipool = findService.findIPool(); ConcurrentHashMap<String, String> ipool = findService.findIPool();
for (int i = 1; i < ipool.size()+1; i++) { for (int i = 1; i < ipool.size()+1; i++) {
...@@ -101,12 +145,29 @@ public class DataCtrl { ...@@ -101,12 +145,29 @@ public class DataCtrl {
System.out.println(str); System.out.println(str);
String ip = ipool.get(str); String ip = ipool.get(str);
System.out.println(ip); System.out.println(ip);
GetImg(str,ip); String path = "/var/www/html/cpc_images/";
GetImg(str,ip,path);
} }
return "sucess"; return "sucess";
} }
public void GetImg(String sataname, String ip){ @GetMapping(value = "/getdbcImg")
@ResponseBody
public String GetDbcImg(){
FindServiceImpl findService = new FindServiceImpl();
ConcurrentHashMap<String, String> ipool = findService.findIPool();
for (int i = 1; i < ipool.size()+1; i++) {
String str = "sate"+i;
System.out.println(str);
String ip = ipool.get(str);
System.out.println(ip);
String path = "/var/www/html/dbc_images/";
GetImg(str,ip,path);
}
return "sucess";
}
public void GetImg(String sataname, String ip, String foldPath){
String IP =ip + ":8083"; String IP =ip + ":8083";
byte[][] res = restTemplate.getForObject("http://" + IP +"/getImg",byte[][].class); byte[][] res = restTemplate.getForObject("http://" + IP +"/getImg",byte[][].class);
if(res == null){ if(res == null){
...@@ -119,7 +180,7 @@ public class DataCtrl { ...@@ -119,7 +180,7 @@ public class DataCtrl {
int i = 0; int i = 0;
for (byte[] re : res) { for (byte[] re : res) {
//得到新路径 //得到新路径
String path = "/home/dell/show/public/assets/cpc_images/"+sataname+"-"+i+".jpg"; String path = foldPath+sataname+"-"+i+".jpg";
outputStream = new FileOutputStream(path); outputStream = new FileOutputStream(path);
//将图片输处到流中 //将图片输处到流中
outputStream.write(re); outputStream.write(re);
...@@ -158,50 +219,88 @@ public class DataCtrl { ...@@ -158,50 +219,88 @@ public class DataCtrl {
return cpuCom; return cpuCom;
} }
//获取计算能力 //卫星复位
@GetMapping("/download") @GetMapping("/reset")
@ResponseBody @ResponseBody
public String download() { public String resetSate(){
return null; FindServiceImpl findService = new FindServiceImpl();
ConcurrentHashMap<String, String> ipool = findService.findIPool();
for (int i = 1; i < ipool.size(); i++) {
String str = "sate"+i;
String ip = ipool.get(str);
String res = dbcTrans.reset(ip);
System.out.println(str+"复位:"+res);
}
return "sucess";
}
//收到图片时的时间
@PostMapping(value = "/getDate")
@ResponseBody
public String getDate(@RequestParam("message") String message) {
System.out.println("返回收到信息:" + message);
Date time = new Date();
System.out.println("时间间隔:" + (time.getTime() - starTime));
return "backEarth sucess";
}
//收到图片时的时间
@PostMapping(value = "/getOverLoad")
@ResponseBody
public boolean getOverload(@RequestBody HashMap<String, String> param) {
System.out.println("================================");
System.out.println(param.get("sName")+" :"+param.get("overLoad"));
System.out.println("================================");
return true;
} }
@GetMapping("/testCpc") @GetMapping("/testCpc")
@ResponseBody @ResponseBody
public String CpcTest() throws ParseException, IOException { public String CpcTest() throws IOException {
File file = new File("C:\\Users\\Elf\\Desktop\\test\\2.jpg"); File file = new File("C:\\Users\\Elf\\Desktop\\test\\2.jpg");
Picture picture = cpcTrans.packagePic(ImageIO.read(file), "123"); Picture picture = cpcTrans.packagePic(ImageIO.read(file));
//包装数据包 //包装数据包
LinkedList<CnfData> cnfData = cpcTrans.packageData(picture); //LinkedList<CnfData> cnfData = cpcTrans.packageData(picture,null);
return cpcTrans.sendData(cnfData.get(0),cnfData.get(0).getNextIPHop()); //return cpcTrans.sendData(cnfData.get(0),cnfData.get(0).getNextIPHop());
return null;
} }
@GetMapping("/testDbc") @GetMapping("/testDbc")
@ResponseBody @ResponseBody
public CnfData DbcTest() throws IOException, ParseException { public CnfData DbcTest() throws IOException, ParseException {
File file = new File("C:\\Users\\Elf\\Desktop\\test\\2.jpg"); File file = new File("/home/elf/test3.jpg");
Picture picture = dbcTrans.packagePic(ImageIO.read(file), "123"); Picture picture = dbcTrans.packagePic(ImageIO.read(file));
LinkedList<CnfData> cnfData = dbcTrans.packageData(picture, "sate3"); LinkedList<CnfData> cnfData = dbcTrans.packageData(picture, "sate1");
return cnfData.get(0); return cnfData.get(0);
} }
@GetMapping("/test") @GetMapping("/test")
@ResponseBody @ResponseBody
public CnfData Test1() throws ParseException, IOException { public CnfData Test1() throws IOException {
File file = new File("C:\\Users\\Elf\\Desktop\\test\\1.jpg"); File file = new File("C:\\Users\\Elf\\Desktop\\test\\1.jpg");
Picture picture = cpcTrans.packagePic(ImageIO.read(file), "123"); Picture picture = cpcTrans.packagePic(ImageIO.read(file));
//包装数据包 //包装数据包
LinkedList<CnfData> cnfData = cpcTrans.packageData(picture); //LinkedList<CnfData> cnfData = cpcTrans.packageData(picture);
//String res = cpcTrans.sendData(cnfData.get(0),"127.0.0.1"); //String res = cpcTrans.sendData(cnfData.get(0),"127.0.0.1");
return cnfData.get(0); //return cnfData.get(0);
return null;
} }
@GetMapping("/testlt") @GetMapping("/testlt")
@ResponseBody @ResponseBody
public String[][] LtTest() throws IOException, ParseException { public String[][] LtTest() throws IOException, ParseException {
File file = new File("C:\\Users\\Elf\\Desktop\\test\\2.jpg"); File file = new File("C:\\Users\\Elf\\Desktop\\test\\2.jpg");
Picture picture = dbcTrans.packagePic(ImageIO.read(file), "123"); Picture picture = dbcTrans.packagePic(ImageIO.read(file));
System.out.println(dbcTrans.getIt().length);
return dbcTrans.getIt(); return dbcTrans.getIt();
} }
@GetMapping("/testDbc2")
@ResponseBody
public CnfData DbcTest2() throws IOException, ParseException {
File file = new File("C:\\Users\\Elf\\Desktop\\test\\2.jpg");
Picture picture = dbcTrans.packagePic(ImageIO.read(file));
LinkedList<CnfData> cnfData = dbcTrans.packageData(picture, "sate1");
return cnfData.get(0);
}
} }
package top.ninwoo.cloud.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.ninwoo.bishe.starter.service.NetworkService;
import java.util.List;
@Service
public class IPService {
@Autowired
private NetworkService networkService;
public String getIpByAppName(String appName) {
List<String> ipList = networkService.getIpListByAppName(11111l, appName);
if(!ipList.isEmpty()){
String ip_tmp = ipList.get(0);
String[] split_list = ip_tmp.split("/");
return split_list[0];
}
return null;
}
}
...@@ -12,11 +12,11 @@ public interface TransService { ...@@ -12,11 +12,11 @@ public interface TransService {
* 打包picture * 打包picture
* @return picture列表 * @return picture列表
*/ */
Picture packagePic(BufferedImage bufferedImage, String fileId); Picture packagePic(BufferedImage bufferedImage);
/** /**
*打包成数据包 *打包成数据包
*/ */
LinkedList<CnfData> packageData(Picture picture) throws ParseException; LinkedList<CnfData> packageData(Picture picture,int[][] link,int[] func) throws ParseException;
LinkedList<CnfData> packageData(Picture picture, String satename) throws ParseException; LinkedList<CnfData> packageData(Picture picture, String satename) throws ParseException;
/** /**
...@@ -31,5 +31,8 @@ public interface TransService { ...@@ -31,5 +31,8 @@ public interface TransService {
* 得到稳态图 * 得到稳态图
*/ */
String[][] getIt() throws ParseException; String[][] getIt() throws ParseException;
} /**
* 卫星复位
*/
String reset(String url);
}
\ No newline at end of file
package top.ninwoo.cloud.service.bpso; package top.ninwoo.cloud.service.bpso;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.ninwoo.cloud.config.BpsoConfig;
import top.ninwoo.cloud.service.csv.Wteg; import top.ninwoo.cloud.service.csv.Wteg;
import java.text.ParseException; import java.text.ParseException;
...@@ -13,7 +16,11 @@ import java.util.Stack; ...@@ -13,7 +16,11 @@ import java.util.Stack;
* 目前只允许计算过程跨单时隙 * 目前只允许计算过程跨单时隙
* @jthu * @jthu
*/ */
@Component
@Slf4j
public class Bpso { public class Bpso {
//最大权值 //最大权值
public static final int MAXWEIGHT = 10000*1000; public static final int MAXWEIGHT = 10000*1000;
...@@ -66,9 +73,9 @@ public class Bpso { ...@@ -66,9 +73,9 @@ public class Bpso {
* BPSO参数 * BPSO参数
*/ */
//粒子群规模 //粒子群规模
static int n = 1000; static int n;
//种群迭代次数 //种群迭代次数
static int k = 500; static int k;
//惯性权重,加速因子1,2 //惯性权重,加速因子1,2
static double s = 1.5; static int c1 = 1; static int c2 = 1; static double s = 1.5; static int c1 = 1; static int c2 = 1;
...@@ -77,7 +84,8 @@ public class Bpso { ...@@ -77,7 +84,8 @@ public class Bpso {
int[][] link = {{0, 1, 1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6, 6, 7}}; int[][] link = {{0, 1, 1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6, 6, 7}};
//task编号 //task编号
int[] func = {0, 2, 3, 3, 1, 1, 4, 0}; int[] func = {0, 2, 3, 3, 1, 1, 4, 0};
doMapApp(link,func); Bpso doMap = new Bpso();
// doMap.doMapApp(link,func);
} }
...@@ -92,14 +100,16 @@ public class Bpso { ...@@ -92,14 +100,16 @@ public class Bpso {
//路由表 //路由表
public static int[][] lastHop; public static int[][] lastHop;
public static void doMapApp(int[][] link1, int[] func1) throws ParseException { public void doMapApp(int[][] link1, int[] func1,BpsoConfig bpsoConfig) throws ParseException {
k = Integer.parseInt(bpsoConfig.getK());
n = Integer.parseInt(bpsoConfig.getN());
link = link1; link = link1;
func = func1; func = func1;
route = new Stack[link[0].length+1]; route = new Stack[link[0].length+1];
for (slotnum = 2;slotnum<=3;slotnum++){ for (slotnum = 1;slotnum<=3;slotnum++){
//slotnum = 3; //slotnum = 3;
dev = num*slotnum; dev = num*slotnum;
n2 = dev - N_STABLE*slotnum; n2 = dev - N_STABLE*slotnum;
...@@ -140,7 +150,8 @@ public class Bpso { ...@@ -140,7 +150,8 @@ public class Bpso {
//执行粒子群算法,得路径计算结果 //执行粒子群算法,得路径计算结果
Bpso doMap = new Bpso(); Bpso doMap = new Bpso();
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 ((1/best_par.fit) != 0){
log.info("规划最短时延:"+(1/best_par.fit));
//赋值节点映射结果 //赋值节点映射结果
int itemp = 0; int itemp = 0;
for (int a:best_par.taskfinal for (int a:best_par.taskfinal
...@@ -204,6 +215,7 @@ public class Bpso { ...@@ -204,6 +215,7 @@ public class Bpso {
Par best_par = new Par(nn, c); Par best_par = new Par(nn, c);
Par[] par_array = new Par[n]; Par[] par_array = new Par[n];
Par [] temp = new Par[2]; //存放返回值 Par [] temp = new Par[2]; //存放返回值
for (int i = 0; i < par_array.length; i++) { for (int i = 0; i < par_array.length; i++) {
par_array[i] = new Par(nn, c); par_array[i] = new Par(nn, c);
initialize(par_array[i],n1,n2, c, dev, num, mapdev); initialize(par_array[i],n1,n2, c, dev, num, mapdev);
......
package top.ninwoo.cloud.service.cpcTrans; package top.ninwoo.cloud.service.cpcTrans;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import top.ninwoo.api.CnfData; import top.ninwoo.api.CnfData;
import top.ninwoo.api.Picture; import top.ninwoo.api.Picture;
import top.ninwoo.cloud.config.BpsoConfig;
import top.ninwoo.cloud.service.IPService;
import top.ninwoo.cloud.service.TransService; import top.ninwoo.cloud.service.TransService;
import top.ninwoo.cloud.service.bpso.Bpso; import top.ninwoo.cloud.service.bpso.Bpso;
import top.ninwoo.cloud.service.findService.FindServiceImpl; import top.ninwoo.cloud.service.findService.FindServiceImpl;
...@@ -23,18 +27,25 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -23,18 +27,25 @@ import java.util.concurrent.ConcurrentHashMap;
import static top.ninwoo.cloud.service.bpso.Bpso.lastHop; import static top.ninwoo.cloud.service.bpso.Bpso.lastHop;
@Slf4j
@Service @Service
public class CpcTrans implements TransService { public class CpcTrans implements TransService {
@Resource @Resource
private RestTemplate restTemplate; private RestTemplate restTemplate;
@Autowired
private BpsoConfig bpsoConfig;
@Autowired
private IPService ipService;
/** /**
* 打包picture * 打包picture
* *
* @return picture列表 * @return picture列表
*/ */
@Override @Override
public Picture packagePic(BufferedImage bufferedImage, String fileId){ public Picture packagePic(BufferedImage bufferedImage){
Picture picture = new Picture(); Picture picture = new Picture();
//转化为byte[]数组 //转化为byte[]数组
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
...@@ -47,7 +58,7 @@ public class CpcTrans implements TransService { ...@@ -47,7 +58,7 @@ public class CpcTrans implements TransService {
//设置图片数据 //设置图片数据
picture.setData(out.toByteArray()); picture.setData(out.toByteArray());
//设置文件名 //设置文件名
picture.setPicId(fileId); picture.setPicId("123");
return picture; return picture;
} }
...@@ -55,7 +66,7 @@ public class CpcTrans implements TransService { ...@@ -55,7 +66,7 @@ public class CpcTrans implements TransService {
* 打包成数据包 * 打包成数据包
*/ */
@Override @Override
public LinkedList<CnfData> packageData(Picture picture) throws ParseException { public LinkedList<CnfData> packageData(Picture picture, int[][] link,int[] func) throws ParseException {
LinkedList<CnfData> cnfDatas = new LinkedList<>(); LinkedList<CnfData> cnfDatas = new LinkedList<>();
FindServiceImpl findService = new FindServiceImpl(); FindServiceImpl findService = new FindServiceImpl();
//判断npe //判断npe
...@@ -66,17 +77,18 @@ public class CpcTrans implements TransService { ...@@ -66,17 +77,18 @@ public class CpcTrans implements TransService {
// 输入: // 输入:
//子任务依赖关系 边 //子任务依赖关系 边
int[][] link = {{0, 1, 1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6, 6, 7}}; //int[][] link = {{0, 1, 1, 2, 3, 4, 5, 6}, {1, 2, 3, 4, 5, 6, 6, 7}};
//task编号 //task编号
int[] func = {0, 2, 3, 3, 1, 1, 4, 0}; //int[] func = {0, 2, 3, 3, 1, 1, 4, 0};
//任务表 //任务表
String[] tasks = {"start/end","binaryProcess", "cutProcess", "greyProcess", "mergeProcess", "tailorProcess"}; String[] tasks = {"start/end","binaryProcess", "cutProcess", "greyProcess", "mergeProcess", "distributeProcess"};
Bpso doMap = new Bpso(); Bpso doMap = new Bpso();
doMap.doMapApp(link,func); doMap.doMapApp(link,func,bpsoConfig);
//映射结果 //映射结果
int[] result = doMap.result; int[] result = doMap.result;
System.out.println("optimal mapping scheme"+ Arrays.toString(result)); System.out.println("optimal mapping scheme"+ Arrays.toString(result));
log.info("optimal mapping scheme"+ Arrays.toString(result));
//路径表 //路径表
String[] path = new String[link[0].length]; String[] path = new String[link[0].length];
...@@ -96,6 +108,7 @@ public class CpcTrans implements TransService { ...@@ -96,6 +108,7 @@ public class CpcTrans implements TransService {
//左为边起点,右为边终点 //左为边起点,右为边终点
path[tm] = startHop+"->"+endHop; path[tm] = startHop+"->"+endHop;
} }
log.info("任务规划结果:"+Arrays.toString(path));
//任务表 //任务表
ConcurrentHashMap<String,String> taskTable = new ConcurrentHashMap(); ConcurrentHashMap<String,String> taskTable = new ConcurrentHashMap();
...@@ -113,6 +126,8 @@ public class CpcTrans implements TransService { ...@@ -113,6 +126,8 @@ public class CpcTrans implements TransService {
} }
taskTable.put(hop,tasks[func[tm]]); taskTable.put(hop,tasks[func[tm]]);
} }
log.info("子任务功能执行卫星列表:"+taskTable.toString());
//T3路由表 //T3路由表
String[][] route = new String[lastHop.length][lastHop[0].length]; String[][] route = new String[lastHop.length][lastHop[0].length];
for(int i =0;i<lastHop.length;i++){ for(int i =0;i<lastHop.length;i++){
...@@ -131,21 +146,24 @@ public class CpcTrans implements TransService { ...@@ -131,21 +146,24 @@ public class CpcTrans implements TransService {
} }
} }
} }
boolean flad = false; log.info("跨时隙路由表:"+Arrays.deepToString(route));
boolean flag = false;
// 防止形成自环,比如route[1][2] = sate1 那么发往sate2的数据包将永远在sate1自环
for(int i =0;i<lastHop.length;i++){ for(int i =0;i<lastHop.length;i++){
for (int j=0;j<lastHop[0].length;j++){ for (int j=0;j<lastHop[0].length;j++){
if (route[i][j].equals("sate"+(i)) && i!=j){ if (route[i][j].equals("sate"+(i)) && i!=j){
flad = true; flag = true;
} }
} }
} }
if (flad==false){ if (flag==false){
System.out.println("correct"); System.out.println("correct");
} }
CnfData dataPackage = new CnfData(); CnfData dataPackage = new CnfData();
ConcurrentHashMap<String,String> ipool = findService.findIPool(); // ConcurrentHashMap<String,String> ipool = findService.findIPool();
dataPackage.setIpPool(ipool); // dataPackage.setIpPool(ipool);
//路径表 //路径表
dataPackage.setPathTable(path); dataPackage.setPathTable(path);
...@@ -156,7 +174,7 @@ public class CpcTrans implements TransService { ...@@ -156,7 +174,7 @@ public class CpcTrans implements TransService {
//图片 //图片
dataPackage.setPicture(picture); dataPackage.setPicture(picture);
//ip池 //ip池
dataPackage.setIpPool(findService.findIPool()); // dataPackage.setIpPool(findService.findIPool());
String[] routeself = findService.findRoute(dataPackage.getCurrentSataHop(), dataPackage.getRoute()); String[] routeself = findService.findRoute(dataPackage.getCurrentSataHop(), dataPackage.getRoute());
ArrayList<String> destinSataHops = findService.findDestinSataHops(path,"D1"); ArrayList<String> destinSataHops = findService.findDestinSataHops(path,"D1");
for(String des : destinSataHops) { for(String des : destinSataHops) {
...@@ -168,7 +186,9 @@ public class CpcTrans implements TransService { ...@@ -168,7 +186,9 @@ public class CpcTrans implements TransService {
//下一跳 //下一跳
transferPackage.setCurrentSataHop(transferPackage.getNextSataHop()); transferPackage.setCurrentSataHop(transferPackage.getNextSataHop());
//ip //ip
transferPackage.setNextIPHop(findService.findIp(transferPackage.getNextSataHop(),transferPackage.getIpPool())); String ip = ipService.getIpByAppName(transferPackage.getNextSataHop());
transferPackage.setNextIPHop(ip);
// transferPackage.setNextIPHop(findService.findIp(transferPackage.getNextSataHop(),transferPackage.getIpPool()));
//终止节点 //终止节点
transferPackage.setEndSateHop("sate11"); transferPackage.setEndSateHop("sate11");
//返回一个数据包 //返回一个数据包
...@@ -190,8 +210,6 @@ public class CpcTrans implements TransService { ...@@ -190,8 +210,6 @@ public class CpcTrans implements TransService {
*/ */
@Override @Override
public String sendData(CnfData cnfData, String url) { public String sendData(CnfData cnfData, String url) {
/*Map<String, Object> param = new HashMap<>();
param.put("cnfData ", cnfData);*/
String IP = url + ":8083"; String IP = url + ":8083";
ResponseEntity<String> res = restTemplate.postForEntity("http://" + IP + "/transfer", cnfData, String.class); ResponseEntity<String> res = restTemplate.postForEntity("http://" + IP + "/transfer", cnfData, String.class);
if (!res.getStatusCode().is2xxSuccessful()) { if (!res.getStatusCode().is2xxSuccessful()) {
...@@ -228,5 +246,14 @@ public class CpcTrans implements TransService { ...@@ -228,5 +246,14 @@ public class CpcTrans implements TransService {
if (set.size()==result.length) return false; if (set.size()==result.length) return false;
else return true; else return true;
} }
}
@Override
public String reset(String url) {
String IP = url + ":8083";
ResponseEntity<String> res = restTemplate.getForEntity("http://" + IP + "/reset", String.class);
if (!res.getStatusCode().is2xxSuccessful()) {
throw new RuntimeException("send Error!");
}
return "sucess";
}
}
...@@ -18,7 +18,7 @@ public class ReadFile { ...@@ -18,7 +18,7 @@ public class ReadFile {
public static NodeL[][] parse(){ public static NodeL[][] parse(){
File csv = new File("C:\\Users\\Elf\\Desktop\\test\\leo60.csv"); File csv = new File("leo60.csv");
// D:\LabratoryJavaPro\ // D:\LabratoryJavaPro\
BufferedReader br = null; BufferedReader br = null;
try { try {
......
...@@ -33,7 +33,7 @@ public class DbcTrans implements TransService { ...@@ -33,7 +33,7 @@ public class DbcTrans implements TransService {
* @return picture列表 * @return picture列表
*/ */
@Override @Override
public Picture packagePic(BufferedImage bufferedImage, String fileId) { public Picture packagePic(BufferedImage bufferedImage) {
Picture picture = new Picture(); Picture picture = new Picture();
//转化为byte[]数组 //转化为byte[]数组
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
...@@ -45,7 +45,7 @@ public class DbcTrans implements TransService { ...@@ -45,7 +45,7 @@ public class DbcTrans implements TransService {
//设置图片数据 //设置图片数据
picture.setData(out.toByteArray()); picture.setData(out.toByteArray());
//设置文件名 //设置文件名
picture.setPicId(fileId); picture.setPicId("123");
return picture; return picture;
} }
...@@ -55,7 +55,7 @@ public class DbcTrans implements TransService { ...@@ -55,7 +55,7 @@ public class DbcTrans implements TransService {
* @param picture * @param picture
*/ */
@Override @Override
public LinkedList<CnfData> packageData(Picture picture) throws ParseException { public LinkedList<CnfData> packageData(Picture picture, int[][] link,int[] func) throws ParseException {
return null; return null;
} }
...@@ -88,6 +88,15 @@ public class DbcTrans implements TransService { ...@@ -88,6 +88,15 @@ public class DbcTrans implements TransService {
double[][] lt = pathRecord.getPathWeight(); double[][] lt = pathRecord.getPathWeight();
//最短路由矩阵 //最短路由矩阵
int[][] lastHop = pathRecord.getLastHop(); int[][] lastHop = pathRecord.getLastHop();
for (int j = 0;j<lastHop.length;j++){
for(int i = 0;i<lastHop.length;i++){
int tmp0 = lastHop[j][i];
while (tmp0 != 0){
lastHop[j][i] = tmp0;
tmp0 = lastHop[j][tmp0];
}
}
}
//路径表 //路径表
String[] path = new String[1]; String[] path = new String[1];
...@@ -97,30 +106,33 @@ public class DbcTrans implements TransService { ...@@ -97,30 +106,33 @@ public class DbcTrans implements TransService {
ConcurrentHashMap<String,String> taskTable = new ConcurrentHashMap(); ConcurrentHashMap<String,String> taskTable = new ConcurrentHashMap();
taskTable.put(satename,"distributeProcess"); taskTable.put(satename,"distributeProcess");
cnfData.setTaskTable(taskTable); cnfData.setTaskTable(taskTable);
//T3路由表 todo //T3路由表
String[][] route = new String[lastHop.length][lastHop[0].length]; String[][] routetest = new String[lastHop.length][lastHop[0].length];
for(int i =0;i<lastHop.length;i++){ for (int l = 0; l < lastHop.length/num; l++) {
for (int j=0;j<lastHop[0].length;j++){ for (int i = l * num; i < l*num+num; i++) {
route[i][j] = "sate"+(lastHop[i][j]); for (int j = l * num; j < lastHop.length; j++) {
if (route[i][j].equals("sate0")){ routetest[i][j] = "sate" + (lastHop[i][j]);
route[i][j]="sate"+(j); //到直联
} if((routetest[i][j].equals("sate0"))){
if (route[i][j].equals("sate0")){ routetest[i][j] = "direct";
route[i][j]="D1"; }
} if(i == j){
//要修改 routetest[i][j] = "self";
//todo }
if (route[i][j].equals("sate31")){ //表示不可达
route[i][j]="D2"; if((j % num) == 0){
routetest[i][j] = null;
}
} }
} }
} }
//不太正确 cnfData.setRoute(routetest);
cnfData.setRoute(route);
//图片 //图片
cnfData.setPicture(picture); cnfData.setPicture(picture);
//ip池 //ip池
cnfData.setIpPool(findService.findIPool()); cnfData.setIpPool(findService.findIPool());
//
cnfData.setOriSateHop(satename);
String[] routeself = findService.findRoute(cnfData.getCurrentSataHop(), cnfData.getRoute()); String[] routeself = findService.findRoute(cnfData.getCurrentSataHop(), cnfData.getRoute());
ArrayList<String> destinSataHops = findService.findDestinSataHops(path,"D1"); ArrayList<String> destinSataHops = findService.findDestinSataHops(path,"D1");
for(String des : destinSataHops) { for(String des : destinSataHops) {
...@@ -156,7 +168,7 @@ public class DbcTrans implements TransService { ...@@ -156,7 +168,7 @@ public class DbcTrans implements TransService {
if (!res.getStatusCode().is2xxSuccessful()) { if (!res.getStatusCode().is2xxSuccessful()) {
throw new RuntimeException("send Error!"); throw new RuntimeException("send Error!");
} }
return "sucess"; return res.getBody();
} }
/** /**
...@@ -204,12 +216,15 @@ public class DbcTrans implements TransService { ...@@ -204,12 +216,15 @@ public class DbcTrans implements TransService {
for (int i = l * num; i < l*num+num; i++) { for (int i = l * num; i < l*num+num; i++) {
for (int j = l * num; j < lastHop.length; j++) { for (int j = l * num; j < lastHop.length; j++) {
routetest[i][j] = "sate" + (lastHop[i][j]); routetest[i][j] = "sate" + (lastHop[i][j]);
//到自己 //到直联
if((i != 0 || i != num*l)&(routetest[i][j].equals("sate0"))){ if((routetest[i][j].equals("sate0"))){
routetest[i][j] = "sate"+i; routetest[i][j] = "direct";
}
if(i == j){
routetest[i][j] = "self";
} }
//表示不可达 //表示不可达
if(j==num*l){ if((j % num) == 0){
routetest[i][j] = null; routetest[i][j] = null;
} }
} }
...@@ -217,4 +232,19 @@ public class DbcTrans implements TransService { ...@@ -217,4 +232,19 @@ public class DbcTrans implements TransService {
} }
return routetest; return routetest;
} }
/**
* 卫星复位
*
* @param url
*/
@Override
public String reset(String url) {
String IP = url + ":8083";
ResponseEntity<String> res = restTemplate.getForEntity("http://" + IP + "/reset", String.class);
if (!res.getStatusCode().is2xxSuccessful()) {
throw new RuntimeException("send Error!");
}
return "sucess";
}
} }
...@@ -9,6 +9,12 @@ spring.thymeleaf.encoding=UTF-8 ...@@ -9,6 +9,12 @@ spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false spring.thymeleaf.cache=false
# # 设置文件上传的大小
spring.servlet.multipart.max-file-size=1024000000000MB spring.servlet.multipart.max-file-size=1024000000000MB
spring.servlet.multipart.max-request-size=1024000000000MB spring.servlet.multipart.max-request-size=1024000000000MB
\ No newline at end of file
# 粒子群配置
# 迭代次数
bps.k=500
# 种群规模
bps.n=10
\ No newline at end of file
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>文件显示</title>
</head>
<body>
<hr/>
<!--<a href="jpg/1.jpg">预览图片</a>-->
<!--<a href="@{/getFile/(fileName=${fileName},fileId=${fileId})}">预览图片</a>-->
<img th:src= "file+'/'+${fileName}" >
</body>
</html>
\ No newline at end of file
...@@ -12,7 +12,11 @@ ...@@ -12,7 +12,11 @@
文件:<input type="file" name="file" /> 文件:<input type="file" name="file" />
</p> </p>
<p> <p>
文件ID:<input type="text" name="fileId" palcegolder="请输入" /> 路径表:<input type="text" name="path_1" palcegolder="请输入" />
<input type="text" name="path_2" palcegolder="请输入" />
</p>
<p>
功能表:<input type="text" name="func" palcegolder="请输入" />
</p> </p>
<p> <p>
<input type="submit" value="上传" /> <input type="submit" value="上传" />
......
...@@ -14,9 +14,12 @@ ...@@ -14,9 +14,12 @@
<p> <p>
文件ID:<input type="text" name="fileId" palcegolder="请输入" /> 文件ID:<input type="text" name="fileId" palcegolder="请输入" />
</p> </p>
<p>
size:<input type="number" name="size" palcegolder="请输入" />
</p>
<p> <p>
<input type="submit" value="上传" /> <input type="submit" value="上传" />
</p> </p>
</form> </form>
</body> </body>
</html> </html>
\ No newline at end of file
package top.ninwoo.edgecenter.service; package top.ninwoo.edgecenter.service;
import com.sun.xml.internal.ws.spi.db.DatabindingException;
import top.ninwoo.common.entity.NetworkTopology; import top.ninwoo.common.entity.NetworkTopology;
import java.text.ParseException; import java.text.ParseException;
......
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