Exemplo n.º 1
0
 def test_read_file1(self):
     file = [
         "testFile", "sbuf-send-pkt2-vf", "ALU2-vf", "biu-dma2fifo-VF",
         "biu-fifo2dma-VF", "des-vf", "isqrt-vf", "scsi-init-send-vf",
         "scsi-targ-send-vf", "select2p-vf", "selmerge2ph-vf", "I2C"
     ]
     file = [
         "scsi", "pscsi", "chu150", "hp-ir", "nowick", "pe-rcv-ifc",
         "rf-contr", "sc-con2", "sdcont2", "stet1"
     ]
     for f in file:
         print(f)
         parse_test = TextParseESTG(self.PATH_TO_TESTS + f)
         parse_test.read_file()
         estg_graph = ESTGGraph(parse_test)
         GraphUtil.print_graph(estg_graph,
                               f,
                               view_flag=True,
                               overwrite_graph=True)
         estg_graph.check_consistency()
         estg_graph.check_output_persistency()
         number_of_places = 0
         number_of_transitions = 0
         for node in estg_graph.extended_graph:
             if node.is_place:
                 number_of_places += 1
             else:
                 number_of_transitions += 1
         print(str(number_of_places) + " Places")
         print(str(number_of_transitions) + " Transitions")
Exemplo n.º 2
0
 def test_stg_conversion(self):
     # inputs, outputs, graph, name, initial_markings, extended_graph, node_classification =\
     # #     GraphUtil.stg_to_estg(self.PATH_TO_TESTS + "atod.g", overwrite_file_flag=False)
     files = [
         "alloc-outbound", "atod", "chu172", "ebergen", "fifo", "hybridf",
         "master-read", "meng9", "pe-send-ifc", "qr42", "ram-read-sbuf",
         "rpdft", "sbuf-ram-write", "sendr-done", "sm", "trimos-send",
         "vbe10b", "wrdatab"
     ]
     # files = ["vbe10b"]
     extension = ".g"
     for file in files:
         try:
             print(file)
             stg_conversion = TextParseSTG(self.PATH_TO_TESTS + file +
                                           extension,
                                           overwrite_file_flag=True)
             parse_test = TextParseESTG(self.PATH_TO_TESTS + file)
             parse_test.read_file()
             estg_graph = ESTGGraph(parse_test)
             GraphUtil.print_graph(estg_graph,
                                   file,
                                   view_flag=False,
                                   overwrite_graph=True)
             print("Success")
         except Exception as e:
             traceback.print_exc()
Exemplo n.º 3
0
 def test_read_file4(self):
     file = "testFile4"
     parse_test = TextParseESTG(self.PATH_TO_TESTS + file)
     parse_test.read_file()
     estg_graph = ESTGGraph(parse_test)
     GraphUtil.print_graph(estg_graph, file)
     estg_graph.check_consistency()
     estg_graph.check_output_persistency()
     self.assertEqual(parse_test.regular_inputs, ["a", "b"])
     self.assertEqual(parse_test.outputs, ["x", "y", "z"])
Exemplo n.º 4
0
 def test_read_file3(self):
     file = "master-read"
     parse_test = TextParseESTG(self.PATH_TO_TESTS + file)
     parse_test.read_file()
     estg_graph = ESTGGraph(parse_test)
     GraphUtil.print_graph(estg_graph,
                           file,
                           view_flag=True,
                           overwrite_graph=True)
     estg_graph.check_consistency()
     estg_graph.check_output_persistency()
     self.assertEqual(parse_test.regular_inputs, ["a", "d"])
     self.assertEqual(parse_test.outputs, ["b", "c", "x"])
Exemplo n.º 5
0
 def test_free_choice_test(self):
     files = [
         "alloc-outbound", "atod", "chu172", "ebergen", "fifo", "hybridf",
         "master-read", "meng9", "pe-send-ifc", "qr42", "ram-read-sbuf",
         "rpdft", "sbuf-ram-write", "sendr-done", "sm", "trimos-send",
         "vbe10b", "wrdatab"
     ]
     for file in files:
         parse_test = TextParseESTG(self.PATH_TO_TESTS + file)
         parse_test.read_file()
         estg_graph = ESTGGraph(parse_test)
         if not GraphUtil.is_free_choice_stg(estg_graph):
             GraphUtil.print_graph(estg_graph, file, view_flag=True)
Exemplo n.º 6
0
 def test_read_file2(self):
     file = "testFile2"
     parse_test = TextParseESTG(self.PATH_TO_TESTS + file)
     parse_test.read_file()
     estg_graph = ESTGGraph(parse_test)
     GraphUtil.print_graph(estg_graph,
                           file,
                           view_flag=True,
                           overwrite_graph=True)
     estg_graph.check_consistency()
     estg_graph.check_output_persistency()
     self.assertEqual(parse_test.regular_inputs,
                      ["ackin", "dack", "done", "dtc", "startdmasend"])
     self.assertEqual(parse_test.outputs,
                      ["dreq", "endmaint", "ready", "regout"])
Exemplo n.º 7
0
def main():
    file_name = sys.argv[1]
    view_flag = True
    if len(sys.argv) > 2:
        view_flag = True
    parse_file = TextParseESTG(PATH_TO_TESTS + file_name)
    parse_file.read_file()
    estg_graph = ESTGGraph(parse_file)
    #estg_graph.check_consistency()
    estg_graph.check_output_persistency()
    direct = DirectMapping(estg_graph)
    GraphUtil.print_graph(estg_graph,
                          file_name,
                          view_flag=view_flag,
                          overwrite_graph=True)
    generator = VHDLGenerator(direct, file_name, False)
    print(generator.last_cycle_2_control_cell)
    print(direct.size_1_cycles)
    print(direct.size_2_cycles)
Exemplo n.º 8
0
class GraphSearchAnimator(object):
    """ Draw a graph search. """

    def __init__(self, graph, vertex_coords):
        """ 

        """
        self.graph = graph
        self.util = GraphUtil(vertex_coords)

    def _astar(self, source, dest, h):
        """
        Implemented by objects that inherit from this.
        """
        pass

    def _animation(self, source, dest, heuristic):
        seq, pred_list = self._astar(source, dest, heuristic)
        return self._process_search_result(seq, pred_list, dest)

    def _process_search_result(self, sequence, pred_list, dest):
        sequence_coords = self._sequence_coords(sequence)
        path = self._construct_shortest_path(pred_list, dest)
        return sequence, sequence_coords, path

    def _find_source_dest(self, source, dest):
        s_vertex = self.util._find_closest_vertex(source)
        d_vertex = self.util._find_closest_vertex(dest)
        return s_vertex, d_vertex

    def _construct_shortest_path(self, pred_list, dest):
        """ 
        Given a predecessor list, such as created by A*, and the dest
        vertex ID, return the shortest path found by the algorithm.

        Will likely have to been overriden in the case of bidirectional
        algorithms.
        """
        path = []
        vertex = dest
        while pred_list[vertex]['pred'] is not None:
            path.append(vertex)
            vertex = pred_list[vertex]['pred']
        path.reverse()
        path = [self.util.coords[v] for v in path]
        return path

    def _sequence_coords(self, seq):
        """ 

        """
        needed = {}
        coords = self.util.coords
        for vertex, actions in seq:
            needed[vertex] = coords[vertex]
            for arc in actions:
                needed[arc] = coords[arc]
        return needed

    def _heuristic_selector(self, heuristic):
        h_fun = self.util._euclidean
        if heuristic == "manhattan":
            h_fun = self.util._manhattan
        elif heuristic == "octile":
            h_fun = self.util._octile
        return h_fun            

    def _alt_heuristic(self, id1, id2):
        max_dist = 0
        lm_dists = self.landmark_dict
        for dist1, dist2 in zip(lm_dists[id1], lm_dists[id2]):
            try:
                d = abs(dist1 - dist2)
                if d > max_dist:
                    max_dist = d
            except TypeError:
                # Some nodes couldnt reach a landmark
                pass
        return max_dist
Exemplo n.º 9
0
    def __init__(self, graph, vertex_coords):
        """ 

        """
        self.graph = graph
        self.util = GraphUtil(vertex_coords)