Exemple #1
0
    def calc_gen(self, gen):
        fitnessless = gen.get_fitlessness()
        if len(fitnessless) == 0:
            return
        tick_tack = ReplaySubject()
        fset = seq(fitnessless) \
            .map(lambda wchr: (wchr['name'], wchr['id'])) \
            .to_set()
        results = []

        def remove_fset(result):
            wchr, fit = result
            tp = wchr['name'], wchr['id']
            if tp in fset:
                fset.discard(tp)
                results.append(result)
            if len(fset) == 0:
                tick_tack.on_next(0)

        s1 = self.executor.sub_compl.subscribe(on_next=remove_fset)

        for fn in fitnessless:
            self.executor.sub_in.on_next(fn)
        if len(fset) == 0:
            tick_tack.on_next(0)
        tick_tack.to_blocking().first()

        tick_tack.dispose()
        s1.dispose()

        gen.init_fitnesses(results)
        if len(gen.get_fitlessness()) > 0:
            raise AssertionError("Посчитались не все гены в хромосоме")
Exemple #2
0
    def wait_compl_ids(self, ids):
        ids = set(ids)
        tick_tack = ReplaySubject()

        def onn(id):
            ids.discard(id)
            if len(ids) == 0:
                tick_tack.on_completed()

        s3 = self.compl_task_id_subject.subscribe(on_next=onn)
        for i in self.compl_tasks_ids:
            ids.discard(i)
        if len(ids) == 0:
            tick_tack.on_next(0)

        tick_tack.to_blocking().first_or_default(0)
        s3.dispose()