configure.in: set AC_CONFIG_MACRO_DIR
[piplib.git] / example / example.c
blob0e8959aab0395ba55372f9e5f8f598db5bcb9f2f
1 /* This is a very simple example of how to use the PipLib inside your programs.
2 * You should compile it by typing 'make' (after edition of the makefile), then
3 * test it for instance by typing 'more FILE.pol | ./example'. Finally you can
4 * compare results given by PIP by typing 'pip32 FILE.dat'
5 */
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <piplib/piplib.h>
12 static PipOptions *options_read(FILE *f)
14 char s[1024];
15 PipOptions *options = pip_options_init();
16 while (fgets(s, 1024, f)) {
17 if (strncasecmp(s, "Maximize", 8) == 0)
18 options->Maximize = 1;
19 if (strncasecmp(s, "Urs_parms", 9) == 0)
20 options->Urs_parms = 1;
21 if (strncasecmp(s, "Urs_unknowns", 12) == 0)
22 options->Urs_unknowns = 1;
23 if (strncasecmp(s, "Rational", 8) == 0)
24 options->Nq = 0;
25 if (strncasecmp(s, "Dual", 4) == 0)
26 options->Compute_dual = 1;
28 return options;
31 int main(int argc, const char **argv)
32 { int bignum ;
33 PipMatrix * domain, * context ;
34 PipQuast * solution ;
35 PipOptions * options ;
36 int verbose = 0;
38 while (argc > 1) {
39 if (strncmp(argv[1], "-v", 2) == 0) {
40 const char *v = argv[1]+2;
41 ++verbose;
42 while (*v++ == 'v')
43 ++verbose;
44 } else
45 break;
46 ++argv;
47 --argc;
50 printf("[PIP2-like future input] Please enter:\n- the context matrix,\n") ;
51 context = pip_matrix_read(stdin) ;
52 pip_matrix_print(stdout,context) ;
54 printf("- the bignum column (start at 0, -1 if no bignum),\n") ;
55 fscanf(stdin," %d",&bignum) ;
56 printf("%d\n",bignum) ;
58 printf("- the constraint matrix.\n") ;
59 domain = pip_matrix_read(stdin) ;
60 pip_matrix_print(stdout,domain) ;
61 printf("\n") ;
63 if (isatty(0))
64 printf("- options (EOF to stop).\n") ;
65 options = options_read(stdin);
66 options->Verbose = verbose;
67 if (isatty(0))
68 pip_options_print(stdout, options);
70 /* The bignum in PIP1 is fixed on the constraint matrix, here is
71 * the translation.
73 if (bignum > 0)
74 bignum += domain->NbColumns - context->NbColumns ;
76 solution = pip_solve(domain,context,bignum,options) ;
78 pip_options_free(options) ;
79 pip_matrix_free(domain) ;
80 pip_matrix_free(context) ;
82 pip_quast_print(stdout,solution,0) ;
84 pip_quast_free(solution) ;
85 return 0 ;