package com.dky.calculate; import com.dky.utils.result.MatchedDevice; import java.util.*; import java.util.concurrent.atomic.AtomicReference; public class SchemeRating { /** * 计算效率和成本评分 * @param list * @return */ public static Map> getOptimalList(List>>> list,Double costRatio,Double effRatio) { Map> optimalMap = new HashMap<>(); list.parallelStream().forEach(stringListMap -> { // 区分热泵、电锅炉 stringListMap.forEach((k,v)->{ // 循环遍历各个方案 v.parallelStream().forEach((plan)->{ AtomicReference rating = new AtomicReference<>(0.0); List> maps = getIndex(list); for (Map 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()); } //3、效率成本公式:(1-(选择效率最大-当前值)/效率最大值)*100*0.8 +(1-(当前值-选择成本最小)/成本最小值)*100*0.2。 rating.set(((1 - ((v1[0] - eff) / v1[0])) * 100 * effRatio) + ((1 - ((cost - v1[1]) / v1[1])) * 100 * costRatio)); optimalMap.put(rating.get(), plan); } }); } }); }); }); return optimalMap; } /** * 获取最优评分 * @param map * @return */ public static List getOptimalScheme(Map> map) { Set keySet = map.keySet(); Double maxValue = keySet.iterator().next(); for (Iterator iterator = keySet.iterator(); iterator.hasNext(); ) { Double value = iterator.next(); if (value > maxValue) { maxValue = value; } } return map.get(maxValue); } public static List> getIndex(List>>> list) { List> 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 map = new HashMap<>(); map.put(k, index); maps.add(map); }); }); return maps; } }