Changeset 20 for opponentmodel


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

Added BOA support, some bug fixes

Location:
opponentmodel
Files:
26 added
4 edited

Legend:

Unmodified
Added
Removed
  • opponentmodel/pom.xml

    r19 r20  
    66        <groupId>geniusweb</groupId>
    77        <artifactId>opponentmodel</artifactId>
    8         <version>1.4.2</version> <!-- must equal ${geniusweb.version} -->
     8        <version>1.4.4</version> <!-- must equal ${geniusweb.version} -->
    99        <packaging>jar</packaging>
    1010
     
    1717                <passwd>${env.ARTIFACTORY_PASS}</passwd>
    1818                <jackson-2-version>2.9.10</jackson-2-version>
    19                 <geniusweb.version>1.4.2</geniusweb.version>
     19                <geniusweb.version>1.4.4</geniusweb.version>
    2020        </properties>
    2121
  • 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        /**
  • opponentmodel/src/test/java/geniusweb/profile/opponentmodel/FrequencyOppModelTest.java

    r18 r20  
    8787                bid3 = new Bid(issuevalues);
    8888
    89                 oppModel1 = new FrequencyOpponentModel(domain);
    90                 oppModel1b = new FrequencyOpponentModel(domain);
    91                 oppModel2 = new FrequencyOpponentModel(domain2);
    92                 oppModel3 = new FrequencyOpponentModel(domain3);
     89                oppModel1 = new FrequencyOpponentModel().with(domain, null);
     90                oppModel1b = new FrequencyOpponentModel().with(domain, null);
     91                oppModel2 = new FrequencyOpponentModel().with(domain2, null);
     92                oppModel3 = new FrequencyOpponentModel().with(domain3, null);
    9393                oppModel4 = oppModel3.with(new Offer(other, bid1), progress);
    9494
     
    113113        @Test(expected = NullPointerException.class)
    114114        public void smokeTestNull() {
    115                 new FrequencyOpponentModel(null);
     115                new FrequencyOpponentModel().with((Domain) null, null);
    116116        }
    117117
    118118        @Test
    119119        public void smokeTest() {
    120                 new FrequencyOpponentModel(domain);
     120                new FrequencyOpponentModel().with(domain, null);
    121121        }
    122122
    123123        @Test
    124124        public void testEmptyModel() {
    125                 FrequencyOpponentModel oppModel = new FrequencyOpponentModel(domain);
     125                FrequencyOpponentModel oppModel = new FrequencyOpponentModel()
     126                                .with(domain, null);
    126127                assertEquals(BigDecimal.ONE, oppModel.getUtility(bid1));
    127128                assertEquals(BigDecimal.ONE, oppModel.getUtility(bid2));
     
    153154        }
    154155
     156        @Test
     157        public void testPartialBidUpdate() {
     158                FrequencyOpponentModel oppModel = oppModel1.with(new Offer(other, bid1),
     159                                progress);
     160                Bid partialbid = new Bid(ISS1, I1V1);
     161                oppModel.with(new Offer(other, partialbid), progress);
     162        }
     163
    155164}
Note: See TracChangeset for help on using the changeset viewer.