Prolog - questions related to graph traversal












0















I'm fairly new to prolog and logic programming in general and took up this example to learn but I'm having a hard time with the solution. So, if someone can help me out or point me in the right direction, that would be really great.



The following is a list of predicates flight(city-a,city-b,airline,distance,time,cost) and country(city,state)



flight(london,dublin,aerlingus,500,45,150).
flight(rome,london,ba,1500,150,400).
flight(rome,paris,airfrance,1200,120,500).
flight(paris,dublin,airfrance,600,60,200).
flight(berlin,moscow,lufthansa,3000,300,900).
flight(paris,amsterdam,airfrance,400,30,100).
flight(berlin,dublin,lufthansa,1200,120,900).
flight(london,newyork,ba,5000,700,1100).
flight(dublin,newyork,aerlingus,4500,360,800).
flight(dublin,cork,ryanair,300,50,50).
flight(dublin,rome,ryanair,2000,150,70).
flight(dublin,chicago,aerlingus,5500,480,890).
flight(amsterdam,hongkong,klm,7000,660,750).
flight(london,hongkong,ba,7500,700,1000).
flight(dublin,amsterdam,ryanair,1000,90,60).
flight(moscow,newyork,aerflot,9000,720,1000).
flight(moscow,hongkong,aerflot,5500,420,500).
flight(newyork,chicago,aa,3000,240,430).
flight(dublin,london,aerlingus,500,45,150).
flight(london,rome,ba,1500,150,400).
flight(paris,rome,airfrance,1200,120,500).
flight(dublin,paris,airfrance,600,60,200).
flight(moscow,berlin,lufthansa,3000,300,900).
flight(amsterdam,paris,airfrance,400,30,100).
flight(dublin,berlin,lufthansa,1200,120,900).
flight(newyork,london,ba,5000,700,1100).
flight(newyork,dublin,aerlingus,4500,360,800).
flight(cork,dublin,ryanair,300,50,50).
flight(rome,dublin,ryanair,2000,150,70).
flight(chicago,dublin,aerlingus,5500,480,890).
flight(hongkong,amsterdam,klm,7000,660,750).
flight(hongkong,london,ba,7500,700,1000).
flight(amsterdam,dublin,ryanair,1000,90,60).
flight(newyork,moscow,aerflot,9000,720,1000).
flight(hongkong,moscow,aerflot,5500,420,500).
flight(chicago,newyork,aa,3000,240,430).
flight(dublin,sao_paulo,airfrance,10000,900,800).
flight(sao_paulo,newyork,airfrance,7000,840,650).
flight(rio,berlin,lufthansa,11000,1200,1100).

country(dublin,ireland).
country(cork,ireland).
country(london,uk).
country(rome,italy).
country(moscow,russia).
country(hongkong,china).
country(amsterdam,holland).
country(berlin,germany).
country(paris,france).
country(newyork,usa).
country(chicago,usa).
country(sao_paulo,brazil).
country(rio,brazil).


I need to design the following predicates -



1) trip(X,Y,T) where X and Y are two cities and T is the list of all cities connecting X and Y. eg. trip(rome,dublin,T) = [rome,london,dublin].



2) all_trip(X,Y,T) where X and Y are two cities and T is the list all possible solutions of predicate 1.



3) trip_dist(X,Y,[T,D]) where X and Y are two cities and W is a list [T|D] where the first element T is the trip from predicate 1 and D is the distance.



4) trip_cost(X,Y,[T,C]) same as predicate 3 but C is the total cost of the trip.










share|improve this question


















  • 4





    Please show your effort and what you have tried so that people can help.

    – TeeKea
    Nov 22 '18 at 21:37













  • If you search this site (e.g., [prolog] flights or [prolog] routes), you'll find this kind of problem comes up frequently. You should be able to get some ideas to get started and be able to ask a more specific question. If you've already tried some things, then please show what you've tried and ask about where you are stuck.

    – lurker
    Nov 23 '18 at 2:49


















0















I'm fairly new to prolog and logic programming in general and took up this example to learn but I'm having a hard time with the solution. So, if someone can help me out or point me in the right direction, that would be really great.



The following is a list of predicates flight(city-a,city-b,airline,distance,time,cost) and country(city,state)



flight(london,dublin,aerlingus,500,45,150).
flight(rome,london,ba,1500,150,400).
flight(rome,paris,airfrance,1200,120,500).
flight(paris,dublin,airfrance,600,60,200).
flight(berlin,moscow,lufthansa,3000,300,900).
flight(paris,amsterdam,airfrance,400,30,100).
flight(berlin,dublin,lufthansa,1200,120,900).
flight(london,newyork,ba,5000,700,1100).
flight(dublin,newyork,aerlingus,4500,360,800).
flight(dublin,cork,ryanair,300,50,50).
flight(dublin,rome,ryanair,2000,150,70).
flight(dublin,chicago,aerlingus,5500,480,890).
flight(amsterdam,hongkong,klm,7000,660,750).
flight(london,hongkong,ba,7500,700,1000).
flight(dublin,amsterdam,ryanair,1000,90,60).
flight(moscow,newyork,aerflot,9000,720,1000).
flight(moscow,hongkong,aerflot,5500,420,500).
flight(newyork,chicago,aa,3000,240,430).
flight(dublin,london,aerlingus,500,45,150).
flight(london,rome,ba,1500,150,400).
flight(paris,rome,airfrance,1200,120,500).
flight(dublin,paris,airfrance,600,60,200).
flight(moscow,berlin,lufthansa,3000,300,900).
flight(amsterdam,paris,airfrance,400,30,100).
flight(dublin,berlin,lufthansa,1200,120,900).
flight(newyork,london,ba,5000,700,1100).
flight(newyork,dublin,aerlingus,4500,360,800).
flight(cork,dublin,ryanair,300,50,50).
flight(rome,dublin,ryanair,2000,150,70).
flight(chicago,dublin,aerlingus,5500,480,890).
flight(hongkong,amsterdam,klm,7000,660,750).
flight(hongkong,london,ba,7500,700,1000).
flight(amsterdam,dublin,ryanair,1000,90,60).
flight(newyork,moscow,aerflot,9000,720,1000).
flight(hongkong,moscow,aerflot,5500,420,500).
flight(chicago,newyork,aa,3000,240,430).
flight(dublin,sao_paulo,airfrance,10000,900,800).
flight(sao_paulo,newyork,airfrance,7000,840,650).
flight(rio,berlin,lufthansa,11000,1200,1100).

country(dublin,ireland).
country(cork,ireland).
country(london,uk).
country(rome,italy).
country(moscow,russia).
country(hongkong,china).
country(amsterdam,holland).
country(berlin,germany).
country(paris,france).
country(newyork,usa).
country(chicago,usa).
country(sao_paulo,brazil).
country(rio,brazil).


I need to design the following predicates -



1) trip(X,Y,T) where X and Y are two cities and T is the list of all cities connecting X and Y. eg. trip(rome,dublin,T) = [rome,london,dublin].



2) all_trip(X,Y,T) where X and Y are two cities and T is the list all possible solutions of predicate 1.



3) trip_dist(X,Y,[T,D]) where X and Y are two cities and W is a list [T|D] where the first element T is the trip from predicate 1 and D is the distance.



4) trip_cost(X,Y,[T,C]) same as predicate 3 but C is the total cost of the trip.










share|improve this question


















  • 4





    Please show your effort and what you have tried so that people can help.

    – TeeKea
    Nov 22 '18 at 21:37













  • If you search this site (e.g., [prolog] flights or [prolog] routes), you'll find this kind of problem comes up frequently. You should be able to get some ideas to get started and be able to ask a more specific question. If you've already tried some things, then please show what you've tried and ask about where you are stuck.

    – lurker
    Nov 23 '18 at 2:49
















0












0








0








I'm fairly new to prolog and logic programming in general and took up this example to learn but I'm having a hard time with the solution. So, if someone can help me out or point me in the right direction, that would be really great.



The following is a list of predicates flight(city-a,city-b,airline,distance,time,cost) and country(city,state)



flight(london,dublin,aerlingus,500,45,150).
flight(rome,london,ba,1500,150,400).
flight(rome,paris,airfrance,1200,120,500).
flight(paris,dublin,airfrance,600,60,200).
flight(berlin,moscow,lufthansa,3000,300,900).
flight(paris,amsterdam,airfrance,400,30,100).
flight(berlin,dublin,lufthansa,1200,120,900).
flight(london,newyork,ba,5000,700,1100).
flight(dublin,newyork,aerlingus,4500,360,800).
flight(dublin,cork,ryanair,300,50,50).
flight(dublin,rome,ryanair,2000,150,70).
flight(dublin,chicago,aerlingus,5500,480,890).
flight(amsterdam,hongkong,klm,7000,660,750).
flight(london,hongkong,ba,7500,700,1000).
flight(dublin,amsterdam,ryanair,1000,90,60).
flight(moscow,newyork,aerflot,9000,720,1000).
flight(moscow,hongkong,aerflot,5500,420,500).
flight(newyork,chicago,aa,3000,240,430).
flight(dublin,london,aerlingus,500,45,150).
flight(london,rome,ba,1500,150,400).
flight(paris,rome,airfrance,1200,120,500).
flight(dublin,paris,airfrance,600,60,200).
flight(moscow,berlin,lufthansa,3000,300,900).
flight(amsterdam,paris,airfrance,400,30,100).
flight(dublin,berlin,lufthansa,1200,120,900).
flight(newyork,london,ba,5000,700,1100).
flight(newyork,dublin,aerlingus,4500,360,800).
flight(cork,dublin,ryanair,300,50,50).
flight(rome,dublin,ryanair,2000,150,70).
flight(chicago,dublin,aerlingus,5500,480,890).
flight(hongkong,amsterdam,klm,7000,660,750).
flight(hongkong,london,ba,7500,700,1000).
flight(amsterdam,dublin,ryanair,1000,90,60).
flight(newyork,moscow,aerflot,9000,720,1000).
flight(hongkong,moscow,aerflot,5500,420,500).
flight(chicago,newyork,aa,3000,240,430).
flight(dublin,sao_paulo,airfrance,10000,900,800).
flight(sao_paulo,newyork,airfrance,7000,840,650).
flight(rio,berlin,lufthansa,11000,1200,1100).

country(dublin,ireland).
country(cork,ireland).
country(london,uk).
country(rome,italy).
country(moscow,russia).
country(hongkong,china).
country(amsterdam,holland).
country(berlin,germany).
country(paris,france).
country(newyork,usa).
country(chicago,usa).
country(sao_paulo,brazil).
country(rio,brazil).


I need to design the following predicates -



1) trip(X,Y,T) where X and Y are two cities and T is the list of all cities connecting X and Y. eg. trip(rome,dublin,T) = [rome,london,dublin].



2) all_trip(X,Y,T) where X and Y are two cities and T is the list all possible solutions of predicate 1.



3) trip_dist(X,Y,[T,D]) where X and Y are two cities and W is a list [T|D] where the first element T is the trip from predicate 1 and D is the distance.



4) trip_cost(X,Y,[T,C]) same as predicate 3 but C is the total cost of the trip.










share|improve this question














I'm fairly new to prolog and logic programming in general and took up this example to learn but I'm having a hard time with the solution. So, if someone can help me out or point me in the right direction, that would be really great.



The following is a list of predicates flight(city-a,city-b,airline,distance,time,cost) and country(city,state)



flight(london,dublin,aerlingus,500,45,150).
flight(rome,london,ba,1500,150,400).
flight(rome,paris,airfrance,1200,120,500).
flight(paris,dublin,airfrance,600,60,200).
flight(berlin,moscow,lufthansa,3000,300,900).
flight(paris,amsterdam,airfrance,400,30,100).
flight(berlin,dublin,lufthansa,1200,120,900).
flight(london,newyork,ba,5000,700,1100).
flight(dublin,newyork,aerlingus,4500,360,800).
flight(dublin,cork,ryanair,300,50,50).
flight(dublin,rome,ryanair,2000,150,70).
flight(dublin,chicago,aerlingus,5500,480,890).
flight(amsterdam,hongkong,klm,7000,660,750).
flight(london,hongkong,ba,7500,700,1000).
flight(dublin,amsterdam,ryanair,1000,90,60).
flight(moscow,newyork,aerflot,9000,720,1000).
flight(moscow,hongkong,aerflot,5500,420,500).
flight(newyork,chicago,aa,3000,240,430).
flight(dublin,london,aerlingus,500,45,150).
flight(london,rome,ba,1500,150,400).
flight(paris,rome,airfrance,1200,120,500).
flight(dublin,paris,airfrance,600,60,200).
flight(moscow,berlin,lufthansa,3000,300,900).
flight(amsterdam,paris,airfrance,400,30,100).
flight(dublin,berlin,lufthansa,1200,120,900).
flight(newyork,london,ba,5000,700,1100).
flight(newyork,dublin,aerlingus,4500,360,800).
flight(cork,dublin,ryanair,300,50,50).
flight(rome,dublin,ryanair,2000,150,70).
flight(chicago,dublin,aerlingus,5500,480,890).
flight(hongkong,amsterdam,klm,7000,660,750).
flight(hongkong,london,ba,7500,700,1000).
flight(amsterdam,dublin,ryanair,1000,90,60).
flight(newyork,moscow,aerflot,9000,720,1000).
flight(hongkong,moscow,aerflot,5500,420,500).
flight(chicago,newyork,aa,3000,240,430).
flight(dublin,sao_paulo,airfrance,10000,900,800).
flight(sao_paulo,newyork,airfrance,7000,840,650).
flight(rio,berlin,lufthansa,11000,1200,1100).

country(dublin,ireland).
country(cork,ireland).
country(london,uk).
country(rome,italy).
country(moscow,russia).
country(hongkong,china).
country(amsterdam,holland).
country(berlin,germany).
country(paris,france).
country(newyork,usa).
country(chicago,usa).
country(sao_paulo,brazil).
country(rio,brazil).


I need to design the following predicates -



1) trip(X,Y,T) where X and Y are two cities and T is the list of all cities connecting X and Y. eg. trip(rome,dublin,T) = [rome,london,dublin].



2) all_trip(X,Y,T) where X and Y are two cities and T is the list all possible solutions of predicate 1.



3) trip_dist(X,Y,[T,D]) where X and Y are two cities and W is a list [T|D] where the first element T is the trip from predicate 1 and D is the distance.



4) trip_cost(X,Y,[T,C]) same as predicate 3 but C is the total cost of the trip.







graph prolog logic traversal






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 21:19









suntan.supermansuntan.superman

1




1








  • 4





    Please show your effort and what you have tried so that people can help.

    – TeeKea
    Nov 22 '18 at 21:37













  • If you search this site (e.g., [prolog] flights or [prolog] routes), you'll find this kind of problem comes up frequently. You should be able to get some ideas to get started and be able to ask a more specific question. If you've already tried some things, then please show what you've tried and ask about where you are stuck.

    – lurker
    Nov 23 '18 at 2:49
















  • 4





    Please show your effort and what you have tried so that people can help.

    – TeeKea
    Nov 22 '18 at 21:37













  • If you search this site (e.g., [prolog] flights or [prolog] routes), you'll find this kind of problem comes up frequently. You should be able to get some ideas to get started and be able to ask a more specific question. If you've already tried some things, then please show what you've tried and ask about where you are stuck.

    – lurker
    Nov 23 '18 at 2:49










4




4





Please show your effort and what you have tried so that people can help.

– TeeKea
Nov 22 '18 at 21:37







Please show your effort and what you have tried so that people can help.

– TeeKea
Nov 22 '18 at 21:37















If you search this site (e.g., [prolog] flights or [prolog] routes), you'll find this kind of problem comes up frequently. You should be able to get some ideas to get started and be able to ask a more specific question. If you've already tried some things, then please show what you've tried and ask about where you are stuck.

– lurker
Nov 23 '18 at 2:49







If you search this site (e.g., [prolog] flights or [prolog] routes), you'll find this kind of problem comes up frequently. You should be able to get some ideas to get started and be able to ask a more specific question. If you've already tried some things, then please show what you've tried and ask about where you are stuck.

– lurker
Nov 23 '18 at 2:49














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438097%2fprolog-questions-related-to-graph-traversal%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438097%2fprolog-questions-related-to-graph-traversal%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno