|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.utils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.zy.asrs.entity.BasDevpPosition; | 
|---|
|  |  |  | import com.zy.asrs.entity.WrkMast; | 
|---|
|  |  |  | import com.zy.core.enums.RouteCollectCountType; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class SortTheExecutionOfTheCarUtil { | 
|---|
|  |  |  | //排序 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //获取最近并在当前位置前边的位置 | 
|---|
|  |  |  | public static Long LatelyAndLessThan(long[] devpPosition,long nowPosition){ | 
|---|
|  |  |  | long result = 0L; | 
|---|
|  |  |  | //    //获取最近并在当前位置前边的位置 | 
|---|
|  |  |  | //    public static Long LatelyAndLessThan(long[] devpPosition,long nowPosition){ | 
|---|
|  |  |  | //        long result = 0L; | 
|---|
|  |  |  | //        long Difference = 1737000L; | 
|---|
|  |  |  | //        for (long position : devpPosition){ | 
|---|
|  |  |  | //            if (position<=nowPosition){ | 
|---|
|  |  |  | //                if ((nowPosition-position) < Difference){ | 
|---|
|  |  |  | //                    Difference = nowPosition-position; | 
|---|
|  |  |  | //                    result = position; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } else { | 
|---|
|  |  |  | //                if ((nowPosition-(position - 1737000L)) < Difference){ | 
|---|
|  |  |  | //                    Difference = nowPosition-(position - 1737000L); | 
|---|
|  |  |  | //                    result = position; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        return result; | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取最近并在当前位置后边的位置 | 
|---|
|  |  |  | public static Integer LatelyAndGreaterThan(List<List<Long>> sitePosition, long nowPosition){ | 
|---|
|  |  |  | int result = 0; | 
|---|
|  |  |  | long Difference = 1737000L; | 
|---|
|  |  |  | for (long position : devpPosition){ | 
|---|
|  |  |  | if (position<=nowPosition){ | 
|---|
|  |  |  | if ((nowPosition-position) < Difference){ | 
|---|
|  |  |  | Difference = nowPosition-position; | 
|---|
|  |  |  | result = position; | 
|---|
|  |  |  | for (List<Long> rgvPositions: sitePosition){ | 
|---|
|  |  |  | Long position = rgvPositions.get(1); | 
|---|
|  |  |  | if (position>nowPosition){ | 
|---|
|  |  |  | if ((position - nowPosition) < Difference){ | 
|---|
|  |  |  | Difference = position - nowPosition; | 
|---|
|  |  |  | result = rgvPositions.get(0).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if ((nowPosition-(position - 1737000L)) < Difference){ | 
|---|
|  |  |  | Difference = nowPosition-(position - 1737000L); | 
|---|
|  |  |  | result = position; | 
|---|
|  |  |  | if ((1737000L - (nowPosition - position)) < Difference){ | 
|---|
|  |  |  | Difference = 1737000L - (nowPosition - position); | 
|---|
|  |  |  | result = rgvPositions.get(0).intValue(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return sou>end; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) { | 
|---|
|  |  |  | int[][] ints = new int[][]{{1,1},{3,3},{2,2},{4,4},{5,5},{6,6},{7,7},{8,8},{9,9},{10,10}}; | 
|---|
|  |  |  | //提取站点集合 | 
|---|
|  |  |  | public static List<Integer> WrkMastExtractSites(List<WrkMast> wrkMastList){ | 
|---|
|  |  |  | List<Integer> siteList = new ArrayList<>(); | 
|---|
|  |  |  | for (WrkMast wrkMast : wrkMastList){ | 
|---|
|  |  |  | if (!siteList.contains(wrkMast.getSourceStaNo())){ | 
|---|
|  |  |  | siteList.add(wrkMast.getSourceStaNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return siteList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //提取站点集合 | 
|---|
|  |  |  | public static List<Integer> BasDevpPositionExtractSites(List<BasDevpPosition> basDevpPositions){ | 
|---|
|  |  |  | List<Integer> siteList = new ArrayList<>(); | 
|---|
|  |  |  | for (BasDevpPosition basDevpPosition : basDevpPositions){ | 
|---|
|  |  |  | if (!siteList.contains(basDevpPosition.getDevNo())){ | 
|---|
|  |  |  | siteList.add(basDevpPosition.getDevNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return siteList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int[][] reorderSteId = ReorderSteId(ints, 2); | 
|---|
|  |  |  | for (int[] ste : reorderSteId){ | 
|---|
|  |  |  | System.out.println(Arrays.toString(ste)); | 
|---|
|  |  |  | //提取站点集合X2 | 
|---|
|  |  |  | public static List<Integer> ExtractSitesComplex(List<Integer> siteList){ | 
|---|
|  |  |  | siteList.addAll(siteList); | 
|---|
|  |  |  | return siteList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //集合转数组 | 
|---|
|  |  |  | public static int[] SetToArrayConversion(List<Integer> siteList){ | 
|---|
|  |  |  | int[] nums = new int[siteList.size()]; | 
|---|
|  |  |  | for (int i = 0;i<siteList.size();i++){ | 
|---|
|  |  |  | nums[i] = siteList.get(i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return nums; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取任务密集区 | 
|---|
|  |  |  | public static List<Integer> ObtainDenseAreasSite(List<Integer> siteList,List<Integer> devpList){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Integer> siteLists = ExtractSitesComplex(devpList); | 
|---|
|  |  |  | int[] nums = SetToArrayConversion(siteLists); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Integer> champion = new ArrayList<>(); | 
|---|
|  |  |  | for (int rangeArea = 1; rangeArea<=devpList.size();rangeArea++){ | 
|---|
|  |  |  | List<List<Integer>> subsets = getConsecutiveSubsets(nums, rangeArea); | 
|---|
|  |  |  | if (subsets != null){ | 
|---|
|  |  |  | int temporaryMaxCount = 0; | 
|---|
|  |  |  | List<Integer> championTemporary = new ArrayList<>(); | 
|---|
|  |  |  | int championCount = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (List<Integer> one : subsets){ | 
|---|
|  |  |  | int intersectionSize = getIntersectionSize(siteList, one); | 
|---|
|  |  |  | if (intersectionSize == temporaryMaxCount){ | 
|---|
|  |  |  | championCount++; | 
|---|
|  |  |  | championTemporary = siteLists; | 
|---|
|  |  |  | } else if (intersectionSize > temporaryMaxCount){ | 
|---|
|  |  |  | championCount = 1 ; | 
|---|
|  |  |  | temporaryMaxCount = intersectionSize; | 
|---|
|  |  |  | championTemporary = siteLists; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (championCount == 1){ | 
|---|
|  |  |  | champion = championTemporary; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | long[] longs = new long[]{1L,1000L,200000L,1100000L,1600000L}; | 
|---|
|  |  |  | long l = LatelyAndLessThan(longs, 1100000L); | 
|---|
|  |  |  | System.out.println("l:"+l); | 
|---|
|  |  |  | return champion; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static Integer ObtainDenseAreasFirstPlace(List<Integer> siteList,List<Integer> devpList){ | 
|---|
|  |  |  | List<Integer> integers = ObtainDenseAreasSite(siteList, devpList); | 
|---|
|  |  |  | if (integers==null){ | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return integers.get(0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    public static void main(String[] args) { | 
|---|
|  |  |  | ////        int[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | 
|---|
|  |  |  | //        List<Integer> siteList = new ArrayList<Integer>() {{ | 
|---|
|  |  |  | //            add(1);add(2);add(3);add(4);add(5);add(6);add(7);add(8);add(9);add(10); | 
|---|
|  |  |  | //        }}; | 
|---|
|  |  |  | //        List<Integer> siteLists = ExtractSitesComplex(siteList); | 
|---|
|  |  |  | //        int[] nums = SetToArrayConversion(siteLists); | 
|---|
|  |  |  | //        int subsetSize = 5;  // 可以通过用户输入或者其他方式控制 | 
|---|
|  |  |  | //        List<List<Integer>> subsets = getConsecutiveSubsets(nums, subsetSize); | 
|---|
|  |  |  | //        if (subsets != null){ | 
|---|
|  |  |  | //            for (List<Integer> subset : subsets) { | 
|---|
|  |  |  | //                System.out.println(subset); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } else { | 
|---|
|  |  |  | //            System.out.println("子集大小必须大于0且小于等于数组长度"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static List<List<Integer>> getConsecutiveSubsets(int[] nums, int size) { | 
|---|
|  |  |  | List<List<Integer>> result = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 确保子集的大小合法 | 
|---|
|  |  |  | if (size > nums.length || size <= 0) { | 
|---|
|  |  |  | //            throw new IllegalArgumentException("子集大小必须大于0且小于等于数组长度"); | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 通过滑动窗口法生成相邻的子集 | 
|---|
|  |  |  | for (int i = 0; i <= nums.length - size; i++) { | 
|---|
|  |  |  | List<Integer> subset = new ArrayList<>(); | 
|---|
|  |  |  | for (int j = 0; j < size; j++) { | 
|---|
|  |  |  | subset.add(nums[i + j]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!result.contains(subset)){ | 
|---|
|  |  |  | result.add(subset); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static int getIntersectionSize(List<Integer> listA, List<Integer> listB) { | 
|---|
|  |  |  | // 使用集合来存储交集元素,避免重复 | 
|---|
|  |  |  | Set<Integer> intersection = new HashSet<>(listA); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 保留集合A和集合B中的共同元素 | 
|---|
|  |  |  | intersection.retainAll(listB); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 返回交集的大小 | 
|---|
|  |  |  | return intersection.size(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    public static void main(String[] args) { | 
|---|
|  |  |  | //        int[][] ints = new int[][]{{1,1},{3,3},{2,2},{4,4},{5,5},{6,6},{7,7},{8,8},{9,9},{10,10}}; | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        int[][] reorderSteId = ReorderSteId(ints, 2); | 
|---|
|  |  |  | //        for (int[] ste : reorderSteId){ | 
|---|
|  |  |  | //            System.out.println(Arrays.toString(ste)); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        long[] longs = new long[]{1L,1000L,200000L,1100000L,1600000L}; | 
|---|
|  |  |  | //        long l = LatelyAndLessThan(longs, 1100000L); | 
|---|
|  |  |  | //        System.out.println("l:"+l); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    public static void main(String[] args) { | 
|---|
|  |  |  | //        int[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | 
|---|
|  |  |  | //        List<List<Integer>> subsets = getSubsets(nums); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        for (List<Integer> subset : subsets) { | 
|---|
|  |  |  | //            System.out.println(subset); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    public static List<List<Integer>> getSubsets(int[] nums) { | 
|---|
|  |  |  | //        List<List<Integer>> result = new ArrayList<>(); | 
|---|
|  |  |  | //        generateSubsets(0, nums, new ArrayList<>(), result); | 
|---|
|  |  |  | //        return result; | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    private static void generateSubsets(int index, int[] nums, List<Integer> current, List<List<Integer>> result) { | 
|---|
|  |  |  | //        if (index == nums.length) { | 
|---|
|  |  |  | //            result.add(new ArrayList<>(current)); | 
|---|
|  |  |  | //            return; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        // 不包含当前元素的子集 | 
|---|
|  |  |  | //        generateSubsets(index + 1, nums, current, result); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        // 包含当前元素的子集 | 
|---|
|  |  |  | //        current.add(nums[index]); | 
|---|
|  |  |  | //        generateSubsets(index + 1, nums, current, result); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        // 回溯 | 
|---|
|  |  |  | //        current.remove(current.size() - 1); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*  好东西,做记录 | 
|---|
|  |  |  | public static void main(String[] args) { | 
|---|
|  |  |  | int[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | 
|---|
|  |  |  | int subsetSize = 3;  // 可以通过用户输入或者其他方式控制 | 
|---|
|  |  |  | List<List<Integer>> subsets = getConsecutiveSubsets(nums, subsetSize); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (List<Integer> subset : subsets) { | 
|---|
|  |  |  | System.out.println(subset); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static List<List<Integer>> getConsecutiveSubsets(int[] nums, int size) { | 
|---|
|  |  |  | List<List<Integer>> result = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 确保子集的大小合法 | 
|---|
|  |  |  | if (size > nums.length || size <= 0) { | 
|---|
|  |  |  | throw new IllegalArgumentException("子集大小必须大于0且小于等于数组长度"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 通过滑动窗口法生成相邻的子集 | 
|---|
|  |  |  | for (int i = 0; i <= nums.length - size; i++) { | 
|---|
|  |  |  | List<Integer> subset = new ArrayList<>(); | 
|---|
|  |  |  | for (int j = 0; j < size; j++) { | 
|---|
|  |  |  | subset.add(nums[i + j]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | result.add(subset); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | * */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    public static void main(String[] args) { | 
|---|
|  |  |  | //        // 示例列表A和列表B | 
|---|
|  |  |  | //        List<Integer> listA = new ArrayList<>(); | 
|---|
|  |  |  | //        List<Integer> listB = new ArrayList<>(); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        // 初始化列表A | 
|---|
|  |  |  | //        listA.add(1); | 
|---|
|  |  |  | //        listA.add(2); | 
|---|
|  |  |  | //        listA.add(3); | 
|---|
|  |  |  | //        listA.add(4); | 
|---|
|  |  |  | //        listA.add(5); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        // 初始化列表B | 
|---|
|  |  |  | //        listB.add(3); | 
|---|
|  |  |  | //        listB.add(4); | 
|---|
|  |  |  | //        listB.add(5); | 
|---|
|  |  |  | //        listB.add(6); | 
|---|
|  |  |  | //        listB.add(7); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        // 计算交集数量 | 
|---|
|  |  |  | //        int intersectionSize = getIntersectionSize(listA, listB); | 
|---|
|  |  |  | //        System.out.println("交集的数量是: " + intersectionSize); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|