summaryrefslogtreecommitdiff
path: root/graph-checker/src/main.rs
blob: 646cca00f1204254e78a779e8945b26d34cca188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// use std::io::{self, BufRead};
use std::time::Instant;

mod graph;
use crate::graph::Graph;

mod theorems;
use crate::theorems::{basic, forbidden, toughness};

mod geng;
use crate::geng::GengIterator;

struct Counters {
    graphs: i32,
    tough_1: i32,
    tough_2: i32,
    bch_hamiltonian: i32,
    t15_hamiltonian: i32,
    t25_hamiltonian: i32,
    dirac_hamiltonian: i32,
    ore_hamiltonian: i32,
    posa_hamiltonian: i32,
    t3_1: i32,
    t3_2: i32,
    c3_5: i32,
    t85: i32,
    t86: i32,
    t87: i32,
    t88: i32,
    t96: i32,
    conj17: i32,
    all_2c: i32,
}

impl Counters {
    fn new() -> Counters {
        return Counters {
            graphs: 0,
            tough_1: 0,
            tough_2: 0,
            bch_hamiltonian: 0,
            t15_hamiltonian: 0,
            t25_hamiltonian: 0,
            dirac_hamiltonian: 0,
            ore_hamiltonian: 0,
            posa_hamiltonian: 0,
            t3_1: 0,
            t3_2: 0,
            c3_5: 0,
            t85: 0,
            t86: 0,
            t87: 0,
            t88: 0,
            t96: 0,
            conj17: 0,
            all_2c: 0,
        };
    }
}

fn main() {
    let gi = GengIterator::new(4);

    let mut time = 0;
    let mut counters = Counters::new();

    for g in &gi {
        counters.graphs += 1;
        let line = g.to_g6();

        let start = Instant::now();
        let closure = g.get_closure();
        let is_complete = closure.is_complete();

        let toughness = if g.is_complete() {
            f64::MAX
        } else {
            g.get_toughness()
        };

        if toughness >= 1.0 {
            counters.tough_1 += 1;
        }
        if toughness >= 2.0 {
            counters.tough_2 += 1;
        }
        let min_degree = g.min_degree() as f64;

        if forbidden::theorem3_1(&g) {
            counters.t3_1 += 1;
            println!("g6:t3_1:{}", line);
        }

        if forbidden::theorem3_2(&g) {
            counters.t3_2 += 1;
            println!("g6:t3_2:{}", line);
        }

        if forbidden::corollary3_5(&g) {
            counters.c3_5 += 1;
            println!("g6:c3_5:{}", line);
        }
        if forbidden::theorem85(&g) {
            counters.t85 += 1;
            println!("g6:t85:{}", line);
        }
        if forbidden::theorem86(&g) {
            counters.t86 += 1;
            println!("g6:t86:{}", line);
        }
        if forbidden::theorem87(&g) {
            counters.t87 += 1;
            println!("g6:t87:{}", line);
        }
        if forbidden::theorem88(&g) {
            counters.t88 += 1;
            println!("g6:t88:{}", line);
        }
        if forbidden::theorem96(&g) {
            counters.t96 += 1;
            println!("g6:t96:{}", line);
        }
        if forbidden::conjecture17(&g) {
            counters.conj17 += 1;
            println!("g6:conj17:{}", line);
        }
        if forbidden::theorem_all_2con(&g) {
            counters.all_2c += 1;
            println!("g6:all_2c:{}", line);
        }
        if toughness::theorem15(&g, toughness, min_degree) {
            counters.t15_hamiltonian += 1;
            println!("g6:bigalke-jung:{}", line);
        }
        if toughness::theorem25(&g, toughness, min_degree) {
            counters.t25_hamiltonian += 1;
            println!("g6:bauer:{}", line);
        }
        if basic::dirac_theorem(&g) {
            counters.dirac_hamiltonian += 1;
            println!("g6:dirac:{}", line);
        }
        if basic::ore_theorem(&g) {
            counters.ore_hamiltonian += 1;
            println!("g6:ore:{}", line);
        }
        if basic::posa_theorem(&g) {
            counters.posa_hamiltonian += 1;
            println!("g6:posa:{}", line);
        }
        if is_complete {
            counters.bch_hamiltonian += 1;
            println!("g6:bondy-chvatal:{}", line);
        }

        if is_complete && false {
            println!("Graph: {line}\n{g}");

            let components_count = g.count_components();
            println!("Components count: {components_count}");
            let min_degree = g.min_degree();
            println!("Minimal degree: {min_degree}");

            let cutset = g.max_independent_cutset();
            println!("Maximal independent cutset:\n{}", cutset.graph);
            println!("Included vertices: {:?}", cutset.vertices);
            println!("Cutset cardinality: {}", cutset.cardinality);

            let cycle = basic::bondy_chvatal_hamiltonian_cycle(&g);
            print!("Hamiltonian cycle: ");
            let start = 0;
            let mut current = start;
            loop {
                print!("{}", current + 1);
                print!(" -> ");
                current = cycle[current];
                if current == start {
                    println!("{}", current + 1);
                    break;
                }
            }
        }

        let elapsed = start.elapsed();
        time += elapsed.as_nanos();
    }

    println!("Total count of graphs: {}", counters.graphs);
    println!("Count of 1-tough graphs: {}", counters.tough_1);
    println!("Count of 2-tough graphs: {}", counters.tough_2);
    println!(
        "Count of Dirac's Hamiltonian graphs: {}",
        counters.dirac_hamiltonian
    );
    println!(
        "Count of Ore's Hamiltonian graphs: {}",
        counters.ore_hamiltonian
    );
    println!(
        "Count of Posa's Hamiltonian graphs: {}",
        counters.posa_hamiltonian
    );
    println!(
        "Count of Bondy-Chvatal Hamiltonian graphs: {}",
        counters.bch_hamiltonian
    );
    println!(
        "Count of Theorem 15 Hamiltonian graphs: {}",
        counters.t15_hamiltonian
    );
    println!(
        "Count of Theorem 25 Hamiltonian graphs: {}",
        counters.t25_hamiltonian
    );
    println!("Time elapsed: {}s", time as f64 / 1e9);
}