diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/LSPWorstPlanForRemovalSelector.java b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/LSPWorstPlanForRemovalSelector.java index e0af254b..ebd2f33c 100644 --- a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/LSPWorstPlanForRemovalSelector.java +++ b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/LSPWorstPlanForRemovalSelector.java @@ -3,58 +3,59 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.matsim.api.core.v01.population.HasPlansAndId; +import org.matsim.core.replanning.selectors.GenericWorstPlanForRemovalSelector; import org.matsim.core.replanning.selectors.PlanSelector; import org.matsim.freight.logistics.LSP; import org.matsim.freight.logistics.LSPPlan; -class LSPWorstPlanForRemovalSelector implements PlanSelector { +class LSPWorstPlanForRemovalSelector extends GenericWorstPlanForRemovalSelector {//implements PlanSelector { - private static final String UNDEFINED_TYPE = "undefined"; - - @Override - public LSPPlan selectPlan(HasPlansAndId lsp) { - - Map typeCounts = new ConcurrentHashMap(); - - // count how many plans per type an agent has: - for (LSPPlan plan : lsp.getPlans()) { - String type = plan.getType(); - if (type == null) { - type = UNDEFINED_TYPE; - } - typeCounts.merge(type, 1, (a, b) -> a + b); - } - - LSPPlan worst = null; - double worstScore = Double.POSITIVE_INFINITY; - for (LSPPlan plan : lsp.getPlans()) { - String type = plan.getType(); - if (type == null) { - type = UNDEFINED_TYPE; - } - if (typeCounts.get(type) > 1) { - if (plan.getScore() == null || plan.getScore().isNaN()) { - worst = plan; - worstScore = Double.NEGATIVE_INFINITY; - } else if (plan.getScore() < worstScore) { - worst = plan; - worstScore = plan.getScore(); - } - } - } - if (worst == null) { - // there is exactly one plan, or we have of each plan-type exactly one. - // select the one with worst score globally, or the first one with score=null - for (LSPPlan plan : lsp.getPlans()) { - if (plan.getScore() == null || plan.getScore().isNaN()) { - return plan; - } - if (plan.getScore() < worstScore) { - worst = plan; - worstScore = plan.getScore(); - } - } - } - return worst; - } +// private static final String UNDEFINED_TYPE = "undefined"; +// +// @Override +// public LSPPlan selectPlan(HasPlansAndId lsp) { +// +// Map typeCounts = new ConcurrentHashMap(); +// +// // count how many plans per type an agent has: +// for (LSPPlan plan : lsp.getPlans()) { +// String type = plan.getType(); +// if (type == null) { +// type = UNDEFINED_TYPE; +// } +// typeCounts.merge(type, 1, (a, b) -> a + b); +// } +// +// LSPPlan worst = null; +// double worstScore = Double.POSITIVE_INFINITY; +// for (LSPPlan plan : lsp.getPlans()) { +// String type = plan.getType(); +// if (type == null) { +// type = UNDEFINED_TYPE; +// } +// if (typeCounts.get(type) > 1) { +// if (plan.getScore() == null || plan.getScore().isNaN()) { +// worst = plan; +// worstScore = Double.NEGATIVE_INFINITY; +// } else if (plan.getScore() < worstScore) { +// worst = plan; +// worstScore = plan.getScore(); +// } +// } +// } +// if (worst == null) { +// // there is exactly one plan, or we have of each plan-type exactly one. +// // select the one with worst score globally, or the first one with score=null +// for (LSPPlan plan : lsp.getPlans()) { +// if (plan.getScore() == null || plan.getScore().isNaN()) { +// return plan; +// } +// if (plan.getScore() < worstScore) { +// worst = plan; +// worstScore = plan.getScore(); +// } +// } +// } +// return worst; +// } }