我正在开发一个Android计划应用程序,但这并不重要,问题是算法/方法,所以欢迎您编写pusedo代码来回答。
数据就像这样
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
所以,我想基于以下标准生成随机位置列表:
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
那么,如何在上述情况下生成列表:
我试图简单地喜欢"硬编码"一个接一个地处理持续时间限制,例如 首先获得一个Park并通过逐个检查优先级/距离来获得下一个,但是应该有一些更明智的方法来创建更通用的方法"处理这个,在更好的性能和优雅方面。
感谢您的帮助
答案 0 :(得分:1)
为什么不在init上为每个Park添加几个最近的商店?
但是你必须改变一些东西来实现类inhéritance:
class Place {
string name;
LatLng latLng
double dur;
bool isBookMark;
}
class Park extends Place {
ArrayList<Shop> nearestParks;
}
class Shop extends Place {
}
当你创建一个商店时,你会看到所有的公园,并在附近的地方添加。