n_trials = 3 first_seed = 1 n_instances = 3 results_no_fit = [] results_old = [] P = Problem(N, H, Kmax, xmax, ymax) for seed in range(first_seed, first_seed + n_instances): P.create_data(seed=seed) no_fit_time, old_time = 0, 0 for _ in range(n_trials): # no fit model P.create_problem(use_no_fit=True) P.solve_cplex() no_fit_time += P.problem.solutionTime # old model P.create_problem(use_no_fit=False) P.solve_cplex() old_time += P.problem.solutionTime results_no_fit.append(no_fit_time / n_trials) results_old.append(old_time / n_trials) with open(f'old_model_vs_no_fit_model_seed{first_seed}_{first_seed+n_instances-1}.txt', 'w') as f: f.write('results no-fit model\n') for i, el in enumerate(results_no_fit, first_seed):
''' N, H, Kmax, xmax, ymax = 5, 12, 6, 10, 10 n_trials = 3 n_instances = 3 first_seed = 1 results = {} for seed in range(first_seed, first_seed + n_instances): P = Problem(N, H, Kmax, xmax, ymax) P.create_data(seed=seed) P.create_problem() cbc_time, cplex_time = 0, 0 for _ in range(n_trials): P.solve_cbc(keepFiles=0, mip=1, msg=1, cuts='forceOn', presolve='on', strong=5, heur='off') cbc_time += P.problem.solutionTime P.solve_cplex()
from problem import Problem # PuLP apis code at https://github.com/coin-or/pulp/tree/master/pulp/apis N, H, Kmax, xmax, ymax = 8, 12, 6, 10, 10 P = Problem(N, H, Kmax, xmax, ymax) # PuLP does not support the creation of a problem from file # Set the seed if you want to reproduce the experiment P.create_data(seed=None) # if filename is None, it doesn't save the model in an lp file # use_no_fit if you want to use the model created using no-fit polygons P.create_problem(filename='problem.lp', use_no_fit=False) # if filename is None, it shows the figure without saving it P.show_original_polygons(filename='problem_init.png') # ------------------------------------------------------ # # ----------------solve with cbc------------------------ # # ------------------------------------------------------ # # Possible cbc parameters at https://projects.coin-or.org/CoinBinary/export/1059/OptimizationSuite/trunk/Installer/files/doc/cbcCommandLine.pdf # or run cbc.exe on your terminal and write ? # use it in options, i.e. if you want to deactivate clique cuts: options = ['clique off'] keepFiles = 0 mip = 1 msg = 1 cuts = 'forceOn' # on, off, root, ifmove, forceOn