Пример #1
0
void Conn::printPathList(PathList& paths, Fleet::Ptr _fleet)
{
  
  
 // cout << "\n\nPrinting path list \n\n";
  while(!paths.empty())
	{

    Cost cost(0);
  	Time time(0);
    bool exp = true;
    Path p = paths.front();
		Path::iterator it = p.begin();

    for(; it != p.end(); it++)
		{
		  Segment* seg = *it;
			cost = cost + seg->cost(_fleet);
      time = time + seg->time(_fleet);
			if(!seg->expediteSupport()) exp = false;
		}
    cout << cost.string() << " " << time.string() << " " << (exp?"yes; ":"no; ");
	  Conn::printPath(paths.front());
		cout << "\n";
	  paths.pop();
	}
	
}
Пример #2
0
Conn::StatPathList Conn::path(Fleet::Ptr _fleet, Location::Ptr _source, Cost _cost, Mile _distance, bool _expedite, Time _time )
{
   Conn::StatPathList paths;
	 Conn::StatPathList results;

   vector<SegmentPtr> segments =  _source->segments();
   vector<SegmentPtr>::iterator it = segments.begin();
   
	 // These are running variables
	 Cost cost = 0;
	 Mile distance = 0;
   bool expedite = _expedite;
	 Time time = 0;

   for(; it != segments.end(); it++)
	 {
     SegmentPtr ret = (*it)->returnSegment();
     if(ret)
		 {
		   if(ret->source())
			 {
				  
					Segment* seg = (*it).ptr();
			    if(_expedite == seg->expediteSupport())
					{
					  Conn::StatPath* p = new StatPath();
					  p->path()->push_back( (*it ).ptr());
					  p->costIs(seg->cost(_fleet));
					  p->distanceIs(seg->length());
					  p->expediteIs(expedite);
						p->timeIs(time);
            paths.push(p);

				 }
					
			 }
		 }
	 }

   int i = 0;
//	 cerr << "Before entering size is: " << paths.size() << "\n";
   while(!paths.empty())
	 {
	  std::cerr << "called " << i++ << "\n"; 
		StatPath*& p = paths.front();
		StatPath* rp = new StatPath();
		//rp->path_ = new Path(*(p->path()));
		rp->pathIs(new Path(*(p->path())));
		results.push(rp);
		Segment*& last_edge = p->path()->back();
	  Segment::Ptr ret = last_edge->returnSegment();
  //  cerr << "Return Segment offront segment is: " << ret->name() << "\n";
		Location::Ptr dest = ret->source();
		cerr << "Its destination: " << dest->name() << "\n";
		

		
    if(nodeExistsInPath(dest, *(p->path())))
		{
		  cerr << "Dest already Exists" << endl;
		  paths.pop();
			continue;
		}

    
    vector<SegmentPtr> segments =  dest->segments();
   	vector<SegmentPtr>::iterator it = segments.begin();
    cerr << "No of new segments considered: " << segments.size() << endl;

	  for(; it != segments.end(); it++)
	  {
		  SegmentPtr seg = *it;
		  SegmentPtr ret = seg->returnSegment();
			if(!ret)
			{
			  //paths.pop();
				continue;
			}
			else
			{
			  if(!ret->source())
				{
				  //paths.pop();
					continue;
				}
				else
				{

					    if(nodeExistsInPath(ret->source(), *(p->path())))
							{
		  					//paths.pop();
								continue;
							}


				  
				  StatPath* p1 = new StatPath(*p);
          if(  ((_expedite == false )||  ( (_expedite == true) && (_expedite == p->expedite()) ) )&& 
					     ( (_cost == Cost::nil()) ||  ( _cost != Cost::nil() && (( p->cost() + seg->cost(_fleet)) <= _cost ) ) )&&
							 ( (_distance == Mile::nil()) || ( _distance != Mile::nil() && ( (p->distance() + seg->length()) <= _distance) ) )&&
							 ( (_time == Time::nil() ) || ( _time != Time::nil() && ( (p->time() + seg->time(_fleet)) <= _time) ))
						)
							
					{
					  p1->path()->push_back( (*it ).ptr());
					  p1->costIs(p->cost() + seg->cost(_fleet));
					  p1->distanceIs(p->distance() + seg->length());
					  p1->expediteIs(_expedite);
						p1->timeIs(p->time() + seg->time(_fleet));

            paths.push(p1);
					//	std::cout << "PUSHING PUSHING " << std::endl;

          }

          
				}
			}
			
		}// End of consideration of all new segments
		paths.pop();
	}
	
	 return results;
}