コード例 #1
0
ファイル: car.cpp プロジェクト: atuus007/SamuSmartCity
osmium::unsigned_object_id_type justine::robocar::AntCar::ant_rernd(void)
{

    AdjacencyList::iterator iter = AntCar::alist.find(m_from);

    WayNodesVect cpv = iter->second;

    int sum = std::accumulate(cpv.begin(), cpv.end(), 0);

    int res = (int)((double) sum / .75);

    int total = sum + cpv.size() * (res / cpv.size());

    for (osmium::unsigned_object_id_type & v : cpv)
        v += res / cpv.size();

    int rnd = std::rand() % total;

    int sum2 = 0;

    WayNodesVect::iterator j = cpv.begin();
    for (; j != cpv.end(); ++j) {
        sum2 += *j;
        if (sum2 >= rnd)
            break;
    }

    osmium::unsigned_object_id_type next_m_to = std::distance(cpv.begin(), j);

    ++*j;

    return next_m_to;
}
コード例 #2
0
ファイル: car.cpp プロジェクト: szanicsl/Robocar-Launcher
osmium::unsigned_object_id_type justine::robocar::Pedestrian::ped_mrernd ( void )
{
  AdjacencyList::iterator iter = Pedestrian::plist.find ( m_from );
  AdjacencyList::iterator iter2 = Pedestrian::plist_evaporate.find ( m_from );

  for ( WayNodesVect::iterator j=iter->second.begin(); j!= iter->second.end(); ++j )
  {
      int del = traffic.get_time() -
                iter2->second[std::distance ( iter->second.begin(), j )];

      int pheromone = *j - del;

      if ( pheromone > 1 )
        *j = pheromone;
      else
        *j = 1;
  }

  WayNodesVect cpv = iter->second;

  int sum = std::accumulate ( cpv.begin(), cpv.end(), 0 );

  int res = ( int ) ( ( double ) sum/.6 );

  int total = sum + cpv.size() * ( res/cpv.size() );

  for ( osmium::unsigned_object_id_type& v : cpv )
    v += res/cpv.size();

  int rnd = std::rand() % total;

  int sum2 = 0;

  WayNodesVect::iterator j=cpv.begin();
  for ( ; j!= cpv.end(); ++j )
  {
    sum2 += *j;

    if ( sum2 >= rnd )
      break;
  }

  osmium::unsigned_object_id_type next_m_to = std::distance ( cpv.begin(), j );

  ++*j;
  iter2->second[std::distance (cpv.begin(), j )] = traffic.get_time();

  return next_m_to;
}