Changeset 10 for bidspace/src/main/java


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

Update 28 jan 2020

Location:
bidspace/src/main/java/geniusweb/bidspace
Files:
6 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) {
Note: See TracChangeset for help on using the changeset viewer.