mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
comply with .editorconfig
This commit is contained in:
parent
58afc3590d
commit
33075b479f
416 changed files with 29653 additions and 29979 deletions
|
|
@ -43,11 +43,10 @@ import java.util.Collection;
|
|||
|
||||
/**
|
||||
* Illustrates dependencies between jobs.
|
||||
*
|
||||
* <p/>
|
||||
* The hard requirement here is that three jobs with name "get key", "use key" and "deliver key" need to
|
||||
* be not only in loose sequence in one particular route but also one after another (without any other activities
|
||||
* between them).
|
||||
*
|
||||
*/
|
||||
public class JobAndActivityDependenciesExample {
|
||||
|
||||
|
|
@ -78,19 +77,18 @@ public class JobAndActivityDependenciesExample {
|
|||
|
||||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
if(((TourActivity.JobActivity)activity).getJob().getName().equals("use key")) {
|
||||
if (((TourActivity.JobActivity) activity).getJob().getName().equals("use key")) {
|
||||
stateManager.putProblemState(keyUsedStateId, VehicleRoute.class, route);
|
||||
}
|
||||
else if(((TourActivity.JobActivity)activity).getJob().getName().equals("get key")) {
|
||||
} else if (((TourActivity.JobActivity) activity).getJob().getName().equals("get key")) {
|
||||
stateManager.putProblemState(keyPickedStateId, VehicleRoute.class, route);
|
||||
}
|
||||
else if(((TourActivity.JobActivity)activity).getJob().getName().equals("deliver key")) {
|
||||
} else if (((TourActivity.JobActivity) activity).getJob().getName().equals("deliver key")) {
|
||||
stateManager.putProblemState(keyDeliveredStateId, VehicleRoute.class, route);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
public void finish() {
|
||||
}
|
||||
}
|
||||
|
||||
static class GetUseAndDeliverHardRouteContraint implements HardRouteConstraint {
|
||||
|
|
@ -112,20 +110,20 @@ public class JobAndActivityDependenciesExample {
|
|||
|
||||
@Override
|
||||
public boolean fulfilled(JobInsertionContext iFacts) {
|
||||
if(iFacts.getJob().getName().equals("get key") || iFacts.getJob().getName().equals("use key")
|
||||
|| iFacts.getJob().getName().equals("deliver key")){
|
||||
if (iFacts.getJob().getName().equals("get key") || iFacts.getJob().getName().equals("use key")
|
||||
|| iFacts.getJob().getName().equals("deliver key")) {
|
||||
VehicleRoute routeOfPickupKey = stateManager.getProblemState(keyPickedStateId, VehicleRoute.class);
|
||||
VehicleRoute routeOfUseKey = stateManager.getProblemState(keyUsedStateId, VehicleRoute.class);
|
||||
VehicleRoute routeOfDeliverKey = stateManager.getProblemState(keyDeliveredStateId, VehicleRoute.class);
|
||||
|
||||
if( routeOfPickupKey != null ){
|
||||
if( routeOfPickupKey != iFacts.getRoute() ) return false;
|
||||
if (routeOfPickupKey != null) {
|
||||
if (routeOfPickupKey != iFacts.getRoute()) return false;
|
||||
}
|
||||
if( routeOfUseKey != null ){
|
||||
if( routeOfUseKey != iFacts.getRoute() ) return false;
|
||||
if (routeOfUseKey != null) {
|
||||
if (routeOfUseKey != iFacts.getRoute()) return false;
|
||||
}
|
||||
if( routeOfDeliverKey != null ) {
|
||||
if( routeOfDeliverKey != iFacts.getRoute() ) return false;
|
||||
if (routeOfDeliverKey != null) {
|
||||
if (routeOfDeliverKey != iFacts.getRoute()) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -157,50 +155,50 @@ public class JobAndActivityDependenciesExample {
|
|||
VehicleRoute routeOfUseKey = stateManager.getProblemState(keyUsedStateId, VehicleRoute.class);
|
||||
VehicleRoute routeOfDeliverKey = stateManager.getProblemState(keyDeliveredStateId, VehicleRoute.class);
|
||||
|
||||
if( !isPickupKey(newAct) && !isUseKey(newAct) && !isDeliverKey(newAct) ){
|
||||
if(isPickupKey(prevAct) && isUseKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if(isPickupKey(prevAct) && isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if(isUseKey(prevAct) && isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if (!isPickupKey(newAct) && !isUseKey(newAct) && !isDeliverKey(newAct)) {
|
||||
if (isPickupKey(prevAct) && isUseKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if (isPickupKey(prevAct) && isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if (isUseKey(prevAct) && isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
if( isPickupKey(newAct) ) {
|
||||
if ( routeOfUseKey != null){
|
||||
if ( !isUseKey(nextAct) ) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if (isPickupKey(newAct)) {
|
||||
if (routeOfUseKey != null) {
|
||||
if (!isUseKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
if ( routeOfDeliverKey != null ){
|
||||
if ( !isDeliverKey( nextAct )) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if (routeOfDeliverKey != null) {
|
||||
if (!isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
if( isUseKey(newAct) ) {
|
||||
if ( routeOfPickupKey != null ) {
|
||||
if ( !isPickupKey(prevAct) ) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if (isUseKey(newAct)) {
|
||||
if (routeOfPickupKey != null) {
|
||||
if (!isPickupKey(prevAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
if ( routeOfDeliverKey != null ) {
|
||||
if ( !isDeliverKey(nextAct) ) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if (routeOfDeliverKey != null) {
|
||||
if (!isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
if( isDeliverKey(newAct) ){
|
||||
if( routeOfUseKey != null ) {
|
||||
if ( !isUseKey(prevAct) ) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if (isDeliverKey(newAct)) {
|
||||
if (routeOfUseKey != null) {
|
||||
if (!isUseKey(prevAct)) return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
}
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
||||
private boolean isPickupKey(TourActivity act) {
|
||||
if(!(act instanceof TourActivity.JobActivity)) return false;
|
||||
return ((TourActivity.JobActivity)act).getJob().getName().equals("get key");
|
||||
if (!(act instanceof TourActivity.JobActivity)) return false;
|
||||
return ((TourActivity.JobActivity) act).getJob().getName().equals("get key");
|
||||
}
|
||||
|
||||
private boolean isUseKey(TourActivity act) {
|
||||
if(!(act instanceof TourActivity.JobActivity)) return false;
|
||||
return ((TourActivity.JobActivity)act).getJob().getName().equals("use key");
|
||||
if (!(act instanceof TourActivity.JobActivity)) return false;
|
||||
return ((TourActivity.JobActivity) act).getJob().getName().equals("use key");
|
||||
}
|
||||
|
||||
private boolean isDeliverKey(TourActivity act) {
|
||||
if(!(act instanceof TourActivity.JobActivity)) return false;
|
||||
return ((TourActivity.JobActivity)act).getJob().getName().equals("deliver key");
|
||||
if (!(act instanceof TourActivity.JobActivity)) return false;
|
||||
return ((TourActivity.JobActivity) act).getJob().getName().equals("deliver key");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -209,54 +207,54 @@ public class JobAndActivityDependenciesExample {
|
|||
public static void main(String[] args) {
|
||||
|
||||
VehicleImpl driver1 = VehicleImpl.Builder.newInstance("driver1")
|
||||
.addSkill("driver1")
|
||||
.setStartLocation(Location.newInstance(0, 0)).setReturnToDepot(false).build();
|
||||
.addSkill("driver1")
|
||||
.setStartLocation(Location.newInstance(0, 0)).setReturnToDepot(false).build();
|
||||
|
||||
VehicleImpl driver3 = VehicleImpl.Builder.newInstance("driver3")
|
||||
.addSkill("driver3")
|
||||
.setStartLocation(Location.newInstance(-3, 5)).setReturnToDepot(true).build();
|
||||
.addSkill("driver3")
|
||||
.setStartLocation(Location.newInstance(-3, 5)).setReturnToDepot(true).build();
|
||||
|
||||
Service s1 = Service.Builder.newInstance("s1")
|
||||
.addRequiredSkill("driver1")
|
||||
.setName("install new device")
|
||||
.setLocation(Location.newInstance(2, 2)).build();
|
||||
.addRequiredSkill("driver1")
|
||||
.setName("install new device")
|
||||
.setLocation(Location.newInstance(2, 2)).build();
|
||||
Service s2 = Service.Builder.newInstance("s2")
|
||||
.addRequiredSkill("driver3")
|
||||
.setName("deliver key")
|
||||
.setLocation(Location.newInstance(2, 4)).build();
|
||||
.addRequiredSkill("driver3")
|
||||
.setName("deliver key")
|
||||
.setLocation(Location.newInstance(2, 4)).build();
|
||||
|
||||
Service s3 = Service.Builder.newInstance("s3")
|
||||
.addRequiredSkill("driver1")
|
||||
.setName("repair heater")
|
||||
.setLocation(Location.newInstance(-2, 2)).build();
|
||||
.addRequiredSkill("driver1")
|
||||
.setName("repair heater")
|
||||
.setLocation(Location.newInstance(-2, 2)).build();
|
||||
|
||||
Service s4 = Service.Builder.newInstance("s4")
|
||||
.addRequiredSkill("driver3")
|
||||
.setName("get key")
|
||||
.setLocation(Location.newInstance(-2.3, 4)).build();
|
||||
.addRequiredSkill("driver3")
|
||||
.setName("get key")
|
||||
.setLocation(Location.newInstance(-2.3, 4)).build();
|
||||
|
||||
Service s5 = Service.Builder.newInstance("s5")
|
||||
.addRequiredSkill("driver1")
|
||||
.setName("cleaning")
|
||||
.setLocation(Location.newInstance(1, 5)).build();
|
||||
.addRequiredSkill("driver1")
|
||||
.setName("cleaning")
|
||||
.setLocation(Location.newInstance(1, 5)).build();
|
||||
|
||||
Service s6 = Service.Builder.newInstance("s6")
|
||||
.addRequiredSkill("driver3")
|
||||
.setName("use key")
|
||||
.setLocation(Location.newInstance(-2, 3)).build();
|
||||
.addRequiredSkill("driver3")
|
||||
.setName("use key")
|
||||
.setLocation(Location.newInstance(-2, 3)).build();
|
||||
|
||||
Service s7 = Service.Builder.newInstance("s7")
|
||||
.addRequiredSkill("driver3")
|
||||
.setName("maintenance")
|
||||
.setLocation(Location.newInstance(-1.7, 3.5)).build();
|
||||
.addRequiredSkill("driver3")
|
||||
.setName("maintenance")
|
||||
.setLocation(Location.newInstance(-1.7, 3.5)).build();
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
|
||||
.addJob(s1).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7)
|
||||
.addVehicle(driver1).addVehicle(driver3);
|
||||
.addJob(s1).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7)
|
||||
.addVehicle(driver1).addVehicle(driver3);
|
||||
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"input/algorithmConfig.xml");
|
||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/algorithmConfig.xml");
|
||||
vraBuilder.addDefaultCostCalculators();
|
||||
vraBuilder.addCoreConstraints();
|
||||
|
||||
|
|
@ -264,13 +262,13 @@ public class JobAndActivityDependenciesExample {
|
|||
StateId keyPicked = stateManager.createStateId("key-picked");
|
||||
StateId keyUsed = stateManager.createStateId("key-used");
|
||||
StateId keyDelivered = stateManager.createStateId("key-delivered");
|
||||
stateManager.addStateUpdater(new KeyStatusUpdater(stateManager,keyPicked,keyUsed,keyDelivered));
|
||||
stateManager.addStateUpdater(new KeyStatusUpdater(stateManager, keyPicked, keyUsed, keyDelivered));
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addConstraint(new GetUseAndDeliverKeySimpleHardActivityConstraint(stateManager,keyPicked,keyUsed,keyDelivered), ConstraintManager.Priority.CRITICAL);
|
||||
constraintManager.addConstraint(new GetUseAndDeliverHardRouteContraint(stateManager,keyPicked,keyUsed,keyDelivered));
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
|
||||
constraintManager.addConstraint(new GetUseAndDeliverKeySimpleHardActivityConstraint(stateManager, keyPicked, keyUsed, keyDelivered), ConstraintManager.Priority.CRITICAL);
|
||||
constraintManager.addConstraint(new GetUseAndDeliverHardRouteContraint(stateManager, keyPicked, keyUsed, keyDelivered));
|
||||
|
||||
vraBuilder.setStateAndConstraintManager(stateManager,constraintManager);
|
||||
vraBuilder.setStateAndConstraintManager(stateManager, constraintManager);
|
||||
VehicleRoutingAlgorithm vra = vraBuilder.build();
|
||||
vra.setMaxIterations(100);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue