1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

add_user_data_to_vehicle_type_id (#71)

* add_user_data_to_vehicle_type_id

* add in to string

* tetss
This commit is contained in:
kandelirina 2018-11-11 08:48:42 +02:00 committed by GitHub
parent c75cd5df9e
commit d1368284ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View file

@ -364,7 +364,7 @@ public class VehicleImpl extends AbstractVehicle {
aBreak = builder.aBreak;
prohibitedTasks = builder.prohibitedTasks;
// setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills));
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot));
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot, getUserData()));
}
/**

View file

@ -20,6 +20,8 @@ package com.graphhopper.jsprit.core.problem.vehicle;
import com.graphhopper.jsprit.core.problem.AbstractVehicle;
import com.graphhopper.jsprit.core.problem.Skills;
import java.util.Objects;
/**
* Key to identify similar vehicles
* <p>
@ -36,8 +38,9 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
public final double latestEnd;
public final Skills skills;
public final boolean returnToDepot;
public final Object userData;
public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills, boolean returnToDepot) {
public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills, boolean returnToDepot, Object userData) {
super();
this.type = typeId;
this.startLocationId = startLocationId;
@ -46,6 +49,11 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
this.latestEnd = latestEnd;
this.skills = skills;
this.returnToDepot = returnToDepot;
this.userData = userData;
}
public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills, boolean returnToDepot) {
this(typeId, startLocationId, endLocationId, earliestStart, latestEnd, skills, returnToDepot, null);
}
@Override
@ -62,6 +70,7 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
if (!skills.equals(that.skills)) return false;
if (!startLocationId.equals(that.startLocationId)) return false;
if (!type.equals(that.type)) return false;
if (!Objects.equals(that.userData, this.userData)) return false;
return true;
}
@ -79,6 +88,9 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + skills.hashCode();
result = 31 * result + (returnToDepot ? 1 : 0);
if (userData != null)
result = 31 * result + userData.hashCode();
return result;
}
@ -87,6 +99,8 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(type).append("_").append(startLocationId).append("_").append(endLocationId)
.append("_").append(Double.toString(earliestStart)).append("_").append(Double.toString(latestEnd));
if (userData != null)
stringBuilder.append("_").append(userData.toString());
return stringBuilder.toString();
}

View file

@ -44,4 +44,22 @@ public class VehicleTypeKeyTest {
.addSkill("skill3").build();
assertFalse(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier()));
}
@Test
public void typeIdentifierShouldBeEqual2() {
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).addSkill("skill1").addSkill("skill2")
.setUserData(new String("it's just a test")).build();
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("start")).addSkill("skill1").addSkill("skill2")
.setUserData(new String("it's just a test")).build();
assertTrue(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier()));
}
@Test
public void typeIdentifierShouldNotBeEqual2() {
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).addSkill("skill1").addSkill("skill2")
.setUserData(new String("it's just a test")).build();
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("start")).addSkill("skill1").addSkill("skill2")
.setUserData(new String("it's just stupid test")).build();
assertFalse(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier()));
}
}