예제 #1
0
def counter_offer(offer):
    logger.info('Asking counter-offer to ' + offer.address)
    gr = Graph()
    subject = ECSDI['contra-oferta']
    gr.add((subject, RDF.type, ECSDI.Contraoferta))
    new_price = offer.price - 2
    gr.add((subject, ECSDI.Precio_envio, Literal(new_price)))
    resp = send_message(build_message(gr, ACL['counter-proposal'], content=subject, sender=AgenteNegociador.uri),
                        offer.address)
    msg = get_message_properties(resp)
    if 'performative' not in msg or msg['performative'] == ACL.refuse:
        logger.warn('An agent rejected us :(')
        return None
    elif msg['performative'] == ACL.agree:
        return Offer(address=offer.address, price=new_price)
    else:
        logger.error('I can\'t understand:(')
        return None
예제 #2
0
def requestOffer(agent, peso, fecha, destino):
    gr = Graph()
    subject = ECSDI['peticion-oferta']
    gr.add((subject, RDF.type, ECSDI.Pedir_oferta_transporte))
    gr.add((subject, ECSDI.Destino, Literal(destino)))
    gr.add((subject, ECSDI.Plazo_maximo_entrega, Literal(fecha)))
    gr.add((subject, ECSDI.Peso_envio, Literal(peso)))
    resp = send_message(build_message(gr, ACL['call-for-proposal'], content=subject, receiver=agent.uri,
                                      sender=AgenteNegociador.uri), agent.address)
    msg = get_message_properties(resp)
    if 'performative' not in msg or msg['performative'] == ACL.refuse:
        logger.warn('Nos ha rechazado un agente')
        return None
    elif msg['performative'] == ACL.propose:
        precio = resp.value(msg['content'], ECSDI.Precio_envio)
        return Offer(address=agent.address, price=precio.toPython())
    logger.error('No se entiende')
    return None