routing-subtour-elimination
Subtour-elimination methods for TSP, VRP, pickup/dropoff routing, and routing MIPs with binary arc variables. Use when route-continuity constraints may permit…
от benchflow-ai★ 1 941 звезда на GitHub
Установить routing-subtour-elimination в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Routing Subtour Elimination
In routing MIPs, degree and continuity constraints are not enough. A vehicle can have one depot-to-depot path and a separate closed cycle among stations. Add subtour-elimination constraints whenever binary arc variables decide routes.
Use this base notation:
START = "depot_start"
END = "depot_end"
vehicles = range(K)
stations = range(n)
from_nodes = [START, *stations]
to_nodes = [*stations, END]
arcs = [(i, j) for i in from_nodes for j in to_nodes if i != j and not (i == START and j == END)]
x = {(v, i, j): model.addVar(vtype="B", name=f"x_{v}_{i}_{j}") for v in vehicles for i, j in arcs}
Required Base Route Constraints
Subtour elimination assumes each selected station has matching inbound and outbound route arcs.
for v in vehicles:
model.addCons(quicksum(x[v, START, j] for j in stations) == 1)
model.addCons(quicksum(x[v, i, END] for i in stations) == 1)
for i in stations:
incoming = quicksum(x[v, j, i] for j in from_nodes if j != i)
outgoing = quicksum(x[v, i, j] for j in to_nodes if j != i)
model.addCons(incoming == outgoing)
model.addCons(outgoing <= 1)
The subtour methods below prevent station-only cycles that are disconnected from START.
1. MTZ Order Constraints
MTZ adds an order variable for each vehicle-station pair. If vehicle v travels from station i to station j, then order[v, j] must be greater than order[v, i].
order = {
(v, i): model.addVar(vtype="C", lb=1, ub=max(1, n), name=f"order_{v}_{i}")
for v in vehicles
for i in stations
}
for v in vehicles:
for i in stations:
for j in stations:
if i != j:
model.addCons(order[v, i] - order[v, j] + n * x[v, i, j] <= n - 1)
Pros:
- Compact:
O(K n^2)constraints andO(K n)extra variables. - Easy to implement in common Python optimization APIs.
- Good default for small and medium benchmark instances.
Cons:
- LP relaxation is weak compared with cutset or flow formulations.
- Can be slow for larger VRPs.
- Order variables are artificial; do not interpret them as service times unless you also model time.
Use MTZ first when correctness and implementation speed matter more than best possible MIP strength.
2. Single-Commodity Flow Connectivity
Add an artificial connectivity flow that starts at the depot and sends one unit to every visited station. This flow is not physical vehicle load.
visit = {
(v, i): quicksum(x[v, i, j] for j in to_nodes if j != i)
for v in vehicles
for i in stations
}
flow_arcs = [(i, j) for i in [START, *stations] for j in stations if i != j]
f = {
(v, i, j): model.addVar(vtype="C", lb=0, ub=n, name=f"conn_flow_{v}_{i}_{j}")
for v in vehicles
for i, j in flow_arcs
}
for v in vehicles:
total_visits = quicksum(visit[v, i] for i in stations)
model.addCons(quicksum(f[v, START, j] for j in stations) == total_visits)
for i, j in flow_arcs:
model.addCons(f[v, i, j] <= n * x[v, i, j])
for i in stations:
incoming_flow = quicksum(f[v, h, i] for h in [START, *stations] if h != i)
outgoing_flow = quicksum(f[v, i, j] for j in stations if j != i)
model.addCons(incoming_flow - outgoing_flow == visit[v, i])
Pros:
- Stronger connectivity logic than MTZ in many models.
- Static constraints, no callback needed.
- Works with optional station visits.
Cons:
- Adds
O(K n^2)continuous variables. - Do not reuse truck load as the connectivity flow when the vehicle can both pick up and drop off. Physical load can increase and decrease; connectivity flow should monotonically distribute artificial units.
- More memory than MTZ.
Use this when MTZ gives weak incumbents or slow progress and the instance is still modest in size.
3. DFJ Subset Cuts
For every nonempty proper subset S of stations, selected station-to-station arcs inside S cannot form a closed cycle:
sum_{i in S, j in S, i != j} x[v,i,j] <= |S| - 1
For very small n, static enumeration is possible:
from itertools import combinations
for v in vehicles:
for r in range(2, n):
for S_tuple in combinations(stations, r):
S = set(S_tuple)
model.addCons(
quicksum(x[v, i, j] for i in S for j in S if i != j) <= len(S) - 1
)
Pros:
- Strong, direct subtour elimination.
- No artificial order or flow variables.
Cons:
- Exponential number of constraints.
- Static enumeration is only acceptable for small station counts.
Use static DFJ only for tiny instances or as a debugging baseline.
4. Lazy or Iterative Cut Separation
The strongest practical pattern is to solve with base route constraints, detect subtours in incumbents, add only the violated DFJ cuts, and continue.
In solvers with convenient lazy callbacks, add cuts during branch-and-bound. Some Python solver APIs require callback or constraint-handler p
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл routing-subtour-elimination?
Subtour-elimination methods for TSP, VRP, pickup/dropoff routing, and routing MIPs with binary arc variables. Use when route-continuity constraints may permit disconnected cycles and the model needs MTZ constraints, flow-based connectivity constraints, DFJ subset cuts, or lazy/iterative subtour cuts.
Как установить скилл routing-subtour-elimination?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл routing-subtour-elimination запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…