Commits

Shlomi Fish committed 2163f52

Implement the --flares-iters-factor option.

Comments (0)

Files changed (6)

fc-solve/source/TODO.txt

 * Implement a --flares-iters-factor option for multiplying the iters count
 allocated to each flare by a constant factor (so one can say make them times
 10, or times 100 or times 0.5, etc.).
+    - Test more thoroughly.
 
 * Convert the functions in lib.c to do
 +fcs_user_t * user = (fcs_user_t *)api_instance;+ .

fc-solve/source/USAGE.txt

 number of Freecell Pro moves, while not considering implicit moves to the
 foundations using Horne's Prune / Raymond Prune.
 
+-fif [factor] , --flares-iters-factor [factor]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Sets a global, floating-point number, factor to multiply all the iterations
+counts in the flares plans. The higher it is, the longer the scans will take,
+but there is a greater chance more of them will succeed, and, as a result,
+the solution may be shorter.
+
+As an example, the following:
+
+------------
+--flares-plan "Run:500@MyFlare,Run:2000@FooFlare" --flares-iters-factor 2
+------------
+
+Is equivalent to:
+
+------------
+--flares-plan "Run:1000@MyFlare,Run:4000@FooFlare"
+------------
+
+while:
+
+------------
+--flares-plan "Run:500@MyFlare,Run:2000@FooFlare" --flares-iters-factor 0.5
+------------
+
+Is equivalent to:
+
+------------
+--flares-plan "Run:250@MyFlare,Run:1000@FooFlare"
+------------
+
 --cache-limit [cache limit]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

fc-solve/source/cmd_line.c

 
 break;
 
+case 'i':
+{
+if (!strncmp(p, "ters-factor", 11)) {
+p += 11;
+opt = FCS_OPT_FLARES_ITERS_FACTOR;
+
+}
+}
+
+break;
+
 case 'p':
 {
 if (!strncmp(p, "lan", 3)) {
 
 break;
 
+case 'f':
+{
+if (!strncmp(p, "if", 2)) {
+p += 2;
+opt = FCS_OPT_FLARES_ITERS_FACTOR;
+
+}
+}
+
+break;
+
 case 'g':
 
 {
         }
         break;
 
+        case FCS_OPT_FLARES_ITERS_FACTOR: /* STRINGS=-fif|--flares-iters-factor; */
+        {
+            PROCESS_OPT_ARG() ;
+
+            freecell_solver_user_set_flares_iters_factor(instance, atof(*arg));
+        }
+        break;
+
         case FCS_OPT_OPTIMIZATION_TESTS_ORDER: /* STRINGS=-opt-to|--optimization-tests-order; */
         {
             int ret;

fc-solve/source/cmd_line_enum.h

     FCS_OPT_FLARE_NAME,
     FCS_OPT_PRELUDE,
     FCS_OPT_FLARES_PLAN,
+    FCS_OPT_FLARES_ITERS_FACTOR,
     FCS_OPT_OPTIMIZATION_TESTS_ORDER,
     FCS_OPT_SCANS_SYNERGY,
     FCS_OPT_RESET,

fc-solve/source/fcs_user.h

     const char * const new_flares_choice_string
 );
 
+DLLEXPORT extern void freecell_solver_user_set_flares_iters_factor(
+    void * user_instance,
+    double new_factor
+);
+
 #ifdef __cplusplus
 }
 #endif

fc-solve/source/lib.c

     freecell_solver_user_long_iter_handler_t long_iter_handler;
     void * iter_handler_context;
     enum FLARES_CHOICE_TYPE flares_choice;
+    double flares_iters_factor;
 
     fc_solve_soft_thread_t * soft_thread;
 
     user->iterations_board_started_at.num_states_in_collection = 0;
     user->all_instances_were_suspended = TRUE;
     user->flares_choice = FLARES_CHOICE_FC_SOLVE_SOLUTION_LEN;
+    user->flares_iters_factor = 1.0;
 
     user->error_string = NULL;
 
         }
         else /* (current_plan_item->type == FLARES_PLAN_RUN_COUNT_ITERS)  */
         {
-            flare_iters_quota = current_plan_item->count_iters;
+            flare_iters_quota =
+                (typeof(flare_iters_quota))
+                (user->flares_iters_factor * current_plan_item->count_iters)
+                ;
+            if (flare_iters_quota < 0)
+            {
+                flare_iters_quota = 0;
+            }
         }
 
         flare_idx = current_plan_item->flare_idx;
     return 0;
 }
 
+DLLEXPORT extern void freecell_solver_user_set_flares_iters_factor(
+    void * api_instance,
+    double new_factor
+)
+{
+    fcs_user_t * user = (fcs_user_t *)api_instance;
+
+    user->flares_iters_factor = new_factor;
+}
+
 #ifdef FCS_COMPILE_DEBUG_FUNCTIONS
 
 int DLLEXPORT fc_solve_user_INTERNAL_compile_all_flares_plans(