Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

programming in R Implement a greedy nearest-neighbour approach to find a suitable route for visiting all houses (pairs of coordinates generated) ( shortest route possible).

programming in R

Implement a greedy nearest-neighbour approach to find a suitable route for visiting all houses (pairs of coordinates generated) ( shortest route possible).

Starting at house 1, visit the house nearest to house 1 first. Then, each time move on to the nearest house not yet visited and, after visiting all houses, return to house 1.

Suppose house 1 is at point (0,1) .

Write a function called gp which will take the matrix of coordinates of the houses as argument and will return

the coordinates of the path found by the greedy algorithm.

( You can generate a set of coordinates of the houses using the function gen.h

gen.h=function(n=10) { while (TRUE) { r <- sqrt(runif(n))*0.9 phi <- runif(n) * 2 * pi houses <- cbind(x=r*sin(phi), y=r*cos(phi)) if (min(dist(houses))>0.15) return(houses) } }

houses <- gen.h ()

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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. What is the impact of information systems on organizations?

Answered: 1 week ago

Question

Evaluate the impact of technology on HR employee services.

Answered: 1 week ago