diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/listener/InsertionListeners.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/listener/InsertionListeners.java index 37ccd7bb..f0c5e9a8 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/listener/InsertionListeners.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/listener/InsertionListeners.java @@ -24,6 +24,7 @@ import com.graphhopper.jsprit.core.problem.vehicle.Vehicle; import java.util.ArrayList; import java.util.Collection; +import java.util.List; public class InsertionListeners { @@ -74,6 +75,14 @@ public class InsertionListeners { } } + public void informJobUnassignedListeners(Job unassigned, List reasons) { + for (InsertionListener l : listeners) { + if (l instanceof JobUnassignedListener) { + ((JobUnassignedListener) l).informJobUnassigned(unassigned, reasons); + } + } + } + public void addListener(InsertionListener insertionListener) { listeners.add(insertionListener); } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/listener/JobUnassignedListener.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/listener/JobUnassignedListener.java new file mode 100644 index 00000000..55a2921d --- /dev/null +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/recreate/listener/JobUnassignedListener.java @@ -0,0 +1,32 @@ +/* + * Licensed to GraphHopper GmbH under one or more contributor + * license agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * GraphHopper GmbH licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.graphhopper.jsprit.core.algorithm.recreate.listener; + +import com.graphhopper.jsprit.core.problem.job.Job; + +import java.util.Collection; + +/** + * Created by schroeder on 06/02/17. + */ +public interface JobUnassignedListener extends InsertionListener { + + void informJobUnassigned(Job unassigned, Collection failedConstraintNames); + +} diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/ConstraintManager.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/ConstraintManager.java index dcd19cd6..1275f825 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/ConstraintManager.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/constraint/ConstraintManager.java @@ -37,6 +37,7 @@ import java.util.List; */ public class ConstraintManager implements HardActivityConstraint, HardRouteConstraint, SoftActivityConstraint, SoftRouteConstraint { + public static enum Priority { CRITICAL, HIGH, LOW } @@ -45,7 +46,7 @@ public class ConstraintManager implements HardActivityConstraint, HardRouteConst private HardActivityLevelConstraintManager actLevelConstraintManager = new HardActivityLevelConstraintManager(); - private HardRouteLevelConstraintManager routeLevelConstraintManager = new HardRouteLevelConstraintManager(); + private HardRouteLevelConstraintManager hardRouteConstraintManager = new HardRouteLevelConstraintManager(); private SoftActivityConstraintManager softActivityConstraintManager = new SoftActivityConstraintManager(); @@ -76,6 +77,25 @@ public class ConstraintManager implements HardActivityConstraint, HardRouteConst resolveConstraints(constraints); } + public Collection getHardRouteConstraints() { + return hardRouteConstraintManager.getConstraints(); + } + + public Collection getCriticalHardActivityConstraints() { + return actLevelConstraintManager.getCriticalConstraints(); + } + + public Collection getHighPrioHardActivityConstraints() { + return actLevelConstraintManager.getHighPrioConstraints(); + } + + public Collection getLowPrioHardActivityConstraints() { + return actLevelConstraintManager.getLowPrioConstraints(); + } +// public Collection getHardActivityConstraints() { +// return actLevelConstraintManager.g; +// } + public DependencyType[] getDependencyTypes() { return dependencyTypes; } @@ -103,7 +123,7 @@ public class ConstraintManager implements HardActivityConstraint, HardRouteConst constraintTypeKnown = true; } if (c instanceof HardRouteConstraint) { - routeLevelConstraintManager.addConstraint((HardRouteConstraint) c); + hardRouteConstraintManager.addConstraint((HardRouteConstraint) c); constraintTypeKnown = true; } if (c instanceof SoftRouteConstraint) { @@ -152,7 +172,7 @@ public class ConstraintManager implements HardActivityConstraint, HardRouteConst } public void addConstraint(HardRouteConstraint routeLevelConstraint) { - routeLevelConstraintManager.addConstraint(routeLevelConstraint); + hardRouteConstraintManager.addConstraint(routeLevelConstraint); } public void addConstraint(SoftActivityConstraint softActivityConstraint) { @@ -165,7 +185,7 @@ public class ConstraintManager implements HardActivityConstraint, HardRouteConst @Override public boolean fulfilled(JobInsertionContext insertionContext) { - return routeLevelConstraintManager.fulfilled(insertionContext); + return hardRouteConstraintManager.fulfilled(insertionContext); } @Override @@ -176,7 +196,7 @@ public class ConstraintManager implements HardActivityConstraint, HardRouteConst public Collection getConstraints() { List constraints = new ArrayList(); constraints.addAll(actLevelConstraintManager.getAllConstraints()); - constraints.addAll(routeLevelConstraintManager.getConstraints()); + constraints.addAll(hardRouteConstraintManager.getConstraints()); constraints.addAll(softActivityConstraintManager.getConstraints()); constraints.addAll(softRouteConstraintManager.getConstraints()); return Collections.unmodifiableCollection(constraints); diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java index 70dd2ee3..9713744a 100644 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java +++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java @@ -178,7 +178,7 @@ public class ShipmentInsertionCalculatorTest { insertionCalculator.setJobActivityFactory(activityFactory); InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE); - assertEquals(InsertionData.createEmptyInsertionData(), iData); + assertTrue(iData instanceof InsertionData.NoInsertionFound); }