如何列出放弃一家航空公司的所有行程 [英] How to list all the trips discarding one airline

查看:40
本文介绍了如何列出放弃一家航空公司的所有行程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的航班数据

#flight(city1, city2,airline,distance,time,price).
flight(dublin, london,ab,8000,4,1000).
flight(moscow,london,ab,9000,5,2000).
flight(dublin,moscow,bc,1000,6,3000).
flight(cork, moscow,ca,2000,7,4000).
flight(chicago, dublin,ab,6000,8,4500).
flight(berlin, moscow,bc,3000,9,4600).
flight(cork, newyork,ca,4000,10,4700).
flight(paris, hongkong,bc,11000,11,4890).

connected(X,Y,_,_,_,_) :- flight(X,Y,_,_,_,_) ; flight(Y,X,_,_,_,_). 

我必须放弃一个航空公司,获得 city1 和 city2 之间的所有行程

I have to get all the trips between city1 and city2 discarding one airline

我已经计算过类似的行程

I have calculated the trip something like

trips(A,B,Path) :- 
      traverse(A,B,[A],Q),
      reverse(Q,Path).
 traverse(A,B,P,[B|P]) :-
         connected(A,B,_,_,_,_).
  traverse(A,B,Visited,Path) :-
         connected(A,C,_,_,_,_),
         C \== B,
         \+member(C,Visited),
         traverse(C,B,[C|Visited],Path). 

这是all_trip

Alltrip(C,L,T):-
      findall(Ci, trips(C,L,Ci), T).

我必须计算这个

Alltrip_noairline(X,Y,T,A):- 其中 X 和 Y 是城市,T 是所有行程的列表,并丢弃包含航空公司 A 航班的所有行程

Alltrip_noairline(X,Y,T,A):- where X and Y are city ,T is the list of all trips and DISCARD all the trip containing a flight with airline A

我被困在这里,不知道如何开始,任何帮助将不胜感激.谢谢

I am stuck here ,don't know how to start ,any help would be appreciated .Thanks

推荐答案

我相信 connected/6 实际上是 flight/6

您可以在程序中添加过滤器目标:

You may add a Filter goal to your procedures:

trips(A,B,Filter, Path) :-
  traverse(A,B,Filter, [A],Q),
  reverse(Q,Path).

traverse(A,B, Filter, P,[B|P]) :-
  flight(A,B,Airline,_,_,_),
  call(Filter, Airline).
traverse(A,B, Filter, Visited,Path) :-
  flight(A,C,Airline,_,_,_),
  C \== B,
  call(Filter, Airline),
   \+ member(C,Visited),
  traverse(C,B, Filter, [C|Visited],Path).

然后在 alltrip/3 中使用接受任何航空公司的过滤器:

Then in alltrip/3 use a filter that accepts any airline:

alltrip(C,L,T):-
   findall(Ci, trips(C,L, any, Ci), T).

any(_).

并且在 alltrip_noairline/4 中禁止某些航空公司:

and in alltrip_noairline/4 one that forbids certain airline:

alltrip_noairline(C,L,T, A):-
   findall(Ci, trips(C,L, except(A), Ci), T).   

except(X, Y):- X\=Y.

这篇关于如何列出放弃一家航空公司的所有行程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆