2014-03-31 2 views
0

안드로이드 일정 응용 프로그램에서 작업하고 있지만 문제가되지 않습니다. 문제는 알고리즘/방법론이므로 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 

그래서, 어떻게 위의 목록을 작성하기를 사례 :

나는 단순히 "하드 코드"를 사용하여 기간 제한을 하나씩 처리하려고했습니다. 우선 공원 하나를 가져 와서 우선 순위/거리를 하나씩 확인하여 다음 단계로 넘어 가야합니다. 그러나 더 나은 성능과 우아함을 고려하여보다 일반적인 "방법론"을 만들어보다 현명한 방법으로이를 처리해야합니다.

도움을 주셔서 감사합니다.

답변

1

왜 각 공원에 초기화에 가까운 상점을 몇 개 추가하지 않으시겠습니까 ??

하지만 당신은 클래스 상속을 구현하기 위해 몇 가지를 변경해야합니다 : 귀하가 가게를 만들 때

class Place { 
    string name; 
    LatLng latLng 
    double dur; 
    bool isBookMark; 
} 
class Park extends Place { 
    ArrayList<Shop> nearestParks; 
} 
class Shop extends Place { 
} 

, 모든 공원을보고 한 정도로 가까운 경우 목록에 추가 할 수 있습니다.

관련 문제