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> getOptimalList(List>>> list) { 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()); } 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 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; } }