Code doesnt work as intended

My code looks like this:

arco(braga, viana_castelo, 5, 55).
arco(braga, esposende, 5, 34).
arco(braga, povoa_varzim, 5, 55).
arco(braga, guimaraes, 5, 25).
arco(braga, aveiro, 5, 100).
arco(viana_castelo, guimaraes, 10, 81).
arco(viana_castelo, esposende, 10, 25).
arco(esposende, povoa_varzim, 3, 15).
arco(esposende, porto, 3, 50).
arco(povoa_varzim, porto, 7, 30).
arco(guimaraes, penafiel, 24, 40).
arco(penafiel, porto, 15, 20).
arco(aveiro, porto, 40, 25).

passageiros(A, B, [A, B], X) :-                      
    arco(A, B, X, _).

passageiros(A, B, PathAB, Length) :-
    arco(A, C, X,_),                             
    passageiros(C, B, PathCB, LengthCB),            
    PathAB = [A | PathCB],                       
    Length is X + LengthCB.

caminho_mais_passageiros(A, B) :-
   findall(p(Len, Path),passageiros(A, B, Path, Len),Paths),
   sort(Paths, R),
   last(R, S),
   S = (p(Len,Pat)),
   Len is =<45,    %% This line is not working and its gives me a error
   printPath(Pat), writef( ' Numero de passageiros = %d\n ', [Len]).

printPath([]).
printPath([X]) :-
    !, write(X).
printPath([X|T]) :-
    write(X),
    write(', '),
    printPath(T).

How can i make the line (Len is =<45, ) work ? I want the values that are <=45

See: Difference between two values

i dont think its that

?- Len = 50, Len =< 45.
false.

?- Len = 40, Len =< 45.
Len = 40.

Does not print the Len =< 45 , just says false, and i want to print the value =< 45

Use gtrace/0 to find out why it is not working:

?- gtrace, caminho_mais_passageiros(A,B).

TIP: you are sorting the paths in ascending order and taking the last element after sorting (the last element would be the longest path, not the shortest).