You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.9 KiB
94 lines
3.9 KiB
1 year ago
|
package com.dky.calculate;
|
||
|
|
||
|
|
||
|
import com.dky.utils.result.MatchedDevice;
|
||
|
|
||
|
import java.util.*;
|
||
|
import java.util.concurrent.atomic.AtomicReference;
|
||
|
|
||
|
public class SchemeRating {
|
||
|
|
||
|
|
||
|
public static Map<Double, List<MatchedDevice>> getOptimalList(List<Map<String, List<List<MatchedDevice>>>> list) {
|
||
|
Map<Double, List<MatchedDevice>> optimalMap = new HashMap<>();
|
||
|
list.parallelStream().forEach(stringListMap -> {
|
||
|
// 区分热泵、电锅炉
|
||
|
stringListMap.forEach((k,v)->{
|
||
|
// 循环遍历各个方案
|
||
|
v.parallelStream().forEach((plan)->{
|
||
|
AtomicReference<Double> rating = new AtomicReference<>(0.0);
|
||
|
List<Map<String, Double[]>> maps = getIndex(list);
|
||
|
for (Map<String, Double[]> map : maps) {
|
||
|
map.forEach((k1, v1) -> {
|
||
|
if (k1.equals(k)){
|
||
|
Double eff = 0.0;
|
||
|
Double cost = 0.0;
|
||
|
for (MatchedDevice device : plan) {
|
||
|
eff = device.getDeviceHeatScene().getHeatEfficiency();
|
||
|
}
|
||
|
for (MatchedDevice device : plan) {
|
||
|
cost = cost + ((device.getCount() * device.getDeviceHeatScene().getDevPrice()) + (device.getCount()) * device.getDeviceHeatScene().getDevSubstituteLaborCost() * device.getDeviceHeatScene().getDevServiceLife());
|
||
|
}
|
||
|
rating.set(((1 - ((v1[0] - eff) / v1[0])) * 100 * 0.8) + ((1 - ((cost - v1[1]) / v1[1])) * 100 * 0.2));
|
||
|
System.out.println("方案: " + plan + ",评分 = " + rating + "\n");
|
||
|
|
||
|
optimalMap.put(rating.get(), plan);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
return optimalMap;
|
||
|
}
|
||
|
|
||
|
public static List<MatchedDevice> getOptimalScheme(Map<Double, List<MatchedDevice>> map) {
|
||
|
Set<Double> keySet = map.keySet();
|
||
|
Double maxValue = keySet.iterator().next();
|
||
|
for (Iterator<Double> iterator = keySet.iterator(); iterator.hasNext(); ) {
|
||
|
Double value = iterator.next();
|
||
|
if (value > maxValue) {
|
||
|
maxValue = value;
|
||
|
}
|
||
|
}
|
||
|
return map.get(maxValue);
|
||
|
}
|
||
|
|
||
|
public static List<Map<String, Double[]>> getIndex(List<Map<String, List<List<MatchedDevice>>>> list) {
|
||
|
List<Map<String, Double[]>> maps = new ArrayList<>();
|
||
|
list.parallelStream().forEach(stringListMap -> {
|
||
|
// 区分热泵、电锅炉
|
||
|
stringListMap.forEach((k, v) -> {
|
||
|
// 循环遍历各个方案
|
||
|
// 热效率、成本
|
||
|
final Double[] index = {0.0, Double.MAX_VALUE};
|
||
|
v.parallelStream().forEach((plan) -> {
|
||
|
Double eff = 0.0;
|
||
|
Double cost = 0.0;
|
||
|
for (MatchedDevice device : plan) {
|
||
|
eff = device.getDeviceHeatScene().getHeatEfficiency();
|
||
|
}
|
||
|
for (MatchedDevice device : plan) {
|
||
|
cost = cost + ((device.getCount() * device.getDeviceHeatScene().getDevPrice()) + (device.getCount()) * device.getDeviceHeatScene().getDevSubstituteLaborCost() * device.getDeviceHeatScene().getDevServiceLife());
|
||
|
}
|
||
|
if (eff >= index[0]) {
|
||
|
index[0] = eff;
|
||
|
}
|
||
|
if (cost <= index[1]) {
|
||
|
index[1] = cost;
|
||
|
}
|
||
|
});
|
||
|
Map<String, Double[]> map = new HashMap<>();
|
||
|
map.put(k, index);
|
||
|
maps.add(map);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
return maps;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|