#Change me if you need to! NUM_ITER = 300000 DIR = os.path.dirname(__file__) INSTANCES_DIR = os.path.join(DIR, "instances") if len(sys.argv) not in (3, 4): print("Invalid Arguments: use python gen_sumbission.py FILENAME N_MIN (<--optional) N_MAX") exit() N_MIN, N_MAX = -1,-1 FILENAME = sys.argv[1] if len(sys.argv) == 4: N_MIN = int(sys.argv[2]) N_MAX = int(sys.argv[3]) elif len(sys.argv) == 3: N_MIN = 1 N_MAX = sys.argv[2] for i in range(N_MIN, N_MAX+1): g = data_util.load_graph(os.path.join(INSTANCES_DIR, str(i)+".in")) p_init = mas.random_permutation(len(g)) print("Working on instance " + str(i) + " of size " + str(len(g)) + "...") t1 = time.time() p_final = mas.anneal(g, p_init, NUM_ITER) ordering = p_final.argsort() with open(FILENAME, "a") as submission: to_write = " ".join([str(int(n)+1) for n in ordering]) + "\n" submission.write(to_write) t2 = time.time() print("Completed in " + str(t2-t1) + "s with score " + str(mas.objective(g, p_final)))
Maximum Acyclic Subgraph """ import mas import random import numpy as np #Generate a snake graph with N=100 vertices g = mas.random_snake(100) #Add ~1,000 edges at random for _ in range(1000): i,j = random.sample(range(100), 2) g[i][j] = 1 np.fill_diagonal(g, 0) #Anneal! p_init = mas.random_permutation(100) p_final = mas.anneal(g, p_init, 100000, plot_results=True)