Changeset 18 for opponentmodel


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

Update to version 1.41

Location:
opponentmodel
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • opponentmodel/pom.xml

    r14 r18  
    66        <groupId>geniusweb</groupId>
    77        <artifactId>opponentmodel</artifactId>
    8         <version>1.4.0</version>
     8        <version>1.4.1</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.1</geniusweb.version>
    1920        </properties>
    2021
     
    3132                        <groupId>geniusweb</groupId>
    3233                        <artifactId>issuevalue</artifactId>
    33                         <version>1.4.0</version>
     34                        <version>${geniusweb.version}</version>
    3435                </dependency>
    3536                <dependency>
    3637                        <groupId>geniusweb</groupId>
    3738                        <artifactId>profile</artifactId>
    38                         <version>1.4.0</version>
     39                        <version>${geniusweb.version}</version>
    3940                </dependency>
    4041                <dependency>
    4142                        <groupId>geniusweb</groupId>
    4243                        <artifactId>references</artifactId>
    43                         <version>1.4.0</version>
     44                        <version>${geniusweb.version}</version>
     45                </dependency>
     46                <dependency>
     47                        <groupId>geniusweb</groupId>
     48                        <artifactId>events</artifactId>
     49                        <version>${geniusweb.version}</version>
     50                </dependency>
     51                <dependency>
     52                        <groupId>geniusweb</groupId>
     53                        <artifactId>timeline</artifactId>
     54                        <version>${geniusweb.version}</version>
    4455                </dependency>
    4556
  • 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}
  • opponentmodel/src/test/java/geniusweb/profile/opponentmodel/FrequencyOppModelTest.java

    r14 r18  
    33import static org.junit.Assert.assertEquals;
    44import static org.junit.Assert.assertTrue;
     5import static org.mockito.Mockito.mock;
    56
    67import java.math.BigDecimal;
     
    1415import org.junit.Test;
    1516
     17import geniusweb.actions.Offer;
     18import geniusweb.actions.PartyId;
    1619import geniusweb.issuevalue.Bid;
    1720import geniusweb.issuevalue.DiscreteValue;
     
    2326import geniusweb.issuevalue.ValueSet;
    2427import geniusweb.opponentmodel.FrequencyOpponentModel;
     28import geniusweb.progress.Progress;
    2529import tudelft.utilities.junit.GeneralTests;
    2630
     
    3236        private static final DiscreteValue I1V2 = new DiscreteValue("i1v2");
    3337        private static final DiscreteValue I1V2b = new DiscreteValue("i1v2b");
     38        private static final Progress progress = mock(Progress.class);
     39        private static final PartyId other = new PartyId("other");
    3440
    3541        private static Domain domain, domain2, domain3;
     
    8591                oppModel2 = new FrequencyOpponentModel(domain2);
    8692                oppModel3 = new FrequencyOpponentModel(domain3);
    87                 oppModel4 = (FrequencyOpponentModel) oppModel3.update(bid1);
     93                oppModel4 = oppModel3.with(new Offer(other, bid1), progress);
    8894
    8995        }
     
    106112
    107113        @Test(expected = NullPointerException.class)
    108         public void smokeNullTest() {
     114        public void smokeTestNull() {
    109115                new FrequencyOpponentModel(null);
    110116        }
     
    124130        @Test
    125131        public void testUpdate() {
    126                 FrequencyOpponentModel oppModel = oppModel1.update(bid1);
     132                FrequencyOpponentModel oppModel = oppModel1.with(new Offer(other, bid1),
     133                                progress);
    127134                assertTrue(BigDecimal.ONE.compareTo(oppModel.getUtility(bid1)) == 0);
    128135                assertTrue(BigDecimal.ZERO.compareTo(oppModel.getUtility(bid3)) == 0);
     
    135142                // bid1 and bid2 both want I1V1. They differ on the number value.
    136143                // bid3 wants I1V2 but does have the number value from bid2
    137                 FrequencyOpponentModel oppModel = oppModel1.update(bid1).update(bid2);
     144                FrequencyOpponentModel oppModel = oppModel1
     145                                .with(new Offer(other, bid1), progress)
     146                                .with(new Offer(other, bid2), progress);
    138147                assertTrue(new BigDecimal("0.75")
    139148                                .compareTo(oppModel.getUtility(bid1)) == 0);
Note: See TracChangeset for help on using the changeset viewer.