Example #1
0
  /**
   * Gets the probabilities of parts per maintenance for a set of entity scope strings.
   *
   * @param scope a collection of entity scope strings.
   * @return map of maintenance parts and probable number of parts needed per maintenance.
   * @throws Exception if error finding maintenance part probabilities.
   */
  Map<Part, Double> getMaintenancePartProbabilities(Collection<String> scope) {
    Map<Part, Double> result = new HashMap<Part, Double>();

    Iterator<String> i = scope.iterator();
    while (i.hasNext()) {
      String entity = i.next();
      Iterator<Part> j = Part.getParts().iterator();
      while (j.hasNext()) {
        Part part = j.next();
        if (part.hasMaintenanceEntity(entity)) {
          double prob = part.getMaintenanceProbability(entity) / 100D;
          int partNumber = part.getMaintenanceMaximumNumber(entity);
          double averageNumber = RandomUtil.getRandomRegressionIntegerAverageValue(partNumber);
          double totalNumber = averageNumber * prob;
          if (result.containsKey(part)) totalNumber += result.get(part);
          result.put(part, totalNumber);
        }
      }
    }

    return result;
  }
Example #2
0
  /**
   * Gets the total mass of construction materials.
   *
   * @param resources map of resources and their amounts (kg).
   * @param parts map of parts and their numbers.
   * @return total mass.
   */
  private double getConstructionMaterialMass(
      Map<AmountResource, Double> resources, Map<Part, Integer> parts) {

    double result = 0D;

    // Add total mass of resources.
    Iterator<AmountResource> i = resources.keySet().iterator();
    while (i.hasNext()) {
      AmountResource resource = i.next();
      double amount = resources.get(resource);
      result += amount;
    }

    // Add total mass of parts.
    Iterator<Part> j = parts.keySet().iterator();
    while (j.hasNext()) {
      Part part = j.next();
      int number = parts.get(part);
      double mass = part.getMassPerItem();
      result += number * mass;
    }

    return result;
  }