COIN-OR CBC Log File Entry

I use the COIN-OR CBC solver to solve some problems of numerical optimization. I am structuring the optimization problem in Python through PuLP.

I noticed that solvers like GUROBI and CPLEX create log files, but I cannot figure out how to get CBC to create a log file (as opposed to printing optimizer progress on screen).

Does anyone know of an option in CBC to install a log file? Re-redirecting all stdout to a file does not work for me, since I solve a bunch of problems in parallel and want their log files to be split.

Here is an example of what I call a solver. This works great and prints progress on the terminal.

prob.solve(pulp.COIN_CMD(msg=1, options=['DivingVectorlength on','DivingSome on']))

This is how I think the solution should be structured (although, obviously, LogFileName is not a valid CBC option).

prob.solve(pulp.COIN_CMD(msg=1, options=['DivingVectorlength on', 'DivingSome on', 'LogFileName stats.log']))

Any help on this would be greatly appreciated. I spend over the Internet, documents, and an interactive CBC session for hours trying to figure this out.

+4
source share
2 answers

For a solution that requires only a few lines of code in your script that calls PuLP and CBC, see James Vogel's solution ( https://github.com/voglster , possibly) at https://groups.google.com/forum/# ! topic / pulp-or-discuss / itbmTC7uNCQ based on os.dup()and os.dup2().

, , linkrot, . , tempfile. , :

from os import dup, dup2, close
f = open('capture.txt', 'w')
orig_std_out = dup(1)
dup2(f.fileno(), 1)

status = prob.solve (PULP_CBC_CMD(maxSeconds = i_max_sec, fracGap = d_opt_gap, msg=1))  #  CBC time limit and relative optimality gap tolerance
print('Completion code: %d; Solution status: %s; Best obj value found: %s' % (status, LpStatus[prob.status], value(prob.objective)))    

dup2(orig_std_out, 1)
close(orig_std_out)
f.close()

capture.txt .

+1

, pulp, , :

solvers.py.

solve_CBC COIN_CMD. cbc-64, subprocess.Popen. stdout None, os.devnull, . 1340 ( PuLP 1.5.6).

cbc = subprocess.Popen((self.path + cmds).split(), stdout = pipe,
                     stderr = pipe)

, (mps) (sol) /tmp ( UNIX) pid , . , , . :

logFilename = os.path.join(self.tmpDir, "%d-cbc.log" % pid)
logFile = open(logFilename, 'a')
cbc = subprocess.Popen((self.path + cmds).split(), stdout = logFile,
                     stderr = pipe)

, /tmp . log N, . cbc . , , .

+1

All Articles