1 | package genius.gui.uncertainty;
|
---|
2 |
|
---|
3 |
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import javax.swing.JLabel;
|
---|
8 | import javax.swing.JOptionPane;
|
---|
9 | import javax.swing.JPanel;
|
---|
10 | import javax.swing.JTextField;
|
---|
11 |
|
---|
12 | import genius.core.repository.ProfileRepItem;
|
---|
13 | import genius.core.uncertainty.UNCERTAINTYTYPE;
|
---|
14 | import genius.core.uncertainty.UncertainPreferenceContainer;
|
---|
15 | import genius.core.uncertainty.flattening.FlattenedUtilitySpace;
|
---|
16 | import genius.core.utility.AbstractUtilitySpace;
|
---|
17 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
18 | import genius.gui.negosession.ContentProxy;
|
---|
19 | import genius.gui.panels.SingleSelectionModel;
|
---|
20 | import genius.gui.panels.SubsetSelectionModel;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * @author Dimitrios Tsimpoukis
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 | public class FlatteningModel {
|
---|
28 |
|
---|
29 | private final ProfileRepItem realProfileRepItem;
|
---|
30 | private final SubsetSelectionModel<ProfileRepItem> multiPrefSelectionModel;
|
---|
31 | private final SingleSelectionModel<String> strategyNamesModel;
|
---|
32 |
|
---|
33 | public FlatteningModel(ProfileRepItem realProfileRepItem) {
|
---|
34 |
|
---|
35 | this.realProfileRepItem = realProfileRepItem;
|
---|
36 | this.multiPrefSelectionModel = new SubsetSelectionModel<ProfileRepItem>(ContentProxy.fetchDomainSpecificProfiles(realProfileRepItem.getDomain())); // TODO need to rule out real
|
---|
37 | this.strategyNamesModel = new SingleSelectionModel<>(getFlatteningStrategyNames());
|
---|
38 | }
|
---|
39 |
|
---|
40 | private static ArrayList<String> getFlatteningStrategyNames() {
|
---|
41 | ArrayList<String> flatteningStrategiesNames = new ArrayList<String>();
|
---|
42 | flatteningStrategiesNames.add("Average Flattening");
|
---|
43 | flatteningStrategiesNames.add("Weighted Average Flattening");
|
---|
44 | flatteningStrategiesNames.add("Random Flattening");
|
---|
45 | flatteningStrategiesNames.add("Weighted Choice Flattening");
|
---|
46 | return flatteningStrategiesNames;
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * @return An UncertainPreferenceContainer object from the GUI selections
|
---|
52 | */
|
---|
53 |
|
---|
54 | public UncertainPreferenceContainer createContainer() {
|
---|
55 | FlattenedUtilitySpace flattenedSpace = createFlattenedSpace(multiPrefSelectionModel.getSelectedItems());
|
---|
56 | return new UncertainPreferenceContainer((AdditiveUtilitySpace)realProfileRepItem.create(), UNCERTAINTYTYPE.PERCEIVEDUTILITY, flattenedSpace);
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * IMPORTANT method takes as input a list of profile repository items and returns a flattened utility space.
|
---|
63 | * @param itemsList
|
---|
64 | * @return FlattenedUtilitySpace
|
---|
65 | */
|
---|
66 |
|
---|
67 | public FlattenedUtilitySpace createFlattenedSpace(List<ProfileRepItem> itemsList) {
|
---|
68 |
|
---|
69 | ArrayList<AbstractUtilitySpace> uspacesList = new ArrayList<AbstractUtilitySpace>();
|
---|
70 | for (ProfileRepItem repItem : itemsList) {
|
---|
71 | uspacesList.add((AbstractUtilitySpace)repItem.create());
|
---|
72 | }
|
---|
73 | double [] weights = getWeightsFromGUI(uspacesList.size());
|
---|
74 | FlattenedUtilitySpace flattenedSpace = new FlattenedUtilitySpace(uspacesList , uspacesList.get(0).getDomain() , weights , strategyNamesModel.getSelection());
|
---|
75 | System.out.println(flattenedSpace.getName());
|
---|
76 | return flattenedSpace;
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Receives the weights from the GUI for the creation of the flattened utility space
|
---|
82 | * @param amount: the amount of preference profiles used for flattening
|
---|
83 | * @return array of weights corresponding to the preference profiles
|
---|
84 | */
|
---|
85 | public double [] getWeightsFromGUI(int amount) {
|
---|
86 |
|
---|
87 | JTextField [] weightsTextField = new JTextField [amount] ;
|
---|
88 | double [] weights = new double [amount];
|
---|
89 |
|
---|
90 | JPanel myPanel = new JPanel();
|
---|
91 |
|
---|
92 | for (int i = 0; i < amount; i++) {
|
---|
93 | if (i == 0) weightsTextField[i] = new JTextField("1",3);
|
---|
94 | else weightsTextField[i] = new JTextField("1",3);
|
---|
95 | myPanel.add(new JLabel("Profile " +(i+1) +" weight:"));
|
---|
96 | myPanel.add(weightsTextField[i]);
|
---|
97 | }
|
---|
98 |
|
---|
99 | int result = JOptionPane.showConfirmDialog(null, myPanel,
|
---|
100 | "Please Enter Preference Profiles Weights", JOptionPane.OK_CANCEL_OPTION);
|
---|
101 | if (result == JOptionPane.OK_OPTION) {
|
---|
102 | for (int i = 0; i < amount; i++) {
|
---|
103 | weights[i] = Double.parseDouble(weightsTextField[i].getText());
|
---|
104 | }
|
---|
105 | return weights;
|
---|
106 | } else {System.out.println("error parsing weights");
|
---|
107 | return getWeightsFromGUI(amount);
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | public ProfileRepItem getRealProfileRepItem() {
|
---|
112 | return realProfileRepItem;
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | public SingleSelectionModel<String> getStrategyNamesModel() {
|
---|
117 | return strategyNamesModel;
|
---|
118 | }
|
---|
119 |
|
---|
120 | public SubsetSelectionModel<ProfileRepItem> getMultiPrefSelectionModel() {
|
---|
121 | return multiPrefSelectionModel;
|
---|
122 | }
|
---|
123 |
|
---|
124 | }
|
---|