I am a full-time consultant and provide services related to the design, implementation and deployment of mathematical programming, optimization and data-science applications. I also teach courses and workshops. Usually I cannot blog about projects I am doing, but there are many technical notes I'd like to share. Not in the least so I have an easy way to search and find them again myself. You can reach me at erwin@amsterdamoptimization.com.
Sunday, September 1, 2024
N-queens and solution pool
Wednesday, April 26, 2023
A large MIP model that should be solved as LP: the root node
In this post, I want to discuss an observation about the root node when solving a MIP model.
Problem Description
We have a large matrix \(\color{darkblue}A=\color{darkblue}a_{i,j}\) with values 0 and 1. In addition, we have a minimum on the row and column totals. These are called \(\color{darkblue}r_i\) and \(\color{darkblue}c_j\). The goal is to remove as many 1's in the matrix \(\color{darkblue}A\) subject to these minimum row and column totals.
Sunday, October 13, 2019
Sometimes a commercial solver is really better...
- Cplex. Optimal solution \(z=60\) found in about 8 seconds. Using 4 threads on an old laptop. Log is below.
- CBC. Hit timelimit of 2 hours. Objective = 62 (non-optimal). Also using 4 threads on the same machine. The strange thing is that with CBC the best possible bound is not changing at all. Not by a millimeter. See the highlighted numbers in the log below. CBC is a very good solver, but sometimes I see things like this.
- Gurobi and Xpress solve this problem very fast. Ran on NEOS via an MPS file.
- SCIP has also problems with this model. Ran on NEOS via an MPS file.
All runs were with default settings. It looks like the commercial solvers do a much better job than the open source and academic codes. Sometimes you get what you pay for.
Cplex Log
Tried aggregator 2 times. MIP Presolve eliminated 4 rows and 5 columns. MIP Presolve modified 3 coefficients. Aggregator did 500 substitutions. Reduced MIP has 999 rows, 1499 columns, and 2497 nonzeros. Reduced MIP has 500 binaries, 0 generals, 0 SOSs, and 0 indicators. Presolve time = 0.02 sec. (7.38 ticks) Found incumbent of value 500.000000 after 0.03 sec. (8.85 ticks) Probing time = 0.00 sec. (0.20 ticks) Tried aggregator 1 time. Reduced MIP has 999 rows, 1499 columns, and 2497 nonzeros. Reduced MIP has 500 binaries, 0 generals, 0 SOSs, and 0 indicators. Presolve time = 0.00 sec. (5.26 ticks) Probing time = 0.00 sec. (0.19 ticks) MIP emphasis: balance optimality and feasibility. MIP search method: dynamic search. Parallel mode: deterministic, using up to 4 threads. Parallel mode: deterministic, using up to 3 threads for concurrent optimization. Tried aggregator 1 time. LP Presolve eliminated 999 rows and 1499 columns. All rows and columns eliminated. Presolve time = 0.02 sec. (0.71 ticks) Initializing dual steep norms . . . Root relaxation solution time = 0.02 sec. (1.15 ticks) Nodes Cuts/ Node Left Objective IInf Best Integer Best Bound ItCnt Gap * 0+ 0 500.0000 0.0000 100.00% Found incumbent of value 500.000000 after 0.06 sec. (16.78 ticks) 0 0 55.2664 490 500.0000 55.2664 0 88.95% * 0+ 0 75.0000 55.2664 26.31% Found incumbent of value 75.000000 after 0.08 sec. (21.35 ticks) 0 0 55.2825 353 75.0000 Cuts: 349 222 26.29% 0 0 55.4160 311 75.0000 Cuts: 349 455 26.11% 0 0 55.4160 275 75.0000 Cuts: 349 775 26.11% * 0+ 0 72.0000 55.4160 23.03% Found incumbent of value 72.000000 after 0.59 sec. (116.10 ticks) 0 0 55.4160 182 72.0000 Cuts: 349 1032 23.03% 0 0 55.4160 141 72.0000 Cuts: 349 1208 23.03% 0 0 55.4160 121 72.0000 Cuts: 192 1336 23.03% 0 0 55.4160 105 72.0000 Cuts: 128 1410 23.03% 0 0 55.4160 98 72.0000 Cuts: 85 1472 23.03% 0 0 55.4160 61 72.0000 Cuts: 74 1494 23.03% 0 0 55.4160 67 72.0000 Cuts: 160 1571 23.03% 0 2 55.4160 56 72.0000 55.4160 1571 23.03% Elapsed time = 1.33 sec. (273.54 ticks, tree = 0.01 MB, solutions = 3) 1239 854 55.4160 59 72.0000 55.4160 3845 23.03% Cuts: 38 * 1471+ 1230 71.0000 55.4160 21.95% Cuts: 16 Found incumbent of value 71.000000 after 3.39 sec. (827.52 ticks) * 1474+ 1230 70.0000 55.4160 20.83% Found incumbent of value 70.000000 after 3.39 sec. (828.63 ticks) * 1481+ 1230 69.0000 55.4160 19.69% Found incumbent of value 69.000000 after 3.41 sec. (831.79 ticks) * 1490+ 1230 68.0000 55.4160 18.51% Found incumbent of value 68.000000 after 3.44 sec. (834.87 ticks) * 1731+ 1033 67.0000 58.7491 12.31% Found incumbent of value 67.000000 after 6.63 sec. (1824.17 ticks) * 1731+ 688 65.0000 59.0933 9.09% Found incumbent of value 65.000000 after 7.25 sec. (2079.31 ticks) * 1731+ 458 62.0000 60.0000 3.23% Found incumbent of value 62.000000 after 7.47 sec. (2162.68 ticks) * 1731+ 305 61.0000 60.0000 1.64% Found incumbent of value 61.000000 after 8.20 sec. (2495.45 ticks) * 1731+ 0 60.0000 60.0000 0.00% Found incumbent of value 60.000000 after 8.58 sec. (2603.40 ticks) * 1731 0 integral 0 60.0000 60.0000 10141 0.00% Found incumbent of value 60.000000 after 8.61 sec. (2604.50 ticks) Cover cuts applied: 150 Implied bound cuts applied: 14 Flow cuts applied: 37 Mixed integer rounding cuts applied: 249 Gomory fractional cuts applied: 26 Root node processing (before b&c): Real time = 1.31 sec. (273.18 ticks) Parallel b&c, 4 threads: Real time = 7.30 sec. (2331.56 ticks) Sync time (average) = 0.25 sec. Wait time (average) = 0.01 sec. ------------ Total (root+branch&cut) = 8.61 sec. (2604.75 ticks) MIP status(101): integer optimal solution
CBC Log
Calling CBC main solution routine... Integer solution of 74 found by feasibility pump after 0 iterations and 0 nodes (2.78 seconds) Integer solution of 72 found by RINS after 0 iterations and 0 nodes (2.96 seconds) 128 added rows had average density of 31.601563 At root node, 128 cuts changed objective from 55.26645 to 55.416026 in 10 passes Cut generator 0 (Probing) - 367 row cuts average 2.1 elements, 0 column cuts (12 active) in 0.022 seconds - new frequency is 1 Cut generator 1 (Gomory) - 598 row cuts average 26.1 elements, 0 column cuts (0 active) in 0.090 seconds - new frequency is 1 Cut generator 2 (Knapsack) - 14 row cuts average 11.9 elements, 0 column cuts (0 active) in 0.037 seconds - new frequency is -100 Cut generator 3 (Clique) - 0 row cuts average 0.0 elements, 0 column cuts (0 active) in 0.003 seconds - new frequency is -100 Cut generator 4 (MixedIntegerRounding2) - 368 row cuts average 11.2 elements, 0 column cuts (0 active) in 0.023 seconds - new frequency is 1 Cut generator 5 (FlowCover) - 394 row cuts average 2.8 elements, 0 column cuts (0 active) in 0.041 seconds - new frequency is 1 Cut generator 6 (TwoMirCuts) - 598 row cuts average 35.5 elements, 0 column cuts (0 active) in 0.072 seconds - new frequency is -100 After 0 nodes, 1 on tree, 72 best solution, best possible 55.416026 (3.94 seconds) Integer solution of 70 found by heuristic after 4138 iterations and 57 nodes (14.24 seconds) Integer solution of 69 found by heuristic after 12712 iterations and 287 nodes (23.32 seconds) Integer solution of 66 found by heuristic after 18149 iterations and 487 nodes (25.94 seconds) After 1005 nodes, 555 on tree, 66 best solution, best possible 55.416026 (31.73 seconds) Integer solution of 65 found by heuristic after 32591 iterations and 1015 nodes (33.93 seconds) Integer solution of 64 found by heuristic after 43252 iterations and 1405 nodes (39.79 seconds) Integer solution of 63 found by heuristic after 52409 iterations and 1805 nodes (44.62 seconds) After 2017 nodes, 1104 on tree, 63 best solution, best possible 55.416026 (45.77 seconds) After 3045 nodes, 1653 on tree, 63 best solution, best possible 55.416026 (52.29 seconds) After 4099 nodes, 2212 on tree, 63 best solution, best possible 55.416026 (55.02 seconds) After 5163 nodes, 2769 on tree, 63 best solution, best possible 55.416026 (57.08 seconds) . . . After 131221 nodes, 37229 on tree, 63 best solution, best possible 55.416026 (610.94 seconds) After 132282 nodes, 37230 on tree, 63 best solution, best possible 55.416026 (613.18 seconds) After 133298 nodes, 37231 on tree, 63 best solution, best possible 55.416026 (615.50 seconds) After 134320 nodes, 37318 on tree, 63 best solution, best possible 55.416026 (621.40 seconds) Integer solution of 62 found by heuristic after 2839018 iterations and 134502 nodes (621.99 seconds) After 135334 nodes, 37422 on tree, 62 best solution, best possible 55.416026 (627.07 seconds) After 136352 nodes, 37407 on tree, 62 best solution, best possible 55.416026 (631.83 seconds) After 137391 nodes, 37395 on tree, 62 best solution, best possible 55.416026 (637.74 seconds) After 138400 nodes, 37385 on tree, 62 best solution, best possible 55.416026 (642.25 seconds) . . . After 1566320 nodes, 37408 on tree, 62 best solution, best possible 55.416026 (7177.35 seconds) After 1567325 nodes, 37412 on tree, 62 best solution, best possible 55.416026 (7182.33 seconds) After 1568336 nodes, 37421 on tree, 62 best solution, best possible 55.416026 (7187.07 seconds) After 1569358 nodes, 37402 on tree, 62 best solution, best possible 55.416026 (7192.93 seconds) After 1570410 nodes, 37400 on tree, 62 best solution, best possible 55.416026 (7199.07 seconds) Thread 0 used 30010 times, waiting to start 2696, 0 locks, 0 locked, 0 waiting for locks Thread 1 used 30010 times, waiting to start 2480, 0 locks, 0 locked, 0 waiting for locks Thread 2 used 30010 times, waiting to start 2083, 0 locks, 0 locked, 0 waiting for locks Thread 3 used 30010 times, waiting to start 1770, 0 locks, 0 locked, 0 waiting for locks Main thread 6737 waiting for threads, 0 locks, 0 locked, 0 waiting for locks Exiting on maximum time Partial search - best objective 62 (best possible 55.416026), took 19832056 iterations and 1570713 nodes (7202.49 seconds) Strong branching done 3540964 times (6897 iterations), fathomed 137838 nodes and fixed 779663 variables Maximum depth 198, 2057372 variables fixed on reduced cost Time limit reached. Have feasible solution. MIP solution: 6.200000e+01 (1570713 nodes, 7202.62 CPU seconds, 7202.62 wall clock seconds)
Friday, March 6, 2009
A conference scheduling problem (2)
In this posting I described the solution for a conference scheduling problem. Now the question is posed: can we add a constraint on the room capacity: up to 15 people per room. The first thing I did was to inspect my solution. Indeed we are exceeding this limit here and there:
In row total some of the occupancy counts are larger than 15. Note that this was a solution with objective=1491. We can add the room capacity constraint as follows:
Using this additional constraint, the solution looks like:
This reduces the optimal objective from 1491 to 1487. I.e. we pay for this with a small decrease w.r.t. the preferences. The solution time was 2 minutes with GAMS/Cplex.
I use here the fact that all rooms are identical. If there are five rooms with different capacity, we need to know how talks are assigned to individual rooms. That requires extra binary variables (either by adding a room index to variable x or by introducing a new variable that handles the room assignment).
A conference scheduling problem
From: GagoX <elgrang...@gmail.com>
Date: Mar 3, 11:43 am
Subject: scheduling problem optimizing preferences
To: sci.mathHi everyone,
this is a real life problem and I have no idea even how to start!
I need to organize a small conference:
Np=50 participants (P1 to P50) and Nt=13 talks (T1 to T13).
There are 5 time spots each with 5 rooms available.
T1 will be given 3 times, T2 to T7 will be given 2 times each and T8
to T13 will be given only once. Consequently there are 22 talks. The
constraint is that the repeated talks should not be scheduled in the
same time slot.Each participant has given his preference to which talk to attend,
from 1st preference to 8th preference. And each participant should
attend 5 talks, one in each time slot.Problem: What talks should be scheduled in each time slot so to
optimize the preferences?The optimum solution would be to fulfill that each participand attend
their 5 first preferences.How is this problem called and is it possible to solve...what should
be the strategy.Or even better, does someone know the solution?I guess if I knew how to ennumerate each possibility (I do not know),
I could then quantify the fulfilling of the preferences and then take
the best one (brute force) (of course programming the whole
thing)...but I am afraid that there are too many possibilities!Thaks a lot in advance!!!!
This is a task that is sometimes very well suited to be implemented as mixed integer programming problem. (If they become too big, scheduling problems can be better implemented using different techniques.)
Lets try to do this quickly in GAMS. We start with the sets, and the basic data:
set
p 'participants' /p1*p50/
t 'presenter' /t1*t13/
n 'talk number' /n1*n3/
s 'timeslot' /slot1*slot5/
;
scalar rooms 'number of parallel sessions' /5/
set talk(t,n) 'each presenter can give several talks' /
t1.(n1,n2,n3)
(t2*t7).(n1,n2)
(t8*t13).n1
/;
scalar numtalk 'total number of talks';
numtalk=card(talk);
display talk,numtalk;
** actually the count is 21
** abort$(numtalk<>22) "oops, check your sets";
parameter ntalk(t) 'numbers of times a talk is given';
ntalk(t) = sum(talk(t,n),1);
display ntalk;
We see that the total number of talks is actually 21.
The preferences can be modeled as a parameter preferences(p,t). We assume eight of each row has numbers 1,..,8 and the rest is zero (no preference). We assume further 8 is highest preference so we will maximize. To be able to run a model we need to simulate some data. We can use random data, but need to consider that talks t1 and t2 through t7 are a little bit more popular (they are repeated a few times). The algorithm is a little bit complicated, but here it is:
parameter italk(t,n) 'number all talks (all 21 of them)';
scalar counter/0/;
loop(talk(t,n),
counter=counter+1;
italk(talk)=counter;
);
display italk;
parameter preferences(p,t) 'preference = 0..8, 8 is highest preference';
preferences(p,t)=0;
scalar kk,kt;
alias(t,tt);
set tcurrent(t);
loop((p,tt)$(ord(tt)<=8),
repeat
* draw from 1..numtalk
kk = UniformInt(1,numtalk);
kt = sum(talk(t,n)$(italk(t,n)=kk),ord(t));
* preferences(p,'element with ord kt') = ord(t)
tcurrent(t)$(ord(t)=kt) = yes;
if (sum(tcurrent,preferences(p,tcurrent))=0,
preferences(p,tcurrent) = ord(tt);
else
kk = 0
);
tcurrent(tcurrent) = no;
until kk<>0;
);
display "after",preferencesWe renumber talks in italks as follows:
---- 84 PARAMETER italk number all talks (all 21 of them)
n1 n2 n3
t1 1.000 2.000 3.000
t2 4.000 5.000
t3 6.000 7.000
t4 8.000 9.000
t5 10.000 11.000
t6 12.000 13.000
t7 14.000 15.000
t8 16.000
t9 17.000
t10 18.000
t11 19.000
t12 20.000
t13 21.000This allows us to draw from unique talks 1..21, which gives a better distribution than if we would have drawn from 1..13 (e.g. we would generate too few attendants for the popular talk t1 which is given three times). Using this we can generate some data for preferences:
---- 110 PARAMETER preferences preference = 0..8, 8 is highest preference
t1 t2 t3 t4 t5 t6 t7 t8 t9
p1 6.000 1.000 4.000 5.000 7.000 3.000
p2 4.000 6.000 7.000 8.000 1.000 5.000 3.000
p3 2.000 3.000 8.000 1.000 4.000 6.000 7.000
p4 1.000 3.000 5.000 2.000 6.000 8.000 7.000
p5 3.000 5.000 4.000 2.000 1.000 7.000 6.000 8.000
p6 4.000 7.000 1.000 8.000 5.000 2.000 3.000 6.000
p7 3.000 7.000 2.000 1.000 8.000 6.000 5.000
p8 7.000 1.000 2.000 4.000 8.000 5.000
p9 1.000 6.000 7.000 3.000 4.000 2.000 5.000
p10 2.000 5.000 3.000 1.000 7.000 6.000 8.000
p11 7.000 6.000 3.000 5.000 2.000 4.000
p12 7.000 1.000 5.000 8.000 2.000 6.000 3.000
p13 8.000 1.000 4.000 6.000 2.000 3.000
p14 2.000 1.000 5.000 3.000 4.000 6.000
p15 2.000 3.000 6.000 5.000 8.000 1.000 7.000
p16 5.000 7.000 1.000 3.000 8.000 2.000
p17 4.000 1.000 8.000 6.000 5.000
p18 3.000 1.000 2.000 5.000 7.000 6.000 4.000
p19 6.000 8.000 7.000 5.000 1.000 4.000
p20 5.000 1.000 6.000 8.000 4.000
p21 1.000 2.000 5.000 3.000 7.000
p22 4.000 1.000 8.000 5.000 3.000 6.000 7.000
p23 2.000 5.000 6.000 8.000 3.000
p24 1.000 4.000 5.000 7.000 6.000 2.000 3.000 8.000
p25 2.000 4.000 6.000 5.000 1.000 7.000
p26 3.000 5.000 7.000 8.000 4.000 6.000
p27 2.000 6.000 8.000 1.000 4.000 3.000 7.000
p28 4.000 1.000 3.000 6.000 7.000 8.000
p29 2.000 3.000 4.000 8.000 1.000 5.000 6.000
p30 4.000 1.000 3.000 8.000 2.000 6.000 5.000
p31 5.000 6.000 2.000 7.000 1.000 4.000
p32 6.000 3.000 4.000 5.000 7.000 8.000
p33 2.000 4.000 6.000 5.000 1.000 8.000
p34 7.000 4.000 3.000 6.000 5.000
p35 1.000 7.000 8.000 2.000 6.000 4.000 3.000
p36 2.000 5.000 3.000 6.000 1.000 7.000
p37 1.000 3.000 5.000 4.000 6.000 2.000
p38 7.000 3.000 8.000 6.000 2.000 1.000
p39 2.000 1.000 4.000 8.000 7.000 5.000
p40 5.000 1.000 4.000 8.000 7.000 2.000 3.000
p41 4.000 7.000 2.000 3.000 5.000 6.000
p42 2.000 8.000 7.000 5.000 4.000 6.000
p43 5.000 2.000 7.000 6.000 1.000 3.000
p44 4.000 7.000 1.000 3.000 5.000
p45 3.000 7.000 1.000 4.000 5.000 8.000 2.000
p46 2.000 5.000 6.000 8.000 4.000 7.000
p47 7.000 5.000 3.000 8.000 2.000 1.000
p48 5.000 7.000 8.000 6.000 3.000
p49 2.000 5.000 1.000 3.000 8.000
p50 2.000 5.000 1.000 3.000 4.000 7.000
+ t10 t11 t12 t13
p1 2.000 8.000
p2 2.000
p3 5.000
p4 4.000
p7 4.000
p8 6.000 3.000
p9 8.000
p10 4.000
p11 1.000 8.000
p12 4.000
p13 5.000 7.000
p14 8.000 7.000
p15 4.000
p16 4.000 6.000
p17 7.000 3.000 2.000
p18 8.000
p19 3.000 2.000
p20 2.000 7.000 3.000
p21 4.000 6.000 8.000
p22 2.000
p23 7.000 1.000 4.000
p25 3.000 8.000
p26 2.000 1.000
p27 5.000
p28 5.000 2.000
p29 7.000
p30 7.000
p31 3.000 8.000
p32 2.000 1.000
p33 3.000 7.000
p34 8.000 2.000 1.000
p35 5.000
p36 8.000 4.000
p37 8.000 7.000
p38 4.000 5.000
p39 3.000 6.000
p40 6.000
p41 8.000 1.000
p42 1.000 3.000
p43 8.000 4.000
p44 6.000 8.000 2.000
p45 6.000
p46 1.000 3.000
p47 6.000 4.000
p48 2.000 1.000 4.000
p49 6.000 4.000 7.000
p50 6.000 8.000Of course in practice we have his data available and we don't have to worry about this step (actually the most complicated part of the whole model). The rest of the model was implemented as follows:
variable z 'objective variable';
binary variables
x(t,p,s) 'assign talk/person/slot'
xts(t,s) 'assign talk/slot'
xtp(t,p) 'assign talk/person'
;
* we can relax xts and xtp
xts.prior(t,s) = INF;
xtp.prior(t,p) = INF;
equations
defxts1(t,s) 'calculate xts: all x=0 => xts = 0'
defxts2(t,p,s) 'calculate xts: any x=1 => xts = 1'
defxtp(t,p) 'calculate xtp'
talkcount(t) 'talk can be repeated ntalk times'
slotcount(s) 'up to 5 talks each period'
listen(p,s) 'p can visit only one talk in each time period'
zdef 'objective: maximize preferences'
;
* x(t,p,s)=0 for all p => xts(t,s) = 0
defxts1(t,s).. xts(t,s) =L= sum(p, x(t,p,s));
* any x(t,p,s)=1 => xts(t,s) = 1
defxts2(t,p,s).. xts(t,s) =G= x(t,p,s);
* p visits talk t in any s
defxtp(t,p).. xtp(t,p) =E= sum(s, x(t,p,s));
* each talk happens exactly ntalk times
talkcount(t).. sum(s, xts(t,s)) =E= ntalk(t);
* timeslot can only hold up to 5 talks
slotcount(s).. sum(t, xts(t,s)) =L= rooms;
* p can only visit one talk in each time period
listen(p,s).. sum(t,x(t,p,s)) =E= 1;
* we don't allow here (t,p) combinations without preference
xtp.fx(t,p)$(preferences(p,t)=0) = 0;
* objective: maximize
zdef.. z =e= sum((t,p), preferences(p,t) * xtp(t,p));
model scheduling /all/;
option mip=cplex;
scheduling.optfile=1;
scheduling.iterlim=100000;
scheduling.optcr=0;
solve scheduling using mip maximizing z;
$onecho > cplex.opt
threads 4
$offechoNote that variables xts and xtp are automatically integer, so we relax them by assigning a priority of infinity to them.
Cplex solves this quite quickly:
--- Job conference2.gms Start 03/05/09 17:58:00 WEX-VIS 23.0.2 x86/MS Windows
GAMS Rev 230 Copyright (C) 1987-2009 GAMS Development. All rights reserved
Licensee: Erwin Kalvelagen G090213/0001CV-WIN
Amsterdam Optimization Modeling Group DC4572
--- Starting compilation
--- conference2.gms(177) 3 Mb
--- Starting execution: elapsed 0:00:00.003
--- conference2.gms(169) 4 Mb
--- Generating MIP model scheduling
--- conference2.gms(170) 5 Mb
--- 4,234 rows 3,966 columns 17,496 non-zeroes
--- 3,250 discrete-columns
*** 465 relaxed-columns WARNING
--- Executing CPLEX: elapsed 0:00:00.034
ILOG CPLEX Feb 14, 2009 23.0.2 WIN 9101.9411 VIS x86/MS Windows
Cplex 11.2.1, GAMS Link 34
Cplex licensed for 1 use of lp, qp, mip and barrier, with 4 parallel threads.
Reading parameter(s) from "C:\projects\test\cplex.opt"
>> threads 4
Finished reading from "C:\projects\test\cplex.opt"
Reading data...
Starting Cplex...
Tried aggregator 1 time.
MIP Presolve eliminated 1501 rows and 1501 columns.
Reduced MIP has 2733 rows, 2465 columns, and 10595 nonzeros.
Reduced MIP has 2000 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec.
Clique table members: 650.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: opportunistic, using up to 4 threads.
Parallel mode: opportunistic, using up to 4 threads for concurrent optimization.
Tried aggregator 1 time.
No LP presolve or aggregator reductions.
Using devex.
Using devex.
Total real time on 4 threads = 0.17 sec.
Root relaxation solution time = 0.17 sec.
Nodes Cuts/
Node Left Objective IInf Best Integer Best Node ItCnt Gap
0 0 1500.0000 906 1500.0000 5
* 0+ 0 1272.0000 1500.0000 5 17.92%
0 0 1500.0000 779 1272.0000 Fract: 1 3652 17.92%
* 0+ 0 1308.0000 1500.0000 3652 14.68%
* 0+ 0 1353.0000 1500.0000 3652 10.86%
* 0+ 0 1446.0000 1500.0000 3652 3.73%
0 2 1500.0000 779 1446.0000 1500.0000 3652 3.73%
* 4+ 0 1460.0000 1500.0000 10828 2.74%
* 4+ 0 1471.0000 1500.0000 10683 1.97%
* 40+ 33 1472.0000 1498.0000 37861 1.77%
100 95 1492.8125 568 1472.0000 1498.0000 54702 1.77%
* 127+ 120 1478.0000 1498.0000 58492 1.35%
200 194 1487.6000 458 1478.0000 1498.0000 74738 1.35%
300 291 1492.6364 499 1478.0000 1498.0000 88945 1.35%
* 346+ 323 1483.0000 1498.0000 101352 1.01%
* 374+ 323 1488.0000 1498.0000 108821 0.67%
400 253 1493.0667 555 1488.0000 1498.0000 115116 0.67%
500 153 1495.0000 654 1488.0000 1498.0000 148604 0.67%
600 159 1491.4444 448 1488.0000 1497.3333 208207 0.63%
700 205 1492.8333 526 1488.0000 1496.6667 247331 0.58%
800 243 1494.6667 438 1488.0000 1496.6667 263583 0.58%
900 312 cutoff 1488.0000 1496.5000 282888 0.57%
1000 385 1494.9375 465 1488.0000 1496.0000 309440 0.54%
Elapsed real time = 32.45 sec. (tree size = 0.49 MB, solutions = 10)
1100 457 1492.1875 579 1488.0000 1495.7500 326655 0.52%
1200 524 cutoff 1488.0000 1495.5000 347873 0.50%
1300 588 1490.5000 386 1488.0000 1495.3333 371387 0.49%
1400 655 1489.4286 429 1488.0000 1495.0000 394081 0.47%
1500 706 cutoff 1488.0000 1495.0000 418373 0.47%
1600 760 cutoff 1488.0000 1494.9167 445114 0.46%
1700 810 1489.5000 355 1488.0000 1494.7500 466940 0.45%
1800 865 cutoff 1488.0000 1494.6667 487877 0.45%
1900 924 1490.3333 385 1488.0000 1494.5000 510279 0.44%
2000 972 1492.5000 523 1488.0000 1494.3333 536279 0.43%
Elapsed real time = 43.77 sec. (tree size = 1.27 MB, solutions = 10)
2100 1022 cutoff 1488.0000 1494.1429 561289 0.41%
* 2127 391 integral 0 1491.0000 1494.0714 567476 0.21%
2200 380 cutoff 1491.0000 1494.0000 590101 0.20%
2300 363 1492.0000 530 1491.0000 1493.6667 627287 0.18%
2400 358 cutoff 1491.0000 1493.5000 652433 0.17%
2500 326 cutoff 1491.0000 1493.2000 684303 0.15%
2600 272 1492.5625 605 1491.0000 1493.0000 722077 0.13%
2700 245 cutoff 1491.0000 1493.0000 749425 0.13%
2800 191 1492.0000 334 1491.0000 1492.5000 771850 0.10%
2900 107 cutoff 1491.0000 1492.2609 793601 0.08%
3000 15 cutoff 1491.0000 1492.0000 808231 0.07%
Elapsed real time = 57.28 sec. (tree size = 0.05 MB, solutions = 11)
Root node processing (before b&c):
Real time = 2.64
Parallel b&c, 4 threads:
Real time = 54.99
Sync time (average) = 2.47
Wait time (average) = 0.00
-------
Total (root+branch&cut) = 57.63 sec.
MIP status(101): integer optimal solution
Fixing integer variables, and solving final LP...
Parallel mode: opportunistic, using up to 4 threads for concurrent optimization.
Tried aggregator 1 time.
LP Presolve eliminated 4234 rows and 3966 columns.
All rows and columns eliminated.
Total real time on 4 threads = 0.00 sec.
Fixed MIP status(1): optimal
Proven optimal solution.
MIP Solution: 1491.000000 (814080 iterations, 3023 nodes)
Final Solve: 1491.000000 (0 iterations)
Best possible: 1491.000000
Absolute gap: 0.000000
Relative gap: 0.000000
--- Restarting execution
--- conference2.gms(170) 0 Mb
--- Reading solution for model scheduling
--- conference2.gms(170) 3 Mb
--- GDX File C:\projects\test\x.gdx
*** Status: Normal completion
--- Job conference2.gms Stop 03/05/09 17:58:58 elapsed 0:00:57.817Note that we found a proven global optimum in less than a minute here. The complete schedule looks like:
It is often the simplest to start with a single large multidimensional “cube” (our variable x(t,p,s)), and then derive auxiliary variables from that cube (our variables xts, xtp). If the problem becomes very large, this may not be possible (x just becomes too large). However, if this structure fits, in many cases the performance is very good. In this case we have 3250 binary variables. This is a large number. Is is quite a feat that we can solve this quickly to optimality.
See also [follow-up].
Thursday, February 12, 2009
TSP Powerset Formulation
> Problem. I have some difficulties to modelling this subtour
> elimination constraint (n = number of nodes):
> sum(i in S, sum(j in S, x(i,j))) <= |S|-1
> for every nonempty subset S of {2,3,..,n}
This is the Ford, Fulkerson, Johnson (1954) formulation, based on the power of {2,3,..,n}. This generates a lot of constraints (2^(n-1)), with many not active in the optimal solution. So this approach only works for small problems.
| $ontext |
Note: the construct system.powerSetRight is a new GAMS feature (24.0, 2013).
This solves quite fast:
| --- Starting compilation IBM ILOG CPLEX 24.7.3 r58181 Released Jul 11, 2016 WEI x86 64bit/MS Windows Reading data... Iteration log . . . Nodes Cuts/ * 0 0 integral 0 3323.0000 3323.0000 45 0.00% Root node processing (before b&c): Proven optimal solution. MIP Solution: 3323.000000 (45 iterations, 0 nodes) Best possible: 3323.000000 --- Restarting execution |
References
- burma14.gms: above model
- burma14-3.gms: generation of powerset written in GAMS (not using system.PowerSetRight).
- burma14-2.gms: formulation from Svestka (J.A. Svestka, A continuous variable representation of the TSP, Math Prog, v15, 1978, pp211-213)
- burma14-4.gms: a cutting plane technique
Easy MIP
--- 122,284 rows 352,038 columns 667,797 non-zeroes
--- 231,136 discrete-columns
Nodes Cuts/
Node Left Objective IInf Best Integer Best Node ItCnt Gap
0 0 588575.0000 606 588575.0000 14792
0 0 588575.0000 689 Cuts: 313 16547
0 0 588575.0000 736 ZeroHalf: 14 17624
* 0+ 0 587775.0000 588575.0000 17624 0.14%
0 2 588575.0000 349 587775.0000 588575.0000 17624 0.14%
Elapsed real time = 30.14 sec. (tree size = 0.00 MB, solutions = 1)
* 10+ 1 588575.0000 588575.0000 18686 0.00%
Thursday, January 29, 2009
Gurobi vs Cplex benchmarks
Here are some benchmarks: http://plato.asu.edu/ftp/
Wednesday, January 28, 2009
Cplex log: number of integer variables
Reading data...
Starting Cplex...
Tried aggregator 1 time.
MIP Presolve eliminated 45077 rows and 15073 columns.
MIP Presolve modified 504 coefficients.
Aggregator did 1008 substitutions.
Reduced MIP has 73884 rows, 26656 columns, and 201936 nonzeros.
Reduced MIP has 2016 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.45 sec.
Clique table members: 900.
MIP emphasis: hidden feasible solutions.
MIP search method: dynamic search.
Parallel mode: opportunistic, using up to 4 threads.
Parallel mode: opportunistic, using up to 4 threads for concurrent optimization.
Using devex.
Using devex.
Total real time on 4 threads = 16.18 sec.
Root relaxation solution time = 16.19 sec.
Nodes Cuts/
Node Left Objective IInf Best Integer Best Node ItCnt Gap
0 0 0.0000 2036 0.0000 20
Wednesday, January 21, 2009
Cplex barrier results
| rows/cols/nz | dual | primal | barrier | |
|---|---|---|---|---|
| model 1 | 1e5/2e5/1.4e6 | 1247 | 857 | 8.7 |
| model 2 | 1.1e5/2.1e5/6.1e5 | 195 | 1223 | 7.3 |
The GAMS models look like:
41 variable z,a1(j),a2(j),s1(i),s2(i),y(k);
42 positive variable s1,s2;
43 equation obj,e1(i),e2(k),e3(i);
44
45 option lp=cplex;
46 option iterlim=1000000;
47 option reslim=10000;
48
49 obj.. z =e= sum(i, s1(i)+s2(i));
50 e1(i).. sum(j, xx(i,j)*a1(j)) + s1(i) - s2(i) =e= b(i);
51 model m1 /obj,e1/;
52 solve m1 minimizing z using lp;
53
54 e2(k).. y(k) =e= sum(j, x(k,j)*a2(j));
55 e3(i).. sum(map(i,k), y(k)) + s1(i) - s2(i) =e= b(i);
56 model m2 /obj,e2,e3/;
57 *solve m2 minimizing z using lp;
Note that the SUM in line 55 is actually not a real summation. It just selects a k belonging to a particular i. A different, maybe better, way to write this would be:
Friday, January 9, 2009
Sensitivity Analysis in a loop with GAMS/Cplex
> see how I can do sensitivity analysis in a loop.
$ontext
shows how to do sensitivity analysis inside a single
GAMS job by using GDX files.
Erwin Kalvelagen, december 2003, revised jan 2009
$offtext
Sets
i canning plants / seattle, san-diego /
j markets / new-york, chicago, topeka / ;
Parameters
a(i) capacity of plant i in cases
/ seattle 350
san-diego 600 /
b(j) demand at market j in cases
/ new-york 325
chicago 300
topeka 275 / ;
Table d(i,j) distance in thousands of miles
new-york chicago topeka
seattle 2.5 1.7 1.8
san-diego 2.5 1.8 1.4 ;
Scalar f freight in dollars per case per thousand miles /90/ ;
Parameter c(i,j) transport cost in thousands of dollars per case ;
c(i,j) = f * d(i,j) / 1000 ;
Variables
x(i,j) shipment quantities in cases
z total transportation costs in thousands of dollars ;
Positive Variable x ;
Equations
cost define objective function
supply(i) observe supply limit at plant i
demand(j) satisfy demand at market j ;
cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
supply(i) .. sum(j, x(i,j)) =l= a(i) ;
demand(j) .. sum(i, x(i,j)) =g= b(j) ;
Model m /all/ ;
*
* set options to cplex writes an include file with sensitivity
* information
*
$onecho > cplex.opt
objrng all
rhsrng all
rngrestart rng.inc
$offecho
m.optfile=1;
m.dictfile=2;
option lp=cplex;
Set rnglim /lo,up/;
*
* three different scenarios
*
set iter /iter1*iter3/;
parameter delta(iter);
delta(iter)$(ord(iter)>1) = 100;
display delta;
*
* write gams file that reads include file rng.inc and
* writes a GDX file (specified on the command line)
*
$onecho > inc2gdx.gms
set i,j,rnglim
$gdxin sets.gdx
$load i j rnglim
$include rng.inc
$offecho
*
* save the sets i,j,rnlim to gdx file sets.gdx
*
execute_unload 'sets.gdx',i,j,rnglim;
*
* parameters to hold ranges for equation DEMAND
*
parameter demandrange(j,rnglim);
parameter alldemandrange(iter,j,rnglim);
loop(iter,
a(i) = a(i) + delta(iter);
SOLVE m USING LP minimizing z;
*
* store the sensitivity information in a GDX file
*
execute '=gams.exe inc2gdx.gms lo=3 gdx=dump.gdx';
*
* get data from GDX file
*
execute_load 'dump.gdx',demandrange=demandRNG;
alldemandrange(iter,j,rnglim) = demandrange(j,rnglim);
);
display alldemandrange;