コード例 #1
0
ファイル: 2_closest_warehouse.py プロジェクト: vlki/drones
import itertools
import sys
import copy
import math

from src.load_input import load_input
from src.util import distance, find_closest_nonempty_warehouses
from src.output import Output

if len(sys.argv) != 3:
    print("invalid number of params")
    print("run as: ./script input_file.in output_file.out")
    sys.exit(1)

world, initial_state = load_input(sys.argv[1])

# this is the function which is called anytime drone is idle and
# it decides what the drone will do next
#
# the idea behind this implementation is to find closest non-empty
# warehouse to drone which can deliver something for any order
# and find order which can be ideally fully
# delivered from this warehouse or order for which the drone can
# be fully loaded
def find_drone_action(state, d):
    if len(state.warehouses) == 1:
        # optimalization for scenario when there is just one warehouse
        closest_warehouses = state.warehouses[:]
    else:
        closest_warehouses = find_closest_nonempty_warehouses(state, d)
コード例 #2
0
ファイル: 1_w-o_cost.py プロジェクト: vlki/drones
#!/usr/bin/env python3

import itertools
import sys
import copy

from src.load_input import load_input
from src.util import distance

world, initial_state = load_input("inputs/busy_day.in")

def o_fulfilment_cost(o_fulfilment):
    cost = 0
    o, o_fulfilment = o_fulfilment

    # give me all the warehouse IDs from which this fulfilment would
    # get the product
    w_ids = [o_item_fulfilment[1] for o_item_fulfilment in o_fulfilment]

    for w_id in w_ids:
        cost += 2 * distance(initial_state.warehouses[w_id].pos, o.pos)

    return cost

def strategy_cost(strategy):
    cost = 0

    for oi, o_fulfilment in enumerate(strategy):
        o = initial_state.open_orders[oi]
        cost += o_fulfilment_cost((o, o_fulfilment))