Esempio n. 1
0
 def __init__(self, planlib, goal=None):
     """ Assigns variables for this class, I'm assuming here that planlib is a set of Actions (from the planlib module)"""
     super(basic_norm_detector,self).__init__(planlib)
     self.reinitialise()
     self.past_observations = [] # Make sure this is not in reinitialise, since this will mess up with the #learn_norms algorithm below
     if(goal == None):
         self.goal=Goal(start_nodes(planlib).pop(), goal_nodes(planlib).pop())
     else:
         self.goal = goal
Esempio n. 2
0
 def gen_scenario_large(self, prob_non_compliance=0.01, prob_viol_detection=0.99, \
                 prob_sanctioning=0.99, prob_random_punishment=0.01):
     planlib = dot_to_plan_library('large-planlib.dot')
     goal = Goal(
         list(start_nodes(planlib))[0],
         list(goal_nodes(planlib))[0])
     norms = self.nb.parse_norms('large-norms.txt')
     scenario = Scenario(norms, planlib, goal, prob_non_compliance, prob_viol_detection, \
                 prob_sanctioning, prob_random_punishment)
     return scenario
Esempio n. 3
0
 def __init__(self,planlib, goal=None):
     super(threshold_norm_detector,self).__init__(planlib)
     self.planlib = planlib
     self.ot = 0.5 # Threshold for obligations
     self.ft = 0.5 # Threshold for prohibitions
     self.reinitialise()
     self.past_observations = []
     self.goal = goal
     if(goal == None):
         self.goal=Goal(start_nodes(planlib).pop(), goal_nodes(planlib).pop())
     else:
         self.goal = goal
Esempio n. 4
0
    def generate_random_observations(self,
                                     norm_detector,
                                     scenario,
                                     runs,
                                     shift_goals=False,
                                     violation_signal=True):
        """Generates random observations for a particular norm representation"""
        s_nodes = start_nodes(norm_detector.planlib)
        goals = goal_nodes(norm_detector.planlib)
        goal = norm_detector.get_goal().end
        observations = []
        for i in range(runs):
            node = random.sample(s_nodes, 1)[0]
            if (shift_goals):
                goal = None  # Need to try goals until we find a compliant one
                while goal is None:
                    if (len(goals) == 0):
                        #log.warning("No goals possible under current norms, skipping initial node")
                        print "No goals possible under current norms, skipping initial node"
                        node = random.sample(s_nodes, 1)[0]
                        continue
                    goal = random.sample(goals, 1)[0]
                    if not self.goal_is_possibly_compliant(
                            norm_detector, goal, node, scenario.norms):
                        goals.remove(
                            goal
                        )  #remove this goal from possible ones to make sure we don't get stuck here
                        goal = None

            plan = self.choose_norm_compliant_plan_with_prob(
                norm_detector, goal, node, scenario.norms,
                scenario.prob_non_compliance
            )  # TODO Here I should add the probability of detection/sanctioning

            if (violation_signal):
                plan = self.annotate_violation_signals(
                    plan, norm_detector, scenario.norms
                )  #TODO Here I should add the probability of random punishment
            observations.append(plan)
        return observations
Esempio n. 5
0
 def goal_nodes(self, norm_detector):
     """Just forward the call to the function in planlib"""
     return goal_nodes(norm_detector.planlib)