Ejemplo n.º 1
0
 def __init__(self, name = "Processor", t_event1 = 1, iterations = 0):
     AtomicDEVS.__init__(self, name)
     self.t_event1 = t_event1
     self.inport = self.addInPort("inport")
     self.outport = self.addOutPort("outport")
     self.state = ModelState()
     self.iterations = iterations
Ejemplo n.º 2
0
 def __init__(self, name="Processor", t_event1=1, iterations=0):
     AtomicDEVS.__init__(self, name)
     self.t_event1 = t_event1
     self.inport = self.addInPort("inport")
     self.outport = self.addOutPort("outport")
     self.state = ModelState()
     self.iterations = iterations
    def __init__(self, market, identifier):
        AtomicDEVS.__init__(self, identifier)
        self.market = market
        self.identifier = identifier

        self.last_current_time = 0.0
        self.time_advance = float('inf')

        self.last_transition = None  # [internal, external]
        self.last_elapsed = 0.0

        self.in_agent = self.addInPort("in_agent")
        self.in_orderbook = self.addInPort("in_orderbook")

        self.out_next = self.addOutPort("out_next")
        self.out_notify_order = self.addOutPort("out_notify_order")
        output_ports_map = {
            'out_next': getattr(self, 'out_next'),
            'out_notify_order': getattr(self, 'out_notify_order')
        }
        strategy_params = {
            'identifier': identifier + '_strategy',
            'output_ports_map': output_ports_map
        }
        super(JournalVersion1, self).__init__(identifier + '_strategy',
                                              JournalStrategy, strategy_params)
Ejemplo n.º 4
0
    def __init__(self, name="RailwaySegment", L=5000, v_max=100):
        AtomicDEVS.__init__(self, name)
        self.train_in = self.addInPort("train_in")
        self.train_out = self.addOutPort("train_out")
        self.Q_recv = self.addInPort("Q_recv")
        self.Q_sack = self.addOutPort("Q_sack")
        self.Q_rack = self.addInPort("Q_rack")
        self.Q_send = self.addOutPort("Q_send")
        self.UPDATE = self.addInPort("UPDATE")

        self.elapsed = 0.0
        self.state = ("neutral", "neutral")

        self.L = L
        self.v_max = v_max
        self.v_end = 0      # velocity of train when it reaches the end
        self.x_end = 0      # position of train when it reaches the end
        self.train = None
        self.timeArrival = 0
        self.duration = 0
        self.isLightInSight = False
        self.query_id = -1

        self.current_time = 0.0
        self.train_arrival_time = 0.0
        self.transit_times = []
        self.uptime = 0
Ejemplo n.º 5
0
    def __init__(self, name, mean):
        AtomicDEVS.__init__(self, name)
        self.state = OperatorState()
        self.mean = mean

        self.in_product = self.addInPort("in_product")
        self.out_stats = self.addOutPort("out_stats")
Ejemplo n.º 6
0
 def __init__(self, name="Generator", t_gen_event1=1.0):
     AtomicDEVS.__init__(self, name)
     self.state = ModelState()
     # Add an extra variable
     self.state.generated = 0
     self.state.counter = t_gen_event1
     self.t_gen_event1 = t_gen_event1
     self.outport = self.addOutPort("outport")
     self.inport = self.addInPort("inport")
Ejemplo n.º 7
0
 def __init__(self, name = "Generator", t_gen_event1 = 1.0):
     AtomicDEVS.__init__(self, name)
     self.state = ModelState()
     # Add an extra variable
     self.state.generated = 0
     self.state.counter = t_gen_event1
     self.t_gen_event1 = t_gen_event1
     self.outport = self.addOutPort("outport")
     self.inport = self.addInPort("inport")
Ejemplo n.º 8
0
    def __init__(self, name="PollQueue"):
        AtomicDEVS.__init__(self, name)
        self.state = "neutral"
        self.train_in = self.addInPort("train_in")
        self.train_out = self.addOutPort("train_out")
        self.Q_rack = self.addInPort("Q_rack")
        self.Q_send = self.addOutPort("Q_send")
        self.train = None

        self.queue = []
Ejemplo n.º 9
0
    def __init__(self, gen_param, size_param, gen_num):
        AtomicDEVS.__init__(self, "Generator")
        # Output port for the event
        self.out_event = self.addOutPort("out_event")
        # Define the state
        self.state = GeneratorState(gen_num)

        # Parameters defining the generator's behaviour
        self.gen_param = gen_param
        self.size_param = size_param
Ejemplo n.º 10
0
    def __init__(self, name, mean, standardDeviation, seed=1):
        AtomicDEVS.__init__(self, name)
        self.state = OperatorState()
        self.mean = mean
        self.standardDeviation = standardDeviation
        np.random.seed(seed)
        self.seed = np.random.randint(100000000)

        self.in_product = self.addInPort("in_product")
        self.out_stats = self.addOutPort("out_stats")
Ejemplo n.º 11
0
    def __init__(self, nr, proc_param):
        AtomicDEVS.__init__(self, "Processor_%i" % nr)

        self.state = ProcessorState()
        self.in_proc = self.addInPort("in_proc")
        self.out_proc = self.addOutPort("out_proc")
        self.out_finished = self.addOutPort("out_finished")

        # Define the parameters of the model
        self.speed = proc_param
        self.nr = nr
Ejemplo n.º 12
0
    def __init__(self, x, y, x_max, y_max):
        AtomicDEVS.__init__(self, "Cell(%d, %d)" % (x, y))
        
        self.state = CellState(T_AMBIENT)

        # For Cell DEVS tracing
        self.x = x
        self.y = y

        self.inports = [self.addInPort("in_N"), self.addInPort("in_E"), self.addInPort("in_S"), self.addInPort("in_W"), self.addInPort("in_G")]
        self.outport = self.addOutPort("out_T")

        self.taMap = {PH_INACTIVE: INFINITY, PH_UNBURNED: 1.0, PH_BURNING: 1.0, PH_BURNED: INFINITY}
Ejemplo n.º 13
0
    def __init__(self, name="Collector"):
        AtomicDEVS.__init__(self, name)
        self.train_in = self.addInPort("train_in")
        self.Q_recv = self.addInPort("Q_recv")
        self.Q_sack = self.addOutPort("Q_sack")
        self.UPDATE = self.addInPort("UPDATE")

        self.elapsed = 0.0
        self.current_time = 0.0
        self.state = "neutral"
        self.query_id = -1

        self.transit_times = []
Ejemplo n.º 14
0
    def __init__(self, identifier, strategy, strategy_params):
        AtomicDEVS.__init__(self, identifier)
        self.identifier = identifier
        self.strategy = strategy(self, **strategy_params)

        self.last_elapsed = 0.0
        self.last_current_time = 0.0

        self.time_advance = self.strategy.next_wakeup_time
        self.last_time_advance = None

        # I/O Ports
        self.in_order = self.addInPort('in_order')
        self.out_journal = self.addOutPort('out_journal')
Ejemplo n.º 15
0
    def __init__(self, outputs):
        AtomicDEVS.__init__(self, "Queue")
        # Fix the time needed to process a single event
        self.processing_time = 1.0
        self.state = QueueState(outputs)

        # Create 'outputs' output ports
        # 'outputs' is a structural parameter!
        self.out_proc = []
        for i in range(outputs):
            self.out_proc.append(self.addOutPort("proc_%i" % i))

        # Add the other ports: incoming events and finished event
        self.in_event = self.addInPort("in_event")
        self.in_finish = self.addInPort("in_finish")
Ejemplo n.º 16
0
 def __init__(self, name, iterations, totalAtomics, modelnumber, local, remote, percentageremotes):
     AtomicDEVS.__init__(self, name)
     self.inport = self.addInPort("inport")
     self.percentageremotes = percentageremotes
     self.outports = []
     self.totalAtomics = totalAtomics
     self.modelnumber = modelnumber
     for i in xrange(totalAtomics):
         self.outports.append(self.addOutPort("outport_" + str(i)))
     self.state = PHOLDModelState()
     ev = modelnumber
     self.state.event = [[ev, getProcTime(ev)]]
     self.iterations = iterations
     self.local = local
     self.remote = remote
Ejemplo n.º 17
0
    def __init__(self, identifier, strategy, strategy_params):
        AtomicDEVS.__init__(self, identifier)
        self.identifier = identifier
        self.strategy = strategy(self, **strategy_params)

        self.last_elapsed = 0.0
        self.last_current_time = 0.0

        self.time_advance = self.strategy.next_wakeup_time
        self.last_time_advance = None

        # I/O Ports
        self.in_notify_order = self.addInPort("in_notify_order")
        self.in_next = self.addInPort("in_next")
        self.out_order = self.addOutPort("out_order")
        self.output_ports = {'out_order'}
Ejemplo n.º 18
0
 def __init__(self, name, iterations, totalAtomics, modelnumber, local,
              remote, percentageremotes):
     AtomicDEVS.__init__(self, name)
     self.inport = self.addInPort("inport")
     self.percentageremotes = percentageremotes
     self.outports = []
     self.totalAtomics = totalAtomics
     self.modelnumber = modelnumber
     for i in xrange(totalAtomics):
         self.outports.append(self.addOutPort("outport_" + str(i)))
     self.state = PHOLDModelState()
     ev = modelnumber
     self.state.event = [[ev, getProcTime(ev)]]
     self.iterations = iterations
     self.local = local
     self.remote = remote
Ejemplo n.º 19
0
    def __init__(self, name="Generator", IAT_min=60, IAT_max=120, a_min=0.2, a_max=0.7, schedule=[], start="Start", end="End"):
        AtomicDEVS.__init__(self, name)
        self.train_out = self.addOutPort("train_out")
        self.UPDATE = self.addInPort("UPDATE")

        self.elapsed = 0.0
        self.state = "Generator"
        self.schedule = schedule
        self.start = start
        self.end = end

        self.IAT_min = IAT_min
        self.IAT_max = IAT_max
        self.a_min = a_min
        self.a_max = a_max

        self.trains_generated = 0
        random.seed(123)
Ejemplo n.º 20
0
    def __init__(self, identifier, contract, delay_order, delay_notification):
        AtomicDEVS.__init__(self, identifier)
        self.identifier = identifier
        self.contract = contract
        self.tick_size = None

        self.last_current_time = 0.0
        self.time_advance = float('inf')

        self.last_transition = None  # [internal, external]
        self.last_elapsed = 0.0

        self.in_order = self.addInPort('in_order')
        self.out_journal = self.addOutPort('out_journal')
        output_ports_map = {'out_journal': self.out_journal}
        self.strategy = OrderbookStrategy(self, identifier, contract,
                                          delay_order, delay_notification,
                                          output_ports_map)
Ejemplo n.º 21
0
    def __init__(self, identifier, strategy, strategy_params, input_ports,
                 contract_port_map):
        AtomicDEVS.__init__(self, identifier)
        self.identifier = identifier
        self.strategy = strategy(self, **strategy_params)

        self.last_elapsed = 0.0
        self.last_current_time = 0.0

        self.time_advance = self.strategy.next_wakeup_time
        self.last_time_advance = None

        # I/O Ports
        self.contract_port_map = contract_port_map
        for port_name in input_ports:
            setattr(self, port_name, self.addInPort(port_name))
        for contract, port_name in contract_port_map.items():
            setattr(self, port_name, self.addOutPort(port_name))
Ejemplo n.º 22
0
    def __init__(self, x, y, x_max, y_max):
        AtomicDEVS.__init__(self, "Cell(%d, %d)" % (x, y))

        self.state = CellState(T_AMBIENT)

        # For Cell DEVS tracing
        self.x = x
        self.y = y

        self.inports = [
            self.addInPort("in_N"),
            self.addInPort("in_E"),
            self.addInPort("in_S"),
            self.addInPort("in_W"),
            self.addInPort("in_G")
        ]
        self.outport = self.addOutPort("out_T")

        self.taMap = {
            PH_INACTIVE: INFINITY,
            PH_UNBURNED: 1.0,
            PH_BURNING: 1.0,
            PH_BURNED: INFINITY
        }
Ejemplo n.º 23
0
 def test_DEVS_model_exceptions(self):
     try:
         # Shouldn't allow instantiation of the base model
         junk = BaseDEVS("junk")
         self.fail()  #pragma: nocover
     except DEVSException:
         pass
     try:
         # Shouldn't allow instantiation of the base model
         junk = AtomicDEVS("junk")
         self.fail()  #pragma: nocover
     except DEVSException:
         pass
     try:
         # Shouldn't allow instantiation of the base model
         junk = CoupledDEVS("junk")
         self.fail()  #pragma: nocover
     except DEVSException:
         pass
Ejemplo n.º 24
0
 def __init__(self, levels):
     AtomicDEVS.__init__(self, "Generator")
     self.outports = []
     for i in range(levels):
         self.outports.append(self.addOutPort("out_" + str(i)))
     self.state = GeneratorState()
Ejemplo n.º 25
0
 def __init__(self, name=None):
     AtomicDEVS.__init__(self, name)
     self.state = MachineState()
     self.inport = self.addInPort("input")
     self.outport = self.addOutPort("output")
Ejemplo n.º 26
0
 def __init__(self):
     AtomicDEVS.__init__(self, "Queue")
     self.state = None
     self.processing_time = 1.0
     self.inport = self.addInPort("input")
     self.outport = self.addOutPort("output")
Ejemplo n.º 27
0
 def __init__(self):
     AtomicDEVS.__init__(self, "PO2")
     self.inport = self.addInPort("inport")
     self.outport1 = self.addOutPort("outport1")
     self.outport2 = self.addOutPort("outport2")
     self.state = None
Ejemplo n.º 28
0
 def __init__(self):
     AtomicDEVS.__init__(self, "example")
Ejemplo n.º 29
0
 def __init__(self, name):
     AtomicDEVS.__init__(self, "Processor_%s" % name)
     self.state = None
     self.inport = self.addInPort("inport")
     self.outport = self.addOutPort("outport")
Ejemplo n.º 30
0
 def __init__(self):
     AtomicDEVS.__init__(self, "Generator")
     # Keep a counter of how many events were sent
     self.outport = self.addOutPort("outport")
     self.state = 0
Ejemplo n.º 31
0
 def __init__(self, name, seed):
         AtomicDEVS.__init__(self, name)
         self.recv_event1 = self.addInPort("in_event1")
         self.send_event1 = self.addOutPort("out_event1")
         self.state = ProcessorState(seed)
Ejemplo n.º 32
0
 def __init__(self, seed):
     AtomicDEVS.__init__(self, "RandomProcessor_" + str(seed))
     self.inport = self.addInPort("inport")
     self.outport = self.addOutPort("outport")
     self.state = RandomProcessorState(seed)
Ejemplo n.º 33
0
 def __init__(self):
     AtomicDEVS.__init__(self, "PO2")
     self.inport = self.addInPort("inport")
     self.outport1 = self.addOutPort("outport1")
     self.outport2 = self.addOutPort("outport2")
     self.state = None
Ejemplo n.º 34
0
 def __init__(self):
     AtomicDEVS.__init__(self, "Queue")
     self.state = None
     self.processing_time = 1.0
     self.inport = self.addInPort("input")
     self.outport = self.addOutPort("output")
Ejemplo n.º 35
0
 def __init__(self):
     AtomicDEVS.__init__(self, "Gen")
     self.outport = self.addOutPort("outport")
     self.state = True
Ejemplo n.º 36
0
 def __init__(self):
     AtomicDEVS.__init__(self, "Generator")
     self.state = True
     self.outport = self.addOutPort("outport")
Ejemplo n.º 37
0
 def __init__(self):
     AtomicDEVS.__init__(self, "ElapsedNothing")
     self.elapsed = 0.3
     self.state = 1
Ejemplo n.º 38
0
 def __init__(self):
     AtomicDEVS.__init__(self, "Generator")
     self.state = None
     self.outport = self.addOutPort("outport")
Ejemplo n.º 39
0
 def __init__(self):
         AtomicDEVS.__init__(self, "Generator")
         self.state = "gen_event1"
         self.send_event1 = self.addOutPort("out_event1")
Ejemplo n.º 40
0
 def __init__(self, name):
     AtomicDEVS.__init__(self, "Processor_%s" % name)
     self.state = None
     self.inport = self.addInPort("inport")
     self.outport = self.addOutPort("outport")
Ejemplo n.º 41
0
    def __init__(self, name, time):
        AtomicDEVS.__init__(self, name)
        self.time = time

        self.object_out = self.addOutPort(name="object_out")
Ejemplo n.º 42
0
 def __init__(self, seed):
     AtomicDEVS.__init__(self, "RandomProcessor_" + str(seed))
     self.inport = self.addInPort("inport")
     self.outport = self.addOutPort("outport")
     self.state = RandomProcessorState(seed)
Ejemplo n.º 43
0
 def __init__(self, count):
     AtomicDEVS.__init__(self, "Consumer_%i" % count)
     self.inport = self.addInPort("inport")
Ejemplo n.º 44
0
 def __init__(self, levels):
     AtomicDEVS.__init__(self, "Generator")
     self.outports = []
     for i in range(levels):
         self.outports.append(self.addOutPort("out_" + str(i)))
     self.state = GeneratorState()