Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
418 views
in Technique[技术] by (71.8m points)

optaweb vehicle routing - Using real distances between points in optaplanner


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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...