Esempio n. 1
0
int main()
{
// Estrutura List
 Route route;
// Ler ponto de um arquivo

 std::ifstream ifs ("points.dat", std::ifstream::in);

 point aux(0,0);

 while (ifs >> aux.real() >> aux.imag()) { 
  route.push_back(aux);
 }

 ifs.close();

// List teste

// Algoritmo
// Step 1: Calcular as poupanças sij=ci0+c0j-cij para i,j=1,...mn i!=j. Criar n rotas de veículos
// (0,i,0) para i=1,...,n. Ordenar as economias num modo não crescente.
 int n=route.size();
 double s[n][n-1];
 point origin=*route.begin();
 Route Aux;
 Subroute Sb; 

 for (Route::iterator i=++route.begin(); i!=route.end(); ++i) {
  Aux.push_back(*i);
  Sb.push_back(Aux);
  for ( Route::iterator j=i; j!=route.end(); ++j) {
   if( i!=j) {
     s[i][j]( std::abs(*i-origin)+std::abs(origin-*j)-std::abs(*i-*j) );
   }
  }
  Aux.clear();
 }

 std::cout << Sb.size() << std::endl;

 s.sort();

 for (std::list<double>::iterator i=s.begin(); i!=s.end(); ++i) 
	std::cout << *i << std::endl;

// Step 2: Iniciar do topo da lista de economias, executando o seguinte. Dada a economia sij,
// determine se há duas rotas, uma contendo arco ou aresta (0,j) e a outra contendo o arco ou aresta
// (i,0), que pode ser mescladas. Se então, combine essas duas rotas deletando (0,j) e (i,0) e
// introduzindo (i,j).

 
 // Mesclar rotas
 for(Subroute::iterator I=Sb.end(); I!=Sb.begin(); --I) {
  
 }

 return 0;
}
Esempio n. 2
0
Network::RouteInfo Network::updateRoute(Route& newRoute) throw(NetworkException) {
    std::pair<const Node&, const Node&> np(newRoute.front(), newRoute.back());
    auto ori = routes.find(np);
    assert(ori != routes.end());
    Route& oldRoute = ori->second.first;
    const double traffic = ori->second.second;

    // Remove the traffic from the old route
    for (auto i = oldRoute.begin(); i < oldRoute.end() - 1; i++) {
        Link l = getLink(make_pair(*i, *(i + 1)));
        l.removeTraffic(traffic);

        i->removeTraffic(*(i + 1), traffic);
    }

    // Add it to the new route
    double cost = 0.0;
    for (auto i = newRoute.begin(); i < newRoute.end() - 1; i++) {
        Link l = getLink(make_pair(*i, *(i + 1)));
        l.addTraffic(traffic);

        i->addTraffic(*(i + 1), traffic);

        cost += l.getCurrentCost(traffic);
    }


    ori->second = RouteInfo(newRoute, traffic);

    return RouteInfo(newRoute, cost);
}
Esempio n. 3
0
/* 
 * This function assures that a new backward ant's route is connected. As
 * neighbours are selected independently by each node, the resulting route
 * may not follow a connected path from src to orig.
 * In that is the case, the route must be discarded in the hope that another
 * and will soon follow the complete path.
 */
bool Network::testRoute(const Route& route) const noexcept {
    bool ret = true;

    for (auto ci = route.begin(); ci < route.end() - 1; ci++) {
        if (links.find(make_pair(*ci, *(ci + 1))) == links.end())
            return false;
    }

    return ret;
}
Esempio n. 4
0
RouteDetails Pathfinding::getPathDetailled(Entity* entity, const Vector3& goal) {
    Route route = getPath(entity, goal);

    Vector3 position = entity->getPosition();
    Vector3* last    = &position;
    float lengthSq   = 0;

    // Chain all the distances together:
    for(auto it = route.begin(); it != route.end(); ++it) {
        lengthSq += (*it).distanceToSq(*last);
        last      = &(*it);
    }

    return RouteDetails(entity, route, lengthSq);
}
Esempio n. 5
0
Network::RouteInfo Network::addTraffic(Node orig, const Node& dst, double traffic, RouteMode mode) throw (TrancasException) {
    /* Algorithm:
     * a) Calculate route (link collection)
     * b) Update info at orig node
     * c) Update link traffic
     * d) Update Nodes neighbour traffic
     */
    Dijkstra spf(orig, dst, *this, traffic, mode==SPF ? Dijkstra::Constant : Dijkstra::Real);

    Route r = spf.getRoute();
    double cost = 0.0;
    for (auto i = r.begin(); i < r.end() - 1; i++) {
        Link l = getLink(make_pair(*i, *(i + 1)));
        cost += l.getCost(traffic);
        l.addTraffic(traffic);

        i->addTraffic(*(i + 1), traffic);
    }
    addNewRoute(r, traffic);

    return RouteInfo(move(r), cost);
}