If you use "let" to set an initial feasible solution, then CPLEX will recognize it. So if CPLEX fails to find any feasible solution then maybe, due to some mistake, your solution wasn't really feasible. After setting the initial feasible solution but before solving, try using the following commands to check for any constraints or variable bounds that are violated by your solution:
display {i in 1.._ncons: _con[i].slack < 0} (_conname[i],_con[i].slack);
display {j in 1.._nvars: _var[j].slack < 0} (_varname[j],_var[j].slack);
Slacks that are negative by only some tiny amount (such as -10^-9) can be ignored, but otherwise negative slacks indicate infeasibilities in your solution. If there are infeasibilities then CPLEX will try to adjust your solution to make it feasible, but if it is not successful then your initial solution will be ignored.
If this test does not show any infeasibilities, then try asking CPLEX for some more information, by adding this setting before solving:
option cplex_options 'mipdisplay 2';
(Or, add 'mipdisplay 2' to your existing cplex_options string, if it isn't there already.) Then post the first 50 lines or so of the resulting output.
Bob Fourer
From: am...@googlegroups.com [mailto:am...@googlegroups.com]
On Behalf Of pmk...@ing.puc.cl
Sent: Monday, August 26, 2013 11:54 AM
To: am...@googlegroups.com
Subject: [AMPL 7405] Giving AMPL-CPLEX an initial solution
I would advise not to round any numbers in your Visual Studio program, but rather to send numbers like 3.19999999999 to AMPL. Then I would advise not rounding in AMPL either, and seeing whether the solution that you provide is deemed feasible by CPLEX. The CPLEX routines use a feasibility tolerance of something like 10^-6, so the difference between 3.19999999999 and 3.2 is not likely to make any difference to feasibility. (Indeed neither of these numbers can be converted exactly to binary in the computer anyway.)
If you do need rounding to achieve feasibility, then I would advise using AMPL's "precision" function to round at, say, the 6th or 8th significant digit. In general you will have a lot more control of how you round in AMPL than in Visual Studio.
On Behalf Of pmk...@ing.puc.cl
Sent: Thursday, August 29, 2013 11:34 AM
To: am...@googlegroups.com
Cc: 4...@ampl.com
Subject: Re: [AMPL 7411] Giving AMPL-CPLEX an initial solution
Numbers like 3.19999924327 or 3.20000097662 result from single-precision representations of 3.2. For example, according to www.h-schmidt.net/FloatConverter, the IEEE single-precision floating-point representations that come closest to 3.2 are
binary decimal
0 10000000 10011001100110011001100 3.1999998092651367
0 10000000 10011001100110011001101 3.200000047683716
With CPLEX's default feasibility tolerance of 10^-6, these discrepancies might be big enough to cause some trouble. The cure for this is to use double precision. If there's nothing you can do about the form of the input values, then in your Visual Studio program you can read them as they are, round them, and assign them to double precision variables, after which no further rounding should be necessary if you use double precision throughout your program.
On Behalf Of pmk...@ing.puc.cl
Sent: Saturday, August 31, 2013 4:10 PM
To: am...@googlegroups.com
Cc: 4...@ampl.com
Subject: Re: [AMPL 7418] Giving AMPL-CPLEX an initial solution
Bob, thank you very much for your answer.
Indeed I needed to round the numbers because Visual Studio was reading the values provided from an input file normally with only five 9's or 0's after the last digit and then with any numbers. For example, 3.2 could be read by Visual Studio as 3.19999924327 or as 3.20000097662.
As well, even if the input values where read and saved correctly, after operating with them in order to calculate the values of all the variables in the initial solution provided to CPLEX, Visual Studio was also miswriting the values. For example, 3.2 + 1.1 could be written as 4.29999964751 or as 4.30000046328.
Now imagine what happens when instead of adding I'm multiplying and when not only the product but also the factors are miswritten. Something like 3.2 * 1.1 could be written as different as 3.51999803 or 3.52000274.
Now, if you make several operations, after a while you have nothing but numbers that don't represent the numbers they should be. The result, more than half of the big amount of constraints I was dealing with were unfeasible making CPLEX incapable of using the feasible solution I was suposly providing.
To solve this I had to program my own rounding algorithm in Visual Studio and use it pretty much before and after every math operation. This in order to keep rounding the numbers and keep them right before they change that much that I can't detect what they should be.
Definitely something that shouldn't happen but... what can we say. I hope this is useful for someone else who might be having the same problem.
Thanks!
.
model model.mod; # here var x is declared;data data.dat;include initial_solution.let;option solver cplex_ampl;solve;
...
let x['a','b','c','d'] := 1;
...