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.
Tuesday, December 4, 2012
History of LP/MIP
PS. You also may want to look at the whole issue at: http://www.zib.de/groetschel/publications/OptimizationStories.pdf. More interesting historic details about optimization.
Monday, December 3, 2012
GAMS question
A question was posed at https://groups.google.com/forum/?fromgroups=#!topic/gamsworld/0qYEcVd9x8I:
| set j /n1*n5/, variable pi(j); |
The user want to pick the 5-th element. This implementation clearly does not work. Some valid answers were given:
| Ab= sum(j$sameas(j,“n5“), pi.L(j) ) ; or ab=sum (k, sum(j$sameas(j,k), pi.L(j) ) ); |
However I would say this is not really good modeling practice. The best approach IMHO would be:
| set j /n1*n5/, variable pi(j); scalar ab; |
There are two advantages of this approach:
- The set k is now domain checked against j; no elements outside j can be specified here without alarm bells going off. Domain checking is very important when developing large, complex models.
- We can substantially simplify the assignment to ab and increase readability. The expression conveys immediately what it is supposed to do.
Setting up proper subsets will help you down the road.
Parallel LP
> Can I run LP solver in parallel on multiple cores? What about all running on GPUs?
All major LP solvers include a barrier/interior point code that can run on multiple cores. This includes Cplex, Gurobi and Mosek. Do not expect perfect scaling but some speed-up is possible. Sparse simplex algorithms are not ideally suited for parallelization. Some recent results were shown by John Forrest. See: ISMP 2012 talk.
About GPUs:
(From the same talk).
There are some other algorithms that can be implemented on GPUs. Many meta-heuristics have been ported to these devices. Here are some links:
- http://www.fit.vutbr.cz/research/view_pub.php?file=%2Fpub%2F9184%2F60240442.pdf&id=9184
- http://link.springer.com/chapter/10.1007%2F978-3-642-04843-2_4?LI=true
- http://www.gputechconf.com/content/GTC/posters/2010/A04-Parallel-Ant-Colony-Optimization-with-CUDA.pdf
- http://sikaman.dyndns.org:8888/honours/karim-tantawy-winter-2011.pdf
- and many more
Friday, November 30, 2012
Don’t always trust what a solver is saying
This is supposed to be a fairly difficult MIQP. However, when I run it I get quickly: INFEASIBLE:
| Tried aggregator 2 times. Total time on 1 threads = 0.05 sec. Nodes Cuts/ 0 0 infeasible 5 Root node processing (before b&c): Problem is integer infeasible. **** SOLVER STATUS 1 Normal Completion |
OK, but that sounds not really correct. I found a good integer solution with a linearized objective (same constraints). So lets fix the integer variables and see what happens:
* solve MIP
solve gms1 minimizing z using mip;
* fix integer variables
x.fx(i,t) = x.l(i,t);
* and feed it into MIQP solver
solve gms2 minimizing z using miqcp;
Now I see:
| Tried aggregator 1 time. Total time on 1 threads = 0.00 sec. Proven optimal solution. MIP Solution: 14817439.000000 (0 iterations, 0 nodes) |
Hmm, so not integer infeasible after all. Some more experiments yielded:
- Using MIPSTART with the MIP solution allowed the MIQP solver to proceed
- Scaling the objective cause the MIQP to proceed also. The scaling looks like:
objective2.. z =e= sum(t,sqr(reserves(t)))/1e6;
Don’t always trust the messages from the solvers…
Sunday, November 25, 2012
GAMS qp interface not very coherent
It is possible to write quadratically constrained problems (and QPs in particular) in GAMS and solve them efficiently with solvers like Cplex, Gurobi. But the rules are somewhat ad-hoc and incoherent.
- GAMS will not extract a QCP when using the notation x**2 (for a rather obscure reason; this should probably be dealt with in a smarter way)
- GAMS will extract a QCP with the notation x*x or sqr(x) or power(x,2)
- But GAMS will again not allow power(x,1) or power(x,0) so we can’t write the following:
| sets |
In forbidden cases you’ll get the poorly worded error message:
*** Could not load data from file: Detected 1 general nonlinear rows in model
Friday, November 23, 2012
Smoothing
In a scheduling model for maintenance of power generators the objective is to smooth the reserves. The authors use a quadratic objective to model and the results over a year look like:
MIQP’s still solve significantly slower than MIP models, so I was looking for a linear approximation. The first thing that comes to mind is to minimize the max. This gives:
The problem here is we get a few weeks with really low reserves. An alternative is to minimize the difference between the max and the min. This looks like:
This actually looks quite similar to the first picture, and we have achieved our goal: make the model linear.
Wednesday, November 21, 2012
1 vs 4 threads
Running a small MIP using 1 thread:
| Optimize a model with 177 rows, 549 columns and 3800 nonzeros Root relaxation: objective 4.990000e+02, 947 iterations, 0.03 seconds Nodes | Current Node | Objective Bounds | Work 0 0 499.00000 0 63 949.00000 499.00000 47.4% - 0s Explored 177443 nodes (1164346 simplex iterations) in 56.54 seconds Optimal solution found (tolerance 0.00e+00) |
Now solve the same model with the same solver on the same machine using 4 threads:
| Optimize a model with 177 rows, 549 columns and 3800 nonzeros Root relaxation: objective 4.990000e+02, 947 iterations, 0.03 seconds Nodes | Current Node | Objective Bounds | Work 0 0 499.00000 0 63 949.00000 499.00000 47.4% - 0s 97009933 49020 897.00000 80 47 901.00000 897.00000 0.44% 5.8 9085s 97054184 47405 infeasible 86 901.00000 897.00000 0.44% 5.8 9090s 97103347 45433 infeasible 95 901.00000 897.00000 0.44% 5.8 9095s 97174397 76 infeasible 97 901.00000 900.91810 0.01% 5.8 9100s Explored 97174474 nodes (560614904 simplex iterations) in 9100.06 seconds Optimal solution found (tolerance 0.00e+00) |
Solution times go from 1 minute to 2.5 hours! Extrapolating this to 8 cores gives me the shivers….
Data errors
Even small tables can contain errors. An example data set in a published paper about scheduling maintenance of power generators looks like:
In GAMS I transcribed this as:
| table data(i,*) |
Just to be sure I added some checks:
| set error(i,t) 'check for mismatch between manpower and outage-weeks'; error(i,t)$(manpower(i,t)=0 and ord(t)<=data(i,'outage-weeks')) = yes; error(i,t)$(manpower(i,t)<>0 and ord(t)>data(i,'outage-weeks')) = yes; abort$card(error) "manpower mismatch",error; |
Low and behold, we see:
| ---- 93 manpower mismatch ---- 93 SET error check for mismatch between manpower and outage-weeks week4 unit12 YES **** Exec Error at line 93: Execution halted: abort$1 'manpower mismatch' |
Indeed we have for this unit a problem in the manpower allocation.
Friday, November 16, 2012
Intel
For parallel MIP the GPU based solutions such as http://www.nvidia.com/object/tesla-supercomputing-solutions.html are not very useful (although for some specialized applications GPU based optimization algorithms have been developed). Now Intel has an alternative:
http://www.drdobbs.com/parallel/intels-50-core-xeon-phi-the-new-era-of-i/240105810
http://www.intel.com/content/www/us/en/processors/xeon/xeon-phi-detail.html
The 60 cores sound attractive, but the limited amount of memory (8GB) may be a problem for big MIPs.
Tuesday, November 6, 2012
Gurobi integer feasibility tolerance
The integer feasibility tolerance determines when a fractional variable can be considered “automatically” integer during the branch-and-bound search. Gurobi allows this to be set as tight as 1.0e-9 (option IntFeasTol). But a client gets the following:
> I still get binary variables like 0.000008 instead of 0.
I actually believe this is a valid question. This is about 1.0e-6. Unfortunately the answer from Gurobi support is somewhat dismissive:
> This is a natural consequence of integer programming, which solves models via a series of linear programs. See FAQ 23:
http://www.gurobi.com/resources/faqs
Scaling can have notorious impact on LP feasibility tolerances (e.g. the scaled model can solve to optimality, but after unscaling become very infeasible). The LP feasibility tolerance controls how much a variable can be outside its bounds before becoming infeasible (or how much an equation can be violated before becoming infeasible – this is just how much a slack can be outside its bounds). I don’t think scaling has an effect on the integer feasibility tolerance.
Note that Cplex allows a integer feasibility tolerance of zero (parameter epint). At first this seems crazy, but actually works fine in models where we need variables to be really discrete. I guess Cplex may just need to do more work in this case: we may need to branch further when a binary variable that is still fractional assumes a value of 1.0e-9.
PS: See the comments for some interesting feedback. The real question remains: why if we request an integer feasibility tolerance of 1e-9 we observe fractional parts of 1e-6.