[1572] | 1 | package de.ugoe.cs.autoquest.tasktrees.alignment.matrix; |
---|
[1324] | 2 | |
---|
[1570] | 3 | |
---|
[1554] | 4 | import java.util.HashMap; |
---|
[1331] | 5 | import java.util.Iterator; |
---|
| 6 | |
---|
| 7 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
[1553] | 8 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentHelpers; |
---|
[1578] | 9 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Constants; |
---|
[1553] | 10 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
[1554] | 11 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 12 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 13 | import de.ugoe.cs.autoquest.usageprofiles.SymbolMap; |
---|
[1324] | 14 | |
---|
[1570] | 15 | |
---|
[1324] | 16 | public class ObjectDistanceSubstitionMatrix implements SubstitutionMatrix { |
---|
| 17 | |
---|
[1554] | 18 | // private ArrayList<int[][]> matrix; |
---|
| 19 | HashMap<Integer, Integer> idmapping; |
---|
| 20 | private TriangleMatrix matrix; |
---|
| 21 | private SymbolMap<ITaskInstance, ITask> uniqueTasks; |
---|
[1568] | 22 | private double gapPenalty; |
---|
[1676] | 23 | private int index = 0; |
---|
[1615] | 24 | |
---|
[1568] | 25 | private double positiveThreshold; |
---|
[1555] | 26 | |
---|
[1554] | 27 | public ObjectDistanceSubstitionMatrix( |
---|
[1620] | 28 | SymbolMap<ITaskInstance, ITask> uniqueTasks,float positiveThreshold, int gapPenalty) { |
---|
[1554] | 29 | this.uniqueTasks = uniqueTasks; |
---|
[1558] | 30 | this.positiveThreshold = positiveThreshold; |
---|
[1554] | 31 | idmapping = new HashMap<Integer, Integer>(); |
---|
| 32 | matrix = new TriangleMatrix(uniqueTasks.size()+1); |
---|
[1620] | 33 | this.gapPenalty = gapPenalty; |
---|
[1558] | 34 | |
---|
[1324] | 35 | } |
---|
| 36 | |
---|
[1615] | 37 | |
---|
[1568] | 38 | public double getGapPenalty() { |
---|
[1555] | 39 | return gapPenalty; |
---|
[1324] | 40 | } |
---|
[1615] | 41 | |
---|
| 42 | public void setGapPenalty(double gapPenalty) { |
---|
| 43 | this.gapPenalty = gapPenalty; |
---|
| 44 | } |
---|
[1324] | 45 | |
---|
[1554] | 46 | public void generate() { |
---|
[1578] | 47 | |
---|
[1677] | 48 | int index1=-1; |
---|
| 49 | int index2=-1; |
---|
| 50 | float distance=0; |
---|
[1554] | 51 | for (Iterator<ITaskInstance> it = uniqueTasks.getSymbols().iterator(); it |
---|
| 52 | .hasNext();) { |
---|
| 53 | Object obj1 = it.next(); |
---|
| 54 | for (Iterator<ITaskInstance> jt = uniqueTasks.getSymbols() |
---|
| 55 | .iterator(); jt.hasNext();) { |
---|
[1677] | 56 | |
---|
| 57 | IEventTaskInstance eti1 = null; |
---|
| 58 | ITask task1 = null; |
---|
| 59 | |
---|
[1554] | 60 | IEventTaskInstance eti2 = null; |
---|
[1677] | 61 | ITask task2 = null; |
---|
| 62 | |
---|
[1554] | 63 | Object obj2 = jt.next(); |
---|
[1677] | 64 | |
---|
| 65 | if (obj1 instanceof IEventTaskInstance && obj2 instanceof IEventTaskInstance) { |
---|
| 66 | eti1 = (IEventTaskInstance) obj1; |
---|
| 67 | index1 = getIndex(eti1); |
---|
[1554] | 68 | eti2 = (IEventTaskInstance) obj2; |
---|
[1677] | 69 | index2 = getIndex(eti2); |
---|
| 70 | distance = distanceBetweenInstances(eti1,eti2); |
---|
[1331] | 71 | } |
---|
[1677] | 72 | else if(obj1 instanceof IEventTaskInstance && !(obj2 instanceof IEventTaskInstance)) { |
---|
| 73 | task2 = ((ITaskInstance) obj2).getTask(); |
---|
| 74 | index2 = getIndex(task2); |
---|
| 75 | eti1 = (IEventTaskInstance) obj1; |
---|
| 76 | index1 = getIndex(eti1); |
---|
| 77 | distance = distanceBetweenTaskAndInstance(task2,eti1); |
---|
[1675] | 78 | } |
---|
[1677] | 79 | else if(!(obj1 instanceof IEventTaskInstance) && obj2 instanceof IEventTaskInstance) { |
---|
| 80 | task1 = ((ITaskInstance) obj1).getTask(); |
---|
| 81 | index1 = getIndex(task1); |
---|
| 82 | eti2 = (IEventTaskInstance) obj2; |
---|
| 83 | index2 = getIndex(eti2); |
---|
| 84 | distance = distanceBetweenTaskAndInstance(task1,eti2); |
---|
| 85 | } |
---|
| 86 | else if(!(obj2 instanceof IEventTaskInstance) && !(obj2 instanceof IEventTaskInstance)) { |
---|
| 87 | task1 = ((ITaskInstance) obj1).getTask(); |
---|
| 88 | index1 = getIndex(task1); |
---|
| 89 | task2 = ((ITaskInstance) obj2).getTask(); |
---|
| 90 | index2 = getIndex(task2); |
---|
| 91 | distance = distanceBetweenTasks(task1,task2); |
---|
| 92 | } |
---|
| 93 | else { |
---|
| 94 | System.out.println("Unknown error"); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | matrix.set(index1, index2,distance); |
---|
[1578] | 98 | |
---|
[1554] | 99 | } |
---|
[1331] | 100 | } |
---|
[1324] | 101 | } |
---|
[1677] | 102 | |
---|
[1558] | 103 | |
---|
[1677] | 104 | private float distanceBetweenTaskAndInstance(ITask task1, IEventTaskInstance eti) { |
---|
| 105 | return 0; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | private float distanceBetweenTasks(ITask task1, ITask task2) { |
---|
| 109 | return 0; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | private int getIndex(ITask task) { |
---|
| 114 | int tempindex =-1; |
---|
| 115 | if(!idmapping.containsKey(task.getId())) { |
---|
| 116 | idmapping.put(task.getId(), index); |
---|
| 117 | tempindex = index; |
---|
| 118 | index++; |
---|
| 119 | } |
---|
| 120 | else { |
---|
| 121 | tempindex = idmapping.get(task.getId()); |
---|
| 122 | } |
---|
| 123 | return tempindex; |
---|
| 124 | } |
---|
| 125 | |
---|
[1676] | 126 | private int getIndex(IEventTaskInstance eti) { |
---|
| 127 | int tempindex = -1; |
---|
[1677] | 128 | if(!idmapping.containsKey(eti.getTask().getId())) { |
---|
[1676] | 129 | idmapping.put(eti.getTask().getId(), index); |
---|
| 130 | tempindex = index; |
---|
| 131 | index++; |
---|
| 132 | } |
---|
[1677] | 133 | else { |
---|
[1676] | 134 | tempindex = idmapping.get(eti.getTask().getId()); |
---|
| 135 | } |
---|
| 136 | return tempindex; |
---|
[1677] | 137 | }; |
---|
[1676] | 138 | |
---|
| 139 | private float distanceBetweenInstances(IEventTaskInstance eti1, IEventTaskInstance eti2) { |
---|
| 140 | IGUIElement first = (IGUIElement) eti1.getEvent().getTarget(); |
---|
| 141 | IGUIElement second = (IGUIElement) eti2.getEvent().getTarget(); |
---|
| 142 | float distance = -1*AlignmentHelpers.distanceBetween(first, second); |
---|
| 143 | distance += positiveThreshold; |
---|
| 144 | return distance; |
---|
| 145 | } |
---|
| 146 | |
---|
[1558] | 147 | public String toString(){ |
---|
| 148 | return matrix.toString(); |
---|
| 149 | } |
---|
[1554] | 150 | |
---|
[1578] | 151 | public double getScore(int taskId1, int taskId2) { |
---|
| 152 | if(taskId1 == Constants.GAP_SYMBOL || taskId1 == Constants.UNMATCHED_SYMBOL || taskId2 == Constants.GAP_SYMBOL || taskId2 == Constants.UNMATCHED_SYMBOL ) { |
---|
| 153 | return 0.0; |
---|
| 154 | } |
---|
| 155 | else { |
---|
[1677] | 156 | int first = idmapping.get(taskId1); |
---|
| 157 | int second = idmapping.get(taskId2); |
---|
| 158 | System.out.println("First: " + first + " Second: " + second); |
---|
| 159 | System.out.println("Matrix: " + matrix.get(first, second)); |
---|
| 160 | return matrix.get(first,second); |
---|
[1578] | 161 | } |
---|
| 162 | |
---|
[1554] | 163 | } |
---|
| 164 | |
---|
[1324] | 165 | } |
---|
[1554] | 166 | |
---|