예제 #1
0
    def __init__(self, sim_param=SimParam(), no_seed=False):
        """
        Initialize the Simulation object.
        :param sim_param: is an optional SimParam object for parameter pre-configuration
        :param no_seed: is an optional parameter. If it is set to True, the RNG should be initialized without a
        a specific seed.
        """
        self.sim_param = sim_param
        self.sim_state = SimState()
        self.system_state = SystemState(self)
        self.event_chain = EventChain()
        self.sim_result = SimResult(self)
        # TODO Task 2.4.3: Uncomment the line below
        self.counter_collection = CounterCollection(self)
        # TODO Task 3.1.2: Uncomment the line below and replace the "None"

        if no_seed:
            #if the mean = 1.0, then 1/lambda_ = 1.0 -> lambda_ = 1
            self.rng = RNG(ExponentialRNS(1.0),
                           ExponentialRNS(1. / float(self.sim_param.RHO)))
        else:
            self.rng = RNG(
                ExponentialRNS(1.0, self.sim_param.SEED_IAT),
                ExponentialRNS(1. / float(self.sim_param.RHO),
                               self.sim_param.SEED_ST))
예제 #2
0
 def savestate(self, message):
     coordinates = self.coordinate_manager.get_coordinates()
     atoms = self.atoms[:]
     bonds = self.bonds[:]
     im = np.copy(self.interaction_matrix)
     new_state = SystemState(message, atoms, bonds, coordinates, im)
     self.system_states.append(new_state)
     print("Saving state %s..." % len(self.system_states))
     self.current_state = new_state
 def reset(self):
     """
     Reset the Simulation object.
     """
     self.sim_state = SimState()
     self.system_state = SystemState(self)
     self.event_chain = EventChain()
     self.sim_result = SimResult(self)
     self.counter_collection = CounterCollection(self)
     self.rng.iat_rns.set_parameters(1.)
     self.rng.st_rns.set_parameters(1. / float(self.sim_param.RHO))
예제 #4
0
 def reset(self, no_seed=False):
     """
     Reset the Simulation object.
     :param no_seed: is an optional parameter. If it is set to True, the RNG should be reset without a
     a specific seed.
     """
     self.sim_state = SimState()
     self.system_state = SystemState(self)
     self.event_chain = EventChain()
     self.sim_result = SimResult(self)
     # TODO Task 2.4.3: Uncomment the line below
     self.counter_collection = CounterCollection(self)
     # TODO Task 3.1.2: Uncomment the line below and replace the "None"
     """
예제 #5
0
 def __init__(self, sim_param=SimParam(), no_seed=False):
     """
     Initialize the Simulation object.
     :param sim_param: is an optional SimParam object for parameter pre-configuration
     :param no_seed: is an optional parameter. If it is set to True, the RNG should be initialized without a
     a specific seed.
     """
     self.sim_param = sim_param
     self.sim_state = SimState()
     self.system_state = SystemState(self)
     self.event_chain = EventChain()
     self.sim_result = SimResult(self)
     # TODO Task 2.4.3: Uncomment the line below
     self.counter_collection = CounterCollection(self)
     # TODO Task 3.1.2: Uncomment the line below and replace the "None"
     """
예제 #6
0
 def reset(self, no_seed=False):
     """
     Reset the Simulation object.
     :param no_seed: is an optional parameter. If it is set to True, the RNG should be reset without a
     a specific seed.
     """
     self.sim_state = SimState()
     self.system_state = SystemState(self)
     self.event_chain = EventChain()
     self.sim_result = SimResult(self)
     # TODO Task 2.4.3: Uncomment the line below
     self.counter_collection = CounterCollection(self)
     # TODO Task 3.1.2: Uncomment the line below and replace the "None"
     if no_seed:
         self.rng = RNG(ExponentialRNS(1.0), ExponentialRNS(1./float(self.sim_param.RHO)))
     else:
         self.rng = RNG(ExponentialRNS(1.0, self.sim_param.SEED_IAT), ExponentialRNS(1./float(self.sim_param.RHO),self.sim_param.SEED_ST))
 def reset(self, no_seed=False):
     """
     Reset the Simulation object.
     :param no_seed: is an optional parameter. If it is set to True, the RNG should be reset without a
     a specific seed.
     """
     self.sim_state = SimState()
     self.system_state = SystemState(self)
     self.event_chain = EventChain()
     self.sim_result = SimResult(self)
     self.counter_collection = CounterCollection(self)
     if no_seed:
         self.rng = RNG(ExponentialRNS(1),
                        ExponentialRNS(1. / float(self.sim_param.RHO)))
     else:
         self.rng = RNG(
             ExponentialRNS(1, self.sim_param.SEED_IAT),
             ExponentialRNS(1. / float(self.sim_param.RHO),
                            self.sim_param.SEED_ST))
 def __init__(self, sim_param=SimParam(), no_seed=False):
     """
     Initialize the Simulation object.
     :param sim_param: is an optional SimParam object for parameter pre-configuration
     :param no_seed: is an optional parameter. If it is set to True, the RNG should be initialized without a
     a specific seed.
     """
     self.sim_param = sim_param
     self.sim_state = SimState()
     self.system_state = SystemState(self)
     self.event_chain = EventChain()
     self.sim_result = SimResult(self)
     self.counter_collection = CounterCollection(self)
     if no_seed:
         self.rng = RNG(ExponentialRNS(1),
                        ExponentialRNS(1. / float(self.sim_param.RHO)))
     else:
         self.rng = RNG(
             ExponentialRNS(1, self.sim_param.SEED_IAT),
             ExponentialRNS(1. / float(self.sim_param.RHO),
                            self.sim_param.SEED_ST))
    #xor = ((starboardTack) and (not isPositive)) or ((not starboardTack) and (isPositive))
    Amoment = epsilon*Amax #*xor

    if (windDirection) and (isPositive):
        Amoment*=-1
    #elif (windDirection) and (not isPositive):
    #    pass
    #elif (not windDirection) and (isPositive):
    #    pass
    elif (not windDirection) and (not isPositive):
        Amoment*=-1
    
    Atotal = AAngle + Amoment



    #Values to send to servos

    controlVariable.setControlVariable(Atotal,delta)

if __name__ == '__main__':
    State = SystemState()
    controlVariable = ControlVariable()
    Tune = TuningVariable()
    initNode()
    initSub("gps_data",gps,gpsCallback)
    initSub("angle_data",angle,angleCallback)
    initPub("servo_data",servoControl,10)

    
예제 #10
0
    def test_system_state(self):
        """
        Test module SystemState. Add and remove packets from server and queue and check for correct behavior.
        """
        s = SystemState(DESTest.sim)

        # check correct initialization
        self.assertEqual(
            [s.buffer_content, s.server_busy], [0, False],
            msg=
            "Error in SystemState. Wrong int indicates queue length, wrong bool server busy."
        )

        # check correct behavior of start_service() after init
        self.assertEqual(
            s.start_service(),
            False,
            msg=
            "Error in SystemState. Wrong value indicates wrong queue length.")

        # check correct adding of packets to server or queue
        self.assertEqual(
            s.add_packet_to_server(),
            True,
            msg=
            "Error in SystemState. Could not add packet to server though it should be idle."
        )
        self.assertEqual(
            s.add_packet_to_server(),
            False,
            msg="Error in SystemState. Server not busy, though it should be.")
        self.assertEqual(
            [s.buffer_content, s.server_busy], [0, True],
            msg=
            "Error in SystemState. Wrong int indicates queue length, wrong bool server busy."
        )
        self.assertEqual(
            s.add_packet_to_queue(),
            True,
            msg=
            "Error in SystemState. Server not busy, though busy though it shouldn't be."
        )
        self.assertEqual(
            [s.buffer_content, s.server_busy], [1, True],
            msg=
            "Error in SystemState. Wrong int indicates queue length, wrong bool server busy."
        )
        self.assertEqual(
            s.add_packet_to_server(),
            False,
            msg=
            "Error in SystemState. Should not be able to add packet to server."
        )
        for _ in range(DESTest.sim.sim_param.S - 1):
            self.assertEqual(
                s.add_packet_to_queue(),
                True,
                msg="Error in SystemState. Could not add packet to queue.")

        # check correct dropping of packets, when queue is full
        self.assertEqual(
            s.add_packet_to_queue(),
            False,
            msg=
            "Error in SystemState. Could add packet to queue though it should be full."
        )
        self.assertEqual(
            [s.buffer_content, s.server_busy], [DESTest.sim.sim_param.S, True],
            msg=
            "Error in SystemState. Wrong int indicates queue length, wrong bool server busy."
        )

        # check behavior of function complete_service()
        s.complete_service()
        self.assertEqual(
            [s.buffer_content, s.server_busy],
            [DESTest.sim.sim_param.S, False],
            msg=
            "Error in SystemState. Wrong int indicates queue length, wrong bool server busy."
        )

        # check behavior of function start_service()
        self.assertEqual(
            s.start_service(),
            True,
            msg=
            "Error in SystemState. Starting service should be possible at this point."
        )
        self.assertEqual(
            [s.buffer_content, s.server_busy],
            [DESTest.sim.sim_param.S - 1, True],
            msg=
            "Error in SystemState. Wrong int indicates queue length, wrong bool server busy."
        )
예제 #11
0
 def test_finite_queue(self):
     """
     Test the basic behavior of the finite queue.
     """
     DESTestExtended.sim.reset()
     s = SystemState(DESTestExtended.sim)
     self.assertEqual(s.get_queue_length(), 0,
                      msg="Error in FiniteQueue. Wrong queue length.")
     s.add_packet_to_queue()
     DESTestExtended.sim.sim_state.now = 5
     s.add_packet_to_queue()
     DESTestExtended.sim.sim_state.now = 10
     s.add_packet_to_queue()
     self.assertEqual(s.get_queue_length(), 3,
                      msg="Error in FiniteQueue. Wrong queue length.")
     s.server_busy = False
     s.start_service()
     self.assertEqual(s.server_busy, True,
                      msg="Error in FiniteQueue. Server should be busy.")
     self.assertEqual(s.served_packet.t_arrival, 0,
                      msg="Error in FiniteQueue. Arrival time of packet wrong.")
     self.assertEqual(s.get_queue_length(), 2,
                      msg="Error in FiniteQueue. Wrong queue length.")
     s.server_busy = False
     s.start_service()
     self.assertEqual(s.server_busy, True,
                      msg="Error in FiniteQueue. Server should be busy.")
     self.assertEqual(s.served_packet.t_arrival, 5,
                      msg="Error in FiniteQueue. Arrival time of packet wrong.")
     self.assertEqual(s.get_queue_length(), 1,
                      msg="Error in FiniteQueue. Wrong queue length.")
     s.server_busy = False
     s.start_service()
     self.assertEqual(s.server_busy, True,
                      msg="Error in FiniteQueue. Server should be busy.")
     self.assertEqual(s.served_packet.t_arrival, 10,
                      msg="Error in FiniteQueue. Arrival time of packet wrong.")
     self.assertEqual(s.get_queue_length(), 0,
                      msg="Error in FiniteQueue. Wrong queue length.")