Thank you very much! I have learned a lot!
Thank you very much! I have learned a lot! It's very interestring to discuss with you.
I still think CPLEX has some troubles handling decimals.I will try my best to expain.
I have 3 TSP instances(Let's call them A,B,and C).Only A has fractional distance matrix.
At first,I try to solve TSP using constraint generation(without callback).First, I model it as an Assignment Problem,solve it ,find all the subtours, generate constraints to eliminate subtours and add them to the model,and solve the model again(using a while loop. If there is no subtoor, the program ends). The program can handle instance B,C real quickly(and I get the correct answers), but it stuck when it comes to instance A. After I truncate the data to integer, everything is OK. Here is the CPLEX log where it stucks.

Then, I try to solve TSP using Lazycallback.Again, I model it as an Assignment Problem, using lazycallback to eliminate subtours.It results that: solving B,C real quickly. But I get error 1217 with the original distance matrix of instance A.After I truncate the data to integer, everything is OK.
At last, I try to solve TSP using generic callback. I encounter excatly the same problem : error 1217 with original data ... and everything is OK after I truncate the data to integer.
What's more,it reminds to me that I once met similar problem when I used column generation to solve VRPTW.When it comes to calculate and compare the Reduced Cost , it seems necessary to truncate.Otherwise, the solve time is extremely slow.
That's why I think CPLEX may have some troubles handling decimals. I am looking forward to you reply!
------------------------------
Jixuan Feng
------------------------------
Original Message:
Sent: Fri October 21, 2022 03:28 PM
From: Paul Rubin
Subject: Java API- Question on generic callback implementation
There is no reason why objective values with fractional coefficients would cause CPLEX to generate a candidate solution that violated any of the constraints. When you round/truncate the objective coefficients to integer, you change the model, which may lead to different results. So possibly you have a problem in the model that still remains, but the change leads CPLEX to a different trajectory on this particular model instance that (by luck) avoids the problem.
I have never used the code structure you are using (making the callback a static subclass, making the master IloCplex object a local variable in a method rather than a class field and then having to recover it in the callback with context getCplex() method, ...), so it's hard for me to see if this would cause thread safety errors. The only class variable in the callback, x, is written to only in the constructor, with all other variable changes occurring to variables local to the invoke method, so I don't see much potential for thread collisions ... but I'm no expert on thread safety either. If you are getting error 1217 with the original distance matrix but not with the integer distance matrix, I would suggest the following experiment:
- solve with the integer distances and record the solution (call it "sol1");
- return the distance matrix to the original double precision values, and in the code setting up the model fix every variable to its value in "sol1" (by setting lower bound = upper bound = value for each variable);
- solve again and, if error 1217 occurs, try to get a minimal conflict set, which will identify which constraints are not satisfied by "sol1".
If "sol1" ends up satisfying the original constraints but violating one of the Benders cuts, then you need to see whether your subproblem is generating incorrect Benders cuts for some reason.
------------------------------
Paul Rubin
Professor Emeritus
Michigan State University
------------------------------
Original Message:
Sent: Fri October 21, 2022 12:45 AM
From: Jixuan Feng
Subject: Java API- Question on generic callback implementation
Hi Mr. Rubin!
I think I know what is happening! The data is to accuracy, which may cause problem when cplex is handling floating point number!
Here is a glance of the distance matrix.Afrer I transform it to integer, everything is ok!

Anyway, Thanks for your time! I learned a lot from you replies and your blogs!!
------------------------------
Jixuan Feng
Original Message:
Sent: Thu October 20, 2022 05:37 PM
From: Paul Rubin
Subject: Java API- Question on generic callback implementation
Immediately after calling the callback constructor, you have System.exit(0). The program should stop there, which is a bit of a conundrum. Besides that, can you reproduce the problem with a smaller test example and, if so, post the output obtained when printing the values of x[][] in the callback?
------------------------------
Paul Rubin
Professor Emeritus
Michigan State University