The following algorithm generates the set of colored edges for a genome $$G$$.

ColoredEdges(G)
    E ← an empty set
    for each chromosome C in G
        N ← ChromosomeToCycle(C)
        for j ← 1 to |C|
            add edge (n2j, n2j + 1) to the set of edges E
    return set set of edges E

In this pseudocode we assume that $$c_{m + 1} = c_1$$ because in a cycle $$C = (c_1, c_2, \ldots, c_m)$$ the last element is followed by the first element.

Assignment

Define a class Genome that represents genomes as collections of (circular) chromosomes. The initialisation method takes zero or more chromosomes (objects of the class Chromosome). Make sure the built-in functions repr and str return string representations of objects of the class Genome that are formatted according to the example given below. In particular, they build on the corresponding string representations of the contained chromosomes.

The class Genome must have a method colored_edges that implements ColoredEdges. If the method is called one a genome $$G$$, it must return an iterator that yields all colored edges in the genome graph of $$G$$ in the form $$(x, y)$$.

Example

>>> genome = Genome(Chromosome(+1, -2, -3), Chromosome(+4, +5, -6))
>>> genome
Genome(Chromosome(1, -2, -3), Chromosome(4, 5, -6))
>>> print(genome)
(+1 -2 -3)(+4 +5 -6)
>>> set(genome.colored_edges())
{(2, 4), (3, 6), (5, 1), (8, 9), (10, 12), (11, 7)}