What version of OR-tools and what language are you using?
Version: 7.7.7810
Language: Java/Kotlin
Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
Routing
What operating system (Linux, Windows, ...) and version?
MacOS
What did you do?
I want to extract the transit value between two nodes. This post and this post tell me I should tell the solver I want to keep track of transit var.
So I wrote a function to do this for SlackVar and TransitVar:
fun setSlackAndTransitVar(index: Int){
// to extract slack var the slack var needs to be "Added": https://github.com/google/or-tools/issues/145#issuecomment-173176505
// transitVar throws an exception
routingModel.addToAssignment(timeDimension.transitVar(index.toLong())) // <-- throw SegFault
routingModel.addToAssignment(timeDimension.slackVar(index.toLong()))
}
the line where the transit var is registered throws SegFault. I am aware that SlackVar needs to be accessed via the original index and CumulVar via the index manager as per this link . I am unclear on TransitVar though. That said, in my tests the values for index and the value return via index manager are the same.
Make sure you include information that can help us debug (full error message, model Proto).
Anything else we should know about your project / environment
All method *Var() should take solver index as argument, which is int64 in C++
OK just to clarify this is what I have done and it seems to work:
val vehicleIndex = node.vehicleIndex
val orToolsNodeIndex = when(node) {
is VehicleStartNode -> routingModel.start(vehicleIndex)
is VehicleEndNode -> routingModel.end(vehicleIndex)
else -> throw IllegalArgumentException("Unidentified vehicle node type. Expecting a vehicle start or end node, received $node")
}
setSlackAndTransitVar(orToolsNodeIndex)
routingMode.start(vehicleIndex) and routingModel.end(vehicleIndex) return the solver index, which should be the same value as indexManager.NodeToIndex(vehicleIndex). Correct?
Also, a note for anyone stumbling upon this: A TransitVar is only defined for nodes that have a subsequent node, so setting TransitVar on vehicle end depot will cause a crash.
No, NodeToIndex should be called with nodes, not vehicles.
Laurent Perron | Operations Research | [email protected] | (33) 1 42 68 53
00
Le ven. 9 oct. 2020 à 07:32, KeremAslan notifications@github.com a écrit :
OK just to clarify this is what I have done and it seems to work:
val vehicleIndex = node.vehicleIndex val orToolsNodeIndex = when(node) { is VehicleStartNode -> routingModel.start(vehicleIndex) is VehicleEndNode -> routingModel.end(vehicleIndex) else -> throw IllegalArgumentException("Unidentified vehicle node type. Expecting a vehicle start or end node, received $node") } setSlackAndTransitVar(orToolsNodeIndex)routingMode.start(vehicleIndex) and routingModel.end(vehicleIndex) return
the solver index, which should be the same value as
indexManager.NodeToIndex(vehicleIndex). Correct?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/or-tools/issues/2192#issuecomment-705977207,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACUPL3JDJ2KWAVTKKC72XGLSJ2OARANCNFSM4SIKYZTA
.
note: this is also true for SlackVar trying to get it from an end node will crash...
Go it thanks!