Example #1
0
 @Override
 public String toString() {
   return "PowSt(I: "
       + minConsumption
       + " C: "
       + consumptionRange
       + " "
       + model.getClass().getName()
       + ")";
 }
  public double getPower(long tick, String type) {
    try {

      ConsumptionModel cm = null;
      if (type == "p") {
        cm = pcm;
      } else {
        cm = qcm;
      }
      double power = 0;
      // TODO
      if (isInUse()) {
        long relativeTick = Math.abs(tick - onTick);
        // If the device has a limited operational duration
        long divTick = relativeTick / cm.getTotalDuration();
        if (divTick >= cm.getOuterN() && cm.getOuterN() > 0) {
          power = 0;
        } else {
          int sum = 0;
          long moduloTick = relativeTick % cm.getTotalDuration();
          int index1 = -1;
          for (int i = 0; i < cm.getPatternN(); i++) {
            sum += (cm.getN(i) * cm.getPatternDuration(i));
            long whichPattern = moduloTick / sum;
            if (whichPattern == 0) {
              index1 = i;
              break;
            }
          }
          sum = 0;
          long moduloTick2 = moduloTick % cm.getPatternDuration(index1);
          int index2 = -1;
          for (int j = 0; j < cm.getPattern(index1).size(); j++) {
            sum += ((Tripplet) cm.getPattern(index1).get(j)).d;
            long whichPattern = moduloTick2 / sum;
            if (whichPattern == 0) {
              index2 = j;
              break;
            }
          }
          relativeTick++;
          power = ((Tripplet) cm.getPattern(index1).get(index2)).v;
        }
      } else {
        power = standByConsumption;
        //			power = 0;
      }
      return power;
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
  }
Example #3
0
 public double getCurrentPower(final double load) {
   if (load > 1.01 || load < -0.01) {
     throw new IllegalStateException("Received an out of range load evaluation request:" + load);
   }
   return model.evaluateConsumption(load);
 }