Пример #1
0
 def handle(self):
     """
     Handle the request. It should contain the directory, model name and tranformation name.
     The handle will make a Himesis of the model
     The handle will make a Himesis of the rules and a schedule
     The handle will execute the transformation
     The handle will export the transformed model to Simulink
     @return: None
     """
     sys.stdout.write( "started thread")
     self.mh =  self.server.getFromPool()
     self.wfile.write('RDY')
     data = self.rfile.readline().rstrip('\n')
     self.wfile.write('OK')
     sys.stdout.write(data)
     path,model,transformation = data.split(';')
     self.mh.chDir(path)
     # Model to Himesis
     modelToHimesis = SimulinkModelToHimesis(self.mh,model,path)
     modelToHimesis.SimulinkModelToHimesis()
     # Transfornation to T-Core
     transformationToHimesis = SimulinkTransformationToHimesis(transformation,path,self.mh)
     transformationToHimesis.SimulinkTransformationModelToHimesis()
     # Execute the Transformation
     exec("from Server.temp."+ Himesis.standardize_name(model) + " import "+ Himesis.standardize_name(model))
     exec("import Server.temp.T_" + transformation)
     packet = Packet()
     exec("packet.graph = "+ Himesis.standardize_name(model) + "()")
     exec('packet = Server.temp.T_'+ transformation +'.packet_in(packet)')
     #export:
     simulinkExport = SimulinkExporter(model,self.mh,packet.graph)
     simulinkExport.exportSimulink()
     self.wfile.write('finished')
Пример #2
0
    def run(self, path, model, opt_name):

        if not self.mh == None:

            start = time.time()
            self.mh.chDir(path)

            # turn Simulink model into himesis graph
            modelToHimesis = SimulinkModelToHimesis(self.mh, model, path)
            modelToHimesis.SimulinkModelToHimesis()

            end = time.time()
            print("Time taken to import from Simulink: " + str(end - start) + " seconds")

            # draw model
            # print("Start drawing")
            # self.mh.drawSystem(model, "~/")
            # print("End drawing")

        start = time.clock()
        hToCBD = HimesisToCBD()
        self.model = hToCBD.convertFile("himesis/" + Himesis.standardize_name(model) + ".py")
        end = time.clock()
        print("Time taken for Himesis to CBD: " + str(end - start) + " seconds")

        # TODO: only needed for dep graph, should remove this
        start = time.clock()
        self.simulator = CBDsimulator(self.model)
        end = time.clock()
        print("Time taken to build simulator: " + str(end - start) + " seconds")

        opt = opt_name(self.simulator, self.mh)
        self.model = opt.optimize(self.model)

        start = time.clock()
        CBDToH = CBDToHimesis()
        h = CBDToH.convert(self.model)
        h2 = CBDToH.convert(self.model, False)
        h.compile("himesis/")
        end = time.clock()
        print("Time taken for CBD to Himesis: " + str(end - start) + " seconds")

        if not self.mh == None:

            start = time.clock()
            simulinkExport = SimulinkExporter(model, self.mh, h)
            simulinkExport.exportSimulink()
            end = time.clock()
            print("Time taken to export to Simulink: " + str(end - start) + " seconds")

            self.mh.endLib()
Пример #3
0
    def transform(self, model, analysis):
    
        #do code transformation
        if self.useModelTransformation:
            
            transformation = "flattening"
            path = "./examples/"
            
            model_name = model.getBlockName()
            model_name = Himesis.standardize_name(model_name)
            
            if not self.mh == None:
                # Transfornation to T-Core
                transformationToHimesis = SimulinkTransformationToHimesis(transformation, path, self.mh)
                transformationToHimesis.SimulinkTransformationModelToHimesis()
            
            
            # Execute the Transformation
            model_graph = self.get_object('./himesis/' + model_name + ".py")
            
            packet = Packet()
            packet.graph = model_graph
            

            exec("import temp.T_" + transformation)
            exec('packet = temp.T_'+ transformation +'.packet_in(packet)')
            
            print(packet)

        else:
        
            for depth in sorted(analysis.keys()):
            
                subsystem = analysis[depth]
                print("Subsystem Name: " + subsystem.getBlockName() + " at depth: " + str(depth))
                
                if len(subsystem.linksIN) == 0:
                    continue
                    
                #TODO: Make these pretty
                self.fix_incoming_edges(model, subsystem)
                self.fix_outgoing_edges(model, subsystem)
                self.remove_subsystem(model, subsystem)

                break
                
        return model