source: src/main/java/genius/core/utility/InclusiveHyperRectangle.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 1.8 KB
Line 
1package genius.core.utility;
2
3import java.util.ArrayList;
4
5import genius.core.Bid;
6import genius.core.issue.ValueInteger;
7
8/**
9 * An {@link InclusiveHyperRectangle} has a utility value when all of its bounds
10 * are satisfied, and zero otherwise.
11 */
12public class InclusiveHyperRectangle extends HyperRectangle {
13 private ArrayList<Bound> boundlist;
14 private double utilityValue;
15 private boolean isAllBidsAcceptable;
16
17 public InclusiveHyperRectangle() {
18 this.isAllBidsAcceptable = false;
19 }
20
21 public InclusiveHyperRectangle(boolean isAllOkay) {
22 this.isAllBidsAcceptable = isAllOkay;
23 }
24
25 public ArrayList<Bound> getBoundList() {
26 return boundlist;
27 }
28
29 protected void setBoundList(ArrayList<Bound> boundlist) {
30 this.boundlist = boundlist;
31 }
32
33 public double getUtilityValue() {
34 return utilityValue;
35 }
36
37 protected void setUtilityValue(double utilityValue) {
38 this.utilityValue = utilityValue;
39 }
40
41 @Override
42 public double getUtility(Bid bid) {
43
44 if (this.isAllBidsAcceptable) // if there is no constraint at all
45 return (utilityValue * weight);
46
47 int issueValue;
48 for (int i = 0; i < boundlist.size(); i++) {
49 issueValue = (int) ((ValueInteger) bid.getValue(boundlist.get(i)
50 .getIssueIndex())).getValue();
51 if ((boundlist.get(i).getMin() > issueValue)
52 || (issueValue > boundlist.get(i).getMax()))
53 return 0.0;
54 }
55
56 return utilityValue * weight;
57 }
58
59 public boolean doesCover(Bid bid) throws Exception {
60 if (this.isAllBidsAcceptable) // no constraint at all
61 return true;
62
63 int issueValue;
64 for (int i = 0; i < boundlist.size(); i++) {
65 issueValue = (int) ((ValueInteger) bid.getValue(boundlist.get(i)
66 .getIssueIndex())).getValue();
67 if ((boundlist.get(i).getMin() > issueValue)
68 || (issueValue > boundlist.get(i).getMax()))
69 return false;
70 }
71 return true;
72 }
73}
Note: See TracBrowser for help on using the repository browser.