|
| 1 | +# GraphBox |
| 2 | + |
| 3 | +**GraphBox** = Graph Sandbox + Graph Toolbox |
| 4 | + |
| 5 | +Abstract and experimental graph algorithms for academic research. The name reflects its dual purpose: |
| 6 | + |
| 7 | +- **Sandbox** — A space for experimenting with graph algorithms, data structures, and traversal strategies |
| 8 | +- **Toolbox** — A collection of reusable, well-tested graph utilities for production use |
| 9 | + |
| 10 | +GraphBox provides a toolkit for graph manipulation, analysis, and generation, specifically designed for academic research in graph theory, network science, and citation analysis. |
| 11 | + |
| 12 | +## Overview |
| 13 | + |
| 14 | +Graph-Box consolidates three previously separate BibGraph packages into a single, focused package: |
| 15 | + |
| 16 | +- **graph-core**: Core graph interfaces and adapters |
| 17 | +- **graph-expansion**: Graph expansion, traversal algorithms, and neighborhood exploration |
| 18 | +- **graph-gen**: Graph specification, generation, and validation system |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +```bash |
| 23 | +pnpm install graph-box |
| 24 | +``` |
| 25 | + |
| 26 | +## Key Features |
| 27 | + |
| 28 | +### Graph Adapters |
| 29 | + |
| 30 | +`GraphAdapter` provides a bridge between different graph implementations, allowing you to use generic algorithms with your specific graph data structures. |
| 31 | + |
| 32 | +```typescript |
| 33 | +import { GraphAdapter } from 'graph-box'; |
| 34 | + |
| 35 | +const adapter = new GraphAdapter(graph); |
| 36 | +``` |
| 37 | + |
| 38 | +### Graph Traversal |
| 39 | + |
| 40 | +Multiple traversal algorithms for exploring graph neighborhoods: |
| 41 | + |
| 42 | +- **BFS** - Breadth-first search |
| 43 | +- **DFS** - Depth-first search |
| 44 | +- **Bidirectional BFS** - Optimized bidirectional search |
| 45 | +- **Degree-Prioritized** - Expansion based on node degree |
| 46 | +- **Priority Queue** - Custom priority-based expansion |
| 47 | + |
| 48 | +```typescript |
| 49 | +import { bfs, dfs, extractEgoNetwork } from 'graph-box'; |
| 50 | + |
| 51 | +const bfsResult = bfs(adapter, 'startNodeId'); |
| 52 | +const dfsResult = dfs(adapter, 'startNodeId'); |
| 53 | +``` |
| 54 | + |
| 55 | +### Graph Extraction |
| 56 | + |
| 57 | +Extract ego networks and multi-source neighborhoods: |
| 58 | + |
| 59 | +```typescript |
| 60 | +const egoNetwork = extractEgoNetwork(adapter, { |
| 61 | + radius: 2, |
| 62 | + seedNodes: ['nodeId'], |
| 63 | +}); |
| 64 | +``` |
| 65 | + |
| 66 | +### Graph Generation |
| 67 | + |
| 68 | +Type-safe graph generation with mathematical constraint validation: |
| 69 | + |
| 70 | +```typescript |
| 71 | +import { generateGraph, validateGraph } from 'graph-box'; |
| 72 | + |
| 73 | +const spec = { |
| 74 | + type: 'complete', |
| 75 | + nodeCount: 100, |
| 76 | + edgeDensity: 0.1, |
| 77 | + constraints: { |
| 78 | + minDegree: 2, |
| 79 | + maxDegree: 10, |
| 80 | + connected: true |
| 81 | + } |
| 82 | +}; |
| 83 | + |
| 84 | +const graph = generateGraph(spec); |
| 85 | +const valid = validateGraph(graph, spec.constraints); |
| 86 | +``` |
| 87 | + |
| 88 | +### Graph Validation |
| 89 | + |
| 90 | +Mathematical constraint validation for graph properties: |
| 91 | + |
| 92 | +```typescript |
| 93 | +import { validateGraph, checkConstraints } from 'graph-box'; |
| 94 | + |
| 95 | +const isValid = validateGraph(graph, constraints); |
| 96 | +``` |
| 97 | + |
| 98 | +## Usage Examples |
| 99 | + |
| 100 | +### Basic Traversal |
| 101 | + |
| 102 | +```typescript |
| 103 | +import { GraphAdapter, bfs } from 'graph-box'; |
| 104 | + |
| 105 | +const graph = { /* your graph */ }; |
| 106 | +const adapter = new GraphAdapter(graph); |
| 107 | + |
| 108 | +const result = bfs(adapter, 'startNodeId'); |
| 109 | +console.log(result.visited); // Array of visited node IDs |
| 110 | +``` |
| 111 | + |
| 112 | +### Ego Network Extraction |
| 113 | + |
| 114 | +```typescript |
| 115 | +import { extractEgoNetwork } from 'graph-box'; |
| 116 | + |
| 117 | +const adapter = new GraphAdapter(graph); |
| 118 | + |
| 119 | +const egoNetwork = extractEgoNetwork(adapter, { |
| 120 | + radius: 2, |
| 121 | + seedNodes: ['author123'], |
| 122 | + includeEdgeWeights: true |
| 123 | +}); |
| 124 | + |
| 125 | +console.log(egoNetwork); |
| 126 | +``` |
| 127 | + |
| 128 | +### Graph Generation |
| 129 | + |
| 130 | +```typescript |
| 131 | +import { generateGraph, GraphSpec } from 'graph-box'; |
| 132 | + |
| 133 | +const spec: GraphSpec = { |
| 134 | + type: 'complete', |
| 135 | + nodeCount: 50, |
| 136 | + edgeDensity: 0.15 |
| 137 | +}; |
| 138 | + |
| 139 | +const graph = generateGraph(spec); |
| 140 | +``` |
| 141 | + |
| 142 | +### Graph Validation |
| 143 | + |
| 144 | +```typescript |
| 145 | +import { validateGraph } from 'graph-box'; |
| 146 | + |
| 147 | +const graph = { /* graph object */ }; |
| 148 | +const isValid = validateGraph(graph); |
| 149 | +``` |
| 150 | + |
| 151 | +## API Reference |
| 152 | + |
| 153 | +### Core Classes |
| 154 | + |
| 155 | +- **GraphAdapter** - Adapter pattern for graph abstraction |
| 156 | +- **GraphExpander** - Interface for dynamic graph expansion |
| 157 | +- **PriorityQueue** - Priority queue for degree-based expansion |
| 158 | + |
| 159 | +### Traversal Algorithms |
| 160 | + |
| 161 | +- **bfs(adapter, startNodeId, options?)** - Breadth-first search |
| 162 | +- **dfs(adapter, startNodeId, options?)** - Depth-first search |
| 163 | +- **BidirectionalBFS** - Bidirectional BFS search |
| 164 | + |
| 165 | +### Extraction Methods |
| 166 | + |
| 167 | +- **extractEgoNetwork(adapter, options)** - Extract ego-centered subgraph |
| 168 | +- **extractMultiSourceEgoNetwork(adapter, options)** - Multi-source extraction |
| 169 | + |
| 170 | +### Generation Functions |
| 171 | + |
| 172 | +- **generateGraph(spec)** - Generate graph from specification |
| 173 | +- **validateGraph(graph, constraints)** - Validate graph against constraints |
| 174 | + |
| 175 | +## Contributing |
| 176 | + |
| 177 | +This package is part of academic research work. Contributions are welcome, please open an issue first. |
| 178 | + |
| 179 | +## License |
| 180 | + |
| 181 | +MIT |
| 182 | + |
| 183 | +## Author |
| 184 | + |
| 185 | +Joe Mearman |
| 186 | + |
| 187 | +## Related Projects |
| 188 | + |
| 189 | +- **BibGraph**: Main BibGraph monorepo |
| 190 | +- **algorithms**: Graph algorithms package for BibGraph |
| 191 | +- **types**: Shared TypeScript types for BibGraph |
0 commit comments