Ejemplo n.º 1
0
    def _random_solution(self):
        valid = False
        while not valid:
            months = []
            for month in self._months:
                months.append({'month': month,
                              'value': bool(random.randint(0, 1))})

            s_vars = []
            for var in self._variables:
                s_vars.append({'variable': var,
                               'value': bool(random.randint(0, 1))})

            solution = ScatterPhenoScenario(months, s_vars, self._data)
            valid = solution.valid(process=self._process)

        return solution
Ejemplo n.º 2
0
    def swap(self, scenario, index, index2):
        """Builds new solution where the values
        on index and index2 are swapped
        """
        months = deepcopy(scenario._all_months)
        variables = deepcopy(scenario._all_variables)

        solution = months + variables
        temp = solution[index]['value']
        solution[index]['value'] = solution[index2]['value']
        solution[index2]['value'] = temp

        new_scenario = ScatterPhenoScenario(months, variables, self._data)
        return new_scenario
Ejemplo n.º 3
0
    def _hardcoded_solution(self, value):
        months = []
        for month in self._months:
            months.append({'month': month,
                          'value': value})

        s_vars = []
        for var in self._variables:
            s_vars.append({'variable': var,
                           'value': value})

        solution = ScatterPhenoScenario(months, s_vars, self._data)

        return solution
Ejemplo n.º 4
0
    def flip(self, scenario, score_entry):
        """Builds new solution where the variable in score_entry is flipped"""
        months = deepcopy(scenario._all_months)
        variables = deepcopy(scenario._all_variables)

        if score_entry['type'] == 'month':
            match = next(x for x in months
                         if x['month'] == score_entry['name'])
        elif score_entry['type'] == 'variable':
            match = next(x for x in variables
                         if x['variable'] == score_entry['name'])
        else:
            raise Exception("Unhandled type %s" % score_entry['type'])

        match['value'] = not match['value']

        new_scenario = ScatterPhenoScenario(months, variables, self._data)
        return new_scenario