source: src/main/java/genius/gui/uncertainty/PairwiseComparisonModel.java@ 346

Last change on this file since 346 was 78, checked in by Wouter Pasman, 6 years ago

#30 use UncertainAdditiveUtilitySpace.

File size: 3.5 KB
Line 
1package genius.gui.uncertainty;
2
3import java.util.stream.IntStream;
4
5import javax.swing.JOptionPane;
6
7import genius.core.boaframework.SortedOutcomeSpace;
8import genius.core.listener.Listener;
9import genius.core.repository.ProfileRepItem;
10import genius.core.uncertainty.UNCERTAINTYTYPE;
11import genius.core.uncertainty.UncertainPreferenceContainer;
12import genius.core.utility.AbstractUtilitySpace;
13import genius.core.utility.UncertainAdditiveUtilitySpace;
14import genius.gui.panels.BooleanModel;
15import genius.gui.panels.TextModel;
16
17public class PairwiseComparisonModel {
18
19 private ProfileRepItem profile;
20
21 private TextModel errorModel = new TextModel("0.0");
22
23 private int numberOfComparisons;
24 private final int maxNumberOfComparisons;
25
26 private BooleanModel experimentalModel = new BooleanModel(true);
27 private BooleanModel confirmationModel = new BooleanModel(false);
28
29 private UncertainPreferenceContainer uncertainPrefContainer = null;
30
31 public PairwiseComparisonModel(ProfileRepItem profile) {
32 this.profile = profile;
33 this.maxNumberOfComparisons = calculateMaxNumberOfComparisons();
34 connect();
35 }
36
37 private int calculateMaxNumberOfComparisons() {
38 SortedOutcomeSpace realSortedOutcomeSpace = new SortedOutcomeSpace(
39 (AbstractUtilitySpace) profile.create());
40 return realSortedOutcomeSpace.getAllOutcomes().size() - 1;
41 }
42
43 /**
44 * All possible values the "number of comparisons" slider can take.
45 */
46 public Integer[] getPossibleValues() {
47 if (maxNumberOfComparisons <= 10)
48 return (Integer[]) IntStream.rangeClosed(1, maxNumberOfComparisons)
49 .boxed().toArray();
50 else if (maxNumberOfComparisons <= 100)
51 return new Integer[] { 1, 5, 10, maxNumberOfComparisons };
52 else
53 return new Integer[] { 1, 5, 10, 50, 100, maxNumberOfComparisons };
54 }
55
56 public void connect() {
57
58 confirmationModel.addListener(new Listener<Boolean>() {
59 @Override
60 public void notifyChange(Boolean data) {
61 if (confirmationModel.getValue() == true) {
62 uncertainPrefContainer = createContainer();
63 int amountOfComps = uncertainPrefContainer
64 .getPairwiseCompUserModel().getBidRanking()
65 .getBidOrder().size() - 1;
66 double certaintyLevel = ((double) amountOfComps
67 / (double) getMaxNumberInComps());
68 double errorRate = Double
69 .parseDouble(getErrorModel().getText()) * 100;
70
71 JOptionPane.showMessageDialog(null,
72 "Pairwise Comparison User Model Created Successfully! \n\n"
73 + "Number of Comparisons: " + amountOfComps
74 + "\n" + "Level Of certainty: "
75 + (Math.round((certaintyLevel) * 100)
76 / 100D) * 100
77 + "%\n" + "Error Rate: "
78 + (Math.round((errorRate) * 100) / 100D)
79 + "%");
80 }
81 }
82 });
83 }
84
85 public ProfileRepItem getProfile() {
86 return profile;
87 }
88
89 public UncertainPreferenceContainer createContainer() {
90 UncertainPreferenceContainer container;
91 container = new UncertainPreferenceContainer(
92 (UncertainAdditiveUtilitySpace) profile.create(),
93 UNCERTAINTYTYPE.PAIRWISECOMP);
94 return container;
95 }
96
97 public TextModel getErrorModel() {
98 return errorModel;
99 }
100
101 public int getMaxNumberInComps() {
102 return maxNumberOfComparisons;
103 }
104
105 public BooleanModel getConfirmationModel() {
106 return confirmationModel;
107 }
108
109 public UncertainPreferenceContainer getUncertainPrefContainer() {
110 return uncertainPrefContainer;
111 }
112
113 public BooleanModel getExperimentalModel() {
114 return experimentalModel;
115 }
116
117 public int getNumberOfComparisons() {
118 return numberOfComparisons;
119 }
120
121 public void setNumberOfComparisons(int numberOfCOmparisons) {
122 this.numberOfComparisons = numberOfCOmparisons;
123 }
124
125}
Note: See TracBrowser for help on using the repository browser.