Skip to content

Commit f0775bf

Browse files
committed
fix: correct mcs algorithm to check earlier neighbors in chordal detection
the maximum cardinality search algorithm for chordal graph detection was incorrectly checking if "later" neighbors form a clique, when it should check "earlier" neighbors (vertices appearing before the current vertex in the elimination ordering). this fix ensures trees and other chordal graphs are correctly identified by the isChordalUndirectedBinary predicate.
1 parent 9af83ae commit f0775bf

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/analyzer/predicates.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,25 @@ const isChordalUndirectedBinary = (g: AnalyzerGraph): boolean => {
189189
}
190190

191191
// Check if this is a perfect elimination ordering
192-
// For each vertex, its later neighbors should form a clique
193-
const laterNeighbors = new Map<AnalyzerVertexId, Set<AnalyzerVertexId>>();
192+
// For MCS, we check that for each vertex, its earlier neighbors form a clique
193+
const earlierNeighbors = new Map<AnalyzerVertexId, Set<AnalyzerVertexId>>();
194194

195195
for (let index = 0; index < order.length; index++) {
196196
const v = order[index];
197-
const laterNbs = new Set<AnalyzerVertexId>();
197+
const earlierNbs = new Set<AnalyzerVertexId>();
198198

199-
// Find neighbors that appear later in ordering
199+
// Find neighbors that appear earlier in ordering
200200
for (const nb of adj[v] ?? []) {
201201
const index_ = order.indexOf(nb);
202-
if (index_ > index) laterNbs.add(nb);
202+
if (index_ < index) earlierNbs.add(nb);
203203
}
204204

205-
laterNeighbors.set(v, laterNbs);
205+
earlierNeighbors.set(v, earlierNbs);
206206
}
207207

208-
// Check each set of later neighbors forms a clique
209-
for (const [, laterNbs] of laterNeighbors) {
210-
const nbs = [...laterNbs];
208+
// Check each set of earlier neighbors forms a clique
209+
for (const [, earlierNbs] of earlierNeighbors) {
210+
const nbs = [...earlierNbs];
211211
for (let index = 0; index < nbs.length; index++) {
212212
for (let index_ = index + 1; index_ < nbs.length; index_++) {
213213
// Check if nbs[i] and nbs[j] are adjacent

src/analyzer/types.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,25 +236,25 @@ export const isChordalUndirectedBinary = (g: AnalyzerGraph): boolean => {
236236
}
237237

238238
// Check if this is a perfect elimination ordering
239-
// For each vertex, its later neighbors should form a clique
240-
const laterNeighbors = new Map<AnalyzerVertexId, Set<AnalyzerVertexId>>();
239+
// For MCS, we check that for each vertex, its earlier neighbors form a clique
240+
const earlierNeighbors = new Map<AnalyzerVertexId, Set<AnalyzerVertexId>>();
241241

242242
for (let index = 0; index < order.length; index++) {
243243
const v = order[index];
244-
const laterNbs = new Set<AnalyzerVertexId>();
244+
const earlierNbs = new Set<AnalyzerVertexId>();
245245

246-
// Find neighbors that appear later in ordering
246+
// Find neighbors that appear earlier in ordering
247247
for (const nb of adj[v] ?? []) {
248248
const index_ = order.indexOf(nb);
249-
if (index_ > index) laterNbs.add(nb);
249+
if (index_ < index) earlierNbs.add(nb);
250250
}
251251

252-
laterNeighbors.set(v, laterNbs);
252+
earlierNeighbors.set(v, earlierNbs);
253253
}
254254

255-
// Check each set of later neighbors forms a clique
256-
for (const [, laterNbs] of laterNeighbors) {
257-
const nbs = [...laterNbs];
255+
// Check each set of earlier neighbors forms a clique
256+
for (const [, earlierNbs] of earlierNeighbors) {
257+
const nbs = [...earlierNbs];
258258
for (let index = 0; index < nbs.length; index++) {
259259
for (let index_ = index + 1; index_ < nbs.length; index_++) {
260260
// Check if nbs[i] and nbs[j] are adjacent

0 commit comments

Comments
 (0)