Exemplo n.º 1
0
def run_qp(mean_vec, cov_mat, alpha, k, separate_profit_vec):
    print('testing the QP relaxation algorithm...')

    start_time = time.time()
    bundle_set, profit_bundle = kbundle.Kbundle_QP_relaxation(
        mean_vec, cov_mat, alpha, k, separate_profit_vec)
    running_time = time.time() - start_time

    return profit_bundle, bundle_set, running_time
Exemplo n.º 2
0
def run_qp(mean_vec, cov_mat, alpha, k, separate_profit_vec):
    print('Testando algoritmo de relaxation QP')

    start_time = time.time()
    bundle_set, profit_bundle = kbundle.Kbundle_QP_relaxation(
        mean_vec, cov_mat, alpha, k, separate_profit_vec)
    running_time = time.time() - start_time

    return profit_bundle, bundle_set, running_time
Exemplo n.º 3
0
    print("Parte 4")
    start = time.time()

    std_array = np.asarray(std_vec).reshape((len(std_vec), 1))
    std_scale_mat = np.dot(std_array, np.transpose(std_array))
    cov_mat = np.multiply(predicted_cov_mat, std_scale_mat).astype(np.double)

    alpha = search(sales_vec)
    # precompute the separate sale profit
    separate_profit_vec = profit.separate_sale_profit(mean_vec, cov_mat, alpha)

    profit_vec = []
    bundle_size_vec = [2]
    # bundle_size_vec_norm = np.where(np.asarray(bundle_size_vec) >= N_mandatory_products)
    for bundle_size in bundle_size_vec:
        bundle_set, profit_bundle = kbundle.Kbundle_QP_relaxation(mean_vec, cov_mat, alpha, bundle_size,
                                                                  separate_profit_vec, mandatory_products_indexes)
        profit_vec.append(profit_bundle)

        with open('data/result_kbundle_' + str(bundle_size) + '.json', 'w') as output_file:
            json.dump({"profit": profit_bundle, "set": list(bundle_set)}, output_file, indent=4)

    with open('data/result_kbundle_profits.json', 'w') as output_file:
        json.dump({"bundle_size_vec": bundle_size_vec, "profit_vec": profit_vec}, output_file, indent=4)

    tempos_execucao[3] = time.time() - start

    max_products_sold = int(customer_product_reduced['sold_units'].max())
    products_sold_axis = np.linspace(1, max_products_sold, max_products_sold)

    count_sales = customer_product_reduced.groupby('sold_units').count()
Exemplo n.º 4
0
    ###############################################################################
    print("Parte 4")
    start = time.time()

    std_array = np.asarray(std_vec).reshape((len(std_vec), 1))
    std_scale_mat = np.dot(std_array, np.transpose(std_array))
    cov_mat = np.multiply(predicted_cov_mat, std_scale_mat).astype(np.double)

    alpha = search(sales_vec)
    # precompute the separate sale profit
    separate_profit_vec = profit.separate_sale_profit(mean_vec, cov_mat, alpha)

    profit_vec = []
    bundle_size_vec = [2]
    for bundle_size in bundle_size_vec:
        bundle_set, profit_bundle = kbundle.Kbundle_QP_relaxation(
            mean_vec, cov_mat, alpha, bundle_size, separate_profit_vec)
        profit_vec.append(profit_bundle)

        with open('data/result_kbundle_' + str(bundle_size) + '.json',
                  'w') as output_file:
            json.dump({
                "profit": profit_bundle,
                "set": list(bundle_set)
            },
                      output_file,
                      indent=4)

    with open('data/result_kbundle_profits.json', 'w') as output_file:
        json.dump(
            {
                "bundle_size_vec": bundle_size_vec,
Exemplo n.º 5
0
	for N in N_vec:
		print ("N =", N)
		for k in k_vec:
			print (">> k =", k)
			profit_algo_vec = []

			arg_vec = []
			running_time_algo_vec = []
			for s in range(sample_size):
				rand_indices = list(np.random.choice(N_product, N))
				mean_vec_sub = [mean_vec[i] for i in rand_indices]
				cov_mat_sub = cov_mat[:, rand_indices][rand_indices]
				separate_profit_vec_sub = [separate_profit_vec[i] for i in rand_indices]

				start_time = time.time()
				_, profit_algo = kbundle.Kbundle_QP_relaxation(mean_vec_sub, cov_mat_sub, alpha, k, separate_profit_vec_sub)
				running_time_algo = time.time() - start_time
				running_time_algo_vec.append(running_time_algo)

				arg_vec.append((mean_vec_sub, cov_mat_sub, k, separate_profit_vec_sub))
				
				profit_algo_vec.append( float(profit_algo) )

			print ('N = ', N, 'k = ', k)

			start_time = time.time()
			profit_opt_vec = pool.starmap(opt_enumerate, arg_vec)
			profit_opt_vec = list(profit_opt_vec)
			running_time_enumerate = time.time() - start_time

			ratio_vec = list(map(lambda x,y:x/y, profit_algo_vec, profit_opt_vec))