《数据结构与程序设计》队列 case study —— airport 模拟机场调度

这篇博客介绍了使用C语言完成的一个数据结构与算法作业——机场调度模拟。通过队列实现待降落和待起飞飞机的管理,并利用泊松分布生成随机降落请求。博主分享了接近两百行的代码,尽管认为代码繁琐,但认为泊松分布的实现有一定参考价值,期待读者的指导和优化建议。
摘要由CSDN通过智能技术生成

3.25 数据结构与算法作业——airport

个人觉得这道题很水没有什么思维难度也没有什么算法思想,只是很麻烦,因为用到的变量实在太多。
(也可能是有别的不麻烦的方法但我没想到orz)
还是记录一下吧,毕竟是第一个自己写的接近两百行的代码♪(・ω・)ノ

代码写的很繁琐,但觉得泊松分布部分写(chao) 的还挺好,蛮有参考价值的。。。
希望对有需要的人有帮助,同时希望看到的大佬能不吝赐教,指点指点怎么简化代码。。。

运行效果

先初始化
在这里插入图片描述
然后开始模拟
(中间调度过程:)
在这里插入图片描述
(最后机场调度情况总结:)
在这里插入图片描述

代码

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <math.h>
#include <time.h>

using namespace std;

class Random{
   
	public:
		Random(bool pseudo=true);
		double random_real();
		int poisson(double mean);
	private:
		int reseed();
		int seed,
			multiplier,add_on;
};

int Random::reseed()
{
   
	seed=seed*multiplier + add_on;
	return seed;
}

Random::Random(bool pseudo)
{
   
	if(pseudo)
		seed=1;
	else
		seed=time(NULL)%INT_MAX;
	multiplier=2743;
	add_on=5923;
}

double Random::random_real()
{
   
	double max=INT_MAX + 1.0;
	double temp=reseed();
	if(temp<0)
		temp=temp+max;
	return temp/max;
}

int Random:
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
/数据结构课程设计--飞机场模拟--初始化及主程序 //舞动青春--张佳贵 //2009年6月 #include #include #include"Extended_queue.h" #include"Random.h" #include"Runway.h" #include"Plane.h" using namespace std; void run_idle(int time) { cout<<" "<<time<<":Runway is idle."<<endl; } //初始化程序 void initialize(int &end_time,int &queue_limit,double &arrival_rate,double &departure_rate){ cout<<"This is program simulates an airport with only one runway."<<endl <<"One plane can land or depart in each unit of time."<<endl; cout<<"Up to what number of planes can be waiting to land" <<" or take off at any time?"<>queue_limit; //输入用户期望的跑道最大容纳量 cout<<"How many uints of time will the simulation run?"<>end_time; bool acceptable; do { cout<<"Expected number of arrivals per uint time?"<>arrival_rate; cout<<"Expected number of departures per uint time?"<>departure_rate; if(arrival_rate<0.0||departure_rate<0.0) cerr<<"These rates must be nonnegative."<1.0) cerr<<"Safety Warning:This airport will become saturated."<<endl; }while(!acceptable); } //主程序 int main() { int end_time; int queue_limit; int flight_number=0; double arrival_rate; double departure_rate; initialize(end_time,queue_limit,arrival_rate,departure_rate); //初始化跑道信息 Random variable; //定义随机数变量 Runway small_airport(queue_limit); //判断当前发出请求的飞机是否应该被接受或拒绝 for(int current_time=0;current_time<end_time;current_time++){ int number_arrivals=variable.poisson(arrival_rate); for(int i=0;i<number_arrivals;i++){ Plane current_plane(flight_number++,current_time,arriving); if(small_airport.can_land(current_plane)!=success) current_plane.refuse(); } int number_departures=variable.poisson(departure_rate); for(int j=0;j<number_departures;j++){ Plane current_plane(fligh
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值