Skip to main content

vertex_chromatic_number

Function vertex_chromatic_number 

Source
pub fn vertex_chromatic_number(colors: &[u32]) -> u32
Expand description

Return the number of distinct colors used in a vertex coloring.

Given a color assignment colors[v] for each vertex, returns the count of distinct colors. This is a utility function that works on the output of vertex_coloring_greedy.

For an empty coloring (no vertices), returns 0.

ยงExamples

use rust_igraph::{Graph, vertex_coloring_greedy, vertex_chromatic_number, GreedyColoringHeuristic};

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
let colors = vertex_coloring_greedy(&g, GreedyColoringHeuristic::DSatur).unwrap();
assert_eq!(vertex_chromatic_number(&colors), 3); // triangle needs 3 colors