def __init__(self,graph=None,marking=None,alphabet=None,marking_alphabet=None):
         if isinstance(marking,GraphMap):
              GraphWithInverses.__init__(self,marking.codomain(),marking.codomain().alphabet())
              self._marking=marking
         else:
              if isinstance(graph,GraphWithInverses):
                   alphabet=graph._alphabet
              GraphWithInverses.__init__(self,graph,alphabet)

              if marking is None: #computes a (random) marking from a rose equivalent to graph

                   A=graph.alphabet()
                   tree=graph.spanning_tree()

                   j=0
                   letter=dict()
                   for a in A.positive_letters():
                        vi=graph.initial_vertex(a)
                        vt=graph.terminal_vertex(a)
                        if (len(tree[vi])==0 or tree[vi][-1]!=A.inverse_letter(a)) and\
                                 (len(tree[vt])==0 or tree[vt][-1]!=a):
                             letter[j]=a
                             j=j+1



                   B=AlphabetWithInverses(j)
                   RB=GraphWithInverses.rose_graph(B)

                   edge_map=dict()

                   for i in xrange(j):
                        a=letter[i]
                        edge_map[B[i]]=graph.reduce_path(tree[graph.initial_vertex(a)]\
                                                           *Word([a])\
                                                           *graph.reverse_path(tree[graph.terminal_vertex(a)]))

                        marking=GraphMap(RB,graph,edge_map)
              else:
                   marking=GraphMap(GraphWithInverses.rose_graph(marking_alphabet),self,marking)
              self._marking=marking
    def __init__(self, graph=None, marking=None, alphabet=None,
                 marking_alphabet=None):
        """
        INPUT:

        - ``graph`` -- (default None) GraphWithInverses is expected
          or will be combute from ''grap''
        - ``marking`` -- (default None) GraphMap is expected
          or will be compute
        - ``alphabet`` -- (default None) if ``graph`` is GraphWithInverses
          ``alphabet`` will be use for ``self``
        - ``marking_alphabet`` -- (default None) alphabet used in the case of a
          ``MarkedGraph`` is created from a GraphWithInverses`` by
          computing (randomly) a rose equivalent to the graph.

        EXAMPLES::

            sage: G = GraphWithInverses({'a':(0,0),'b':(0,1),'c':(1,0)})
            sage: M = MarkedGraph(graph=G)
            sage: print M
            Marked graph: a: 0->0, c: 1->0, b: 0->1
            Marking: a->a, b->bc
            sage: A = AlphabetWithInverses(2)
            sage: G = GraphWithInverses.rose_graph(A)
            sage: H = GraphWithInverses.rose_graph(A)
            sage: f = GraphMap(G,H,"a->aba,b->ab")
            sage: M = MarkedGraph(marking=f)
            sage: print M
            Marked graph: a: 0->0, b: 0->0
            Marking: a->aba, b->ab
            sage: print MarkedGraph(marking=f, alphabet=A)
            Marked graph: a: 0->0, b: 0->0
            Marking: a->aba, b->ab
            sage: print MarkedGraph(marking=f, marking_alphabet=A)
            Marked graph: a: 0->0, b: 0->0
            Marking: a->aba, b->ab
        """
        if isinstance(marking, GraphMap):
            GraphWithInverses.__init__(self,
                                       marking.codomain(),
                                       marking.codomain().alphabet())
            self._marking = marking
        else:
            if isinstance(graph, GraphWithInverses):
                alphabet = graph.alphabet()
            GraphWithInverses.__init__(self, graph, alphabet)

            if marking is None:  # computes a (random) marking
                # from a rose equivalent to graph

                A = graph.alphabet()
                tree = graph.spanning_tree()

                j = 0
                letter = dict()
                for a in A.positive_letters():
                    vi = graph.initial_vertex(a)
                    vt = graph.terminal_vertex(a)
                    if (len(tree[vi]) == 0 or
                            tree[vi][-1] != A.inverse_letter(a)) \
                            and (len(tree[vt]) == 0 or tree[vt][-1] != a):
                        letter[j] = a
                        j = j + 1

                B = AlphabetWithInverses(j)
                RB = GraphWithInverses.rose_graph(B)

                edge_map = dict()

                for i in xrange(j):
                    a = letter[i]
                    edge_map[B[i]] = graph.reduce_path(
                        tree[graph.initial_vertex(a)] * Word([a]) *
                        graph.reverse_path(tree[graph.terminal_vertex(a)]))
                marking = GraphMap(RB, graph, edge_map)
            else:
                marking = GraphMap(
                    GraphWithInverses.rose_graph(marking_alphabet),
                    self, marking)
            self._marking = marking