def simulate(self, T = sys.maxint): """Simulate the model (Root-Coordinator). """ ### for all available DEVS package (keys of built-in DEVS_DIR_PATH_DICT dictionary) for pydevs_dir in __builtin__.__dict__['DEVS_DIR_PATH_DICT']: ### only the selected one if pydevs_dir == __builtin__.__dict__['DEFAULT_DEVS_DIRNAME']: path = __builtin__.__dict__['DEVS_DIR_PATH_DICT'][pydevs_dir] ### split from DEVSKernel string and replace separator with point d = re.split("DEVSKernel", path)[-1].replace(os.sep, '.') exec "from DEVSKernel%s.simulator import Simulator"%d S = Simulator(self._simulator.model) ### old version of PyPDEVS if len(inspect.getargspec(S.simulate).args) > 1: kwargs = {'verbose':True} ### TODO if self._simulator.ntl: kwargs['termination_condition'] = terminate_never else: kwargs['termination_time'] = T S.simulate(**kwargs) ### new version of PyPDEVS (due to the number of config param which is growing) else: ### see simconfig.py to have informations about setters ### verbose manager, if None print are displayed in stdout, else in the out/verbose.txt file if self._simulator.verbose: S.setVerbose(None) else: out_dir = os.path.join(HOME_PATH, 'out') if not os.path.exists(out_dir): os.mkdir(out_dir) verbose_file = os.path.join(getOutDir(), 'verbose.txt') S.setVerbose(verbose_file) ### TODO if self._simulator.ntl: S.setTerminationCondition(terminate_never) else: S.setTerminationTime(T) S.setClassicDEVS(self.SetClassicDEVSOption()) ### dynamic structure for local PyPDEVS simulation S.setDSDEVS(self._simulator.dynamic_structure_flag) #S.setRealTime() S.simulate() self._simulator.terminate()
def simulate(self, T=sys.maxint): """Simulate the model (Root-Coordinator). """ ### for all available DEVS package (keys of built-in DEVS_DIR_PATH_DICT dictionary) for pydevs_dir in __builtin__.__dict__['DEVS_DIR_PATH_DICT']: ### only the selected one if pydevs_dir == __builtin__.__dict__['DEFAULT_DEVS_DIRNAME']: path = __builtin__.__dict__['DEVS_DIR_PATH_DICT'][pydevs_dir] ### split from DEVSKernel string and replace separator with point d = re.split("DEVSKernel", path)[-1].replace(os.sep, '.') exec "from DEVSKernel%s.simulator import Simulator" % d S = Simulator(self._simulator.model) ### old version of PyPDEVS if len(inspect.getargspec(S.simulate).args) > 1: kwargs = {'verbose': True} ### TODO if self._simulator.ntl: kwargs['termination_condition'] = terminate_never else: kwargs['termination_time'] = T S.simulate(**kwargs) ### new version of PyPDEVS (due to the number of config param which is growing) else: ### see simconfig.py to have informations about setters ### verbose manager, if None print are displayed in stdout, else in the out/verbose.txt file if self._simulator.verbose: S.setVerbose(None) else: out_dir = os.path.join(HOME_PATH, 'out') if not os.path.exists(out_dir): os.mkdir(out_dir) verbose_file = os.path.join(getOutDir(), 'verbose.txt') S.setVerbose(verbose_file) ### TODO if self._simulator.ntl: S.setTerminationCondition(terminate_never) else: S.setTerminationTime(T) S.setClassicDEVS(self.SetClassicDEVSOption()) #S.setRealTime() S.simulate() self._simulator.terminate()
def makeDEVSConf(model, liaison, addInner, filename): """ Make conf file from D graph of the diagram for visualization on web site """ sys.stdout.write("Setting file...\n") text = "" forme_model = {"var":0,"x":1,"y":2,"in":3,"out":4,"dim_width":5,"dim_height":6} # Calcul de la hauteur du plus grand diagramme # Recuperation du plus grand diagramme, pour modifier sa hauteur m_x = 0 m_y = 0 labelDiagramme = "" for m in model: if model[m][forme_model["x"]] > m_x: m_x = model[m][forme_model["x"]] if model[m][forme_model["y"]] > m_y: m_y = model[m][forme_model["y"]] if model[m][forme_model["y"]] == 20 and model[m][forme_model["x"]] == 20: labelDiagramme = m var = model[m][forme_model["var"]] m_y = m_y + 120 m_x = m_x + 150 lenComp = len(labelDiagramme) tmp = posDimDefine(lenComp, 0)[:1][0] model[labelDiagramme][forme_model["dim_height"]] = m_y model[labelDiagramme][forme_model["dim_width"]] = m_x oldWidth = 1300 + tmp newWidth = m_x + tmp # oldHeight = 300 # newHeight = # print "newWidth : ", newWidth , " - m_x : " , m_x , " - tmp : " , tmp var = var.replace(", width: " + str(oldWidth) + ", ", ", width: " + str(newWidth) + ", ") var = var.replace(", height: 300},", ", height: " + str(m_y) + "},") model[labelDiagramme][forme_model["var"]] = var # Config du diagramme title = "Discrete Event System Specification" description = 'Description du diagramme.' dimension = 'dimension(1200,560)' #Total des largeurs et hauteurs du "canvas" if newWidth < 1200: dim_width = 1200 elif newWidth >= 1200: dim_width = newWidth + 40 if newWidth < 1200: dim_height = 1200 elif newWidth >= 1200: dim_height = m_y + 40 devs = '\nvar devs = Joint.dia.devs;\nJoint.paper("world", ' + str(dim_width) + ', ' + str(dim_height) + ');' arrow = '\nvar arrow = devs.arrow;' text = text + 'title(\''+title+'\');' + '\n' +'description(\''+ description+'\');' + '\n' +dimension+ ';\n' + devs str_model = "\n\n" for m in model: str_model = str_model + model[m][forme_model["var"]] # print model[m] # print "Next :" text = text + str_model str_addInner = "\n\n" for i in addInner: str_addInner = str_addInner + i + "\n" text = text + str_addInner text = text + arrow str_liaison = "\n\n" for l in liaison: str_liaison = str_liaison + l text = text + str_liaison ### js file is stored in out directory fn = os.path.join(getOutDir(), filename) ### file exist ? update = os.path.exists(fn) try: with open(fn, "wb") as f: f.write(text) except: sys.stdout.write("%s file not %s.\n"%(fn, 'updated' if update else 'completed')) else: sys.stdout.write("%s file %s.\n"%(fn, 'updated' if update else 'completed'))
def makeDEVSConf(model, liaison, addInner, filename): """ Make conf file from D graph of the diagram for visualization on web site """ sys.stdout.write("Setting file...\n") text = "" forme_model = { "var": 0, "x": 1, "y": 2, "in": 3, "out": 4, "dim_width": 5, "dim_height": 6 } # Calcul de la hauteur du plus grand diagramme # Recuperation du plus grand diagramme, pour modifier sa hauteur m_x = 0 m_y = 0 labelDiagramme = "" for m in model: if model[m][forme_model["x"]] > m_x: m_x = model[m][forme_model["x"]] if model[m][forme_model["y"]] > m_y: m_y = model[m][forme_model["y"]] if model[m][forme_model["y"]] == 20 and model[m][ forme_model["x"]] == 20: labelDiagramme = m var = model[m][forme_model["var"]] m_y = m_y + 120 m_x = m_x + 150 lenComp = len(labelDiagramme) tmp = posDimDefine(lenComp, 0)[:1][0] model[labelDiagramme][forme_model["dim_height"]] = m_y model[labelDiagramme][forme_model["dim_width"]] = m_x oldWidth = 1300 + tmp newWidth = m_x + tmp # oldHeight = 300 # newHeight = # print "newWidth : ", newWidth , " - m_x : " , m_x , " - tmp : " , tmp var = var.replace(", width: " + str(oldWidth) + ", ", ", width: " + str(newWidth) + ", ") var = var.replace(", height: 300},", ", height: " + str(m_y) + "},") model[labelDiagramme][forme_model["var"]] = var # Config du diagramme title = "Discrete Event System Specification" description = 'Description du diagramme.' dimension = 'dimension(1200,560)' #Total des largeurs et hauteurs du "canvas" if newWidth < 1200: dim_width = 1200 elif newWidth >= 1200: dim_width = newWidth + 40 if newWidth < 1200: dim_height = 1200 elif newWidth >= 1200: dim_height = m_y + 40 devs = '\nvar devs = Joint.dia.devs;\nJoint.paper("world", ' + str( dim_width) + ', ' + str(dim_height) + ');' arrow = '\nvar arrow = devs.arrow;' text = text + 'title(\'' + title + '\');' + '\n' + 'description(\'' + description + '\');' + '\n' + dimension + ';\n' + devs str_model = "\n\n" for m in model: str_model = str_model + model[m][forme_model["var"]] # print model[m] # print "Next :" text = text + str_model str_addInner = "\n\n" for i in addInner: str_addInner = str_addInner + i + "\n" text = text + str_addInner text = text + arrow str_liaison = "\n\n" for l in liaison: str_liaison = str_liaison + l text = text + str_liaison ### js file is stored in out directory fn = os.path.join(getOutDir(), filename) ### file exist ? update = os.path.exists(fn) try: with open(fn, "wb") as f: f.write(text) except: sys.stdout.write("%s file not %s.\n" % (fn, 'updated' if update else 'completed')) else: sys.stdout.write("%s file %s.\n" % (fn, 'updated' if update else 'completed'))
def simulate(self, T=100000000): """Simulate the model (Root-Coordinator). """ path = builtins.__dict__['DEVS_DIR_PATH_DICT'][ builtins.__dict__['DEFAULT_DEVS_DIRNAME']] d = re.split("DEVSKernel", path)[-1].replace(os.sep, '.') simulator = importlib.import_module("DEVSKernel%s.simulator" % d) #exec("from DEVSKernel%s.simulator import Simulator"%d) S = simulator.Simulator(self._simulator.model) ### old version of PyPDEVS if len(inspect.getargspec(S.simulate).args) > 1: kwargs = {'verbose': True} ### TODO if self._simulator.ntl: kwargs['termination_condition'] = terminate_never else: kwargs['termination_time'] = T S.simulate(**kwargs) ### new version of PyPDEVS (due to the number of config param which is growing) else: ### see simconfig.py to have informations about setters ### verbose manager, if None print are displayed in stdout, else in the out/verbose.txt file if self._simulator.verbose: S.setVerbose(None) else: out_dir = os.path.join(HOME_PATH, 'out') if not os.path.exists(out_dir): os.mkdir(out_dir) verbose_file = os.path.join(getOutDir(), 'verbose.txt') S.setVerbose(verbose_file) ### TODO if self._simulator.ntl: S.setTerminationCondition(terminate_never) else: S.setTerminationTime(T) S.setClassicDEVS(self.SetClassicDEVSOption()) ### dynamic structure for local PyPDEVS simulation S.setDSDEVS(self._simulator.dynamic_structure_flag) #S.setMemoization(self._simulator.memoization_flag) ### real time simulation if self._simulator.real_time_flag: S.setRealTime(self._simulator.real_time_flag) S.setRealTimeInputFile(None) #S.setRealTimePorts(refs) S.setRealTimePlatformThreads() S.simulate() self._simulator.terminate()