1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| package com.zy.asrs.utils;
|
| /**
| * 权重优先级计算工具:
| * 按权重计算时间/距离/区域总优先级,并限制到 [-1, 1]
| */
| public final class PriorityWeightCalculatorUtil {
|
| private PriorityWeightCalculatorUtil() {
| }
|
| public static double calculate(double timePriority,
| double distancePriority,
| double regionPriority,
| double timeWeight,
| double distanceWeight,
| double regionWeight) {
| double sum = Math.abs(timeWeight) + Math.abs(distanceWeight) + Math.abs(regionWeight);
| if (sum <= 0D) {
| timeWeight = 1D;
| distanceWeight = 1D;
| regionWeight = 1D;
| sum = 3D;
| }
| double t = timeWeight / sum;
| double d = distanceWeight / sum;
| double r = regionWeight / sum;
| double score = timePriority * t + distancePriority * d + regionPriority * r;
| return clamp(score, -1D, 1D);
| }
|
| private static double clamp(double value, double min, double max) {
| if (value < min) {
| return min;
| }
| if (value > max) {
| return max;
| }
| return value;
| }
| }
|
|