|
@@ -0,0 +1,83 @@
|
|
|
+package com.rongwei.rwapsserver.aps.util;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.rongwei.rwapsserver.aps.domain.ApsSolution;
|
|
|
+import com.rongwei.rwapsserver.aps.domain.ProductionProcesses;
|
|
|
+import org.optaplanner.core.api.score.ScoreExplanation;
|
|
|
+import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;
|
|
|
+import org.optaplanner.core.api.score.constraint.ConstraintMatch;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class ApsUtils {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 最终得分分析
|
|
|
+ * @param explain
|
|
|
+ * @param processes
|
|
|
+ */
|
|
|
+ public void softExplain(ScoreExplanation<ApsSolution, HardSoftScore> explain, List<ProductionProcesses> processes){
|
|
|
+ if(explain != null && explain.getConstraintMatchTotalMap() != null && explain.getConstraintMatchTotalMap().size()>0){
|
|
|
+ explain.getConstraintMatchTotalMap().forEach((k,v)->{
|
|
|
+ String constraintName = v.getConstraintName();
|
|
|
+ if(constraintName != null){
|
|
|
+ String desc = ApsConstants.constraintDesc.get(constraintName);
|
|
|
+ String consLevel = ApsConstants.hardConstraint.contains(constraintName) ? "hard" : "soft";
|
|
|
+ if(desc != null && v.getConstraintMatchSet() != null && v.getConstraintMatchSet().size()>0){
|
|
|
+ for (ConstraintMatch<HardSoftScore> hardSoftScoreConstraintMatch : v.getConstraintMatchSet()) {
|
|
|
+ if(hardSoftScoreConstraintMatch.getIndictedObjectList() != null && hardSoftScoreConstraintMatch.getIndictedObjectList().size() > 0){
|
|
|
+ for (Object o : hardSoftScoreConstraintMatch.getIndictedObjectList()) {
|
|
|
+ if(o instanceof ProductionProcesses){
|
|
|
+ ProductionProcesses productionProcesses = (ProductionProcesses)o;
|
|
|
+ constraintDescInit(productionProcesses,desc,consLevel);
|
|
|
+ } else if (o instanceof ArrayList) {
|
|
|
+ List<ProductionProcesses> processesList = (ArrayList)o;
|
|
|
+ for (ProductionProcesses productionProcesses : processesList) {
|
|
|
+ constraintDescInit(productionProcesses,desc,consLevel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 冲突描述
|
|
|
+ * @param productionProcesses
|
|
|
+ * @param desc
|
|
|
+ * @param consLevel
|
|
|
+ */
|
|
|
+ private void constraintDescInit(ProductionProcesses productionProcesses,String desc,String consLevel){
|
|
|
+ if("y".equals(productionProcesses.getHasConflict())){
|
|
|
+ if("hard".equals(consLevel)){
|
|
|
+ if(StrUtil.isBlank(productionProcesses.getConflictDes())){
|
|
|
+ productionProcesses.setConflictDes(desc);
|
|
|
+ }else{
|
|
|
+ if(!productionProcesses.getConflictDes().contains(desc)){
|
|
|
+ productionProcesses.setConflictDes(productionProcesses.getConflictDes()+";"+desc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(StrUtil.isBlank(productionProcesses.getSoftconflictdes())){
|
|
|
+ productionProcesses.setSoftconflictdes(desc);
|
|
|
+ }else{
|
|
|
+ if(!productionProcesses.getSoftconflictdes().contains(desc)){
|
|
|
+ productionProcesses.setSoftconflictdes(productionProcesses.getSoftconflictdes()+";"+desc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ productionProcesses.setHasConflict("y");
|
|
|
+ if("hard".equals(consLevel)){
|
|
|
+ productionProcesses.setConflictDes(desc);
|
|
|
+ }else{
|
|
|
+ productionProcesses.setSoftconflictdes(desc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|