Ignore:
Timestamp:
03/27/15 13:26:47 (10 years ago)
Author:
pharms
Message:
  • adapted to allow giving percentages, too
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/sequences/CMDsequencesSubset.java

    r1885 r1934  
    4949    public void run(List<Object> parameters) { 
    5050        int subsetCount; 
    51         int subsetSize; 
     51        double subsetSize; 
     52        boolean isPercent = false; 
    5253        String sequencesName; 
    5354        String newSequencesName; 
    5455        try { 
    5556            subsetCount = Integer.parseInt((String) parameters.get(0)); 
    56             subsetSize = Integer.parseInt((String) parameters.get(1)); 
     57            isPercent = ((String) parameters.get(1)).endsWith("%"); 
     58             
     59            if (!isPercent) { 
     60                subsetSize = Integer.parseInt((String) parameters.get(1)); 
     61            } 
     62            else { 
     63                String percent = (String) parameters.get(1); 
     64                percent = percent.substring(0, percent.length() - 1); 
     65                subsetSize = Double.parseDouble(percent); 
     66            } 
    5767            sequencesName = (String) parameters.get(2); 
    5868            if (parameters.size() > 3) { 
     
    108118        } 
    109119         
     120        int effSubsetSize; 
     121        if (isPercent) { 
     122            effSubsetSize = (int) Math.floor(subsetSize * allEvents / 100); 
     123        } 
     124        else { 
     125            effSubsetSize = (int) subsetSize; 
     126        } 
     127         
    110128        Console.println("creating " + subsetCount + " sequence sets covering on average " + 
    111                         subsetSize + " events by subdividing " + sequences.size() + 
     129                        effSubsetSize + " events by subdividing " + sequences.size() + 
    112130                        " sequences covering " + allEvents + " events into subsets"); 
    113131         
    114         boolean mutuallyExclusiveSubsets = (subsetSize * subsetCount) < allEvents; 
     132        boolean mutuallyExclusiveSubsets = (effSubsetSize * subsetCount) <= allEvents; 
    115133         
    116134        if (!mutuallyExclusiveSubsets) { 
     
    120138 
    121139        List<List<List<Event>>> subsets = new LinkedList<>(); 
    122         double randomProbability = ((double) subsetSize) / allEvents; 
     140        double randomProbability = ((double) effSubsetSize) / allEvents; 
    123141        ListIterator<List<Event>> sequencesIterator = fixedOrderSequences.listIterator(); 
    124142        int minSubsetSize = Integer.MAX_VALUE; 
     
    128146        for (int i = 0; i < subsetCount; i++) { 
    129147            List<List<Event>> subset = new LinkedList<>(); 
    130             int remainingEventsToAdd = subsetSize; 
     148            int remainingEventsToAdd = effSubsetSize; 
    131149            while (remainingEventsToAdd > 0) { 
    132150                if (!sequencesIterator.hasNext()) { 
Note: See TracChangeset for help on using the changeset viewer.