Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1.  
  2. #option:
  3. #   1 - small_orders_first
  4. #   2 - closest_distance
  5. #   3 - random
  6. #   4 - mathematical
  7. def score(dwo, option):
  8.     if option == 1:
  9.         return score_small_orders_first(dwo)
  10.     elif option == 2:
  11.         return score_closest_distance(dwo)
  12.     elif option == 3:
  13.         return score_random(dwo)
  14.     else:
  15.         return score_mathematically_correct(dwo)
  16.  
  17.  
  18. def score_small_orders_first(dwo):
  19.     (drone, warehouse, order) = dwo
  20.     order_product_count = 0
  21.     common_products = 0
  22.  
  23.     for i in [0..len(warehouse.products)]:
  24.         if i in order.products:
  25.             order_product_count += 1
  26.             if warehouse.products[i] > 0:
  27.                 common_products += min(order.products[i], warehouse.products[i])
  28.  
  29.     if common_products == 0:
  30.         return 10000
  31.     else:
  32.         score = (2000.0 * order_product_count) + (13.0 / dist_sq(drone, warehouse))
  33.         return 1.0 / score
  34.  
  35.  
  36. def score_closest_distance(dwo):
  37.     (d, w, o) = dwo
  38.     return dist_sq(d,w) + dist_sq(w,o) + dist_sq(d,o)
  39.  
  40.  
  41. import random
  42. def score_random(dwo):
  43.     return random.random()
  44.  
  45.  
  46. def score_mathematically_correct(dwo):
  47.     (d, w, o) = dwo
  48.     return get_score(d,w,o);
  49.  
  50. def get_score(drone, warehouse, order):
  51.     wo_common_products = 0
  52.     wo_common_product_weight = 0
  53.     dw_warehouse_variety = 1
  54.  
  55.     for i in [0..len(warehouse.products)]:
  56.         if (warehouse.products[i] > 0):
  57.             dw_warehouse_variety += 1
  58.             if (i in order.products):
  59.                 wo_common_products += min(order.products[i], warehouse.products[i])
  60.                 wo_common_product_weight += product_type_weight[i] * wo_common_products
  61.  
  62.  
  63.     dw_warehouse_centrality = 1
  64.  
  65.     wo = (wo_common_product_weight * dist_sq(warehouse, order)) / (1.0 + wo_common_products)
  66.     dw = (dist_sq(warehouse, drone)) / (1.0 + (dw_warehouse_centrality * dw_warehouse_variety))
  67.  
  68.  
  69. def can_pickup(prod_id, available_amount, available_weight):
  70.     local_weight = available_weight
  71.     ret = 0
  72.     for i in [0..available_amount]:
  73.         if (local_weight - product_type_weight[prod_id]) > 0:
  74.             ret += 1
  75.  
  76.     return ret
  77.  
  78.  
  79. def decision_result(dwo):
  80.     (drone, warehouse, order) = dwo
  81.     available_weight = MAX_WEIGHT - drone.weight
  82.     ret_dict = {}
  83.  
  84.     for i in [0..len(warehouse.products)]:
  85.         if (warehouse.products[i] > 0) and (i in order.products):
  86.             ret_dict[i] = can_pickup(i, min(order.products[i], warehouse.products[i]), available_weight)
  87.  
  88.     return ret_dict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement