Changeset 20 for opponentmodel/src/main


Ignore:
Timestamp:
08/05/20 09:42:15 (4 years ago)
Author:
bart
Message:

Added BOA support, some bug fixes

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

Legend:

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

    r18 r20  
    2424 * (as you might expect as {@link NumberValueSetUtilities} is only affected by
    2525 * the endpoints).
    26  *
     26 * <p>
     27 * immutable.
    2728 */
    2829public class FrequencyOpponentModel implements UtilitySpace, OpponentModel {
    2930
    3031        private static final int DECIMALS = 4; // accuracy of our computations.
     32        private static int serial = 1; // counter for auto name generation
     33
    3134        private final Domain domain;
    3235        private final Map<String, Map<Value, Integer>> bidFrequencies;
    3336        private final BigDecimal totalBids;
    34         private static int serial = 1; // counter for auto name generation
    35 
    36         public FrequencyOpponentModel(Domain domain) {
    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                  */
    42                 this(domain,
     37
     38        public FrequencyOpponentModel() {
     39                this.domain = null;
     40                this.bidFrequencies = null;
     41                this.totalBids = BigDecimal.ZERO;
     42        }
     43
     44        @Override
     45        public FrequencyOpponentModel with(Domain domain, Bid resBid) {
     46                // FIXME merge already available frequencies?
     47                return new FrequencyOpponentModel(domain,
    4348                                domain.getIssues().stream().collect(
    4449                                                Collectors.toMap(iss -> iss, iss -> new HashMap<>())),
     
    115120        }
    116121
    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          */
    123122        @Override
    124123        public FrequencyOpponentModel with(Action action, Progress progress) {
     
    127126
    128127                Bid bid = ((Offer) action).getBid();
    129                 String err = domain.isComplete(bid);
    130                 if (err != null) {
    131                         throw new IllegalArgumentException(err);
    132                 }
    133128                Map<String, Map<Value, Integer>> newFreqs = cloneMap(bidFrequencies);
    134129                for (String issue : domain.getIssues()) {
    135130                        Map<Value, Integer> freqs = newFreqs.get(issue);
    136131                        Value value = bid.getValue(issue);
    137                         Integer oldfreq = freqs.get(value);
    138                         if (oldfreq == null) {
    139                                 oldfreq = 0;
     132                        if (value != null) {
     133                                Integer oldfreq = freqs.get(value);
     134                                if (oldfreq == null) {
     135                                        oldfreq = 0;
     136                                }
     137                                freqs.put(value, oldfreq + 1);
    140138                        }
    141                         freqs.put(value, oldfreq + 1);
    142139                }
    143140
  • opponentmodel/src/main/java/geniusweb/opponentmodel/OpponentModel.java

    r18 r20  
    22
    33import geniusweb.actions.Action;
     4import geniusweb.issuevalue.Bid;
    45import geniusweb.issuevalue.Domain;
    56import geniusweb.profile.Profile;
     
    1314 * Domain as argument. unfortunately this can not be enforced in a java
    1415 * interface
     16 *
     17 * <p>
     18 * <em>MUST</em> have an empty constructor as these are also used as part of the
     19 * BOA framework.
     20 *
    1521 */
    1622public interface OpponentModel extends Profile {
     23
     24        /**
     25         * Initializes the model. This function must be called first after
     26         * constructing an instance. It can also be called later, if there is a
     27         * change in the domain or resBid.
     28         *
     29         * @param domain the domain to work with
     30         * @param resBid the reservation bid, or null if no reservationbid is
     31         *               available.
     32         * @return OpponentModel that uses given domain and reservationbid.
     33         *
     34         */
     35        OpponentModel with(Domain domain, Bid resBid);
    1736
    1837        /**
Note: See TracChangeset for help on using the changeset viewer.