Package com.tnsai.coordination
Class MultiRoundContractNet
java.lang.Object
com.tnsai.coordination.MultiRoundContractNet
Multi-round Contract Net Protocol (CNP) implementation.
Extends the basic CNP with multi-round negotiation support:
- Call for Proposals (CFP) broadcast
- Collect initial proposals
- If best proposal not acceptable, request counter-offers
- Repeat up to maxRounds times
- Accept best proposal
Usage Example
MultiRoundContractNet cnp = MultiRoundContractNet.builder()
.manager(managerAgent)
.contractors(List.of(agent1, agent2, agent3))
.proposalRequester((contractor, task, round, targetScore, timeout) ->
messaging.requestProposal(contractor, task, timeout)) // required
.maxRounds(3)
.improvementThreshold(0.1) // Expect 10% improvement each round
.acceptanceThreshold(0.5) // Accept if score < 0.5
.build();
NegotiationResult result = cnp.negotiate(task);
- Since:
- 0.0.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for MultiRoundContractNet.static interfaceListener for negotiation events.static classResult of a negotiation round.static classRepresents a task to be negotiated.static interfaceStrategy for evaluating proposals.static interfaceSource of contractor proposals. -
Method Summary
-
Method Details
-
negotiate
public MultiRoundContractNet.NegotiationResult negotiate(MultiRoundContractNet.NegotiationTask task) Negotiates a contract for the given task.- Parameters:
task- the task to negotiate- Returns:
- the negotiation result
-
negotiateAsync
public CompletableFuture<MultiRoundContractNet.NegotiationResult> negotiateAsync(MultiRoundContractNet.NegotiationTask task) Negotiates asynchronously.- Parameters:
task- the task to negotiate- Returns:
- future with the negotiation result
-
addListener
Adds a negotiation listener. -
removeListener
Removes a negotiation listener. -
getMaxRounds
public int getMaxRounds() -
getImprovementThreshold
public double getImprovementThreshold() -
getAcceptanceThreshold
public double getAcceptanceThreshold() -
getContractors
-
builder
Creates a new builder.
-