@Override public int getNumNestedTransitions(int s, int i, int j) { DistributionSet ds = trans.get(s).get(i); Iterator<Distribution> iter = ds.iterator(); Distribution distr = null; int k = 0; while (iter.hasNext() && k <= j) { distr = iter.next(); k++; } if (k <= j) return 0; else return distr.size(); }
@Override public void clearState(int i) { // Do nothing if state does not exist if (i >= numStates || i < 0) return; // Clear data structures and update stats List<DistributionSet> list = trans.get(i); numDistrSets -= list.size(); for (DistributionSet set : list) { numDistrs -= set.size(); for (Distribution distr : set) numTransitions -= distr.size(); } // TODO: recompute maxNumDistrSets // TODO: recompute maxNumDistrs // Remove all distribution sets trans.set(i, new ArrayList<DistributionSet>(0)); }
/** * Add distribution set 'newSet' to state s (which must exist). Distribution set is only actually * added if it does not already exists for state s. (Assuming 'allowDupes' flag is not enabled.) * Returns the index of the (existing or newly added) set. Returns -1 in case of error. */ public int addDistributionSet(int s, DistributionSet newSet) { ArrayList<DistributionSet> set; // Check state exists if (s >= numStates || s < 0) return -1; // Add distribution set (if new) set = trans.get(s); if (!allowDupes) { int i = set.indexOf(newSet); if (i != -1) return i; } set.add(newSet); // Update stats numDistrSets++; maxNumDistrSets = Math.max(maxNumDistrSets, set.size()); numDistrs += newSet.size(); maxNumDistrs = Math.max(maxNumDistrs, newSet.size()); for (Distribution distr : newSet) numTransitions += distr.size(); return set.size() - 1; }