Reputation: 3209
When an aircraft approaches an airport to land, the aircraft's approach procedure is divided up into transitions. Each transition consists of a set of legs.
sig Transition {
legs: set Leg
}
sig Leg {}
The set of legs within a transition is ordered. For each transition, I want to be able to access the first leg in the transition, the last leg in the transition, and I want to navigate from leg to leg in the transition. Thus, I want a first, last, and next function.
What's the simplest way to implement this? I have an implementation working but I wonder if there's something simpler. My implementation associates each Leg to a sequence number:
open util/ordering [SequenceNumber]
sig SequenceNumber {}
sig Transition {
legs: Leg one -> one SequenceNumber
}
Then I created my own utility functions:
fun First (t: Transition): Leg {
t.legs.(min [Leg.(t.legs)])
}
fun Last (t: Transition): Leg {
t.legs.(max [Leg.(t.legs)])
}
fun Next (t: Transition, leg: Leg): Leg {
t.legs.(next [leg.(t.legs)])
}
I am hoping you can show me a simpler solution.
Upvotes: 0
Views: 88
Reputation: 419
Why not use seq Leg
and the inbuilt sequence predicates & functions?
Upvotes: 1