<s> from apgl . io . GraphWriter import GraphWriter <EOL> import logging <EOL> class SimpleGraphWriter ( GraphWriter ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self ) : <EOL> self . vertexIdDict = { } <EOL> def writeToFile ( self , fileName , graph ) : <EOL> """<STR_LIT>""" <EOL> self . vertexIdDict = { } <EOL> fileName = fileName + "<STR_LIT>" <EOL> numVertices = graph . getNumVertices ( ) <EOL> index = <NUM_LIT:0> <EOL> f = open ( fileName , '<STR_LIT:w>' ) <EOL> f . write ( "<STR_LIT>" ) <EOL> logging . info ( '<STR_LIT>' + fileName ) <EOL> for i in graph . getAllVertexIds ( ) : <EOL> self . vertexIdDict [ i ] = index <EOL> vertexString = str ( index ) + "<STR_LIT:\n>" <EOL> f . write ( vertexString ) <EOL> index += <NUM_LIT:1> <EOL> if graph . isUndirected ( ) : <EOL> f . write ( "<STR_LIT>" ) <EOL> else : <EOL> f . write ( "<STR_LIT>" ) <EOL> f . write ( self . __getArcString ( graph ) ) <EOL> f . close ( ) <EOL> logging . info ( "<STR_LIT>" + str ( numVertices ) + "<STR_LIT>" + str ( graph . getNumEdges ( ) ) + "<STR_LIT>" ) <EOL> def __getArcString ( self , graph ) : <EOL> arcString = "<STR_LIT>" <EOL> for edge in graph . getAllEdges ( ) : <EOL> vertex1 = edge [ <NUM_LIT:0> ] <EOL> vertex2 = edge [ <NUM_LIT:1> ] <EOL> index1 = self . vertexIdDict [ vertex1 ] <EOL> index2 = self . vertexIdDict [ vertex2 ] <EOL> arcString = arcString + str ( index1 ) + "<STR_LIT:U+002CU+0020>" + str ( index2 ) + "<STR_LIT:U+002CU+0020>" + str ( graph . getEdge ( vertex1 , vertex2 ) ) + "<STR_LIT:\n>" <EOL> return arcString </s>
