1 | package de.ugoe.cs.autoquest.tasktrees.alignment.substitution; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.Collection; |
---|
5 | import java.util.HashMap; |
---|
6 | import java.util.Iterator; |
---|
7 | |
---|
8 | import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; |
---|
9 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
10 | |
---|
11 | import java.util.List; |
---|
12 | |
---|
13 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
14 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentHelpers; |
---|
15 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
16 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
17 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
18 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
19 | import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; |
---|
20 | import de.ugoe.cs.util.console.GlobalDataContainer; |
---|
21 | |
---|
22 | public class ObjectDistanceSubstitionMatrix implements SubstitutionMatrix { |
---|
23 | |
---|
24 | // private ArrayList<int[][]> matrix; |
---|
25 | HashMap<Integer, Integer> idmapping; |
---|
26 | private TriangleMatrix matrix; |
---|
27 | private SymbolMap<ITaskInstance, ITask> uniqueTasks; |
---|
28 | private float gapPenalty; |
---|
29 | private float positiveThreshold; |
---|
30 | |
---|
31 | public ObjectDistanceSubstitionMatrix( |
---|
32 | SymbolMap<ITaskInstance, ITask> uniqueTasks) { |
---|
33 | this.uniqueTasks = uniqueTasks; |
---|
34 | idmapping = new HashMap<Integer, Integer>(); |
---|
35 | matrix = new TriangleMatrix(uniqueTasks.size()+1); |
---|
36 | gapPenalty = -10; |
---|
37 | //Todo: Calculate this value (the mean distance between every element) before |
---|
38 | positiveThreshold =7; |
---|
39 | } |
---|
40 | |
---|
41 | @Override |
---|
42 | public float getGapPenalty() { |
---|
43 | return gapPenalty; |
---|
44 | } |
---|
45 | |
---|
46 | @Override |
---|
47 | public void generate() { |
---|
48 | int index = 0; |
---|
49 | float meandistance = 0; |
---|
50 | for (Iterator<ITaskInstance> it = uniqueTasks.getSymbols().iterator(); it |
---|
51 | .hasNext();) { |
---|
52 | Object obj1 = it.next(); |
---|
53 | IEventTaskInstance eti1 = null; |
---|
54 | if (obj1 instanceof IEventTaskInstance) { |
---|
55 | eti1 = (IEventTaskInstance) obj1; |
---|
56 | } |
---|
57 | |
---|
58 | for (Iterator<ITaskInstance> jt = uniqueTasks.getSymbols() |
---|
59 | .iterator(); jt.hasNext();) { |
---|
60 | IEventTaskInstance eti2 = null; |
---|
61 | Object obj2 = jt.next(); |
---|
62 | if (obj2 instanceof IEventTaskInstance) { |
---|
63 | eti2 = (IEventTaskInstance) obj2; |
---|
64 | } |
---|
65 | IGUIElement first = (IGUIElement) eti1.getEvent().getTarget(); |
---|
66 | IGUIElement second = (IGUIElement) eti2.getEvent().getTarget(); |
---|
67 | int tempindex1 = -1; |
---|
68 | int tempindex2 = -1; |
---|
69 | if(!idmapping.containsKey(eti1.getTask().getId())) |
---|
70 | { |
---|
71 | idmapping.put(eti1.getTask().getId(), index); |
---|
72 | tempindex1 = index; |
---|
73 | index++; |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | tempindex1 = idmapping.get(eti1.getTask().getId()); |
---|
78 | } |
---|
79 | if(!idmapping.containsKey(eti2.getTask().getId())) |
---|
80 | { |
---|
81 | idmapping.put(eti2.getTask().getId(), index); |
---|
82 | tempindex2 = index; |
---|
83 | index++; |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | tempindex2 = idmapping.get(eti2.getTask().getId()); |
---|
88 | } |
---|
89 | float distance = AlignmentHelpers.distanceBetween(first, second); |
---|
90 | meandistance += distance; |
---|
91 | |
---|
92 | if (distance > positiveThreshold) { |
---|
93 | distance = -1*distance; |
---|
94 | } |
---|
95 | matrix.set(tempindex1, tempindex2,distance); |
---|
96 | |
---|
97 | } |
---|
98 | } |
---|
99 | System.out.println(meandistance/(uniqueTasks.size()*uniqueTasks.size())); |
---|
100 | //System.out.println(idmapping.toString()); |
---|
101 | //System.out.println(matrix.toString()); |
---|
102 | //System.out.println(idmapping.keySet().toString()); |
---|
103 | //System.out.println(idmapping.values().toString()); |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | @Override |
---|
108 | public float getDistance(int taskId1, int taskId2) { |
---|
109 | //System.out.println("Taskid1: " + taskId1 + " Taskid2: " + taskId2 + " Idmapping1: " + idmapping.get(taskId1) + " Idmapping2: " + idmapping.get(taskId2)); |
---|
110 | |
---|
111 | return matrix.get(idmapping.get(taskId1),idmapping.get(taskId2)); |
---|
112 | } |
---|
113 | |
---|
114 | } |
---|
115 | |
---|