コード例 #1
0
 public boolean equals(Object o) {
   // A direct implementation (instead of EqualsBuilder) to avoid dependencies
   if (this == o) {
     return true;
   } else if (o instanceof HardSoftScore) {
     HardSoftScore other = (HardSoftScore) o;
     return hardScore == other.getHardScore() && softScore == other.getSoftScore();
   } else {
     return false;
   }
 }
  @Override
  public HardSoftScore calculateScore(CloudBalance cloudBalance, int initScore) {
    int computerListSize = cloudBalance.getComputerList().size();
    Map<CloudComputer, Integer> cpuPowerUsageMap = new HashMap<>(computerListSize);
    Map<CloudComputer, Integer> memoryUsageMap = new HashMap<>(computerListSize);
    Map<CloudComputer, Integer> networkBandwidthUsageMap = new HashMap<>(computerListSize);
    for (CloudComputer computer : cloudBalance.getComputerList()) {
      cpuPowerUsageMap.put(computer, 0);
      memoryUsageMap.put(computer, 0);
      networkBandwidthUsageMap.put(computer, 0);
    }
    Set<CloudComputer> usedComputerSet = new HashSet<>(computerListSize);

    visitProcessList(
        cpuPowerUsageMap,
        memoryUsageMap,
        networkBandwidthUsageMap,
        usedComputerSet,
        cloudBalance.getProcessList());

    int hardScore = sumHardScore(cpuPowerUsageMap, memoryUsageMap, networkBandwidthUsageMap);
    int softScore = sumSoftScore(usedComputerSet);

    return HardSoftScore.valueOf(initScore, hardScore, softScore);
  }
コード例 #3
0
  public void addConstraintMatch(boolean constraintMatchEnabled) {
    HardSoftScoreHolder scoreHolder = new HardSoftScoreHolder(constraintMatchEnabled);

    scoreHolder.addHardConstraintMatch(mockRuleContext("scoreRule1"), -1000);

    RuleContext ruleContext2 = mockRuleContext("scoreRule2");
    scoreHolder.addHardConstraintMatch(ruleContext2, -200);
    callUnMatch(ruleContext2);

    RuleContext ruleContext3 = mockRuleContext("scoreRule3");
    scoreHolder.addSoftConstraintMatch(ruleContext3, -30);
    scoreHolder.addSoftConstraintMatch(ruleContext3, -3); // Overwrite existing
    scoreHolder.addHardConstraintMatch(ruleContext3, -300); // Different score level
    scoreHolder.addHardConstraintMatch(ruleContext3, -400); // Overwrite existing

    RuleContext ruleContext4 = mockRuleContext("scoreRule4");
    scoreHolder.addHardConstraintMatch(ruleContext4, -1);
    scoreHolder.addSoftConstraintMatch(ruleContext4, -1);
    callUnMatch(ruleContext4);

    assertEquals(HardSoftScore.valueOf(-1400, -3), scoreHolder.extractScore());
    if (constraintMatchEnabled) {
      assertEquals(6, scoreHolder.getConstraintMatchTotals().size());
    }
  }
コード例 #4
0
 public int compareTo(HardSoftScore other) {
   // A direct implementation (instead of CompareToBuilder) to avoid dependencies
   if (hardScore != other.getHardScore()) {
     if (hardScore < other.getHardScore()) {
       return -1;
     } else {
       return 1;
     }
   } else {
     if (softScore < other.getSoftScore()) {
       return -1;
     } else if (softScore > other.getSoftScore()) {
       return 1;
     } else {
       return 0;
     }
   }
 }
コード例 #5
0
 public HardSoftScore calculateScore() {
   return HardSoftScore.valueOf(hardScore, softScore);
 }
コード例 #6
0
 public HardSoftScore subtract(HardSoftScore subtrahend) {
   return new HardSoftScore(
       hardScore - subtrahend.getHardScore(), softScore - subtrahend.getSoftScore());
 }
コード例 #7
0
 public HardSoftScore add(HardSoftScore augment) {
   return new HardSoftScore(
       hardScore + augment.getHardScore(), softScore + augment.getSoftScore());
 }