当前位置: 首页 > news >正文

手机网站开发需要哪些人有域名有服务器怎么做网站

手机网站开发需要哪些人,有域名有服务器怎么做网站,天津快推科技有限公司,无忧网站后台Hello,CSDN的各位小伙伴们,又见面啦!今天我们要学习的例程是:Car Wash!我们开始吧! 例程背景 这个例程相对于example 2来说会简单一些,有一个洗车厂,里面有若干台洗车机器&#xf…

Hello,CSDN的各位小伙伴们,又见面啦!今天我们要学习的例程是:Car Wash!我们开始吧!

例程背景

这个例程相对于example 2来说会简单一些,有一个洗车厂,里面有若干台洗车机器,一台机器在一段时间内只能给一台车进行洗车服务。车辆陆陆续续到达洗车厂,如果有机器空闲,则开始为该车辆服务,如果没有机器空闲,则车辆会排队等待,直到有空闲的机器。

例程代码分析

照旧,基本的头文件和参数的定义我们就不赘述了:

import simpy
import randomRANDOM_SEED = 42
NUM_MACHINES = 2
WASHTIME = 5
T_INTER = 7
SIM_TIME = 20

下面我们先定义洗车厂,首先我们想洗车场有n个机器 ,每个机器自然就是建模成simpy中的resource。另外,洗车场还会有洗车的功能,洗车功能则需要花费一些时间。有了这些理解,我们可以直接写出洗车场的类:

class CarWash:# carwash里面包含了若干个机器,能够同时为车辆进行洗车服务def __init__(self, env, num_machines, washtime):self.env = envself.machine = simpy.Resource(env, capacity=num_machines)self.washtime = washtimedef wash(self):yield self.env.timeout(self.washtime)  # 洗车需要花费的时间

下面我们来定义单一台车辆的行为,值得注意的是:车辆什么时候到达洗车场我们是不需要在车辆自己的建模中考虑的,应该把它分离出来,我们需要考虑的是车辆到达洗车场后,如何做:请求机器资源,然后开始洗车,然后释放机器资源并离开。所以我们可以写出车辆行为的代码:

def car(env, name, cw):print('Car: ', name, ' arrives at the carwash at: ', env.now)with cw.machine.request() as request:  # 请求机器资源yield request  # 等待洗车机print('Car: ', name, ' enters the carwash at: ', env.now)yield env.process(cw.wash())  # 开始洗车print('Car: ', name, ' leaves the carwash at: ', env.now)

with 跳出后,simpy会自动释放resource。最后,我们来简单定义一个车辆陆陆续续到达洗车场的函数即可:

def set_up(env, num_machines, washtime, t_inter):# 先创建一个carwash类carwash = CarWash(env, num_machines, washtime)i = 0# 初始有四辆车for _ in range(4):i += 1env.process(car(env, i, carwash))# 创建后续驶来的车辆while True:i += 1yield env.timeout(random.randint(t_inter - 2, t_inter + 2))env.process(car(env, i, carwash))

最后启动仿真:

print('EXAMPLE 3: CAR WAHS...')
random.seed(RANDOM_SEED)
env = simpy.Environment()
env.process(set_up(env, NUM_MACHINES, WASHTIME, T_INTER))
env.run(until=SIM_TIME)

仿真结果如下:

EXAMPLE 3: CAR WAHS...
Car:  1  arrives at the carwash at:  0
Car:  2  arrives at the carwash at:  0
Car:  3  arrives at the carwash at:  0
Car:  4  arrives at the carwash at:  0
Car:  1  enters the carwash at:  0
Car:  2  enters the carwash at:  0
Car:  5  arrives at the carwash at:  5
Car:  1  leaves the carwash at:  5
Car:  2  leaves the carwash at:  5
Car:  3  enters the carwash at:  5
Car:  4  enters the carwash at:  5
Car:  6  arrives at the carwash at:  10
Car:  3  leaves the carwash at:  10
Car:  4  leaves the carwash at:  10
Car:  5  enters the carwash at:  10
Car:  6  enters the carwash at:  10
Car:  5  leaves the carwash at:  15
Car:  6  leaves the carwash at:  15
Car:  7  arrives at the carwash at:  17
Car:  7  enters the carwash at:  17
http://www.ds6.com.cn/news/107791.html

相关文章:

  • 网站设计与网页制作毕业论文怎么做好seo内容优化
  • 怎么架构网站软广告经典案例
  • 做网站和做微商城有什么区别舆情分析报告模板
  • wordpress加上特效seo1域名查询
  • wps的ppt做网站超链接ue5培训机构哪家强
  • 荣昌区城乡建设委员会网站湖南发展最新消息公告
  • 什么是销售型网站推广运营平台
  • wordpress 地图html青岛seo网站排名优化
  • phalapi wordpressseo站内优化包括
  • 广东做陶瓷的网站济南seo网站关键词排名
  • 专业搭建网站百度贴吧网页入口
  • 高校信息化建设网站系统微信seo
  • 广东住房和城乡建设厅网站首页凡科网怎么建网站
  • 网站上报名系统怎么做湖南百度推广代理商
  • 陕西省人民政府官网淄博seo公司
  • 河北省建筑人才网seo网站监测
  • 简单易做的的网站汕头最好的seo外包
  • wordpress关注查看手机优化专家
  • 西安微信网站开发优化新十条
  • 网站建设 落地页搜索引擎优化策略不包括
  • 包装设计公司商业模式seo网络优化师招聘
  • 信息咨询公司网站源码深圳短视频推广
  • 四川省建设资格注册中心网站品牌营销活动策划方案
  • 深圳线上注册公司网站快速排名优化报价
  • 网站建设公司项目介绍郑州seo优化大师
  • 微信网站是怎么做的品牌营销的四大策略
  • wordpress快速建站百度广告联盟价格
  • 前几年做那个网站能致富冯耀宗seo博客
  • 光谷网站建设网站关键词优化费用
  • 宜兴百度推广公司选择宁波seo优化公司