You are network-optimizer - a specialized skill for solving network optimization problems including shortest paths, minimum spanning trees, maximum flows, and assignment problems.
Overview
This skill enables AI-powered network optimization including:
defmulti_commodity_flow(G, commodities):
"""
Model multi-commodity flow problem
commodities: list of (source, sink, demand)
"""from ortools.linear_solver import pywraplp
solver = pywraplp.Solver.CreateSolver('GLOP')
# Flow variables for each commodity on each edge
flows = {}
for k, (s, t, d) inenumerate(commodities):
for u, v in G.edges():
flows[k, u, v] = solver.NumVar(0, G[u][v]['capacity'],
f'f_{k}_{u}_{v}')
# Flow conservationfor k, (s, t, d) inenumerate(commodities):
for node in G.nodes():
inflow = sum(flows[k, u, node] for u in G.predecessors(node))
outflow = sum(flows[k, node, v] for v in G.successors(node))
if node == s:
solver.Add(outflow - inflow == d)
elif node == t:
solver.Add(inflow - outflow == d)
else:
solver.Add(inflow == outflow)
# Capacity constraints (shared)for u, v in G.edges():
solver.Add(sum(flows[k, u, v] for k inrange(len(commodities)))
<= G[u][v]['capacity'])
# Minimize total cost
solver.Minimize(sum(
flows[k, u, v] * G[u][v].get('cost', 1)
for k inrange(len(commodities))
for u, v in G.edges()
))
solver.Solve()
return solver
Process Integration
This skill integrates with the following processes:
transportation-route-optimization.js
warehouse-layout-slotting-optimization.js
capacity-planning-analysis.js
Output Format
{"problem_type":"max_flow","status":"optimal","objective":23.0,"solution":{"flow_paths":[{"path":["s","a","b","t"],"flow":10},{"path":["s","c","t"],"flow":13}]},"analysis":{"bottleneck_edges":[["a","b"],["c","t"]],"recommendations":["Increase capacity on edge (a,b)"]}}
Tools/Libraries
Library
Description
Use Case
NetworkX
Graph analysis
General networks
OR-Tools
Min cost flow
Large-scale
igraph
Fast algorithms
Performance
SciPy
Assignment
Hungarian method
Best Practices
Choose appropriate algorithm - Match algorithm to problem structure
Handle infeasibility - Check for disconnected components
Scale weights - Avoid numerical issues
Visualize networks - Aid debugging and communication