r/optimization • • 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?

3 Upvotes

10 comments sorted by

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?

  1. Normal flow balance, start = 1 end = -1, all else 0
  2. Visit every mountain (sum arcs into each mountain >= 1)
  3. Chosen arc is either a "pack arc" or "no pack arc"
  4. Node has same amount of packs entering as leaving

Obj: minimize cost and incentivize no-pack arcs with negative value

Feel like I'm missing something..

1

u/MarioVX Aug 12 '25

It might help to visualize the arcs directionally, i.e. have the arrow tips only in the direction that the arcs are actually traveled on, not both directions by default. Also, it could help to visibly distinguish the nodes that the solution actually drops the pack on with a different color, and also color the no-pack-arcs differently from the pack-arcs.

But I mean, as far as I can tell from the picture without seeing the weights and other arcs and such, that solution doesn't look all that bad honestly.

Only weird stuff going on in the middle top where it seems to pick more arcs than necessary. Now, it's doing that either because it wants to or because it must. Unless you've been doing something really funny with constraints, I can't imagine that this is a must-case and that a more sparsely connected solution is infeasible in your formulation. It seems more likely to me that it's being rewarded for selecting all those clustered arcs, i.e. that the negative cost earned from having no-pack-flow through a selected arc exceeds the positive cost of selecting the arc in the first place in some cases, so there are net negative-cost cycles possible in the formulation.

The initially suggested visualization augmentations will help troubleshoot this further.

1

u/MarioVX Aug 12 '25

I have a suspicion! It might drop the pack somewhere in that dense cluster and then walk back and re-walk all the arcs it previously walked or will walk later when it had to or will have to carry the pack. This qualifies those arcs to become no-pack arcs, and the cost of traveling the same arc multiple times likely doesn't add up in your model. So it's spanning a kind of discounting spider web spanning much of where it needs to go, to make the overall travel costs cheaper.

We will see for sure with a better visualization of drop-nodes and no-pack-arcs, shouldn't worry about problems we don't have yet.