当前位置: 首页>>代码示例>>C++>>正文


C++ Solver::addPoint方法代码示例

本文整理汇总了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;
}
开发者ID:aicioara,项目名称:c3gp,代码行数:54,代码来源:map_points.cpp


注:本文中的Solver::addPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。