本文整理汇总了C++中Solver::addPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Solver::addPoint方法的具体用法?C++ Solver::addPoint怎么用?C++ Solver::addPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solver
的用法示例。
在下文中一共展示了Solver::addPoint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process_coordinates
/**
* @param The given data points
* @return Some processing on this data (possibly)
*/
MapPoints* process_coordinates(MapPoints* map_points,
TravelTimeComputer* time_computer) {
std::vector<Coordinate*> points;
points.push_back(map_points->origin);
for (const auto& it : *map_points->errands) {
points.push_back(it);
}
transit_type transit_matrix[points.size()][points.size()];
Solver * solver;
if (map_points->algorithm_to_use == "gtsp") {
solver = new GtspSolver();
} else {
solver = new TspSolver();
}
solver->setNumberOfNodes(points.size());
for (int i = 0; i < points.size(); i++) {
for (int j = 0 ; j < points.size(); j++) {
std::pair<double, transit_type> best_time = time_computer->find_time(*points[i], *points[j]);
solver->addPoint(i, j, best_time.first);
transit_matrix[i][j] = best_time.second;
}
}
solver->setStartingPoint(0);
if (map_points->algorithm_to_use == "gtsp") {
for (int i = 0; i < points.size(); i++) {
solver->setGroupForNode(i, points[i]->group);
}
}
std::vector<int>* nodesOrder = solver->solve();
int last_point = nodesOrder->at(0);
std::vector<Coordinate*>* ordered_errands = new std::vector<Coordinate*>();
for (int i = 1; i < nodesOrder->size(); i++) {
int current_point = nodesOrder->at(i);
points[current_point]->transit = transit_matrix[last_point][current_point];
ordered_errands->push_back(points[current_point]);
last_point = current_point;
}
map_points->errands = ordered_errands;
map_points->destination->transit = transit_matrix[last_point][nodesOrder->at(0)];
return map_points;
}