1 | package genius.core.uncertainty;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 |
|
---|
7 | import genius.core.Bid;
|
---|
8 | import genius.core.bidding.BidDetails;
|
---|
9 | import genius.core.bidding.BidDetailsSorterUtility;
|
---|
10 | import genius.core.boaframework.NegotiationSession;
|
---|
11 | import genius.core.utility.AbstractUtilitySpace;
|
---|
12 | import genius.core.utility.UncertainAdditiveUtilitySpace;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * This class intends to be the gateway for more dynamic negotiations under preference uncertainty.
|
---|
16 | * In exchange of a cost, it should provide an agent with more information about the true utility space.
|
---|
17 | *
|
---|
18 | * Author: Adel Magra
|
---|
19 | */
|
---|
20 |
|
---|
21 | public class User {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * The underlying true utility space that is not accessible from the agent's perspective.
|
---|
25 | */
|
---|
26 | private UncertainAdditiveUtilitySpace utilspace;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * The total bother cost inflicted to the user from the elicitation actions of the agent.
|
---|
30 | */
|
---|
31 | private double elicitationBother;
|
---|
32 |
|
---|
33 | public User(UncertainAdditiveUtilitySpace utilspace) {
|
---|
34 | this.utilspace = utilspace;
|
---|
35 | this.elicitationBother = 0;
|
---|
36 | }
|
---|
37 | /**
|
---|
38 | * This function allows an agent to update its user model with a bid against a cost.
|
---|
39 | * @param bid: bid that we wish to add at its correct place in the ranking of the user model
|
---|
40 | * @param usermodel: current user model
|
---|
41 | * @return an updated user model with the bid added to it
|
---|
42 | */
|
---|
43 |
|
---|
44 | public UserModel elicitRank(Bid bid, UserModel userModel){
|
---|
45 |
|
---|
46 | BidRanking currentRanking = userModel.getBidRanking();
|
---|
47 | List<Bid> currentOrder = currentRanking.getBidOrder();
|
---|
48 | List<Bid> newOrder = new ArrayList<Bid>();
|
---|
49 | for( int i=0; i<currentOrder.size(); i++) {
|
---|
50 | newOrder.add(currentOrder.get(i));
|
---|
51 | }
|
---|
52 |
|
---|
53 | //In the case where the bid is already in the user model, just return the current user model
|
---|
54 | if(newOrder.contains(bid))
|
---|
55 | return userModel;
|
---|
56 |
|
---|
57 | //General Case
|
---|
58 | elicitationBother += this.getElicitationCost();
|
---|
59 | BidDetails newBid = new BidDetails(bid, utilspace.getUtility(bid));
|
---|
60 |
|
---|
61 | //bid will never be the max or min bid, because both are in every user model
|
---|
62 | //So we only take care of the case where minBid < bid < maxBid
|
---|
63 | for(int i=0; i<= newOrder.size()-1; i++){
|
---|
64 | Bid iBid = newOrder.get(i);
|
---|
65 | BidDetails currentBid = new BidDetails(iBid,utilspace.getUtility(iBid));
|
---|
66 | int comparResult = (new BidDetailsSorterUtility()).compare(newBid, currentBid);
|
---|
67 | if(comparResult == 1) { // bid < iBid
|
---|
68 | newOrder.add(i,bid);
|
---|
69 | BidRanking newRank = new BidRanking(newOrder, userModel.getBidRanking().getLowUtility(), userModel.getBidRanking().getHighUtility());
|
---|
70 | UserModel newModel = new UserModel(newRank);
|
---|
71 | return newModel;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | //In case something fails
|
---|
75 | System.out.println("Couldn't update user model upon request");
|
---|
76 | return userModel;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Gives back the cost of eliciting the user.
|
---|
81 | * @return elicitation cost.
|
---|
82 | */
|
---|
83 | public double getElicitationCost() {
|
---|
84 | return utilspace.getElicitationCost();
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Gives back the Total Bother cost inflicted to the user
|
---|
89 | * @return elicitationBother
|
---|
90 | */
|
---|
91 | public double getTotalBother() {
|
---|
92 | return elicitationBother;
|
---|
93 | }
|
---|
94 |
|
---|
95 | }
|
---|