diff options
| -rwxr-xr-x | generate-results.sh | 20 | ||||
| -rwxr-xr-x | solvability.sh | 6 | ||||
| -rw-r--r-- | src/main/input-output/input/command_line_helper.cpp | 17 | ||||
| -rw-r--r-- | src/main/main.cpp | 25 |
4 files changed, 47 insertions, 21 deletions
diff --git a/generate-results.sh b/generate-results.sh index cf41873..0392450 100755 --- a/generate-results.sh +++ b/generate-results.sh @@ -1,5 +1,16 @@ #!/bin/bash +trap 'exit 130' INT + +if [ "$#" != 3 ]; then + echo "Usage: <seeds> <cores> <timeout>" + exit 1 +fi + +seeds="$1" +cores="$2" +timeout="$3" + declare -a arr=( "alpha-star" "bakers-game" @@ -50,6 +61,8 @@ declare -a arr=( ## Rules incorrect +#"martha" +#"penguin" ## Too difficult (?) @@ -60,12 +73,15 @@ declare -a arr=( DATE=`date +%Y-%m-%d-%H-%M-%S` -mkdir -p results/$DATE +out_dir=results/$DATE + +mkdir -p "$out_dir" +echo "Writing to $out_dir/" for i in "${arr[@]}" do echo "Running $i ..." - sol --type "$i" --solvability 20 --time 60 --stream none > results/$DATE/$i.csv + ./solvability.sh "$seeds" "$cores" "./cmake-build-release/bin/solvitaire --type $i --timeout $timeout" "$out_dir"/$i.csv done echo "Done!" diff --git a/solvability.sh b/solvability.sh index e0d157a..3fc9f7f 100755 --- a/solvability.sh +++ b/solvability.sh @@ -1,8 +1,8 @@ #!/bin/bash if [ "$#" != 4 ]; then - # e.g.: ./solvability 1000 40 "sol --type alpha-star --timeout 6000" results.csv echo "Usage: <seeds> <cores> \"<solvitaire_command>\" <output_file>" + echo "e.g.: ./solvability.sh 1000 40 \"sol --type alpha-star --timeout 6000\" results.csv" exit 1 fi @@ -11,8 +11,6 @@ cores="$2" sol_command="$3" out="$4" -# Features: smart-sol - echo "Attempted Seed, Outcome, Time Taken(ms), States Searched, Unique States Searched, Backtracks, Dominance Moves, States Removed From Cache, Final States In Cache, Final Buckets In Cache, Maximum Search Depth, Final Search Depth" > "$out" -parallel -j"$cores" "$sol_command" --ra {} --class ::: $(seq "$seeds") >> "$out" 2> /dev/null +parallel -j"$cores" "$sol_command" --str smart-solvability --ra {} --class ::: $(seq "$seeds") >> "$out" 2> /dev/null diff --git a/src/main/input-output/input/command_line_helper.cpp b/src/main/input-output/input/command_line_helper.cpp index 65bbcd6..5a66aa6 100644 --- a/src/main/input-output/input/command_line_helper.cpp +++ b/src/main/input-output/input/command_line_helper.cpp @@ -52,8 +52,8 @@ command_line_helper::command_line_helper() ("streamliners", po::value<string>(), "Applies streamliners to the search. Options include 'none', 'both', 'suit-symmetry'," " 'auto-foundations', and 'smart-solvability'. Defaults to 'none', unless '--solvability' is" - " also supplied, in which case defaults to 'smart-solvability'. 'smart-solvability' mode is only" - " available with '--solvability', and runs first with both streamliners and a 10% timeout. If this" + " also supplied, in which case defaults to 'smart-solvability'. 'smart-solvability' mode" + " runs first with both streamliners and a 10% timeout. If this" " is unsuccessful (unsolvable or timeout), then runs again without streamliners.") ("benchmark", "outputs performance statistics for the solver on the " "supplied solitaire game. Must supply " @@ -152,14 +152,7 @@ bool command_line_helper::parse(int argc, const char* argv[]) { if (s == "auto-foundations" ) streamliners = streamliner_opt::AUTO_FOUNDATIONS; else if (s == "suit-symmetry") streamliners = streamliner_opt::SUIT_SYMMETRY; else if (s == "both") streamliners = streamliner_opt::BOTH; - else if (s == "smart-solvability") { - if (solvability == -1) { - print_streamliner_solvability_error(); - return false; - } else { - streamliners = streamliner_opt::SMART; - } - } + else if (s == "smart-solvability") streamliners = streamliner_opt::SMART; else if (s == "none") streamliners = streamliner_opt::NONE; else { print_streamliner_error(s); @@ -260,10 +253,6 @@ void command_line_helper::print_streamliner_error(const string& str) { " 'auto-foundations', and 'smart-solvability'"); } -void command_line_helper::print_streamliner_solvability_error() { - LOG_ERROR ("Smart streamliner mode can only be used with '--solvability'"); -} - const vector<string> command_line_helper::get_input_files() { return input_files; } diff --git a/src/main/main.cpp b/src/main/main.cpp index 55feedf..57540d6 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -125,13 +125,36 @@ void solve_input_files(const vector<string> input_files, const sol_rules& rules, void solve_game(const game_state& gs, command_line_helper& clh, int seed) { solver solv(gs, clh.get_cache_capacity()); - solver::result result = solv.run(millisec(clh.get_timeout())); + solver::result result, streamliner_result; + bool smart = clh.get_streamliners() == command_line_helper::streamliner_opt::SMART; + bool run_again = false; + + if (smart) { + result = solv.run(millisec(clh.get_timeout() / 10)); + run_again = result.sol_type != solver::result::type::SOLVED; + if (run_again) + streamliner_result = solv.run(millisec(clh.get_timeout())); + } else { + result = solv.run(millisec(clh.get_timeout())); + } if (clh.get_classify()) { cout << seed; solver::print_result_csv(result); + if (smart) { + if (run_again) { + solver::print_result_csv(streamliner_result); + } else { + solver::print_null_seed_info(); + } + } cout << "\n"; } else { + if (run_again) { + cout << "Unsolvable using streamliner. Running again...\n"; + result = streamliner_result; + } + if (result.sol_type == solver::result::type::SOLVED) { solv.print_solution(); } else { |
