package ru.ifmo.nds.jmh.main;

import java.util.*;

import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import ru.ifmo.nds.IdCollection;
import ru.ifmo.nds.jmh.UniformCorrelated;
import ru.ifmo.nds.jmh.UniformHypercube;
import ru.ifmo.nds.jmh.UniformHyperplanes;

public class Minimal {
    private static final List<String> minimalN = Arrays.asList("10", "100", "1000");
    private static final List<String> minimalD = Arrays.asList("2", "3", "5", "10");
    private static final List<String> minimalF = Arrays.asList("1", "2", "n/2", "n");

    private static final List<String> moreMinimalN = Arrays.asList("3", "31", "316", "3162", "10000");
    private static final List<String> moreMinimalD = Arrays.asList("4", "6", "7", "8", "9", "11", "12", "13", "14", "15");

    public static void main(String[] args) throws RunnerException {
        Set<String> allSortings = IdCollection.getAllNonDominatedSortingIDs();

        final String[] stub = new String[0];

        List<String> n = new ArrayList<>();
        List<String> d = new ArrayList<>();
        List<String> f = new ArrayList<>(minimalF);

        String outputFile = "jmh-output.json";

        boolean failed = false;
        boolean useGiven = false;

        for (String s : args) {
            if (s.startsWith("--out=")) {
                outputFile = s.substring("--out=".length());
            } else if (s.startsWith("--use=")) {
                if (useGiven) {
                    failed = true;
                    System.err.println("Error: multiple --use directives given");
                } else {
                    useGiven = true;
                    String cmd = s.substring("--use=".length());
                    switch (cmd) {
                        case "min":
                            n.addAll(minimalN);
                            d.addAll(minimalD);
                            break;
                        case "more-d":
                            n.addAll(minimalN);
                            d.addAll(moreMinimalD);
                            break;
                        case "more-n":
                            n.addAll(moreMinimalN);
                            d.addAll(minimalD);
                            d.addAll(moreMinimalD);
                            d.sort(Comparator.comparingInt(Integer::parseInt));
                            break;
                        default:
                            System.err.println("Error: unknown option to --use: '" + cmd + "'");
                    }
                }
            } else {
                failed = true;
                System.err.println("Error: unknown command '" + s + "'");
            }
        }

        failed |= n.isEmpty();

        if (failed) {
            System.err.println("Usage: Minimal --use=<min|more-d|more-n> [--out=<file>]");
            System.exit(1);
        }

        Options options = new OptionsBuilder()
                .include(UniformHypercube.class.getName())
                .include(UniformHyperplanes.class.getName())
                .include(UniformCorrelated.class.getName())
                .param("algorithmId", allSortings.toArray(stub))
                .param("n", n.toArray(stub))
                .param("d", d.toArray(stub))
                .param("f", f.toArray(stub))
                .resultFormat(ResultFormatType.JSON)
                .result(outputFile)
                .build();
        new Runner(options).run();
    }
}

@@ -1046,23 +1046,25 @@
 ing%3E all
-Sorting
+Algorithm
 s = IdCo
@@ -1103,16 +1103,79 @@
 ngIDs();
+%0A        Set%3CString%3E algorithms = new TreeSet%3C%3E(allAlgorithms);
 %0A%0A      
@@ -2774,32 +2774,659 @@
               %7D%0A
+            %7D else if (s.startsWith(%22--algo=%22)) %7B%0A                StringTokenizer st = new StringTokenizer(s.substring(%22--algo=%22.length()), %22,%22);%0A                algorithms.clear();%0A                while (st.hasMoreTokens()) %7B%0A                    String token = st.nextToken();%0A                    if (!allAlgorithms.contains(token)) %7B%0A                        failed = true;%0A                        System.err.println(%22Error: unknown algorithm '%22 + token + %22' passed to --algo%22);%0A                        break;%0A                    %7D else %7B%0A                        algorithms.add(token);%0A                    %7D%0A                %7D%0A
             %7D el
@@ -3422,32 +3422,32 @@
        %7D else %7B%0A
-
                 
@@ -3686,16 +3686,45 @@
 %7Cmore-n%3E
+ %5B--algo=%3Calgo1%3E,%3Calgo2%3E,...%5D
  %5B--out=
@@ -4044,16 +4044,15 @@
 , al
-lSorting
+gorithm
 s.to

Add support for explicitly specifying algorithms in Minimal.