def solve_easy(in_path, out_path): in_file = InFile(in_path) out_file = OutFile(out_path) states = DroneStates(in_file) d = 0 # Current drone number print(in_file.orders) orderNb = 0 for order_id in range(0, in_file.c): orderNb += 1 order = in_file.orders[order_id] for i in range(0, len(order["product_ids"])): for j in range(i + 1, len(order["product_ids"])): if order["product_ids"][i] == order["product_ids"][j]: d += 1 print"Order : %d ID1 : %d ID2 : %d DOUBLON" % (orderNb, order["product_ids"][i], order["product_ids"][j]) #else: #print"Order : %d ID1 : %d ID2 : %d" % (orderNb, order["product_ids"][i], order["product_ids"][j]) print(d) out_file.write()
def solve_easy(in_path, out_path): in_file = InFile(in_path) out_file = OutFile(out_path) states = DroneStates(in_file) d = 0 # Current drone number print(in_file.orders) orderNb = 0 for order_id in range(0, in_file.c): orderNb += 1 order = in_file.orders[order_id] for i in range(0, len(order["product_ids"])): for j in range(i + 1, len(order["product_ids"])): if order["product_ids"][i] == order["product_ids"][j]: d += 1 print "Order : %d ID1 : %d ID2 : %d DOUBLON" % ( orderNb, order["product_ids"][i], order["product_ids"][j]) #else: #print"Order : %d ID1 : %d ID2 : %d" % (orderNb, order["product_ids"][i], order["product_ids"][j]) print(d) out_file.write()
def generate_cpp(header_name): cpp_name = re.sub(r".(h|hpp)", ".cpp", header_name) outfile = OutFile(cpp_name) header_content = cpp_parser.file_read(header_name) namespaces = cpp_parser.get_namespaces(header_content) class_name = cpp_parser.get_class(header_content) methods = cpp_parser.get_methods(header_content) tab_level = len(namespaces) outfile.append("#include \"" + header_name + "\"\n\n") for i in range(len(namespaces)): outfile.append(tabbing(i) + "namespace " + namespaces[i] + "\n"+ tabbing(i) + "{\n") for method in methods: write_method(outfile ,method, class_name, tab_level) for i in range(tab_level, 0, -1): outfile.append(tabbing(i - 1) + "}\n")
def solve_easy(in_path, out_path): in_file = InFile(in_path) out_file = OutFile(out_path) states = DroneStates(in_file) d = 0 # Current drone number w = 0 # Current weight products_to_deliver = [] new_orders = sort_orders(in_file.orders, in_file.warehouses[0]["coords"]) for o in new_orders: order_id = o["index"] order = in_file.orders[order_id] for product_id in order["product_ids"]: # Find a warehouse where the product is available warehouse = find_warehouse(in_file, product_id, states.states[d]["pos"]) if w + in_file.weights[product_id] > in_file.max_load: # We have to change the drone # The drone number d deliver the product try: states.deliver(d, order_id) # If there is still time, output the command for p in products_to_deliver: out_file.deliver(d, order_id, p, 1) except NoTimeLeft: pass d += 1 w = 0 products_to_deliver = [] if d >= in_file.d: d = 0 w += in_file.weights[product_id] products_to_deliver.append(product_id) # The drone number d take this product try: states.load(d, warehouse) # If there is still time, output the command out_file.load(d, warehouse, product_id, 1) except NoTimeLeft: pass # Empty the drone at end of order even is some space is left try: states.deliver(d, order_id) # If there is still time, output the command for p in products_to_deliver: out_file.deliver(d, order_id, p, 1) except NoTimeLeft: pass d += 1 w = 0 products_to_deliver = [] if d >= in_file.d: d = 0 out_file.write()