@Override
 public MutatedInstanceMetaData<MultiMaskEfsmSkeleton, MultiMaskEfsmMutation> apply(
     MultiMaskEfsmSkeleton individual) {
   List<Step> transitions = getTransitions(individual);
   if (transitions.isEmpty()) {
     return new MutatedInstanceMetaData<MultiMaskEfsmSkeleton, MultiMaskEfsmMutation>(
         new MultiMaskEfsmSkeleton(individual), new MutationCollection<MultiMaskEfsmMutation>());
   }
   MyMap num = new MyMap();
   for (Step s : transitions) {
     num.put(s, 1);
   }
   for (VarsActionsScenario s : individual.getCounterExamples()) {
     getTrace(individual, s, num);
   }
   double sum = 0;
   for (Step s : transitions) {
     sum += num.get(s);
   }
   int i = 0;
   double cur = num.get(transitions.get(0)) / sum;
   ThreadLocalRandom random = ThreadLocalRandom.current();
   while (random.nextDouble() > cur) {
     i++;
     cur += num.get(transitions.get(i)) / sum;
   }
   Step s = transitions.get(i);
   MultiMaskEfsmSkeleton ind = new MultiMaskEfsmSkeleton(individual);
   int x = random.nextInt(MultiMaskEfsmSkeleton.STATE_COUNT);
   ind.getState(s.state).getTransitionGroup(s.event, s.group).setNewState(s.index, x);
   return new MutatedInstanceMetaData<MultiMaskEfsmSkeleton, MultiMaskEfsmMutation>(
       ind,
       new MutationCollection<MultiMaskEfsmMutation>(
           new DestinationStateMutation(s.state, s.event, s.group, s.index, x)));
 }
Example #2
0
  public static char getRandomCharAccordingToFrequency() {
    double dice = random.nextDouble(100);

    for (int i = 0; i < alphabetsFrequencies.length; i++) {
      if (dice < alphabetsFrequencies[i]) {
        return (char) ('a' + i);
      }
    }

    return 'z';
  }
Example #3
0
  public static String getRandomString(int numOfChars) {
    StringBuilder stringBuilder = new StringBuilder();
    boolean isSpace = true;
    boolean isDot = false;
    boolean isInSentence = false;
    boolean isComma = false;

    for (int i = 0; i < numOfChars; i++) {
      if (i >= numOfChars - 1) {
        stringBuilder.append('.');
        isDot = true;
        continue;
      }

      if (isSpace) {
        char temp = getRandomCharAccordingToFrequency();

        if (isInSentence) {
          stringBuilder.append(temp);
        } else {
          stringBuilder.append(Character.toUpperCase(temp));
          isInSentence = true;
        }

        isSpace = false;
        continue;
      }

      if (isDot) {
        stringBuilder.append(' ');
        isSpace = true;
        isDot = false;
        continue;
      }

      if (isComma) {
        stringBuilder.append(' ');
        isSpace = true;
        isComma = false;
        continue;
      }

      if (i >= numOfChars - 2) {
        isSpace = false;
      } else {
        isSpace = random.nextDouble(100) <= 17.1662;
      }

      if (isSpace) {
        stringBuilder.append(' ');
        continue;
      }

      if (i >= numOfChars - 3) {
        isDot = false;
      } else {
        isDot = random.nextDouble(100) <= 1.5124;
      }

      if (isDot) {
        stringBuilder.append('.');
        isInSentence = false;
        isDot = true;
        continue;
      }

      if (i >= numOfChars - 3) {
        isComma = false;
      } else {
        isComma = random.nextDouble(100) <= 0.7384;
      }

      if (isComma) {
        stringBuilder.append(',');
        continue;
      }

      stringBuilder.append(getRandomCharAccordingToFrequency());
    }

    return stringBuilder.toString();
  }
Example #4
0
  @Listener
  public void onDestructEntityEventDeath(
      DestructEntityEvent.Death event,
      @Getter("getTargetEntity") @Has(MoneyData.class) Living entity) {
    if (entity instanceof Player) {
      return;
    }

    if (entity.getType().equals(EntityTypes.ARMOR_STAND)
        || entity.getType().equals(EntityTypes.HUMAN)) {
      return;
    }

    WorldSettings settings = WorldSettings.get(entity.getWorld());

    if (settings.getDropsPerSecond().isAtDropLimit()) {
      return;
    }

    Optional<MobWallet> optionalWallet = settings.getMobWallet(entity);

    if (!optionalWallet.isPresent()) {
      return;
    }
    MobWallet wallet = optionalWallet.get();

    if (BigDecimal.valueOf(random.nextDouble()).compareTo(wallet.getFrequency()) >= 0) {
      return;
    }

    BigDecimal amount = wallet.getAmount(settings.getPrecision());

    if (amount.compareTo(BigDecimal.ZERO) == 0) {
      return;
    }

    WalletDropEvent walletDropEvent = new WalletDropEvent(amount, entity);

    if (settings.isDropsEnabled()) {
      Optional<Player> optionalPlayer = validPlayer(event.getCause());

      if (optionalPlayer.isPresent()) {
        Player player = optionalPlayer.get();

        if (player.gameMode().get().equals(GameModes.CREATIVE)
            && !settings.isCreativeModeAllowed()) {
          return;
        }

        if (settings.isUsePermissions()) {
          if (!player.hasPermission("walletdrop.enable")) {
            return;
          }
        }
      } else {
        if (settings.isKillOnlyDrops()) {
          return;
        }
      }

      if (!Sponge.getEventManager().post(walletDropEvent)) {
        settings.getDropsPerSecond().add();

        for (MoneyStack moneyStack : walletDropEvent.getMoneyStacks()) {
          moneyStack.drop(walletDropEvent.getLocation());
        }
      }
    } else {
      Optional<Player> optionalPlayer = validPlayer(event.getCause());

      if (!optionalPlayer.isPresent()) {
        return;
      }
      Player player = optionalPlayer.get();

      if (player.gameMode().get().equals(GameModes.CREATIVE) && !settings.isCreativeModeAllowed()) {
        return;
      }

      if (settings.isUsePermissions()) {
        if (!player.hasPermission("walletdrop.enable")) {
          return;
        }
      }

      if (!Sponge.getEventManager().post(walletDropEvent)) {
        settings.getDropsPerSecond().add();

        WalletDrop.depositOrWithdraw(player, walletDropEvent.getAmount());

        WalletDrop.sendPickupMessage(player, walletDropEvent.getAmount());
      }
    }
  }