46 Eigen::DenseBase<TDerivedPtr>
const& ptr,
47 Eigen::DenseBase<TDerivedAdj>
const& adj,
50 -> Eigen::Vector<TIndex, Eigen::Dynamic>
52 PBAT_PROFILE_NAMED_SCOPE(
"pbat.graph.GreedyColor");
56 TIndex
const n = ptr.size() - 1;
57 using IndexVectorType = Eigen::Vector<TIndex, Eigen::Dynamic>;
58 using Colors = IndexVectorType;
60 C.setConstant(TIndex(-1));
62 IndexVectorType ordering(n);
63 std::ranges::copy(std::views::iota(TIndex(0), n), ordering.data());
64 switch (eOrderingStrategy)
69 auto di = ptr(i + 1) - ptr(i);
70 auto dj = ptr(j + 1) - ptr(j);
76 auto di = ptr(i + 1) - ptr(i);
77 auto dj = ptr(j + 1) - ptr(j);
84 for (TIndex u : ordering)
87 std::fill(usable.begin(), usable.end(),
true);
90 auto vEnd = ptr(u + TIndex(1));
92 for (
auto k = vBegin; k < vEnd; ++k)
96 if (cv >= 0 and usable[cv])
103 bool bPaletteInsufficient = nUnusable == palette.Size();
104 if (bPaletteInsufficient)
107 C(u) = palette.Size();
108 palette.Push(TIndex(1));
114 auto colors = std::views::iota(0, palette.Size());
115 auto c = *std::ranges::min_element(colors, [&](
auto ci,
auto cj) {
117 switch (eSelectionStrategy)
121 (usable[ci] and usable[cj]) ? palette[ci] < palette[cj] : usable[ci];
124 bLess = (usable[ci] and usable[cj]) ? ci < cj : usable[ci];
auto ArgSort(TIndex n, FLess less) -> Eigen::Vector< TIndex, Eigen::Dynamic >
Computes the indices that would sort an array.
Definition ArgSort.h:32
auto GreedyColor(Eigen::DenseBase< TDerivedPtr > const &ptr, Eigen::DenseBase< TDerivedAdj > const &adj, EGreedyColorOrderingStrategy eOrderingStrategy=EGreedyColorOrderingStrategy::LargestDegree, EGreedyColorSelectionStrategy eSelectionStrategy=EGreedyColorSelectionStrategy::LeastUsed) -> Eigen::Vector< TIndex, Eigen::Dynamic >
Greedy graph coloring algorithm.
Definition Color.h:45