Engineering Algorithm Development
Engineering algorithm development turns a stated engineering requirement into a procedure whose results you can justify. You decide what information enters, how calculations proceed, what counts as an acceptable result, and when the procedure stops. The central task is making those decisions precise enough that someone else can follow the procedure and check its behavior before implementation.
Specify what success means
A specification states the permitted inputs, required outputs, and conditions connecting them. Include units, valid ranges, assumptions, and the meaning of equality at a boundary. “Fill the tank sufficiently” is ambiguous; “return the first sampling time at which volume is at least the target without exceeding capacity” is testable.
Consider a hypothetical tank model with initial volume 0.40 m3, constant net inflow 0.006 m3/s, and updates every 10 s. The target is 0.50 m3 and capacity is 0.60 m3. State whether you want the first qualifying sampling time or an estimated crossing time between samples. These are different outputs.
Specify unsuccessful outcomes too. Invalid inputs, an unsafe proposed update, and exhaustion of an update allowance convey different information. None should silently become a successful result.
Build a bounded procedure
Choose the information that must persist between steps. This information is the state. For a repeated calculation, a general update is
Here sk is the state after k updates, d contains fixed input data, and Δt is the time represented by one update. Specify the initial state s0 and initialize the counter to zero.
For the tank, the supplied model gives
Each update adds (0.006)(10)=0.060 m3. The first two updated volumes are therefore 0.46 m3 and 0.52 m3. The first qualifying sampling time is 20 s.
Check whether the initial state already meets the target. Before accepting a proposed update, check any safety constraint. If the proposed volume exceeds capacity, the sampled procedure cannot accept that update, even if it also passes the target. This rule concerns the specified sampled procedure; it does not establish that filling is physically impossible.
Give repeated work a finite bound, such as a maximum number of updates. A loop invariant is a statement that remains true whenever a repeated step begins. For this tank procedure, the stored volume is within capacity, and the counter equals the number of accepted updates. These statements help you check initialization and each update.
Verify and refine
Trace a small case manually, recording the state, counter, and decision at each step. Then select tests that challenge the requirements rather than merely produce familiar numbers.
Test case | Behavior to verify |
|---|---|
Initial state satisfies the target | Success with zero updates |
An update reaches the target exactly | Success when the boundary is inclusive |
Success occurs on the final allowed update | Success takes precedence over an exhausted allowance |
Proposed update exceeds a safety bound | Unsafe state is not accepted |
Allowance ends before success | An explicit limit outcome is returned |
Review why the procedure works as well as testing examples. If you return the first feasible candidate, justify why the inspection order makes it the required candidate. After a revision, repeat boundary tests: changing one comparison can alter equality cases elsewhere. Improve efficiency only while preserving the specified results and failure behavior.
What to remember
- Define valid inputs, units, success, and unsuccessful outcomes.
- Initialize the state and counter consistently.
- Make update order, boundary comparisons, and stopping rules explicit.
- Combine manual traces, boundary tests, and reasoning about correctness.
Example: Developing a cooling completion procedure
A test rig estimates when a component is ready for handling. Its supplied sampled cooling model is
where temperatures are expressed in degrees Celsius and each update represents 2.0 min. Initially, T0=86 ∘C. The component is ready when T≤30 ∘C. The procedure may perform at most four updates and must return the first qualifying sampling time, or LIMIT with the final temperature and elapsed time if the target remains unmet. Do not interpolate between samples.
Develop the procedure
a) Specify the state, checking order, and finite stopping rule.
Store the current temperature T and the number of completed updates k. Initialize T=86 ∘C and k=0. The elapsed time is always
Repeat the following decisions in order:
- If T≤30 ∘C, return SUCCESS with T and t.
- Otherwise, if k=4, return LIMIT with T and t.
- Otherwise, calculate the new temperature from the supplied model, store it, increase k by one, and repeat.
Checking the target first allows success at initialization and on the fourth update. The counter increases once per update and cannot exceed four, so the maximum simulated time is
At each check, T represents exactly k completed updates. Checking the target at every sampling time in increasing order ensures that the first reported success is the earliest qualifying sample.
Trace the calculation
b) Apply the procedure and report its output.
The initial temperature exceeds 30 ∘C, so the zero-update check does not return success. Calculate and check each successive state:
The checks give the following results:
- After zero updates, t=0.0 min and T=86 ∘C; the target is unmet.
- After ________ update, t=2.0 min and T=54 ∘C; the target is unmet.
- After ________ updates, t=4.0 min and T=38 ∘C; the target is unmet.
- After three updates, t=6.0 min and T=30 ∘C; the target is met.
Equality satisfies the target. The procedure therefore returns SUCCESS at
It performs no fourth update because the required output is the first qualifying sampling time.
Test the boundaries
c) Keep the same model and four-update allowance. Predict the output if the target is changed to 26 ∘C, then to 25 ∘C. Also check an initial temperature of 29 ∘C with the original 30 ∘C target.
With the original initial temperature, the fourth updated temperature is
For a 26 ∘C target, the earlier samples all exceed the target, while the fourth equals it. The procedure returns SUCCESS with T=26 ∘C at 4(2.0)=8.0 min. Checking the allowance before the target would incorrectly reject this valid final-update success.
For a 25 ∘C target, the fourth temperature remains above the target:
The allowance is exhausted, so the output is LIMIT with final temperature 26 ∘C and elapsed time 8.0 min. This outcome describes the permitted run; it does not claim that further cooling could never meet the target.
With initial temperature 29 ∘C and target 30 ∘C, the initial check succeeds because 29≤30. The result is SUCCESS at 0.0 min with temperature 29 ∘C and zero updates.
A pump monitor receives one pressure reading at a time. Readings from 20 to 80 kPa, inclusive, are acceptable. The alarm should be on whenever the latest readings include at least three consecutive out-of-range readings.
Complete this algorithm using exact integers. The counter begins at zero and records the number of consecutive out-of-range readings ending at the latest reading.
- If the new reading is acceptable, assign to the counter.
- Otherwise, increase the counter by .
- After updating the counter, turn the alarm on if the counter is at least three; otherwise, turn it off.
A ventilation controller can choose fan speeds of 600, 900, 1200, or 1500 rpm. A supplied model evaluates the airflow at each speed. The required output is the smallest available speed whose airflow is at least 0.080 m3/s, or NONE if no speed qualifies. Which procedure guarantees this output for any set of supplied model results?