Пример #1
0
    def next(self, state, **runopts):
        bqm = state.problem

        if self.size > len(bqm):
            raise ValueError("subproblem size cannot be greater than the problem size")

        variables = select_random_subgraph(bqm, self.size)
        sample = state.samples.change_vartype(bqm.vartype).first.sample
        subbqm = bqm_induced_by(bqm, variables, sample)
        return state.updated(subproblem=subbqm)
Пример #2
0
    def next(self, state, **runopts):
        bqm = state.problem

        size = self.size
        if size > len(bqm):
            logger.debug("{} subproblem size greater than the problem size, "
                         "adapting to problem size".format(self.name))
            size = len(bqm)

        variables = select_random_subgraph(bqm, size)
        sample = state.samples.change_vartype(bqm.vartype).first.sample
        subbqm = bqm_induced_by(bqm, variables, sample)

        logger.debug("{} selected {} subproblem variables: {!r}".format(
            self.name, len(variables), variables))
        return state.updated(subproblem=subbqm)