zjj
2025-02-17 200a5b4d08215c44fd3fb2d010191e7dedb5e4c5
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateUtils.java
@@ -5,13 +5,16 @@
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;
@@ -23,6 +26,9 @@
    @Value("${pythonCalcPath}")
    private String pythonCalcPath;
    @Value("${pythonCalcSimilarity}")
    private String pythonCalcSimilarity;
    public List<NavigateNode> calc(String startPoint, String endPoint, Integer mapType, List<int[]> shuttlePoints) {
        //通过开始编号和结束编号获取对应的xy轴坐标
@@ -46,7 +52,7 @@
        String pathStr = solution.astarSearch(start, end, pythonCalcPath);
        if (pathStr == null) {
            System.err.println("未找到路径");
            News.error("{} dash {} can't find navigate path!", startPoint, endPoint);
            return null;
        }
@@ -288,7 +294,57 @@
        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);
@@ -301,7 +357,9 @@
//            System.out.println(currentPathAllDistance);
//            System.out.println(list);
//        }
//
//    }
        System.loadLibrary("example");
    }
}