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

    Iterator<Malfunction> i = malfunctions.iterator();
    while (i.hasNext()) {
      Malfunction malfunction = i.next();
      if (malfunction.unitScopeMatch(scope)) {
        double malfunctionProbability = malfunction.getProbability() / 100D;
        MalfunctionConfig config = SimulationConfig.instance().getMalfunctionConfiguration();
        String[] partNames = config.getRepairPartNamesForMalfunction(malfunction.getName());
        for (String partName : partNames) {
          double partProbability =
              config.getRepairPartProbability(malfunction.getName(), partName) / 100D;
          int partNumber = config.getRepairPartNumber(malfunction.getName(), partName);
          double averageNumber = RandomUtil.getRandomRegressionIntegerAverageValue(partNumber);
          double totalNumber = averageNumber * partProbability * malfunctionProbability;
          Part part = (Part) ItemResource.findItemResource(partName);
          if (result.containsKey(part)) totalNumber += result.get(part);
          result.put(part, totalNumber);
        }
      }
    }

    return result;
  }
Exemple #2
0
  /**
   * Gets the value of the function for a named building.
   *
   * @param buildingName the building name.
   * @param newBuilding true if adding a new building.
   * @param settlement the settlement.
   * @return value (VP) of building function.
   * @throws Exception if error getting function value.
   */
  public static double getFunctionValue(
      String buildingName, boolean newBuilding, Settlement settlement) {

    // Settlements need enough dining capacity for all associated people.
    double demand = settlement.getAllAssociatedPeople().size();

    // Supply based on wear condition of buildings.
    double supply = 0D;
    Iterator<Building> i = settlement.getBuildingManager().getBuildings(FUNCTION).iterator();
    while (i.hasNext()) {
      Building diningBuilding = i.next();
      Dining dining = (Dining) diningBuilding.getFunction(FUNCTION);
      double capacity = dining.getDiningCapacity();
      double wearFactor =
          ((diningBuilding.getMalfunctionManager().getWearCondition() / 100D) * .75D) + .25D;
      supply += capacity * wearFactor;
    }

    if (!newBuilding) {
      BuildingConfig config = SimulationConfig.instance().getBuildingConfiguration();
      double capacity = config.getDiningCapacity(buildingName);
      supply -= capacity;
      if (supply < 0D) supply = 0D;
    }

    return demand / (supply + 1D);
  }
Exemple #3
0
  /**
   * Constructor.
   *
   * @param building the building this function is for.
   */
  public Dining(Building building) {
    // Use Function constructor.
    super(FUNCTION, building);

    // Populate data members.
    BuildingConfig config = SimulationConfig.instance().getBuildingConfiguration();
    capacity = config.getDiningCapacity(building.getName());

    // Load activity spots
    loadActivitySpots(config.getDiningActivitySpots(building.getName()));
  }
 @Override
 public void setUp() throws Exception {
   SimulationConfig.loadConfig();
 }
  /** Create the initial arriving settlements from the settlement configuration. */
  public static List<ArrivingSettlement> createInitialArrivingSettlements() {

    List<ArrivingSettlement> arrivingSettlements = new ArrayList<ArrivingSettlement>();

    MarsClock currentTime = Simulation.instance().getMasterClock().getMarsClock();

    SettlementConfig settlementConfig = SimulationConfig.instance().getSettlementConfiguration();
    int arrivingSettlementNum = settlementConfig.getNumberOfNewArrivingSettlements();
    for (int x = 0; x < arrivingSettlementNum; x++) {
      String name = settlementConfig.getNewArrivingSettlementName(x);
      if (name.equals(SettlementConfig.RANDOM)) {
        UnitManager unitManager = Simulation.instance().getUnitManager();
        name = unitManager.getNewName(UnitType.SETTLEMENT, null, null, null);
      }

      String template = settlementConfig.getNewArrivingSettlementTemplate(x);

      int population = settlementConfig.getNewArrivingSettlementPopulationNumber(x);
      int numOfRobots = settlementConfig.getNewArrivingSettlementNumOfRobots(x);
      // Determine arrival time.
      double arrivalTime = settlementConfig.getNewArrivingSettlementArrivalTime(x);
      MarsClock arrivalDate = (MarsClock) currentTime.clone();
      arrivalDate.addTime(arrivalTime * 1000D);

      // Get arriving settlement longitude
      double longitude = 0D;
      String longitudeStr = settlementConfig.getNewArrivingSettlementLongitude(x);
      if (longitudeStr.equals(SettlementConfig.RANDOM)) {
        longitude = Coordinates.getRandomLongitude();
      } else {
        longitude = Coordinates.parseLongitude(longitudeStr);
      }

      // Get arriving settlement latitude
      double latitude = 0D;
      String latitudeStr = settlementConfig.getNewArrivingSettlementLatitude(x);
      if (latitudeStr.equals(SettlementConfig.RANDOM)) {
        latitude = Coordinates.getRandomLatitude();
      } else {
        latitude = Coordinates.parseLatitude(latitudeStr);
      }

      Coordinates location = new Coordinates(latitude, longitude);

      // Create arriving settlement.
      ArrivingSettlement arrivingSettlement =
          new ArrivingSettlement(name, template, arrivalDate, location, population, numOfRobots);
      // 2015-01-17 Added scenarioID
      int scenarioID = settlementConfig.getNewArrivingSettlementScenarioID(x);
      arrivingSettlement.setScenarioID(scenarioID);

      // Determine launch date.
      MarsClock launchDate = (MarsClock) arrivalDate.clone();
      launchDate.addTime(-1D * AVG_TRANSIT_TIME * 1000D);
      arrivingSettlement.setLaunchDate(launchDate);

      // Set transit state based on launch and arrival time.
      TransitState transitState = TransitState.PLANNED;
      if (MarsClock.getTimeDiff(currentTime, launchDate) >= 0D) {
        transitState = TransitState.IN_TRANSIT;
        if (MarsClock.getTimeDiff(currentTime, arrivalDate) >= 0D) {
          transitState = TransitState.ARRIVED;
        }
      }
      arrivingSettlement.setTransitState(transitState);

      // Add arriving settlement to list.
      arrivingSettlements.add(arrivingSettlement);
    }

    return arrivingSettlements;
  }