私は、この サンプル コードをコアに使用するプロジェクトに取り組んでいます。カスタムの距離/時間マトリックスを使用してルーティングの問題を解決します。アルゴリズムは完全に機能しているように見えますが、出力をグラフで表示する方法が見つかりません。サンプル コードだけを変更せずに実行すると、次のようになります。
2015-07-07 11:56:33,354 [メイン] 警告 jsprit.analysis.toolbox.Plotter - 座標がないため、vrp をプロットできません
このエラーは理にかなっています。実際には場所が指定されていないため、何もプロットできません。場所間の相対的な距離/時間を指定しただけです。緯度/経度で作業しており、ポイント間の実際の道路距離が必要なため、カスタム マトリックスを使用する必要があります。ただし、問題が拡大するにつれて、各場所に緯度/経度を割り当て、これらの点をデカルト座標であるかのように扱うグラフを作成するだけで非常に役立ちます。集水域はそれほど大きくないので、より複雑なプロットを作成しなくても、解決策が理にかなっているのかどうかをすぐに確認できるはずです. だから私の質問は、カスタムの距離/時間マトリックスを使用してjspritに問題を解決させる簡単な方法があるかどうかですが、プロットの目的で座標を場所に割り当てますか? まるで分からなくて、
編集: ステファンから提案された変更があっても、私はこれに長い間取り組んできましたが、役に立ちませんでした。基本コードを変更せずにそれを行う方法を見つけることができず、それによって、既に作業しているものに連鎖的な問題が発生することは望ましくありません。
場所の構築は問題ありませんが、提案されたコードとは少し異なります。
Location.Builder.newInstance().setId("0").setCoordinate(Coordinate.newInstance(10.0, 10.0)).build();
次に、サービスを作成したいときに、現在のコードによって新しい場所を定義する必要があるという問題が発生します (場所は newInstance のみを受け入れます)。
Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(6.0, 1.0)).build();
サービスが事前定義された場所にあると簡単に言う既存の方法が見つかりません。
次に、場所を直接 VehicleRoutingProblem.Builder に追加することを考えました。ビルダーに場所を追加するには、"addLocation(String LocationID, Coordinate coordinate)" として定義する必要があるため、事前定義された場所を明示的に取得しないことに注意してください。ビルダー内で定義する必要があります。これは次のようになります。
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 5).setCostPerDistance(1).setCostPerTime(2).build();
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle")
.setStartLocation(Location.newInstance("0")).setType(type).build();
Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance("1")).build();
Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance("2")).build();
Service s3 = Service.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance("3")).build();
//define a matrix-builder building an asymmetric matrix
VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
costMatrixBuilder.addTransportDistance("0", "1", 19.13);
costMatrixBuilder.addTransportDistance("0", "2", 18.56);
costMatrixBuilder.addTransportDistance("0", "3", 21.68);
costMatrixBuilder.addTransportDistance("1", "0", 15.91);
costMatrixBuilder.addTransportDistance("1", "2", 15.01);
costMatrixBuilder.addTransportDistance("1", "3", 11.45);
costMatrixBuilder.addTransportDistance("2", "0", 19.42);
costMatrixBuilder.addTransportDistance("2", "1", 12.54);
costMatrixBuilder.addTransportDistance("2", "3", 11.13);
costMatrixBuilder.addTransportDistance("3", "0", 25.75);
costMatrixBuilder.addTransportDistance("3", "1", 9.94);
costMatrixBuilder.addTransportDistance("3", "2", 11.24);
costMatrixBuilder.addTransportTime("0", "1", 12);
costMatrixBuilder.addTransportTime("0", "2", 11);
costMatrixBuilder.addTransportTime("0", "3", 15);
costMatrixBuilder.addTransportTime("1", "0", 10);
costMatrixBuilder.addTransportTime("1", "2", 10);
costMatrixBuilder.addTransportTime("1", "3", 10);
costMatrixBuilder.addTransportTime("2", "0", 15);
costMatrixBuilder.addTransportTime("2", "1", 9);
costMatrixBuilder.addTransportTime("2", "3", 10);
costMatrixBuilder.addTransportTime("3", "0", 17);
costMatrixBuilder.addTransportTime("3", "1", 13);
costMatrixBuilder.addTransportTime("3", "2", 10);
VehicleRoutingTransportCosts costMatrix = costMatrixBuilder.build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(FleetSize.FINITE).setRoutingCost(costMatrix)
.addVehicle(vehicle).addJob(s1).addJob(s2).addJob(s3)
.addLocation("0", Coordinate.newInstance(1.0, 1.0)).addLocation("1", Coordinate.newInstance(9.0, 2.0))
.addLocation("2", Coordinate.newInstance(5.0, 4.0)).addLocation("3", Coordinate.newInstance(4.0, 8.0))
.addLocation("4", Coordinate.newInstance(3.0, 7.0)).build();`
それはうまくいきます。ただし、位置インデックスとそれらをプロットする機能との間の関連付けが行われないため、それでもプロットされません。ただし、(要求されたように) ソルバーが事前定義された costMatrix のみを使用することを確認できるため、出力された回答は依然として正しいです。