use crate::graph::graph::Graph;
use crate::graph::undirected::edge::UndirectedEdge;
use crate::service::colour::colouriser::Colouriser;
use crate::service::matching::perfect_matchings::{Matching, MatchingGraph};
#[derive(Debug, Clone)]
pub struct MatchingColouriser2 {}
impl Colouriser for MatchingColouriser2 {
fn is_colorable<G: Graph>(graph: &G) -> bool {
let mut match_graph = MatchingGraph::from_graph(graph);
let matchings = match_graph.perfect_matchings();
let is_col = Self::is_col(&matchings);
is_col
}
fn new() -> Self {
Self {}
}
}
impl MatchingColouriser2 {
fn is_col(matchings: &Vec<Matching>) -> bool {
let mut i = 0;
for first in matchings.iter() {
i = i + 1;
for j in i..matchings.len() {
let second = &matchings[j];
if Self::are_disjoint(first, second) {
return true;
}
}
}
false
}
fn are_disjoint(first: &Matching, second: &Matching) -> bool {
for edge in first.edges.iter() {
if Self::has_edge(second, edge) {
return false;
}
}
true
}
fn has_edge(matching: &Matching, edge: &UndirectedEdge) -> bool {
for matching_edge in matching.edges.iter() {
if edge == matching_edge {
return true;
}
}
false
}
}