Java Code Examples for java.util.BitSet#intersects()

The following examples show how to use java.util.BitSet#intersects() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LeftHandSideGenerator.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private List<BitSet> findLHS(Set<BitSet> Li, CMAX_SET correctSet) {

        List<BitSet> lhs_i = new LinkedList<BitSet>();
        for (BitSet l : Li) {
            boolean isLHS = true;
            for (BitSet x : correctSet.getCombinations()) {
                if (!l.intersects(x)) {
                    isLHS = false;
                    break;
                }
            }
            if (isLHS) {
                lhs_i.add(l);
            }
        }
        return lhs_i;
    }
 
Example 2
Source File: MaxHolesFlexibleConstraint.java    From cpsolver with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void weaken(Assignment<Lecture, Placement> assignment, Placement value) {
    if (!isHard()) return;
    for (int dayCode : Constants.DAY_CODES) {
        if ((value.getTimeLocation().getDayCode() & dayCode) == 0) continue; // ignore other days
        for (BitSet week : getWeeks()) {
            if (week != null && !week.intersects(value.getTimeLocation().getWeekCode())) continue; // ignore other weeks
            int penalty = countHoles(assignment, dayCode, null, value, null, week);
            if (penalty > iMaxHolesOnADay) {
                Map<BitSet, Integer> holes = iMaxHoles.get(dayCode);
                if (holes == null) {
                    holes = new HashMap<BitSet, Integer>();
                    iMaxHoles.put(dayCode, holes);
                }
                Integer oldPenalty = holes.get(week);
                if (oldPenalty != null && oldPenalty >= penalty) continue;
                holes.put(week, penalty);
            }
        }
    }
}
 
Example 3
Source File: FindCoversGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private boolean covers(BitSet obs, List<DifferenceSet> originalDiffSet) {

        for (DifferenceSet diff : originalDiffSet) {

        	if (!obs.intersects(diff.getAttributes())) {
                return false;
            }
        }

        return true;
    }
 
Example 4
Source File: IdentifierInfo.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private boolean containsWithAlternates(BitSet container, BitSet containee) {
    if (!contains(container, containee)) {
        return false;
    }
    for (BitSet alternatives : scriptSetSet) {
        if (!container.intersects(alternatives)) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: MaxHolesFlexibleConstraint.java    From cpsolver with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void computeConflicts(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
    if (!isHard()) return;
    
    MaxHolesFlexibleConstraintContext context = (MaxHolesFlexibleConstraintContext)getContext(assignment);
    
    // constraint is checked for every day in week
    for (int dayCode : Constants.DAY_CODES) {
        if ((value.getTimeLocation().getDayCode() & dayCode) == 0) continue; // ignore other days
        // constraint is checked for every week in semester (or for the whole semester)
        for (BitSet week : getWeeks()) {
            if (week != null && !week.intersects(value.getTimeLocation().getWeekCode())) continue; // ignore other weeks
            // check penalty
            int penalty = countHoles(assignment, dayCode, conflicts, value, null, week);
            while (penalty > context.getMaxHoles(dayCode, week)) {
                // too many holes -> identify adepts for unassignment
                List<Placement> adepts = new ArrayList<Placement>();
                for (Placement placement: getRelevantPlacements(assignment, dayCode, conflicts, value, null, week)) {
                    if (placement.equals(value)) continue; // skip given value
                    // check if removing placement would improve the penalty
                    HashMap<Lecture, Placement> assignments = new HashMap<Lecture, Placement>(); assignments.put(placement.variable(), null);
                    int newPenalty = countHoles(assignment, dayCode, conflicts, value, assignments, week);
                    if (newPenalty <= penalty)
                        adepts.add(placement);
                }
                
                // no adepts -> fail
                if (adepts.isEmpty()) {
                    conflicts.add(value); return;
                }
                
                // pick one randomly
                conflicts.add(ToolBox.random(adepts));
                penalty = countHoles(assignment, dayCode, conflicts, value, null, week);
            }
        }
    }
}
 
Example 6
Source File: RegionMaker.java    From jadx with Apache License 2.0 5 votes vote down vote up
@Nullable
private BlockNode searchFallThroughCase(BlockNode successor, BlockNode out, BitSet caseBlocks) {
	BitSet df = successor.getDomFrontier();
	if (df.intersects(caseBlocks)) {
		return getOneIntersectionBlock(out, caseBlocks, df);
	}
	Set<BlockNode> allPathsBlocks = BlockUtils.getAllPathsBlocks(successor, out);
	Map<BlockNode, BitSet> bitSetMap = BlockUtils.calcPartialPostDominance(mth, allPathsBlocks, out);
	BitSet pdoms = bitSetMap.get(successor);
	if (pdoms != null && pdoms.intersects(caseBlocks)) {
		return getOneIntersectionBlock(out, caseBlocks, pdoms);
	}
	return null;
}
 
Example 7
Source File: DagAwareYarnTaskScheduler.java    From tez with Apache License 2.0 4 votes vote down vote up
@GuardedBy("this")
@Nullable
private Collection<ContainerId> maybePreempt(Resource freeResources) {
  if (preemptionPercentage == 0 || numHeartbeats - lastPreemptionHeartbeat < numHeartbeatsBetweenPreemptions) {
    return null;
  }
  if (!requestTracker.isPreemptionDeadlineExpired() && requestTracker.fitsHighestPriorityRequest(freeResources)) {
    if (numHeartbeats % 50 == 1) {
      LOG.info("Highest priority request fits in free resources {}", freeResources);
    }
    return null;
  }

  int numIdleContainers = idleTracker.getNumContainers();
  if (numIdleContainers > 0) {
    if (numHeartbeats % 50 == 1) {
      LOG.info("Avoiding preemption since there are {} idle containers", numIdleContainers);
    }
    return null;
  }

  BitSet blocked = requestTracker.createVertexBlockedSet();
  if (!blocked.intersects(assignedVertices)) {
    if (numHeartbeats % 50 == 1) {
      LOG.info("Avoiding preemption since there are no descendants of the highest priority requests running");
    }
    return null;
  }

  Resource preemptLeft = requestTracker.getAmountToPreempt(preemptionPercentage);
  if (!resourceCalculator.anyAvailable(preemptLeft)) {
    if (numHeartbeats % 50 == 1) {
      LOG.info("Avoiding preemption since amount to preempt is {}", preemptLeft);
    }
    return null;
  }

  PriorityQueue<HeldContainer> candidates = new PriorityQueue<>(11, PREEMPT_ORDER_COMPARATOR);
  blocked.and(assignedVertices);
  for (int i = blocked.nextSetBit(0); i >= 0; i = blocked.nextSetBit(i + 1)) {
    Collection<HeldContainer> containers = vertexAssignments.get(i);
    if (containers != null) {
      candidates.addAll(containers);
    } else {
      LOG.error("Vertex {} in assignedVertices but no assignments?", i);
    }
  }

  ArrayList<ContainerId> preemptedContainers = new ArrayList<>();
  HeldContainer hc;
  while ((hc = candidates.poll()) != null) {
    LOG.info("Preempting container {} currently allocated to task {}", hc.getId(), hc.getAssignedTask());
    preemptedContainers.add(hc.getId());
    resourceCalculator.deductFrom(preemptLeft, hc.getCapability());
    if (!resourceCalculator.anyAvailable(preemptLeft)) {
      break;
    }
  }

  return preemptedContainers;
}