Example #1
0
class Blue_collar(HumanType):
    def __init__(self, _id):
        HumanType.__init__(self, _id)
        self._id = _id
        self.out_time = TimeStructContstraintToDay(
            6, 22, Statistic(RANDOM_SEED + _id, AVG_TIME, TIME_STDDEV))
        #self.out_time = TimeStructContstraintToDayDeterministic(6,22)
        self.trash = Statistic(RANDOM_SEED + _id, AVG_TRASH, TRASH_STDDEV)
        pass

    def get_type(self):
        return "Blue_collar"

    def get_wakeup(self):
        return TimeStruct(6, 22, Statistic(RANDOM_SEED, AVG_TIME, TIME_STDDEV))

    def get_sleep(self):
        return TimeStruct(23, 35, Statistic(RANDOM_SEED, AVG_TIME,
                                            TIME_STDDEV))

    def get_out(self):
        return self.out_time

    def get_in(self):
        return TimeStruct(17, 30, Statistic(RANDOM_SEED, 0, 1))

    def get_trash(self):
        return self.trash.get_delta()

    def get_satisfaction_func(self, trash):
        """if trash >0:
                                    return -10
                                else:
                                    return 10"""

        if trash >= 0.8:
            return -10
        elif trash <= 0:
            return 20
        elif trash < 0.8:
            return 10

    def is_vacation(self):
        return False

    def init_seed(self, h_id):
        self.out_time = TimeStructContstraintToDay(
            6, 22, Statistic(h_id, AVG_TIME, TIME_STDDEV))
        self.trash = Statistic(h_id, AVG_TRASH, TRASH_STDDEV)
Example #2
0
class Student(HumanType):
    def __init__(self, _id):
        HumanType.__init__(self, _id)
        self._id = _id
        self.out_time = TimeStructContstraintToDay(
            7, 58, Statistic(RANDOM_SEED + _id, AVG_TIME, TIME_STDDEV))
        self.trash = Statistic(RANDOM_SEED + _id, AVG_TRASH, TRASH_STDDEV)
        pass

    def get_type(self):
        return "Student"

    def get_wakeup(self):
        return TimeStruct(7, 58, Statistic(RANDOM_SEED, AVG_TIME, TIME_STDDEV))

    def get_sleep(self):
        return TimeStruct(24, 51, Statistic(RANDOM_SEED, AVG_TIME,
                                            TIME_STDDEV))

    def get_out(self):
        return self.out_time

    def get_in(self):
        return TimeStruct(21, 00, Statistic(RANDOM_SEED, 0, 1))

    def get_trash(self):
        return self.trash.get_delta()

    def get_satisfaction_func(self, trash):
        if trash >= 0.8:
            return -10
        elif trash <= 0:
            return 20
        elif trash < 0.8:
            return 10

    def is_vacation(self):
        return False

    def init_seed(self, h_id):
        self.out_time = TimeStructContstraintToDay(
            7, 58, Statistic(h_id, AVG_TIME, TIME_STDDEV))
        self.trash = Statistic(h_id, AVG_TRASH, TRASH_STDDEV)
Example #3
0
class Homemaker(HumanType):
    def __init__(self, _id):
        HumanType.__init__(self, _id)
        self._id = _id
        self.out_time = TimeStructContstraintToDay(
            13, 00, Statistic(RANDOM_SEED + _id, AVG_TIME, TIME_STDDEV))
        #self.out_time = TimeStructContstraintToDayDeterministic(13,00)
        #self.out_time= TimeStructConstraintRandom(self.get_wakeup(), self.get_sleep(), Statistic(0, 10, 6))
        self.trash = Statistic(RANDOM_SEED + _id, AVG_TRASH, TRASH_STDDEV)
        pass

    def get_type(self):
        return "Homemaker"

    def get_wakeup(self):
        return TimeStruct(6, 17, Statistic(RANDOM_SEED, AVG_TIME, TIME_STDDEV))

    def get_sleep(self):
        return TimeStruct(23, 21, Statistic(RANDOM_SEED, AVG_TIME,
                                            TIME_STDDEV))

    def get_out(self):
        return self.out_time
        #return TimeStructConstraintRandom(self.get_wakeup(), self.get_sleep(), Statistic(0, 10, 6))

    def get_in(self):
        return TimeStruct(15, 0, Statistic(RANDOM_SEED, 0, 1))
        """
                            def get_trash(self):
                                ev_t=SystemSimulator().get_engine("sname").get_global_time()
                                ev_t= ev_t-int(ev_t /8762)*8762
                                if ev_t>=8280:
                                    if ev_t <=8760:
                                        return 2.4
                                else:
                                    return 1.2
        """

    def get_trash(self):
        return self.trash.get_delta()

    def get_satisfaction_func(self, trash):
        if trash >= 0.8:
            return -10
        elif trash <= 0:
            return 20
        elif trash < 0.8:
            return 10
        """
        if trash >0:
            return -10
        else:
            return 10
        """

    def is_vacation(self):
        return False

    def init_seed(self, h_id):
        self.out_time = TimeStructContstraintToDay(
            13, 00, Statistic(h_id, AVG_TIME, TIME_STDDEV))
        # self.out_time = TimeStructContstraintToDayDeterministic(13,00)
        # self.out_time= TimeStructConstraintRandom(self.get_wakeup(), self.get_sleep(), Statistic(0, 10, 6))
        self.trash = Statistic(h_id, AVG_TRASH, TRASH_STDDEV)
Example #4
0
class Check(BehaviorModelExecutor):
    def __init__(self, instance_time, destruct_time, name, engine_name, htype):
        BehaviorModelExecutor.__init__(self, instance_time, destruct_time,
                                       name, engine_name)

        self.init_state("IDLE")
        self.insert_state("IDLE", Infinite)
        self.insert_state("CHECK", 0)
        self.insert_state("REPORT", 0)

        self.insert_input_port("request")
        self.insert_input_port("checked")  # from garbage can

        self.insert_output_port("check")  # to garbage can
        self.insert_output_port("gov_report")
        self.htype = htype
        #print(self.htype.get_id()+RANDOM_SEED,file=sys.__stdout__)
        from UI.config import RANDOM_SEED
        self.stat = Statistic(RANDOM_SEED + self.htype.get_id(), 20,
                              4)  # Satisfaction mean and stddev
#        self.satis_func = satis_func
#        self.satisfaction = 100
#        self.hid = hid

    def get_satis(self, trash):
        if trash > 0.5:
            return -10
        else:
            return 10
        pass

    def ext_trans(self, port, msg):
        if self.htype.is_vacation():
            self.htype.satisfaction = None
            pass
        else:
            if port == "request":
                self._cur_state = "CHECK"

            if port == "checked":
                if self.htype.satisfaction == None:
                    self.htype.satisfaction = 100
                    self.htype.satisfaction += self.htype.get_satisfaction_func(
                        msg.retrieve()[0])
                else:
                    #    self.htype.satisfaction += self.htype.get_satisfaction_func(msg.retrieve()[0])
                    self.htype.satisfaction += self.get_satis(
                        msg.retrieve()[0])

                if self.htype.satisfaction >= 100:
                    self.htype.satisfaction = 100
                if self.htype.satisfaction < 0:
                    self.htype.satisfaction += self.stat.get_delta()
                    self._cur_state = "REPORT"
                #print(self.htype.)
                #print(SystemSimulator().get_engine("sname").get_global_time(),"[check] "+self.get_name() + ":" + str(self.htype.satisfaction),file=sys.__stdout__)

    def output(self):
        if self._cur_state == "CHECK":
            if self.htype.is_vacation():
                self.htype.satisfaction = None
                return None
            else:
                msg = SysMessage(self.get_name(), "check")
                msg.insert(self.htype)
                return msg

        if self._cur_state == "REPORT":
            #print('[check]#')
            msg = SysMessage(self.get_name(), "gov_report")
            msg.insert(self.htype)
            return msg

        return None

    def int_trans(self):
        if self._cur_state == "CHECK":
            self._cur_state = "IDLE"
        elif self._cur_state == "REPORT":
            self._cur_state = "IDLE"