============================================================================ Builder method for creating coloring problem graphs. These are undirected. nodes and edges have no weights associated with them. edges (u->v) are formatted as: e u v
| 330 | // * edges (u->v) are formatted as: |
| 331 | // e u v |
| 332 | int vtkDIMACSGraphReader::buildColoringGraph(vtkGraph* output) |
| 333 | { |
| 334 | std::string S; |
| 335 | int iEdgeU, iEdgeV; |
| 336 | int currentEdgeId = 0; |
| 337 | |
| 338 | VTK_CREATE(vtkMutableUndirectedGraph, builder); |
| 339 | VTK_CREATE(vtkIntArray, vertexPedigreeIds); |
| 340 | VTK_CREATE(vtkIntArray, edgePedigreeIds); |
| 341 | |
| 342 | // Set up Pedigree-IDs arrays. |
| 343 | vertexPedigreeIds->SetName("vertex id"); |
| 344 | vertexPedigreeIds->SetNumberOfTuples(this->numVerts); |
| 345 | edgePedigreeIds->SetName("edge id"); |
| 346 | edgePedigreeIds->SetNumberOfTuples(this->numEdges); |
| 347 | |
| 348 | // Allocate Vertices in the graph builder |
| 349 | for (int i = 0; i < this->numVerts; i++) |
| 350 | { |
| 351 | builder->AddVertex(); |
| 352 | vertexPedigreeIds->SetValue(i, i + 1); |
| 353 | } |
| 354 | |
| 355 | // set starting edge id number. |
| 356 | int baseEdgeId = 1; |
| 357 | |
| 358 | vtksys::ifstream IFP(this->FileName); |
| 359 | if (IFP.is_open()) |
| 360 | { |
| 361 | while (vtksys::SystemTools::GetLineFromStream(IFP, S)) |
| 362 | { |
| 363 | istringstream iss(S); |
| 364 | char lineType; |
| 365 | iss >> lineType; |
| 366 | switch (lineType) |
| 367 | { |
| 368 | case 'e': /* edge arc */ |
| 369 | { |
| 370 | iss >> iEdgeU >> iEdgeV; |
| 371 | |
| 372 | if (iEdgeU == 0 || iEdgeV == 0) |
| 373 | { |
| 374 | vtkErrorMacro(<< "DIMACS graph vertices are numbered 1..n; 0 is not allowed"); |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | builder->AddEdge(iEdgeU - 1, iEdgeV - 1); |
| 379 | edgePedigreeIds->SetValue(currentEdgeId, currentEdgeId + baseEdgeId); |
| 380 | currentEdgeId++; |
| 381 | } |
| 382 | break; |
| 383 | default: |
| 384 | break; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | // Add the pedigree ids to the graph |
nothing calls this directly
no test coverage detected