with tf.Session() as sess:  # start session
    sess.run(tf.global_variables_initializer()) # Run initialize op
    
    save_path = "save/"+dir_
    
    
    predictions_length, predictions_length_w2opt, time_mmodel, time_l2opt = [], [], [], []
    pred_all_2opt, time_all_2opt = [], []
    for i in tqdm(range(1000)): # test instance
        seed_ = 1+i
        saver.restore(sess, save_path+"/actor.ckpt") # Restore variables from disk.
        init_glob = [actor.global_step.assign(10000), actor.global_step2.assign(10000)]
        sess.run(init_glob)
        input_batch, dist_batch = dataset.test_batch(1, actor.max_length, actor.dimension, seed=seed_)
        feed = {actor.input_: input_batch,  actor.distances: dist_batch} # Get feed dict


        #start 
        start_active_search = t()
        for it_j in range(config.acive_search_steps):
            reward, predictions,  _, _ = sess.run([actor.reward, actor.predictions,
                                                            actor.trn_op1, actor.trn_op2], feed_dict=feed)

            if it_j % 100 == 0: 
                print(i)
                print('reward',np.min(reward))
                print('predictions',predictions)
                print(sess.run(actor.global_step))
                print('time : ', t() - start_active_search)
variables_to_save = [v for v in tf.global_variables() if 'Adam' not in v.name] # Save & restore all the variables.
saver = tf.train.Saver(var_list=variables_to_save, keep_checkpoint_every_n_hours=1.0)   


with tf.Session() as sess:  # start session
    sess.run(tf.global_variables_initializer()) # Run initialize op
    
    save_path = "save/"+dir_
    saver.restore(sess, save_path+"/actor.ckpt") # Restore variables from disk.
    
    predictions_length, predictions_length_w2opt, time_mmodel, time_l2opt = [], [], [], []
    pred_all_2opt, time_all_2opt = [], []
    for i in tqdm(range(1000)): # test instance
        seed_ = 1+i
        input_batch, dist_batch = dataset.test_batch(1, config.max_length, config.dimension, seed=seed_)
        feed = {actor.input_: input_batch,  actor.distances: dist_batch} # Get feed dict
        start = t()
        tour, reward = sess.run([actor.from_, actor.reward], feed_dict=feed) # sample tours
        model_time = (t() - start)
        time_mmodel.append(model_time)
        j = np.argmin(reward) # find best solution
        best_permutation = tour[j]
        predictions_length.append(reward[j])
        #print('reward (before 2 opt)',reward[j])
        #dataset.visualize_2D_trip(input_batch[0][best_permutation])
        #dataset.visualize_sampling(tour)
        
        start2 = t()
        opt_tour, opt_length = dataset.loop2opt(best_permutation, dist_batch[0])
        l2opt_time = t()- start + model_time