在Optaplanner中使用点之间的真实距离 [英] Using real distances between points in optaplanner

查看:65
本文介绍了在Optaplanner中使用点之间的真实距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


你好

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

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

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

注意:我的矩阵大约是2X10X10到2X100X100.

提前谢谢.

opp


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

推荐答案

这就是我的方法.可能有比这更好的解决方案-我必须承认,我才刚刚开始使用Optaplanner. 欢迎提出任何改进建议.

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

我的矩阵的格式为从客户"到客户"距离",并创建了一个距离类. **在导入器中,我为每个位置构建一个DistanceMap: *

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

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

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

这篇关于在Optaplanner中使用点之间的真实距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆