瀏覽代碼

求解中间数据

huangxingxing 7 月之前
父節點
當前提交
13fca937ca

+ 67 - 45
src/main/java/com/miniframe/bisiness/mdo/MDO0039Service.java

@@ -55,12 +55,25 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
 		XIFileUtils.mkdir(LogService.BPATH+"/"+pro.getId());
 		XIFileUtils.mkdir(LogService.BPATH+"/"+pro.getId()+"/in");
 		XIFileUtils.mkdir(LogService.BPATH+"/"+pro.getId()+"/out");
-		//日志文件清空
+
+		File nsga2_history1 =new File(LogService.BPATH+"/"+pro.getId()+"/out/nsga2_history1.txt");
+		if(!nsga2_history1.exists()){
+			nsga2_history1.createNewFile();
+		}
+		File nsga2_history2 =new File(LogService.BPATH+"/"+pro.getId()+"/out/nsga2_history2.txt");
+		if(!nsga2_history2.exists()){
+			nsga2_history2.createNewFile();
+		}
+				//日志文件清空
 		LogService.clearLog(pid);
 		//创建problem.xml
 		TemplateGenerator.createProblemXml(pid);
 		//创建run.py
 		TemplateGenerator.createRunpy(pid);
+
+
+
+
 		run(pid,pro.getStype());
 	}
 
@@ -88,52 +101,61 @@ public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow
 					String line =new String(frame.getPayload());
 					LogService.addLog(pid,line);
 					System.out.print(new String(frame.getPayload()));
-//					//存储每步数据
-//					if("Forrester".equals(stype)||"Branin".equals(stype)||"Rastrigin".equals(stype)
-//							||"Rosenbrock".equals(stype)||"G9".equals(stype)
-//					){
-//						if(line.startsWith("[")){
-//							MdoProComval v=null;
-//							if(comvals.isEmpty()){
-//								v= new MdoProComval();
-//								comvals.add(v);
-//							}
-//							if(flag[0]){//没有结束
-//								v=comvals.get(comvals.size()-1);
-//							}else{
-//								v= new MdoProComval();
-//								comvals.add(v);
-//							}
-//							String[] valts = line.replace("[","").replace("]","").split(" ");
-//							valNSiz[0] = valts.length;
-//							List<String> valtsl = Arrays.asList(valts);
-//							vals[0].addAll(valtsl);
-//						}
-//						if(line.startsWith(" gen =")){
-//							String step = line.split("=")[1].trim();
-//							MdoProComval comval=comvals.get(comvals.size()-1);;
-//							comval.setId(UtilTools.getUUid());
-//							comval.setPid(pid);
-//							comval.setStep(step);
-//							List<String> x_nL = new ArrayList<>();
-//							for (int i = 0; i < valNSiz[0]; i++) {
-//								x_nL.add("x"+i);
-//							}
-//							comval.setVars(x_nL.toString().replace("[","").replace("]",""));
-//							comval.setVals(vals[0].toString().replace("[","").replace("]","").replace(","," "));
-//							comvalDao.insert(comval);
-//							vals[0] = new ArrayList<>();
-//							flag[0] =false;
-//
-//							try {
-//								LogService.addLog(pid, XiJsonUtil.objectToJson(comval));
-//							} catch (JsonProcessingException e) {
-//								e.printStackTrace();
-//							}
-//						}
-//					}
+//					saveLog(line);
 					super.onNext(frame);
 				}
+
+				/**
+				 * 20250210 保存 日志  弃用
+				 * @param line
+				 */
+				private void saveLog(String line) {
+					//存储每步数据
+					if("Forrester".equals(stype)||"Branin".equals(stype)||"Rastrigin".equals(stype)
+							||"Rosenbrock".equals(stype)||"G9".equals(stype)
+					){
+						if(line.startsWith("[")){
+							MdoProComval v=null;
+							if(comvals.isEmpty()){
+								v= new MdoProComval();
+								comvals.add(v);
+							}
+							if(flag[0]){//没有结束
+								v=comvals.get(comvals.size()-1);
+							}else{
+								v= new MdoProComval();
+								comvals.add(v);
+							}
+							String[] valts = line.replace("[","").replace("]","").split(" ");
+							valNSiz[0] = valts.length;
+							List<String> valtsl = Arrays.asList(valts);
+							vals[0].addAll(valtsl);
+						}
+						if(line.startsWith(" gen =")){
+							String step = line.split("=")[1].trim();
+							MdoProComval comval=comvals.get(comvals.size()-1);;
+							comval.setId(UtilTools.getUUid());
+							comval.setPid(pid);
+							comval.setStep(step);
+							List<String> x_nL = new ArrayList<>();
+							for (int i = 0; i < valNSiz[0]; i++) {
+								x_nL.add("x"+i);
+							}
+							comval.setVars(x_nL.toString().replace("[","").replace("]",""));
+							comval.setVals(vals[0].toString().replace("[","").replace("]","").replace(","," "));
+							comvalDao.insert(comval);
+							vals[0] = new ArrayList<>();
+							flag[0] =false;
+
+							try {
+								LogService.addLog(pid, XiJsonUtil.objectToJson(comval));
+							} catch (JsonProcessingException e) {
+								e.printStackTrace();
+							}
+						}
+					}
+				}
+
 				@Override
 				public void onError(Throwable throwable) {
 					System.err.println("日志获取失败");

+ 13 - 1
src/main/java/com/miniframe/tools/docker/DockerExe.java

@@ -128,12 +128,24 @@ public class DockerExe {
                 .withSource("/cephfs/mdo/"+pid +"/in/run.py")
                 .withTarget("/workspace/run.py")
                 .withReadOnly(false);
+        Mount nsga2_history1 = new Mount()
+                .withType(MountType.BIND)
+                .withSource("/cephfs/mdo/"+pid +"/out/nsga2_history1.txt")
+                .withTarget("/workspace/nsga2_history1.txt")
+                .withReadOnly(false);
+        Mount nsga2_history2 = new Mount()
+                .withType(MountType.BIND)
+                .withSource("/cephfs/mdo/"+pid +"/out/nsga2_history2.txt")
+                .withTarget("/workspace/nsga2_history2.txt")
+                .withReadOnly(false);
+
         List<Mount> am =new ArrayList<>();
         am.add(cephfsVMount);
         am.add(sitePackages);
-
         am.add(outMount);
         am.add(runMount);
+        am.add(nsga2_history1);
+        am.add(nsga2_history2);
         //创建容器
         CreateContainerResponse container = dockerClient
                 .createContainerCmd("xgd:2.0")//镜像名称