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

Method buildMaxflowGraph

IO/Infovis/vtkDIMACSGraphReader.cxx:200–324  ·  view source on GitHub ↗

============================================================================ Build a graph from a max-flow problem. These are directed. These should have TWO node descriptor lines of the format: n ID where is either an 's' or a 't', for the source and sink, respectively. Format of edge lines is: a u v cap to create an edge u->v, and cap gives the edge capacity.

Source from the content-addressed store, hash-verified

198// a u v cap
199// to create an edge u->v, and cap gives the edge capacity.
200int vtkDIMACSGraphReader::buildMaxflowGraph(vtkGraph* output)
201{
202 std::string S;
203 int iEdgeU, iEdgeV, iVertexID;
204 int currentEdgeId = 0;
205 int numSrcs = 0;
206 int numSinks = 0;
207
208 std::string sAttribute;
209 VTK_CREATE(vtkMutableDirectedGraph, builder);
210
211 VTK_CREATE(vtkIntArray, vertexSourceArray);
212 VTK_CREATE(vtkIntArray, vertexSinkArray);
213 VTK_CREATE(vtkIntArray, edgeCapacityArray);
214
215 VTK_CREATE(vtkIntArray, vertexPedigreeIds);
216 VTK_CREATE(vtkIntArray, edgePedigreeIds);
217
218 vertexSourceArray->SetName("sources");
219 vertexSinkArray->SetName("sinks");
220 edgeCapacityArray->SetName("capacity");
221
222 vertexSourceArray->SetNumberOfTuples(this->numVerts);
223 vertexSinkArray->SetNumberOfTuples(this->numVerts);
224 edgeCapacityArray->SetNumberOfTuples(this->numEdges);
225
226 for (int i = 0; i < this->numVerts; i++)
227 {
228 vertexSourceArray->SetValue(i, 0);
229 vertexSinkArray->SetValue(i, 0);
230 }
231
232 for (int i = 0; i < this->numEdges; i++)
233 {
234 edgeCapacityArray->SetValue(i, 0);
235 }
236
237 // Set up Pedigree-IDs arrays.
238 vertexPedigreeIds->SetName("vertex id");
239 vertexPedigreeIds->SetNumberOfTuples(this->numVerts);
240 edgePedigreeIds->SetName("edge id");
241 edgePedigreeIds->SetNumberOfTuples(this->numEdges);
242
243 // Allocate Vertices in the graph builder
244 for (int i = 0; i < this->numVerts; i++)
245 {
246 builder->AddVertex();
247 vertexPedigreeIds->SetValue(i, i + 1);
248 }
249
250 // set starting edge id number.
251 int baseEdgeId = 1;
252
253 vtksys::ifstream IFP(this->FileName);
254 if (IFP.is_open())
255 {
256 while (vtksys::SystemTools::GetLineFromStream(IFP, S))
257 {

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected