logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Janet FearnleyPsychology
(4/5)

969 Answers

Hire Me
expert
Adarsh Vikram RaiComputer science
(/5)

926 Answers

Hire Me
expert
Marvin BittleBusiness
(5/5)

693 Answers

Hire Me
expert
Peter EllisAccounting
(5/5)

935 Answers

Hire Me
Others
(5/5)

Write a predicate route 3 to plan routes route Start Finish Visits should succeed if there is a route from Start to Finish visiting the towns in list Visits

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

COMP 304 Assignment 4

(More Prolog)

Introduction

All your work must be submitted electronically. Submit a plain text Prolog code file named COMP304A4.pl. Any other material (which includes any additional descriptions of the way you chose to solve any of the problems) must be in .pdf or .txt format.

All your code must be properly commented on. Use comments extensively to communicate the purpose of each predicate, its variables and clauses, and what the overall design of your program is.

Supply sample queries that demonstrate the functionality of your programs as requested in the following questions. These may derive from queries you have used in your own testing but make sure that your sample queries are not too high in numbers, yet still manage to demonstrate all functionality.

Some of the assessment may be automated, so please ensure to comply to the details listed below.

1 Auto Router

Table 1 describes the North Island’s major road network and the distances between towns.

1.1 Road Database

Define a predicate road/3 to capture this information. You will use this predicate to help plan route around the North Island.

One condition which we demand of any route is that no town is visited twice; every station of a route should provide a new town to enjoy.

From                              To                             km

Wellington                  Palmerston North       143

Palmerston North      Wanganui                     74

Palmerston North       Napier                         178

Palmerston North      Taupo                           259

Wanganui                  Taupo                           231

Wanganui                  New Plymouth             163

Wanganui                  Napier                          252

Napier                       Taupo                           147

Napier                       Gisborne                      215

New Plymouth          Hamilton                     242

New Plymouth          Taupo                          289

Taupo                        Hamilton                     153

Taupo                        Rotorua                        82

Taupo                       Gisborne                      334

Gisborne                  Rotorua                        291

Rotorua                   Hamilton                      109

Hamilton                 Auckland                      126

Table 1: Connection data

1.2 Route Planning

Write a predicate route/3 to plan routes: route(Start, Finish, Visits) should succeed if there is a route from Start to Finish visiting the towns in list Visits.

1.3 Route Planning With Distances

Write a predicate route/4 to plan routes: route(Start, Finish, Visits, Distance) should succeed if there is a route from Start to Finish, visiting the towns in list Visits, which is overall Distance long.

1.4 Finding All Routes

There is a predefined Prolog predicate findall/3 which you can use to find all the solutions to a goal. The first argument to findall is a Prolog term, the second argument is a Prolog goal and the third argument is a list. The list becomes bound to the list of instances of the term for which the goal succeeds. Using findall only makes sense if there are variables shared between the term and the goal. Often the term is just a variable, but it can be any term.

For example:

?- findall((X,Y), append(X, Y, [1,2]), Results).

Results = [ ([], [1, 2]), ([1], [2]), ([1, 2], [])].

Write a predicate choice/3 to help plan routes: Predicate choice(Start, Finish, RoutesAndDistances) should produce a list of all the routes (including their distances) between Start and Finish.

1.4.1 Finding All Routes Including Towns

Write a predicate via/4 to help planning routes: via(Start, Finish, Via, RoutesAndDistances) should produce a list of all the routes (including their distances) between Start and Finish which visit towns within Via.

1.4.2 Finding All Routes Avoiding Towns

Write a predicate avoiding/4 to help plan routes: avoiding(Start, Finish, Avoiding, RoutesAndDistances) should produce a list of all the routes (including their distances) between Start and Finish which do not visit towns within Avoiding.

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme