Class CompareAlgorithms

java.lang.Object
experiment.CompareAlgorithms

public class CompareAlgorithms extends Object
Large class containing many methods for running the experiments and creating new experiments. Some parameters such as debugging and timeout duration are set in-file and have to be changed manually in the code.
  • Field Details

    • num_completed

      public static long num_completed
    • num_skipped

      public static long num_skipped
    • num_prints

      public static long num_prints
    • num_total

      public static long num_total
    • timeout_amount

      public static long timeout_amount
    • timeout_unit

      public static TimeUnit timeout_unit
    • expansion_rate_printer

      public static boolean expansion_rate_printer
    • printReset

      static boolean printReset
  • Constructor Details

    • CompareAlgorithms

      public CompareAlgorithms()
  • Method Details

    • run

      public static void run(Stream<Supplier<ArtificialGamePosition>> trees, CompareAlgorithms.AlgoSetup algorithms, SearchAlgorithm.Limits limits, String write_to, Optional<String[]> read_from, int number_of_threads, boolean breakIterationOnSolve, boolean retry_unsolved, int initial_iteration)
      run(Stream, AlgoSetup, Duration, Limits, String, Optional, int, int, int, boolean, boolean, boolean, int) with an infinite time limit and without any transposition tables. Do not use this if the algorithm setup contains algorithms which require a transposition table, this will result in a runtime error.
    • run

      public static void run(Stream<Supplier<ArtificialGamePosition>> trees, CompareAlgorithms.AlgoSetup algorithms, SearchAlgorithm.Limits limits, String write_to, Optional<String[]> read_from, int number_of_threads, int number_of_tables, int table_size, boolean breakIterationOnSolve, boolean retry_unsolved, int initial_iteration)
    • run

      public static void run(Stream<Supplier<ArtificialGamePosition>> trees, CompareAlgorithms.AlgoSetup algorithms, Duration time_limit, SearchAlgorithm.Limits limits, String write_to, Optional<String[]> read_from, int number_of_threads, int number_of_tables, int table_size, boolean saveTimeIntractable, boolean breakIterationOnSolve, boolean retry_unsolved, int initial_iteration)
      Performs an algorithm comparison on the provided tree generator and algorithm set. This will keep performing runs for every tree in the generator. So provide a tree generator with a finite size or limit the overall runtime with the statically provided time limit with timeout_amount and timeout_unit.
      Parameters:
      trees - a finite stream of tree generators. Each tree supplier is called exactly once.
      algorithms - The algorithm setup to apply.
      time_limit - the time limit of each individual run, may be infinite.
      limits - the spatial limits of each individual run, may be infinite, but not null.
      write_to - the name of the file to write to.
      read_from - the names of files to read from, may be empty.
      number_of_threads - the number of computer threads to use for parallel computation of runs.
      number_of_tables - the number of transposition tables to use for algorithms that use transposition tables, may be 0 if no algorithms use transposition tables.
      table_size - the size of each transposition table used.
      saveTimeIntractable - whether to save runs that exceeded the time limit.
      breakIterationOnSolve - whether to stop iterating on runs of the same algorithm on the same tree when the first one of such iterations was solved.
      retry_unsolved - whether to re-run unsolved runs with lower limits, as loaded from the provided files.
      initial_iteration - the initial iteration number to apply to the algorithm setup. By default would be 0.
    • waitForTable

      static Table waitForTable(int table_size, Table[] shared_tables, boolean[] table_occupied, int[] num_waiting_for_table, int[] tableID)
      Runs wait for a table to become available in this method.
      Parameters:
      table_size -
      shared_tables -
      table_occupied -
      num_waiting_for_table -
      tableID -
      Returns:
    • freeTable

      static void freeTable(Table table, Table[] shared_tables, boolean[] table_occupied, int[] num_waiting_for_table, int table_ID)
      Frees the provided table.
      Parameters:
      table -
      shared_tables -
      table_occupied -
      num_waiting_for_table -
      table_ID -
    • repeat

      public static <T> Stream<T> repeat(int times, Supplier<Stream<T>> streams)
      Concatenates the given streams a specified number of times.
      Type Parameters:
      T - the type of object the stream contains
      Parameters:
      times - the number of times to repeat the given stream
      streams - a supplier of streams
      Returns:
      A stream containing all the elements from times number of calls to the streams stream supplier function.
    • getTrees

      public static Stream<Supplier<ArtificialGamePosition>> getTrees(Boolean[] adversarial, Integer[] width, Long[] range, Integer[] alt_vals, Double[] growth_factor, Double[] force_relevance, long initial_seed)
      Generates a stream of artificial game trees for all combinations of the provided parameters, using a random seed for each tree generated from the given initial seed.
      Parameters:
      adversarial - Array of booleans indicating whether the tree is adversarial (true or non-adversarial (false).
      width - Array of branching factors (number of children per node).
      range - Array of initial ranges for the root node.
      alt_vals - Array of numbers of alternative values (distribution parameter).
      growth_factor - Array of growth factors (distribution parameter).
      force_relevance - Array of force relevance chances (probability children are relevant given a growth factor above 1).
      initial_seed - Initial seed for the random number generator.
      Returns:
      Stream of ArtificialGamePosition trees for all parameter combinations.
    • getTrees

      public static Stream<Supplier<ArtificialGamePosition>> getTrees(Boolean[] adversarial, Integer[] width, Long[] range, Integer[] alt_vals, Double[] growth_factor, Double[] force_relevance, Long[] seeds)
      Generates a stream of artificial game trees for all combinations of the provided parameters, for each seed in the given array. For each seed, all parameter combinations are generated.
      Parameters:
      adversarial - Array of booleans indicating whether the tree is adversarial (true or non-adversarial (false).
      width - Array of branching factors (number of children per node).
      range - Array of initial ranges for the root node.
      alt_vals - Array of numbers of alternative values (distribution parameter).
      growth_factor - Array of growth factors (distribution parameter).
      force_relevance - Array of force relevance chances (probability children are relevant given a growth factor above 1).
      seeds - Array of seeds; each seed is used for a full parameter grid.
      Returns:
      Stream of ArtificialGamePosition trees for all seeds and parameter combinations.
    • getTrees

      public static Stream<Supplier<ArtificialGamePosition>> getTrees(Boolean[] adversarial, Integer[] width, Long[] range, Integer[] alt_vals, Double[] growth_factor, Double[] force_relevance, LongSupplier seeds)
      Generates a stream of artificial game trees for all combinations of the provided parameters, using a supplied seed for each tree. The seed supplier is called once for each tree generated.
      Parameters:
      adversarial - Array of booleans indicating whether the tree is adversarial (true or non-adversarial (false).
      width - Array of branching factors (number of children per node).
      range - Array of initial ranges for the root node.
      alt_vals - Array of numbers of alternative values (distribution parameter).
      growth_factor - Array of growth factors (distribution parameter).
      force_relevance - Array of force relevance chances (probability children are relevant given a growth factor above 1).
      seeds - Supplier of seeds; called once per tree.
      Returns:
      Stream of ArtificialGamePosition trees for all parameter combinations.
    • getTrees

      public static Stream<Supplier<VariantAGP>> getTrees(Boolean[] adversarial, Integer[] maxWidth, Generator.Width[] width, Long[] range, Generator.Bounds[] distribution, Double[] growth_factor, Double[] force_relevance, LongSupplier seeds)
      Generates a stream of variant artificial game trees for all combinations of the provided parameters, using a supplied seed for each tree. The seed supplier is called once for each tree generated.
      Parameters:
      width - a function to generate the number of children at each node
      distribution - a function to generate node bounds at each node
      Returns:
      Stream of VariantAGP trees for all parameter combinations.
    • getAlreadyComputedRuns

      static void getAlreadyComputedRuns(long[][] _skip_seeds, String[][][] _skip_algs, boolean count_intractable_for_expansions_as_solved, boolean save_limits, boolean count_node_limit_exceeded_as_unsolved, String... files)
    • getAlreadyComputedRuns

      static void getAlreadyComputedRuns(String file1, String file2, String file3, long[][] _skip_seeds, String[][][] _skip_algs, boolean count_intractable_for_expansions_as_solved, boolean save_limits, boolean count_node_limit_exceeded_as_unsolved)
    • getAlreadyComputedRuns

      static void getAlreadyComputedRuns(String file1, String file2, long[][] _skip_seeds, String[][][] _skip_algs, boolean count_intractable_for_expansions_as_solved, boolean save_limits, boolean count_node_limit_exceeded_as_unsolved)
    • getAlreadyComputedRuns

      static void getAlreadyComputedRuns(String previous_run_file, long[][] _skip_seeds, String[][][] _skip_algs, boolean count_intractable_for_expansions_as_solved, boolean save_limits, boolean count_node_limit_exceeded_as_unsolved)
    • getAlreadyComputedRuns

      static void getAlreadyComputedRuns(String[] files_of_previous_runs, long[][] _skip_seeds, String[][][] _skip_algs, boolean count_intractable_for_expansions_as_solved, boolean save_limits, boolean count_node_limit_exceeded_as_unsolved)
      Reads from a file or set of files and recovers which runs have previously been completed so they can be skipped.
      Parameters:
      files_of_previous_runs - the file or files to read, may be empty.
      _skip_seeds - pointer-like value, this contains part of the output of this method, contains the seeds which have runs that may be skipped.
      _skip_algs - pointer-like value, this contains part of the output of this method, contains detailed information on which runs can be skipped.
      count_intractable_for_expansions_as_solved - whether to record runs that were unsolved due to exceeding the limits as solved runs.
      save_limits - whether to record the limits of a run in the output _skip_algs.
      count_node_limit_exceeded_as_unsolved - whether to record solved runs exceeding the node limit as unsolved.
    • checkIfSaved

      static boolean checkIfSaved(String skipAlgStr, String algorithm, int iteration, boolean[] wasSolved, boolean[] sameLimits, SearchAlgorithm.Limits limits)
      Check if this algorithm with the specified iteration is stored in the previous file.
      Parameters:
      skipAlgStr - the array of algorithms to skip for this seed, generated by getAlreadyComputedRuns(String[], long[][], String[][][], boolean, boolean, boolean)
      algorithm - the algorithm being checked
      iteration - the iteration being checked
      Returns:
      true if the provided string-line matches the provided algorithm and already includes the provided iteration as saved. false otherwise.
    • writeln

      static void writeln(String s)
    • writeln

      static void writeln()
    • writef

      static void writef(String s, Object... os)
    • writefln

      static void writefln(String s, Object... os)
    • write

      static void write(String s)
    • flush

      static void flush()
    • closeAllPrints

      static void closeAllPrints()
    • resetPrint

      static void resetPrint()
    • recordProgress

      public static void recordProgress(int set_total)
    • recordProgress

      static void recordProgress()
    • recordSkip

      static void recordSkip()
    • startExpansionRatePrinter

      public static void startExpansionRatePrinter(ExecutorService exec)
      Temporary method used to print the rate of expansion during runs. This causes a hit in performance, for debugging only.
      Parameters:
      exec - the thread pool executor being used for the experiments.