示例#1
0
    def construct_ta_from_node(self, orientdb_node):
        """Constructs a TA object from an OrientDB node.

        :param pyorient.otypes.OrientRecord orientdb_node: A pyorient node
        :returns TA ta: A TA object constructed from the pyorient node
        """
        orient_record = self.get_connected_nodes(orientdb_node._rid, direction='in', filterdepth=1)

        eligible_frequencies=[]
        for record in orient_record:
            if record._class == 'Channel':
                eligible_frequencies.append(Frequency(int(record.frequency)))

        ta = TA(
            id_=orientdb_node.id,
            minimum_voice_bandwidth=Kbps(
                float(orientdb_node.minimum_voice_bandwidth)),
            minimum_safety_bandwidth=Kbps(
                float(orientdb_node.minimum_safety_bandwidth)),
            latency=timedelta(microseconds=1000*int(orientdb_node.latency)),
            scaling_factor=float(orientdb_node.scaling_factor),
            c=float(orientdb_node.c),
            eligible_frequencies=eligible_frequencies)

        return ta
示例#2
0
    def construct_channel_from_node(self, orientdb_node):
        """Constructs a Channel object from a pyorient node

        :param pyorient.otypes.OrientRecord orientdb_node: A pyorient channel node
        :returns Channel channel: A Channel object constructed from the pyorient node
        """
        channel = Channel(frequency=Frequency(int(orientdb_node.frequency)),
                            capacity=Kbps(int(orientdb_node.capacity)))
        return channel
示例#3
0
    def setUpClass(cls):
        cls.valid_channel_frequency = Frequency(4919500000)
        cls.valid_channel_length = time(microsecond=100000)
        cls.valid_channel_latency = time(microsecond=50000)
        cls.valid_channel_capacity = Kbps(100000)

        cls.valid_channel = Channel(cls.valid_channel_frequency,
                                    cls.valid_channel_length,
                                    cls.valid_channel_latency,
                                    cls.valid_channel_capacity)
示例#4
0
    def _generate_channels(config, seed):
        """Generates a set amount of Channels in the range of data provided by data_file.

        :param ConfigurationObject config: The Configuration for an instance of a challenge problem
        :param int seed: The seed to use when evaluating PRFs
        :returns [<Channel>] channels: A list of channels generated from config
        """
        channels = []
        for i in range(0, config.num_channels):
            base_frequency = config.frequency[0]
            frequency_incrementation = config.frequency[1]
            capacity = PRF(config.capacity)
            channels.append(
                Channel(frequency=Frequency(base_frequency +
                                            (i * frequency_incrementation)),
                        capacity=Kbps(capacity.evaluate(seed))))
        return channels
示例#5
0
    def generate(config):
        """Generates a ConstraintsObject within the parameters specified by a ConfigurationObject

        :param ConfigurationObject config: The Configuration for an instance of a challenge problem
        :returns ConstraintsObject:
        """
        constraints_object_list = []

        if config.testing == 1:
            if config.testing_seed != 'timestamp':
                seed = config.testing_seed
                numpy.random.seed(seed)
                random.seed(seed)

            channel_list = []
            for i in range(config.testing_num_channels):
                channel = Channel(frequency=Frequency(4919 + i * 22),
                                  capacity=Kbps(
                                      config.testing_channel_capacity))
                channel_list.append(channel)

            ta_list = []
            for i in range(config.testing_num_tas):
                eligible_frequency_list = []
                for j in range(config.testing_eligible_frequencies[i]):
                    eligible_frequency_list.append(channel_list[j].frequency)

                ta = TA(id_='TA{0}'.format(i + 1),
                        minimum_voice_bandwidth=Kbps(
                            int(config.testing_total_min_bw[i]) / 2),
                        minimum_safety_bandwidth=Kbps(
                            int(config.testing_total_min_bw[i]) / 2),
                        latency=timedelta(microseconds=1000 *
                                          int(config.testing_latency[i])),
                        scaling_factor=config.testing_scaling_factor[i],
                        c=config.testing_c[i],
                        eligible_frequencies=eligible_frequency_list)

                ta_list.append(ta)

            testing_constraints_object = ConstraintsObject(
                id_='TestingConstraintsObject',
                candidate_tas=ta_list,
                channels=channel_list,
                seed='timestamp',
                goal_throughput_bulk=Kbps(config.goal_throughput_bulk),
                goal_throughput_voice=Kbps(config.goal_throughput_voice),
                goal_throughput_safety=Kbps(config.goal_throughput_safety),
                guard_band=timedelta(microseconds=1000 *
                                     int(config.guard_band)),
                epoch=timedelta(microseconds=1000 * int(config.epoch)),
                txop_timeout=TxOpTimeout(config.txop_timeout))

            constraints_object_list.append(testing_constraints_object)

        else:
            if len(config.instances) == 2:
                seed = config.instances[1]
                numpy.random.seed(seed)
                random.seed(seed)
            else:
                seed = 'timestamp'

            for x in range(1, config.instances[0] + 1):
                channels = ConstraintsObjectGenerator._generate_channels(
                    config, seed)
                candidate_tas = ConstraintsObjectGenerator._generate_tas(
                    config, channels, seed)

                constraints_object = ConstraintsObject(
                    id_=x,
                    candidate_tas=candidate_tas,
                    channels=channels,
                    seed=seed,
                    goal_throughput_bulk=Kbps(config.goal_throughput_bulk),
                    goal_throughput_voice=Kbps(config.goal_throughput_voice),
                    goal_throughput_safety=Kbps(config.goal_throughput_safety),
                    guard_band=timedelta(microseconds=1000 *
                                         int(config.guard_band)),
                    epoch=timedelta(microseconds=1000 * int(config.epoch)),
                    txop_timeout=TxOpTimeout(config.txop_timeout))

                constraints_object_list.append(constraints_object)

                if isinstance(seed, int):
                    seed += 1

        return constraints_object_list
示例#6
0
 def test___eq__(self):
     f1 = Frequency(4919500000)
     f2 = Frequency(4919500000)
     self.assertTrue(f1 == f2)
示例#7
0
 def test_valid_frequency(self):
     frequency = Frequency(4919500000)
     self.assertEqual(4919500000, frequency.value)