solver:terminate_the_optimization_after_gams_cplex_reaches_a_certain_value_of_the_objective

The example model below shows how to interact with CPLEX that it stops pretty much after CPLEX found the solution value 21 (or larger). This is done in using the same mechanism as described in “The GAMS Branch-and-Cut-and-Heuristic Facility”.

First we have userincbicall which is called every time we find a new incumbent. We are also in ”interactive” mode, meaning that we accept new options on the fly. The trigger for reading in new options is a trigger file called readop2. This is created by the incumbent checking routine only if we reached 21 or higher. The Cplex option sets a very large optca (Cplex name for it is epagap), so we should terminate immediately. The iatriggertime is set to 1 meaning that Cplex checks every second if there is a triggerfile. This should be set to larger values (60 seconds or so) for real models. This can be used effieciently, for example, in the case when a model is decomposed into sub-models. When a sub-model is solved then the solution can be used in the other sub-models to create a integer cut, hence the solution speed is improved.

Note: This approach requires distribution 22.6 ++.

Option description:

**iatriggertime (double)**
The time interval in seconds when the solver checks for existence of the trigger file. This is comparable to the situation that ctrl+c is pressed if the trigger file exist. The options iatriggertime, iatriggerfile and iafile enables an automated way to handle the interactive communication with the solver.

**iatriggerfile (string)**
The name of the trigger file. When the solver checks and finds the trigger file a secondary option file (iafile) is processed and the trigger file is removed. Note that the trigger file works as an indicator and only the existence of the file is checked.

**iafile (string)**
The secondary option file consists of CPLEX options to be used during the remaining part of the solution procedure. Hence, the secondary option file, iafile, is dedicated to be used during the interactive communication with the solver. Processing of the iafile is triggered by existence of the iatriggerfile.

$title Non-transitive Dice Design (DICE,SEQ=176) $Ontext Probabilistic dice - an example of a non-transitive relation. We want to design a set of dice with an integer number on each face such that on average dice1 beats dice2, and dice2 on average beats dice3 etc, but diceN has to beat dice1. MIP codes behave very erratic on such a problem and slight reformulations can result in dramatic changes in performance. Also note the face value will be integers automatically. Gardner, M, Scientific American. Robert A Bosh, Mindsharpener, Optima, MP Society Newsletter, Vol 70, June 2003, page 8-9 Robert A Bosh, Monochromatic Squares, Optima, MP Society Newsletter, Vol 71, March 2004, page 6-7 $Offtext sets f faces on a dice / face1*face6 / dice number of dice / dice1*dice3 / ; scalars flo lowest face value / 1 / fup highest face value wn wins needed - possible bound ; fup = card(dice) * card(f); wn = floor(0.5 * sqr(card(f))) + 1; alias(f,fp); alias(dice,dicep); variables wnx number of wins fval(dice,f) value of dice - will be integer comp(dice,f,fp) one if f beats fp ; binary variable comp; fval.lo(dice,f) = flo; fval.up(dice,f) = fup; fval.fx("dice1","face1") = flo; equation eq1(dice) count the wins eq3(dice,f,fp) definition of non-transitive relation eq4(dice,f) different face values for a single dice; eq1(dice).. sum((f,fp), comp(dice,f,fp)) =e= wnx; eq3(dice,f,fp) .. fval(dice,f) + (fup-flo)*(1-comp(dice,f,fp)) =g= fval(dice++1,fp) + 1; eq4(dice,f-1) .. fval(dice,f-1) + 1 =l= fval(dice,f); model xdice /all /; $if set nosolve $exit xdice.optfile=1; option mip=cplex; option optcr=0; * Delete trigger file which might be around from a previous run $call rm -rf readop2 * Set dummy upper bound * Note: This is actually not necessary, it is just done because of a bug in older versions wnx.up=1000; solve xdice using mip max wnx; $onecho > cplex.opt userincbicall checkincb.gms interactive yes iafile cplex.op2 iatriggerfile readop2 iatriggertime 1 $offecho $echo epagap 1e20 > cplex.op2 $onecho > checkincb.gms variable wnx; $gdxin bchout_i.gdx $load wnx file fx /readop2/; if (round(wnx.l) >= 21, put fx 'read cplex.op2'); $offecho

--- Job dice Start 02/01/08 12:56:42 GAMS Rev 149 Copyright (C) 1987-2007 GAMS Development. All rights reserved ... --- Starting compilation --- dice.gms(82) 3 Mb --- Starting execution: elapsed 0:00:00.037 --- dice.gms(62) 4 Mb --- Generating MIP model xdice --- dice.gms(64) 4 Mb --- 126 rows 127 columns 465 non-zeroes --- 108 discrete-columns --- dice.gms(64) 4 Mb --- Executing CPLEX: elapsed 0:00:00.071 ILOG CPLEX Dec 24, 2007 WEX.CP.CP 22.6 035.037.041.wei For Cplex 11.0 Cplex 11.0.0, GAMS Link 34 Cplex licensed for 1 use of lp, qp, mip and barrier, with 2 parallel threads. Reading parameter(s) from "C:\temp\cplex.opt" >> userincbicall checkincb.gms >> interactive yes >> iafile cplex.op2 >> iatriggerfile readop2 >> iatriggertime 1 Finished reading from "C:\temp\cplex.opt" Reading data... Starting Cplex... Tried aggregator 1 time. MIP Presolve eliminated 12 rows and 11 columns. MIP Presolve modified 460 coefficients. Reduced MIP has 114 rows, 116 columns, and 419 nonzeros. Presolve time = 0.00 sec. MIP emphasis: balance optimality and feasibility. MIP search method: dynamic search. Parallel mode: none, using 1 thread. Tried aggregator 1 time. No LP presolve or aggregator reductions. Presolve time = 0.00 sec. Initializing dual steep norms . . . Iteration log . . . Iteration: 1 Dual objective = 30.000000 Perturbation started. Iteration: 52 Dual objective = 30.000000 Iteration: 114 Dual objective = 29.999967 Removing perturbation. Root relaxation solution time = 0.00 sec. Nodes Cuts/ Node Left Objective IInf Best Integer Best Node ItCnt Gap * 0+ 0 0.0000 29.6862 139 --- *** Reporting incumbent with objective 0. 0 0 29.0000 59 0.0000 Cuts: 63 177 --- 0 0 28.4000 69 0.0000 Cuts: 36 216 --- 0 0 27.7572 64 0.0000 Cuts: 23 256 --- 0 0 26.7039 71 0.0000 Flowcuts: 17 317 --- * 0+ 0 12.0000 26.7039 317 122.53% *** Reporting incumbent with objective 12. 0 0 26.6207 72 12.0000 Cuts: 81 341 121.84% 0 0 26.4449 74 12.0000 Flowcuts: 11 368 120.37% 0 0 26.1618 76 12.0000 Cuts: 13 390 118.02% 0 0 26.0578 73 12.0000 Cuts: 59 406 117.15% 0 0 25.7993 74 12.0000 Flowcuts: 4 417 114.99% 0 0 25.7065 73 12.0000 Cuts: 9 431 114.22% 0 0 25.6514 73 12.0000 Impl Bds: 5 437 113.76% 0 0 25.6510 73 12.0000 Flowcuts: 1 438 113.76% * 0+ 0 16.0000 25.6510 438 60.32% *** Reporting incumbent with objective 16. 0 2 25.0000 70 16.0000 25.6510 438 60.32% * 10+ 7 18.0000 25.0000 686 38.89% *** Reporting incumbent with objective 18. 100 59 24.0000 73 18.0000 24.3467 3322 35.26% Cuts: 50 * 110+ 59 19.0000 24.3467 3674 28.14% *** Reporting incumbent with objective 19. 200 123 20.0000 14 19.0000 24.0000 7359 26.32% Cuts: 8 * 240+ 123 20.0000 24.0000 8515 20.00% Cuts: 13 *** Reporting incumbent with objective 20. * 290+ 108 21.0000 24.0000 10576 14.29% Cuts: 6 *** Reporting incumbent with objective 21. 300 117 infeasible 21.0000 24.0000 11000 14.29% 400 171 23.0000 41 21.0000 24.0000 15702 14.29% Cuts: 26 Implied bound cuts applied: 1 Flow cuts applied: 67 Mixed integer rounding cuts applied: 6 Zero-half cuts applied: 1 Gomory fractional cuts applied: 2 >> epagap 1e20 Implied bound cuts applied: 1 Flow cuts applied: 67 Mixed integer rounding cuts applied: 6 Zero-half cuts applied: 1 Gomory fractional cuts applied: 2 Fixing integer variables, and solving final LP... Tried aggregator 1 time. LP Presolve eliminated 124 rows and 125 columns. Aggregator did 2 substitutions. All rows and columns eliminated. Presolve time = 0.00 sec. Solution satisfies tolerances. MIP Solution: 21.000000 (20900 iterations, 482 nodes) Final Solve: 21.000000 (0 iterations) Best possible: 23.000000 Absolute gap: 2.000000 Relative gap: 0.095238 --- Restarting execution --- dice.gms(64) 2 Mb --- Reading solution for model xdice --- dice.gms(64) 2 Mb *** Status: Normal completion --- Job dice.gms Stop 02/01/08 12:56:44 elapsed 0:00:02.187

IMPRESSUM / LEGAL NOTICE
PRIVACY POLICY
solver/terminate_the_optimization_after_gams_cplex_reaches_a_certain_value_of_the_objective.txt · Last modified: 2017/09/02 17:37 by support