Forum Discussion
FICO
9 years agoCommunity Manager
TSP Subtour-Elimination Callback Class
I am new to Xpress and trying to implement a simple TSP instance using BCL Java to get myself up to speed. I have done this in Cplex before using the cut callbacks, which work fine for adding the subtour elimination constraints to the B&B tree during the solve. However, the following code snippet does not quite work in Xpress. It is a simple 13-node TSP where root node's integer solution is as follows:
x[0][2] = 1
x[0][7] = 1 x[1][8] = 1 x[1][11] = 1 x[2][3] = 1 x[3][7] = 1 x[4][11] = 1 x[4][12] = 1 x[5][9] = 1 x[5][10] = 1 x[6][8] = 1 x[6][12] = 1 x[9][10] = 1Obviously, we need to add a subtour elimination constraint, such as:
CUT(0):x[0][2] + x[0][7] + x[2][3] + x[3][7] <= 3
However, the solver declare the problem infeasible after adding this valid cut.
*** Search completed *** Time: 0 Nodes: 1
Problem is integer infeasible Number of integer feasible solutions found is 0 Best bound is 1.00000E+40What am I missing?
Code Attached.
3 Replies
- FICOCommunity Manager
A couple of points regarding your code:
- Please remove the "loadMat" call within the callback.
- The 'optnode' callback function is triggered when a node relaxation has been solved to optimality and the Optimizer is about to branch or declare the node integer feasible. Only if the node is about to be declared integer feasible you should check for subtours, so start it with a test of whether XPRS.MIPINFEAS=0.
- I would also recommend to set globally XPRS.SYMMETRY=0.
- In terms of possible alternative cut formulations, you may want to take a look at the Mosel model example f5tour.mos in the subdirectory examples/mosel/ApplBook/F_TransAir of the Xpress distribution: if the problem is entirely symmetric, it can be helpful to exclude also the same tour in the other sense.
- FICOCommunity Manager
Thanks a bunch for your response. In the example f5tour.mos, my understanding is that it re-solves the whole problem from scratch after adding each subtour cut. If so, is there a way to implement do this in Mosel via a callback method that adds subtour cuts as necessary within the B&B tree?
As for BCL, I made the changes that you suggested but it still does not like the cut I am adding. Any idea what else might be going wrong here?
Code attached.
- FICOCommunity Manager
Attached a version of the Mosel model that uses the OPTNODE callback.
What kind of errors/log are you seeing from your BCL program? (It is not runnable without the definition of the class Edge.)
Related Content
Related Content
Implementing the TSP with DFJ subtour elimination constraints
To learn how callbacks work in Xpress, based on the answer by Daniel Junglas in this question: https://community.fico.com/s/question/0D54W00008P73MsSAJ/lazy-cut-callback-in-java, I've been experiment...5 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum3 unread comments3 unread0Views0likes3CommentsAre preintsol callbacks threadsafe?
The optimizer documentation states "When the MIP callbacks are called they are MUTEX protected to allow non threadsafe user callbacks." In my Java code for one-tree Benders, if I specify a single thr...9 months agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum3 unread comments3 unread3Views0likes3CommentsVariable names in callback (Java API)
I construct a cut in a preintsol callback using variables from the model containing the callback. When constructing the model, I give the variables names (using withName(...)) and store them in a vec...9 months agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum4 unread comments4 unread1View0likes4Comments