if ((proposeVariant.getPredictedCostPerTimeUnit() <= resourcePercentageRemaining) &&
if ((proposedVariant.getPredictedCostPerTimeUnit() <= resourcePercentageRemaining) &&
  private void selectActions(CostBenefitEvaluation cbe, ActionSelectionKnob knob) {    rankAvailableActions(cbe, knob);        Iterator iter;    boolean done = false;    double resourcePercentageRemaining = getCurrentEnclaveResources();    Set alreadyActiveActions = findActiveActions(cbe);    /* assume for now that all Compensatory actionss are revokable - so there is no sunk cost    // deduct the cost of actions that we can't terminate    iter = alreadyActiveActions.iterator();    while (iter.hasNext()) {        Action thisAction = (Action)iter.next();        double thisCost = getCostForAction(thisAction);        resourcePercentageRemaining = resourcePercentageRemaining - thisCost;    }    */    Set alreadySelectedVariants = new HashSet();    iter = cbe.getOrderedEvaluations().iterator();    if (logger.isInfoEnabled()) logger.info(cbe.dumpAvailableVariants());    while (iter.hasNext()) {        ActionEvaluation thisActionEvaluation = (ActionEvaluation) iter.next();        Action thisAction = thisActionEvaluation.getAction();        Set permittedVariants = new HashSet();          Iterator iter3 = thisActionEvaluation.getOrderedAvaliableVariants().iterator();        boolean pickedSomeVariant = false;        while (iter3.hasNext() && !pickedSomeVariant) {            VariantEvaluation proposedVariant = (VariantEvaluation)iter3.next();            if (logger.isDebugEnabled()) logger.debug("Considering conflict for Action: " +thisActionEvaluation.getAction().getClass().getName() + "Variant: " + proposedVariant.toString());            if (logger.isDebugEnabled()) logger.debug(proposedVariant + " doesNotConflict: " + thisActionEvaluation.doesNotConflict(proposedVariant, alreadyActiveActions, alreadySelectedVariants));            if (thisActionEvaluation.doesNotConflict(proposedVariant, alreadyActiveActions, alreadySelectedVariants)) {                if ((proposeVariant.getPredictedCostPerTimeUnit() <= resourcePercentageRemaining) &&                        (proposedVariant.getPredictedBenefit() > 0.0) || (thisActionEvaluation.mustSelectOne())) {                    pickedSomeVariant = true;                    alreadySelectedVariants.add(proposedVariant);                    proposedVariant.setChosen();                    resourcePercentageRemaining = resourcePercentageRemaining - proposedVariant.getPredictedCostPerTimeUnit();                    if (logger.isInfoEnabled()) logger.info("Selected: " + proposedVariant.toString() + "for: " + thisAction.getAssetID().toString() + ", % resources left " + resourcePercentageRemainaining);                    if (eventService.isEventEnabled()) eventService.event(agentId + " selected " + thisAction.getClass().getName() + ":" + proposedVariant + " for " + thisAction.getAssetID().toString());                    if ((!thisAction.getPermittedValues().contains(proposedVariant.getVariantName()))                            && (thisAction.getValue() == null                                  || !thisAction.getValue().getAction().equals(proposedVariant.getVariantName())                                || !thisAction.getValue().isActive())) {                        permittedVariants.add(proposedVariant);                        publishAdd(new SelectedAction(thisAction, permittedVariants, Math.round(knob.getPatienceFactor()*proposedVariant.getExpectedTransitionTime()), cbe));                        if (logger.isInfoEnabled()) logger.info("Enabling: " + proposedVariant.toString() + "for: " + thisAction.getAssetID().toString());                    }                    // special code to activate/deactivate RMIAction in tandem with SecurityDefenseAction - a special case for ACUC #2B                    if (thisAction.getClass().getName().equals("org.cougaar.core.security.coordinator.Security_Defense_Setting")) {                        Action rmiAction = findAction(thisAction.getAssetID(), "org.cougaar.robustness.dos.coordinator.RMIAction").getAction();                        if (proposedVariant.getVariantName().equals("High")) {                            String rmiVariantName = "Disabled";                            VariantEvaluation rmiVariant = getRmiVariantEvaluation(cbe, rmiAction, rmiVariantName);                            if (rmiVariant != null && rmiAction != null && rmiAction.getValuesOffered().contains(rmiVariantName)) {                                if (logger.isInfoEnabled()) logger.info("Selected: " + rmiVariant.toString() + "for: " + rmiAction.getAssetID().toString());                                if (eventService.isEventEnabled()) eventService.event(agentId + " selected " + rmiAction.getClass().getName() + ":" + rmiVariant.getVariantName() + " for " + rmiAction.getAssetID());                                Set rmiPermittedVariants = new HashSet();                                  if ((!rmiAction.getPermittedValues().contains(rmiVariant.getVariantName()))                                        && (thisAction.getValue() == null                                              || !thisAction.getValue().getAction().equals(proposedVariant.getVariantName())                                            || !thisAction.getValue().isActive())) {                                    permittedVariants.add(proposedVariant);                                    publishAdd(new SelectedAction(thisAction, permittedVariants, Math.round(knob.getPatienceFactor()*proposedVariant.getExpectedTransitionTime()), cbe));                                    if (logger.isInfoEnabled()) logger.info("Enabling: " + proposedVariant.toString() + "for: " + thisAction.getAssetID().toString());                                }                             }                             else if (eventService.isEventEnabled()) eventService.event(rmiVariantName + " was not offered");                        }                        if(proposedVariant.getVariantName().equals("Low")) {                            String rmiVariantName = "Enabled";                            VariantEvaluation rmiVariant = getRmiVariantEvaluation(cbe, rmiAction, rmiVariantName);                            if (rmiVariant != null && rmiAction != null && rmiAction.getValuesOffered().contains(rmiVariantName)) {                                if (logger.isInfoEnabled()) logger.info("Selected: " + rmiVariant.toString() + "for: " + rmiAction.getAssetID().toString());                                if (eventService.isEventEnabled()) eventService.event(agentId + " selected " + rmiAction.getClass().getName() + ":" + rmiVariant.getVariantName() + " for " + rmiAction.getAssetID().toString());                                Set rmiPermittedVariants = new HashSet();                                  if ((!rmiAction.getPermittedValues().contains(rmiVariant.getVariantName()))                                        && (thisAction.getValue() == null                                              || !thisAction.getValue().getAction().equals(proposedVariant.getVariantName())                                            || !thisAction.getValue().isActive())) {                                    permittedVariants.add(proposedVariant);                                    publishAdd(new SelectedAction(thisAction, permittedVariants, Math.round(knob.getPatienceFactor()*proposedVariant.getExpectedTransitionTime()), cbe));                                    if (logger.isInfoEnabled()) logger.info("Enabling: " + proposedVariant.toString() + "for: " + thisAction.getAssetID().toString());                                }                             }                             else if (eventService.isEventEnabled()) eventService.event(rmiVariantName + " was not offered");                        }                    }                                    }            }        }    }    if (alreadySelectedVariants.isEmpty()) { // could not find anything useful to do        if (logger.isInfoEnabled()) logger.info("Done processing: " + cbe.dumpAvailableVariants());        publishRemove(cbe);    }  }