Mock Scenario Test: Rave Developer Assessment
Many airlines will issue a take-home assignment or live coding test to evaluate your declarative logic skills. Since standard platforms like LeetCode do not support Rave, they will usually ask you to write pseudo-Rave code or evaluate a logic puzzle.
Here is a realistic mock scenario.
📌 The Scenario
Background:
You are optimizing schedules for a European base. The union CBA states that a crew member's total flight time in a single Duty cannot exceed 9 hours (09:00). Additionally, the union strongly prefers that crews do not sit on the ground between flights for more than 2 hours (02:00).
The Requirements:
- Write a hard constraint to ensure the total flight time in a duty does not exceed
09:00. - Write a soft penalty that adds
50.0cost points for every minute of sit time that exceeds02:00between any two consecutive flights in a duty. - Add this penalty to the total cost of the Duty.
💻 Your Task
Write the Rave code to implement these requirements.
Hint: Remember how to use monotonic constraints, the sum traverser, and the for each inter-instance navigator.
✅ Solution & Explanation
Part 1: The Hard Constraint (Flight Time Limit)
This is a classic monotonic limit. We want this to be a Final Rule so it prunes the search space efficiently.
CONSTANTS:
%max_flight_time% = 09:00;
ENDCONSTANTS
// The compiler will infer this as a Final Rule because flight time is non-negative
CONSTRAINT max_duty_flight_time OF Duty
COMMENT: "Total flight time in a duty must not exceed 9 hours."
STATUS: ON;
RULE:
sum(leg(duty), leg.%flight_time%) <= %max_flight_time%;
ENDCONSTRAINT
Part 2: The Sit Time Soft Penalty
We need to iterate over consecutive legs, check the sit time, and calculate a penalty if it exceeds 2 hours.
CONSTANTS:
%max_sit_time_threshold% = 02:00;
%sit_time_penalty_per_min% = 50.0;
ENDCONSTANTS
// Calculate the penalty for a single connection
%connection_sit_penalty% =
for each f1 -> f2 in elements
if (f2.departure_time - f1.arrival_time) > %max_sit_time_threshold% then
// Convert the excess duration to minutes and multiply by the penalty weight
((f2.departure_time - f1.arrival_time) - %max_sit_time_threshold%) * %sit_time_penalty_per_min%
else
0.0;
// Aggregate the penalties across the entire duty
%total_duty_sit_penalty% = sum(leg(duty), %connection_sit_penalty%);
Part 3: The Duty Cost Property
Finally, we add this penalty to the base cost of the duty.
🧠Interviewer Follow-Up Question:
- Interviewer: "Why didn't you put
valid is_closed;inside themax_duty_flight_timeconstraint?" - Your Response: "Because total flight time is a non-decreasing monotonic sum. By leaving
valid is_closed;out, the compiler correctly identifies it as a Final Rule. If I addedis_closed, it would turn into an Illegal Subchain Rule, the solver would stop pruning the tree early, and performance would plummet."