示例#1
0
文件: main.py 项目: klangner/santa
def solution():
    print('Load data...')
    data = load_data()
    print('Find trips...')
    trips = find_trips(data)
    print('Save trips...')
    save_solution(trips)
    print('Calculate score for %d trips...' % len(trips))
    score = santa.weighted_reindeer_weariness(trips)
    print(score)
示例#2
0
文件: greedy.py 项目: klangner/santa

def greedy2(df):
    """
    Try to get 2 gifts every time
    :param df: data
    :return: DataFrame with trip id
    """
    df = df.sort(['Longitude', 'Latitude'])
    trip_id = -1
    df['TripId'] = 0
    last_pos = santa.NORTH_POLE
    for i, row in df.iterrows():
        pos = row['Longitude'], row['Latitude']
        if i % 2 == 0 or santa.haversine(pos, last_pos) > santa.haversine(pos, santa.NORTH_POLE)/3:
            trip_id += 1
            last_pos = pos
        df.set_value(i, 'TripId', trip_id)
    return df


def save_solution(df):
    df[['GiftId', 'TripId']].to_csv('../data/solution.csv', index=False)


data = load_data()
solution = greedy2(data)
save_solution(solution)
score = santa.weighted_reindeer_weariness(solution)
print(score)