''' This script can be very slow. ''' N, H, Kmax, xmax, ymax = 7, 15, 7, 10, 10 n_instances = 5 n_trials = 3 results_no_opt = [] results_opt = [] P = Problem(N, H, Kmax, xmax, ymax) for n in range(n_instances): P.create_data() no_opt_time, opt_time = 0, 0 for _ in range(n_trials): # If I call solve with M_opt without # re-create the problem, it # keeps adding constraint P.create_problem() P.solve_cplex(use_M_opt=False) no_opt_time += P.problem.solutionTime P.solve_cplex(use_M_opt=True) opt_time += P.problem.solutionTime
''' This script can be very slow, depending on the LP problems that are create randomly. ''' 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
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