Ignore:
Timestamp:
06/11/20 16:34:40 (4 years ago)
Author:
bart
Message:

Update to version 1.41

Location:
opponentmodel/src/main/java/geniusweb/opponentmodel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • opponentmodel/src/main/java/geniusweb/opponentmodel/FrequencyOpponentModel.java

    r14 r18  
    66import java.util.stream.Collectors;
    77
     8import geniusweb.actions.Action;
     9import geniusweb.actions.Offer;
    810import geniusweb.issuevalue.Bid;
    911import geniusweb.issuevalue.Domain;
     
    1214import geniusweb.profile.utilityspace.NumberValueSetUtilities;
    1315import geniusweb.profile.utilityspace.UtilitySpace;
     16import geniusweb.progress.Progress;
    1417
    1518/**
     
    2326 *
    2427 */
    25 public class FrequencyOpponentModel implements OpponentModel, UtilitySpace {
     28public class FrequencyOpponentModel implements UtilitySpace, OpponentModel {
    2629
    2730        private static final int DECIMALS = 4; // accuracy of our computations.
     
    3235
    3336        public FrequencyOpponentModel(Domain domain) {
    34                 // map with empth hashmap for each issue.
     37                /*
     38                 * simply reset the whole model and make a new one... maybe this can be
     39                 * done smarter for minor changes? map with empth hashmap for each
     40                 * issue.
     41                 */
    3542                this(domain,
    3643                                domain.getIssues().stream().collect(
     
    3946        }
    4047
     48        /**
     49         * internal constructor. Assumes the freqs keyset is equal to the available
     50         * issues.
     51         *
     52         * @param domain the domain
     53         * @param freqs  the observed frequencies for all issue values. This map is
     54         *               assumed to be a fresh private-access only copy.
     55         * @param total  the total number of bids contained in the freqs map. This
     56         *               must be equal to the sum of the Integer values in the
     57         *               {@link #bidFrequencies} for each issue (this is not
     58         *               checked).
     59         */
     60        private FrequencyOpponentModel(Domain domain,
     61                        Map<String, Map<Value, Integer>> freqs, BigDecimal total) {
     62                if (domain == null) {
     63                        throw new NullPointerException("domain=null");
     64                }
     65                this.domain = domain;
     66                this.bidFrequencies = freqs;
     67                this.totalBids = total;
     68        }
     69
    4170        @Override
    4271        public BigDecimal getUtility(Bid bid) {
     
    86115        }
    87116
    88         @Override
    89         public FrequencyOpponentModel update(Bid bid) {
     117        /**
     118         * {@inheritDoc}
     119         *
     120         * <h1>change info</h1> This replaces update(Bid). Now you pass the entire
     121         * action and the progress instead of just the bid.
     122         */
     123        @Override
     124        public FrequencyOpponentModel with(Action action, Progress progress) {
     125                if (!(action instanceof Offer))
     126                        return this;
     127
     128                Bid bid = ((Offer) action).getBid();
    90129                String err = domain.isComplete(bid);
    91130                if (err != null) {
     
    108147
    109148        /**
    110          * internal constructor. Assumes the freqs keyset is equal to the available
    111          * issues.
    112          *
    113          * @param domain the domain
    114          * @param freqs  the observed frequencies for all issue values. This map is
    115          *               assumed to be a fresh private-access only copy.
    116          * @param total  the total number of bids contained in the freqs map. This
    117          *               must be equal to the sum of the Integer values in the
    118          *               {@link #bidFrequencies} for each issue (this is not
    119          *               checked).
    120          */
    121         private FrequencyOpponentModel(Domain domain,
    122                         Map<String, Map<Value, Integer>> freqs, BigDecimal total) {
    123                 if (domain == null) {
    124                         throw new NullPointerException("domain=null");
    125                 }
    126                 this.domain = domain;
    127                 this.bidFrequencies = freqs;
    128                 this.totalBids = total;
    129         }
    130 
    131         /**
    132149         *
    133150         * @param freqs
     
    141158                }
    142159                return map;
     160        }
     161
     162        @Override
     163        public Bid getReservationBid() {
     164                // don't throw but we really have no clue.
     165                return new Bid(new HashMap<>());
    143166        }
    144167
     
    188211        }
    189212
    190         @Override
    191         public Bid getReservationBid() {
    192                 throw new UnsupportedOperationException();
    193         }
    194 
    195213}
  • opponentmodel/src/main/java/geniusweb/opponentmodel/OpponentModel.java

    r14 r18  
    11package geniusweb.opponentmodel;
    22
    3 import geniusweb.issuevalue.Bid;
     3import geniusweb.actions.Action;
     4import geniusweb.issuevalue.Domain;
    45import geniusweb.profile.Profile;
    56import geniusweb.profile.utilityspace.UtilitySpace;
     7import geniusweb.progress.Progress;
    68
    79/**
    810 * An opponentmodel estimates a {@link UtilitySpace} from received opponent
    9  * bids.
     11 * actions.
     12 * <h1>Requirement</h1> A OpponentModel must have a constructor that takes the
     13 * Domain as argument. unfortunately this can not be enforced in a java
     14 * interface
    1015 */
    1116public interface OpponentModel extends Profile {
     17
    1218        /**
    13          *
    14          * @param bid the next bid that was received
    15          * @return a new {@link OpponentModel} that takes the next bid into account.
     19         * Update this with a new action that was done by the opponent that this
     20         * model is modeling. {@link #with(Domain)} must be called before calling
     21         * this.
     22         *
     23         * @param action   the new incoming action.
     24         * @param progress the current progress of the negotiation. Calls to this
     25         *                 must be done with increasing progress.
     26         * @return the updated {@link OpponentModel}
    1627         */
    17         OpponentModel update(Bid bid);
     28        OpponentModel with(Action action, Progress progress);
    1829
    1930}
Note: See TracChangeset for help on using the changeset viewer.