Class CompareAlgorithms
java.lang.Object
experiment.CompareAlgorithms
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass for configuring the setup of algorithms to experiments for comparing them. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanstatic longstatic longstatic longstatic longstatic boolean(package private) static booleanstatic longstatic TimeUnit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static booleancheckIfSaved(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.(package private) static void(package private) static voidflush()(package private) static voidfreeTable(Table table, Table[] shared_tables, boolean[] table_occupied, int[] num_waiting_for_table, int table_ID) Frees the provided table.(package private) static voidgetAlreadyComputedRuns(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) (package private) static voidgetAlreadyComputedRuns(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.(package private) static voidgetAlreadyComputedRuns(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) (package private) static voidgetAlreadyComputedRuns(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) (package private) static voidgetAlreadyComputedRuns(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) 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.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.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.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.(package private) static voidstatic voidrecordProgress(int set_total) (package private) static voidstatic <T> Stream<T> Concatenates the given streams a specified number of times.(package private) static voidstatic voidrun(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.static voidrun(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(Stream, AlgoSetup, Duration, Limits, String, Optional, int, int, int, boolean, boolean, boolean, int)with an infinite time limit.static voidrun(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.static voidTemporary method used to print the rate of expansion during runs.(package private) static TablewaitForTable(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.(package private) static void(package private) static void(package private) static void(package private) static voidwriteln()(package private) static void
-
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
-
print_detailed_progress
public static boolean print_detailed_progress -
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(Stream, AlgoSetup, Duration, Limits, String, Optional, int, int, int, boolean, boolean, boolean, int)with an infinite time limit. -
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 withtimeout_amountandtimeout_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 notnull.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
-
freeTable
-
repeat
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 streamstreams- a supplier of streams- Returns:
- A stream containing all the elements from
timesnumber of calls to thestreamsstream 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 (trueor 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
ArtificialGamePositiontrees 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 (trueor 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
ArtificialGamePositiontrees 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 (trueor 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
ArtificialGamePositiontrees 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 nodedistribution- a function to generate node bounds at each node- Returns:
- Stream of
VariantAGPtrees for all parameter combinations.
-
getAlreadyComputedRuns
-
getAlreadyComputedRuns
-
getAlreadyComputedRuns
-
getAlreadyComputedRuns
-
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 bygetAlreadyComputedRuns(String[], long[][], String[][][], boolean, boolean, boolean)algorithm- the algorithm being checkediteration- the iteration being checked- Returns:
trueif the provided string-line matches the provided algorithm and already includes the provided iteration as saved.falseotherwise.
-
writeln
-
writeln
static void writeln() -
writef
-
writefln
-
write
-
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
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.
-