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.
149 lines
6.0 KiB
149 lines
6.0 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<String, SchemeRatingRes> getOptimalList(List<List<MatchedDevice>> list,Double costRatio,Double effRatio,Map<String,Double> maxEff,Map<String, Double> minPrice) {
|
|
|
|
Map<String, SchemeRatingRes> optimalMap = new HashMap<>();
|
|
list.forEach(plan->{
|
|
String devTechType = plan.get(0).getDeviceHeatScene().getDevTechType();
|
|
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());
|
|
}
|
|
|
|
double v1 = (maxEff.get(devSubType) - eff) / maxEff.get(devSubType); // 热效率占比计算
|
|
double v = (cost - minPrice.get(devSubType)) / minPrice.get(devSubType); // 成本占比计算
|
|
|
|
// 3、(1-(选择对应设备细类的效率最大的效率值(效率最大值)-当前设备的效率值值)/效率最大值)*100*系数 +(1-(当前成本值-对应设备细类的成本最小值)/对应设备细类的成本最小值)*100*0.2。取最高得分。
|
|
rating.set(((1 - v1) * 100 * effRatio) + ((1 - v) * 100 * costRatio));
|
|
|
|
System.out.println("当前方案成本 = " + cost + ",方案详情 = ");
|
|
for (MatchedDevice matchedDevice : plan){
|
|
System.out.println(matchedDevice);
|
|
}
|
|
System.out.println("当前方案评分: " + rating.get() + "\n");
|
|
|
|
// 方案评分结果
|
|
SchemeRatingRes schemeRatingRes = new SchemeRatingRes(plan, rating.get(), devTechType);
|
|
optimalMap.put(devTechType, schemeRatingRes);
|
|
|
|
});
|
|
return optimalMap;
|
|
}
|
|
|
|
/**
|
|
* 获取最优评分的方案
|
|
* @param map
|
|
* @return
|
|
*/
|
|
public static List<MatchedDevice> getOptimalScheme(Map<String, SchemeRatingRes> map) {
|
|
|
|
final AtomicReference<Double>[] rating = new AtomicReference[]{new AtomicReference<>(-100.0)};
|
|
final List<MatchedDevice>[] list = new List[]{new ArrayList<>()};
|
|
map.forEach((k,v)->{
|
|
if (v.getSchemeRating() > rating[0].get()) {
|
|
rating[0].set(v.getSchemeRating());
|
|
list[0] = v.getList();
|
|
}
|
|
});
|
|
|
|
return list[0];
|
|
}
|
|
|
|
/**
|
|
* 获取不同设备细类下的效率最大值
|
|
* @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 不同设备细类下的成本最小值
|
|
*/
|
|
public static Map<String,Double> getMinPriceGroupByDevSubType(List<List<MatchedDevice>> alternateDeviceList){
|
|
Map<String,Double> map = new HashMap<>();
|
|
alternateDeviceList.forEach(plan -> {
|
|
Double thisPlanCost = 0.0;
|
|
String devSubType = plan.get(0).getDeviceHeatScene().getDevSubType();
|
|
for (MatchedDevice device : plan) {
|
|
thisPlanCost = thisPlanCost + ((device.getCount() * device.getDeviceHeatScene().getDevPrice()) + (device.getCount()) * device.getDeviceHeatScene().getDevSubstituteLaborCost() * device.getDeviceHeatScene().getDevServiceLife());
|
|
}
|
|
|
|
Double v = map.get(devSubType);
|
|
if ( v == null){
|
|
map.put(devSubType, thisPlanCost);
|
|
} else {
|
|
if(thisPlanCost < v){
|
|
map.put(devSubType, thisPlanCost);
|
|
}
|
|
}
|
|
});
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|