【问题标题】:Using real distances between points in optaplanner在 optaplanner 中使用点之间的实际距离
【发布时间】:2014-01-30 11:51:42
【问题描述】:


你好

我是 optaplanner 的新手。我正在尝试使用 vrp (tw) 示例。

我想设置实际距离(路线距离)以获得真正的解决方案。

我在双 NXN 矩阵中的所有点之间都有实际距离(距离(a,b) 距离(b,a)),所以,我如何使用 .xml(.vrp)输入文件中的矩阵来解决 vrp问题?

注意:我的矩阵大约从 2X10X10 到 2X100X100。

提前致谢。

呵呵

【问题讨论】:

标签: optaplanner optaweb-vehicle-routing


【解决方案1】:

这是我的方式。可能有比这更好的解决方案 - 我不得不承认我刚刚开始使用 Optaplanner。 欢迎提出任何改进建议。

希望这会有所帮助。 Brgds,保罗

我的矩阵采用“From Customer”“To Customer”“Distance”的形式,我创建了一个距离类。 *在 Importer 中,我为每个 Location 构建一个 DistanceMap:*

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

在位置类中,我使用以下方法获取距离:

 public int getMilliDistanceDistanceMap(Location location) {
        // Implementation distanceMap
     return distance.getDistance(location, this)  ; 

而距离类方法是这样的:

public int getDistance(Location fromLocation,Location toLocation )
{
    double distance = toLocation.getDistance().distanceMap.get(fromLocation.getId());
    return  (int) (distance * 1000);
}

【讨论】:

  • 非常感谢您的回答。我知道我们必须修改源才能应用解决方案。所以,我不是Java程序员,我会尝试编写建议的代码......最好的问候
【解决方案2】:

截至2019年,从optaweb-vehicle-routing开始

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多