code: def _write_graph_to_dimacs_file(
      graph, f, source=None, target=None, capacity="capacity"
  ):
      """Writes the graph in DIMACS format to the given file.
  
      @param f: the name of the file to be written or a Python file handle.
      @param source: the source vertex ID. If C{None}, igraph will try to
        infer it from the C{source} graph attribute.
      @param target: the target vertex ID. If C{None}, igraph will try to
        infer it from the C{target} graph attribute.
      @param capacity: the capacities of the edges in a list or the name of
        an edge attribute that holds the capacities. If there is no such
        edge attribute, every edge will have a capacity of 1.
      """
      if source is None:
          try:
              source = graph["source"]
          except KeyError:
              raise ValueError(
                  "source vertex must be provided in the 'source' graph "
                  "attribute or in the 'source' argument of write_dimacs()"
              ) from None
  
      if target is None:
          try:
              target = graph["target"]
          except KeyError:
              raise ValueError(
                  "target vertex must be provided in the 'target' graph "
                  "attribute or in the 'target' argument of write_dimacs()"
              ) from None
  
      if (
          isinstance(capacity, str)
          and capacity not in graph.edge_attributes()
      ):
          warn(
              "'%s' edge attribute does not exist" % capacity,
              stacklevel=1,
          )
          capacity = [1] * graph.ecount()
  
      return GraphBase.write_dimacs(graph, f, source, target, capacity)
  
file_path: python-igraph/src/igraph/io/files.py
imports: import gzip
  import os
  from shutil import copyfileobj
  from warnings import warn
  from igraph._igraph import GraphBase
  from igraph.utils import named_temporary_file
label_desc: Use image node_id 9 for calling a global function with example usage: _write_graph_to_dimacs_file(graph, f, source, target, capacity) and returns: GraphBase