def moveBidOnDirectionEdge(self, bid, service, directionMove):
        '''
        Create a new bid from bid based on the direction given bu directionMove
        Test: implemented.
        '''
        newBid = Bid()
        uuidId = uuid.uuid1(
        )  # make a UUID based on the host ID and current time
        idStr = str(uuidId)
        newBid.setValues(idStr, bid.getProvider(), bid.getService())
        for decisionVariable in directionMove:
            direction = (directionMove[decisionVariable])['Direction']
            step = (directionMove[decisionVariable])['Step']
            new_value = bid.getDecisionVariable(decisionVariable) + step

            # Make sure that the value is within the variable limits
            min_value = (
                service.getDecisionVariable(decisionVariable)).getMinValue()
            max_value = (
                service.getDecisionVariable(decisionVariable)).getMaxValue()
            new_value = max(min_value, new_value)
            new_value = min(max_value, new_value)

            newBid.setDecisionVariable(decisionVariable, new_value)
        return newBid
Exemplo n.º 2
0
 def handleFront(self, front):
     logger.debug('Starting handleFront')
     val_return = []
     bidXmLNodes = front.getElementsByTagName("Bid")
     for bidXmlNode in bidXmLNodes:
         bid = Bid()
         bid.setFromXmlNode(bidXmlNode)
         val_return.append(bid)
     logger.debug('Ending handleFront' + str(len(val_return)))
     return val_return
 def createBid(self, bidId, strProv, serviceId, period, unitary_cost, unitary_profit, capacity, parent_bid_Id ):
     bid = Bid()
     bid.setValues(bidId, strProv, serviceId)
     bid.setStatus(Bid.ACTIVE)
     bid.setUnitaryProfit(unitary_profit)
     bid.setUnitaryCost(unitary_cost)
     bid.setCreationPeriod(period)
     bid.setCapacity(capacity)
     bid.insertParentBid(parent_bid_Id)
     return bid        
def createBidService2(strProv, serviceId, quality, price):
    '''
    Create a transit provider bid
    '''
    bid = Bid()
    uuidId = uuid.uuid1()  # make a UUID based on the host ID and current time
    idStr = str(uuidId)
    bid.setValues(idStr, strProv, serviceId)
    bid.setDecisionVariable("3", quality)  # quality
    bid.setDecisionVariable("4", price)  # Price
    bid.setStatus(Bid.ACTIVE)
    return bid
def createBid(strProv, serviceId, delay, price):
    '''
    Create an edge provider bid
    '''
    bid = Bid()
    uuidId = uuid.uuid1()  # make a UUID based on the host ID and current time
    idStr = str(uuidId)
    bid.setValues(idStr, strProv, serviceId)
    bid.setDecisionVariable("1", price)  #Price
    bid.setDecisionVariable("2", delay)  # Delay
    bid.setStatus(Bid.ACTIVE)
    return bid
Exemplo n.º 6
0
def createBid(db, executionCount, bidId, strProv, service, period,
              unitary_cost, unitary_profit, capacity):
    bid = Bid()
    bid.setValues(bidId, strProv, service.getId())
    bid.setStatus(Bid.ACTIVE)
    bid.setUnitaryProfit(unitary_profit)
    bid.setUnitaryCost(unitary_cost)
    bid.setCreationPeriod(period)
    bid.setCapacity(capacity)
    for decisionVariable in (service)._decision_variables:
        value = getDecisionVariable(db, executionCount, bidId,
                                    decisionVariable)
        bid.setDecisionVariable(decisionVariable, value)
    return bid
Exemplo n.º 7
0
    def handleCompetitorBids(self, period, competitorsXmlNode):
        bids = competitorsXmlNode.getElementsByTagName("Bid")
        try:
            agent_type = self._list_args['Type']
            if ( agent_type.getType() == AgentType.PRESENTER_TYPE):
                logger.debug('Handle competitor bids')
                self._list_args['Current_Bids'] = {}  
                logger.debug('clear Handle competitor bids')
                
            for bid in bids:
                logger.debug('We are inside the bid loop')
                competitor_bid = Bid()
                competitor_bid.setFromXmlNode(bid)                
                if (competitor_bid.getProvider() != self._list_args['strId']):
                    if (competitor_bid.getService() == (self._list_args['serviceId'])):                        
                        if (competitor_bid.getId() in self._list_args['Related_Bids']):
                            # The bid must be replaced as the provider update it.
                            oldCompetitorBid = (self._list_args['Related_Bids'])[competitor_bid.getId()]
                            competitor_bid.setCreationPeriod(oldCompetitorBid.getCreationPeriod())  
                            (self._list_args['Related_Bids'])[competitor_bid.getId()] = competitor_bid
                        else:
                            if (competitor_bid.isActive() == True):
                                competitor_bid.setCreationPeriod(period)

                            # Replace the parent bid, looking for the actual one already in the dictionary 
                            if (competitor_bid.getParentBid() != None):
                                parentBidId = competitor_bid.getParentBid().getId() 
                                if parentBidId not in self._list_args['Related_Bids']:
                                    logger.error('Parent BidId %s not found in related bids', parentBidId)
                                else:
                                    parentBid = (self._list_args['Related_Bids'])[parentBidId]
                                    competitor_bid.insertParentBid(parentBid)
                                
                            #logger.debug('Inserting competitor bid:' + competitor_bid.__str__())
                            (self._list_args['Related_Bids'])[competitor_bid.getId()] = competitor_bid
                        
                        # Inserts on exchanged bids
                        if (agent_type.getType() == AgentType.PRESENTER_TYPE):
                            (self._list_args['Current_Bids'])[competitor_bid.getId()] = competitor_bid
                                    
            if (agent_type.getType() == AgentType.PRESENTER_TYPE):
                logger.debug('End Handle competitor bids - num exchanged:' + str(len(self._list_args['Current_Bids'])))
            logger.debug('clear 3 Handle competitor bids')
            logger.debug('Ending handled bid competitors for agent is:' + str(self._list_args['Id']))
            
        except Exception as e:
            raise FoundationException(str(e))
    def convertToOwnBid(self, serviceOwn, serviceProvider, bid,
                        adaptationFactor, fileResult):
        '''
        This function assumes that:
            1. If the aggregation function is maximize or minimize we convservate the same quality in percentage
            2. If the aggregation function is sum, then we assume the minimal quality is added.
        Test: implemented.
        '''
        newBid = Bid()
        uuidId = uuid.uuid1(
        )  # make a UUID based on the host ID and current time
        idStr = str(uuidId)
        newBid.setValues(idStr, self.getProviderId(), serviceOwn.getId())
        effectiveMove = True
        for decisionVariable in serviceProvider._decision_variables:
            min_value = (serviceProvider.getDecisionVariable(decisionVariable)
                         ).getMinValue()
            max_value = (serviceProvider.getDecisionVariable(decisionVariable)
                         ).getMaxValue()
            provOptimum = serviceProvider.getDecisionVariableObjetive(
                decisionVariable)

            value = bid.getDecisionVariable(decisionVariable)

            if ((max_value - min_value) == 0):
                percentage = 1
            else:
                percentage = (value - min_value) / (max_value - min_value)

            ownDecisionVariable, aggregationMode = self.getRelatedDecisionVariable(
                serviceProvider.getId(), serviceOwn.getId(), decisionVariable)
            min_value = (serviceOwn.getDecisionVariable(ownDecisionVariable)
                         ).getMinValue()
            max_value = (serviceOwn.getDecisionVariable(ownDecisionVariable)
                         ).getMaxValue()
            ownOptimum = serviceOwn.getDecisionVariableObjetive(
                ownDecisionVariable)

            if (decisionVariable !=
                    serviceProvider.getPriceDecisionVariable()):
                newValue = self.calculateQualityRelativeObjective(
                    percentage, min_value, max_value, aggregationMode,
                    adaptationFactor)
                newValueAdj = self.calculateRequiredQuality(
                    newValue, min_value, max_value, value, ownOptimum,
                    aggregationMode)
                newBid.setDecisionVariable(ownDecisionVariable, newValueAdj)
                if (newValueAdj < 0):
                    effectiveMove = False

        # Set the original bid as the provider Bid parent.
        newBid.setProviderBid(bid)
        if (effectiveMove == True):
            # calculate the cost
            unitaryCost = self.calculateBidUnitaryCost(newBid, fileResult)
            for decisionVariable in serviceOwn._decision_variables:
                # If the variable is price, it maintains the current level of the decision variable
                if (serviceOwn._decision_variables[decisionVariable].
                        getModeling() == DecisionVariable.MODEL_PRICE):
                    newBid.setDecisionVariable(decisionVariable, unitaryCost)
            return newBid
        else:
            return None