gpt4 book ai didi

java - 创建对称矩阵java VRP

转载 作者:行者123 更新时间:2023-11-30 03:55:12 26 4
gpt4 key购买 nike

事实上我正在从事一个车辆路线问题项目,我正在尝试生成一个问题实例。
这是一个示例,其中我们有一个仓库“0”和三个站“1”、“2”和“3”
我创建了下表:

distdata= new int[stations][(stations+1)]; // where stations is equal to number of stations

我随机填充了矩阵,并将具有相同行和列索引的单元格设置为零,因此同一站与其自身之间的距离等于零。

 System.out.println("Matrix of stations's distances : \n");
try {
BufferedWriter out2 = new BufferedWriter(new FileWriter("StationsDist.bench"));

for (int i = 0; i < stations + 1; i++) {
System.out.println("\t[" + i + "]");
}
System.out.println("\n");

for (int i = 0; i < stations; i++) {
System.out.println("\n[" + (i + 1) + "]");

for (int j = 0; j < stations + 1; j++) {
if ((i + 1) == j) {

dij = 0;
} else {
dij = (int) (Math.random() * 20) + 1;
}
System.out.println("\t[" + dij + "]");
out2.write(dij + "\t");
distdata[i][j] = dij;
distdatac[i][j] = dij;

}
out2.write("\n");
System.out.println("\n");
}


out2.close();
} catch (IOException e) {
}

我得到了这个输出:

    [0] [1] [2] [3] // [0]-> Depot, [1]-> station 1, [2]-> station 2 ...

[1] [3] [0] [7] [4] // [3] is the distance between station 1 and the depot, and [0] is the null distance between station 1 and itself ...
[2] [1] [9] [0] [6]
[3] [2] [5] [8] [0]

问题是距离 distdata[1][2] 应等于距离 distdata[2][1],因为它们表示相同的站点。
我需要创建一个对称矩阵或将表格更改为以下内容:

    [0] [1] [2] [3]

[1] [3] [0] [7] [4]
[2] [1] [7] [0] [6]
[3] [2] [4] [6] [0]

谁能帮帮我吗?

最佳答案

看看我如何实现对称和非对称传输成本矩阵 ( https://github.com/jsprit/jsprit/blob/master/jsprit-core/src/main/java/jsprit/core/util/VehicleRoutingTransportCostsMatrix.java )。这可能对您有帮助。

关于java - 创建对称矩阵java VRP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23404908/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com