名称: 图算法选择器 描述: 根据问题约束选择最优图算法 允许工具:
- 读取
- 写入
- 搜索
- 全局匹配
图算法选择器技能
目的
根据问题约束、图属性和性能要求选择最优图算法。
能力
- 算法选择的约束分析
- 权衡分析(Dijkstra vs Bellman-Ford vs Floyd-Warshall)
- 特殊情况检测(稀疏 vs 稠密,负权边)
- 算法复杂度与约束的映射
- 推荐算法变体和优化方案
目标流程
- 最短路径算法
- 高级图算法
- 图遍历
- 图建模
算法选择矩阵
最短路径
| 场景 | 算法 | 复杂度 |
|---|---|---|
| 无权图 | 广度优先搜索 | O(V+E) |
| 非负权重 | Dijkstra | O((V+E)log V) |
| 负权重 | Bellman-Ford | O(VE) |
| 所有节点对 | Floyd-Warshall | O(V^3) |
| 有向无环图 | 拓扑排序 + 动态规划 | O(V+E) |
最小生成树
| 场景 | 算法 | 复杂度 |
|---|---|---|
| 稀疏图 | Kruskal | O(E log E) |
| 稠密图 | Prim | O(V^2) 或 O(E log V) |
输入模式
{
"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"]
}
输出模式
{
"type": "object",
"properties": {
"success": { "type": "boolean" },
"recommendedAlgorithm": { "type": "string" },
"complexity": { "type": "string" },
"alternatives": { "type": "array" },
"reasoning": { "type": "string" }
},
"required": ["success", "recommendedAlgorithm"]
}