问题
Hello
I am new to optaplanner. I am trying to use the vrp (tw) example.
I'll like to set real distances (route distances) in order to get a real solution.
I have real distances between all points in a double NXN matrix (distance(a,b)<>distance(b,a)), so, how can I use the matrix in the .xml (.vrp) input file to solve vrp problem ?
Note : my matrix is about from 2X10X10 to 2X100X100.
Thanks in advance.
opp
回答1:
Here is the way I went. There might be much better solutions than this - I have to admit that I just started to play around with Optaplanner. Any suggestions on improvement are welcomed.
Hope this helps. Brgds, Paul
My matrix is in the form "From Customer" "To Customer" "Distance" and I created a class Distance. *In the Importer I build a DistanceMap for each Location:*
readConstantLine("CustFrom CustTo Distance");
long locationId = -1;
line = bufferedReader.readLine();
distanceMap = new HashMap<Long, Double>(locationListSize);
while (line != null && !line.trim().isEmpty()) {
String[] lineTokens = splitBySpacesOrTabs(line.trim(), 3);
if (locationId != Long.parseLong(lineTokens[0])){
if (distanceMap.isEmpty() == false){
Location location = new Location();
location = locationList.get((int) locationId);
distance.setDistanceMap(distanceMap);
location.setDistance(distance);
locationList.set((int) locationId, location);
}
locationId = Long.parseLong(lineTokens[0]);
distance = new Distance();
distanceMap = new HashMap<Long, Double>(locationListSize);
}
distanceMap.put( Long.parseLong(lineTokens[1]), Double.parseDouble(lineTokens[2]));
line = bufferedReader.readLine();
}
if (distanceMap.isEmpty() == false){
Location location = new Location();
location = locationList.get((int) locationId);
distance.setDistanceMap(distanceMap);
location.setDistance(distance);
locationList.set((int) locationId, location);
In the location class I use the following method to get the Distance:
public int getMilliDistanceDistanceMap(Location location) {
// Implementation distanceMap
return distance.getDistance(location, this) ;
And the distance class method looks like this:
public int getDistance(Location fromLocation,Location toLocation )
{
double distance = toLocation.getDistance().distanceMap.get(fromLocation.getId());
return (int) (distance * 1000);
}
回答2:
As of 2019, start from optaweb-vehicle-routing
来源:https://stackoverflow.com/questions/21455751/using-real-distances-between-points-in-optaplanner