def create_data_model(): data = {} data['depot'] = 0 data['num_vehicles'] = 0 data['demands'] = [] data['distance_matrix'] = [] data['vehicle_capacities'] = [] numVehicles = 4 maxCapacity = 400 capacity, graph, delivery_demand, cityref, datafile = dataset('data_2_23.txt') #------------------------- tempdata = pd.read_csv("../helpers/raw_data/" + datafile ) citydata = tempdata.set_index("x") distanceMat = [] for pointA in graph.keys(): matrix = [] for pointB in graph.keys(): dist = int(get_city_distance( citydata, cityref[pointA], cityref[pointB] )) matrix.append( dist ) distanceMat.append(matrix) deliveryDemands = [] for demand in delivery_demand.keys(): deliveryDemands.append( delivery_demand[demand] ) deliveryCapacity= [] for i in range(0, numVehicles): deliveryCapacity.append( maxCapacity ) data['num_vehicles'] = numVehicles data['demands'] = get_normalized_demands(deliveryDemands) data['distance_matrix'] = distanceMat data['vehicle_capacities'] = deliveryCapacity return data
from functions import dataset, plot_paths from sweep import Sweep import numpy as np import pandas as pd import random as rand import time if __name__ == '__main__': """ capacity : capacity graph : Graph delivery_demand : Delivery demands """ capacity, graph, delivery_demand, cityref, datafile = dataset( 'data_3_240.txt') #------------------------- tempdata = pd.read_csv("../helpers/raw_data/" + datafile) citydata = tempdata.set_index("x") for vehicle_capacity in [1000, 1500, 2500, 2000, 2745, 4000, 11000, 15000]: sweepAlg = Sweep(vehicle_capacity, delivery_demand, cityref, citydata) start_time = time.time() sweepAlg.set_graph(graph) bestSol = sweepAlg.process() elasped_time = (time.time() - start_time) if bestSol is not None: plot_paths(graph, cityref, bestSol, elasped_time, False)
N,M = dataset_X.shape print(N,M) # network accuracy t_idx = [int(line.strip()) for line in open("train_id.txt", 'r')] te_idx = [int(line.strip()) for line in open("test_id.txt", 'r')] x_tv = dataset_X[t_idx] y_tv = dataset_Y[t_idx] x_test = dataset_X[te_idx] y_test = dataset_Y[te_idx] x_train, y_train, x_val, y_val,tr_idx,val_idx = dataset(x_tv, y_tv, test_ratio=0.05) # print x_test.shape num_classes = y_test.shape[-1] x_train = x_train.astype('float32') x_test = x_test.astype('float32') x_val = x_val.astype('float32') x_train = x_train.astype('float32').reshape((len(x_train), M,1)) x_test = x_test.astype('float32').reshape((len(x_test),M,1)) x_val = x_val.astype('float32').reshape((len(x_val),M,1)) print(np.sum(y_test,axis=0)) print(np.sum(y_val,axis=0)) print(np.sum(y_train,axis=0))
plt.show() if __name__ == '__main__': """ PARAMS alpha: relative importance of pheromone beta: relative importance of heuristic information sigma: rho: pheromone coefficient theta: num_ants: number of ants MAX_NFC: max number of function calls """ vehicle_capacity, graph, delivery_demand, optimal = dataset('dataset.txt') alpha = 2 beta = 5 sigma = 3 rho = 0.8 theta = 80 num_ants = 22 MAX_NFC = 1000 vrp = ACOVRP(alpha, beta, sigma, rho, theta, num_ants, vehicle_capacity, delivery_demand, MAX_NFC) vrp.set_graph(graph) bestSol = vrp.process() if bestSol is not None:
most_vector, max_count, count_vector = most_repeared_promoter( dataset_X, dataset_Y) _, p_count, n_count = count_vector vart_pos = [] for i in range(len(most_vector)): if most_vector[i] != '0': vart_pos.append(i) np.random.seed(42) tf.set_random_seed(42) random.seed(42) # network accuracy x_train, y_train, x_test, y_test = dataset(dataset_X, dataset_Y, test_ratio=0.1) #print x_train.shape #print x_test.shape num_classes = 2 x_train = x_train.astype('float32') #.reshape((len(x_train),8,8,1)) x_test = x_test.astype('float32') x_train = x_train.astype('float32').reshape((len(x_train), 64, 1)) x_test = x_test.astype('float32').reshape((len(x_test), 64, 1)) cnn = architecture(num_classes) history = cnn.fit(x_train, y_train, batch_size=64, epochs=50,
import json import pandas as pd from functions import dataset if __name__ == '__main__': dataset_name = "data_3_96" capacity, graph, delivery_demand, cityref, indexes, datafile = dataset( dataset_name + '.txt') data_arr = {} for i in graph: data_arr[i] = { "index": int(i), "location": cityref[i], "lat": float(graph[i][0]), "lng": float(graph[i][1]), "demand": float(delivery_demand[i]), "cityref": int(indexes[i]), } jsonData = json.dumps(data_arr, indent=4) with open("./dataset/" + dataset_name + ".json", "w") as f: f.write(jsonData)