Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

implent class Trip Planner with locate _ all, plan _ route, and find _ nearby in dssl 2 given these directions: locate - all Takes

implent class Trip Planner with locate_all, plan_route, and find_nearby in dssl2 given these directions:
locate-all Takes a point-of-interest category; returns the positions of all points-
order you want, but the result should not include duplicates.
plan-route Takes a starting position (latitude and longitude) and the name of
a point-of-interest; returns a shortest path from the starting position to
the named point-of-interest. You can assume the starting position is at a
road segment endpoint. Returns the empty list if the destination does not
exist or is unreachable.
find-nearby Takes a starting position (latitude and longitude), a point-of-
interest category, and a limit n; returns the (up to) n points-of-interest
in the given category nearest the starting position. You can assume the
starting position is at a road segment endpoint. Resolve ties however you
want, and order points-of-interest within the list in any order you want.
#lang dssl2
# Final project: Trip Planner
import cons
### Basic Types ###
# - Latitudes and longitudes are numbers:
let Lat? = num?
let Lon? = num?
# - Point-of-interest categories and names are strings:
let Cat? = str?
let Name? = str?
# - Raw positions are 2-element vectors with a latitude and a longitude
let RawPos? = TupC[Lat?, Lon?]
# - Raw road segments are 4-element vectors with the latitude and
# longitude of their first endpoint, then the latitude and longitude
# of their second endpoint
let RawSeg? = TupC[Lat?, Lon?, Lat?, Lon?]
# - Raw points-of-interest are 4-element vectors with a latitude, a
# longitude, a point-of-interest category, and a name
let RawPOI? = TupC[Lat?, Lon?, Cat?, Name?]
### Contract Helpers ###
# ListC[T] is a list of `T`s (linear time):
let ListC = Cons.ListC
# List of unspecified element type (constant time):
let List? = Cons.list?
interface TRIP_PLANNER:
# Returns the positions of all the points-of-interest that belong to
# the given category.
def locate_all(
self,
dst_cat: Cat? # point-of-interest category
)-> ListC[RawPos?] # positions of the POIs
# Returns the shortest route, if any, from the given source position
# to the point-of-interest with the given name.
def plan_route(
self,
src_lat: Lat?, # starting latitude
src_lon: Lon?, # starting longitude
dst_name: Name? # name of goal
)-> ListC[RawPos?] # path to goal
# Finds no more than `n` points-of-interest of the given category
# nearest to the source position.
def find_nearby(
self,
src_lat: Lat?, # starting latitude
src_lon: Lon?, # starting longitude
dst_cat: Cat?, # point-of-interest category
n: nat? # maximum number of results
)-> ListC[RawPOI?] # list of nearby POIs
class TripPlanner (TRIP_PLANNER):
pass
# ^ YOUR PART GOES HERE
def my_first_example():
return TripPlanner([[0,0,0,1],[0,0,1,0]],
[[0,0, "bar", "The Empty Bottle"],
[0,1, "food", "Pierogi"]])
test 'My first locate_all test':
assert my_first_example().locate_all("food")==\
cons([0,1], None)
test 'My first plan_route test':
assert my_first_example().plan_route(0,0, "Pierogi")==\
cons([0,0], cons([0,1], None))
test 'My first find_nearby test':
assert my_first_example().find_nearby(0,0, "food", 1)==\
cons([0,1, "food", "Pierogi"], None)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions