Set weight for rule in :attr:`R`.

        Adds the rule if it is not in :attr:`R`.

def set_weight(self, rule, weight):
        """Set weight for rule in :attr:`R`.

        Adds the rule if it is not in :attr:`R`.
        """
        if not issubclass(rule.__class__, (Rule, RuleLeaf)):
            raise TypeError("Rule to set weight ({}) is not subclass "
                            "of {} or {}.".format(rule, Rule, RuleLeaf))
        assert (weight >= -1.0 and weight <= 1.0)
        try:
            ind = self._R.index(rule)
            self._W[ind] = weight
        except:
            self.add_rule(rule, weight)