android - 获取随机数据列表的算法/工作方法

标签 android performance algorithm

我正在开发一个 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/

相关文章:

java - 无法连接到 Openfire 服务器(使用 smack api)

android - 从 BroadcastReceiver 启动服务

asp.net - 将 MS Ajax Minfier 4.0 用于 Asp.Net MVC 2.0?

iphone:如何同步 2 个 NSMutableArrays 的内容?

python - 在 Python3 中绘制具有节点和边的网络

android - 将 Facebook 模块安装到 Android Studio 0.8.9

android - AlertDialog 自定义标题有黑色边框

linux - 为什么我的 Ubuntu Core 14.04 系统启动速度这么慢?

performance - 对于 VS Foreach on Array 性能(在 AS3/Flex 中)

python - 获取邻接列表中的所有叶子节点