Example #1
0
  private List<Vector2D> makeBlobs(int centers, double clusterStd, double min, double max) {

    NormalDistribution dist = new NormalDistribution(random, 0.0, clusterStd, 1e-9);

    double range = max - min;
    Vector2D[] centerPoints = new Vector2D[centers];
    for (int i = 0; i < centers; i++) {
      centerPoints[i] =
          new Vector2D(random.nextDouble() * range + min, random.nextDouble() * range + min);
    }

    int[] nSamplesPerCenter = new int[centers];
    int count = samples / centers;
    Arrays.fill(nSamplesPerCenter, count);

    for (int i = 0; i < samples % centers; i++) {
      nSamplesPerCenter[i]++;
    }

    List<Vector2D> points = new ArrayList<>();
    for (int i = 0; i < centers; i++) {
      for (int j = 0; j < nSamplesPerCenter[i]; j++) {
        points.add(new Vector2D(dist.sample(), dist.sample()).add(centerPoints[i]));
      }
    }
    return points;
  }
  // ======== per-timeslot activities ========
  @Override
  public void step() {
    // check for end-of-shift
    Shift newShift = shiftSchedule[indexOfShift(getNowInstant())];
    if (newShift != currentShift) {
      log.info(getName() + " start of shift");
      // Take all batteries out of service
      double totalEnergy = getEnergyCharging() + getEnergyInUse();
      setEnergyCharging(getEnergyCharging() + getEnergyInUse());
      setCapacityInUse(0.0);
      setEnergyInUse(0.0);

      // Put the strongest batteries in trucks for the next shift
      if (null != newShift) {
        setCapacityInUse(newShift.getTrucks() * batteryCapacity);
        setEnergyInUse(Math.min(getCapacityInUse(), totalEnergy));
        setEnergyCharging(totalEnergy - getEnergyInUse());
      }
      log.info(
          getName()
              + ": new shift cInUse "
              + capacityInUse
              + ", eInUse "
              + energyInUse
              + ", eCharging "
              + energyCharging);
      currentShift = newShift;
    }

    // discharge batteries on active trucks
    if (null != currentShift) {
      double usage = Math.max(0.0, normal.sample() * truckStd + truckKW * currentShift.getTrucks());
      double deficit = usage - getEnergyInUse();
      log.debug(getName() + ": trucks use " + usage + " kWh");
      if (deficit > 0.0) {
        log.warn(getName() + ": trucks use more energy than available by " + deficit + " kWh");
        addEnergyInUse(deficit);
        addEnergyCharging(-deficit);
      }
      addEnergyInUse(-usage);
    }

    // use energy on chargers, accounting for regulation
    double regulation = getSubscription().getRegulation();
    log.info(getName() + ": regulation " + regulation);
    double energyUsed = useEnergy(regulation);

    // Record energy used
    getSubscription().usePower(energyUsed);
    log.info(
        getName()
            + " cInUse "
            + capacityInUse
            + ", eInUse "
            + energyInUse
            + ", eCharging "
            + energyCharging);
  }
    private static SparseRealMatrix initializeMatrix(SparseRealMatrix matrix, double sigma) {
      NormalDistribution normRandom = new NormalDistribution(0.0, sigma);
      int r = matrix.getRowDimension();
      int c = matrix.getColumnDimension();

      for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
          double x = normRandom.sample();
          matrix.setEntry(i, j, x);
        }
      }
      return matrix;
    }
Example #4
0
 private Vector2D generateNoiseVector(NormalDistribution distribution) {
   return new Vector2D(distribution.sample(), distribution.sample());
 }