def __init__(self, nname, env): super().__init__(nname) conf = Configuration() self.queue = Store(env) self.tcomm = conf.get('[comm]t_comm') self.perr = conf.get('[comm]p_err') self.unavail = conf.get('[comm]unavail')
def mergeMTTRS(components): retval = list() conf = Configuration() for comp in components: name = str(comp[0]).lower() mttr = conf.get('[rbc]' + name + '_mttr') new = (*comp, mttr) retval.append(new) return retval
def run(self): # loading configuration files self.argumentFactory.setup(self.inifiles,self.indices) # running executor Configuration().put('logtemplate',self.logTemplate) self.executor = Configuration().get('executor') ret = self.executor.execute(self) # Post running report = ret.mean() report = ret.tocsv(report) self.writeIntoIndices(report)
def __init__(self, nname, mmtbf=0, mmttr=0): super().__init__(nname) self.owner = None self.mtbf = mmtbf self.mttr = mmttr conf = Configuration() self.finalTime = conf.get('stoptime') self.working = True self.process = self.env.process(self.run()) self.faultStartTime = self.env.now self.repairStartTime = self.env.now self.repairman = Blackboard().get('maintainers')
def execute(self, simulator): retval = Analyser() c = Configuration() stop = c.get('stoptime') stopcondition = False counter = 0 while (not stopcondition): self.mark('ITERATION', counter) logname = c.get('logtemplate') + '.' + str(counter) record = simulator.main(logname, stop) retval.add(record) stopcondition = self.computeStopCondition(counter, retval) counter += 1 return retval
def setup(logname): lvl = Configuration().get('logginglevel') lvl = LoggerFactory.diction[lvl] logging.basicConfig(filename=logname, filemode='w', level=lvl, format="%(name)s;%(levelname)s;%(message)s")
def setup(self, iifiles, iindices): cfile = iifiles[0] mfile = iifiles[1] conf = ConfigurationFactory() subs = conf.loadConfiguration(cfile) conf.loadMaintenance(mfile, subs) conf = Configuration() conf.put('indices', iindices)
def computeStopCondition(self, iteration, values): eps = Configuration().get('epsilon') stopcondition = super().computeStopCondition(iteration, values) dim = values.size() if not stopcondition and dim > 5: temp = values.confidence95() diffs = list(map(lambda x: x[1][1] - x[1][0], temp.items())) mids = list(map(lambda x: (x[1][0] + x[1][1]) / 2, temp.items())) deltas = [diffs[i] / mids[i] for i in range(0, len(diffs))] delta = mean(deltas) stopcondition = (delta < eps) return stopcondition
def execute(self, simulator): retval = Analyser() conf = Configuration() slaves = conf.get('slaves') iters = conf.get('experiments') q = Queue() s = Semaphore(slaves) counters = range(0, iters) payloads = list(map(lambda cnt: (simulator, conf, cnt, q, s), counters)) processes = list() for payload in payloads: p = Process(target=self.core, args=(payload, )) processes.append(p) p.start() for process in processes: process.join() for c in counters: ret = q.get() if not ret is None: retval.add(ret) return retval
def loadScenario(self, enviro): numberOfEvcs = Configuration().get('[ertms]evcs') numberOfRbcs = Configuration().get('[ertms]rbcs') toETCS = Store(enviro) rbcs = list() comms = list() evcs = list() for i in range(0, numberOfRbcs): rname = 'RBC_' + str(i) rbc = RBC(rname, toETCS) rbcs.append(rbc) rbcCounter = 0 for i in range(0, numberOfEvcs): cname = 'COMM_' + str(i) comm = Comm(cname, enviro) comms.append(comm) ename = 'EVC_' + str(i) evc = EVC(ename, comm, toETCS) evcs.append(evc) logicname = 'LOGIC_' + str(rbcCounter) + '_to_' + str(i) rbcs[rbcCounter].addBehaviour(logicname, comm) rbcCounter = (rbcCounter + 1) % numberOfRbcs etcs = ETCS('ETCS', toETCS, numberOfRbcs, numberOfEvcs)
def core(self, payload): simulator, oldconf, counter, queue, sem = payload with sem: conf = Configuration() conf.mergeBoard(oldconf) stop = conf.get('stoptime') logname = conf.get('logtemplate') + '.' + str(counter) record = simulator.main(logname, stop) queue.put(record)
class Simulation(): def __init__(self, infiles, logs, iindices, factory): self.inifiles = infiles self.logTemplate = logs self.indices = iindices self.executor = None self.argumentFactory = factory def run(self): # loading configuration files self.argumentFactory.setup(self.inifiles,self.indices) # running executor Configuration().put('logtemplate',self.logTemplate) self.executor = Configuration().get('executor') ret = self.executor.execute(self) # Post running report = ret.mean() report = ret.tocsv(report) self.writeIntoIndices(report) def writeIntoIndices(self, rep): fhandle = open(self.indices, 'w') fhandle.write(rep) fhandle.close() def main(self,logname,stop): # environment setup enviro = Environment() Blackboard().put('enviro', enviro) # start recorder record = Recorder() record.reset() # setup maintenance maintainers = MaintainersFactroy.generate(Configuration().get('[main]maintainers')) Blackboard().put('maintainers', maintainers) # setup of the simulation LoggerFactory.setup(logname) watchdog = WatchDogFactory.generate() self.loadScenario(enviro) # start the simulation eve = watchdog.getTrigger() timeout = enviro.timeout(stop) simulationStop = enviro.any_of([timeout,eve]) enviro.run(simulationStop) # stop the simulation LoggerFactory.shutdown() retval = record.generateRecord() return retval
def generate(): conf = Configuration() ttimeout = conf.get('watchdog[period]') rratio = conf.get('watchdog[monitorperiod]') rratioFlag = conf.get('watchdog[monitorflag]') finalTime = conf.get('stoptime') ttimeoutFlag = ttimeout != 0 period = rratio * finalTime enviro = Blackboard().get('enviro') wd = WatchDog(ttimeoutFlag, ttimeout, period, rratioFlag, enviro) return wd
def main(self,logname,stop): # environment setup enviro = Environment() Blackboard().put('enviro', enviro) # start recorder record = Recorder() record.reset() # setup maintenance maintainers = MaintainersFactroy.generate(Configuration().get('[main]maintainers')) Blackboard().put('maintainers', maintainers) # setup of the simulation LoggerFactory.setup(logname) watchdog = WatchDogFactory.generate() self.loadScenario(enviro) # start the simulation eve = watchdog.getTrigger() timeout = enviro.timeout(stop) simulationStop = enviro.any_of([timeout,eve]) enviro.run(simulationStop) # stop the simulation LoggerFactory.shutdown() retval = record.generateRecord() return retval
def __init__(self, nname, ch): super().__init__(nname) self.channel = ch self.matime = Configuration().get('[comm]ma_time')
def __init__(self, nname, toetcs): conf = Configuration() comp = conf.get('[rbc]structure') mttr = conf.get('[rbc]top_mttr') comp = mergeMTTRS(comp) self.structure = RHardware(nname, comp, mttr, [toetcs])
def computeStopCondition(self, iteration, values): iters = Configuration().get('experiments') stopcondition = (iteration == iters) return stopcondition
def __init__(self, nname): super().__init__(nname) self.onrun = True self.infinite = Configuration().get('stoptime') self.process = self.env.process(self.run())