Changeset 10


Ignore:
Timestamp:
01/28/20 10:19:54 (5 years ago)
Author:
bart
Message:

Update 28 jan 2020

Files:
58 added
50 edited

Legend:

Unmodified
Added
Removed
  • bidspace/src/main/java/geniusweb/bidspace/BidsWithUtility.java

    r8 r10  
    1212import geniusweb.issuevalue.Domain;
    1313import geniusweb.issuevalue.Value;
    14 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     14import geniusweb.profile.utilityspace.LinearAdditive;
    1515import tudelft.utilities.immutablelist.AbstractImmutableList;
    1616import tudelft.utilities.immutablelist.FixedList;
     
    2222/**
    2323 * Tool class containing functions dealing with utilities of all bids in a given
    24  * {@link LinearAdditiveUtilitySpace}. This class caches previously computed
    25  * values to accelerate the calls and subsequent calls. Re-use the object to
    26  * keep/reuse the cache.
     24 * {@link LinearAdditive}. This class caches previously computed values to
     25 * accelerate the calls and subsequent calls. Re-use the object to keep/reuse
     26 * the cache.
    2727 * <h1>Rounding</h1> Internally, utilities of bids are rounded to the given
    2828 * precision. This may cause inclusion/exclusion of some bids in the results.
    29  * See {@link #BidsWithUtility(LinearAdditiveUtilitySpace, int)} for more
    30  * details
     29 * See {@link #BidsWithUtility(LinearAdditive, int)} for more details
    3130 */
    3231public class BidsWithUtility {
     
    4443         * Default constructor, uses default precision 6. This value seems practical
    4544         * for the common range of issues, utilities and weights. See
    46          * {@link #BidsWithUtil(LinearAdditiveUtilitySpace, int)} for more details
    47          * on the precision.
    48          *
    49          * @param space the {@link LinearAdditiveUtilitySpace} to analyze
    50          */
    51         public BidsWithUtility(LinearAdditiveUtilitySpace space) {
     45         * {@link #BidsWithUtil(LinearAdditive, int)} for more details on the
     46         * precision.
     47         *
     48         * @param space the {@link LinearAdditive} to analyze
     49         */
     50        public BidsWithUtility(LinearAdditive space) {
    5251                this(space, 6);
    5352        }
     
    5554        /**
    5655         *
    57          * @param space     the {@link LinearAdditiveUtilitySpace} to analyze
     56         * @param space     the {@link LinearAdditive} to analyze
    5857         * @param precision the number of digits to use for computations. In
    5958         *                  practice, 6 seems a good default value.
     
    7776         *
    7877         */
    79         public BidsWithUtility(LinearAdditiveUtilitySpace space, int precision) {
     78        public BidsWithUtility(LinearAdditive space, int precision) {
    8079                this(getInfo(space, precision), precision);
    8180        }
     
    119118        public List<IssueInfo> getInfo() {
    120119                return Collections.unmodifiableList(issueInfo);
     120        }
     121
     122        /**
     123         *
     124         * @param isMax the extreme bid required
     125         * @return the extreme bid, either the minimum if isMax=false or maximum if
     126         *         isMax=true
     127         */
     128        public Bid getExtremeBid(boolean isMax) {
     129                Map<String, Value> map = new HashMap<>();
     130                for (IssueInfo info : issueInfo) {
     131                        map.put(info.getName(), info.getExtreme(isMax));
     132                }
     133                return new Bid(map);
    121134        }
    122135
     
    154167        }
    155168
    156         private static List<IssueInfo> getInfo(LinearAdditiveUtilitySpace space2,
     169        private static List<IssueInfo> getInfo(LinearAdditive space2,
    157170                        int precision) {
    158171                Domain dom = space2.getDomain();
  • bidspace/src/main/java/geniusweb/bidspace/Interval.java

    r4 r10  
    137137                        if (other.max != null)
    138138                                return false;
    139                 } else if (!max.equals(other.max))
     139
     140                } else if (max.compareTo(other.max) != 0)
     141                        // THIS WAS FIXED MANUALLY TO USE COMPARETO
    140142                        return false;
    141143                if (min == null) {
    142144                        if (other.min != null)
    143145                                return false;
    144                 } else if (!min.equals(other.min))
     146                } else if (min.compareTo(other.min) != 0)
     147                        // THIS WAS FIXED MANUALLY TO USE COMPARETO
    145148                        return false;
    146149                return true;
  • bidspace/src/main/java/geniusweb/bidspace/IssueInfo.java

    r4 r10  
    4949        public Interval getInterval() {
    5050                return interval;
     51        }
     52
     53        /**
     54         *
     55         * @param isMax
     56         * @return the extreme value, either the minimum if isMax=false or maximum
     57         *         if isMax=true
     58         */
     59        public Value getExtreme(boolean isMax) {
     60                BigDecimal extremeutil = null;
     61                Value extremeval = null;
     62                for (Value val : values) {
     63                        BigDecimal util = weightedUtils.get(val);
     64                        if (extremeval == null) {
     65                                extremeutil = weightedUtils.get(val);
     66                                extremeval = val;
     67                        } else {
     68                                if (isMax) {
     69                                        if (util.compareTo(extremeutil) > 0) {
     70                                                extremeutil = util;
     71                                                extremeval = val;
     72                                        }
     73                                } else {
     74                                        if (util.compareTo(extremeutil) < 0) {
     75                                                extremeutil = util;
     76                                                extremeval = val;
     77                                        }
     78
     79                                }
     80                        }
     81                }
     82                return extremeval;
    5183        }
    5284
  • bidspace/src/main/java/geniusweb/bidspace/pareto/ParetoLinearAdditive.java

    r1 r10  
    1010import geniusweb.issuevalue.Domain;
    1111import geniusweb.profile.Profile;
    12 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     12import geniusweb.profile.utilityspace.LinearAdditive;
    1313
    1414/**
    15  * pareto frontier implementation for {@link LinearAdditiveUtilitySpace}.
    16  * Simplistic implementation that iterates over all bids.
     15 * pareto frontier implementation for {@link LinearAdditive}. Simplistic
     16 * implementation that iterates over all bids.
    1717 */
    1818public class ParetoLinearAdditive implements ParetoFrontier {
    1919
    20         private final List<LinearAdditiveUtilitySpace> utilSpaces;
     20        private final List<LinearAdditive> utilSpaces;
    2121        private Set<Bid> points = null;
    2222        // all issues in a deterministic order
     
    2424        /**
    2525         *
    26          * @param utilSpaces. Must contain at least two
    27          *                    {@link LinearAdditiveUtilitySpace}s and all must be
    28          *                    defined on the same donain.
     26         * @param utilSpaces. Must contain at least two {@link LinearAdditive}s and
     27         *                    all must be defined on the same donain.
    2928         */
    30         public ParetoLinearAdditive(List<LinearAdditiveUtilitySpace> utilSpaces) {
     29        public ParetoLinearAdditive(List<LinearAdditive> utilSpaces) {
    3130                if (utilSpaces == null || utilSpaces.size() < 2) {
    3231                        throw new IllegalArgumentException(
     
    3433                }
    3534                Domain domain = utilSpaces.get(0).getDomain();
    36                 for (LinearAdditiveUtilitySpace space : utilSpaces) {
     35                for (LinearAdditive space : utilSpaces) {
    3736                        if (!space.getDomain().equals(domain)) {
    3837                                throw new IllegalArgumentException(
  • bidspace/src/main/java/geniusweb/bidspace/pareto/ParetoPoint.java

    r1 r10  
    1010import geniusweb.issuevalue.Bid;
    1111import geniusweb.issuevalue.Value;
    12 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     12import geniusweb.profile.utilityspace.LinearAdditive;
    1313
    1414/**
     
    2626         *
    2727         * @param bid    a (possibly partial) {@link Bid}
    28          * @param spaces the {@link LinearAdditiveUtilitySpace}s to consider
     28         * @param spaces the {@link LinearAdditive}s to consider
    2929         */
    30         public ParetoPoint(Bid bid, List<LinearAdditiveUtilitySpace> spaces) {
     30        public ParetoPoint(Bid bid, List<LinearAdditive> spaces) {
    3131                this.bid = bid;
    3232                utilities = new ArrayList<>();
    33                 for (LinearAdditiveUtilitySpace space : spaces) {
     33                for (LinearAdditive space : spaces) {
    3434                        utilities.add(space.getUtility(bid));
    3535                }
  • bidspace/src/main/java/geniusweb/bidspace/pareto/PartialPareto.java

    r1 r10  
    88import geniusweb.issuevalue.Bid;
    99import geniusweb.issuevalue.Value;
    10 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     10import geniusweb.profile.utilityspace.LinearAdditive;
    1111
    1212/**
     
    2828         * implemented recursively (O(log(#issues))).
    2929         *
    30          * @param utilSpaces the {@link LinearAdditiveUtilitySpace}s
     30         * @param utilSpaces the {@link LinearAdditive}s
    3131         * @param issues     the issues (subset of all issues in the space) to be
    3232         *                   used for this pareto
     
    3434         *         given issues.
    3535         */
    36         public static PartialPareto create(
    37                         List<LinearAdditiveUtilitySpace> utilSpaces, List<String> issues) {
     36        public static PartialPareto create(List<LinearAdditive> utilSpaces,
     37                        List<String> issues) {
    3838
    3939                if (issues.size() == 1) {
  • bidspace/src/test/java/geniusweb/bidspace/pareto/ParetoE2Etest.java

    r1 r10  
    1919import com.fasterxml.jackson.databind.ObjectMapper;
    2020
    21 import geniusweb.bidspace.pareto.GenericPareto;
    22 import geniusweb.bidspace.pareto.ParetoFrontier;
    23 import geniusweb.bidspace.pareto.ParetoLinearAdditive;
    2421import geniusweb.profile.Profile;
     22import geniusweb.profile.utilityspace.LinearAdditive;
    2523import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
    2624
     
    6159                                .readValue(file2, Profile.class);
    6260
    63                 List<LinearAdditiveUtilitySpace> profiles = new LinkedList<>();
     61                List<LinearAdditive> profiles = new LinkedList<>();
    6462                profiles.add(profile1);
    6563                profiles.add(profile2);
  • bidspace/src/test/java/geniusweb/bidspace/pareto/ParetoPointTest.java

    r1 r10  
    1515import org.junit.Test;
    1616
    17 import geniusweb.bidspace.pareto.ParetoPoint;
    1817import geniusweb.issuevalue.Bid;
    1918import geniusweb.issuevalue.Value;
    20 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     19import geniusweb.profile.utilityspace.LinearAdditive;
    2120
    2221public class ParetoPointTest {
     
    2625        private static final BigDecimal D0_4 = BigDecimal.valueOf(0.4);
    2726        private static final BigDecimal D0_5 = BigDecimal.valueOf(0.5);
    28         private final LinearAdditiveUtilitySpace space1 = mock(
    29                         LinearAdditiveUtilitySpace.class),
    30                         space2 = mock(LinearAdditiveUtilitySpace.class);
     27        private final LinearAdditive space1 = mock(LinearAdditive.class),
     28                        space2 = mock(LinearAdditive.class);
    3129        private final Bid bid11 = mock(Bid.class), bid12 = mock(Bid.class),
    3230                        bid21 = mock(Bid.class), bid22 = mock(Bid.class);
  • bidspace/src/test/java/geniusweb/bidspace/pareto/PartialParetoTest.java

    r1 r10  
    1616import org.junit.Test;
    1717
    18 import geniusweb.bidspace.pareto.PartialPareto;
    1918import geniusweb.issuevalue.Bid;
    2019import geniusweb.issuevalue.Domain;
    2120import geniusweb.issuevalue.Value;
    2221import geniusweb.issuevalue.ValueSet;
    23 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     22import geniusweb.profile.utilityspace.LinearAdditive;
    2423
    2524public class PartialParetoTest {
     
    3130        private static final BigDecimal D0_5 = BigDecimal.valueOf(0.5);
    3231
    33         private final LinearAdditiveUtilitySpace space1 = mock(
    34                         LinearAdditiveUtilitySpace.class),
    35                         space2 = mock(LinearAdditiveUtilitySpace.class);
     32        private final LinearAdditive space1 = mock(LinearAdditive.class),
     33                        space2 = mock(LinearAdditive.class);
    3634
    3735        private Domain domain = mock(Domain.class);
  • events/src/main/java/geniusweb/actions/Action.java

    r1 r10  
    1212 */
    1313@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.WRAPPER_OBJECT)
    14 @JsonSubTypes({ @JsonSubTypes.Type(value = EndNegotiation.class), @JsonSubTypes.Type(value = Offer.class),
    15                 @JsonSubTypes.Type(value = Accept.class) })
     14@JsonSubTypes({ @JsonSubTypes.Type(value = EndNegotiation.class),
     15                @JsonSubTypes.Type(value = Offer.class),
     16                @JsonSubTypes.Type(value = Accept.class),
     17                @JsonSubTypes.Type(value = Comparison.class),
     18                @JsonSubTypes.Type(value = ElicitComparison.class) })
    1619public interface Action {
    1720        /**
  • events/src/main/java/geniusweb/actions/ActionWithBid.java

    r1 r10  
    77
    88/**
    9  * An {@link Action} containing a bid.
     9 * An {@link Action} containing a bid. Note that the presense of a bid does not
     10 * necessarily mean that an offer was placed for this bid.
    1011 *
    1112 */
  • exampleparties/humangui/src/main/java/geniusweb/exampleparties/humangui/HumanGui.java

    r9 r10  
    22
    33import java.awt.BorderLayout;
    4 import java.net.URI;
    5 import java.net.URISyntaxException;
    64import java.util.Arrays;
    75import java.util.HashSet;
     
    2321import geniusweb.profileconnection.ProfileConnectionFactory;
    2422import geniusweb.profileconnection.ProfileInterface;
    25 import geniusweb.references.ProtocolRef;
    2623import tudelft.utilities.logging.Reporter;
    2724
     
    8582        @Override
    8683        public Capabilities getCapabilities() {
    87                 try {
    88                         return new Capabilities(new HashSet<>(
    89                                         Arrays.asList(new ProtocolRef(new URI("SAOP")))));
    90                 } catch (URISyntaxException e) {
    91                         getReporter().log(Level.SEVERE, "Failed to create capabilities URI",
    92                                         e);
    93                         return null;
    94                 }
     84                return new Capabilities(new HashSet<>(Arrays.asList("SAOP")));
    9585        }
    9686
  • exampleparties/humangui/src/test/java/geniusweb/exampleparties/humangui/BiddingInfoTest.java

    r9 r10  
    3232import geniusweb.party.inform.Settings;
    3333import geniusweb.profile.Profile;
    34 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     34import geniusweb.profile.utilityspace.LinearAdditive;
    3535import geniusweb.profileconnection.ProfileConnectionFactory;
    3636import geniusweb.profileconnection.ProfileInterface;
     
    6161        private final ProgressRounds progress = mock(ProgressRounds.class);
    6262        private Settings settings;
    63         private LinearAdditiveUtilitySpace profile, profile2;
     63        private LinearAdditive profile, profile2;
    6464        private final Parameters parameters = new Parameters();
    6565        private Reporter reporter = mock(Reporter.class);
     
    7676                String serialized = new String(Files.readAllBytes(Paths.get(PROFILE)),
    7777                                StandardCharsets.UTF_8);
    78                 profile = (LinearAdditiveUtilitySpace) jackson.readValue(serialized,
    79                                 Profile.class);
     78                profile = (LinearAdditive) jackson.readValue(serialized, Profile.class);
    8079                String serialized2 = new String(Files.readAllBytes(Paths.get(PROFILE2)),
    8180                                StandardCharsets.UTF_8);
    82                 profile2 = (LinearAdditiveUtilitySpace) jackson.readValue(serialized2,
     81                profile2 = (LinearAdditive) jackson.readValue(serialized2,
    8382                                Profile.class);
    8483
  • exampleparties/humangui/src/test/java/geniusweb/exampleparties/humangui/HumanGuiTest.java

    r9 r10  
    3434import geniusweb.party.inform.YourTurn;
    3535import geniusweb.profile.Profile;
    36 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     36import geniusweb.profile.utilityspace.LinearAdditive;
    3737import geniusweb.progress.ProgressRounds;
    3838import geniusweb.references.Parameters;
     
    5757        private final ProgressRounds progress = mock(ProgressRounds.class);
    5858        private Settings settings;
    59         private LinearAdditiveUtilitySpace profile;
     59        private LinearAdditive profile;
    6060        private final Parameters parameters = new Parameters();
    6161
     
    7070                String serialized = new String(Files.readAllBytes(Paths.get(PROFILE)),
    7171                                StandardCharsets.UTF_8);
    72                 profile = (LinearAdditiveUtilitySpace) jackson.readValue(serialized,
    73                                 Profile.class);
     72                profile = (LinearAdditive) jackson.readValue(serialized, Profile.class);
    7473
    7574        }
     
    9392                Capabilities capabilities = party.getCapabilities();
    9493                assertFalse("party does not define protocols",
    95                                 capabilities.getProtocols().isEmpty());
     94                                capabilities.getBehaviours().isEmpty());
    9695        }
    9796
    9897        @Test
    9998        public void testGetCapabilities() {
    100                 assertTrue(party.getCapabilities().getProtocols().contains(SAOP));
     99                assertTrue(party.getCapabilities().getBehaviours().contains(SAOP));
    101100        }
    102101
  • exampleparties/pom.xml

    r2 r10  
    2323                <module>boulware</module>
    2424                <module>linear</module>
     25                <module>simpleshaop</module>
     26                <module>comparebids</module>
    2527        </modules>
    2628</project>
  • exampleparties/randomparty/src/main/java/geniusweb/exampleparties/randomparty/RandomParty.java

    r9 r10  
    33import java.io.IOException;
    44import java.math.BigInteger;
    5 import java.net.URI;
    6 import java.net.URISyntaxException;
    75import java.util.Arrays;
    86import java.util.HashSet;
     
    3028import geniusweb.progress.Progress;
    3129import geniusweb.progress.ProgressRounds;
    32 import geniusweb.references.ProtocolRef;
    3330import tudelft.utilities.logging.Reporter;
    3431
     
    8178        @Override
    8279        public Capabilities getCapabilities() {
    83                 try {
    84                         return new Capabilities(new HashSet<>(
    85                                         Arrays.asList(new ProtocolRef(new URI("SAOP")))));
    86                 } catch (URISyntaxException e) {
    87                         getReporter().log(Level.SEVERE, "Failed to create capabilities URI",
    88                                         e);
    89                         return null;
    90                 }
     80                return new Capabilities(new HashSet<>(Arrays.asList("SAOP")));
    9181        }
    9282
     
    115105        }
    116106
    117         private boolean isGood(Bid bid) {
     107        private boolean isGood(Bid bid) throws IOException {
    118108                if (bid == null)
    119109                        return false;
  • exampleparties/randomparty/src/test/java/geniusweb/exampleparties/randomparty/RandomPartyTest.java

    r9 r10  
    4242import geniusweb.party.inform.YourTurn;
    4343import geniusweb.profile.Profile;
    44 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     44import geniusweb.profile.utilityspace.LinearAdditive;
    4545import geniusweb.progress.ProgressRounds;
    4646import geniusweb.references.Parameters;
     
    5353public class RandomPartyTest {
    5454
    55         private static final ProtocolRef SAOP = new ProtocolRef("SAOP");
     55        private static final String SAOP = "SAOP";
    5656        private static final PartyId otherparty = new PartyId("other");
    5757        private static final String PROFILE = "src/test/resources/testprofile.json";
     
    6363        private final ProgressRounds progress = mock(ProgressRounds.class);
    6464        private Settings settings;
    65         private LinearAdditiveUtilitySpace profile;
     65        private LinearAdditive profile;
    6666        private final Parameters parameters = new Parameters();
    6767
     
    7676                String serialized = new String(Files.readAllBytes(Paths.get(PROFILE)),
    7777                                StandardCharsets.UTF_8);
    78                 profile = (LinearAdditiveUtilitySpace) jackson.readValue(serialized,
    79                                 Profile.class);
     78                profile = (LinearAdditive) jackson.readValue(serialized, Profile.class);
    8079
    8180        }
     
    9493                Capabilities capabilities = party.getCapabilities();
    9594                assertFalse("party does not define protocols",
    96                                 capabilities.getProtocols().isEmpty());
     95                                capabilities.getBehaviours().isEmpty());
    9796        }
    9897
     
    176175        @Test
    177176        public void testGetCapabilities() {
    178                 assertTrue(party.getCapabilities().getProtocols().contains(SAOP));
     177                assertTrue(party.getCapabilities().getBehaviours().contains(SAOP));
    179178        }
    180179
  • exampleparties/randompartypy/src/main/resources/RandomParty.py

    r9 r10  
    6565        # Override
    6666        def getCapabilities(self): # -> Capabilities
    67                 try:
    68                         return Capabilities(HashSet([ ProtocolRef(URI("SAOP"))]))
    69                 except:
    70                         getReporter().log(Level.SEVERE, "Failed to create capabilities URI",e);
    71                 return None
     67                        return Capabilities(HashSet([ "SAOP"]))
    7268
    7369        # Override
  • exampleparties/randompartypy/src/test/java/geniusweb/exampleparties/randompartypy/RandomPartyTest.java

    r9 r10  
    3939import geniusweb.party.inform.YourTurn;
    4040import geniusweb.profile.Profile;
    41 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     41import geniusweb.profile.utilityspace.LinearAdditive;
    4242import geniusweb.progress.ProgressRounds;
    4343import geniusweb.pythonadapter.PythonPartyAdapter;
     
    5151
    5252        private static final String PROFILE = "src/test/resources/testprofile.json";
    53         private static final ProtocolRef SAOP = new ProtocolRef("SAOP");
     53        private static final String SAOP = "SAOP";
    5454        private static final PartyId otherparty = new PartyId("other");
    5555        private final static ObjectMapper jackson = new ObjectMapper();
     
    6262        private final Parameters parameters = new Parameters();
    6363
    64         private LinearAdditiveUtilitySpace profile; // the real profile
     64        private LinearAdditive profile; // the real profile
    6565
    6666        @Before
     
    8080                String serialized = new String(Files.readAllBytes(Paths.get(PROFILE)),
    8181                                StandardCharsets.UTF_8);
    82                 profile = (LinearAdditiveUtilitySpace) jackson.readValue(serialized,
    83                                 Profile.class);
     82                profile = (LinearAdditive) jackson.readValue(serialized, Profile.class);
    8483
    8584        }
     
    9897                Capabilities capabilities = party.getCapabilities();
    9998                assertFalse("party does not define protocols",
    100                                 capabilities.getProtocols().isEmpty());
     99                                capabilities.getBehaviours().isEmpty());
    101100        }
    102101
     
    167166        @Test
    168167        public void testGetCapabilities() {
    169                 assertTrue(party.getCapabilities().getProtocols().contains(SAOP));
     168                assertTrue(party.getCapabilities().getBehaviours().contains(SAOP));
    170169        }
    171170
  • exampleparties/timedependentparty/src/main/java/geniusweb/exampleparties/timedependentparty/ExtendedUtilSpace.java

    r4 r10  
    1111import geniusweb.issuevalue.Bid;
    1212import geniusweb.issuevalue.Value;
    13 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     13import geniusweb.profile.utilityspace.LinearAdditive;
    1414import tudelft.utilities.immutablelist.ImmutableList;
    1515
     
    2020 */
    2121public class ExtendedUtilSpace {
    22         private LinearAdditiveUtilitySpace utilspace;
     22        private LinearAdditive utilspace;
    2323        private BigDecimal tolerance; // utility tolerance for a bid.
    2424        private BidsWithUtility bidutils;
     
    2727        private BigDecimal maxUtil;
    2828
    29         public ExtendedUtilSpace(LinearAdditiveUtilitySpace space) {
     29        public ExtendedUtilSpace(LinearAdditive space) {
    3030                this.utilspace = space;
    3131                bidutils = new BidsWithUtility(utilspace);
  • exampleparties/timedependentparty/src/main/java/geniusweb/exampleparties/timedependentparty/TimeDependentParty.java

    r8 r10  
    44import java.math.BigDecimal;
    55import java.math.BigInteger;
    6 import java.net.URI;
    7 import java.net.URISyntaxException;
    86import java.util.Arrays;
    97import java.util.HashSet;
     
    2422import geniusweb.party.inform.YourTurn;
    2523import geniusweb.profile.Profile;
    26 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     24import geniusweb.profile.utilityspace.LinearAdditive;
    2725import geniusweb.profileconnection.ProfileConnectionFactory;
    2826import geniusweb.profileconnection.ProfileInterface;
    2927import geniusweb.progress.Progress;
    3028import geniusweb.progress.ProgressRounds;
    31 import geniusweb.references.ProtocolRef;
    3229import tudelft.utilities.immutablelist.ImmutableList;
    3330import tudelft.utilities.logging.Reporter;
     
    4441        private static final BigDecimal DEC100 = new BigDecimal("100");
    4542        private ProfileInterface profileint;
    46         private LinearAdditiveUtilitySpace utilspace = null; // last received space
     43        private LinearAdditive utilspace = null; // last received space
    4744        private PartyId me;
    4845        private Progress progress;
     
    6158        @Override
    6259        public Capabilities getCapabilities() {
    63                 try {
    64                         return new Capabilities(new HashSet<>(
    65                                         Arrays.asList(new ProtocolRef(new URI("SAOP")))));
    66                 } catch (URISyntaxException e) {
    67                         getReporter().log(Level.SEVERE, "Failed to create capabilities URI",
    68                                         e);
    69                         return null;
    70                 }
     60                return new Capabilities(new HashSet<>(Arrays.asList("SAOP")));
    7161        }
    7262
     
    148138        }
    149139
    150         private LinearAdditiveUtilitySpace updateUtilSpace() {
     140        private LinearAdditive updateUtilSpace() throws IOException {
    151141                Profile newutilspace = profileint.getProfile();
    152142                if (!newutilspace.equals(utilspace)) {
    153                         utilspace = (LinearAdditiveUtilitySpace) newutilspace;
     143                        utilspace = (LinearAdditive) newutilspace;
    154144                        extendedspace = new ExtendedUtilSpace(utilspace);
    155145                }
  • exampleparties/timedependentparty/src/test/java/geniusweb/exampleparties/timedependentparty/TimeDependentPartyTest.java

    r9 r10  
    5353public class TimeDependentPartyTest {
    5454
    55         private static final ProtocolRef SAOP = new ProtocolRef("SAOP");
     55        private static final String SAOP = "SAOP";
    5656        private static final PartyId otherparty = new PartyId("other");
    5757        private static final String PROFILE = "src/test/resources/testprofile.json";
     
    105105                Capabilities capabilities = party.getCapabilities();
    106106                assertFalse("party does not define protocols",
    107                                 capabilities.getProtocols().isEmpty());
     107                                capabilities.getBehaviours().isEmpty());
    108108        }
    109109
     
    198198        @Test
    199199        public void testGetCapabilities() {
    200                 assertTrue(party.getCapabilities().getProtocols().contains(SAOP));
     200                assertTrue(party.getCapabilities().getBehaviours().contains(SAOP));
    201201        }
    202202
  • party/src/main/java/geniusweb/party/Capabilities.java

    r1 r10  
    55import com.fasterxml.jackson.annotation.JsonAutoDetect;
    66import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
    7 
    8 import geniusweb.references.ProtocolRef;
    9 
    107import com.fasterxml.jackson.annotation.JsonCreator;
    118import com.fasterxml.jackson.annotation.JsonProperty;
     
    1916         * List of supported protocols
    2017         */
    21         private final Set<ProtocolRef> protocols;
     18        private final Set<String> behaviours;
    2219
    2320        /**
     
    2623         */
    2724        @JsonCreator
    28         public Capabilities(@JsonProperty("protocols") Set<ProtocolRef> protocols) {
    29                 if (protocols == null) {
    30                         throw new IllegalArgumentException("protocols==null");
     25        public Capabilities(@JsonProperty("behaviours") Set<String> behaviours) {
     26                if (behaviours == null) {
     27                        throw new IllegalArgumentException("behaviours==null");
    3128                }
    32                 this.protocols = protocols;
     29                this.behaviours = behaviours;
    3330        }
    3431
    35         public Set<ProtocolRef> getProtocols() {
    36                 return protocols;
     32        public Set<String> getBehaviours() {
     33                return behaviours;
    3734        }
    3835
     
    4239                int result = 1;
    4340                result = prime * result
    44                                 + ((protocols == null) ? 0 : protocols.hashCode());
     41                                + ((behaviours == null) ? 0 : behaviours.hashCode());
    4542                return result;
    4643        }
     
    5552                        return false;
    5653                Capabilities other = (Capabilities) obj;
    57                 if (protocols == null) {
    58                         if (other.protocols != null)
     54                if (behaviours == null) {
     55                        if (other.behaviours != null)
    5956                                return false;
    60                 } else if (!protocols.equals(other.protocols))
     57                } else if (!behaviours.equals(other.behaviours))
    6158                        return false;
    6259                return true;
     
    6562        @Override
    6663        public String toString() {
    67                 return "Capabilities[" + "Protocols=" + protocols + "]";
     64                return "Capabilities[" + "Behaviours=" + behaviours + "]";
    6865        }
    6966
  • party/src/main/java/geniusweb/party/inform/Inform.java

    r1 r10  
    33import com.fasterxml.jackson.annotation.JsonAutoDetect;
    44import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
     5import com.fasterxml.jackson.annotation.JsonSubTypes;
     6import com.fasterxml.jackson.annotation.JsonTypeInfo;
    57
    68import geniusweb.party.Party;
    7 
    8 import com.fasterxml.jackson.annotation.JsonSubTypes;
    9 import com.fasterxml.jackson.annotation.JsonTypeInfo;
    109
    1110/**
  • party/src/test/java/geniusweb/party/CapabilitiesTest.java

    r1 r10  
    44
    55import java.io.IOException;
    6 import java.net.URI;
    76import java.net.URISyntaxException;
    87import java.util.Arrays;
     
    1817import com.fasterxml.jackson.databind.ObjectMapper;
    1918
    20 import geniusweb.party.Capabilities;
    21 import geniusweb.references.ProtocolRef;
    2219import tudelft.utilities.junit.GeneralTests;
    2320
     
    2623        private Capabilities capabilities1, capabilities1a, capabilities2,
    2724                        capabilities3;
    28         private String asJson = "{\"protocols\":[\"ws:localhost/protocol1\"]}";
     25        private String asJson = "{\"behaviours\":[\"SAOP\"]}";
    2926
    3027        @Before
    3128        public void before() throws URISyntaxException {
    32                 capabilities1 = new Capabilities(Sets
    33                                 .newSet(new ProtocolRef(new URI("ws:localhost/protocol1"))));
    34                 capabilities1a = new Capabilities(Sets
    35                                 .newSet(new ProtocolRef(new URI("ws:localhost/protocol1"))));
    36                 capabilities2 = new Capabilities(Sets
    37                                 .newSet(new ProtocolRef(new URI("ws:localhost/protocol2"))));
    38                 capabilities3 = new Capabilities(Sets
    39                                 .newSet(new ProtocolRef(new URI("ws:localhost/protocol3"))));
     29                capabilities1 = new Capabilities(Sets.newSet("SAOP"));
     30                capabilities1a = new Capabilities(Sets.newSet("SAOP"));
     31                capabilities2 = new Capabilities(Sets.newSet("SEB"));
     32                capabilities3 = new Capabilities(Sets.newSet("SEB", "SAOP"));
    4033        }
    4134
     
    4841        @Override
    4942        public List<String> getGeneralTestStrings() {
    50                 return Arrays.asList(
    51                                 "Capabilities.*Protocols=.*ProtocolRef.*protocol1.*",
    52                                 "Capabilities.*Protocols=.*ProtocolRef.*protocol2.*",
    53                                 "Capabilities.*Protocols=.*ProtocolRef.*protocol3.*");
     43                return Arrays.asList("Capabilities.*Behaviours=.*SAOP.*",
     44                                "Capabilities.*Behaviours=.*SEB.*",
     45                                "Capabilities.*Behaviours=.*SEB.*SAOP.*");
    5446        }
    5547
  • profile/src/main/java/geniusweb/profile/DefaultPartialOrdering.java

    r2 r10  
    2626 * limited anyway.
    2727 */
    28 public class DefaultPartialOrdering extends DefaultProfile implements PartialOrdering {
     28public class DefaultPartialOrdering extends DefaultProfile
     29                implements PartialOrdering {
    2930
    3031        /**
     
    4041         * @param reservationbid
    4142         * @param bids
    42          * @param isbetterList   a list of tuples [bid1index, bid2index]. It indicates
    43          *                       that bids[bid1index] isbetterthan bids[bid2index].
     43         * @param isbetterList   a list of tuples [bid1index, bid2index]. It
     44         *                       indicates that bids[bid1index] isbetterthan
     45         *                       bids[bid2index].
    4446         */
    4547        @JsonCreator
    46         public DefaultPartialOrdering(@JsonProperty("name") String name, @JsonProperty("domain") Domain domain,
    47                         @JsonProperty("reservationBid") Bid reservationbid, @JsonProperty("bids") List<Bid> bids,
     48        public DefaultPartialOrdering(@JsonProperty("name") String name,
     49                        @JsonProperty("domain") Domain domain,
     50                        @JsonProperty("reservationBid") Bid reservationbid,
     51                        @JsonProperty("bids") List<Bid> bids,
    4852                        @JsonProperty("better") List<List<Integer>> isbetterList) {
    4953                this(name, domain, reservationbid, makeBidMap(bids, isbetterList));
     
    5458         * @param domain         the {@link Domain} description
    5559         * @param reservationbid the reservation {@link Bid}
    56          * @param isBetterMap    a map with keys = a better bid and value=a less good
    57          *                       bid.
     60         * @param isBetterMap    a map with keys = a better bid and value=a less
     61         *                       good bid.
    5862         */
    59         public DefaultPartialOrdering(String name, Domain domain, Bid reservationbid, Map<Bid, Set<Bid>> isBetterMap) {
     63        public DefaultPartialOrdering(String name, Domain domain,
     64                        Bid reservationbid, Map<Bid, Set<Bid>> isBetterMap) {
    6065                super(name, domain, reservationbid);
    6166                this.isBetter = isBetterMap;
     
    7176        /**
    7277         *
    73          * @return a list with all the bids
     78         * @return a list with all the bids that are referred to, either as better
     79         *         or as worse than another bid
    7480         */
    7581        @JsonGetter
     
    97103                        if (isBetter.containsKey(bid)) {
    98104                                for (Bid worsebid : isBetter.get(bid)) {
    99                                         betterlist.add(Arrays.asList(bidslist.indexOf(bid), bidslist.indexOf(worsebid)));
     105                                        betterlist.add(Arrays.asList(bidslist.indexOf(bid),
     106                                                        bidslist.indexOf(worsebid)));
    100107                                }
    101108                        }
     
    107114        @Override
    108115        public String toString() {
    109                 return "DefaultPartialOrdering[" + getValuesString() + "," + isBetter + "]";
     116                return "DefaultPartialOrdering[" + getValuesString() + "," + isBetter
     117                                + "]";
    110118        }
    111119
    112         private static Map<Bid, Set<Bid>> makeBidMap(List<Bid> bids, List<List<Integer>> isBetterList) {
     120        private static Map<Bid, Set<Bid>> makeBidMap(List<Bid> bids,
     121                        List<List<Integer>> isBetterList) {
    113122                Map<Bid, Set<Bid>> betterMap = new HashMap<>();
    114123
    115124                for (List<Integer> tuple : isBetterList) {
    116125                        if (tuple.size() != 2) {
    117                                 throw new IllegalArgumentException("Expected tuple but found " + tuple + "in " + isBetterList);
     126                                throw new IllegalArgumentException("Expected tuple but found "
     127                                                + tuple + "in " + isBetterList);
    118128                        }
    119129                        Bid betterbid = bids.get(tuple.get(0));
     
    133143                final int prime = 31;
    134144                int result = super.hashCode();
    135                 result = prime * result + ((isBetter == null) ? 0 : isBetter.hashCode());
     145                result = prime * result
     146                                + ((isBetter == null) ? 0 : isBetter.hashCode());
    136147                return result;
    137148        }
  • profile/src/main/java/geniusweb/profile/utilityspace/DiscreteValueSetUtilities.java

    r9 r10  
    22
    33import java.math.BigDecimal;
     4import java.util.Collections;
    45import java.util.HashMap;
    56import java.util.HashSet;
     
    6869        }
    6970
     71        /**
     72         * @return copy of the value-utility pair map.
     73         */
     74        public Map<DiscreteValue, BigDecimal> getUtilities() {
     75                return Collections.unmodifiableMap(valueUtilities);
     76        }
     77
    7078        @Override
    7179        public String isFitting(ValueSet valueset) {
  • profile/src/main/java/geniusweb/profile/utilityspace/LinearAdditiveUtilitySpace.java

    r7 r10  
    2525 */
    2626@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE)
    27 public class LinearAdditiveUtilitySpace implements UtilitySpace {
     27public class LinearAdditiveUtilitySpace implements LinearAdditive {
    2828
    2929        private final String name;
     
    131131        }
    132132
    133         /**
    134          *
    135          * @param issue the issue to get weighted util for
    136          * @param value the issue value to use (typically coming from a bid)
    137          * @return weighted util of just the issue value:
    138          *         issueUtilities[issue].utility(value) * issueWeights[issue)
    139          */
    140         private BigDecimal util(String issue, Value value) {
    141                 return issueWeights.get(issue)
    142                                 .multiply(issueUtilities.get(issue).getUtility(value));
    143         }
    144 
     133        @Override
    145134        public BigDecimal getWeight(String issue) {
    146135                return issueWeights.get(issue);
     
    220209        }
    221210
    222         /**
    223          * @return the map from issue names to valuesetutilities (un-weighted)
    224          */
     211        @Override
    225212        public Map<String, ValueSetUtilities> getUtilities() {
    226213                return Collections.unmodifiableMap(issueUtilities);
    227214        }
    228215
    229         /**
    230          *
    231          * @return the map from issue names to weights. weights sum to 1.
    232          */
     216        @Override
    233217        public Map<String, BigDecimal> getWeights() {
    234218                return Collections.unmodifiableMap(issueWeights);
    235219        }
    236220
     221        /**
     222         *
     223         * @param issue the issue to get weighted util for
     224         * @param value the issue value to use (typically coming from a bid)
     225         * @return weighted util of just the issue value:
     226         *         issueUtilities[issue].utility(value) * issueWeights[issue)
     227         */
     228        private BigDecimal util(String issue, Value value) {
     229                return issueWeights.get(issue)
     230                                .multiply(issueUtilities.get(issue).getUtility(value));
     231        }
     232
    237233}
  • profile/src/main/java/geniusweb/profile/utilityspace/SumOfGroupsUtilitySpace.java

    r9 r10  
    8484         * grouping.
    8585         *
    86          * @param las the {@link LinearAdditiveUtilitySpace} to be converted/copied.
    87          *
    88          */
    89         public SumOfGroupsUtilitySpace(LinearAdditiveUtilitySpace las) {
     86         * @param las the {@link LinearAdditive} to be converted/copied.
     87         *
     88         */
     89        public SumOfGroupsUtilitySpace(LinearAdditive las) {
    9090                this(las.getDomain(), las.getName(), las2parts(las),
    9191                                las.getReservationBid());
     
    212212        /**
    213213         *
    214          * @param las a {@link LinearAdditiveUtilitySpace}
     214         * @param las a {@link LinearAdditive}
    215215         * @return a Map with partname-PartsUtilities. The partnames are identical
    216216         *         to the issues in the given las.
    217217         */
    218218        private static HashMap<String, PartsUtilities> las2parts(
    219                         LinearAdditiveUtilitySpace las) {
     219                        LinearAdditive las) {
    220220
    221221                HashMap<String, PartsUtilities> map = new HashMap<>();
  • profile/src/test/java/geniusweb/profile/utilityspace/NumberValueSetUtilTest.java

    r9 r10  
    33import static org.junit.Assert.assertEquals;
    44
     5import java.io.IOException;
    56import java.math.BigDecimal;
    67import java.util.Arrays;
     
    89
    910import org.junit.Test;
     11
     12import com.fasterxml.jackson.core.JsonParseException;
     13import com.fasterxml.jackson.core.JsonProcessingException;
     14import com.fasterxml.jackson.databind.JsonMappingException;
     15import com.fasterxml.jackson.databind.ObjectMapper;
    1016
    1117import geniusweb.issuevalue.DiscreteValue;
     
    3541                        lowval1, low1util, highvalb, highutil);
    3642        private static final BigDecimal ZERO_1 = new BigDecimal("0.1");
     43        private final String utilstring = "{\"numberutils\":{\"lowValue\":12.5,\"lowUtility\":0.5,\"highValue\":18.5,\"highUtility\":0.9}}";
     44
     45        private static final ObjectMapper jackson = new ObjectMapper();
    3746
    3847        @Override
     
    173182        }
    174183
     184        @Test
     185        public void testSerialize() throws JsonProcessingException {
     186
     187                String json = jackson.writeValueAsString(valueset1);
     188                System.out.println(json);
     189                assertEquals(utilstring, json);
     190        }
     191
     192        @Test
     193        public void testDeserialize()
     194                        throws JsonParseException, JsonMappingException, IOException {
     195                ValueSetUtilities valueutils = jackson.readValue(utilstring,
     196                                ValueSetUtilities.class);
     197                assertEquals(valueset1, valueutils);
     198
     199        }
     200
    175201}
  • profileconnection/src/main/java/geniusweb/profileconnection/ProfileInterface.java

    r9 r10  
    11package geniusweb.profileconnection;
     2
     3import java.io.IOException;
    24
    35import geniusweb.profile.Profile;
     
    1214         * @return the latest version of the profile. May change at any time, after
    1315         *         someone updates the version on the server. Call to this may block
    14          *         for limited time if the profile is not yet available. May return
    15          *         null if the profile is not available.
    16          */
    17         public Profile getProfile();
     16         *         for limited time if the profile is not yet available.
     17         *         @throws IOException if profile can not be fetched     */
     18        public Profile getProfile() throws IOException;
    1819}
  • profileconnection/src/main/java/geniusweb/profileconnection/WebsocketProfileConnector.java

    r9 r10  
    6969
    7070        @Override
    71         public Profile getProfile() {
     71        public Profile getProfile() throws IOException {
    7272                int remaining_wait = TIMEOUT_MS;
    7373                try {
     
    8080                                        e);
    8181                }
     82                if (profile == null) {
     83                        throw new IOException("Failed to fetch profile");
     84                }
    8285                return profile;
    8386        }
  • profileconnection/src/test/java/geniusweb/profileconnection/WebsocketProfileConnectorTest.java

    r1 r10  
    33import static org.junit.Assert.assertEquals;
    44import static org.junit.Assert.assertNotNull;
    5 import static org.junit.Assert.assertNull;
    65import static org.mockito.Matchers.any;
    76import static org.mockito.Mockito.mock;
     
    2221
    2322import geniusweb.profile.Profile;
    24 import geniusweb.profileconnection.WebsocketProfileConnector;
    2523import tudelft.utilities.logging.Reporter;
    2624
     
    4240
    4341        @Test
    44         public void testOnOpen()
     42        public void onOpenSmokeTest()
    4543                        throws IOException, DeploymentException, URISyntaxException {
    4644                WebsocketProfileConnector connector = new WebsocketProfileConnector(
    4745                                new URI("ws://someprofile"), reporter, wscontainer);
    4846                connector.onOpen(session);
    49                 assertNull(connector.getProfile());
    5047        }
    5148
     
    9390        }
    9491
    95         @Test
     92        @Test(expected = IOException.class)
    9693        public void testGetProfileTimeout()
    9794                        throws DeploymentException, IOException, URISyntaxException {
     
    116113                        }
    117114                }).start();
    118                 Profile profile = connector.getProfile();
    119                 assertNull(profile);
     115                connector.getProfile();
    120116        }
    121117
  • protocol/src/main/java/geniusweb/protocol/session/DefaultSessionState.java

    r9 r10  
    6464                        Map<PartyId, PartyWithProfile> partyprofiles, ProtocolException e) {
    6565                if (partyprofiles == null) {
    66                         partyprofiles = Collections.EMPTY_MAP;
     66                        partyprofiles = Collections.emptyMap();
    6767                }
    6868                if (conns == null) {
    6969                        this.connections = new ProtocolToPartyConnections(
    70                                         Collections.EMPTY_LIST);
     70                                        Collections.emptyList());
    7171                } else {
    7272                        this.connections = conns;
     
    9797
    9898        /**
    99          * @return
    10099         * @return map with {@link PartyWithProfile} for the parties. May be an
    101100         *         incomplete map, as more parties with their profiles may be set
  • protocol/src/main/java/geniusweb/protocol/session/SessionSettings.java

    r1 r10  
    77import geniusweb.protocol.NegoSettings;
    88import geniusweb.protocol.session.saop.SAOPSettings;
     9import geniusweb.protocol.session.shaop.SHAOPSettings;
    910import geniusweb.references.PartyWithProfile;
    1011import tudelft.utilities.logging.Reporter;
     
    1314 * interface for settings for session protocols. Immutable.
    1415 */
    15 @JsonSubTypes({ @JsonSubTypes.Type(value = SAOPSettings.class) })
    16 
     16@JsonSubTypes({ @JsonSubTypes.Type(value = SAOPSettings.class),
     17                @JsonSubTypes.Type(value = SHAOPSettings.class) })
    1718public interface SessionSettings extends NegoSettings {
    1819
     
    2223         * @return list of {@link PartyWithProfile} items.
    2324         */
    24         public List<PartyWithProfile> getParticipants();
     25        List<TeamOfPartiesAndProfiles> getTeams();
    2526
    2627        /**
    27          * Allows modification of SessionSettings to include a party. This is needed for
    28          * tournament auto-configuration of sessions.
     28         * Allows modification of SessionSettings to include a party. This is needed
     29         * for tournament auto-configuration of sessions.
    2930         *
    30          * @param partyprof the party with profile to be added
     31         * @param partyprofteam the {@link TeamOfPartiesAndProfiles} to be added
    3132         * @return new modified SessionSettings object
    3233         */
    33         public SessionSettings with(PartyWithProfile partyprof);
     34        SessionSettings with(TeamOfPartiesAndProfiles partyprofteam);
     35
     36        /**
     37         *
     38         * @return all parties from all teams, as a flattened ordered list. The
     39         *         order : start with all parties from team 1, then all from team 2,
     40         *         etc. The specific order of the parties from a team depends on the
     41         *         protocol.
     42         */
     43        List<PartyWithProfile> getAllParties();
    3444
    3545        /**
    3646         * @param logger the logger where the protocol can log events to.
    37          * @return the an initialized and ready to use {@link SessionProtocol} that can
    38          *         handle this Negotiation.
     47         * @return the an initialized and ready to use {@link SessionProtocol} that
     48         *         can handle this Negotiation.
    3949         */
    4050        @Override
    41         public SessionProtocol getProtocol(Reporter logger);
     51        SessionProtocol getProtocol(Reporter logger);
    4252
    4353}
  • protocol/src/main/java/geniusweb/protocol/session/saop/SAOP.java

    r9 r10  
    6565public class SAOP extends DefaultListenable<ProtocolEvent>
    6666                implements SessionProtocol {
    67         private static final int TIME_MARGIN = 20;// ms extra delay after deadline
    68         private static final int MINDURATION = 100;
    69         private static final int MIN_SLEEP_TIME = 1000;
    70         private static final int MAX_SLEEP_TIME = 60000;
     67        public static final int TIME_MARGIN = 20;// ms extra delay after deadline
     68        public static final int MINDURATION = 100;
     69        public static final int MIN_SLEEP_TIME = 1000;
     70        public static final int MAX_SLEEP_TIME = 60000;
    7171        private static final ProtocolRef SAOP = new ProtocolRef("SAOP");
    7272        private final Reporter log;
     
    154154                        throws InterruptedException, IOException {
    155155                List<PartyWithProfile> participants = state.getSettings()
    156                                 .getParticipants();
     156                                .getAllParties();
    157157                List<Reference> parties = participants.stream()
    158158                                .map(parti -> (parti.getParty().getPartyRef()))
     
    319319                        setState(state.with(new ProtocolException(message, party, e)));
    320320                }
     321                log.log(Level.WARNING, "SAOP protocol intercepted error due to party "
     322                                + party + ":" + message, e);
    321323        }
    322324
  • protocol/src/main/java/geniusweb/protocol/session/saop/SAOPSettings.java

    r1 r10  
    44import java.util.LinkedList;
    55import java.util.List;
     6import java.util.stream.Collectors;
    67
    78import com.fasterxml.jackson.annotation.JsonCreator;
     
    1112import geniusweb.protocol.session.SessionProtocol;
    1213import geniusweb.protocol.session.SessionSettings;
     14import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
    1315import geniusweb.references.PartyWithProfile;
    1416import tudelft.utilities.logging.Reporter;
    1517
    1618public class SAOPSettings implements SessionSettings {
    17         private final List<PartyWithProfile> participants;
     19        private final List<SaopPartyWithProfile> participants;
    1820        private final Deadline deadline;
    1921
     
    2830        @JsonCreator
    2931        public SAOPSettings(
    30                         @JsonProperty("participants") List<PartyWithProfile> participants,
     32                        @JsonProperty("participants") List<SaopPartyWithProfile> participants,
    3133                        @JsonProperty("deadline") Deadline deadline) {
    3234                this.participants = participants;
     
    5153
    5254        @Override
    53         public List<PartyWithProfile> getParticipants() {
     55        public List<TeamOfPartiesAndProfiles> getTeams() {
    5456                return Collections.unmodifiableList(participants);
    5557        }
     
    6062        public Deadline getDeadline() {
    6163                return deadline;
     64        }
     65
     66        @Override
     67        public List<PartyWithProfile> getAllParties() {
     68                return participants.stream()
     69                                .map(particip -> particip.getAllParties().get(0))
     70                                .collect(Collectors.toList());
    6271        }
    6372
     
    101110
    102111        @Override
    103         public SessionSettings with(PartyWithProfile party) {
    104                 List<PartyWithProfile> newparts = new LinkedList<>(participants);
    105                 newparts.add(party);
     112        public SessionSettings with(TeamOfPartiesAndProfiles party) {
     113                if (!(party instanceof SaopPartyWithProfile))
     114                        throw new IllegalArgumentException(
     115                                        "Added party must be SaopPartyWithProfile but got "
     116                                                        + party);
     117                List<SaopPartyWithProfile> newparts = new LinkedList<>(participants);
     118                newparts.add((SaopPartyWithProfile) party);
    106119                return new SAOPSettings(newparts, deadline);
    107120        }
  • protocol/src/main/java/geniusweb/protocol/session/saop/SAOPState.java

    r9 r10  
    1616import geniusweb.progress.ProgressRounds;
    1717import geniusweb.protocol.ProtocolException;
     18import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    1819import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    19 import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    2020import geniusweb.protocol.session.DefaultSessionState;
    2121import geniusweb.protocol.session.SessionSettings;
     
    6161
    6262        /**
    63          * @param actor         the actor that did this action. Can be used to check
    64          *                      if action is valid. NOTICE caller has to make sure
    65          *                      the current state is not final.
    66          * @param action        the action that was proposed by actor.
    67          * @param currentTimeMs the current time in ms since 1970, see
    68          *                      {@link System#currentTimeMillis()}
    69          * @return new SessionState with the action added as last action.
    70          */
    71         public SAOPState with(PartyId actor, Action action) {
    72                 try {
    73                         return with1(actor, action);
    74                 } catch (ProtocolException e) {
    75                         List<Action> newactions = new LinkedList<>(getActions());
    76                         newactions.add(action);
    77                         return new SAOPState(newactions, getConnections(), getProgress(),
    78                                         getSettings(), getPartyProfiles(), e);
    79                 }
    80         }
    81 
    82         /**
    8363         *
    8464         * @param connection   the new {@link ProtocolToPartyConn}
     
    164144
    165145        /**
     146         * @param actor         the actor that did this action. Can be used to check
     147         *                      if action is valid. NOTICE caller has to make sure
     148         *                      the current state is not final.
     149         * @param action        the action that was proposed by actor.
     150         * @param currentTimeMs the current time in ms since 1970, see
     151         *                      {@link System#currentTimeMillis()}
     152         * @return new SessionState with the action added as last action.
     153         */
     154
     155        public SAOPState with(PartyId actor, Action action) {
     156
     157                if (actor == null) { // this is a bug
     158                        throw new IllegalArgumentException("actor must not be null");
     159                }
     160                if (!actor.equals(getNextActor())) {
     161                        throw new IllegalArgumentException("Party does not have the turn ");
     162
     163                }
     164                if (action == null) {
     165                        throw new IllegalArgumentException("action is null");
     166                }
     167                if (!actor.equals(action.getActor())) {
     168                        throw new IllegalArgumentException(
     169                                        "act contains wrong credentials: " + action);
     170                }
     171
     172                // check protocol is followed for specific actions
     173                if (action instanceof Accept) {
     174                        Bid bid = getLastBid();
     175                        if (bid == null) {
     176                                throw new IllegalArgumentException(
     177                                                "Accept without a recent offer");
     178                        }
     179                        if (!bid.equals(((Accept) action).getBid())) {
     180                                throw new IllegalArgumentException(
     181                                                "Party accepts a bid differing from the last offer ="
     182                                                                + bid + ", action=" + action + ")");
     183                        }
     184                } else if (action instanceof Offer) {
     185                        // offer is always fine. We don't check if bid is actually in domain
     186                        // or complete etc. We would need domain for that
     187                } else if (action instanceof EndNegotiation) {
     188                        // just act, we will get into the final state then.
     189                } else {
     190                        throw new IllegalArgumentException(
     191                                        "Action " + action + " is not allowed in SAOP");
     192                }
     193
     194                List<Action> newactions = new LinkedList<>(getActions());
     195                newactions.add(action);
     196                return new SAOPState(newactions, getConnections(), advanceProgress(),
     197                                getSettings(), getPartyProfiles(), null);
     198        }
     199
     200        /**
    166201         * Check up to nparticipants-1 steps back if there was an offer.
    167202         *
     
    182217        }
    183218
    184         private SAOPState with1(PartyId actor, Action action)
    185                         throws ProtocolException {
    186 
    187                 if (actor == null) { // this is a bug
    188                         throw new IllegalArgumentException("actor must not be null");
    189                 }
    190                 if (!actor.equals(getNextActor())) {
    191                         throw new ProtocolException("Party does not have the turn ",
    192                                         actor.getName());
    193 
    194                 }
    195                 if (action == null) {
    196                         throw new ProtocolException("action is null", actor.getName());
    197                 }
    198                 if (!actor.equals(action.getActor())) {
    199                         throw new ProtocolException(
    200                                         "act contains wrong credentials: " + action,
    201                                         actor.getName());
    202                 }
    203 
    204                 // check protocol is followed for specific actions
    205                 if (action instanceof Accept) {
    206                         Bid bid = getLastBid();
    207                         if (bid == null) {
    208                                 throw new ProtocolException("Accept without a recent offer",
    209                                                 actor.getName());
    210                         }
    211                         if (!bid.equals(((Accept) action).getBid())) {
    212                                 throw new ProtocolException(
    213                                                 "Party accepts a bid differing from the last offer ="
    214                                                                 + bid + ", action=" + action + ")",
    215                                                 actor.getName());
    216                         }
    217                 } else if (action instanceof Offer) {
    218                         // offer is always fine. We don't check if bid is actually in domain
    219                         // or complete etc. We would need domain for that
    220                 } else if (action instanceof EndNegotiation) {
    221                         // just act, we will get into the final state then.
    222                 } else {
    223                         throw new ProtocolException(
    224                                         "Action " + action + " is not allowed in SAOP",
    225                                         actor.getName());
    226                 }
    227 
    228                 List<Action> newactions = new LinkedList<>(getActions());
    229                 newactions.add(action);
    230                 return new SAOPState(newactions, getConnections(), advanceProgress(),
    231                                 getSettings(), getPartyProfiles(), null);
    232         }
    233 
    234219        /**
    235220         *
  • protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsProtocol.java

    r9 r10  
    8181                        long now = System.currentTimeMillis();
    8282                        if (sessionstate.isFinal(now)) {
     83                                // List<TeamOfPartiesAndProfiles> participants =
     84                                // sessionstate.getSettings().getParticipants()
    8385                                SessionResult result = new SessionResult(
    84                                                 sessionstate.getSettings().getParticipants(),
     86                                                sessionstate.getSettings().getAllParties(),
    8587                                                sessionstate.getAgreement(), sessionstate.getError());
    8688                                state = state.with(result);
  • protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettings.java

    r8 r10  
    11package geniusweb.protocol.tournament.allpermutations;
    22
     3import java.net.URI;
     4import java.net.URISyntaxException;
    35import java.util.Collections;
    46import java.util.List;
     
    79import com.fasterxml.jackson.annotation.JsonProperty;
    810
     11import geniusweb.profile.Profile;
    912import geniusweb.protocol.session.SessionSettings;
     13import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
     14import geniusweb.protocol.session.saop.SAOPSettings;
     15import geniusweb.protocol.session.saop.SaopPartyWithProfile;
     16import geniusweb.protocol.session.shaop.SHAOPSettings;
     17import geniusweb.protocol.session.shaop.ShaopTeam;
    1018import geniusweb.protocol.tournament.TournamentProtocol;
    1119import geniusweb.protocol.tournament.TournamentSettings;
     20import geniusweb.references.Parameters;
    1221import geniusweb.references.PartyRef;
    1322import geniusweb.references.PartyWithParameters;
     
    3039 * Takes a number of parties and profiles and makes all permutations of them
    3140 * with the given number of parties and profiles. All profiles must be in the
    32  * same domain. All sessions are based on the given sessionsettings (can be any
    33  * session protocol). The parties for each tournament session are added to this
    34  * basic sessionsettings.
    35  *
     41 * same domain.
     42 * <p>
     43 * All sessions are based on the given {@link SessionSettings} (can be
     44 * {@link SAOPSettings} or {@link SHAOPSettings}). The parties for each
     45 * tournament session are added to this basic sessionsettings. sessionsettings
     46 * contains basically all the normal run-sessionsettings. This is used as a
     47 * "template" for all sessions of the tournament. You can put any use any
     48 * session setting here, and each session will be run according to the protocol
     49 * you select here.
     50 *
     51 * The participants list usually is empty. The AllPermutationsProtocol adds the
     52 * the required parties to this list. So if you provide a non-empty list here,
     53 * then these parties would be present in every session in the tournament.
     54 * <p>
     55 * If the tournament is used with a SHAOP sessionsettings, a number of rules are
     56 * used to generate the COB party from the settings.
     57 *
     58 * The COB party is assumed to be the comparebids-1.0.0 party on the same server
     59 * as the party you provide. So if you provide http://server/../party1-1.2.3
     60 * then the cob party will be assumed to be at
     61 * http://server/../comparebids-1.0.0. The provided parties that you provide are
     62 * the SHAOP parties (you can also use SAOP parties). The provided profile is
     63 * also given to the SHAOP party. Be aware that you typically need a parameter
     64 * like partial=10. The COB party gets the profile as specified, but without the
     65 * query part. The COB and SHAOP party are thus a fixed pair.
    3666 */
    3767public class AllPermutationsSettings implements TournamentSettings {
     68
    3869        private final List<PartyWithParameters> parties;
    3970        private final List<ProfileRef> profiles;
     
    4980         *                          we use PermutationsWithoutReturn to create the
    5081         *                          parties.
    51          * @param profiles
     82         * @param profiles          list of available {@link Profile}s to be
     83         *                          permutated over the parties
    5284         * @param partiesPerSession number of parties per session, must be at least
    5385         *                          2.
     
    97129         */
    98130        public ImmutableList<SessionSettings> permutations() {
    99                 ImmutableList<ImmutableList<PartyWithProfile>> partylistlist;
     131                ImmutableList<ImmutableList<TeamOfPartiesAndProfiles>> partylistlist;
    100132                ImmutableList<PartyWithParameters> partieslist = new FixedList<PartyWithParameters>(
    101133                                parties);
     
    166198         */
    167199        private SessionSettings createSetting(
    168                         ImmutableList<PartyWithProfile> partyproflist) {
     200                        ImmutableList<TeamOfPartiesAndProfiles> partyproflist) {
    169201                SessionSettings settings = sessionsettings;
    170                 for (PartyWithProfile partyprof : partyproflist) {
     202                for (TeamOfPartiesAndProfiles partyprof : partyproflist) {
    171203                        settings = settings.with(partyprof);
    172204                }
     
    181213         * @param drawPartyWithPutback if parties can be drawn multiple times
    182214         * @return list of sessionsets where each sessionset contains settings for a
    183          *         session: a list with {@link PartyWithProfile}s. The sessionsets
    184          *         are made by making all combinations of parties and profiles.
    185          *         Profiles are drawn with replace.
    186          */
    187         private ImmutableList<ImmutableList<PartyWithProfile>> getParticipants(
     215         *         session: a list with {@link TeamOfPartiesAndProfiles}s. The
     216         *         sessionsets are made by making all combinations of parties and
     217         *         profiles. Profiles are drawn with replace.
     218         */
     219        private ImmutableList<ImmutableList<TeamOfPartiesAndProfiles>> getParticipants(
    188220                        ImmutableList<PartyWithParameters> parties,
    189221                        ImmutableList<ProfileRef> profiles, int n,
     
    205237                                partiesPermutations, profilesPermutations);
    206238
    207                 return new MapList<Tuple<ImmutableList<PartyWithParameters>, ImmutableList<ProfileRef>>, ImmutableList<PartyWithProfile>>(
    208                                 tuple -> partyprofilelist(tuple), tuples);
     239                return new MapList<Tuple<ImmutableList<PartyWithParameters>, ImmutableList<ProfileRef>>, ImmutableList<TeamOfPartiesAndProfiles>>(
     240                                tuple -> teamlist(tuple), tuples);
    209241        }
    210242
     
    213245         * @param tuple a tuple with (1) ImmutableList<PartyRef> (2)
    214246         *              ImmutableList<ProfileRef>
    215          * @return list of PartyWithProfile, each picked from the two lists in
    216          *         order.
    217          */
    218         private ImmutableList<PartyWithProfile> partyprofilelist(
     247         * @return list of TeamOfPartiesAndProfiles, each picked from the two lists
     248         *         in order.
     249         */
     250        private ImmutableList<TeamOfPartiesAndProfiles> teamlist(
    219251                        Tuple<ImmutableList<PartyWithParameters>, ImmutableList<ProfileRef>> tuple) {
    220                 Function2<PartyWithParameters, ProfileRef, PartyWithProfile> //
    221                 makeparty = new Function2<PartyWithParameters, ProfileRef, PartyWithProfile>() {
     252                Function2<PartyWithParameters, ProfileRef, TeamOfPartiesAndProfiles> //
     253                makeparty = new Function2<PartyWithParameters, ProfileRef, TeamOfPartiesAndProfiles>() {
    222254                        @Override
    223                         public PartyWithProfile apply(PartyWithParameters party,
     255                        public TeamOfPartiesAndProfiles apply(PartyWithParameters party,
    224256                                        ProfileRef profile) {
    225                                 return new PartyWithProfile(party, profile);
     257                                if (sessionsettings instanceof SAOPSettings)
     258                                        return new SaopPartyWithProfile(party, profile);
     259                                else if (sessionsettings instanceof SHAOPSettings) {
     260                                        return new ShaopTeam(new PartyWithProfile(party, profile),
     261                                                        makeCob(party.getPartyRef(), profile));
     262                                } else
     263                                        throw new IllegalArgumentException(
     264                                                        "Unknown/unsupported protocol "
     265                                                                        + sessionsettings.getClass());
    226266                        }
     267
    227268                };
    228                 return new MapThreadList<PartyWithProfile, PartyWithParameters, ProfileRef>(
     269                return new MapThreadList<TeamOfPartiesAndProfiles, PartyWithParameters, ProfileRef>(
    229270                                makeparty, tuple.get1(), tuple.get2());
    230271        }
    231272
     273        /**
     274         * Extract the raw URL, without the part after the question mark
     275         *
     276         * @param party   a party reference (for another party)
     277         * @param profile a profile that may have a filter like "?partial=XX"
     278         * @return profile without the filter and with a cob party on the same
     279         *         machine. IT IS ASSUMED that there will the default
     280         *         "comparebids-1.0.0" party on the same machine as where the other
     281         *         party is
     282         */
     283        protected static PartyWithProfile makeCob(PartyRef party,
     284                        ProfileRef profile) {
     285                try {
     286                        URI profileuri = profile.getURI();
     287                        URI partyuri = party.getURI();
     288                        ProfileRef cobprof = new ProfileRef(profileuri.getScheme() + "://"
     289                                        + profileuri.getAuthority() + profileuri.getPath());
     290                        String partypath = partyuri.getPath();
     291                        partypath = partypath.substring(0, partypath.lastIndexOf('/'));
     292                        PartyWithParameters cobparty = new PartyWithParameters(new PartyRef(
     293                                        partyuri.getScheme() + "://" + partyuri.getAuthority()
     294                                                        + partypath + "/comparebids-1.0.0"),
     295                                        new Parameters());
     296                        return new PartyWithProfile(cobparty, cobprof);
     297
     298                } catch (URISyntaxException e) {
     299                        throw new IllegalArgumentException(
     300                                        "Failed making cob party with profile " + profile, e);
     301                }
     302        }
     303
    232304}
  • protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsState.java

    r1 r10  
    5555         */
    5656        public AllPermutationsState with(SessionResult result) {
    57                 if (!getNextSettings().getParticipants()
     57                if (!getNextSettings().getAllParties()
    5858                                .equals(result.getParticipants())) {
    5959                        throw new IllegalArgumentException("Inconsistent session result");
  • protocol/src/test/java/geniusweb/protocol/session/DefaultSessionStateTest.java

    r9 r10  
    2929import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    3030import geniusweb.protocol.session.saop.SAOPSettings;
     31import geniusweb.protocol.session.saop.SaopPartyWithProfile;
    3132import geniusweb.references.Parameters;
    3233import geniusweb.references.PartyRef;
     
    3940        private final ObjectMapper jackson = new ObjectMapper();
    4041        private DefaultSessionState1 state1, state1a, stateA, stateE, stateF;
     42        // The 1 is because we are testing an instance, not the abstract class
    4143        private String state1string = "{\"DefaultSessionState1\":{\"actions\":[],\"progress\":{\"time\":{\"duration\":1000,\"start\":1000}},\"settings\":{\"SAOPSettings\":{\"participants\":[{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"},{\"party\":{\"partyref\":\"party2\",\"parameters\":{}},\"profile\":\"profile2\"}],\"deadline\":{\"deadlinetime\":{\"durationms\":1000}}}},\"error\":null,\"partyprofiles\":{\"party1\":{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"}}}}";
    4244        private ProgressTime progr;
     
    5860                                new PartyRef("party2"), new Parameters());
    5961                ProfileRef profile2 = new ProfileRef("profile2");
    60                 List<PartyWithProfile> participants = Arrays.asList(
    61                                 new PartyWithProfile(party1ref, profile1),
    62                                 new PartyWithProfile(party2ref, profile2));
     62                List<SaopPartyWithProfile> participants = Arrays.asList(
     63                                new SaopPartyWithProfile(party1ref, profile1),
     64                                new SaopPartyWithProfile(party2ref, profile2));
    6365                SessionSettings settings = new SAOPSettings(participants, deadline);
    6466                ProtocolException e = new ProtocolException("test protocol error",
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPSettingsTest.java

    r8 r10  
    2323import geniusweb.references.PartyRef;
    2424import geniusweb.references.PartyWithParameters;
    25 import geniusweb.references.PartyWithProfile;
    2625import geniusweb.references.ProfileRef;
    2726import tudelft.utilities.junit.GeneralTests;
     
    3029public class SAOPSettingsTest extends GeneralTests<SAOPSettings> {
    3130
    32         private PartyWithProfile partyprof1 = mock(PartyWithProfile.class);
    33         private PartyWithProfile partyprof2 = mock(PartyWithProfile.class);
    34         private PartyWithProfile partyprof3 = mock(PartyWithProfile.class);
    35         private List<PartyWithProfile> participants2 = Arrays.asList(partyprof1,
     31        private SaopPartyWithProfile partyprof1 = mock(SaopPartyWithProfile.class);
     32        private SaopPartyWithProfile partyprof2 = mock(SaopPartyWithProfile.class);
     33        private SaopPartyWithProfile partyprof3 = mock(SaopPartyWithProfile.class);
     34        private List<SaopPartyWithProfile> participants2 = Arrays.asList(partyprof1,
    3635                        partyprof2);
    37         private List<PartyWithProfile> participants3 = Arrays.asList(partyprof1,
     36        private List<SaopPartyWithProfile> participants3 = Arrays.asList(partyprof1,
    3837                        partyprof2, partyprof3);
    3938
     
    6766                                new PartyRef("http://party2"), new Parameters());
    6867                ProfileRef profile2 = new ProfileRef("http://profile2");
    69                 PartyWithProfile partywithprof1 = new PartyWithProfile(party1,
     68                SaopPartyWithProfile partywithprof1 = new SaopPartyWithProfile(party1,
    7069                                profile1);
    71                 PartyWithProfile partywithprof2 = new PartyWithProfile(party2,
     70                SaopPartyWithProfile partywithprof2 = new SaopPartyWithProfile(party2,
    7271                                profile2);
    73                 List<PartyWithProfile> participants = Arrays.asList(partywithprof1,
     72                List<SaopPartyWithProfile> participants = Arrays.asList(partywithprof1,
    7473                                partywithprof2);
    7574
     
    141140                SAOPSettings saop = new SAOPSettings(participants2, deadline);
    142141                SessionSettings saop2 = saop.with(partyprof3);
    143                 assertEquals(3, saop2.getParticipants().size());
     142                assertEquals(3, saop2.getTeams().size());
    144143        }
    145144
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPStateTest.java

    r9 r10  
    2727import geniusweb.progress.ProgressTime;
    2828import geniusweb.protocol.ProtocolException;
     29import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    2930import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    30 import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    3131import geniusweb.protocol.session.SessionSettings;
    3232import tudelft.utilities.junit.GeneralTests;
     
    220220        }
    221221
    222         @Test
     222        @Test(expected = IllegalArgumentException.class)
    223223        public void withWrongActionTest() {
    224224                // wrong because action has actor null which does not match party1
    225225                SAOPState state = state1.with(party1, action);
    226                 assertEquals(1, state.getActions().size());
    227                 assertEquals(action, state.getActions().get(0));
    228                 assertTrue(state.isFinal(NOW));
    229                 assertEquals(
    230                                 "geniusweb.protocol.ProtocolException: party1:act contains wrong credentials: act1",
    231                                 state.getError().toString());
    232         }
    233 
    234         @Test
     226//              assertEquals(1, state.getActions().size());
     227//              assertEquals(action, state.getActions().get(0));
     228//              assertTrue(state.isFinal(NOW));
     229        }
     230
     231        @Test(expected = IllegalArgumentException.class)
    235232        public void withActionTest() {
    236233                when(action.getActor()).thenReturn(party1);
    237                 SAOPState state = state1.with(party1, action);
    238                 assertEquals(1, state.getActions().size());
    239                 assertEquals(action, state.getActions().get(0));
     234                state1.with(party1, action);
    240235        }
    241236
     
    265260        }
    266261
    267         @Test
     262        @Test(expected = IllegalArgumentException.class)
    268263        public void RefuseImmediateAccept() {
    269264                Accept nullaccept = new Accept(party1, null);
    270265                SAOPState state = state1.with(party1, nullaccept);
    271                 assertTrue(state.isFinal(NOW));
    272                 assertEquals(
    273                                 "geniusweb.protocol.ProtocolException: party1:Accept without a recent offer",
    274                                 state.getError().toString());
    275         }
    276 
    277         @Test
     266        }
     267
     268        @Test(expected = IllegalArgumentException.class)
    278269        public void RefuseNotMyTurn() {
    279270                List<Action> actions = Arrays.asList(offer1);
     
    281272                                settings, null, null);
    282273
    283                 state = state.with(party1, offer1);
    284                 assertTrue(state.isFinal(NOW));
    285                 assertEquals(
    286                                 "geniusweb.protocol.ProtocolException: party1:Party does not have the turn ",
    287                                 state.getError().toString());
    288         }
    289 
    290         @Test
     274                state.with(party1, offer1);
     275//              assertTrue(state.isFinal(NOW));
     276//              assertEquals(
     277//                              "geniusweb.protocol.ProtocolException: party1:Party does not have the turn ",
     278//                              state.getError().toString());
     279        }
     280
     281        @Test(expected = IllegalArgumentException.class)
    291282        public void RefuseNullAccept() {
    292283                List<Action> actions = Arrays.asList(offer1);
     
    297288                state = state.with(party2, nullaccept);
    298289                assertTrue(state.isFinal(NOW));
    299                 assertTrue(state.getError().toString().matches(
    300                                 ".*party2.*Party accepts a bid differing from the last offer.*"));
    301         }
    302 
    303         @Test
     290        }
     291
     292        @Test(expected = IllegalArgumentException.class)
    304293        public void RefuseNullAction() {
    305294                List<Action> actions = Arrays.asList(offer1);
     
    308297
    309298                state = state.with(party2, null);
    310                 assertEquals(
    311                                 "geniusweb.protocol.ProtocolException: party2:action is null",
    312                                 state.getError().toString());
    313299        }
    314300
  • protocol/src/test/java/geniusweb/protocol/session/saop/SAOPTest.java

    r9 r10  
    2020import java.util.List;
    2121import java.util.Map;
     22import java.util.stream.Collectors;
    2223
    2324import org.junit.Test;
     
    3940import geniusweb.progress.Progress;
    4041import geniusweb.protocol.ProtocolException;
    41 import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
    4242import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
    4343import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
     44import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
     45import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
    4446import geniusweb.references.Parameters;
    4547import geniusweb.references.PartyRef;
     
    7375        private final PartyRef party2ref = mock(PartyRef.class);
    7476        private final SAOPSettings settings = mock(SAOPSettings.class);
    75         private final PartyWithProfile party1 = mock(PartyWithProfile.class);
    76         private final PartyWithProfile party2 = mock(PartyWithProfile.class);
     77        private final SaopPartyWithProfile team1 = mock(SaopPartyWithProfile.class);
     78        private final SaopPartyWithProfile team2 = mock(SaopPartyWithProfile.class);
    7779        private SAOP saop;
    7880        private ProtocolToPartyConnFactory factory;
     
    8082        private ProtocolToPartyConn conn1 = mock(ProtocolToPartyConn.class),
    8183                        conn2 = mock(ProtocolToPartyConn.class);
    82         private Map<PartyId, PartyWithProfile> partyprofiles;
     84        private Map<PartyId, SaopPartyWithProfile> partyprofiles;
    8385        private Progress progress = mock(Progress.class);
    8486        private ProfileRef profile1;
     
    101103                        throws URISyntaxException, IOException, NoResourcesNowException {
    102104                SAOP = new ProtocolRef("SAOP");
    103                 when(party1.getParty()).thenReturn(partywithparam1);
    104                 when(party2.getParty()).thenReturn(partywithparam2);
     105                when(team1.getParty()).thenReturn(partywithparam1);
     106                when(team2.getParty()).thenReturn(partywithparam2);
     107                when(team1.getAllParties()).thenReturn(Arrays.asList(team1));
     108                when(team2.getAllParties()).thenReturn(Arrays.asList(team2));
    105109
    106110                partyprofiles = new HashMap<>();
    107                 partyprofiles.put(PARTY1ID, party1);
    108                 partyprofiles.put(PARTY2ID, party2);
     111                partyprofiles.put(PARTY1ID, team1);
     112                partyprofiles.put(PARTY2ID, team2);
    109113
    110114                when(deadlinetime.getDuration()).thenReturn(1000l);
    111115
    112                 List<PartyWithProfile> participants = new ArrayList<>();
    113                 participants.add(party1);
    114                 participants.add(party2);
    115                 when(settings.getParticipants()).thenReturn(participants);
     116                List<TeamOfPartiesAndProfiles> teams = new ArrayList<>();
     117                teams.add(team1);
     118                teams.add(team2);
     119                when(settings.getTeams()).thenReturn(teams);
     120                when(settings.getAllParties()).thenReturn(Arrays.asList(team1, team2));
    116121                when(settings.getDeadline()).thenReturn(deadlinetime);
    117122
     
    126131
    127132                profile1 = mock(ProfileRef.class);
    128                 when(party1.getProfile()).thenReturn(profile1);
     133                when(team1.getProfile()).thenReturn(profile1);
    129134                profile2 = mock(ProfileRef.class);
    130                 when(party2.getProfile()).thenReturn(profile2);
     135                when(team2.getProfile()).thenReturn(profile2);
    131136
    132137                mockState(connectedstate, "connected state");
     
    157162                when(state.getSettings()).thenReturn(settings);
    158163                when(state.getConnections()).thenReturn(connectionswithparties);
    159                 when(state.getPartyProfiles()).thenReturn(partyprofiles);
     164                when(state.getPartyProfiles())
     165                                .thenReturn(partyprofiles.entrySet().stream().collect(
     166                                                Collectors.toMap(e -> e.getKey(), e -> e.getValue())));
    160167                when(state.getProgress()).thenReturn(progress);
    161168                when(state.with(any(ProtocolToPartyConn.class),
  • references/src/main/java/geniusweb/references/Parameters.java

    r8 r10  
    1111public class Parameters extends HashMap<String, Object> {
    1212
     13        /**
     14         * Getter with type-check
     15         *
     16         * @param <T>       the expected type
     17         * @param paramname the parameter name that must be in the map
     18         * @param classType the expected value type for this parameter
     19         * @return object of requested type.
     20         * @throws IllegalArgumentException if the object is not available.
     21         */
     22        @SuppressWarnings("unchecked")
     23        public <T> T get(String paramname, Class<T> classType) {
     24                if (!containsKey(paramname)
     25                                || !(get(paramname).getClass().isInstance(classType)))
     26                        throw new IllegalArgumentException(" Missing contain a parameter "
     27                                        + paramname + " with a " + classType.getName() + " value");
     28                return (T) get(paramname);
     29        }
    1330}
  • references/src/main/java/geniusweb/references/PartyWithProfile.java

    r8 r10  
    2222        }
    2323
     24        /**
     25         *
     26         * @return the {@link PartyWithParameters}. never null.
     27         */
    2428        public PartyWithParameters getParty() {
    2529                return party;
     
    2731        }
    2832
     33        /**
     34         * @return the profile setting for this party. Never null.
     35         */
    2936        public ProfileRef getProfile() {
    3037                return profile;
  • simplerunner/pom.xml

    r9 r10  
    4242                        <artifactId>randomparty</artifactId>
    4343                        <version>1.1.0</version>
     44                        <scope>test</scope>
     45                </dependency>
     46                <dependency>
     47                        <groupId>geniusweb.exampleparties</groupId>
     48                        <artifactId>comparebids</artifactId>
     49                        <version>1.0.0</version>
     50                        <scope>test</scope>
     51                </dependency>
     52                <dependency>
     53                        <groupId>geniusweb.exampleparties</groupId>
     54                        <artifactId>simpleshaop</artifactId>
     55                        <version>1.0.0</version>
    4456                        <scope>test</scope>
    4557                </dependency>
  • simplerunner/src/main/java/geniusweb/simplerunner/NegoRunner.java

    r9 r10  
    1414import geniusweb.protocol.NegoSettings;
    1515import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory;
    16 import geniusweb.protocol.session.SessionSettings;
    1716import tudelft.utilities.logging.ReportToLogger;
    1817import tudelft.utilities.logging.Reporter;
     
    7271                String serialized = new String(Files.readAllBytes(Paths.get(args[0])),
    7372                                StandardCharsets.UTF_8);
    74                 SessionSettings settings = jackson.readValue(serialized,
    75                                 SessionSettings.class);
     73                NegoSettings settings = jackson.readValue(serialized,
     74                                NegoSettings.class);
    7675
    7776                NegoRunner runner = new NegoRunner(settings,
  • simplerunner/src/test/java/geniusweb/simplerunner/SessionRunnerE2ETest.java

    r2 r10  
    1616import com.fasterxml.jackson.databind.ObjectMapper;
    1717
    18 import geniusweb.protocol.session.SessionSettings;
     18import geniusweb.protocol.NegoSettings;
    1919import tudelft.utilities.logging.ReportToLogger;
    2020import tudelft.utilities.logging.Reporter;
     
    3434        @Parameters
    3535        public static Collection<Object[]> data() {
    36                 return Arrays.asList(
    37                                 new Object[][] { { "src/test/resources/settings.json" }, { "src/test/resources/settings2.json" } });
     36                return Arrays
     37                                .asList(new Object[][] { { "src/test/resources/settings.json" },
     38                                                { "src/test/resources/settings2.json" },
     39                                                { "src/test/resources/shaoptoursettings.json" } });
    3840        }
    3941
     
    4446        @Before
    4547        public void before() throws IOException {
    46                 String serialized = new String(Files.readAllBytes(Paths.get(filename)), StandardCharsets.UTF_8);
    47                 SessionSettings settings = jackson.readValue(serialized, SessionSettings.class);
     48                System.out.println("Running from file " + filename);
     49                String serialized = new String(Files.readAllBytes(Paths.get(filename)),
     50                                StandardCharsets.UTF_8);
     51                NegoSettings settings = jackson.readValue(serialized,
     52                                NegoSettings.class);
    4853
    49                 runner = new NegoRunner(settings, new ClassPathConnectionFactory(), logger);
     54                runner = new NegoRunner(settings, new ClassPathConnectionFactory(),
     55                                logger);
    5056
    5157        }
Note: See TracChangeset for help on using the changeset viewer.