$title Random Min Cost Flow, writes its own cplex.opt file $offuellist offuelxref offsymlist offsymxref option limrow=0, limcol=0, solprint=off; set nodes /1*1000/ sources(nodes) sinks(nodes); * the three variants of the cplex LP solver we want to try. set cplexOptions /1*3/; parameter optionnumber(cplexOptions) /1 1, 2 2, 3 3/; alias (nodes,i,j,k); set arcs(i,j); parameter cost(i,j), supply(nodes), randomVector(nodes); variables f(i,j), totalcost; positive variable f; scalar counter; * first define a random set of arcs of a given density. * (If density is too low, the problem may not have a solution - * there may not be a path from sources to sinks.) option seed=25671; arcs(i,j) = yes$(uniform(0,1) < .025); * no self-directed arcs arcs(i,i) = no; * now define costs on these arcs cost(i,j) = uniform(0,50) $ arcs(i,j); * determine eligible source nodes (those with outflowing arcs) * and sinks (those with inflowing arcs); sources(nodes) = no; sinks(nodes) = no; loop(arcs(i,j), sources(i) = yes; sinks(j) = yes; ); supply(nodes) = 0; * pick two sources to have positive supplies counter = 0; loop(nodes$(sources(nodes) and counter<2), supply(nodes) = 10; counter = counter+1; ); * and five sinks to have balancing negative supplies counter = 0; loop(nodes$(sinks(nodes) and counter<5 and supply(nodes)=0), supply(nodes) = -4; counter = counter+1; ); * display sources, sinks, supply; equations balance(i), objective; balance(i).. sum(arcs(i,k), f(arcs)) - sum(arcs(j,i), f(arcs)) =e= supply(i); objective.. totalcost =e= sum(arcs, cost(arcs)*f(arcs)); model mcf/balance, objective/; * look for a cplex options file mcf.optfile = 1; * we're going to write the cplex.opt file file lpoptions /cplex.opt/; * overwrite it, don't append lpoptions.ap = 0; * loop over the three possible solver options. loop(cplexOptions, put lpoptions; * put 'lpmethod ', cplexOptions.tl; put 'lpmethod ', optionNumber(cplexOptions):2:0; put /'itlim 1000000'/; putclose; solve mcf using lp minimizing totalcost; ); option f:0:0:2; display f.l;