- java.lang.Object
-
- org.jgrapht.nio.BaseEventDrivenImporter<java.lang.Integer,Triple<java.lang.Integer,java.lang.Integer,java.lang.Double>>
-
- org.jgrapht.nio.dimacs.DIMACSEventDrivenImporter
-
- All Implemented Interfaces:
EventDrivenImporter<java.lang.Integer,Triple<java.lang.Integer,java.lang.Integer,java.lang.Double>>
public class DIMACSEventDrivenImporter extends BaseEventDrivenImporter<java.lang.Integer,Triple<java.lang.Integer,java.lang.Integer,java.lang.Double>> implements EventDrivenImporter<java.lang.Integer,Triple<java.lang.Integer,java.lang.Integer,java.lang.Double>>
A generic importer using consumers for DIMACS format.See
DIMACSFormat
for a description of all the supported DIMACS formats.In summary, one of the most common DIMACS formats was used in the 2nd DIMACS challenge and follows the following structure:
DIMACS G { c <comments> ignored during parsing of the graph p edge <number of nodes> <number of edges> e <edge source 1> <edge target 1> e <edge source 2> <edge target 2> e <edge source 3> <edge target 3> e <edge source 4> <edge target 4> ... }
e <edge source 1> <edge target 1> <edge_weight>
By default this importer recomputes node identifiers starting from $0$ as they are encountered in the file. It is also possible to instruct the importer to keep the original file numbering of the nodes. Additionally you can also instruct the importer to use zero-based numbering or keep the original number of DIMACS which starts from one. Note: the current implementation does not fully implement the DIMACS specifications! Special (rarely used) fields specified as 'Optional Descriptors' are currently not supported (ignored).
- Author:
- Michael Behrisch (adaptation of GraphReader class), Joris Kinable, Dimitrios Michail
-
-
Constructor Summary
Constructors Constructor Description DIMACSEventDrivenImporter()
Construct a new importer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
importInput(java.io.Reader input)
Import a graphprotected java.lang.Integer
mapVertexToInteger(java.lang.String id)
Map a vertex identifier to an integer.DIMACSEventDrivenImporter
renumberVertices(boolean renumberVertices)
Set whether to renumber vertices or not.DIMACSEventDrivenImporter
zeroBasedNumbering(boolean zeroBasedNumbering)
Set whether to use zero-based numbering for vertices.-
Methods inherited from class org.jgrapht.nio.BaseEventDrivenImporter
addEdgeAttributeConsumer, addEdgeConsumer, addEdgeCountConsumer, addGraphAttributeConsumer, addImportEventConsumer, addVertexAttributeConsumer, addVertexConsumer, addVertexCountConsumer, notifyEdge, notifyEdgeAttribute, notifyEdgeCount, notifyGraphAttribute, notifyImportEvent, notifyVertex, notifyVertexAttribute, notifyVertexCount, removeEdgeAttributeConsumer, removeEdgeConsumer, removeEdgeCountConsumer, removeGraphAttributeConsumer, removeImportEventConsumer, removeVertexAttributeConsumer, removeVertexConsumer, removeVertexCountConsumer
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgrapht.nio.EventDrivenImporter
addEdgeAttributeConsumer, addEdgeConsumer, addEdgeCountConsumer, addGraphAttributeConsumer, addImportEventConsumer, addVertexAttributeConsumer, addVertexConsumer, addVertexCountConsumer, importInput, importInput, removeEdgeAttributeConsumer, removeEdgeConsumer, removeEdgeCountConsumer, removeGraphAttributeConsumer, removeImportEventConsumer, removeVertexAttributeConsumer, removeVertexConsumer, removeVertexCountConsumer
-
-
-
-
Method Detail
-
zeroBasedNumbering
public DIMACSEventDrivenImporter zeroBasedNumbering(boolean zeroBasedNumbering)
Set whether to use zero-based numbering for vertices. The DIMACS format by default starts vertices numbering from one. If true then we will use zero-based numbering. Default to true.- Parameters:
zeroBasedNumbering
- whether to use zero-based numbering- Returns:
- the importer
-
renumberVertices
public DIMACSEventDrivenImporter renumberVertices(boolean renumberVertices)
Set whether to renumber vertices or not. If true then the vertices are assigned new numbers from $0$ to $n-1$ in the order that they are first encountered in the file. Otherwise, the original numbering (minus one in order to get a zero-based numbering) of the DIMACS file is kept. Defaults to true.- Parameters:
renumberVertices
- whether to renumber vertices or not- Returns:
- the importer
-
importInput
public void importInput(java.io.Reader input)
Description copied from interface:EventDrivenImporter
Import a graph- Specified by:
importInput
in interfaceEventDrivenImporter<java.lang.Integer,Triple<java.lang.Integer,java.lang.Integer,java.lang.Double>>
- Parameters:
input
- the input reader
-
mapVertexToInteger
protected java.lang.Integer mapVertexToInteger(java.lang.String id)
Map a vertex identifier to an integer.- Parameters:
id
- the vertex identifier- Returns:
- the integer
-
-