且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用惰性约束回调实现TSP

更新时间:2022-04-09 01:13:46

我不认为您想提前致电 add_lazy_constraints 。如果这样做了,则可以直接将懒惰约束添加到模型中。

I don't think you want to call add_lazy_constraints beforehand. If you did this, then you could just add the lazy constraints directly to the model.

相反,您需要在回调函数中使用一些代码来分隔约束。根据 sol 中的值,您会发现违反的子巡回消除约束并将其添加。

Instead you want some code in your callback that separates the constraints. Based on the values in sol you find a violated subtour elimination constraint and add it.