@Test @Ignore public void testPerformance() { boolean[] set = new boolean[10]; Arrays.fill(set, true); PowerSet original = new PowerSet(set); long time10 = System.currentTimeMillis(); original.getOnPowerSet(0); time10 = (System.currentTimeMillis() - time10) / 1000; System.out.print(String.format("Computing PowerSet of size 10 took %d seconds", time10)); set = new boolean[11]; Arrays.fill(set, true); original = new PowerSet(set); long time11 = System.currentTimeMillis(); original.getOnPowerSet(0); time11 = (System.currentTimeMillis() - time11) / 1000; System.out.print(String.format("Computing PowerSet of size 11 took %d seconds",time11)); assertTrue(time11 > time10); }
public Set<PowerSet> getOnPowerSet(int minOn) { Set<PowerSet> sets = new HashSet<PowerSet>(); if (sizeOn() <= minOn) { return sets; } for (int p=0; p<set.length; p++){ if (set[p]){ PowerSet cs = new PowerSet(this); cs.switchOff(p); sets.add(cs); sets.addAll(cs.getOnPowerSet(minOn)); } } return sets; }
PowerSet { public Set<PowerSet> getOnPowerSet(int minOn) { Set<PowerSet> sets = new HashSet<PowerSet>(); if (sizeOn() <= minOn) { return sets; } for (int p=0; p<set.length; p++){ if (set[p]){ PowerSet cs = new PowerSet(this); cs.switchOff(p); sets.add(cs); sets.addAll(cs.getOnPowerSet(minOn)); } } return sets; } }
PowerSet { public Set<PowerSet> getOnPowerSet(int minOn) { Set<PowerSet> sets = new HashSet<PowerSet>(); if (sizeOn() <= minOn) { return sets; } for (int p=0; p<set.length; p++){ if (set[p]){ PowerSet cs = new PowerSet(this); cs.switchOff(p); sets.add(cs); sets.addAll(cs.getOnPowerSet(minOn)); } } return sets; } PowerSet(int size);  PowerSet(boolean[] set);  PowerSet(PowerSet powerSet); }
PowerSet { public Set<PowerSet> getOnPowerSet(int minOn) { Set<PowerSet> sets = new HashSet<PowerSet>(); if (sizeOn() <= minOn) { return sets; } for (int p=0; p<set.length; p++){ if (set[p]){ PowerSet cs = new PowerSet(this); cs.switchOff(p); sets.add(cs); sets.addAll(cs.getOnPowerSet(minOn)); } } return sets; } PowerSet(int size);  PowerSet(boolean[] set);  PowerSet(PowerSet powerSet); void switchOn(int i); void switchOff(int i); boolean isOn(int i); boolean isOff(int i); boolean isChild(List<PowerSet> parents); boolean isChild(PowerSet potentialParent); List<PowerSet> getChildren(List<PowerSet> invalidParents); int size(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); Set<PowerSet> getOnPowerSet(int minOn); int sizeOn(); int getDiff(PowerSet child); }
PowerSet { public Set<PowerSet> getOnPowerSet(int minOn) { Set<PowerSet> sets = new HashSet<PowerSet>(); if (sizeOn() <= minOn) { return sets; } for (int p=0; p<set.length; p++){ if (set[p]){ PowerSet cs = new PowerSet(this); cs.switchOff(p); sets.add(cs); sets.addAll(cs.getOnPowerSet(minOn)); } } return sets; } PowerSet(int size);  PowerSet(boolean[] set);  PowerSet(PowerSet powerSet); void switchOn(int i); void switchOff(int i); boolean isOn(int i); boolean isOff(int i); boolean isChild(List<PowerSet> parents); boolean isChild(PowerSet potentialParent); List<PowerSet> getChildren(List<PowerSet> invalidParents); int size(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); Set<PowerSet> getOnPowerSet(int minOn); int sizeOn(); int getDiff(PowerSet child);  }