Beispiel #1
0
bool CSolutionInfo::addTour(CTourInfo& tour) {
    m_vtourAll.push_back(tour);
    int vid = tour.getVehicleId();
    std::vector<int>::iterator it;
    it = std::find(m_vUnusedVehicles.begin(), m_vUnusedVehicles.end(), vid);
    if (it != m_vUnusedVehicles.end()) {
        m_vUnusedVehicles.erase(it);
    }
    m_iVehicleUsed++;
    m_dTotalDistance += tour.getDistance();
    m_dTotalTravelTime += tour.getTravelTime();
    m_dTotalCost += tour.getCost();

    std::vector<int> vecOrders = tour.getOrderVector();

    m_iOrdersServed += static_cast<int>(vecOrders.size());

    for (const auto &order : vecOrders) {
        int oid = order;
        it = std::find(m_vUnservedOrderId.begin(), m_vUnservedOrderId.end(), oid);
        if (it != m_vUnservedOrderId.end()) {
            m_vUnservedOrderId.erase(it);
        }
    }

    return true;
}
Beispiel #2
0
CostPack CVRPSolver::getCostForInsert(CTourInfo& curTour, COrderInfo& curOrder, int pos) {
    std::vector<int> vecOrderId = curTour.getOrderVector();

    vecOrderId.insert(vecOrderId.begin() + pos, curOrder.getOrderId());
    double dCost, dDistance, dTravelTime;
    dCost = dDistance = dTravelTime = 0.0;
    CostPack costRet;

    costRet.cost = INF;
    costRet.distance = INF;
    costRet.traveltime = INF;

    CostPack cPack = getDepotToOrderCost(curTour.getStartDepot(), vecOrderId[0]);

    dCost += cPack.cost;
    dDistance += cPack.distance;

    int ind = m_mapOrderIdToIndex[vecOrderId[0]];

    if (dTravelTime + cPack.traveltime > m_vOrderInfos[ind].getCloseTime())
        return costRet;

    dTravelTime = (std::max)(dTravelTime + cPack.traveltime + m_vOrderInfos[ind].getServiceTime(),
            static_cast<double>(m_vOrderInfos[ind].getOpenTime() + m_vOrderInfos[ind].getServiceTime()));

    unsigned int i;
    for (i = 1; i < vecOrderId.size(); i++) {
        cPack = getOrderToOrderCost(vecOrderId[i - 1], vecOrderId[i]);
        dCost += cPack.cost;
        dDistance += cPack.distance;

        ind = m_mapOrderIdToIndex[vecOrderId[i]];

        if (dTravelTime + cPack.traveltime > m_vOrderInfos[ind].getCloseTime())
            return costRet;

        dTravelTime = (std::max)(dTravelTime + cPack.traveltime + m_vOrderInfos[ind].getServiceTime(),
                static_cast<double>(m_vOrderInfos[ind].getOpenTime() + m_vOrderInfos[ind].getServiceTime()));
    }

    cPack = getOrderToDepotCost(vecOrderId[i - 1], curTour.getEndDepot());
    dCost += cPack.cost;
    dDistance += cPack.distance;

    dTravelTime += cPack.traveltime;

    ind = m_mapDepotIdToIndex[curTour.getEndDepot()];
    if (dTravelTime > m_vDepotInfos[ind].getCloseTime())
        return costRet;

    costRet.cost = dCost - curTour.getCost();
    costRet.distance = dDistance - curTour.getDistance();
    costRet.traveltime = dTravelTime - curTour.getTravelTime();

    return costRet;
}