def create_config_params(self):
        config_params = {}
        config_dict = {}
        config_param = ConfigParam('domainid', DataType.UINT32,
                                   str(self.domain))
        config_dict[config_param.name] = config_param

        for config_param_name in config_dict:
            config_param = config_dict[config_param_name]
            field_value = FieldValue()
            field_value.parse_field_value_from_config_param(config_param)
            config_params[config_param_name] = field_value

        return config_params
Exemple #2
0
    def test_not_enough_quantities(self):
        print('in test_not_enough_quantities')
        auction_key = "1.1"
        start = datetime.now()
        stop = start + timedelta(seconds=100)

        module = self.loader.get_module("progressive_second_price")

        if module:
            params = {}
            # The following are the required parameters
            config_param_1 = FieldValue(name="bandwidth")
            config_param_1.parse_field_value("20")
            params["bandwidth"] = config_param_1

            tot_demand = module.proc_module.calculate_requested_quantities(
                self.bids)
            self.assertEqual(tot_demand, 85)

            allocations = module.execute(params, auction_key, start, stop,
                                         self.bids)
            self.assertEqual(len(allocations), 10)

            qty_allocated = 0
            for allocation in allocations:
                qty_allocated += module.proc_module.get_allocation_quantity(
                    allocation)

            self.assertEqual(qty_allocated, 20)

            sell_prices = []
            qty_allocates = []
            bid_ids = []
            revenue = 0
            for allocation in allocations:
                qty = module.proc_module.get_allocation_quantity(allocation)
                sell_price = module.proc_module.get_bid_price(allocation)
                bid_id = allocation.get_parent_key()
                revenue = revenue + (qty * sell_price)
                sell_prices.append(sell_price)
                qty_allocates.append(qty)
                bid_ids.append(bid_id)

            print(sell_prices)
            print(qty_allocates)
            print(bid_ids)
Exemple #3
0
    def test_parse_field_value(self):
        field_value = FieldValue()

        value = "*"
        field_value.parse_field_value(value)
        self.assertEqual(field_value.cnt_values, 0)

        value = "10-50"
        field_value.parse_field_value(value)
        self.assertEqual(field_value.cnt_values, 2)

        value = "1,2,3,4,5,67"
        field_value.parse_field_value(value)
        self.assertEqual(field_value.cnt_values, 6)

        value = "Invalid"
        field_value.parse_field_value(value)
        self.assertEqual(field_value.cnt_values, 1)
Exemple #4
0
    def __init__(self, key: str, module: Module, auction: Auction, config_dict: dict):
        """
        Creates the auction process.
        :param key: unique key to identify the auction process
        :param module: module used to execute the auction
        :param auction: auction that is going to be executed
        :param config_dict: parameters
        """
        super(AuctionProcess, self).__init__(key, module)
        self.auction = auction
        self.bids = {}
        self.config_params = {}

        for config_param_name in config_dict:
            config_param = config_dict[config_param_name]
            field_value = FieldValue()
            field_value.parse_field_value_from_config_param(config_param)
            self.config_params[config_param_name] = field_value
Exemple #5
0
    def test_calculate_allocation_quantities(self):
        print('in test_not_enough_quantities')
        auction_key = "1.1"
        start = datetime.now()
        stop = start + timedelta(seconds=100)

        module = self.loader.get_module("progressive_second_price")

        if module:
            params = {}
            # The following are the required parameters
            config_param_1 = FieldValue(name="bandwidth")
            config_param_1.parse_field_value("20")
            params["bandwidth"] = config_param_1

            ordered_bids = module.proc_module.sort_bids_by_price(self.bids)
            allocations = module.calculate_allocations(20, ordered_bids)

            for alloc_key in allocations:
                print(allocations[alloc_key].bidding_object_key,
                      allocations[alloc_key].quantity)
Exemple #6
0
    def _parse_resource_request(self, node: Element, global_set: str, time_format: str):
        """
        Parses an auction node in the xml.

        :param node: Element  element to parse
        :param global_set: str global set
        :return:
        """
        # get the Id property
        name = node.get("ID").lower()
        if global_set:
            set_name = global_set
        else:
            set_name = str(self.domain)

        resource_request_key = set_name + '.' + name
        resource_request = ResourceRequest(resource_request_key, time_format)

        intervals = []

        # Iterates over children nodes
        start = datetime.now()
        for subitem in node.iterchildren():
            if isinstance(subitem.tag, str):
                if subitem.tag.lower() == "field":
                    field_value = FieldValue()
                    field_value.parse_field_value_from_xml(subitem)
                    resource_request.add_field_value(field_value)

                elif subitem.tag.lower() == "interval":
                    start, interval = self._parse_interval(subitem, start, resource_request_key)
                    intervals.append(interval)

        # Copies field values.
        for interval in intervals:
            interval.set_fields(resource_request.get_field_values())
            resource_request.add_interval(interval)

        return resource_request
Exemple #7
0
    def test_enough_quantities(self):
        print('in test_enough_quantities')
        auction_key = "1.1"
        start = datetime.now()
        stop = start + timedelta(seconds=100)

        module = self.loader.get_module("progressive_second_price")
        if module:
            params = {}
            # The following are the required parameters
            config_param_1 = FieldValue(name="bandwidth")
            config_param_1.parse_field_value("45")
            params["bandwidth"] = config_param_1

            allocations = module.execute(params, auction_key, start, stop,
                                         self.bids)
            self.assertEqual(len(allocations), 10)

            qty_allocated = 0
            for allocation in allocations:
                qty_allocated += module.proc_module.get_allocation_quantity(
                    allocation)

            self.assertEqual(qty_allocated, 73)
Exemple #8
0
    def test_enough_quantities(self):
        print('in test_enough_quantities')
        auction_key = "1.1"
        start = datetime.now()
        stop = start + timedelta(seconds=100)

        module = self.loader.get_module("two_auction_perfect_information")
        if module:
            params = {}
            # The following are the required parameters
            config_param_1 = FieldValue(name="bandwidth01")
            config_param_1.parse_field_value("45")
            params["bandwidth01"] = config_param_1

            config_param_2 = FieldValue(name="bandwidth02")
            config_param_2.parse_field_value("45")
            params["bandwidth02"] = config_param_2

            config_param_3 = FieldValue(name="reserveprice01")
            config_param_3.parse_field_value("0.15")
            params["reserveprice01"] = config_param_3

            config_param_4 = FieldValue(name="reserveprice02")
            config_param_4.parse_field_value("0.5")
            params["reserveprice02"] = config_param_4

            config_param_5 = FieldValue(name="maxvalue01")
            config_param_5.parse_field_value("0.5")
            params["maxvalue01"] = config_param_5

            config_param_6 = FieldValue(name="maxvalue02")
            config_param_6.parse_field_value("0.9")
            params["maxvalue02"] = config_param_6

            allocations = module.execute(params, auction_key, start, stop,
                                         self.bids)
            self.assertEqual(len(allocations), 10)

            qty_allocated = 0
            for allocation in allocations:
                qty_allocated += module.proc_module.get_allocation_quantity(
                    allocation)

            self.assertEqual(qty_allocated, 73)
Exemple #9
0
    def test_not_enough_quantities(self):
        print('in test_not_enough_quantities')
        auction_key = "1.1"
        start = datetime.now()
        stop = start + timedelta(seconds=100)

        module = self.loader.get_module("two_auction_perfect_information")

        if module:
            params = {}
            # The following are the required parameters
            config_param_1 = FieldValue(name="bandwidth01")
            config_param_1.parse_field_value("20")
            params["bandwidth01"] = config_param_1

            config_param_2 = FieldValue(name="bandwidth02")
            config_param_2.parse_field_value("30")
            params["bandwidth02"] = config_param_2

            config_param_3 = FieldValue(name="reserveprice01")
            config_param_3.parse_field_value("0.15")
            params["reserveprice01"] = config_param_3

            config_param_4 = FieldValue(name="reserveprice02")
            config_param_4.parse_field_value("0.5")
            params["reserveprice02"] = config_param_4

            config_param_5 = FieldValue(name="maxvalue01")
            config_param_5.parse_field_value("0.5")
            params["maxvalue01"] = config_param_5

            config_param_6 = FieldValue(name="maxvalue02")
            config_param_6.parse_field_value("0.9")
            params["maxvalue02"] = config_param_6

            tot_demand = module.proc_module.calculate_requested_quantities(
                self.bids)
            self.assertEqual(tot_demand, 85)

            allocations = module.execute(params, auction_key, start, stop,
                                         self.bids)
            self.assertEqual(len(allocations), 10)

            qty_allocated = 0
            for allocation in allocations:
                qty_allocated += module.proc_module.get_allocation_quantity(
                    allocation)

            self.assertEqual(qty_allocated, 50)

            sell_prices = []
            qty_allocates = []
            bid_ids = []
            revenue = 0
            for allocation in allocations:
                qty = module.proc_module.get_allocation_quantity(allocation)
                sell_price = module.proc_module.get_bid_price(allocation)
                bid_id = allocation.get_parent_key()
                revenue = revenue + (qty * sell_price)
                sell_prices.append(sell_price)
                qty_allocates.append(qty)
                bid_ids.append(bid_id)

            print(sell_prices)
            print(qty_allocates)
            print(bid_ids)
Exemple #10
0
    def test_enough_quantities(self):
        print('in test_enough_quantities')
        auction_key = "1.1"
        start = datetime.now()
        stop = start + timedelta(seconds=100)

        module = self.loader.get_module("basic_module")
        if module:
            # The following are the required parameters
            params = {}
            # The following are the required parameters
            config_param_1 = FieldValue(name="bandwidth")
            config_param_1.parse_field_value("90")
            params["bandwidth"] = config_param_1

            config_param_2 = FieldValue(name="subsidy")
            config_param_2.parse_field_value("1.2")
            params["subsidy"] = config_param_2

            config_param_3 = FieldValue(name="maxvalue01")
            config_param_3.parse_field_value("0.5")
            params["maxvalue01"] = config_param_3

            config_param_4 = FieldValue(name="reserveprice")
            config_param_4.parse_field_value("0.15")
            params["reserveprice"] = config_param_4

            allocations = module.execute(params, auction_key, start, stop,
                                         self.bids)
            self.assertEqual(len(allocations), 10)

            qty_allocated = 0
            for allocation in allocations:
                qty_allocated += module.proc_module.get_allocation_quantity(
                    allocation)

            self.assertEqual(qty_allocated, 73)

            for allocation in allocations:
                sell_price = module.proc_module.get_bid_price(allocation)
                break

            self.assertEqual(sell_price, 0.15)
    def test_enough_quantities(self):

        auction_key = "1.1"
        start = datetime.now()
        stop = start + timedelta(seconds=100)

        module = self.loader.get_module("two_auction_generalized")

        if module:
            params = {}
            # The following are the required parameters
            config_param_1 = FieldValue(name="bandwidth01")
            config_param_1.parse_field_value("45")
            params["bandwidth01"] = config_param_1

            config_param_2 = FieldValue(name="bandwidth02")
            config_param_2.parse_field_value("45")
            params["bandwidth02"] = config_param_2

            config_param_3 = FieldValue(name="reserveprice01")
            config_param_3.parse_field_value("0.15")
            params["reserveprice01"] = config_param_3

            config_param_4 = FieldValue(name="reserveprice02")
            config_param_4.parse_field_value("0.5")
            params["reserveprice02"] = config_param_4

            config_param_5 = FieldValue(name="maxvalue01")
            config_param_5.parse_field_value("0.5")
            params["maxvalue01"] = config_param_5

            config_param_6 = FieldValue(name="maxvalue02")
            config_param_6.parse_field_value("0.9")
            params["maxvalue02"] = config_param_6

            allocations = module.execute(params, auction_key, start, stop,
                                         self.bids)
            self.assertEqual(len(allocations), 10)

            sell_prices = []
            qty_allocates = []
            revenue = 0
            for allocation in allocations:
                qty = module.proc_module.get_allocation_quantity(allocation)
                sell_price = module.proc_module.get_bid_price(allocation)
                revenue = revenue + (qty * sell_price)
                sell_prices.append(sell_price)
                qty_allocates.append(qty)

            print(sell_prices)
            print(qty_allocates)