示例#1
0
std::vector<std::vector<SearchParameters> > Controller::runRouteSearch(SearchParameters parameters)
{
    std::vector<std::vector<Path> > result = routeSearcher.searchRoutes(parameters.getStart(), parameters.getFinish(),
                               parameters.toRouteCost());

    std::vector<std::vector<SearchParameters> > routes;
    std::vector<std::vector<Path> >::iterator it;
    for (it = result.begin(); it != result.end(); it++)
    {
        std::vector<Path> current = (*it);
        std::vector<SearchParameters> route = std::vector<SearchParameters>();
        for (std::vector<Path>::iterator iter = current.begin(); iter != current.end(); ++iter)
        {
            SearchParameters routeParams;
            routeParams.setStart(iter->getFrom().getId());
            routeParams.setFinish(iter->getTo().getId());
            routeParams.setMoney(parameters.getTravellersNumber()*(iter->getRouteCost().getMoneyCost()));
            routeParams.setTime(iter->getRouteCost().getTimeCost());
            std::set<Interest> interests = iter->getRouteCost().getInterests();
            std::set<Transport> transports = iter->getRouteCost().getTransport();
            for (std::set<Interest>::iterator i = interests.begin(); i != interests.end(); ++i)
            {
                routeParams.addInterest(*i);
            }

            for (std::set<Transport>::iterator i = transports.begin(); i != transports.end(); ++i)
            {
                routeParams.addTransport(*i);
            }
            route.emplace_back(routeParams);
        }
        routes.emplace_back(route);
    }
    return routes;
}
示例#2
0
void MainWindow::showFullInfo() {
    QPushButton* b = qobject_cast<QPushButton *>(sender());
    int index = b->property("index").toInt();

    std::vector<SearchParameters> path = vvPaths.at(index);

    QString startName = QString::fromStdString(CityMap::Instance().getPlaceById(path.at(0).getStart()).getName());
    QString finishName = QString::fromStdString(CityMap::Instance().getPlaceById(path.at(path.size() - 1).getFinish()).getName());

    QString cost = QString::number(MainWindow::defineCost(path));
    QString duration = MainWindow::defineDuration(path).toString();

    std::vector<QString> stopsList;
    for(int i = 0; i < path.size(); i++) {
        SearchParameters sp = path.at(i);
        QString stopName = QString::fromStdString(CityMap::Instance().getPlaceById(sp.getStart()).getName());
        stopsList.push_back(stopName);
    }
//    for(int i = 0; i < routesTableItem.pathVector.size(); i++) {
//        SearchParameters searchParams = routesTableItem.pathVector.at(i);
//        std::string str = CityMap::Instance().getPlaceById(searchParams.getStart()).getName();
//        stopsList.push_back(QString::fromStdString(str));
//    }
    stopsList.push_back(finishName);

    QString stopsStr;
    for(int i = 0; i < stopsList.size();i++) {
        stopsStr += QString::number(i+1);
        stopsStr += ") ";
        stopsStr += stopsList.at(i);
        stopsStr += "\n";
    }

    QMessageBox::information(this, "Информация о маршруте",
                             QString("\nИз: ") + startName +
                             QString("\nВ: ") + finishName +
                             QString("\nСтоимость: ") + cost +
                             QString("\nВремя: ") + duration +
                             QString("\nОстановки: \n") +
                             stopsStr);

}