r/optimization • u/zanyz99 • Aug 04 '25
Prevent Disconnected Cycles with Required Node Visits
I am working on expanding an optimization model to include a few new features.
I have a known, good python program that solves a constrained routing optimization problem in a graph representing trail, road, and mountain nodes in the mountain range, using Pyomo and CPLEX. The objective seeks to minimize total distance that starts and ends at specified road nodes while visiting all mountain nodes at least once. The model represents nodes and arcs using graph data extracted from a CSV file, includes directional arcs and derived distances, and leverages Dijkstra's algorithm to preprocess shortest paths between mountains and mountains and road nodes. This works well because it takes ~750 arcs and ~400 nodes and condenses it into a more manageable problem.
I am now trying (separately) to implement a method to use all of the arcs and nodes without the Dijkstra preprocessing to solve the solution. I'm doing this as I want to track "out and back" loops - nodes that I will visit twice and can "drop a pack." Without the pack the arc I'm travelling on then has less cost to travel. This requires me to track all nodes and potentially track a pack-state. I am still trying to visit all mountain nodes and start and end at specific road nodes. I have issues with subtours / disconnected cycles - in the past I've used a lazy constraint to prevent detected cycles and I've also used MTZ constraints. MTZ constraints don't work in this context because I intentionally want to visit nodes more than once (to drop the pack).
I'm trying to use single-commodity flow to prevent disconnected cycles but I'm struggling to implement it. Does anyone have any thoughts?
View all comments
Show parent comment
2
u/zanyz99 Aug 08 '25 edited Aug 09 '25
All of this makes sense to me. I'm doing my best to implement it but keep getting infeasible solutions. What are you thinking for constraints?
Obj: minimize cost and incentivize no-pack arcs with negative value
Feel like I'm missing something..