Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your program will begin by reading one line of input from the Python shell ( e . g . , via a call to the
Your program will begin by reading one line of input from the Python shell eg via a call to the builtin input function specifying the path to an input file that describes the work that your program will be doing. Do not print a prompt or anything else; read this input before writing any output.
If the specified file doesn't exist, your program will then print one line of output FILE NOT FOUND and then terminate. Otherwise, your program will have a simulation to run, with everything driven by what's in that input file, so let's take a look at what you can expect to be in it
The input
Your program's input file consists of lines of text. Each file will fit one of six characteristics, described below.
A line can begin with the word LENGTH, followed by a space, followed by a positive integer value. This line establishes the length of the simulation, specified in milliseconds. So for example, the line LENGTH would mean that the simulation will run for simulation milliseconds, numbered through with the simulation ending and nothing else happening at time
A line can begin with the word DEVICE, followed by a space, followed by a nonnegative integer value. These lines establish the existence of one device in our simulation; the integer is the device ID that uniquely identifies the device.
A line can begin with the word PROPAGATE, followed by three nonnegative integer values, separated by spaces. These lines describe a rule for propagating an alert or cancellation from one device to another. The three integers specify, as follows, three things:
A device ID that may subsequently receive an alert or cancellation.
A device ID to which the received alert or cancellation should be propagated.
A delay, expressed as a positive integer number of milliseconds, indicating how long it will be before the propagated alert or cancellation will be received by the second device. Positive means that it will never be zero.
So for example, the line PROPAGATE indicates that device will propagate any alert or cancellation to device and that device will receive it milliseconds later.
A line can begin with the word ALERT, followed by three values, separated by spaces.
A device ID that will be scheduled to raise an alert at a particular time during the simulation.
An arbitrary string of nonspace characters specifying the description of the alert.
The simulation time at which the alert will be raised, which means that the specified device will begin the process of propagating it This time is given as a nonnegative integer number of milliseconds after the start of the simulation. Nonnegative" means that it might be zero.
So for example, the line ALERT OhNo indicates that device will raise an alert with the text OhNo at simulation time
A line can begin with the word CANCEL, followed by three values, separated by spaces.
A device ID that will be scheduled to cancel an alert at a particular time during the simulation.
An arbitrary string of nonspace characters specifying the description of the alert being canceled.
The simulation time at which the cancellation will occur, which means that the specified device will begin the process of propagating the cancellation. This time is given as a nonnegative integer number of milliseconds after the start of the simulation. Nonnegative" means that it might be zero.
So for example, the line CANCEL OhNo indicates that device will cancel an alert with the text OhNo at simulation time
A line can be blank or consist only of spaces. These lines are used for readability of the input file, and can be ignored by your program when detected.
A line can begin with a # character, in which case it can be followed by zero or more characters of text with no restrictions. These lines are used as comments in the input file similar to comments in a Python program and can be ignored by your program when detected.
There is no restriction about the order in which you'll find the lines of the file. Any of those kinds of lines can appear anywhere in the file.
However, you can assume that the input will be formatted according to those rules; we won't be testing your program with input files that don't meet those requirements, so your program can do anything including crash if given such an input file.
There are also a few other assumptions you can safely make about the input ie we won't test scenarios where these assumptions aren't true, so we don't care how or if your program handles them
The simulation's length will always be specified exactly once.
No time listed in the input will occur after the scheduled end of the simulation.
No pair of devices listed in the input file will have the same device ID
No propagation rule will list the same two device IDs ie devices never propagate to themselves
No pair of propagation rules will list the same tw
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started