我正在开发一个 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
那么,在上面的例子中如何生成列表:
我试图简单地喜欢“硬编码”来一个一个地处理持续时间限制,例如 首先获得一个公园,然后通过一个接一个地检查优先级/距离来获得下一个公园,但应该有一些更明智的方法来创建更通用的“方法论”来处理这个问题,在更好的性能和优雅方面。
感谢帮助
最佳答案
为什么不在初始化时为每个公园添加几个最近的商店?
但是你必须改变一些东西来实现类继承:
class Place {
string name;
LatLng latLng
double dur;
bool isBookMark;
}
class Park extends Place {
ArrayList<Shop> nearestParks;
}
class Shop extends Place {
}
当您创建商店时,您会查看所有公园并在足够的情况下添加到列表中。
关于android - 获取随机数据列表的算法/工作方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22769091/