Changeset 1721 for branches/autoquest-core-tasktrees-alignment
- Timestamp:
- 09/04/14 10:42:11 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/autoquest-core-tasktrees-alignment/src/main/java/de/ugoe/cs/autoquest/tasktrees/temporalrelation/SequenceForTaskDetectionRuleAlignment.java
r1720 r1721 23 23 import java.io.Serializable; 24 24 import java.util.ArrayList; 25 import java.util.Collection; 25 26 import java.util.Collections; 26 27 import java.util.Comparator; … … 32 33 import java.util.Map; 33 34 import java.util.Set; 35 import java.util.concurrent.Callable; 36 import java.util.concurrent.ExecutorService; 37 import java.util.concurrent.Executors; 38 import java.util.concurrent.TimeUnit; 34 39 import java.util.logging.Level; 35 40 … … 77 82 public class SequenceForTaskDetectionRuleAlignment implements ISessionScopeRule { 78 83 79 80 84 public static int nThreads = Runtime.getRuntime().availableProcessors()-1; 85 86 81 87 private int iteration = 0; 82 88 /** … … 94 100 */ 95 101 private ITaskBuilder taskBuilder; 102 96 103 97 104 /** … … 649 656 650 657 // Generate pairwise alignments 651 int size = appData.getNumberSequences().size();652 Console.traceln(Level.INFO, "generating pairwise alignments from " + size + " sessions");658 int numberSeqSize = appData.getNumberSequences().size(); 659 Console.traceln(Level.INFO, "generating pairwise alignments from " + numberSeqSize + " sessions"); 653 660 int count = 0; 654 661 … … 657 664 if(!(aligned.exists() && !aligned.isDirectory())) { 658 665 appData.matchseqs = new LinkedList<Match>(); 659 System.out.println(appData.matchseqs);660 666 for (int i = 0; i < appData.getNumberSequences().size(); i++) { 661 667 NumberSequence ns1 = appData.getNumberSequences().get(i); 662 668 count++; 663 664 //Print out the progress 665 if(size>100) { 666 if((count%(size/100)==0)) { 667 Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 668 } 669 } 670 else { 671 Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 672 } 669 printProgressPercentage(count,numberSeqSize); 673 670 for (int j = 0; j < appData.getNumberSequences().size(); j++) { 674 671 NumberSequence ns2 = appData.getNumberSequences().get(j); … … 690 687 691 688 692 Console.traceln(Level.INFO, "searching for patterns occuring most"); 693 694 count = 0; 695 size=appData.getMatchseqs().size(); 696 Console.traceln(Level.INFO, "Pattern count is " + size); 697 // search each match in every other sequence 698 for (Iterator<Match> it = appData.getMatchseqs().iterator(); it.hasNext();) { 699 Match pattern = it.next(); 700 count++; 701 //Print out the progress 702 if(size>100) { 703 if((count%(size/100)==0)) { 704 Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 705 } 706 } 707 else { 708 Console.traceln(Level.INFO,(Math.round((float) count/size*100))+ "%"); 709 } 710 // Skip sequences with more 0 events (scrolls) than other events. 711 // Both of the pattern sequences are equally long, so the zero 712 // counts just need to be smaller than the length of one sequence 713 if (pattern.getFirstSequence().eventCount(0) 714 + pattern.getSecondSequence().eventCount(0) + 1 > pattern 715 .getFirstSequence().size()) 716 continue; 717 718 for (int j = 0; j < appData.getNumberSequences().size(); j++) { 719 LinkedList<Integer> startpositions = appData 720 .getNumberSequences().get(j).containsPattern(pattern); 721 if (startpositions.size() > 0) { 722 for (Iterator<Integer> jt = startpositions.iterator(); jt 723 .hasNext();) { 724 int start = jt.next(); 725 pattern.addOccurence(new MatchOccurence(start, start 726 + pattern.size(), j)); 727 } 728 729 } 730 } 731 } 732 689 Console.traceln(Level.INFO, "searching for patterns occuring most with " + nThreads + " threads"); 690 691 //Prepare parallel search of matchseqs 692 ExecutorService executor = Executors.newFixedThreadPool(nThreads); 693 int matchSeqSize=appData.getMatchseqs().size(); 694 int interval = Math.round(matchSeqSize/nThreads); 695 int rest = matchSeqSize % nThreads; 696 697 for(int i =0;i<matchSeqSize-interval;i+=interval) { 698 int offset =0; 699 if(rest!=0) { 700 offset=1; 701 rest--; 702 } 703 int from = i; 704 int to = i+interval+offset; 705 System.out.println("Creating thread with matches from " + from + " to " + to); 706 // search each match in every other sequence 707 ParallelMatchOcurrencesFinder finder = new ParallelMatchOcurrencesFinder(appData,from,to); 708 executor.execute(finder); 709 } 710 executor.shutdown(); 711 try { 712 executor.awaitTermination(2, TimeUnit.HOURS); 713 } catch (InterruptedException e) { 714 // TODO Auto-generated catch block 715 e.printStackTrace(); 716 } 717 718 733 719 Console.traceln(Level.INFO, "sorting results"); 734 720 // Sort results to get the most occurring results … … 839 825 appData.getStopWatch().stop("replacing tasks"); 840 826 } 827 828 829 //Print out the progress 830 private static void printProgressPercentage(int count, int size) { 831 832 if(size>100) { 833 if((count%(size/100)==0)) { 834 Console.traceln(Level.INFO,("Thread" + Thread.currentThread().getName() + ": " + Math.round((float) count/size*100))+ "%"); 835 } 836 } 837 else { 838 Console.traceln(Level.INFO,("Thread" + Thread.currentThread().getName() + ": " +Math.round((float) count/size*100))+ "%"); 839 } 840 } 841 842 843 844 845 private class ParallelMatchOcurrencesFinder implements Runnable { 846 private final RuleApplicationData appData; 847 private final int from; 848 private final int to; 849 ParallelMatchOcurrencesFinder(RuleApplicationData appData, int from, int to) { 850 this.appData = appData; 851 this.from = from; 852 this.to = to; 853 } 854 855 @Override 856 public void run() { 857 int count = 0; 858 int size=to-from; 859 Console.traceln(Level.INFO, "Pattern count is " + size); 860 for (int i=from; i<to;i++) { { 861 Match pattern = appData.getMatchseqs().get(i); 862 count++; 863 printProgressPercentage(count,size); 864 // Skip sequences with more 0 events (scrolls) than other events. 865 // Both of the pattern sequences are equally long, so the zero 866 // counts just need to be smaller than the length of one sequence 867 if (pattern.getFirstSequence().eventCount(0) 868 + pattern.getSecondSequence().eventCount(0) + 1 > pattern 869 .getFirstSequence().size()) 870 continue; 871 872 for (int j = 0; j < appData.getNumberSequences().size(); j++) { 873 LinkedList<Integer> startpositions = appData 874 .getNumberSequences().get(j).containsPattern(pattern); 875 if (startpositions.size() > 0) { 876 for (Iterator<Integer> jt = startpositions.iterator(); jt 877 .hasNext();) { 878 int start = jt.next(); 879 pattern.addOccurence(new MatchOccurence(start, start 880 + pattern.size(), j)); 881 } 882 883 } 884 } 885 } 886 } 887 } 888 } 889 890 891 841 892 842 893 /** … … 895 946 submat= new ObjectDistanceSubstitionMatrix(6,-3,false); 896 947 newTasks = new LinkedList<ITask>(); 897 this.detectedAndReplacedTasks = true; 948 949 //this.detectedAndReplacedTasks = true; 898 950 } 899 951
Note: See TracChangeset
for help on using the changeset viewer.