% In this problem, use prim’s algorithm to solve
% an airport and airline related problem
% use cut because we want minimum spanning Tree
Copyright By PowCoder代写 加微信 powcoder
% Assuming graph is connected, we can use edges to describe the graph
% Find the minumum spanning tree
% use the following predicate to init the graph
edges(Edges) :-
a(ord,bwi,621),
a(ord,bos,867),
a(bos,sfo,2704),
a(ord,sfo,1846),
a(bwi,jfk,184),
a(mia,bwi,946),
a(jfk,mia,1090),
a(bos,jfk,187),
a(ord,dfw,802),
a(lax,mia,2342),
a(pvd,jfk,144),
a(mia,bos,1258),
a(lax,sfo,337),
a(dfw,jfk,1391),
a(dfw,sfo,1464),
a(ord,jfk,740),
a(dfw,lax,1235),
a(mia,dfw,1121),
a(pvd,ord,849)].
% using prim’s algorithm
% Implement mst(Tree,Edges,TotalCost)
% Tree is the Minimum Spanning Tree
% Edges are all the edges of the connected graph
% TotalCost is the total cost of the MST
% Use cut because of the nature of the problem (Minimum).
% Do not change the code below
solve(Tree, TotalCost):- edges(Edges), mst(Tree,Edges,TotalCost).
% Result is the following. Note the format of the tree
% Tree = [lax-sfo, dfw-lax, bwi-mia, ord-dfw, jfk-bos, jfk-pvd, bwi-jfk, ord-bwi]
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com