Changeset 1954


Ignore:
Timestamp:
05/31/15 19:22:54 (9 years ago)
Author:
pharms
Message:
  • fixed a bug in the detection of overlapping iterations before merging them.
  • now iterations are ignored, if they cause no repetitions in a task to be merged
  • the same applies for optionals making hopefully the merge more intuitive and cause less large selections
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-tasktrees-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/CondenseSimilarTasksRuleTest.java

    r1845 r1954  
    666666        String output = 
    667667            "UserSession {" + 
    668             "  Selection sel1 {" + 
     668            "  Sequence sequence5 {" + 
     669            "    Iteration itSequence6 {" + 
     670            "      Sequence sequence6 {" + 
     671            "        Event action1 {}" + 
     672            "        Selection 1 {" + 
     673            "          Event action2 {}" + 
     674            "        }" + 
     675            "      }" + 
     676            "      Sequence sequence6 {" + 
     677            "        Event action1 {}" + 
     678            "        Selection 1 {" + 
     679            "          Event action2 {}" + 
     680            "        }" + 
     681            "      }" + 
     682            "    }" + 
     683            "    Event action3 {}" + 
     684            "  }" + 
     685            "  Sequence sequence5 {" + 
     686            "    Iteration itSequence6 {" + 
     687            "      Sequence sequence6 {" + 
     688            "        Event action1 {}" + 
     689            "        Selection 1 {" + 
     690            "          Event action4 {}" + 
     691            "        }" + 
     692            "      }" + 
     693            "    }" + 
     694            "    Event action3 {}" + 
     695            "  }" + 
     696            "}"; 
     697 
     698        applySessionScopeRule(CondenseSimilarTasksRule.class, input, output); 
     699    } 
     700 
     701    /** 
     702     * 
     703     */ 
     704    @Test 
     705    public void test_IterationPreservation_03() throws Exception { 
     706        String input = 
     707            "UserSession {" + 
     708            "  Sequence sequence1 {" + 
     709            "    Iteration itSequence2 {" + 
     710            "      Sequence sequence2 {" + 
     711            "        Event action1 {}" + 
     712            "        Event action2 {}" + 
     713            "      }" + 
     714            "      Sequence sequence2 {" + 
     715            "        Event action1 {}" + 
     716            "        Event action2 {}" + 
     717            "      }" + 
     718            "    }" + 
     719            "    Event action3 {}" + 
     720            "  }" + 
     721            "  Sequence sequence3 {" + 
     722            "    Event action1 {}" + 
     723            "    Iteration itSequence4 {" + 
     724            "      Sequence sequence4 {" + 
     725            "        Event action4 {}" + 
     726            "        Event action3 {}" + 
     727            "      }" + 
     728            "      Sequence sequence4 {" + 
     729            "        Event action4 {}" + 
     730            "        Event action3 {}" + 
     731            "      }" + 
     732            "      Sequence sequence4 {" + 
     733            "        Event action4 {}" + 
     734            "        Event action3 {}" + 
     735            "      }" + 
     736            "    }" + 
     737            "  }" + 
     738            "}"; 
     739 
     740        String output = 
     741            "UserSession {" + 
     742            "  Selection selection1 {" + 
    669743            "    Sequence sequence1 {" + 
    670744            "      Iteration itSequence2 {" + 
     
    681755            "    }" + 
    682756            "  }" + 
    683             "  Selection sel1 {" + 
     757            "  Selection selection1 {" + 
    684758            "    Sequence sequence3 {" + 
    685759            "      Event action1 {}" + 
     
    689763            "          Event action3 {}" + 
    690764            "        }" + 
     765            "        Sequence sequence4 {" + 
     766            "          Event action4 {}" + 
     767            "          Event action3 {}" + 
     768            "        }" + 
     769            "        Sequence sequence4 {" + 
     770            "          Event action4 {}" + 
     771            "          Event action3 {}" + 
     772            "        }" + 
    691773            "      }" + 
    692774            "    }" + 
     
    701783     */ 
    702784    @Test 
    703     public void test_IterationPreservation_03() throws Exception { 
     785    public void test_IterationPreservation_04() throws Exception { 
    704786        String input = 
    705787            "UserSession {" + 
     
    734816        String output = 
    735817            "UserSession {" + 
     818            "  Iteration itSequence5 {" + 
     819            "    Sequence sequence5 {" + 
     820            "      Iteration itSequence6 {" + 
     821            "        Sequence sequence6 {" + 
     822            "          Event action1 {}" + 
     823            "          Selection 1 {" + 
     824            "            Event action2 {}" + 
     825            "          }" + 
     826            "        }" + 
     827            "        Sequence sequence6 {" + 
     828            "          Event action1 {}" + 
     829            "          Selection 1 {" + 
     830            "            Event action2 {}" + 
     831            "          }" + 
     832            "        }" + 
     833            "      }" + 
     834            "      Event action3 {}" + 
     835            "    }" + 
     836            "    Sequence sequence5 {" + 
     837            "      Iteration itSequence6 {" + 
     838            "        Sequence sequence6 {" + 
     839            "          Event action1 {}" + 
     840            "          Selection 1 {" + 
     841            "            Event action4 {}" + 
     842            "          }" + 
     843            "        }" + 
     844            "      }" + 
     845            "      Event action3 {}" + 
     846            "    }" + 
     847            "  }" + 
     848            "}"; 
     849 
     850        applySessionScopeRule(CondenseSimilarTasksRule.class, input, output); 
     851    } 
     852 
     853    /** 
     854     * 
     855     */ 
     856    @Test 
     857    public void test_IterationPreservation_05() throws Exception { 
     858        String input = 
     859            "UserSession {" + 
     860            "  Iteration itSequence1 {" + 
     861            "    Sequence sequence1 {" + 
     862            "      Iteration itSequence2 {" + 
     863            "        Sequence sequence2 {" + 
     864            "          Event action1 {}" + 
     865            "          Event action2 {}" + 
     866            "        }" + 
     867            "        Sequence sequence2 {" + 
     868            "          Event action1 {}" + 
     869            "          Event action2 {}" + 
     870            "        }" + 
     871            "      }" + 
     872            "      Event action3 {}" + 
     873            "    }" + 
     874            "  }" + 
     875            "  Iteration itSequence3 {" + 
     876            "    Sequence sequence3 {" + 
     877            "      Event action1 {}" + 
     878            "      Iteration itSequence4 {" + 
     879            "        Sequence sequence4 {" + 
     880            "          Event action4 {}" + 
     881            "          Event action3 {}" + 
     882            "        }" + 
     883            "        Sequence sequence4 {" + 
     884            "          Event action4 {}" + 
     885            "          Event action3 {}" + 
     886            "        }" + 
     887            "        Sequence sequence4 {" + 
     888            "          Event action4 {}" + 
     889            "          Event action3 {}" + 
     890            "        }" + 
     891            "      }" + 
     892            "    }" + 
     893            "  }" + 
     894            "}"; 
     895 
     896        String output = 
     897            "UserSession {" + 
    736898            "  Iteration itSelection1 {" + 
    737             "    Selection sel1 {" + 
     899            "    Selection selection1 {" + 
    738900            "      Sequence sequence1 {" + 
    739901            "        Iteration itSequence2 {" + 
     
    750912            "      }" + 
    751913            "    }" + 
    752             "    Selection sel1 {" + 
     914            "    Selection selection1 {" + 
    753915            "      Sequence sequence3 {" + 
    754916            "        Event action1 {}" + 
     
    758920            "            Event action3 {}" + 
    759921            "          }" + 
     922            "          Sequence sequence4 {" + 
     923            "            Event action4 {}" + 
     924            "            Event action3 {}" + 
     925            "          }" + 
     926            "          Sequence sequence4 {" + 
     927            "            Event action4 {}" + 
     928            "            Event action3 {}" + 
     929            "          }" + 
    760930            "        }" + 
    761931            "      }" + 
     
    771941     */ 
    772942    @Test 
    773     public void test_IterationPreservation_04() throws Exception { 
     943    public void test_IterationPreservation_06() throws Exception { 
    774944        String input = 
    775945            "UserSession {" + 
     
    810980        String output = 
    811981            "UserSession {" + 
    812             "  Selection sel1 {" + 
    813             "    Sequence sequence1 {" + 
    814             "      Iteration itSequence2 {" + 
    815             "        Sequence sequence2 {" + 
    816             "          Event action1 {}" + 
    817             "          Iteration itSequence3 {" + 
    818             "            Sequence sequence3 {" + 
    819             "              Event action2 {}" + 
     982            "  Sequence sequence7 {" + 
     983            "    Event action1 {}" + 
     984            "    Iteration itSequence8 {" + 
     985            "      Sequence sequence8 {" + 
     986            "        Event action2 {}" + 
     987            "        Selection selection1 {" + 
     988            "          Event action3 {}" + 
     989            "        }" + 
     990            "      }" + 
     991            "      Sequence sequence8 {" + 
     992            "        Event action2 {}" + 
     993            "        Selection selection1 {" + 
     994            "          Event action3 {}" + 
     995            "        }" + 
     996            "      }" + 
     997            "    }" + 
     998            "    Event action4 {}" + 
     999            "  }" + 
     1000            "  Sequence sequence7 {" + 
     1001            "    Event action1 {}" + 
     1002            "    Iteration itSequence8 {" + 
     1003            "      Sequence sequence8 {" + 
     1004            "        Event action2 {}" + 
     1005            "        Selection selection1 {" + 
     1006            "          Event action5 {}" + 
     1007            "        }" + 
     1008            "      }" + 
     1009            "    }" + 
     1010            "    Event action4 {}" + 
     1011            "  }" + 
     1012            "}"; 
     1013 
     1014        applySessionScopeRule(CondenseSimilarTasksRule.class, input, output); 
     1015    } 
     1016 
     1017    /** 
     1018     * 
     1019     */ 
     1020    @Test 
     1021    public void test_IterationPreservation_07() throws Exception { 
     1022        String input = 
     1023            "UserSession {" + 
     1024            "  Sequence sequence1 {" + 
     1025            "    Iteration itSequence2 {" + 
     1026            "      Sequence sequence2 {" + 
     1027            "        Event action1 {}" + 
     1028            "        Iteration itSequence3 {" + 
     1029            "          Sequence sequence3 {" + 
     1030            "            Event action2 {}" + 
     1031            "            Event action3 {}" + 
     1032            "          }" + 
     1033            "          Sequence sequence3 {" + 
     1034            "            Event action2 {}" + 
     1035            "            Event action3 {}" + 
     1036            "          }" + 
     1037            "        }" + 
     1038            "      }" + 
     1039            "    }" + 
     1040            "    Event action4 {}" + 
     1041            "  }" + 
     1042            "  Sequence sequence4 {" + 
     1043            "    Event action1 {}" + 
     1044            "    Iteration itSequence5 {" + 
     1045            "      Sequence sequence5 {" + 
     1046            "        Iteration itSequence6 {" + 
     1047            "          Sequence sequence6 {" + 
     1048            "            Event action2 {}" + 
     1049            "            Event action5 {}" + 
     1050            "          }" + 
     1051            "          Sequence sequence6 {" + 
     1052            "            Event action2 {}" + 
     1053            "            Event action5 {}" + 
     1054            "          }" + 
     1055            "          Sequence sequence6 {" + 
     1056            "            Event action2 {}" + 
     1057            "            Event action5 {}" + 
     1058            "          }" + 
     1059            "        }" + 
     1060            "        Event action4 {}" + 
     1061            "      }" + 
     1062            "    }" + 
     1063            "  }" + 
     1064            "}"; 
     1065 
     1066        String output = 
     1067            "UserSession {" + 
     1068            "  Sequence sequence7 {" + 
     1069            "    Event action1 {}" + 
     1070            "    Iteration itSequence8 {" + 
     1071            "      Sequence sequence8 {" + 
     1072            "        Event action2 {}" + 
     1073            "        Selection selection1 {" + 
     1074            "          Event action3 {}" + 
     1075            "        }" + 
     1076            "      }" + 
     1077            "      Sequence sequence8 {" + 
     1078            "        Event action2 {}" + 
     1079            "        Selection selection1 {" + 
     1080            "          Event action3 {}" + 
     1081            "        }" + 
     1082            "      }" + 
     1083            "    }" + 
     1084            "    Event action4 {}" + 
     1085            "  }" + 
     1086            "  Sequence sequence7 {" + 
     1087            "    Event action1 {}" + 
     1088            "    Iteration itSequence8 {" + 
     1089            "      Sequence sequence8 {" + 
     1090            "        Event action2 {}" + 
     1091            "        Selection selection1 {" + 
     1092            "          Event action5 {}" + 
     1093            "        }" + 
     1094            "      }" + 
     1095            "      Sequence sequence8 {" + 
     1096            "        Event action2 {}" + 
     1097            "        Selection selection1 {" + 
     1098            "          Event action5 {}" + 
     1099            "        }" + 
     1100            "      }" + 
     1101            "      Sequence sequence8 {" + 
     1102            "        Event action2 {}" + 
     1103            "        Selection selection1 {" + 
     1104            "          Event action5 {}" + 
     1105            "        }" + 
     1106            "      }" + 
     1107            "    }" + 
     1108            "    Event action4 {}" + 
     1109            "  }" + 
     1110            "}"; 
     1111 
     1112        applySessionScopeRule(CondenseSimilarTasksRule.class, input, output); 
     1113    } 
     1114 
     1115    /** 
     1116     * 
     1117     */ 
     1118    @Test 
     1119    public void test_IterationPreservation_08() throws Exception { 
     1120        String input = 
     1121            "UserSession {" + 
     1122            "  Sequence sequence1 {" + 
     1123            "    Iteration itSequence2 {" + 
     1124            "      Sequence sequence2 {" + 
     1125            "        Event action1 {}" + 
     1126            "        Iteration itSequence3 {" + 
     1127            "          Sequence sequence3 {" + 
     1128            "            Event action2 {}" + 
     1129            "            Event action3 {}" + 
     1130            "          }" + 
     1131            "          Sequence sequence3 {" + 
     1132            "            Event action2 {}" + 
     1133            "            Event action3 {}" + 
     1134            "          }" + 
     1135            "        }" + 
     1136            "      }" + 
     1137            "    }" + 
     1138            "    Event action4 {}" + 
     1139            "  }" + 
     1140            "  Sequence sequence4 {" + 
     1141            "    Event action1 {}" + 
     1142            "    Iteration itSequence5 {" + 
     1143            "      Sequence sequence5 {" + 
     1144            "        Iteration itSequence6 {" + 
     1145            "          Sequence sequence6 {" + 
     1146            "            Event action2 {}" + 
     1147            "            Event action5 {}" + 
     1148            "          }" + 
     1149            "        }" + 
     1150            "        Event action4 {}" + 
     1151            "      }" + 
     1152            "      Sequence sequence5 {" + 
     1153            "        Iteration itSequence6 {" + 
     1154            "          Sequence sequence6 {" + 
     1155            "            Event action2 {}" + 
     1156            "            Event action5 {}" + 
     1157            "          }" + 
     1158            "        }" + 
     1159            "        Event action4 {}" + 
     1160            "      }" + 
     1161            "    }" + 
     1162            "  }" + 
     1163            "}"; 
     1164 
     1165        String output = 
     1166            "UserSession {" + 
     1167            "  Sequence sequence7 {" + 
     1168            "    Event action1 {}" + 
     1169            "    Iteration itSequence8 {" + 
     1170            "      Sequence sequence8 {" + 
     1171            "        Iteration itSequence9 {" + 
     1172            "          Sequence sequence9 {" + 
     1173            "            Event action2 {}" + 
     1174            "            Selection selection1 {" + 
    8201175            "              Event action3 {}" + 
    8211176            "            }" + 
    822             "            Sequence sequence3 {" + 
    823             "              Event action2 {}" + 
     1177            "          }" + 
     1178            "          Sequence sequence9 {" + 
     1179            "            Event action2 {}" + 
     1180            "            Selection selection1 {" + 
    8241181            "              Event action3 {}" + 
    8251182            "            }" + 
    8261183            "          }" + 
    8271184            "        }" + 
    828             "      }" + 
    829             "      Event action4 {}" + 
    830             "    }" + 
    831             "  }" + 
    832             "  Selection sel1 {" + 
    833             "    Sequence sequence4 {" + 
    834             "      Event action1 {}" + 
    835             "      Iteration itSequence5 {" + 
    836             "        Sequence sequence5 {" + 
    837             "          Iteration itSequence6 {" + 
    838             "            Sequence sequence6 {" + 
    839             "              Event action2 {}" + 
    840             "              Event action5 {}" + 
    841             "            }" + 
    842             "          }" + 
    843             "          Event action4 {}" + 
    844             "        }" + 
     1185            "        Event action4 {}" + 
     1186            "      }" + 
     1187            "    }" + 
     1188            "  }" + 
     1189            "  Sequence sequence7 {" + 
     1190            "    Event action1 {}" + 
     1191            "    Iteration itSequence8 {" + 
     1192            "      Sequence sequence8 {" + 
     1193            "        Iteration itSequence9 {" + 
     1194            "          Sequence sequence9 {" + 
     1195            "            Event action2 {}" + 
     1196            "            Selection selection1 {" + 
     1197            "              Event action3 {}" + 
     1198            "            }" + 
     1199            "          }" + 
     1200            "        }" + 
     1201            "        Event action4 {}" + 
     1202            "      }" + 
     1203            "      Sequence sequence8 {" + 
     1204            "        Iteration itSequence9 {" + 
     1205            "          Sequence sequence9 {" + 
     1206            "            Event action2 {}" + 
     1207            "            Selection selection1 {" + 
     1208            "              Event action3 {}" + 
     1209            "            }" + 
     1210            "          }" + 
     1211            "        }" + 
     1212            "        Event action4 {}" + 
    8451213            "      }" + 
    8461214            "    }" + 
     
    8551223     */ 
    8561224    @Test 
    857     public void test_IterationPreservation_05() throws Exception { 
     1225    public void test_IterationPreservation_09() throws Exception { 
    8581226        String input = 
    8591227            "UserSession {" + 
     
    9191287            "    Event noiseAction1 {}" + 
    9201288            "    Iteration itSelection1 {" + 
    921             "      Selection sel1 {" + 
    922             "        Sequence sequence2 {" + 
    923             "          Iteration itSequence3 {" + 
    924             "            Sequence sequence3 {" + 
    925             "              Event action1 {}" + 
    926             "              Iteration itSequence4 {" + 
    927             "                Sequence sequence4 {" + 
    928             "                  Event action2 {}" + 
    929             "                  Event action3 {}" + 
    930             "                }" + 
    931             "              }" + 
    932             "            }" + 
    933             "          }" + 
    934             "          Event action4 {}" + 
    935             "        }" + 
    936             "      }" + 
    937             "      Selection sel1 {" + 
    938             "        Sequence sequence2 {" + 
    939             "          Iteration itSequence3 {" + 
    940             "            Sequence sequence3 {" + 
    941             "              Event action1 {}" + 
    942             "              Iteration itSequence4 {" + 
    943             "                Sequence sequence4 {" + 
    944             "                  Event action2 {}" + 
    945             "                  Event action3 {}" + 
    946             "                }" + 
    947             "              }" + 
    948             "            }" + 
    949             "          }" + 
    950             "          Event action4 {}" + 
    951             "        }" + 
     1289            "      Sequence sequence10 {" + 
     1290            "        Event action1 {}" + 
     1291            "        Selection selection1 {" + 
     1292            "          Event action2 {}" + 
     1293            "        }" + 
     1294            "        Event action3 {}" + 
     1295            "        Event action4 {}" + 
     1296            "      }" + 
     1297            "      Sequence sequence10 {" + 
     1298            "        Event action1 {}" + 
     1299            "        Selection selection1 {" + 
     1300            "          Event action2 {}" + 
     1301            "        }" + 
     1302            "        Event action3 {}" + 
     1303            "        Event action4 {}" + 
    9521304            "      }" + 
    9531305            "    }" + 
     
    9571309            "    Event noiseAction1 {}" + 
    9581310            "    Iteration itSelection1 {" + 
    959             "      Selection sel1 {" + 
    960             "        Sequence sequence6 {" + 
    961             "          Event action1 {}" + 
    962             "          Iteration itSequence7 {" + 
    963             "            Sequence sequence7 {" + 
    964             "              Iteration itSequence8 {" + 
    965             "                Sequence sequence8 {" + 
    966             "                  Event action5 {}" + 
    967             "                  Event action3 {}" + 
    968             "                }" + 
    969             "              }" + 
    970             "              Event action4 {}" + 
    971             "            }" + 
    972             "          }" + 
    973             "        }" + 
     1311            "      Sequence sequence10 {" + 
     1312            "        Event action1 {}" + 
     1313            "        Selection selection1 {" + 
     1314            "          Event action5 {}" + 
     1315            "        }" + 
     1316            "        Event action3 {}" + 
     1317            "        Event action4 {}" + 
    9741318            "      }" + 
    9751319            "    }" + 
     
    9851329     */ 
    9861330    @Test 
    987     public void test_IterationPreservation_06() throws Exception { 
     1331    public void test_IterationPreservation_10() throws Exception { 
    9881332        String input = 
    9891333            "UserSession {" + 
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/utils/SimilarTasks.java

    r1890 r1954  
    2727import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 
    2828import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
     29import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
    2930import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 
    30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
     31import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 
    3132import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    32 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
     33import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 
     34import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
    3335import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; 
    3436import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
     
    344346    public List<TaskPath> getPathsToIgnore() { 
    345347        List<TaskPath> result = new LinkedList<TaskPath>(); 
    346         Delta singleChangeDelta = null; 
    347348         
    348349        if ((patch.getDeltas().size() == 1) && 
    349350            (patch.getDeltas().get(0).getType() == Delta.TYPE.CHANGE)) 
    350351        { 
    351             singleChangeDelta = patch.getDeltas().get(0); 
    352         } 
    353          
    354         // if it is a full change, then the parent of either side must be fully ignored 
    355         if (singleChangeDelta != null) { 
     352            // if it is a full change, then the parent of either side must be fully ignored 
     353            Delta singleChangeDelta = patch.getDeltas().get(0); 
     354 
    356355            if ((singleChangeDelta.getOriginal().getPosition() == 0) && 
    357356                (singleChangeDelta.getOriginal().size() == leftHandSideTraversal.size())) 
     
    372371         
    373372        if (result.size() < 2) { 
    374             // if we do not already ignore both root tasks, check for selections and interleaving 
    375             // iterations that have to be ignored if they belong to a delta 
     373            // if we do not already ignore both root tasks, check for overlapping 
     374            // iterations that are executed multiple times for the tasks to be merged as they have 
     375            // to be ignored 
     376            result.addAll(getConflictingIterations()); 
     377             
     378            // then check for tasks fully inside delta, which can be preserved 
    376379            for (Delta delta : patch.getDeltas()) { 
    377                 //getSelections(delta, result); 
    378                 getPathsToRealIntersectingIterations(delta, result); 
    379380                getNotFullyInterleavingIteration(delta, result); 
    380381                getPathsToParentTasksFullyInsideDelta(delta, result); 
    381382            } 
    382383             
    383             // check for any parent optional that may be empty and can hence not be flattened 
    384             TaskPath tmppath = new TaskPath(); 
    385             tmppath.add(leftHandSide, 0); 
    386             getParentOptionals(tmppath, result); 
    387             tmppath = new TaskPath(); 
    388             tmppath.add(rightHandSide, 0); 
    389             getParentOptionals(tmppath, result); 
     384            // check for any parent optional that are at least once empty in instances of the 
     385            // tasks to be merged and that can, hence, not be flattened 
     386            getUnexecutedParentOptionals(leftHandSide, result); 
     387            getUnexecutedParentOptionals(rightHandSide, result); 
    390388             
    391389            // check if there are common subtasks on both sides that lie outside any delta and 
     
    839837        } 
    840838    }*/ 
    841  
    842     /** 
    843      * 
    844      */ 
    845     @SuppressWarnings("unchecked") 
    846     private void getPathsToRealIntersectingIterations(Delta delta, List<TaskPath> paths) { 
    847         TaskPath path1 = getCommonPath((List<TaskPath>) delta.getOriginal().getLines()); 
    848         TaskPath path2 = getCommonPath((List<TaskPath>) delta.getRevised().getLines()); 
    849          
    850         // both paths denote those parent tasks that contain the delta. 
    851         // But there may be parent tasks still contained in the path that are iterations and 
    852         // that are disjoint with a parent in the other path. Those iterations need to be 
    853         // considered, as otherwise a created selection would be against the associative law of 
    854         // iterations. Hence, we search for the topmost iteration on both paths that is disjoint 
    855         // with a parent node in the respective other path. 
    856          
    857         for (int i = 0; i < path1.size(); i++) { 
    858             TaskPath path1Prefix = path1.subPath(0, i + 1); 
    859             int[] idxsPath1 = leftHandSideTraversal.getIndexesRootedBy(path1Prefix); 
    860              
    861             // normalize the indexes to be 0 the index of the delta. Everything left of it 
    862             // is smaller 0, everything right of it, larger. 
    863             idxsPath1[0] -= delta.getOriginal().getPosition(); 
    864             idxsPath1[1] -= delta.getOriginal().getPosition() + delta.getOriginal().size() - 1; 
    865              
    866             for (int j = 0; j < path2.size(); j++) { 
    867                 TaskPath path2Prefix = path2.subPath(0, j + 1); 
    868                 int[] idxsPath2 = rightHandSideTraversal.getIndexesRootedBy(path2Prefix); 
    869                  
    870                 // normalize the indexes to be 0 the index of the delta. Everything left of it 
    871                 // is smaller 0, everything right of it, larger. 
    872                 idxsPath2[0] -= delta.getRevised().getPosition(); 
    873                 idxsPath2[1] -= 
    874                     delta.getRevised().getPosition() + delta.getRevised().size() - 1; 
    875                  
    876                 // now compare the indexes and check, if the sublists are real subsets of each 
    877                 // other. If not, they only have a real common subset but there is at least one 
    878                 // non shared element on both sides. If so, and one is an iteration, we 
    879                 // have to use it as elements to be selected 
    880                 if (((idxsPath1[0] < idxsPath2[0]) && (idxsPath1[1] < idxsPath2[1])) || 
    881                     ((idxsPath1[0] > idxsPath2[0]) && (idxsPath1[1] > idxsPath2[1]))) 
    882                 { 
    883                     if ((path1.get(i).getTask() instanceof IIteration) && 
    884                         (path2.get(j).getTask() instanceof IIteration)) 
    885                     { 
    886                         // System.out.println("found paths to real intersecting parents"); 
    887                         // int[] indexBuf = leftHandSideTraversal.getIndexesRootedBy(path1Prefix); 
    888                         // System.out.println(idxsPath1[0] + "(" + indexBuf[0] + ")  " + idxsPath1[1] + 
    889                         //                    "(" + indexBuf[1] + ")  " + path1Prefix); 
    890                         // indexBuf = rightHandSideTraversal.getIndexesRootedBy(path2Prefix); 
    891                         // System.out.println(idxsPath2[0] + "(" + indexBuf[0] + ")  " + idxsPath2[1] + 
    892                         //                    "(" + indexBuf[1] + ")  " + path2Prefix); 
     839     
     840    /** 
     841     * conflicting iterations are those that belong to either side of the sequence pair, that cover 
     842     * at least two actions, and that were executed multiple times in the context of the tasks 
     843     * to be merged. Iterations do only conflict, if there are at least two, one belonging to the 
     844     * left hand side, and the other to the right hand side. They conflict only, if they cover the 
     845     * same terminal nodes in the task traversals. 
     846     */ 
     847    private List<TaskPath> getConflictingIterations() { 
     848        List<TaskPath> iterationsWithMultipleExecutions = new LinkedList<>(); 
     849        getIterationsWithMultipleExecutions(leftHandSide, iterationsWithMultipleExecutions); 
     850         
     851        if (iterationsWithMultipleExecutions.size() > 0) { 
     852            // only, if iterations are executed in both side, they are of interest. Hence, 
     853            // check right hand side only, if left hand side contains repeated iterations. 
     854            int noOfLeftHandSideRepeatedIterations = iterationsWithMultipleExecutions.size(); 
     855            getIterationsWithMultipleExecutions(rightHandSide, iterationsWithMultipleExecutions); 
     856             
     857            if (iterationsWithMultipleExecutions.size() > noOfLeftHandSideRepeatedIterations) { 
     858                // also the right hand side contains problematic iterations. Check if they are 
     859                // overlapping and drop all which are not. 
     860                dropNonOverlappingIterations(iterationsWithMultipleExecutions); 
     861            } 
     862            else { 
     863                // no conflict, clear the list 
     864                iterationsWithMultipleExecutions.clear(); 
     865            } 
     866        } 
     867         
     868        return iterationsWithMultipleExecutions; 
     869    } 
     870 
     871    /** 
     872     * 
     873     */ 
     874    private void getIterationsWithMultipleExecutions(ITask          task, 
     875                                                     List<TaskPath> result) 
     876    { 
     877        for (ITaskInstance instance : task.getInstances()) { 
     878            TaskPath taskPath = new TaskPath(); 
     879            taskPath.add(task, 0); 
     880            getIterationsWithMultipleExecutions(instance, taskPath, result); 
     881        } 
     882    } 
     883 
     884    /** 
     885     * 
     886     */ 
     887    private void getIterationsWithMultipleExecutions(ITaskInstance  instance, 
     888                                                     TaskPath       currentPath, 
     889                                                     List<TaskPath> result) 
     890    { 
     891        if (instance instanceof IIterationInstance) { 
     892            if (((IIterationInstance) instance).size() > 1) { 
     893                // iteration executed multiple times --> store path 
     894                result.add(currentPath.subPath(0, currentPath.size())); // ensure to create a copy 
     895            } 
     896             
     897            currentPath.add(((IIteration) instance.getTask()).getMarkedTask(), 0); 
     898             
     899            for (ITaskInstance child : (IIterationInstance) instance) { 
     900                getIterationsWithMultipleExecutions(child, currentPath, result); 
     901            } 
     902             
     903            currentPath.removeLast(); 
     904        } 
     905        else if (instance instanceof ISequenceInstance) { 
     906            int index = 0; 
     907            for (ITaskInstance child : (ISequenceInstance) instance) { 
     908                currentPath.add(child.getTask(), index++); 
     909                getIterationsWithMultipleExecutions(child, currentPath, result); 
     910                currentPath.removeLast(); 
     911            } 
     912        } 
     913        else if (instance instanceof ISelectionInstance) { 
     914            ITaskInstance child = ((ISelectionInstance) instance).getChild(); 
     915            currentPath.add(child.getTask(), 0); 
     916            getIterationsWithMultipleExecutions(child, currentPath, result); 
     917            currentPath.removeLast(); 
     918        } 
     919        else if (instance instanceof IOptionalInstance) { 
     920            ITaskInstance child = ((IOptionalInstance) instance).getChild(); 
     921            if (child != null) { 
     922                currentPath.add(child.getTask(), 0); 
     923                getIterationsWithMultipleExecutions(child, currentPath, result); 
     924                currentPath.removeLast(); 
     925            } 
     926        } 
     927    } 
     928 
     929    /** 
     930     * 
     931     */ 
     932    private void dropNonOverlappingIterations(List<TaskPath> iterationsWithMultipleExecutions) { 
     933        // to check overlappings, iterate the iterations. Then check for each the indexes it covers 
     934        // in its respective traversal. Adapt the indexes depending on deltas that an iteration 
     935        // covers. Then check all other iterations. Consider also here the indexes in the traversal. 
     936        // also here, the indexes must be adapted in case of covered deltas. 
     937        List<TaskPath> overlappingIterations = new LinkedList<TaskPath>(); 
     938         
     939        for (TaskPath leftPath : iterationsWithMultipleExecutions) { 
     940            if (leftPath.getTask(0).equals(leftHandSide)) { 
     941                int[] leftIdxs = leftHandSideTraversal.getIndexesRootedBy(leftPath); 
     942                 
     943                for (TaskPath rightPath : iterationsWithMultipleExecutions) { 
     944                    if (rightPath.getTask(0).equals(rightHandSide)) { 
     945                        int[] rightIdxs = rightHandSideTraversal.getIndexesRootedBy(rightPath); 
    893946                         
    894                         paths.add(path1Prefix); 
    895                         paths.add(path2Prefix); 
    896                         return; 
    897                     } 
    898                 } 
    899             } 
    900         } 
     947                        adaptIndexesBasedOnDeltas(leftIdxs, rightIdxs, patch.getDeltas()); 
     948                         
     949                        if (((leftIdxs[0] < rightIdxs[0]) && (rightIdxs[0] <= leftIdxs[1])) || 
     950                            ((rightIdxs[0] < leftIdxs[0]) && (leftIdxs[0] <= rightIdxs[1]))) 
     951                        { 
     952                            overlappingIterations.add(leftPath); 
     953                            overlappingIterations.add(rightPath); 
     954                        } 
     955                    } 
     956                } 
     957            } 
     958        } 
     959         
     960        iterationsWithMultipleExecutions.retainAll(overlappingIterations); 
     961    } 
     962 
     963    /** 
     964     * 
     965     */ 
     966    private void adaptIndexesBasedOnDeltas(int[]       originalIndexes, 
     967                                           int[]       revisedIndexes, 
     968                                           List<Delta> deltas) 
     969    { 
     970        int originalStartUpdate = 0; 
     971        int originalEndUpdate = 0; 
     972        int revisedStartUpdate = 0; 
     973        int revisedEndUpdate = 0; 
     974         
     975        for (Delta delta : deltas) { 
     976            if (delta.getOriginal().getPosition() < originalIndexes[0]) { 
     977                originalStartUpdate += delta.getRevised().size(); 
     978            } 
     979            if (delta.getOriginal().getPosition() < originalIndexes[1]) { 
     980                originalEndUpdate += delta.getRevised().size(); 
     981            } 
     982            if (delta.getRevised().getPosition() < revisedIndexes[0]) { 
     983                revisedStartUpdate += delta.getOriginal().size(); 
     984            } 
     985            if (delta.getRevised().getPosition() < revisedIndexes[1]) { 
     986                revisedEndUpdate += delta.getOriginal().size(); 
     987            } 
     988        } 
     989         
     990        originalIndexes[0] += originalStartUpdate; 
     991        originalIndexes[1] += originalEndUpdate; 
     992        revisedIndexes[0] += revisedStartUpdate; 
     993        revisedIndexes[1] += revisedEndUpdate; 
    901994    } 
    902995 
     
    9391032    /** 
    9401033     * If a chunk has a minimum number of 2 entries and at least one of them belongs to an iteration 
    941      * the does not cover the other and also expands to preceding or succeeding paths in the 
    942      * traversal, we can no merge the situation. 
     1034     * that does not cover the other and also expands to preceding or succeeding paths in the 
     1035     * traversal, we can not merge the situation. 
    9431036     */ 
    9441037    private void getNotFullyInterleavingIterations(Chunk          chunk, 
     
    10311124     * 
    10321125     */ 
    1033     private void getParentOptionals(TaskPath taskPath, List<TaskPath> result) { 
    1034         ITask task = taskPath.getLast(); 
    1035          
    1036         if (task instanceof IOptional) { 
    1037             result.add(new TaskPath(taskPath)); 
    1038         } 
    1039         else if (task instanceof ISequence) { 
    1040             for (int i = 0; i < ((ISequence) task).getChildren().size(); i++) { 
    1041                 taskPath.add(((ISequence) task).getChildren().get(i), i); 
    1042                 getParentOptionals(taskPath, result); 
    1043                 taskPath.removeLast(); 
    1044             } 
    1045         } 
    1046         else if (task instanceof ISelection) { 
    1047             for (int i = 0; i < ((ISelection) task).getChildren().size(); i++) { 
    1048                 taskPath.add(((ISelection) task).getChildren().get(i), 0); 
    1049                 getParentOptionals(taskPath, result); 
    1050                 taskPath.removeLast(); 
    1051             } 
    1052         } 
    1053         else if (task instanceof IIteration) { 
    1054             taskPath.add(((IIteration) task).getMarkedTask(), 0); 
    1055             getParentOptionals(taskPath, result); 
    1056             taskPath.removeLast(); 
     1126    private void getUnexecutedParentOptionals(ITask          task, 
     1127                                              List<TaskPath> result) 
     1128    { 
     1129        for (ITaskInstance instance : task.getInstances()) { 
     1130            TaskPath taskPath = new TaskPath(); 
     1131            taskPath.add(task, 0); 
     1132            getUnexecutedParentOptionals(instance, taskPath, result); 
     1133        } 
     1134    } 
     1135     
     1136    /** 
     1137     * 
     1138     */ 
     1139    private void getUnexecutedParentOptionals(ITaskInstance  instance, 
     1140                                              TaskPath       currentPath, 
     1141                                              List<TaskPath> result) 
     1142    { 
     1143        if (instance instanceof IOptionalInstance) { 
     1144            ITaskInstance child = ((IOptionalInstance) instance).getChild(); 
     1145            if (child != null) { 
     1146                currentPath.add(child.getTask(), 0); 
     1147                getUnexecutedParentOptionals(child, currentPath, result); 
     1148                currentPath.removeLast(); 
     1149            } 
     1150            else { 
     1151                result.add(currentPath.subPath(0, currentPath.size())); // ensure to create a copy 
     1152            } 
     1153        } 
     1154        else if (instance instanceof IIterationInstance) { 
     1155            currentPath.add(((IIteration) instance.getTask()).getMarkedTask(), 0); 
     1156             
     1157            for (ITaskInstance child : (IIterationInstance) instance) { 
     1158                getUnexecutedParentOptionals(child, currentPath, result); 
     1159            } 
     1160             
     1161            currentPath.removeLast(); 
     1162        } 
     1163        else if (instance instanceof ISequenceInstance) { 
     1164            int index = 0; 
     1165            for (ITaskInstance child : (ISequenceInstance) instance) { 
     1166                currentPath.add(child.getTask(), index++); 
     1167                getUnexecutedParentOptionals(child, currentPath, result); 
     1168                currentPath.removeLast(); 
     1169            } 
     1170        } 
     1171        else if (instance instanceof ISelectionInstance) { 
     1172            ITaskInstance child = ((ISelectionInstance) instance).getChild(); 
     1173            currentPath.add(child.getTask(), 0); 
     1174            getUnexecutedParentOptionals(child, currentPath, result); 
     1175            currentPath.removeLast(); 
    10571176        } 
    10581177    } 
Note: See TracChangeset for help on using the changeset viewer.