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:
parent
c75cd5df9e
commit
d1368284ac
3 changed files with 34 additions and 2 deletions
|
|
@ -364,7 +364,7 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
aBreak = builder.aBreak;
|
aBreak = builder.aBreak;
|
||||||
prohibitedTasks = builder.prohibitedTasks;
|
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));
|
||||||
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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ package com.graphhopper.jsprit.core.problem.vehicle;
|
||||||
import com.graphhopper.jsprit.core.problem.AbstractVehicle;
|
import com.graphhopper.jsprit.core.problem.AbstractVehicle;
|
||||||
import com.graphhopper.jsprit.core.problem.Skills;
|
import com.graphhopper.jsprit.core.problem.Skills;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key to identify similar vehicles
|
* Key to identify similar vehicles
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -36,8 +38,9 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
|
||||||
public final double latestEnd;
|
public final double latestEnd;
|
||||||
public final Skills skills;
|
public final Skills skills;
|
||||||
public final boolean returnToDepot;
|
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();
|
super();
|
||||||
this.type = typeId;
|
this.type = typeId;
|
||||||
this.startLocationId = startLocationId;
|
this.startLocationId = startLocationId;
|
||||||
|
|
@ -46,6 +49,11 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
|
||||||
this.latestEnd = latestEnd;
|
this.latestEnd = latestEnd;
|
||||||
this.skills = skills;
|
this.skills = skills;
|
||||||
this.returnToDepot = returnToDepot;
|
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
|
@Override
|
||||||
|
|
@ -62,6 +70,7 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
|
||||||
if (!skills.equals(that.skills)) return false;
|
if (!skills.equals(that.skills)) return false;
|
||||||
if (!startLocationId.equals(that.startLocationId)) return false;
|
if (!startLocationId.equals(that.startLocationId)) return false;
|
||||||
if (!type.equals(that.type)) return false;
|
if (!type.equals(that.type)) return false;
|
||||||
|
if (!Objects.equals(that.userData, this.userData)) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +88,9 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
|
||||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||||
result = 31 * result + skills.hashCode();
|
result = 31 * result + skills.hashCode();
|
||||||
result = 31 * result + (returnToDepot ? 1 : 0);
|
result = 31 * result + (returnToDepot ? 1 : 0);
|
||||||
|
if (userData != null)
|
||||||
|
result = 31 * result + userData.hashCode();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,6 +99,8 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
stringBuilder.append(type).append("_").append(startLocationId).append("_").append(endLocationId)
|
stringBuilder.append(type).append("_").append(startLocationId).append("_").append(endLocationId)
|
||||||
.append("_").append(Double.toString(earliestStart)).append("_").append(Double.toString(latestEnd));
|
.append("_").append(Double.toString(earliestStart)).append("_").append(Double.toString(latestEnd));
|
||||||
|
if (userData != null)
|
||||||
|
stringBuilder.append("_").append(userData.toString());
|
||||||
return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,4 +44,22 @@ public class VehicleTypeKeyTest {
|
||||||
.addSkill("skill3").build();
|
.addSkill("skill3").build();
|
||||||
assertFalse(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier()));
|
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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue