46 if (tour.
cities.empty())
return total_cost;
48 auto prev_id = tour.
cities.front();
49 for (
const auto &
id : tour.
cities) {
50 if (
id == tour.
cities.front())
continue;
54 total_cost +=
costs[prev_id][id];
65 ids.reserve(data_costs.size() * 2);
66 for (
const auto &cost : data_costs) {
67 ids.push_back(cost.from_vid);
68 ids.push_back(cost.to_vid);
70 std::sort(
ids.begin(),
ids.end());
71 ids.erase(std::unique(
ids.begin(),
ids.end()),
ids.end());
80 for (
const auto &i :
ids) {
81 if (i ==
id)
return true;
94 for (
size_t pos = 0; pos <
ids.size(); ++pos) {
95 if (
ids[pos] ==
id)
return pos;
97 throw std::make_pair(std::string(
"(INTERNAL) Dmatrix: Unable to find node on matrix"),
id);
114 (std::numeric_limits<double>::max)()));
116 for (
const auto &data : data_costs) {
120 for (
size_t i = 0; i <
costs.size(); ++i) {
127 get_distance(std::pair<double, double> p1 , std::pair<double, double> p2) {
128 auto dx = p1.first - p2.first;
129 auto dy = p1.second - p2.second;
130 return std::sqrt(dx * dx + dy * dy);
137 ids.reserve(euclidean_data.size());
138 for (
const auto &e: euclidean_data) {
139 ids.push_back(e.second);
145 (std::numeric_limits<double>::max)()));
147 for (
const auto &from : euclidean_data) {
148 for (
const auto &to : euclidean_data) {
152 costs[to_id][from_id] =
costs[from_id][to_id];
156 for (
size_t i = 0; i <
costs.size(); ++i) {
163 for (
const auto &row :
costs) {
164 for (
const auto &val : row) {
165 if (val == (std::numeric_limits<double>::infinity)())
return false;
166 if (val == (std::numeric_limits<double>::max)())
return false;
182 for (
size_t i = 0; i <
costs.size(); ++i) {
183 for (
size_t j = 0; j <
costs.size(); ++j) {
184 for (
size_t k = 0; k <
costs.size(); ++k) {
194 for (
size_t i = 0; i <
costs.size(); ++i) {
195 for (
size_t j = 0; j <
costs.size(); ++j) {
196 if (0.000001 < std::fabs(
costs[i][j] -
costs[j][i])) {
197 std::ostringstream log;
200 <<
"costs[i][j] \t" <<
costs[i][j]
201 <<
"costs[j][i] \t" <<
costs[j][i]
217 for (
const auto id : matrix.
ids) {
222 for (
const auto &row : matrix.
costs) {
224 for (
const auto cost : row) {
225 log <<
"Internal(" << i <<
"," << j <<
")"
226 <<
"\tUsers(" << matrix.
ids[i] <<
"," << matrix.
ids[j] <<
")"
231 <<
"\t = " << matrix.
costs[i][j]
232 <<
"\t = " << matrix.
costs[j][i]
234 << (matrix.
costs[i][j] ==
235 (std::numeric_limits<double>::infinity)())
237 << (matrix.
costs[j][i] ==
238 (std::numeric_limits<double>::infinity)())
246 for (
size_t i = 0; i < matrix.
costs.size(); ++i) {
247 for (
size_t j = 0; j < matrix.
costs.size(); ++j) {
248 for (
size_t k = 0; k < matrix.
costs.size(); ++k) {
249 log << matrix.
costs[i][k] <<
" <= ("
250 << matrix.
costs[i][j] <<
" + " << matrix.
costs[j][k] <<
")"
251 << (matrix.
costs[i][k]