def match(self, situation):
<EOL>by_action = {}<EOL>for condition, actions in self._population.items():<EOL><INDENT>if not condition(situation):<EOL><INDENT>continue<EOL><DEDENT>for action, rule in actions.items():<EOL><INDENT>if action in by_action:<EOL><INDENT>by_action[action][condition] = rule<EOL><DEDENT>else:<EOL><INDENT>by_action[action] = {condition: rule}<EOL><DEDENT><DEDENT><DEDENT>match_set = MatchSet(self, situation, by_action)<EOL>if self._algorithm.covering_is_required(match_set):<EOL><INDENT>rule = self._algorithm.cover(match_set)<EOL>assert rule.condition(situation)<EOL>replaced = self.add(rule)<EOL>for replaced_rule in replaced:<EOL><INDENT>action = replaced_rule.action<EOL>condition = replaced_rule.condition<EOL>if action in by_action and condition in by_action[action]:<EOL><INDENT>del by_action[action][condition]<EOL>if not by_action[action]:<EOL><INDENT>del by_action[action]<EOL><DEDENT><DEDENT><DEDENT>if rule.action not in by_action:<EOL><INDENT>by_action[rule.action] = {}<EOL><DEDENT>by_action[rule.action][rule.condition] = rule<EOL>match_set = MatchSet(self, situation, by_action)<EOL><DEDENT>return match_set<EOL>
Accept a situation (input) and return a MatchSet containing the
        classifier rules whose conditions match the situation. If
        appropriate per the algorithm managing this classifier set, create
        new rules to ensure sufficient coverage of the possible actions.

        Usage:
            match_set = model.match(situation)

        Arguments:
            situation: The situation for which a match set is desired.
        Return:
            A MatchSet instance for the given situation, drawn from the
            classifier rules in this classifier set.