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