Update tsp.cc & vrp.cc
This commit is contained in:
@@ -18,8 +18,8 @@
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
|
||||
namespace operations_research {
|
||||
struct DataProblem {
|
||||
DataProblem()
|
||||
struct DataModel {
|
||||
DataModel()
|
||||
: locations({{4, 4},
|
||||
{2, 0},
|
||||
{8, 0},
|
||||
@@ -57,7 +57,7 @@ struct DataProblem {
|
||||
* @details It uses the data.locations to computes the Manhattan distance
|
||||
* between the two positions of two different indices.*/
|
||||
std::vector<std::vector<int64>> GenerateManhattanDistanceMatrix(
|
||||
const DataProblem& data) {
|
||||
const DataModel& data) {
|
||||
std::vector<std::vector<int64>> distances = std::vector<std::vector<int64>>(
|
||||
data.num_locations, std::vector<int64>(data.num_locations, 0LL));
|
||||
for (int fromNode = 0; fromNode < data.num_locations; fromNode++) {
|
||||
@@ -73,11 +73,10 @@ std::vector<std::vector<int64>> GenerateManhattanDistanceMatrix(
|
||||
// [END manhattan_distance_matrix]
|
||||
|
||||
//! @brief Print the solution
|
||||
//! @param[in] data Data of the problem.
|
||||
//! @param[in] manager Index manager used.
|
||||
//! @param[in] routing Routing solver used.
|
||||
//! @param[in] solution Solution found by the solver.
|
||||
void PrintSolution(const DataProblem& data, const RoutingIndexManager& manager,
|
||||
void PrintSolution(const RoutingIndexManager& manager,
|
||||
const RoutingModel& routing, const Assignment& solution) {
|
||||
LOG(INFO) << "Objective: " << solution.ObjectiveValue();
|
||||
// Inspect solution.
|
||||
@@ -101,7 +100,7 @@ void PrintSolution(const DataProblem& data, const RoutingIndexManager& manager,
|
||||
|
||||
void Solve() {
|
||||
// Instantiate the data problem.
|
||||
DataProblem data;
|
||||
DataModel data;
|
||||
|
||||
// Create Routing Index Manager & Routing Model
|
||||
RoutingIndexManager manager(data.num_locations, data.num_vehicles,
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
#include "ortools/constraint_solver/routing_parameters.h"
|
||||
|
||||
namespace operations_research {
|
||||
class DataProblem {
|
||||
class DataModel {
|
||||
private:
|
||||
std::vector<std::vector<int>> locations_;
|
||||
|
||||
public:
|
||||
DataProblem() {
|
||||
DataModel() {
|
||||
locations_ = {
|
||||
{4, 4},
|
||||
{2, 0}, {8, 0},
|
||||
@@ -61,7 +61,7 @@ namespace operations_research {
|
||||
private:
|
||||
std::vector<std::vector<int64>> distances_;
|
||||
public:
|
||||
ManhattanDistance(const DataProblem& data) {
|
||||
ManhattanDistance(const DataModel& data) {
|
||||
// Precompute distance between location to have distance callback in O(1)
|
||||
distances_ = std::vector<std::vector<int64>>(
|
||||
data.GetLocations().size(),
|
||||
@@ -91,7 +91,7 @@ namespace operations_research {
|
||||
//! @param[in] data Data of the problem.
|
||||
//! @param[in] callback transit cost callback.
|
||||
//! @param[in, out] routing Routing solver used.
|
||||
static void AddDistanceDimension(const DataProblem& data, const int callback, RoutingModel* routing) {
|
||||
static void AddDistanceDimension(const DataModel& data, const int callback, RoutingModel* routing) {
|
||||
std::string distance("Distance");
|
||||
routing->AddDimension(
|
||||
callback,
|
||||
@@ -111,7 +111,7 @@ namespace operations_research {
|
||||
//! @param[in] routing Routing solver used.
|
||||
//! @param[in] solution Solution found by the solver.
|
||||
void PrintSolution(
|
||||
const DataProblem& data,
|
||||
const DataModel& data,
|
||||
const RoutingIndexManager& manager,
|
||||
const RoutingModel& routing,
|
||||
const Assignment& solution) {
|
||||
@@ -138,7 +138,7 @@ namespace operations_research {
|
||||
|
||||
void Solve() {
|
||||
// Instantiate the data problem.
|
||||
DataProblem data;
|
||||
DataModel data;
|
||||
|
||||
// Create Routing Index Manager & Routing Model
|
||||
RoutingIndexManager manager(
|
||||
|
||||
Reference in New Issue
Block a user