Skip to content

Commit

Permalink
Add option to remove max_num_states.
Browse files Browse the repository at this point in the history
Enabling it seems to make matters a little worse.
  • Loading branch information
shlomif committed May 28, 2017
1 parent 343b091 commit 360f96e
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions fc-solve/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ option (FCS_BREAK_BACKWARD_COMPAT_1 "Break some backward compatibility in the li
option (FCS_WITHOUT_FC_PRO_MOVES_COUNT "Don't include the code and functionality of FC-Pro moves count.")
option (FCS_WITHOUT_TRIM_MAX_STORED_STATES "Don't include the trim-max-stored-states-functionality (should make things faster).")
option (FCS_WITHOUT_ITER_HANDLER "Don't include the iteration handler functionality (should make things faster).")
option (FCS_WITHOUT_MAX_NUM_STATES "Don't include the iterations limit functionality (should make things faster).")
option (FCS_DISABLE_MULTI_FLARES "Disable the multi-flaring functionality. May make things faster but break compatibilty. Enable at your own risk.")
option (FCS_DISABLE_MOVES_TRACKING "Disable the moves-tracking functionality. May make things faster but break a lot of compatibilty. Enable at your own risk.")
option (FCS_DISABLE_NUM_STORED_STATES "Disable the num-stored-states functionality. May make things faster but breaks compatibilty. Enable at your own risk.")
Expand Down
3 changes: 2 additions & 1 deletion fc-solve/source/Tatzer
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ my %BOOL_OPTS_WITH_FALSE_DEFAULTS =
'with-compact-moves' => 'FCS_USE_COMPACT_MOVE_TOKENS',
'without-depth-field' => 'FCS_WITHOUT_DEPTH_FIELD',
'without-fc-pro' => 'FCS_WITHOUT_FC_PRO_MOVES_COUNT',
'without-max-num-states' => 'FCS_WITHOUT_MAX_NUM_STATES',
'without-iter-handler' => 'FCS_WITHOUT_ITER_HANDLER',
'without-trim' => 'FCS_WITHOUT_TRIM_MAX_STORED_STATES',
'without-visited-iter' => 'FCS_WITHOUT_VISITED_ITER',
Expand Down Expand Up @@ -156,7 +157,7 @@ my %themes =
reduce_mem => [ qw(-l bench -l mem_reduction_settings) ],
fc_reduce_mem => [ qw(-l fc_bench -l mem_reduction_settings --scan-buckets-num=1) ],
testing => [qw(--rwd --dbm=kaztree --test-suite --num-stacks=13),],
extra_speed => [qw(--break-back-compat-1 --without-fc-pro --without-trim --disable-flares --disable-moves-track --disable-check-valid --disable-patsolve --disable-resume --hard-code-reparent-states --hard-code-calc-real-depth --disable-err-strs --disable-num-stored-states),],
extra_speed => [qw(--break-back-compat-1 --without-fc-pro --without-max-num-states --without-trim --disable-flares --disable-moves-track --disable-check-valid --disable-patsolve --disable-resume --hard-code-reparent-states --hard-code-calc-real-depth --disable-err-strs --disable-num-stored-states),],
);

foreach my $rec (
Expand Down
2 changes: 2 additions & 0 deletions fc-solve/source/cl_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ static void command_signal_handler(int signal_num GCC_UNUSED)

static void abort_signal_handler(int signal_num GCC_UNUSED)
{
#ifndef FCS_WITHOUT_MAX_NUM_STATES
freecell_solver_user_limit_iterations_long(instance, 0);
#endif
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion fc-solve/source/cmd_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ DLLEXPORT int freecell_solver_user_cmd_line_parse_args_with_file_nesting_count(

case FCS_OPT_MAX_ITERS: /* STRINGS=-mi|--max-iters; */
PROCESS_OPT_ARG();

#ifndef FCS_WITHOUT_MAX_NUM_STATES
freecell_solver_user_limit_iterations_long(instance, atol((*arg)));
#endif
break;

case FCS_OPT_TESTS_ORDER: /* STRINGS=-to|--tests-order; */
Expand Down
1 change: 1 addition & 0 deletions fc-solve/source/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern "C" {
#cmakedefine FCS_WITHOUT_DEPTH_FIELD

#cmakedefine FCS_WITHOUT_ITER_HANDLER
#cmakedefine FCS_WITHOUT_MAX_NUM_STATES

/*
* This flag controls a hash behaviour. It seems to improve things somewhat.
Expand Down
2 changes: 2 additions & 0 deletions fc-solve/source/fc_pro_range_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ int main(int argc, char *argv[])
freecell_solver_user_apply_preset(instance, variant);
#endif

#ifndef FCS_WITHOUT_MAX_NUM_STATES
if (was_total_iterations_limit_per_board_set)
{
freecell_solver_user_limit_iterations_long(
instance, total_iterations_limit_per_board);
}
#endif

char buffer[2000];
for (long long board_num = start_board; board_num <= end_board; board_num++)
Expand Down
2 changes: 2 additions & 0 deletions fc-solve/source/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ struct fc_solve_instance_struct
/* The number of states that were checked by the solving algorithm. */
fcs_int_limit_t i__num_checked_states;

#ifndef FCS_WITHOUT_MAX_NUM_STATES
/*
* Limit for the maximal number of checked states. max_num_checked_states
* is useful because it can limit the amount of consumed memory (and time).
Expand All @@ -592,6 +593,7 @@ struct fc_solve_instance_struct
* Normally should be used instead.
* */
fcs_int_limit_t effective_max_num_checked_states;
#endif
#ifndef FCS_DISABLE_NUM_STORED_STATES
fcs_int_limit_t effective_max_num_states_in_collection;
#ifndef FCS_WITHOUT_TRIM_MAX_STORED_STATES
Expand Down
19 changes: 12 additions & 7 deletions fc-solve/source/instance_for_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ static inline void fc_solve_alloc_instance(fc_solve_instance_t *const instance,
*(instance) = (fc_solve_instance_t){
.meta_alloc = meta_alloc,
.i__num_checked_states = 0,
#ifndef FCS_WITHOUT_MAX_NUM_STATES
.effective_max_num_checked_states = FCS_INT_LIMIT_MAX,
#endif
#ifndef FCS_DISABLE_NUM_STORED_STATES
.num_states_in_collection = 0,
#ifndef FCS_WITHOUT_TRIM_MAX_STORED_STATES
Expand Down Expand Up @@ -1013,10 +1015,15 @@ static inline void switch_to_next_soft_thread(
|| (instance->num_states_in_collection >= \
instance->effective_max_num_states_in_collection)
#endif
#ifdef FCS_WITHOUT_MAX_NUM_STATES
#define instance__check_exceeded_stats(instance) FALSE
#else
#define instance__check_exceeded_stats(instance) \
((instance->i__num_checked_states >= \
instance->effective_max_num_checked_states) \
instance_check_exceeded__num_states(instance))
((ret == FCS_STATE_SUSPEND_PROCESS) && \
((instance->i__num_checked_states >= \
instance->effective_max_num_checked_states) \
instance_check_exceeded__num_states(instance)))
#endif

static inline fc_solve_solve_process_ret_t run_hard_thread(
fc_solve_hard_thread_t *const hard_thread)
Expand Down Expand Up @@ -1160,8 +1167,7 @@ static inline fc_solve_solve_process_ret_t run_hard_thread(
instance->solving_soft_thread = soft_thread;
}
#endif
if (was_solved || ((ret == FCS_STATE_SUSPEND_PROCESS) &&
instance__check_exceeded_stats(instance)))
if (was_solved || instance__check_exceeded_stats(instance))
{
return ret;
}
Expand Down Expand Up @@ -1232,8 +1238,7 @@ static inline fc_solve_solve_process_ret_t fc_solve_resume_instance(
ret = run_hard_thread(hard_thread);
if ((ret == FCS_STATE_IS_NOT_SOLVEABLE) ||
(ret == FCS_STATE_WAS_SOLVED) ||
((ret == FCS_STATE_SUSPEND_PROCESS) &&
instance__check_exceeded_stats(instance)))
instance__check_exceeded_stats(instance))
{
goto end_of_hard_threads_loop;
}
Expand Down
10 changes: 10 additions & 0 deletions fc-solve/source/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ typedef struct
* the board
* */
instance_item_t *current_instance, *instances_list, *end_of_instances_list;
#ifndef FCS_WITHOUT_MAX_NUM_STATES
/*
* The global (sequence-wide) limit of the iterations. Used
* by limit_iterations() and friends
* */
fcs_int_limit_t current_iterations_limit;
#endif
/*
* The number of iterations this board started at.
* */
Expand Down Expand Up @@ -278,7 +280,9 @@ static MYINLINE void user_initialize(fcs_user_t *const user)
user->iter_handler = NULL;
#endif
#endif
#ifndef FCS_WITHOUT_MAX_NUM_STATES
user->current_iterations_limit = -1;
#endif

user->iterations_board_started_at = initial_stats;
user->all_instances_were_suspended = TRUE;
Expand Down Expand Up @@ -333,6 +337,7 @@ int DLLEXPORT freecell_solver_user_apply_preset(
}
#endif

#ifndef FCS_WITHOUT_MAX_NUM_STATES
void DLLEXPORT freecell_solver_user_limit_iterations_long(
void *const api_instance, const fcs_int_limit_t max_iters)
{
Expand All @@ -353,6 +358,7 @@ void DLLEXPORT freecell_solver_user_limit_current_instance_iterations(
((fcs_user_t *)api_instance)->current_instance->limit = max_iters;
}
#endif
#endif

static inline fc_solve_soft_thread_t *api_soft_thread(void *const api_instance)
{
Expand Down Expand Up @@ -1059,6 +1065,7 @@ static inline fc_solve_solve_process_ret_t resume_solution(
#endif
#define NUM_ITERS_LIMITS_MINUS_1 (NUM_ITERS_LIMITS - 1)

#ifndef FCS_WITHOUT_MAX_NUM_STATES
{
const fcs_int_limit_t limits[NUM_ITERS_LIMITS_MINUS_1] = {
user->current_iterations_limit
Expand All @@ -1085,6 +1092,7 @@ static inline fc_solve_solve_process_ret_t resume_solution(
user->iterations_board_started_at
.num_checked_states));
}
#endif

user->init_num_checked_states.num_checked_states =
instance->i__num_checked_states;
Expand Down Expand Up @@ -1169,6 +1177,7 @@ static inline fc_solve_solve_process_ret_t resume_solution(
instance_item->was_flare_finished = TRUE;
#endif
}
#ifndef FCS_WITHOUT_MAX_NUM_STATES
else if (user->ret_code == FCS_STATE_SUSPEND_PROCESS)
{
/*
Expand Down Expand Up @@ -1224,6 +1233,7 @@ static inline fc_solve_solve_process_ret_t resume_solution(
instance_item->was_flare_finished = TRUE;
#endif
}
#endif

} while ((user->current_instance < end_of_instances_list) &&
(ret == FCS_STATE_IS_NOT_SOLVEABLE));
Expand Down
2 changes: 2 additions & 0 deletions fc-solve/source/measure_depth_dep_tests_order_performance.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ int main(int argc, char *argv[])
fcs_state_string_t state_string;
get_board(board_num, state_string);

#ifndef FCS_WITHOUT_MAX_NUM_STATES
freecell_solver_user_limit_iterations_long(instance, iters_limit);
#endif
curr_result->start_time = fcs_get_time();

curr_result->verdict =
Expand Down
2 changes: 2 additions & 0 deletions fc-solve/source/pruner-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ static void my_iter_handler(void *const user_instance,
#ifdef FCS_WITH_ERROR_STRS
free(error_string);
#endif
#ifndef FCS_WITHOUT_MAX_NUM_STATES
freecell_solver_user_limit_iterations_long(pruner, 128 * 1024);
#endif

const int ret =
freecell_solver_user_solve_board(pruner, state_string);
Expand Down
4 changes: 4 additions & 0 deletions fc-solve/source/scans_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,12 @@ static inline fcs_int_limit_t calc_ht_max_num_states(
const fc_solve_hard_thread_t *const hard_thread)
{
const_AUTO(a, HT_FIELD(hard_thread, ht__max_num_checked_states));
#ifdef FCS_WITHOUT_MAX_NUM_STATES
return a;
#else
const_AUTO(b, CALC_HARD_THREAD_MAX_NUM_CHECKED_STATES__HELPER());
return min(a, b);
#endif
}
/*
* fc_solve_soft_dfs_do_solve() is the event loop of the
Expand Down
2 changes: 2 additions & 0 deletions fc-solve/source/serial_range_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ int main(int argc, char *argv[])
bin_init(&binary_output, &start_board, &end_board,
&total_iterations_limit_per_board);

#ifndef FCS_WITHOUT_MAX_NUM_STATES
if (was_total_iterations_limit_per_board_set)
{
freecell_solver_user_limit_iterations_long(
instance, total_iterations_limit_per_board);
}
#endif

for (long long board_num = start_board; board_num <= end_board; board_num++)
{
Expand Down

0 comments on commit 360f96e

Please sign in to comment.