10 #ifndef _ZOLTAN2_ALGSERIALGREEDY_HPP_
11 #define _ZOLTAN2_ALGSERIALGREEDY_HPP_
23 template <
typename Adapter>
29 typedef typename Adapter::offset_t offset_t;
30 typedef typename Adapter::scalar_t scalar_t;
32 const RCP<const typename Adapter::base_adapter_t> adapter_;
33 RCP<Teuchos::ParameterList> pl_;
34 RCP<Environment> env_;
35 RCP<const Teuchos::Comm<int> > comm_;
40 const RCP<const typename Adapter::base_adapter_t> &adapter,
41 const RCP<Teuchos::ParameterList> &pl,
42 const RCP<Environment> &env,
43 const RCP<
const Teuchos::Comm<int> > &comm,
45 ) : adapter_(adapter), pl_(pl), env_(env), comm_(comm), graphFlags_(graphFlags)
58 ArrayView<const gno_t> edgeIds;
59 ArrayView<const offset_t> offsets;
60 ArrayView<StridedData<lno_t, scalar_t> > wgts;
63 const size_t nVtx = model->getLocalNumVertices();
64 model->getEdgeList(edgeIds, offsets, wgts);
68 cout <<
"Debug: Local graph from getLocalEdgeList" << endl;
69 cout <<
"rank " << comm_->getRank() <<
": nVtx= " << nVtx << endl;
70 cout <<
"rank " << comm_->getRank() <<
": edgeIds: " << edgeIds << endl;
71 cout <<
"rank " << comm_->getRank() <<
": offsets: " << offsets << endl;
76 ArrayRCP<int> colors = solution->getColorsRCP();
77 for (
size_t i=0; i<nVtx; i++){
91 ArrayView<const gno_t> edgeIds,
92 ArrayView<const offset_t> offsets,
99 offset_t maxDegree = 0;
100 for (
size_t i=0; i<nVtx; i++){
101 if (offsets[i+1]-offsets[i] > maxDegree)
102 maxDegree = offsets[i+1]-offsets[i];
111 Teuchos::Array<int> forbidden(maxDegree+2, 0);
114 Teuchos::Array<lno_t> numVerticesWithColor(maxDegree+2, 0);
117 Teuchos::ParameterList &pl = env_->getParametersNonConst();
118 std::string colorChoice = pl.get<std::string>(
"color_choice",
"FirstFit");
120 for (
size_t i=0; i<nVtx; i++){
123 for (offset_t j=offsets[v]; j<offsets[v+1]; j++){
124 gno_t nbor = edgeIds[j];
126 if (colors[nbor] > 0){
128 forbidden[colors[nbor]] = v;
135 if ((colors[v]==0) || ((colors[v]>0) && forbidden[colors[v]] == v)){
137 if (colorChoice.compare(
"FirstFit")){
139 for (
int c=1; c <= maxColor+1; c++){
140 if (forbidden[c] != v){
146 else if (colorChoice.compare(
"Random")){
150 Teuchos::Array<int> avail(maxColor+1);
151 for (
int c=1; c < maxColor+1; c++){
152 if (forbidden[c] != v){
153 avail[numAvail++] = c;
157 colors[v] = maxColor+1;
159 colors[v] = avail[rand()%numAvail];
161 else if (colorChoice.compare(
"RandomFast")){
163 bool foundColor =
false;
164 int r = (rand() % maxColor) +1;
165 for (
int c=r; c <= maxColor; c++){
166 if (forbidden[c] != v){
173 for (
int c=1; c < r; c++){
174 if (forbidden[c] != v){
181 if (!foundColor) colors[v] = maxColor+1;
183 else if (colorChoice.compare(
"LeastUsed")){
186 int leastUsedColor = 1;
187 for (
int c=1; c <= maxColor; c++){
188 if (forbidden[c] != v){
189 if (numVerticesWithColor[c] < leastUsedColor){
194 colors[v] = leastUsedColor;
197 numVerticesWithColor[colors[v]]++;
200 if ((v==0) && colors[v]==0) colors[v]=1;
203 if (colors[v] > maxColor){
204 maxColor = colors[v];
216 RCP<Teuchos::StringValidator> color_choice_Validator = Teuchos::rcp(
217 new Teuchos::StringValidator(
218 Teuchos::tuple<std::string>(
219 "FirstFit",
"Random",
"RandomFast",
"LeastUsed" )));
220 pl.set(
"color_choice",
"FirstFit",
"selection criterion for coloring",
221 color_choice_Validator);
Time an algorithm (or other entity) as a whole.
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
map_t::global_ordinal_type gno_t
void color(const RCP< ColoringSolution< Adapter > > &solution)
Coloring method.
Algorithm defines the base class for all algorithms.
map_t::local_ordinal_type lno_t
GraphModel defines the interface required for graph models.
Defines the ColoringSolution class.
Defines the GraphModel interface.
static void getValidParameters(ParameterList &pl)
Set up validators specific to this algorithm.
AlgSerialGreedy(const RCP< const typename Adapter::base_adapter_t > &adapter, const RCP< Teuchos::ParameterList > &pl, const RCP< Environment > &env, const RCP< const Teuchos::Comm< int > > &comm, modelFlag_t graphFlags)
void colorCrsGraph(const size_t nVtx, ArrayView< const gno_t > edgeIds, ArrayView< const offset_t > offsets, ArrayRCP< int > colors)
The class containing coloring solution.