def sol2edgeset(sol, symmetric=True):
    """Converts solution to a set of edges (2-tuples). If the problem is
    symmetric the tuples are directed from smaller to larger node value to 
    avoid duplicates."""
    edges = set()
    for i in range(0,len(sol)-1):
        j = i+1
        if symmetric or sol[i]<sol[j]:
            edges.add( (sol[i], sol[j]) )
        else:
            edges.add( (sol[j], sol[i]) )
    return edges