From bb6bc1f4030cf813e128f021ccecd42420f35628 Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期五, 06 六月 2025 13:38:10 +0800
Subject: [PATCH] *
---
src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java | 209 ++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 193 insertions(+), 16 deletions(-)
diff --git a/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java b/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java
index 93fbbfa..f56f198 100644
--- a/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java
+++ b/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java
@@ -3,6 +3,7 @@
import com.zy.asrs.entity.BasDevpPosition;
import com.zy.asrs.entity.WrkMast;
import com.zy.core.enums.RouteCollectCountType;
+import org.apache.xmlbeans.impl.xb.xsdschema.All;
import java.util.*;
@@ -29,20 +30,40 @@
return ints;
}
- //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃墠杈圭殑浣嶇疆
+// //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃墠杈圭殑浣嶇疆1000000===>10000==>0==>1000000
+// public static Integer LatelyAndLessThan(List<BasDevpPosition> devpPosition, long nowPosition,long perimeter){
+// Integer result = 0;
+// long Difference = perimeter;
+// for (BasDevpPosition positions : devpPosition){
+// Long position = positions.getPlcPosition();
+// if (position<=nowPosition){
+// if ((nowPosition-position) < Difference){
+// Difference = nowPosition-position;
+// result = positions.getDevNo();
+// }
+// } else {
+// if ((nowPosition-(position - perimeter)) < Difference){
+// Difference = nowPosition-(position - perimeter);
+// result = positions.getDevNo();
+// }
+// }
+// }
+// return result;
+// }
+ //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃墠杈圭殑浣嶇疆 0==>1000===>1000000==>0
public static Integer LatelyAndLessThan(List<BasDevpPosition> devpPosition, long nowPosition,long perimeter){
Integer result = 0;
long Difference = perimeter;
for (BasDevpPosition positions : devpPosition){
Long position = positions.getPlcPosition();
- if (position<=nowPosition){
- if ((nowPosition-position) < Difference){
- Difference = nowPosition-position;
+ if (position >= nowPosition){
+ if ((position-nowPosition) < Difference){
+ Difference = position-nowPosition;
result = positions.getDevNo();
}
} else {
- if ((nowPosition-(position - perimeter)) < Difference){
- Difference = nowPosition-(position - perimeter);
+ if (perimeter - (nowPosition - position) < Difference){
+ Difference = perimeter - (nowPosition - position);
result = positions.getDevNo();
}
}
@@ -50,20 +71,35 @@
return result;
}
- //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆
+// //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆 1000000===>10000==>0==>1000000
+// public static Integer LatelyAndLessThanWcs(List<BasDevpPosition> devpPosition, long nowPosition,long perimeter){
+// Integer result = 0;
+// Integer integer = LatelyAndLessThan(devpPosition, nowPosition,perimeter);
+// for (BasDevpPosition basDevpPosition:devpPosition){
+// if (basDevpPosition.getDevNo().equals(integer)){
+// if (basDevpPosition.getDevNo() == 101){
+// result = 133;
+// }
+// break;
+// }
+// result = basDevpPosition.getDevNo();
+// }
+// return result;
+// }
+ //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆 0==>1000===>1000000==>0
public static Integer LatelyAndLessThanWcs(List<BasDevpPosition> devpPosition, long nowPosition,long perimeter){
- Integer result = 0;
+ Integer result = -1;
Integer integer = LatelyAndLessThan(devpPosition, nowPosition,perimeter);
for (BasDevpPosition basDevpPosition:devpPosition){
if (basDevpPosition.getDevNo().equals(integer)){
- if (basDevpPosition.getDevNo() == 101){
- result = 133;
+ if (basDevpPosition.getDevNo() == 134){
+ result = 101;
}
break;
}
result = basDevpPosition.getDevNo();
}
- return result;
+ return result == -1? 101 : result;
}
// //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃墠杈圭殑浣嶇疆
// public static Long LatelyAndLessThan(long[] devpPosition,long nowPosition){
@@ -85,15 +121,36 @@
// return result;
// }
- //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆
+// //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆 1000000===>10000==>0==>1000000
+// public static Integer LatelyAndGreaterThan(List<List<Long>> sitePosition, long nowPosition ,long perimeter){
+// int result = 0;
+// long Difference = perimeter;
+// 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 ((perimeter - (nowPosition - position)) < Difference){
+// Difference = perimeter - (nowPosition - position);
+// result = rgvPositions.get(0).intValue();
+// }
+// }
+// }
+// return result;
+// }
+
+ //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆 0==>1000===>1000000==>0
public static Integer LatelyAndGreaterThan(List<List<Long>> sitePosition, long nowPosition ,long perimeter){
- int result = 0;
+ int result = -1;
long Difference = perimeter;
for (List<Long> rgvPositions: sitePosition){
Long position = rgvPositions.get(1);
- if (position>nowPosition){
- if ((position - nowPosition) < Difference){
- Difference = position - nowPosition;
+ if (position <= nowPosition){
+ if ((nowPosition - position) < Difference){
+ Difference = nowPosition - position;
result = rgvPositions.get(0).intValue();
}
} else {
@@ -147,6 +204,30 @@
basDevpPositions[devpPosition.length - basDevpPosition.getId().intValue()] = basDevpPosition;
}
return basDevpPositions;
+ }
+
+ //閫嗗簭鎺掑垪
+ public static List<List<Integer>> siteListAll(List<BasDevpPosition> devpPosition){
+ List<List<Integer>> sitePositions = new ArrayList<>();
+ Integer[] integers = new Integer[devpPosition.size()];
+ List<Integer> devRegions = new ArrayList<>();
+ int i = 0;
+ for (BasDevpPosition basDevpPosition : devpPosition){
+ if (basDevpPosition.getDevRegion()==0){
+ continue;
+ }
+ if (!devRegions.contains(basDevpPosition.getDevRegion())){
+ devRegions.add(basDevpPosition.getDevRegion());
+ integers[basDevpPosition.getDevRegion()] = i;
+ i++;
+ List<Integer> sitePosition = new ArrayList<>();
+ sitePosition.add(basDevpPosition.getDevNo());
+ sitePositions.add(sitePosition);
+ } else {
+ sitePositions.get(integers[basDevpPosition.getDevRegion()]).add(basDevpPosition.getDevNo());
+ }
+ }
+ return sitePositions;
}
//閫嗗簭鎺掑垪
@@ -402,4 +483,100 @@
// }
+ //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃墠杈圭殑浣嶇疆 0==>1000===>1000000==>0
+ public static Double LatelyAndLessThan(long devPosition,long rgvPosition,long perimeter){
+ long Difference = perimeter;
+ if (devPosition >= rgvPosition){
+// if ((devPosition-rgvPosition) < Difference){
+ Difference = devPosition-rgvPosition;
+// }
+ } else {
+// if (perimeter - (rgvPosition - devPosition) < Difference){
+ Difference = perimeter - (rgvPosition - devPosition);
+// }
+ }
+ return Double.valueOf(Difference);
+ }
+
+ public static int calculateShortestDistanceDistance(List<Integer> data, int a, int b) {
+ Result result = calculateShortestDistance(data, a, b);
+ return result.distance;
+ }
+
+ public static List<Integer> calculateShortestDistancePassedData(List<Integer> data, int a, int b) {
+ Result result = calculateShortestDistance(data, a, b);
+ return result.passedData;
+ }
+
+// public static String calculateShortestDistanceDirection(List<Integer> data, int a, int b) {
+// Result result = calculateShortestDistance(data, a, b);
+// return result.direction;
+// }
+
+ public static boolean calculateShortestDistanceDirection(List<Integer> data, int a, int b) {
+ Result result = calculateShortestDistance(data, a, b);
+ return result.direction.equals("鍚戝墠璧帮紙椤烘椂閽堬級");
+ }
+
+
+ public static void main(String[] args) {
+ List<Integer> data = new ArrayList<>();
+ // 鐢� List<Integer> 鍒濆鍖栨暟鎹�
+ for (int i = 1; i <= 9; i++) {
+ data.add(i);
+ }
+
+ int a = 3; // 璧风偣
+ int b = 3; // 缁堢偣
+
+ Result result = calculateShortestDistance(data, a, b);
+ System.out.println("鏈�杩戠殑璺濈鏄�: " + result.distance);
+ System.out.println("缁忚繃鐨勬暟鎹�: " + result.passedData);
+ System.out.println("鏂瑰悜: " + result.direction);
+ }
+
+ public static Result calculateShortestDistance(List<Integer> data, int a, int b) {
+ int length = data.size();
+ int indexA = data.indexOf(a);
+ int indexB = data.indexOf(b);
+
+ if (indexA == -1 || indexB == -1) {
+ throw new IllegalArgumentException("鍒楄〃涓湭鎵惧埌鎸囧畾鐨勫厓绱�");
+ }
+
+ // 椤烘椂閽堟柟鍚戠殑璺濈鍙婄粡杩囩殑鏁版嵁
+ List<Integer> clockwiseData = new ArrayList<>();
+ int clockwiseDistance = (indexB - indexA + length) % length;
+ for (int i = 0; i <= clockwiseDistance; i++) {
+ clockwiseData.add(data.get((indexA + i) % length));
+ }
+
+ // 閫嗘椂閽堟柟鍚戠殑璺濈鍙婄粡杩囩殑鏁版嵁
+ List<Integer> counterClockwiseData = new ArrayList<>();
+ int counterClockwiseDistance = (indexA - indexB + length) % length;
+ for (int i = 0; i <= counterClockwiseDistance; i++) {
+ counterClockwiseData.add(data.get((indexA - i + length) % length));
+ }
+
+ // 姣旇緝璺濈骞惰繑鍥炵粨鏋�
+ if (clockwiseDistance <= counterClockwiseDistance) {
+ return new Result(clockwiseDistance, clockwiseData, "鍚戝墠璧帮紙椤烘椂閽堬級");
+ } else {
+ return new Result(counterClockwiseDistance, counterClockwiseData, "鍚戝悗璧帮紙閫嗘椂閽堬級");
+ }
+ }
+
+ // 鐢ㄤ簬杩斿洖缁撴灉鐨勭被
+ static class Result {
+ public int distance;
+ public List<Integer> passedData;
+ public String direction;
+
+ public Result(int distance, List<Integer> passedData, String direction) {
+ this.distance = distance;
+ this.passedData = passedData;
+ this.direction = direction;
+ }
+ }
+
}
--
Gitblit v1.9.1