0

Theres a problem such that there are n houses a1,...an on a straight line. You want to build facilities such that each house is at most distance X from a facility. There are p locations b1,...bp that the facilities can be built. I am trying to figure a greedy algorithm to figure out what is the minimum number of facilities that can be built.

How would I go about solving this?

  • Have a look here: https://en.wikipedia.org/wiki/Facility_location_problem – shapiro yaacov Oct 18 '15 at 07:27
  • Here is a [similar question](http://stackoverflow.com/questions/33177619/dynamic-programming-algorithm-for-facility-locations/33179250). As the only difference is that you have no cost on placing facilities,you can modify your solution accordingly. – Rahul Nori Oct 18 '15 at 08:06

1 Answers1

0

For each location (B1,...,Bp), create a list that contains the houses that are within X distance from that location.

Create a list of houses (lets call this list "NeedToCover") that initially contains all of the houses.

Now go through each location's list and determine which location's list covers the most houses in the "NeedToCover" list. This will be the the location where you will build your facility.

After building the facility, remove all the houses in "NeedToCover" that was covered by that location that you had just picked.

Repeat the above steps with the remaining houses in "NeedToCover" and the remaining locations until "NeedToCover" is empty, in which that means all houses are within X distance from a facility.

(This algorithm is greedy because each time you are picking the location that covers the most houses out of the remaining houses "without regard for the future.")

Arararagi
  • 83
  • 1
  • 9