@prefix nepo: <http://neptune.aws.com/ontology/airroutes/>.
@prefix list: <http://www.w3.org/2000/10/swap/list#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix : <http://example.org/#>.

# connectivity
{(?from ?to ?visited ?length ?max) :route (?from ?to)} <= {
    ?length math:notGreaterThan ?max.
    ?from nepo:hasOutboundRouteTo ?to.
    ?visited list:notMember ?to.
}.

{(?from ?to ?visited ?length ?max) :route ?route} <= {
    ?length math:notGreaterThan ?max.
    ?from nepo:hasOutboundRouteTo ?via.
    ?visited list:notMember ?via.
    ?newVisited list:firstRest (?from ?visited).
    (?length 1) math:sum ?newLength.
    (?via ?to ?newVisited ?newLength ?max) :route ?newRoute.
    ?route list:firstRest (?from ?newRoute).
}.
