def __init__(self, *args, **kwargs):
        # These are needed (and the normal way to override from a python class)
        Sofa.Core.Controller.__init__(self, *args, **kwargs)

        self.init_done = False

        self.mesh = None
        edges = []
        if kwargs["mesh"]:
            self.mesh = kwargs["mesh"]
            for edge in self.mesh.edges.value:
                edges += [(edge[0], edge[1], 1)]

        skel_graph = Graph()
        for edge in edges:
            skel_graph.add_edge(*edge)

        self.startNode = kwargs["startNode"]
        self.goalNode = kwargs["goalNode"]

        self.path = dijkstra(skel_graph, self.startNode, self.goalNode)
        print("shortest path from {} to {} is {}".format(
            self.startNode, self.goalNode, self.path))

        self.skelMO = None
        if kwargs["skelMO"]:
            self.skelMO = kwargs["skelMO"]

        self.goalMO = None
        if kwargs["goalMO"]:
            self.goalMO = kwargs["goalMO"]

        self.it = 0
        self.max_it = 1000
Exemple #2
0
def create_graph(list_of_seq):
    """Creates an overlap graph based on a list of sequences."""
    super_string_graph = Graph()
    num_seq = len(list_of_seq)
    i = 0
    while i < num_seq:
        first = list_of_seq[i]
        j = 0
        while j < num_seq:
            if i != j:
                second = list_of_seq[j]
                max_overlap = min(
                    len(first),
                    len(second))  # Maximum overlength is shortest sequence
                min_overlap = max(
                    len(first), len(second)
                ) // 2  # Minimum overlap is half of the largest sequence
                overlap = max_overlap
                found = False
                while overlap >= min_overlap and not found:
                    if suffix(first, overlap) == prefix(second, overlap):
                        super_string_graph.add_edge(first,
                                                    second,
                                                    weight=overlap)
                        found = True
                    overlap -= 1
            j += 1
        i += 1
    return super_string_graph