source: branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/alignment/matrix/ObjectDistanceSubstitionMatrix.java @ 1675

Last change on this file since 1675 was 1675, checked in by rkrimmel, 10 years ago

Fixed first iteration of sequence detection and replacement

File size: 3.3 KB
RevLine 
[1572]1package de.ugoe.cs.autoquest.tasktrees.alignment.matrix;
[1324]2
[1570]3
[1554]4import java.util.HashMap;
[1331]5import java.util.Iterator;
6
7import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
[1553]8import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.AlignmentHelpers;
[1578]9import de.ugoe.cs.autoquest.tasktrees.alignment.algorithms.Constants;
[1553]10import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
[1554]11import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
12import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
13import de.ugoe.cs.autoquest.usageprofiles.SymbolMap;
[1324]14
[1570]15
[1324]16public 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;
[1615]23       
[1568]24        private double positiveThreshold;
[1555]25       
[1554]26        public ObjectDistanceSubstitionMatrix(
[1620]27                        SymbolMap<ITaskInstance, ITask> uniqueTasks,float positiveThreshold, int gapPenalty) {
[1554]28                this.uniqueTasks = uniqueTasks;
[1558]29                this.positiveThreshold = positiveThreshold;
[1554]30                idmapping = new HashMap<Integer, Integer>();
31                matrix = new TriangleMatrix(uniqueTasks.size()+1);
[1620]32                this.gapPenalty = gapPenalty;
[1558]33               
[1324]34        }
35
[1615]36
[1568]37        public double getGapPenalty() {
[1555]38                return gapPenalty;
[1324]39        }
[1615]40       
41        public void setGapPenalty(double gapPenalty) {
42                this.gapPenalty = gapPenalty;
43        }
[1324]44
[1554]45        public void generate() {
[1578]46       
[1555]47                int index = 0;
[1578]48               
[1558]49                float maxDistance =34;
[1554]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                        }
[1675]57                        else {
58                                //System.out.println("Not an EventTaskInstance");
59                                continue;
60                        }
[1555]61               
[1554]62                        for (Iterator<ITaskInstance> jt = uniqueTasks.getSymbols()
63                                        .iterator(); jt.hasNext();) {
64                                IEventTaskInstance eti2 = null;
65                                Object obj2 = jt.next();
66                                if (obj2 instanceof IEventTaskInstance) {
67                                        eti2 = (IEventTaskInstance) obj2;
[1331]68                                }
[1675]69                                else{
70                                        //System.out.println("Not an EventtaskInstance");
71                                        continue;
72                                }
[1554]73                                IGUIElement first = (IGUIElement) eti1.getEvent().getTarget();
74                                IGUIElement second = (IGUIElement) eti2.getEvent().getTarget();
[1555]75                                int tempindex1 = -1;
76                                int tempindex2 = -1;
77                                if(!idmapping.containsKey(eti1.getTask().getId()))
78                                {
79                                        idmapping.put(eti1.getTask().getId(), index);
80                                        tempindex1 = index;
81                                        index++;
82                                }       
83                                else
84                                {
85                                        tempindex1 = idmapping.get(eti1.getTask().getId());
86                                }       
87                                if(!idmapping.containsKey(eti2.getTask().getId()))
88                                {
89                                        idmapping.put(eti2.getTask().getId(), index);
90                                        tempindex2 = index;
91                                        index++;
92                                }       
93                                else
94                                {
95                                        tempindex2 = idmapping.get(eti2.getTask().getId());
96                                }
[1558]97                                float distance = -1*AlignmentHelpers.distanceBetween(first, second);
[1555]98                       
[1570]99                       
[1558]100                                if(distance > maxDistance){
101                                        maxDistance = distance;
[1555]102                                }
[1558]103                               
[1570]104                                distance += positiveThreshold;
[1558]105                               
[1570]106
[1558]107                               
[1555]108                                matrix.set(tempindex1, tempindex2,distance);
[1578]109       
[1554]110                        }
[1331]111                }
[1324]112        }
[1558]113       
114        public String toString(){
115                return matrix.toString();
116        }
[1554]117
[1578]118        public double getScore(int taskId1, int taskId2) {
119                if(taskId1 == Constants.GAP_SYMBOL || taskId1 == Constants.UNMATCHED_SYMBOL || taskId2 == Constants.GAP_SYMBOL || taskId2 == Constants.UNMATCHED_SYMBOL ) {
120                        return 0.0;
121                }
122                else {
123                        return matrix.get(idmapping.get(taskId1),idmapping.get(taskId2));       
124                }
125               
[1554]126        }
127
[1324]128}
[1554]129
Note: See TracBrowser for help on using the repository browser.