⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runway.h

📁 这是本人精心搜集的关于常用图论算法的一套源码
💻 H
字号:
#include "Queue.h"

enum Runway_activity {idle, land, flyingoff};
class Runway
{
  public:
    Extended_queue<Plane> landing;
    Extended_queue<Plane> takeoff;
    Runway(int limit);
    Error_code can_land(const Plane &current);
    Error_code can_depart(const Plane &current);
    Runway_activity activity(int time, Plane &moving);
    void shut_down(int time) const;
  private: 
    int queue_limit;
    int num_land_requests;    // number of planes asking to land
    int num_takeoff_requests; // number of planes asking to take off
    int num_landings;         // number of planes that have landed
    int num_takeoffs;         //number of planes that have taken off
    int num_land_accepted;    // number of planes queued to land
    int num_takeoff_accepted; // number of planes queued to take off
    int num_land_refused;     // number of landing planes refused
    int num_takeoff_refused;  // number of departing planes refused
    int land_wait;            //total_time of planes_waiting to land
    int takeoff_wait;         //total_time of planes_waiting to take off
    int idle_time;            //total_time runway is idle
};
  
Runway::Runway(int limit)
/* Post: TheRunway data members are initialized to record no priorRunway use
   and to record thelimit on queue sizes. */
{
  queue_limit=limit;
  num_land_requests=num_takeoff_requests=0;
  num_landings=num_takeoffs=0;
  num_land_refused=num_takeoff_refused=0;
  num_land_accepted = num_takeoff_accepted=0;
  land_wait=takeoff_wait=idle_time=0;
}

Error_code Runway::can_land(const Plane &current)
/* Post: If possible, the Plane current is added to the landing Queue; otherwise, 
         an Error_code of overflow is returned. The Runway statistics are updated.
   Uses: class Extended queue . */
{
  Error_code result;
  if(landing.size()<queue_limit)
      result=landing.append(current);
  else
     result=fail;
  num_land_requests++;
  if(result!=success)
     num_land_refused++;
  else
     num_land_accepted++;
  return result;
}

Error_code Runway::can_depart(const Plane &current)
/* Post: If possible, the Plane current is added to the departing Queue ; otherwise, an
         Error_code of overflow is returned. The Runway statistics are updated.
   Uses: class Extended queue . */
{
  Error_code result;
  if(takeoff.size()<queue_limit)
      result=takeoff.append(current);
  else
     result=fail;
  num_takeoff_requests++;
  if(result!=success)
     num_takeoff_refused++;
  else
     num_takeoff_accepted++;
  return result;
}
Runway_activity Runway::activity(int time, Plane &moving)
/* Post: If the landingQueue has entries, its frontPlane is copied to the parameter
         moving and a resultland is returned. Otherwise, if the takeoff Queue has
         entries, its frontPlane is copied to the parameter moving and a resulttakeoff
          is returned. Otherwise,idle is returned. Runway statistics are updated.
    Uses: class Extended queue. */
{
   Runway_activity in_progress;
   if(!landing.empty( ))
      { landing.retrieve(moving);
        land_wait += time-moving.started( );
        num_landings++;
        in_progress = land;
        landing.serve( );
       }
   else if(!takeoff.empty( ))
          {  takeoff.retrieve(moving);
             takeoff_wait+=time-moving.started( );
             num_takeoffs++;
	     in_progress = flyingoff;
             takeoff.serve( );
          }
        else{
             idle_time++;
             in_progress = idle;
            }
   return in_progress;
}  
void Runway::shut_down(int time) const
/* Post: Runway usage statistics are summarized and printed. */
{
 cout<<"\n\nSimulation has concluded after "<<time<<" time units.\n";
 cout<<"Total number of planes processed ";
 cout<<(num_land_requests + num_takeoff_requests)<<endl;
 cout<<"Total number of planes asking to land "<<num_land_requests<<endl;
 cout<<"Total number of planes asking to take off "<<num_takeoff_requests<<endl;
 cout<<"Total number of planes accepted for landing "<<num_land_accepted<<endl;
 cout<<"Total number of planes accepted for takeoff ";
 cout<<num_takeoff_accepted<<endl;
 cout<<"Total number of planes refused for landing "<<num_land_refused<<endl;
 cout<< "Total number of planes refused for takeoff "<< num_takeoff_refused<<endl;
 cout<< "Total number of planes that landed "<<num_landings<<endl;
 cout<< "Total number of planes that took off "<<num_takeoffs<<endl;
 cout<< "Total number of planes left in landing queue "<<landing.size( )<<endl;
 cout<< "Total number of planes left in takeoff queue "<<takeoff.size( )<<endl;
 cout<< "Percentage of time runway idle "<<(100.0*(float)idle_time)/((float)time)<<"%"<<endl;
 cout<< "Average wait in landing queue "<<((float)land_wait)/((float)num_landings)<<" time units\n";
 cout<< "Average wait in takeoff queue ";
 cout<<((float) takeoff_wait)/((float) num_takeoffs)<<" time units"<<endl;
 cout<< "Average observed rate of planes wanting to land ";
 cout<< ((float) num_land_requests)/((float)time)<<" per time unit"<<endl;
 cout<< "Average observed rate of planes wanting to take off ";
 cout<< ((float)num_takeoff_requests)/((float)time)<< " per time unit"<<endl;
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -