[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 | |
---|
[1570] | 7 | |
---|
[1331] | 8 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
[1553] | 9 | import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentHelpers; |
---|
| 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; |
---|
| 23 | private double positiveThreshold; |
---|
[1555] | 24 | |
---|
[1554] | 25 | public ObjectDistanceSubstitionMatrix( |
---|
[1558] | 26 | SymbolMap<ITaskInstance, ITask> uniqueTasks,float positiveThreshold) { |
---|
[1554] | 27 | this.uniqueTasks = uniqueTasks; |
---|
[1558] | 28 | this.positiveThreshold = positiveThreshold; |
---|
[1554] | 29 | idmapping = new HashMap<Integer, Integer>(); |
---|
| 30 | matrix = new TriangleMatrix(uniqueTasks.size()+1); |
---|
[1559] | 31 | gapPenalty = -5; |
---|
[1558] | 32 | |
---|
[1324] | 33 | } |
---|
| 34 | |
---|
| 35 | @Override |
---|
[1568] | 36 | public double getGapPenalty() { |
---|
[1555] | 37 | return gapPenalty; |
---|
[1324] | 38 | } |
---|
| 39 | |
---|
| 40 | @Override |
---|
[1554] | 41 | public void generate() { |
---|
[1555] | 42 | int index = 0; |
---|
[1558] | 43 | //TODO We need to determine this parameter before generating the matrix.. |
---|
[1568] | 44 | //float meandistance = 18; |
---|
[1558] | 45 | //TODO We need to determine this parameter before generating the matrix.. |
---|
| 46 | float maxDistance =34; |
---|
[1554] | 47 | for (Iterator<ITaskInstance> it = uniqueTasks.getSymbols().iterator(); it |
---|
| 48 | .hasNext();) { |
---|
| 49 | Object obj1 = it.next(); |
---|
| 50 | IEventTaskInstance eti1 = null; |
---|
| 51 | if (obj1 instanceof IEventTaskInstance) { |
---|
| 52 | eti1 = (IEventTaskInstance) obj1; |
---|
| 53 | } |
---|
[1568] | 54 | //System.out.println(eti1.getTask().toString()); |
---|
[1555] | 55 | |
---|
[1554] | 56 | for (Iterator<ITaskInstance> jt = uniqueTasks.getSymbols() |
---|
| 57 | .iterator(); jt.hasNext();) { |
---|
| 58 | IEventTaskInstance eti2 = null; |
---|
| 59 | Object obj2 = jt.next(); |
---|
| 60 | if (obj2 instanceof IEventTaskInstance) { |
---|
| 61 | eti2 = (IEventTaskInstance) obj2; |
---|
[1331] | 62 | } |
---|
[1554] | 63 | IGUIElement first = (IGUIElement) eti1.getEvent().getTarget(); |
---|
| 64 | IGUIElement second = (IGUIElement) eti2.getEvent().getTarget(); |
---|
[1555] | 65 | int tempindex1 = -1; |
---|
| 66 | int tempindex2 = -1; |
---|
| 67 | if(!idmapping.containsKey(eti1.getTask().getId())) |
---|
| 68 | { |
---|
| 69 | idmapping.put(eti1.getTask().getId(), index); |
---|
| 70 | tempindex1 = index; |
---|
| 71 | index++; |
---|
| 72 | } |
---|
| 73 | else |
---|
| 74 | { |
---|
| 75 | tempindex1 = idmapping.get(eti1.getTask().getId()); |
---|
| 76 | } |
---|
| 77 | if(!idmapping.containsKey(eti2.getTask().getId())) |
---|
| 78 | { |
---|
| 79 | idmapping.put(eti2.getTask().getId(), index); |
---|
| 80 | tempindex2 = index; |
---|
| 81 | index++; |
---|
| 82 | } |
---|
| 83 | else |
---|
| 84 | { |
---|
| 85 | tempindex2 = idmapping.get(eti2.getTask().getId()); |
---|
| 86 | } |
---|
[1558] | 87 | float distance = -1*AlignmentHelpers.distanceBetween(first, second); |
---|
[1555] | 88 | |
---|
[1570] | 89 | |
---|
[1558] | 90 | if(distance > maxDistance){ |
---|
| 91 | maxDistance = distance; |
---|
[1555] | 92 | } |
---|
[1558] | 93 | |
---|
[1570] | 94 | distance += positiveThreshold; |
---|
[1558] | 95 | |
---|
[1570] | 96 | |
---|
[1558] | 97 | |
---|
[1555] | 98 | matrix.set(tempindex1, tempindex2,distance); |
---|
| 99 | |
---|
[1554] | 100 | } |
---|
[1331] | 101 | } |
---|
[1558] | 102 | //System.out.println("ObjectDistanceMatrix: MaxDistance: " + maxDistance); |
---|
| 103 | //System.out.println(meandistance/(uniqueTasks.size()*uniqueTasks.size())); |
---|
[1555] | 104 | //System.out.println(idmapping.toString()); |
---|
| 105 | //System.out.println(matrix.toString()); |
---|
| 106 | //System.out.println(idmapping.keySet().toString()); |
---|
| 107 | //System.out.println(idmapping.values().toString()); |
---|
| 108 | |
---|
[1324] | 109 | } |
---|
[1558] | 110 | |
---|
| 111 | public String toString(){ |
---|
| 112 | return matrix.toString(); |
---|
| 113 | } |
---|
[1554] | 114 | |
---|
| 115 | @Override |
---|
[1568] | 116 | public double getDistance(int taskId1, int taskId2) { |
---|
[1555] | 117 | //System.out.println("Taskid1: " + taskId1 + " Taskid2: " + taskId2 + " Idmapping1: " + idmapping.get(taskId1) + " Idmapping2: " + idmapping.get(taskId2)); |
---|
[1554] | 118 | return matrix.get(idmapping.get(taskId1),idmapping.get(taskId2)); |
---|
| 119 | } |
---|
| 120 | |
---|
[1324] | 121 | } |
---|
[1554] | 122 | |
---|