45 #ifndef _ZOLTAN2_ALGSERIALGREEDY_HPP_
46 #define _ZOLTAN2_ALGSERIALGREEDY_HPP_
58 template <
typename Adapter>
62 typedef typename Adapter::lno_t lno_t;
63 typedef typename Adapter::gno_t gno_t;
64 typedef typename Adapter::offset_t offset_t;
65 typedef typename Adapter::scalar_t scalar_t;
67 RCP<GraphModel<typename Adapter::base_adapter_t> > model_;
68 RCP<Teuchos::ParameterList> pl_;
69 RCP<Environment> env_;
70 RCP<const Teuchos::Comm<int> > comm_;
75 const RCP<Teuchos::ParameterList> &pl,
76 const RCP<Environment> &env,
77 const RCP<
const Teuchos::Comm<int> > &comm
78 ) : model_(model), pl_(pl), env_(env), comm_(comm)
91 ArrayView<const gno_t> edgeIds;
92 ArrayView<const offset_t> offsets;
93 ArrayView<StridedData<lno_t, scalar_t> > wgts;
95 const size_t nVtx = model_->getLocalNumVertices();
96 model_->getEdgeList(edgeIds, offsets, wgts);
100 cout <<
"Debug: Local graph from getLocalEdgeList" << endl;
101 cout <<
"rank " << comm_->getRank() <<
": nVtx= " << nVtx << endl;
102 cout <<
"rank " << comm_->getRank() <<
": edgeIds: " << edgeIds << endl;
103 cout <<
"rank " << comm_->getRank() <<
": offsets: " << offsets << endl;
108 ArrayRCP<int> colors = solution->getColorsRCP();
109 for (
size_t i=0; i<nVtx; i++){
123 ArrayView<const gno_t> edgeIds,
124 ArrayView<const offset_t> offsets,
131 offset_t maxDegree = 0;
132 for (
size_t i=0; i<nVtx; i++){
133 if (offsets[i+1]-offsets[i] > maxDegree)
134 maxDegree = offsets[i+1]-offsets[i];
143 Teuchos::Array<int> forbidden(maxDegree+2, 0);
146 Teuchos::Array<lno_t> numVerticesWithColor(maxDegree+2, 0);
149 Teuchos::ParameterList &pl = env_->getParametersNonConst();
150 std::string colorChoice = pl.get<std::string>(
"color_choice",
"FirstFit");
152 for (
size_t i=0; i<nVtx; i++){
155 for (offset_t j=offsets[v]; j<offsets[v+1]; j++){
156 gno_t nbor = edgeIds[j];
158 if (colors[nbor] > 0){
160 forbidden[colors[nbor]] = v;
167 if ((colors[v]==0) || ((colors[v]>0) && forbidden[colors[v]] == v)){
169 if (colorChoice.compare(
"FirstFit")){
171 for (
int c=1; c <= maxColor+1; c++){
172 if (forbidden[c] != v){
178 else if (colorChoice.compare(
"Random")){
182 Teuchos::Array<int> avail(maxColor+1);
183 for (
int c=1; c < maxColor+1; c++){
184 if (forbidden[c] != v){
185 avail[numAvail++] = c;
189 colors[v] = maxColor+1;
191 colors[v] = avail[rand()%numAvail];
193 else if (colorChoice.compare(
"RandomFast")){
195 bool foundColor =
false;
196 int r = (rand() % maxColor) +1;
197 for (
int c=r; c <= maxColor; c++){
198 if (forbidden[c] != v){
205 for (
int c=1; c < r; c++){
206 if (forbidden[c] != v){
213 if (!foundColor) colors[v] = maxColor+1;
215 else if (colorChoice.compare(
"LeastUsed")){
218 int leastUsedColor = 1;
219 for (
int c=1; c <= maxColor; c++){
220 if (forbidden[c] != v){
221 if (numVerticesWithColor[c] < leastUsedColor){
226 colors[v] = leastUsedColor;
229 numVerticesWithColor[colors[v]]++;
232 if ((v==0) && colors[v]==0) colors[v]=1;
235 if (colors[v] > maxColor){
236 maxColor = colors[v];
248 RCP<Teuchos::StringValidator> color_choice_Validator = Teuchos::rcp(
249 new Teuchos::StringValidator(
250 Teuchos::tuple<std::string>(
251 "FirstFit",
"Random",
"RandomFast",
"LeastUsed" )));
252 pl.set(
"color_choice",
"FirstFit",
"selection criterion for coloring",
253 color_choice_Validator);
Time an algorithm (or other entity) as a whole.
void color(const RCP< ColoringSolution< Adapter > > &solution)
Coloring method.
AlgSerialGreedy(const RCP< GraphModel< typename Adapter::base_adapter_t > > &model, const RCP< Teuchos::ParameterList > &pl, const RCP< Environment > &env, const RCP< const Teuchos::Comm< int > > &comm)
Algorithm defines the base class for all algorithms.
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.
void colorCrsGraph(const size_t nVtx, ArrayView< const gno_t > edgeIds, ArrayView< const offset_t > offsets, ArrayRCP< int > colors)
The class containing coloring solution.