config = get_config() dataset = DataGenerator() real_tour_concorde = {} pool = Pool(processes=8) last = 10000 if not os.path.exists("supervised_data"): os.mkdir("supervised_data") for i in tqdm(range(10000, 30000)): # test instance seed_ = 1 + i reward, tour = [], [] input_batch, dist_batch = dataset.create_batch(config.batch_size, config.graph_dimension, config.dimension, seed=seed_) sys.stdout = open(os.devnull, "w") result_tours = [ pool.apply(pool_operation, args=(input_batch, x)) for x in range(config.batch_size) ] sys.stdout = sys.__stdout__ real_tour_concorde[seed_] = result_tours if seed_ % 100 == 0: f = open( "supervised_data/batch_seed_" + str(last) + "_" + str(seed_) + ".pkl", "wb")
os.makedirs(save_path) restore_path = "saveSL/" + dir_actor + "/actor.ckpt" with tf.Session() as sess: # start session+ "next" count_no_weights() sess.run(tf.global_variables_initializer()) # run initialize op # saver_all.restore(sess, restore_path) writer = tf.summary.FileWriter('summarySL/' + dir_actor, sess.graph) # summary writer for i in tqdm(range(10000, 10000 + config.nb_steps)): # Forward pass & train step seed_ = i + 1 input_batch, dist_batch = dataset.create_batch(actor.batch_size, actor.max_length, actor.dimension, seed=seed_) if i % 100 == 0: with open( "supervised_data/batch_seed_" + str(i) + "_" + str(i + 100) + ".pkl", 'rb') as handle: optimal_tour_dic = pickle.load(handle) optimal_tours = np.array(optimal_tour_dic[seed_]) feed = { actor.input_: input_batch, actor.optimal_tour: optimal_tours, actor.temperature: np.array([temperature]) } # get feed dict actor.predictions: real_lengths if actor.version == 'graph':
import pickle from dataGenerator import DataGenerator from utils import visualize_2D_trip last = 19000 i = 19100 seed_ = 19053 with open("supervised_data/batch_seed_" + str(last) + "_" + str(i) + ".pkl", 'rb') as handle: b = pickle.load(handle) dataset = DataGenerator() input_batch, dist_batch = dataset.create_batch(256, 50, 2, seed=seed_) visualize_2D_trip(input_batch[100], b[seed_][100], 'niente', 1)