Get the FREE Ultimate OpenClaw Setup Guide →

graph-algorithm-selector

npx machina-cli add skill a5c-ai/babysitter/graph-algorithm-selector --openclaw
Files (1)
SKILL.md
2.1 KB

Graph Algorithm Selector Skill

Purpose

Select the optimal graph algorithm based on problem constraints, graph properties, and performance requirements.

Capabilities

  • Constraint analysis for algorithm selection
  • Trade-off analysis (Dijkstra vs Bellman-Ford vs Floyd-Warshall)
  • Special case detection (sparse vs dense, negative edges)
  • Algorithm complexity mapping to constraints
  • Suggest algorithm variants and optimizations

Target Processes

  • shortest-path-algorithms
  • advanced-graph-algorithms
  • graph-traversal
  • graph-modeling

Algorithm Selection Matrix

Shortest Path

ScenarioAlgorithmComplexity
UnweightedBFSO(V+E)
Non-negative weightsDijkstraO((V+E)log V)
Negative weightsBellman-FordO(VE)
All pairsFloyd-WarshallO(V^3)
DAGTopological + DPO(V+E)

MST

ScenarioAlgorithmComplexity
Sparse graphKruskalO(E log E)
Dense graphPrimO(V^2) or O(E log V)

Input Schema

{
  "type": "object",
  "properties": {
    "problemType": {
      "type": "string",
      "enum": ["shortestPath", "mst", "connectivity", "flow", "matching", "traversal"]
    },
    "graphProperties": { "type": "object" },
    "constraints": {
      "type": "object",
      "properties": {
        "V": { "type": "integer" },
        "E": { "type": "integer" },
        "negativeWeights": { "type": "boolean" },
        "negativeCycles": { "type": "boolean" }
      }
    }
  },
  "required": ["problemType", "constraints"]
}

Output Schema

{
  "type": "object",
  "properties": {
    "success": { "type": "boolean" },
    "recommendedAlgorithm": { "type": "string" },
    "complexity": { "type": "string" },
    "alternatives": { "type": "array" },
    "reasoning": { "type": "string" }
  },
  "required": ["success", "recommendedAlgorithm"]
}

Source

git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/algorithms-optimization/skills/graph-algorithm-selector/SKILL.mdView on GitHub

Overview

Graph Algorithm Selector automatically chooses the most suitable algorithm based on problem type, graph properties, and performance needs. It analyzes constraints such as V, E, negative weights, and negative cycles, detects sparse vs dense graphs, and suggests variants and optimizations.

How This Skill Works

Users provide the problemType (shortestPath, mst, etc.) and a constraints object. The selector maps these inputs to the decision matrix described in the skill, selecting among BFS, Dijkstra, Bellman-Ford, Floyd-Warshall, Topological+DP, Kruskal, and Prim based on the scenario, then outputs the recommendedAlgorithm, its complexity, alternatives, and a concise reasoning.

When to Use It

  • You need a shortest path in an unweighted graph.
  • You have non-negative edge weights and want efficient performance.
  • The graph may have negative weights; check for negative cycles and decide if Bellman-Ford is appropriate.
  • You require all-pairs shortest paths or you're working with a DAG and can use DP.
  • You're selecting an MST and must decide between Kruskal for sparse graphs and Prim for dense graphs.

Quick Start

  1. Step 1: Provide problemType (e.g., shortestPath or mst) and constraints (V, E, negativeWeights, negativeCycles) per the Input Schema.
  2. Step 2: Run the Graph Algorithm Selector with those inputs.
  3. Step 3: Review the output: recommendedAlgorithm, complexity, alternatives, and reasoning, then implement.

Best Practices

  • Define problemType up front (shortestPath, mst, etc.) and collect V, E, and weight properties before running the selector.
  • Use the constraint indicators (negativeWeights, negativeCycles) to filter algorithm options.
  • Consider graph density to favor Kruskal (sparse) or Prim (dense) for MST.
  • Leverage the provided complexity mappings to estimate runtime budgets.
  • Review alternatives and potential optimizations (e.g., adjacency lists, heap optimizations).

Example Use Cases

  • Shortest path in an unweighted road network: BFS with O(V+E) complexity.
  • Non-negative weighted routing: Dijkstra with a min-heap, O((V+E) log V).
  • Graph with potential negative weights but no negative cycles: Bellman-Ford for single-source paths, O(VE).
  • All-pairs shortest paths in a dense graph: Floyd-Warshall, O(V^3).
  • MST selection: Kruskal for sparse graphs (O(E log E)) or Prim for dense graphs (O(V^2) or O(E log V)).

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers