~ubuntu-branches/ubuntu/saucy/freecell-solver/saucy

« back to all changes in this revision

Viewing changes to test_multi_parallel.c

  • Committer: Package Import Robot
  • Author(s): Gergely Risko
  • Date: 2012-06-22 10:08:05 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120622100805-evoda1ccdr8vt5xr
Tags: 3.12.0-1
New upstream version. (closes: #675262)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <stdio.h>
34
34
#include <stdlib.h>
35
35
#include <string.h>
36
 
#ifndef WIN32
37
 
#include <sys/time.h>
38
 
#else
39
 
#include <sys/types.h>
40
 
#include <sys/timeb.h>
41
 
#endif
 
36
 
 
37
#include "portable_time.h"
 
38
#include "portable_int64.h"
42
39
 
43
40
#include "fcs_user.h"
44
41
#include "fcs_cl.h"
46
43
#include "inline.h"
47
44
#include "bool.h"
48
45
#include "range_solvers_gen_ms_boards.h"
49
 
 
50
 
struct fc_solve_display_information_context_struct
51
 
{
52
 
    fcs_bool_t debug_iter_state_output;
53
 
    int freecells_num;
54
 
    int stacks_num;
55
 
    int decks_num;
56
 
    fcs_bool_t parseable_output;
57
 
    fcs_bool_t canonized_order_output;
58
 
    fcs_bool_t display_10_as_t;
59
 
    fcs_bool_t display_parent_iter_num;
60
 
    fcs_bool_t debug_iter_output_on;
61
 
    fcs_bool_t display_moves;
62
 
    fcs_bool_t display_states;
63
 
    int standard_notation;
64
 
};
65
 
 
66
 
typedef struct fc_solve_display_information_context_struct fc_solve_display_information_context_t;
 
46
#include "output_to_file.h"
67
47
 
68
48
static void my_iter_handler(
69
49
    void * user_instance,
189
169
    "-i", "--iter-output",
190
170
    "-s", "--state-output",
191
171
    "-p", "--parseable-output",
 
172
    "-c", "--canonized-order-output",
 
173
    "-sn", "--standard-notation",
 
174
    "-snx", "--standard-notation-extended",
 
175
    "-sam", "--display-states-and-moves",
192
176
    "-t", "--display-10-as-t",
193
177
    "-pi", "--display-parent-iter",
194
178
    NULL
268
252
    int ret;
269
253
    int board_num;
270
254
    int start_board, end_board, stop_at;
271
 
#ifndef WIN32
272
 
    struct timeval tv;
273
 
    struct timezone tz;
274
 
#else
275
 
    struct _timeb tb;
276
 
#endif
277
 
    int total_num_iters_temp = 0;
278
 
#ifndef WIN32
279
 
    long long total_num_iters = 0;
280
 
#else
281
 
    __int64 total_num_iters = 0;
282
 
#endif
 
255
    fcs_portable_time_t mytime;
 
256
 
 
257
    fcs_int64_t total_num_iters = 0;
283
258
    char * error_string;
284
259
    int parser_ret;
285
260
 
 
261
    fcs_bool_t was_total_iterations_limit_per_board_set = FALSE;
286
262
    int total_iterations_limit_per_board = -1;
287
263
 
288
264
    char * binary_output_filename = NULL;
289
265
    fcs_state_string_t state_string;
290
266
 
291
267
    binary_output_t binary_output;
 
268
    const char * solutions_directory = NULL;
 
269
    char * solution_filename = NULL;
292
270
 
293
271
    int arg = 1, start_from_arg;
294
272
    if (argc < 4)
301
279
    end_board = atoi(argv[arg++]);
302
280
    stop_at = atoi(argv[arg++]);
303
281
 
 
282
    init_debug_context(&user.display_context);
 
283
 
304
284
    for (;arg < argc; arg++)
305
285
    {
306
286
        if (!strcmp(argv[arg], "--binary-output-to"))
323
303
                print_help();
324
304
                exit(-1);
325
305
            }
 
306
            was_total_iterations_limit_per_board_set = TRUE;
326
307
            total_iterations_limit_per_board = atoi(argv[arg]);
327
308
        }
 
309
        else if (!strcmp(argv[arg], "--solutions-directory"))
 
310
        {
 
311
            arg++;
 
312
            if (arg == argc)
 
313
            {
 
314
                fprintf(stderr, "--solutions-directory came without an argument!\n");
 
315
                print_help();
 
316
                exit(-1);
 
317
            }
 
318
            solutions_directory = argv[arg];
 
319
            solution_filename = malloc(strlen(solutions_directory) + 1024);
 
320
        }
328
321
        else
329
322
        {
330
323
            break;
333
326
 
334
327
    start_from_arg = arg;
335
328
 
336
 
 
337
 
 
338
 
    /* for(board_num=1;board_num<100000;board_num++) */
339
 
#ifndef WIN32
340
 
    gettimeofday(&tv,&tz);
341
 
    printf("Started at %li.%.6li\n",
342
 
        tv.tv_sec,
343
 
        tv.tv_usec
344
 
        );
345
 
#else
346
 
    _ftime(&tb);
347
 
    printf("Started at %li.%.6i\n",
348
 
        tb.time,
349
 
        tb.millitm*1000
350
 
        );
351
 
#endif
 
329
    FCS_PRINT_STARTED_AT(mytime);
352
330
    fflush(stdout);
353
331
 
354
332
    if (binary_output_filename)
430
408
        freecell_solver_user_cmd_line_parse_args(
431
409
            user.instance,
432
410
            argc,
433
 
            (freecell_solver_str_t *)argv,
 
411
            (freecell_solver_str_t *)(void *)argv,
434
412
            arg,
435
413
            known_parameters,
436
414
            cmd_line_callback,
444
422
        fprintf(stderr, "Unknown option: %s", argv[arg]);
445
423
        return (-1);
446
424
    }
447
 
    else if (
448
 
        (parser_ret == FCS_CMD_LINE_PARAM_WITH_NO_ARG)
449
 
            )
 
425
    else if (parser_ret == FCS_CMD_LINE_PARAM_WITH_NO_ARG)
450
426
    {
451
427
        fprintf(stderr, "The command line parameter \"%s\" requires an argument"
452
428
                " and was not supplied with one.\n", argv[arg]);
453
429
        return (-1);
454
430
    }
455
 
    else if (
456
 
        (parser_ret == FCS_CMD_LINE_ERROR_IN_ARG)
457
 
        )
 
431
    else if (parser_ret == FCS_CMD_LINE_ERROR_IN_ARG)
458
432
    {
459
433
        if (error_string != NULL)
460
434
        {
464
438
        return (-1);
465
439
    }
466
440
 
467
 
 
468
 
 
469
441
    ret = 0;
470
442
 
471
 
 
472
 
 
473
443
    for(board_num=start_board;board_num<=end_board;board_num++)
474
444
    {
475
445
        get_board(board_num, state_string);
476
446
 
477
 
        freecell_solver_user_limit_iterations(user.instance, total_iterations_limit_per_board);
 
447
        if (was_total_iterations_limit_per_board_set)
 
448
        {
 
449
            freecell_solver_user_limit_iterations(user.instance, total_iterations_limit_per_board);
 
450
        }
478
451
 
479
452
        ret =
480
453
            freecell_solver_user_solve_board(
484
457
 
485
458
        if (ret == FCS_STATE_SUSPEND_PROCESS)
486
459
        {
487
 
#ifndef WIN32
488
 
            gettimeofday(&tv,&tz);
489
 
            printf("Intractable Board No. %i at %li.%.6li\n",
490
 
                board_num,
491
 
                tv.tv_sec,
492
 
                tv.tv_usec
493
 
                );
494
 
#else
495
 
            _ftime(&tb);
496
 
            printf("Intractable Board No. %i at %li.%.6i\n",
497
 
                board_num,
498
 
                tb.time,
499
 
                tb.millitm*1000
500
 
            );
501
 
#endif
 
460
            FCS_PRINT_INTRACTABLE_BOARD(mytime, board_num);
502
461
            fflush(stdout);
503
462
            print_int_wrapper(-1);
504
463
        }
505
464
        else if (ret == FCS_STATE_FLARES_PLAN_ERROR)
506
465
        {
507
 
            const char * error_string;
 
466
            const char * flares_error_string;
508
467
 
509
 
            error_string =
 
468
            flares_error_string =
510
469
                freecell_solver_user_get_last_error_string(user.instance);
511
470
 
512
 
            printf("Flares Plan: %s\n", error_string);
 
471
            printf("Flares Plan: %s\n", flares_error_string);
513
472
 
514
473
            break;
515
474
        }
516
475
        else if (ret == FCS_STATE_IS_NOT_SOLVEABLE)
517
476
        {
518
 
#ifndef WIN32
519
 
            gettimeofday(&tv,&tz);
520
 
            printf("Unsolved Board No. %i at %li.%.6li\n",
521
 
                board_num,
522
 
                tv.tv_sec,
523
 
                tv.tv_usec
524
 
                );
525
 
#else
526
 
            _ftime(&tb);
527
 
            printf("Unsolved Board No. %i at %li.%.6i\n",
528
 
                board_num,
529
 
                tb.time,
530
 
                tb.millitm*1000
531
 
            );
532
 
#endif
 
477
            FCS_PRINT_UNSOLVED_BOARD(mytime, board_num);
533
478
            print_int_wrapper(-2);
534
479
        }
535
480
        else
537
482
            print_int_wrapper(freecell_solver_user_get_num_times(user.instance));
538
483
        }
539
484
 
540
 
        total_num_iters_temp += freecell_solver_user_get_num_times(user.instance);
541
 
        if (total_num_iters_temp > 1000000)
 
485
        if (solutions_directory)
542
486
        {
543
 
            total_num_iters += total_num_iters_temp;
544
 
            total_num_iters_temp = 0;
 
487
            FILE * output_fh;
 
488
            sprintf(solution_filename, "%s%09d.sol",
 
489
                solutions_directory, board_num
 
490
            );
 
491
 
 
492
            output_fh = fopen(solution_filename, "wt");
 
493
 
 
494
            if (! output_fh)
 
495
            {
 
496
                fprintf(stderr,
 
497
                        "Could not open output file '%s' for writing!",
 
498
                        solution_filename
 
499
                       );
 
500
                return -1;
 
501
            }
 
502
 
 
503
            fc_solve_output_result_to_file(
 
504
                output_fh, user.instance, ret, &user.display_context
 
505
            );
 
506
 
 
507
            fclose(output_fh);
 
508
            output_fh = NULL;
545
509
        }
 
510
 
 
511
        total_num_iters += freecell_solver_user_get_num_times(user.instance);
 
512
 
546
513
        if (board_num % stop_at == 0)
547
514
        {
548
 
            total_num_iters += total_num_iters_temp;
549
 
            total_num_iters_temp = 0;
550
 
 
551
 
 
552
 
#ifndef WIN32
553
 
            gettimeofday(&tv,&tz);
554
 
            printf("Reached Board No. %i at %li.%.6li (total_num_iters=%lli)\n",
555
 
                board_num,
556
 
                tv.tv_sec,
557
 
                tv.tv_usec,
558
 
                total_num_iters
559
 
                );
560
 
#else
561
 
            _ftime(&tb);
562
 
            printf(
563
 
#ifdef __GNUC__
564
 
                    "Reached Board No. %i at %li.%.6i (total_num_iters=%lli)\n",
565
 
#else
566
 
                    "Reached Board No. %i at %li.%.6i (total_num_iters=%I64i)\n",
567
 
#endif
568
 
                board_num,
569
 
                tb.time,
570
 
                tb.millitm*1000,
571
 
                total_num_iters
572
 
            );
573
 
#endif
 
515
            FCS_PRINT_REACHED_BOARD(mytime, board_num, total_num_iters);
574
516
            fflush(stdout);
575
 
 
576
517
        }
577
518
 
578
519