Add independent set verification

This commit is contained in:
hal8174 2025-01-22 23:05:45 +01:00
parent 394e14cef4
commit 2f8aa9d2c6
6 changed files with 51 additions and 25 deletions

View file

@ -352,8 +352,8 @@
1055
1060
1061
1066
1067
1068
1073
1074
1079

View file

@ -4,9 +4,9 @@
6
9
11
13
19
14
17
23
26
30
35
25
31
36

View file

@ -396,7 +396,7 @@
510
511
512
519
520
521
522
523

View file

@ -7366,7 +7366,7 @@
17273
17274
17276
17278
17277
17279
17280
17282
@ -7387,7 +7387,7 @@
17311
17312
17314
17316
17315
17317
17319
17320
@ -7399,7 +7399,7 @@
17330
17332
17333
17336
17335
17337
17341
17342
@ -7412,7 +7412,7 @@
17356
17357
17359
17361
17360
17362
17364
17365
@ -7425,11 +7425,11 @@
17376
17378
17379
17382
17381
17383
17387
17388
17391
17390
17392
17393
17395
@ -7444,7 +7444,7 @@
17411
17412
17414
17416
17415
17417
17418
17420
@ -7453,11 +7453,11 @@
17425
17427
17429
17431
17432
17433
17435
17436
17438
17439
17440
17441
17442
@ -7473,7 +7473,7 @@
17460
17461
17463
17464
17465
17466
17467
17468
@ -7495,12 +7495,12 @@
17499
17500
17502
17503
17504
17505
17507
17508
17510
17512
17511
17513
17514
17516
@ -7534,11 +7534,11 @@
17566
17568
17570
17572
17573
17574
17576
17577
17579
17580
17581
17582
17583

View file

@ -1,22 +1,22 @@
35
43
58
82
93
133
134
151
154
172
187
191
204
205
226
227
230
275
277
287
290
297
300
341
345
346

View file

@ -9,6 +9,8 @@ use std::{
#[derive(Parser)]
struct Args {
filename: PathBuf,
#[arg(short, long)]
verify: bool,
}
type NodeType = u16;
@ -213,6 +215,26 @@ impl IndependentSet {
}
}
fn verify_independent_set<'a>(
set: impl IntoIterator<Item = &'a NodeType>,
td: &Baumzerlegung,
) -> bool {
let mut visited = HashSet::new();
for &v in set {
visited.insert(v);
if let Some(w_edges) = td.edges.get(&v) {
for &w in w_edges {
if visited.contains(&w) {
return false;
}
}
}
}
true
}
fn main() {
let mut args = Args::parse();
args.filename.set_extension("");
@ -227,8 +249,12 @@ fn main() {
let mut s = s.solution().iter().copied().collect::<Vec<_>>();
if args.verify {
assert!(verify_independent_set(&s, &td));
}
s.sort();
println!("{}", s.len());
for i in s {
let _ = writeln!(bf, "{i}");
}