mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add unassigned job listener - related to #180
This commit is contained in:
parent
a2787ca390
commit
ba6dbfae45
4 changed files with 67 additions and 6 deletions
|
|
@ -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<String> reasons) {
|
||||
for (InsertionListener l : listeners) {
|
||||
if (l instanceof JobUnassignedListener) {
|
||||
((JobUnassignedListener) l).informJobUnassigned(unassigned, reasons);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(InsertionListener insertionListener) {
|
||||
listeners.add(insertionListener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<String> failedConstraintNames);
|
||||
|
||||
}
|
||||
|
|
@ -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<HardRouteConstraint> getHardRouteConstraints() {
|
||||
return hardRouteConstraintManager.getConstraints();
|
||||
}
|
||||
|
||||
public Collection<HardActivityConstraint> getCriticalHardActivityConstraints() {
|
||||
return actLevelConstraintManager.getCriticalConstraints();
|
||||
}
|
||||
|
||||
public Collection<HardActivityConstraint> getHighPrioHardActivityConstraints() {
|
||||
return actLevelConstraintManager.getHighPrioConstraints();
|
||||
}
|
||||
|
||||
public Collection<HardActivityConstraint> getLowPrioHardActivityConstraints() {
|
||||
return actLevelConstraintManager.getLowPrioConstraints();
|
||||
}
|
||||
// public Collection<HardActivityConstraint> 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<Constraint> getConstraints() {
|
||||
List<Constraint> constraints = new ArrayList<Constraint>();
|
||||
constraints.addAll(actLevelConstraintManager.getAllConstraints());
|
||||
constraints.addAll(routeLevelConstraintManager.getConstraints());
|
||||
constraints.addAll(hardRouteConstraintManager.getConstraints());
|
||||
constraints.addAll(softActivityConstraintManager.getConstraints());
|
||||
constraints.addAll(softRouteConstraintManager.getConstraints());
|
||||
return Collections.unmodifiableCollection(constraints);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue