public static void main(String[] args) throws Exception {
    if (args.length == 2) {
      int a, b;
      a = Integer.parseInt(args[0]);
      b = Integer.parseInt(args[1]);
      int x = UnifRandom(a, b);
      assert (a <= x && x <= b);
    } else {
      Supplier<CloneableInputsMap> formInputs =
          () -> {
            Random rgen = new Random();
            int a = rgen.nextInt(100);
            int b = rgen.nextInt(100) + a + 1;
            CloneableInputsMap inputs = new CloneableInputsMap();
            inputs.addInteger("a", a);
            inputs.addInteger("b", b);
            return inputs;
          };
      Function<CloneableInputsMap, Integer> runAlg =
          (inputs) -> UnifRandom(inputs.getInteger("a"), inputs.getInteger("b"));
      BiFunction<Integer, CloneableInputsMap, Boolean> checkResults =
          (observed, extra) ->
              extra.getInteger("a") <= observed && observed <= extra.getInteger("b");

      AlgVerifierInterfaces<Integer, CloneableInputsMap> algVerifier =
          new InputOutputVerifier<>(checkResults);
      AlgorithmFactory algorithmFactory =
          new AlgorithmRunnerAndVerifier<>(
              "UnifRandomNumberGenerator", NUM_TESTS, formInputs, runAlg, algVerifier);
      algorithmFactory.run();
    }
  }
  public static void main(String[] args) throws Exception {
    Supplier<CloneableInputsMap> formInputs =
        () -> {
          CloneableInputsMap inputs = new CloneableInputsMap();
          Random rgen = new Random();
          char[] s = new char[(ARR_LEN << 1) + 1];
          MiscHelperMethods.randCharArray(() -> (char) ('a' + rgen.nextInt(26)), ARR_LEN, s);
          inputs.addCharArray("s", s);
          inputs.addInteger("len", ARR_LEN);
          return inputs;
        };
    Function<CloneableInputsMap, Integer> runAlg =
        (inputs) -> replaceAndRemove(inputs.getCharArray("s"), inputs.getInteger("len"));

    Function<CloneableInputsMap, Integer> knownOutput =
        (inputs) -> {
          String expected = knownOutput(inputs.getCharArray("s"), inputs.getInteger("len"));
          inputs.addCharArray("s", expected.toCharArray());
          return expected.length();
        };

    Function<CloneableInputsMap, CloneableInputsMap> saveExtraResults =
        (inputs) -> {
          CloneableInputsMap extraResults = new CloneableInputsMap();
          extraResults.addCharArray("s", inputs.getCharArray("s"));
          return extraResults;
        };
    AlgVerifierInterfaces.QuadFunction<
            Integer, Integer, CloneableInputsMap, CloneableInputsMap, Boolean>
        checkAns =
            (observed, expected, algExtraResults, expExtraResults) ->
                observed.equals(expected)
                    && algExtraResults.getCharArray("s").length >= observed
                    && expExtraResults.getCharArray("s").length >= observed
                    && String.valueOf(algExtraResults.getCharArray("s"))
                        .substring(0, observed)
                        .equals(
                            String.valueOf(expExtraResults.getCharArray("s"))
                                .substring(0, observed));

    AlgVerifierInterfaces<Integer, CloneableInputsMap> algVerifier =
        new OutputOutputExtraExtraVerifier<>(checkAns);
    AlgorithmFactory algorithmFactory =
        new AlgorithmRunnerAndVerifier<>(
            "Replace and Remove",
            NUM_TESTS,
            formInputs,
            runAlg,
            knownOutput,
            saveExtraResults,
            algVerifier);

    System.out.println(
        String.format("Running algorithms on character arrays of length %d...", ARR_LEN));
    //    algorithmFactory.setSequential();
    algorithmFactory.run();
  }
 public static void main(String[] args) {
   Algorithm algorithm =
       AlgorithmFactory.getAlgorithm(AlgorithmFactory.AlgorithmType.SHORTEST_PATH);
   if (algorithm != null) {
     algorithm.solveProblem();
   }
   algorithm = AlgorithmFactory.getAlgorithm(AlgorithmFactory.AlgorithmType.SPANNING_TREE);
   if (algorithm != null) {
     algorithm.solveProblem();
   }
 }
Exemple #4
0
  /**
   * Creates a new Chopper.
   *
   * @param alg The algorithm to use.
   * @param graph The graph to slice.
   */
  public BarrierChopper(String className, Graph g) {

    // load the demanded algorithm
    Object o = AlgorithmFactory.loadClass(className, g);
    chopper = (edu.kit.joana.ifc.sdg.graph.chopper.barrier.BarrierChopper) o;

    // initialize the sourceCriteria and sinkCriteria and barrier sets
    sourceCriteria = new TreeSet<SDGNode>(SDGNode.getIDComparator());
    sinkCriteria = new TreeSet<SDGNode>(SDGNode.getIDComparator());
    barrier = new TreeSet<SDGNode>(SDGNode.getIDComparator());
  }
Exemple #5
0
  /**
   * Get the base probe for configuration. It should never be run! Instead use makeProbe() to make a
   * copy which you can run.
   *
   * @return the base probe generating it if necessary or null if one cannot be generated (e.g. no
   *     selected sequence)
   */
  Probe<?> getBaseProbe() {
    // if there is no base probe and the sequence is not null then generate a new base probe for the
    // sequence
    if (_baseProbe == null && _sequence != null) {
      try {
        if (_sequence instanceof Ring) {
          final TransferMapTracker tracker = AlgorithmFactory.createTransferMapTracker(_sequence);
          _baseProbe = ProbeFactory.getTransferMapProbe(_sequence, tracker);

        } else {
          final ParticleTracker tracker = AlgorithmFactory.createParticleTracker(_sequence);
          _baseProbe = ProbeFactory.createParticleProbe(_sequence, tracker);
        }
      } catch (Exception exception) {
        throw new RuntimeException("Exception making a new probe.", exception);
      }
    }

    return _baseProbe;
  }
  /**
   * Gets the registered algorithmes.
   *
   * @return collection of algorithms registered
   */
  public static Collection<LayoutToolAlgorithms> getRegisteredAlgorithmes() {
    IConfigurationElement[] elements =
        Platform.getExtensionRegistry()
            .getConfigurationElementsFor(Constants.EXTENSION_POINT_ID_ALGORITHMS);
    LinkedList<LayoutToolAlgorithms> algo = new LinkedList<LayoutToolAlgorithms>();
    for (IConfigurationElement e : elements) {
      try {
        LayoutToolAlgorithms algorithm = new LayoutToolAlgorithms();
        AlgorithmFactory factory =
            (AlgorithmFactory) e.createExecutableExtension(Constants.EXTENSION_CLASS_ALGORITHMS);
        algorithm.setAlgorithm(factory.createAlgorithm());
        if (e.getAttribute(Constants.EXTENSION_NAME) != null) {
          String name = e.getAttribute(Constants.EXTENSION_NAME);
          name = format(name);
          algorithm.setName(name);
        }
        if (e.getAttribute(Constants.EXTENSION_ICON) != null) {
          algorithm.setIcon(getIcon(e, e.getAttribute(Constants.EXTENSION_ICON)));
        }
        if (e.getAttribute(Constants.EXTENSION_TOOLTIP) != null) {
          algorithm.setToolTipText(e.getAttribute(Constants.EXTENSION_TOOLTIP));
        }
        if (e.getAttribute(Constants.EXTENSION_PATH) != null) {
          algorithm.setPath(e.getAttribute(Constants.EXTENSION_PATH));
        }
        algo.add(algorithm);
      } catch (CoreException e1) {
        e1.printStackTrace();
      }
      if (!algo.isEmpty()) {
        Collections.sort(
            algo,
            new Comparator<LayoutToolAlgorithms>() {

              public int compare(LayoutToolAlgorithms arg0, LayoutToolAlgorithms arg1) {
                int length0 = 0;
                if (arg0.getPath() != null) {
                  String[] pathSplit0 = arg0.getPath().split("\\.");
                  length0 = pathSplit0.length;
                }
                int length1 = 0;
                if (arg1.getPath() != null) {
                  String[] pathSplit1 = arg1.getPath().split("\\.");
                  length1 = pathSplit1.length;
                }
                if (length1 == length0) {
                  String a = arg0.getPath() + arg0.getName();
                  String b = arg1.getPath() + arg1.getName();
                  if (a == null) {
                    a = "";
                  }
                  if (b == null) {
                    b = "";
                  }
                  return a.compareTo(b);
                }
                return length1 - length0;
              }
            });
      }
    }
    return algo;
  }
 @Test
 public void createDepthFirstPathCounterMaximumStops() {
   MatcherAssert.assertThat(
       algorithmFactory.createCountPathsWithAtLeastAGivenNumberOfStops(A, B, 5),
       isA(CountPathsWithAtLeastAGivenNumberOfStops.class));
 }
 @Test
 public void createDepthFirstPathCounterExactStops() {
   MatcherAssert.assertThat(
       algorithmFactory.createCountPathsWithNumberOfStops(A, B, 5),
       isA(CountPathsWithNumberOfStops.class));
 }
 @Test
 public void createCycleCountAlgorithm() {
   MatcherAssert.assertThat(algorithmFactory.createCycleCountAlgorithm(), isA(CycleCount.class));
 }
 @Test
 public void createShortestPathAlgorithm() {
   MatcherAssert.assertThat(
       algorithmFactory.createShortestPathAlgorithm(A, B), isA(ShortestPath.class));
 }