Reputation: 13555
I am working on a android schedule app but that isn't matter , the problem is a algorithm / methodology so you are welcome to just write the pusedo code to answer.
The data is like this
Place
=============
Name
lat
lng
duration
isBookMark
type
Note: There are **only** two type: Shop , Park ,
duration is the time base on hour e.g. 1 => 1hour, 0.5 hour etc....
lat lng are the location unit
So, I would like to generate a random place list based on the following criteria:
1.) There are 2 duration limit
if short limit, then I need to get exactly 1 Park and some Shop , based on the hour 3 - 5 is given
if medium limit, I need to get exactly 2 Park and some Shop, based on the hour 6 -8 is given
if long limit, then I need to get exactly 3 Park and some Shop , based on the hour 9 - 11 is given
2. ) The user can select whether the bookmarked item is higher priority, so it may need to handle bookmark higher priority when select the item.
3. ) Also, the next place chosen must be the nearest place. You can assume there is already a `calcuateDistanceDiff()` function aviliable
So , how to generate a list in the above case:
I have tried to simply like "hardcode" to handle the duration limit one by one e.g. get one Park first and get the next by checking the priority / distance one by one , but there should be some more wise way to create a more generic "methodology" to handle this, in terms of better performance and elegant.
Thanks for helping
Upvotes: 0
Views: 54
Reputation: 7872
Why don't you add for each Park few Nearest Shops on init??
But you'll have to change few things to implements class inhéritance :
class Place {
string name;
LatLng latLng
double dur;
bool isBookMark;
}
class Park extends Place {
ArrayList<Shop> nearestParks;
}
class Shop extends Place {
}
When your are creating a Shop, you look at all the Parks and add in the list if near enought.
Upvotes: 1