一键导入
optimize-local-search
For NP-hard optimization: TSP, scheduling, assignment problems. Uses greedy construction + local improvement (2-opt, hill climbing).
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
For NP-hard optimization: TSP, scheduling, assignment problems. Uses greedy construction + local improvement (2-opt, hill climbing).
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Conducts iterative deep research on any topic using web search, progressive exploration, and structured synthesis. Use when asked for comprehensive research, deep investigation, thorough analysis, or multi-source exploration of any topic. Triggers: research, investigate, deep dive, comprehensive analysis, explore thoroughly, find everything about.
For cross-cutting concerns: add behavior without modifying functions, caching, timing, logging, validation wrappers.
For performance work: measure before changing, profile to find bottlenecks, compare before and after.
For symbolic computation: ASTs, mathematical expressions, code that manipulates code structure, expression transformations.
For ordered processing: A* search, Dijkstra, event simulation, task scheduling. Efficient min/max extraction with heap-based queue.
For dynamic programming: overlapping subproblems, recursive solutions with repeated computations, memoization to avoid redundant work.
| name | optimize-local-search |
| description | For NP-hard optimization: TSP, scheduling, assignment problems. Uses greedy construction + local improvement (2-opt, hill climbing). |
Greedy + Local Search: Build initial solution fast, then improve iteratively.
def optimize(initial_solution, neighbors, score, max_iterations=10000):
"""Hill climbing: repeatedly move to better neighbor."""
current = initial_solution
current_score = score(current)
for _ in range(max_iterations):
improved = False
for neighbor in neighbors(current):
neighbor_score = score(neighbor)
if neighbor_score > current_score:
current, current_score = neighbor, neighbor_score
improved = True
break
if not improved:
break # Local optimum reached
return current
def two_opt(tour):
"""Improve tour by reversing segments that reduce total distance."""
tour = list(tour)
improved = True
while improved:
improved = False
for i in range(1, len(tour) - 2):
for j in range(i + 2, len(tour)):
if j == len(tour) - 1 and i == 1:
continue # Skip if reversing whole tour
# Check if reversing tour[i:j] improves distance
A, B, C, D = tour[i-1], tour[i], tour[j-1], tour[j % len(tour)]
if distance(A, B) + distance(C, D) > distance(A, C) + distance(B, D):
tour[i:j] = reversed(tour[i:j])
improved = True
return tour
def nearest_neighbor_tsp(cities):
"""Greedy: always go to nearest unvisited city."""
start = cities[0]
tour = [start]
unvisited = set(cities) - {start}
while unvisited:
nearest = min(unvisited, key=lambda c: distance(tour[-1], c))
tour.append(nearest)
unvisited.remove(nearest)
return tour
# Combine: greedy construction + local improvement
def solve_tsp(cities):
initial = nearest_neighbor_tsp(cities)
return two_opt(initial)