Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #option:
- # 1 - small_orders_first
- # 2 - closest_distance
- # 3 - random
- # 4 - mathematical
- def score(dwo, option):
- if option == 1:
- return score_small_orders_first(dwo)
- elif option == 2:
- return score_closest_distance(dwo)
- elif option == 3:
- return score_random(dwo)
- else:
- return score_mathematically_correct(dwo)
- def score_small_orders_first(dwo):
- (drone, warehouse, order) = dwo
- order_product_count = 0
- common_products = 0
- for i in [0..len(warehouse.products)]:
- if i in order.products:
- order_product_count += 1
- if warehouse.products[i] > 0:
- common_products += min(order.products[i], warehouse.products[i])
- if common_products == 0:
- return 10000
- else:
- score = (2000.0 * order_product_count) + (13.0 / dist_sq(drone, warehouse))
- return 1.0 / score
- def score_closest_distance(dwo):
- (d, w, o) = dwo
- return dist_sq(d,w) + dist_sq(w,o) + dist_sq(d,o)
- import random
- def score_random(dwo):
- return random.random()
- def score_mathematically_correct(dwo):
- (d, w, o) = dwo
- return get_score(d,w,o);
- def get_score(drone, warehouse, order):
- wo_common_products = 0
- wo_common_product_weight = 0
- dw_warehouse_variety = 1
- for i in [0..len(warehouse.products)]:
- if (warehouse.products[i] > 0):
- dw_warehouse_variety += 1
- if (i in order.products):
- wo_common_products += min(order.products[i], warehouse.products[i])
- wo_common_product_weight += product_type_weight[i] * wo_common_products
- dw_warehouse_centrality = 1
- wo = (wo_common_product_weight * dist_sq(warehouse, order)) / (1.0 + wo_common_products)
- dw = (dist_sq(warehouse, drone)) / (1.0 + (dw_warehouse_centrality * dw_warehouse_variety))
- def can_pickup(prod_id, available_amount, available_weight):
- local_weight = available_weight
- ret = 0
- for i in [0..available_amount]:
- if (local_weight - product_type_weight[prod_id]) > 0:
- ret += 1
- return ret
- def decision_result(dwo):
- (drone, warehouse, order) = dwo
- available_weight = MAX_WEIGHT - drone.weight
- ret_dict = {}
- for i in [0..len(warehouse.products)]:
- if (warehouse.products[i] > 0) and (i in order.products):
- ret_dict[i] = can_pickup(i, min(order.products[i], warehouse.products[i]), available_weight)
- return ret_dict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement