Beispiel #1
0
    def test_time ( self ):
        """
        Test that ensures that emissions have the correct time of creation
        """
        # Instantiate CommsPlatform
        platform1 = CommsPlatform(1)
        platform2 = CommsPlatform(2)
        allPlatforms = (platform1, platform2)
        
        # Instantiate DisruptorPlatform
        disruptor = DisruptorPlatform(1, 0)
        
        # Define connectivity/adjacency matrix
        adjMatrix = np.full((3,3), True, dtype=bool)
        
        # Instantiate Environment
        env = Environment(adjMatrix, allPlatforms, (disruptor,))

        # Create and transmit data
        numSteps = 20
        txPayloads = [random.random() for i in range(numSteps)]
        
        # Run simulation
        deltaT = 0.25
        for t in range(numSteps):
            platform1.txData(txPayloads[t], [2])
            # Verify emission time is correct
            if t > env.disruptorDelay:
                self.assertEqual(disruptor.env[0][0].time, deltaT * (t-env.disruptorDelay-1))
            
            # Step simulation
            env.step(deltaT)
Beispiel #2
0
    def test_uniqueID(self):
        """
        Test that ensures all CommsPlatforms have unique IDs
        """
        # Instantiate CommsPlatforms
        theID = 0
        platform1 = CommsPlatform(theID)
        platform2 = CommsPlatform(theID)
        allPlatforms = (platform1, platform2)

        # Define connectivity/adjacency matrix
        adjMatrix = np.full((2, 2), True, dtype=bool)

        # Instantiate Environment
        self.assertRaises(AssertionError, Environment, adjMatrix, allPlatforms)
Beispiel #3
0
    def test_validDestID(self):
        """
        Test that ensures destination ID for packet must be in connectivity list
        """
        # Instantiate CommsPlatforms
        theID = 0
        platform = CommsPlatform(theID)

        # Define connectivity/adjacency matrix
        adjMatrix = np.full((1, 1), True, dtype=bool)

        # Instantiate Environment
        env = Environment(adjMatrix, (platform, ))

        # Transmit data
        thePayload = 1
        # Should produce no error
        platform.txData(thePayload, [theID])
        # Should produce error
        self.assertRaises(AssertionError, platform.txData, thePayload,
                          [theID + 1])
Beispiel #4
0
    def setUp(self):
        # Instantiate CommsPlatforms
        platform1 = CommsPlatform(0)
        platform2 = CommsPlatform(1)
        allPlatforms = (platform1, platform2)
        platform1.destIDs = [1]
        platform2.destIDs = [0]

        self.platforms = allPlatforms
Beispiel #5
0
    def test_delay ( self ):
        """
        Test that ensures Disruptor Platform awareness of the Environment is delayed correctly
        """
        # Instantiate CommsPlatforms
        platform1 = CommsPlatform(1)
        platform2 = CommsPlatform(2)
        platform3 = CommsPlatform(3)
        allPlatforms = (platform1, platform2, platform3)
        
        # Instantiate DisruptorPlatform
        disruptor = DisruptorPlatform(1, 0)
        
        # Define connectivity/adjacency matrix
        adjMatrix = np.full((4,4), True, dtype=bool)
        
        # Instantiate Environment
        delay = 2
        env = Environment(adjMatrix, allPlatforms, (disruptor,), theDisruptorDelay=delay)

        # Create and transmit data
        numSteps = 20
        txPayloads = [random.random() for i in range(numSteps)]
        
        # Run simulation
        deltaT = 0.25
        envQueue = queue.Queue()
        for t in range(numSteps):
            platform1.txData(txPayloads[t], [2])

            envQueue.put(copy.deepcopy(env.data))
            
            # Compare current value from Environment with delayed value from Disruptor
            if t >= delay:
                pastEnv = envQueue.get()
                for platformIndex in range(len(env.data)):
                    for binIndex in range(env.numFrequencyBins):
                        if pastEnv[platformIndex][binIndex]:
                            self.assertEqual(pastEnv[platformIndex][binIndex].sourceID, disruptor.env[platformIndex][binIndex].sourceID)
                            self.assertEqual(pastEnv[platformIndex][binIndex].destID, disruptor.env[platformIndex][binIndex].destID)
                            self.assertEqual(pastEnv[platformIndex][binIndex].payload, disruptor.env[platformIndex][binIndex].payload)
                            self.assertEqual(pastEnv[platformIndex][binIndex].msgID, disruptor.env[platformIndex][binIndex].msgID)
                            self.assertEqual(pastEnv[platformIndex][binIndex].freqBin, disruptor.env[platformIndex][binIndex].freqBin)
                            #self.assertEqual(pastEnv[platformIndex][binIndex].position, disruptor.env[platformIndex][binIndex].position)
                        else:
                            self.assertEqual(pastEnv[platformIndex][binIndex], disruptor.env[platformIndex][binIndex])

            # Step simulation
            env.step(deltaT)
Beispiel #6
0
    def test_dataTransfer ( self ):
        """
        Test that ensures data transferred by one CommsPlatform is received by the intended Comms Platforms
        """
        # Instantiate CommsPlatforms
        platform1 = CommsPlatform(1)
        platform2 = CommsPlatform(2)
        platform3 = CommsPlatform(3)
        allPlatforms = (platform1, platform2, platform3)
        rxPlatforms = [platform2, platform3]
        nonRxPlatforms = [platform1]

        # Define connectivity/adjacency matrix
        adjMatrix = np.full((3,3), True, dtype=bool)
        
        # Instantiate Environment
        env = Environment(adjMatrix, allPlatforms)

        # Create and transmit data
        numSteps = 20
        txPayloads = [random.random() for i in range(numSteps)]
        
        # Run simulation
        deltaT = 0.25
        for t in range(numSteps):
            platform1.txData(txPayloads[t], [2,3])
        
            # Ensure platforms receive correct data
            for p in rxPlatforms:
                # Obtain any received data
                theRxData = p.rxData()

                if t == 0:
                    self.assertEqual(theRxData, None)
                else:
                    self.assertEqual(theRxData, txPayloads[t-1])
            
            # Ensure platforms that are not supposed to receive any data in fact have not
            for p in nonRxPlatforms:
                # Obtain any received data
                theRxData = p.rxData()
                self.assertEqual(theRxData, None)

            # Step simulation
            env.step(deltaT)
Beispiel #7
0
from acme.platforms.CommsPlatform import CommsPlatform
from acme.platforms.DisruptorPlatform import DisruptorPlatform
from acme.Environment import Environment
import random
import numpy as np

# Specify parameters
numberOfFrequencyBins = 10  # Number of frequency bins in the environment
maxTxQueue = 30  # Maximum number of packets in queue for each blue agent
numMaxDisruptionTokens = 4  # Maximum number of disruption tokens for red agent
numTimeStepsPerEpoch = 10  # Number of time steps per time epoch
mac = "rr"

# Instantiate communications platforms
plat0 = CommsPlatform("c1", theMaxSize=maxTxQueue)
plat1 = CommsPlatform("c2", theMaxSize=maxTxQueue)
plat2 = CommsPlatform("c3", theMaxSize=maxTxQueue)
allPlatforms = (plat0, plat1, plat2)

# Instantiate disruptor
theDisruptor = (DisruptorPlatform("d1", numMaxDisruptionTokens, numberOfFrequencyBins, numTimeStepsPerEpoch),)

# Define global connectivity/adjacency matrix
adjMatrix = np.full((4,4), False, dtype=bool)
adjMatrix[0,1:3] = True
adjMatrix[1,0] = True
adjMatrix[1,2] = True
adjMatrix[2,0:2] = True
adjMatrix[3,0:3] = True

# Instantiate environment