Skip to content

Commit 75b6b0a

Browse files
committed
refactor(algorithms): split spec.ts into modular structure
Break monolithic spec.ts (1,149 lines) into 12 focused modules: - spec/core.ts: Core properties (Directionality, Weighting, Cycles, etc.) - spec/advanced.ts: Advanced properties (VertexCardinality, Embedding, etc.) - spec/network.ts: Network analysis (ScaleFree, SmallWorld, Community) - spec/geometric.ts: Geometric properties (UnitDisk, Planarity) - spec/path-cycle.ts: Path and cycle properties (Hamiltonian, Traceable) - spec/structural.ts: Structural classes (Perfect, Split, Cograph, etc.) - spec/regularity.ts: Regularity properties (Cubic, k-regular) - spec/symmetry.ts: Symmetry properties (SelfComplementary, etc.) - spec/metrics.ts: Metric properties (Diameter, Radius, Girth, etc.) - spec/invariants.ts: Graph invariants and spectral properties - spec/products.ts: Graph products and related structures (254 lines) - spec/index.ts: Barrel file for clean re-exports Main spec.ts reduced to 723 lines (37% reduction). Preserves all types and maintains backward compatibility. All 504 tests passing in algorithms package.
1 parent 0d8a38a commit 75b6b0a

File tree

13 files changed

+1057
-641
lines changed

13 files changed

+1057
-641
lines changed

packages/graph-gen/src/spec.ts

Lines changed: 216 additions & 641 deletions
Large diffs are not rendered by default.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
* Advanced Graph Properties
3+
*
4+
* Extended property axes for future graph generation capabilities.
5+
*/
6+
7+
// ============================================================================
8+
// ADVANCED PROPERTY AXES (future extension)
9+
// ============================================================================
10+
11+
/** Vertex set cardinality */
12+
export type VertexCardinality =
13+
| { kind: "finite"; n?: number }
14+
| { kind: "countably_infinite" }
15+
| { kind: "uncountably_infinite" };
16+
17+
/** Vertex identity */
18+
export type VertexIdentity =
19+
| { kind: "distinguishable" }
20+
| { kind: "indistinguishable" };
21+
22+
/** Vertex ordering */
23+
export type VertexOrdering =
24+
| { kind: "unordered" }
25+
| { kind: "total_order" }
26+
| { kind: "partial_order" };
27+
28+
/** Edge arity (binary vs hypergraph) */
29+
export type EdgeArity =
30+
| { kind: "binary" }
31+
| { kind: "k_ary"; k: number };
32+
33+
/** Edge signedness */
34+
export type Signedness =
35+
| { kind: "unsigned" }
36+
| { kind: "signed" }
37+
| { kind: "multi_signed" };
38+
39+
/** Edge uncertainty */
40+
export type Uncertainty =
41+
| { kind: "deterministic" }
42+
| { kind: "probabilistic" }
43+
| { kind: "fuzzy" };
44+
45+
/** Vertex metadata */
46+
export type VertexData =
47+
| { kind: "unlabelled" }
48+
| { kind: "labelled" }
49+
| { kind: "attributed" };
50+
51+
/** Edge metadata */
52+
export type EdgeData =
53+
| { kind: "unlabelled" }
54+
| { kind: "labelled" }
55+
| { kind: "attributed" };
56+
57+
/** Degree constraints */
58+
export type DegreeConstraint =
59+
| { kind: "unconstrained" }
60+
| { kind: "bounded"; max: number }
61+
| { kind: "regular"; degree: number }
62+
| { kind: "degree_sequence"; sequence: readonly number[] };
63+
64+
/** Partiteness (bipartite, k-partite) */
65+
export type Partiteness =
66+
| { kind: "unrestricted" }
67+
| { kind: "bipartite" }
68+
| { kind: "k_partite"; k: number };
69+
70+
/** Graph embedding */
71+
export type Embedding =
72+
| { kind: "abstract" }
73+
| { kind: "planar" }
74+
| { kind: "surface_embedded" }
75+
| { kind: "geometric_metric_space" }
76+
| { kind: "spatial_coordinates"; dims: 2 | 3 };
77+
78+
/** Tree rooting */
79+
export type Rooting =
80+
| { kind: "unrooted" }
81+
| { kind: "rooted" }
82+
| { kind: "multi_rooted" };
83+
84+
/** Temporal properties */
85+
export type Temporal =
86+
| { kind: "static" }
87+
| { kind: "dynamic_structure" }
88+
| { kind: "temporal_edges" }
89+
| { kind: "temporal_vertices" }
90+
| { kind: "time_ordered" };
91+
92+
/** Layering (multiplex networks, etc.) */
93+
export type Layering =
94+
| { kind: "single_layer" }
95+
| { kind: "multi_layer" }
96+
| { kind: "multiplex" }
97+
| { kind: "interdependent" };
98+
99+
/** Edge ordering */
100+
export type EdgeOrdering =
101+
| { kind: "unordered" }
102+
| { kind: "ordered" };
103+
104+
/** Port specification */
105+
export type Ports =
106+
| { kind: "none" }
107+
| { kind: "port_labelled_vertices" };
108+
109+
/** Observability */
110+
export type Observability =
111+
| { kind: "fully_specified" }
112+
| { kind: "partially_observed" }
113+
| { kind: "latent_or_inferred" };
114+
115+
/** Operational semantics */
116+
export type OperationalSemantics =
117+
| { kind: "structural_only" }
118+
| { kind: "annotated_with_functions" }
119+
| { kind: "executable" };
120+
121+
/** Measure semantics (cost, utility, etc.) */
122+
export type MeasureSemantics =
123+
| { kind: "none" }
124+
| { kind: "metric" }
125+
| { kind: "cost" }
126+
| { kind: "utility" };
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Core Graph Properties
3+
*
4+
* Fundamental property axes used in current test fixtures.
5+
*/
6+
7+
// ============================================================================
8+
// CORE PROPERTY AXES (used in current test fixtures)
9+
// ============================================================================
10+
11+
/** Edge direction property */
12+
export type Directionality =
13+
| { kind: "directed" }
14+
| { kind: "undirected" };
15+
16+
/** Edge weighting property */
17+
export type Weighting =
18+
| { kind: "unweighted" }
19+
| { kind: "weighted_numeric" }; // TODO: extend to weighted_vector, valued_symbolic
20+
21+
/** Cycle presence property */
22+
export type Cycles =
23+
| { kind: "acyclic" }
24+
| { kind: "cycles_allowed" };
25+
26+
/** Connectivity property */
27+
export type Connectivity =
28+
| { kind: "connected" }
29+
| { kind: "unconstrained" }; // "disconnected" in our old system
30+
31+
/** Node/edge type diversity property */
32+
export type SchemaHomogeneity =
33+
| { kind: "homogeneous" }
34+
| { kind: "heterogeneous" };
35+
36+
/** Multiple edges between same vertices property */
37+
export type EdgeMultiplicity =
38+
| { kind: "simple" }
39+
| { kind: "multi" };
40+
41+
/** Self-loop permission property */
42+
export type SelfLoops =
43+
| { kind: "allowed" }
44+
| { kind: "disallowed" };
45+
46+
/** Target density for graph generation */
47+
export type Density =
48+
| { kind: "sparse" } // ~15% of max edges
49+
| { kind: "moderate" } // ~40% of max edges
50+
| { kind: "dense" } // ~70% of max edges
51+
| { kind: "unconstrained" };
52+
53+
/** Graph completeness property */
54+
export type Completeness =
55+
| { kind: "complete" }
56+
| { kind: "incomplete" };
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Geometric and Topological Properties
3+
*
4+
* Properties related to geometric constraints and planarity.
5+
*/
6+
7+
// ============================================================================
8+
// GEOMETRIC AND TOPOLOGICAL PROPERTIES (Unit disk, planar)
9+
// ============================================================================
10+
11+
/** Unit disk graph property (geometric constraint) */
12+
export type UnitDisk =
13+
| { kind: "unit_disk"; unitRadius?: number; spaceSize?: number }
14+
| { kind: "not_unit_disk" }
15+
| { kind: "unconstrained" };
16+
17+
/** Planar graph property (K5/K3,3-free) */
18+
export type Planarity =
19+
| { kind: "planar" }
20+
| { kind: "non_planar" }
21+
| { kind: "unconstrained" };
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/**
2+
* Graph Specification System
3+
*
4+
* Atomic graph-type properties using discriminated unions for type-safe composition.
5+
* Each property is a disjoint union with a `kind` discriminator for exhaustiveness checking.
6+
*
7+
* This module re-exports all property types for convenient importing.
8+
*/
9+
10+
// Core properties
11+
export type {
12+
Directionality,
13+
Weighting,
14+
Cycles,
15+
Connectivity,
16+
SchemaHomogeneity,
17+
EdgeMultiplicity,
18+
SelfLoops,
19+
Density,
20+
Completeness,
21+
} from "./core.js";
22+
23+
// Advanced properties
24+
export type {
25+
VertexCardinality,
26+
VertexIdentity,
27+
VertexOrdering,
28+
EdgeArity,
29+
Signedness,
30+
Uncertainty,
31+
VertexData,
32+
EdgeData,
33+
DegreeConstraint,
34+
Partiteness,
35+
Embedding,
36+
Rooting,
37+
Temporal,
38+
Layering,
39+
EdgeOrdering,
40+
Ports,
41+
Observability,
42+
OperationalSemantics,
43+
MeasureSemantics,
44+
} from "./advanced.js";
45+
46+
// Network analysis properties
47+
export type {
48+
ScaleFree,
49+
SmallWorld,
50+
CommunityStructure,
51+
} from "./network.js";
52+
53+
// Geometric properties
54+
export type {
55+
UnitDisk,
56+
Planarity,
57+
} from "./geometric.js";
58+
59+
// Path and cycle properties
60+
export type {
61+
Hamiltonian,
62+
Traceable,
63+
} from "./path-cycle.js";
64+
65+
// Structural classes
66+
export type {
67+
Perfect,
68+
Split,
69+
Cograph,
70+
Threshold,
71+
Line,
72+
ClawFree,
73+
} from "./structural.js";
74+
75+
// Regularity properties
76+
export type {
77+
Cubic,
78+
SpecificRegular,
79+
StronglyRegular,
80+
} from "./regularity.js";
81+
82+
// Symmetry properties
83+
export type {
84+
SelfComplementary,
85+
VertexTransitive,
86+
EdgeTransitive,
87+
ArcTransitive,
88+
} from "./symmetry.js";
89+
90+
// Metric properties
91+
export type {
92+
Diameter,
93+
Radius,
94+
Girth,
95+
Circumference,
96+
} from "./metrics.js";
97+
98+
// Invariants and spectral properties
99+
export type {
100+
HereditaryClass,
101+
IndependenceNumber,
102+
VertexCover,
103+
DominationNumber,
104+
Spectrum,
105+
AlgebraicConnectivity,
106+
SpectralRadius,
107+
} from "./invariants.js";
108+
109+
// Graph products and related structures
110+
export type {
111+
Toughness,
112+
Integrity,
113+
Cage,
114+
MooreGraph,
115+
Ramanujan,
116+
CartesianProduct,
117+
TensorProduct,
118+
StrongProduct,
119+
LexicographicProduct,
120+
MinorFree,
121+
TopologicalMinorFree,
122+
CompleteBipartite,
123+
Eulerian,
124+
KVertexConnected,
125+
KEdgeConnected,
126+
Wheel,
127+
Grid,
128+
Toroidal,
129+
Star,
130+
Comparability,
131+
Interval,
132+
Permutation,
133+
Chordal,
134+
PerfectMatching,
135+
KColorable,
136+
ChromaticNumber,
137+
Treewidth,
138+
Branchwidth,
139+
FlowNetwork,
140+
BinaryTree,
141+
SpanningTree,
142+
Tournament,
143+
} from "./products.js";

0 commit comments

Comments
 (0)