|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.framework.common.SpringUtils; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.MapNode; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.NavigateNode; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.PythonSimilarityResult; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.enums.MapNodeType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.core.model.enums.NavigationMapType; | 
|---|
|  |  |  | import com.zy.asrs.wcs.rcs.News; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.BufferedReader; | 
|---|
|  |  |  | import java.io.InputStreamReader; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Collections; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${pythonCalcPath}") | 
|---|
|  |  |  | private String pythonCalcPath; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${pythonCalcSimilarity}") | 
|---|
|  |  |  | private String pythonCalcSimilarity; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public List<NavigateNode> calc(String startPoint, String endPoint, Integer mapType, List<int[]> shuttlePoints) { | 
|---|
|  |  |  | //通过开始编号和结束编号获取对应的xy轴坐标 | 
|---|
|  |  |  | 
|---|
|  |  |  | return node; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    public static void main(String[] args) { | 
|---|
|  |  |  | public Double similarityPath(List<NavigateNode> firstPath, List<NavigateNode> secondPath) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | List<int[]> first = new ArrayList<>(); | 
|---|
|  |  |  | for (NavigateNode node : firstPath) { | 
|---|
|  |  |  | first.add(new int[]{node.getX(), node.getY()}); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<int[]> second = new ArrayList<>(); | 
|---|
|  |  |  | for (NavigateNode node : secondPath) { | 
|---|
|  |  |  | second.add(new int[]{node.getX(), node.getY()}); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ProcessBuilder processBuilder = new ProcessBuilder("python", pythonCalcSimilarity, JSON.toJSONString(first), JSON.toJSONString(second)); | 
|---|
|  |  |  | processBuilder.redirectErrorStream(true); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Process process = processBuilder.start(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 读取Python脚本的输出 | 
|---|
|  |  |  | BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); | 
|---|
|  |  |  | String line; | 
|---|
|  |  |  | StringBuilder builder = new StringBuilder(); | 
|---|
|  |  |  | while ((line = reader.readLine()) != null) { | 
|---|
|  |  |  | builder.append(line); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 等待Python脚本执行完成 | 
|---|
|  |  |  | int exitCode = process.waitFor(); | 
|---|
|  |  |  | if (exitCode != 0) { | 
|---|
|  |  |  | System.out.println("Python script exited with error code: " + exitCode); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | reader.close(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (builder.length() <= 0) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PythonSimilarityResult result = JSON.parseObject(builder.toString(), PythonSimilarityResult.class); | 
|---|
|  |  |  | if (result.getCalcResult() != 200) { | 
|---|
|  |  |  | return 0D; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Double similarity = result.getSimilarity(); | 
|---|
|  |  |  | return similarity; | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return 0D; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) { | 
|---|
|  |  |  | //        //计算路径 | 
|---|
|  |  |  | //        List<NavigateNode> calc = calc("1000901", "1800201", NavigationMapType.NONE.id, null); | 
|---|
|  |  |  | //        System.out.println(calc); | 
|---|
|  |  |  | 
|---|
|  |  |  | //            System.out.println(currentPathAllDistance); | 
|---|
|  |  |  | //            System.out.println(list); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | System.loadLibrary("example"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|