电科院-电能替代模型工具开发
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.

128 lines
5.2 KiB

package com.dky.calculate;
import com.dky.utils.entity.SysDeviceHeatScene;
import com.dky.utils.result.MatchedDevice;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
public class SchemeRating {
/**
* 计算每一种方案的效率和成本评分
* @param list
* @return
*/
public static Map<Double, List<MatchedDevice>> getOptimalList(List<List<MatchedDevice>> list,Double costRatio,Double effRatio,Map<String,Double> maxEff,Map<String,Double> minPrice) {
Map<Double, List<MatchedDevice>> optimalMap = new HashMap<>();
list.forEach(plan->{
AtomicReference<Double> rating = new AtomicReference<>(0.0);
String devSubType = plan.get(0).getDeviceHeatScene().getDevSubType();
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*系数 +(1-(当前成本值-对应设备细类的成本最小值)/对应设备细类的成本最小值)*100*0.2。取最高得分。
rating.set(((1 - ((maxEff.get(devSubType) - eff) / maxEff.get(devSubType))) * 100 * effRatio) + ((1 - ((cost - minPrice.get(devSubType)) / minPrice.get(devSubType))) * 100 * costRatio));
optimalMap.put(rating.get(), plan);
});
return optimalMap;
}
/**
* 获取最优评分
* @param map
* @return
*/
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);
}
/**
* 获取不同设备细类下的效率最大值
* @param alternateDeviceList 可替代设备列表
* @return 不同设备细类下的效率最大值map
*/
public static Map<String,Double> getMaxEfficiencyGroupByDevSubType( List<SysDeviceHeatScene> alternateDeviceList){
Map<String,Double> map = new HashMap<>();
alternateDeviceList.forEach(alternateDevice ->{
String devSubType = alternateDevice.getDevSubType();
Double v = map.get(devSubType);
if ( v == null){
map.put(devSubType,alternateDevice.getHeatEfficiency());
} else {
if( alternateDevice.getHeatEfficiency() > v){
map.put(devSubType,alternateDevice.getHeatEfficiency());
}
}
});
return map;
}
/**
* 获取不同设备细类下的成本最小值
* @param alternateDeviceList 可替代设备列表
* @return 不同设备细类下的成本最小值map
*/
public static Map<String,Double> getMinPriceGroupByDevSubType( List<SysDeviceHeatScene> alternateDeviceList){
Map<String,Double> map = new HashMap<>();
alternateDeviceList.forEach(alternateDevice -> {
String devSubType = alternateDevice.getDevSubType();
Double v = map.get(devSubType);
if ( v == null){
map.put(devSubType,alternateDevice.getDevPrice()+ alternateDevice.getDevSubstituteLaborCost()*alternateDevice.getDevServiceLife());
} else {
if( alternateDevice.getDevPrice() < v){
map.put(devSubType,alternateDevice.getDevPrice() + alternateDevice.getDevSubstituteLaborCost()*alternateDevice.getDevServiceLife());
}
}
});
return map;
}
public static List<Map<String, Double[]>> getIndex(List<List<MatchedDevice>> list) {
List<Map<String, Double[]>> maps = new ArrayList<>();
final Double[] index = {0.0, Double.MAX_VALUE};
Map<String, Double[]> map = new HashMap<>();
list.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.put(plan.get(0).getDeviceHeatScene().getDevSubType(), index);
maps.add(map);
});
return maps;
}
}