MCPcopy Create free account
hub / github.com/Kitware/VTK / buildColoringGraph

Method buildColoringGraph

IO/Infovis/vtkDIMACSGraphReader.cxx:332–400  ·  view source on GitHub ↗

============================================================================ 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

Source from the content-addressed store, hash-verified

330// * edges (u->v) are formatted as:
331// e u v
332int 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

Callers

nothing calls this directly

Calls 11

GetLineFromStreamFunction · 0.85
is_openMethod · 0.80
SetPedigreeIdsMethod · 0.80
GetVertexDataMethod · 0.80
GetEdgeDataMethod · 0.80
SetNameMethod · 0.45
SetNumberOfTuplesMethod · 0.45
AddVertexMethod · 0.45
SetValueMethod · 0.45
AddEdgeMethod · 0.45
CheckedShallowCopyMethod · 0.45

Tested by

no test coverage detected