讲解:CS115、Computer Simulation、Python、PythonWeb|Python

CS115 - Computer Simulation, Assignment #1 – Train Unloading DockDue at START of class in the 6th Lecture of the QuarterNote you CANNOT use CSIM – must use a non-simulation languageIn this assignment, you will write a simulation of a train unloading dock. Trains arrive at thestation as a Poisson process on average once every 10 hours. Each train takes between 3.5 and 4.5hours, uniformly at random, to unload. If the loading dock is busy, then trains wait in a first-come,first-served queue outside the loading dock for the currently unloading train to finish. Negligibletime passes between the departure of one train, and the entry of the next train (if any) into theloading dock---unless the entering train has no crew (see below).There are a number of complications. Each train has a crew that, by union regulations, cannot workmore than 12 hours at a time. When a train arrives at the station, the crew’s remaining work time isuniformly distributed at random between 6 and 11 hours. When a crew abandons their train at theend of their shift, they are said to have “hogged out”. A train whose crew has hogged out cannot bemoved, and so if a hogged-out train is at the front of the queue and the train in front finishesunloading, it cannot be moved into the loading dock until a replacement crew arrives (crews fromother trains cannot be used). Furthermore, a train that is already in the loading dock cannot beunloaded in the absence of its crew, so once the crew hogs out, unloading must stop temporarilyuntil the next crew arrives for that train. This means that the unloading dock can be idle even ifthere is a train in it, and even if it is empty and a (hogged-out) train is at the front of the queue.Once a train’s crew has hogged out, the arrival of a replacement crew takes between 2.5 and 3.5hours, uniformly at random. However, due to union regulations, the new crew’s 12-hour clockstarts ticking as soon as they are called in for replacement (i.e., at the instant the previous crewhogged out); i.e., their 2.5-3.5 hour travel time counts as part of their 12-hour shift.You will simulate for 72,000 hours (plus the time it takes for all remaining trains to depart), andoutput the following statistics at the end:1. Total number of trains served.2. Average and maximum of the time-in-system over trains.3. The percentage of time the loading dock spent busy, idle, and hogged-out (i.e., whenprevented from unloading a train that has hogged-out) (does this add to 100%? Why orwhy not?)4. Time average and maximum number of trains in the queue.5. A histogram of the number of trains that hogged out 0, 1, 2, etc times.Input Specification: We will run your code, but to make it easy for the grader, we need everybodyto adhere to the following guidelines: create a makefile that builds your program (if necessary), andyour program should take either two or three command-line arguments. When given threearguments, the first argument should just be “-s”, your program should read the second argument asthe file path to the pre-determined train arrival schedule (described below), and it should read thethird argument as the file path to the pre-determined travel-times for new crews (also describedbelow). When only given two arguments, the first argument must be the average train inter-arrivaltime, and the second argument must be the total simulation time. Thus, for example, if yourprogram is written in C and compiled to an executable called “train”, then to run it with thedefault parameters above, I should be able to run it on my Unix command line as:$ make$ ./train 10.0 72000.0or$ make$ ./train –s schedule.txt traveltimes.txtIf you are using a language that does not run like the above (e.g. Python “python train.py 10.072000.0”, or Java “java -cp . train 10.0 72000.0”) create a shell script or program wrapperthat takes in the arguments and runs your code as above. For example, if you are using Python, youcan create a shell script named “train.sh” containing:#!/usr/bin/env bashpython train.py $@That will allow the grader to run your program using:$ ./train.sh 10.0 72000.0(Note: If you want to use this yourself on GNU/Linux, you’ll need to mark it as executableusing the command “chmod –x train.sh”)Also, if you are using a language that does not require building/compiling (e.g. Python), just createa makefile with no targets:target: ;The pre-determined train arrival schedule contains three space-delimited columns: arrival times,unloading times, and remaining crew hours (in that order), with each arrival event on a new line:0.02013 3.70 8.928.12 4.12 10.1012.52 3.98 7.82...1210.0 4.12 9.21The pre-determined travel-times for new crews contains a single column of data: the travel-time fornew crews. It would be safe to assume there could be more rows 代做CS115作业、代做Computer Simulation作业、代写Python程序语言作业、Python编程作业代in this file than the previous file.2.513.0001...2.89When using a pre-determined schedule and there are no more train arrivals scheduled, end thesimulation after the very last train has departed; when using random values, stop adding arrivalevents after the total simulation time has passed as specified by the command arguments (e.g., at72,000 hours). The simulation will stop after the last train has departed in this case as well.Output Specification: Your program should print one line for every event that gets called. I wantto be able to follow what’s happening in your code. Each train and each crew should be assignedan increasing integer ID. The final statistics should come after the simulation output and closelymatch the specified format. Output lines should resemble the following example:Time 0.00: train 0 arrival for 4.45h of unloading, crew 0 with 7.80h before hogout (Q=0)Time 0.00: train 0 entering dock for 4.45h of unloading, crew 0 with 7.80h before hogoutTime 0.56: train 1 arrival for 4.33h of unloading, crew 1 with 6.12h before hogout (Q=1)Time 3.72: train 0 departing (Q=1)Time 3.72: train 1 entering dock for 4.33h of unloading, crew 1 with 2.96h before hogoutTime 6.68: train 1 crew 1 hogged out during service (SERVER HOGGED)Time 9.43: train 1 replacement crew 2 arrives (SERVER UNHOGGED)...Time 319.64: train 33 entering dock for 3.51h of unloading, crew 39 with 3.09h before hogout (Q=2)Time 322.73: train 33 crew 39 hogged out during service (SERVER HOGGED)Time 323.63: train 34 crew 40 hogged out in queueTime 325.78: train 33 replacement crew 41 arrives (SERVER UNHOGGED)Time 326.20: train 33 departing (Q=1)Time 326.20: train 34 crew 42 hasnt arrived yet, cannot enter dock (SERVER HOGGED)Time 326.82: train 34 replacement crew 42 arrives (SERVER UNHOGGED)Time 326.82: train 34 entering dock for 4.32h of unloading, crew 42 with 8.81h before hogout (Q=1)...Time 1234.00: simulation endedStatistics----------Total number of trains served: 512Average time-in-system per train: 3.141593hMaximum time-in-system per train: 6.283186hDock idle percentage: 64.00%Dock busy percentage: 32.00%Dock hogged-out percentage: 16.00%Time average of trains in queue: 0.1234Maximum number of trains in queue: 2Histogram of hogout count per train:[0]: 512[1]: 128[2]: 32... (show as many bins as necessary)Numbers can have any number of decimal places (valid examples include 13 and 3.14159), but noscientific notation.A script to automatically check the output formatting will be provided to give feedback on I/Ospecification compliance. To run it with your program’s output, you can run the followingcommands:$ ./train –s schedule.txt traveltimes.txt > output.txt$ ./python3 checker.py output.txtSubmission: Submit a brief write-up of your results, along with your source code and specificsections of the output (only the first few pages and the last page) for the default parameters. There should be no more than 10 pages. Submit both a paper printout to me in class, and alsoelectronically via the submit command on ICS openlab.Grading: You can use any non-simulation language (ie., any language not already designed forsimulation), but it must allow command-line execution similar to the above, and I must be able torun it on my Linux box. This probably eliminates most proprietary languages, such as Matlab.However, if you want to use anything “weird” (i.e., anything other than Pascal, Fortran, C, C++,Java, Lisp, or Scheme), please clear it with me first. In the worst case, I may ask you to run it forme, in my office, in front of my eyes, if I can’t figure out how to run your language myself.Your code should be “pretty”, which means easily understood and maintainable by anotherprogrammer. This is of course subjective, but it should be well indented, and well commentedinside, such that, if we were fellow employees and I had to change your code, I wouldn’t be cursingyour birth after several hours (or days) of trying to figure it out. It should be easy-to-read; thevariables should have meaningful (but not overly verbose) names; the comments should clarifytricky points but not obvious ones. (I’ve seen the comment “add one to x” beside “x++”; thatqualifies as an unnecessary comment. A better comment would tell us WHY x is beingincremented, if it’s not obvious.) The prettiness (i.e., understandability, readability, andmaintainability) of your code, by the grader’s judgment alone, will count as 25% of your grade.Your code should be correct. We will judge the correctness of your code both by reading it, andbased on tracing its output events and final statistics. Correctness of the traces and the output willcount for 50% of the grade. The write-up will count for the remaining 25%.转自:http://ass.3daixie.com/2018110131238755.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,490评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,581评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,830评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,957评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,974评论 6 393
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,754评论 1 307
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,464评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,357评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,847评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,995评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,137评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,819评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,482评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,023评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,149评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,409评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,086评论 2 355

推荐阅读更多精彩内容