PIPS
pip.c
Go to the documentation of this file.
1 /*
2 
3  $Id: pip.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /* Name : pip.c
28  * Package : pip
29  * Author : F. Dumontet, A. Platonoff and A. Leservot
30  * Date : 30 july 1993
31  * Historic :
32  * - 16 nov 93, few changes (e.g. "test1" to "pip_in", etc.), AP
33  * - 08 dec 93, creation of a new package named pip.
34  * - 10 dec 93, new version of pip_solve : direct call to pip. AL
35  * - 31 jul 95, cleaning, pip_solve_min, pip_solve_max, old_pip_solve,
36  * old2_pip_solve, AP
37  *
38  * Documents:
39  * Comments : file containing the functions that resolve a Parametric Integer
40  * Programming problem with the PIP solver.
41  */
42 
43 /* Ansi includes */
44 #include <setjmp.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include <errno.h>
48 #include <stdlib.h>
49 
50 /* Newgen includes */
51 #include "genC.h"
52 
53 /* C3 includes */
54 #include "boolean.h"
55 #include "arithmetique.h"
56 #include "vecteur.h"
57 #include "contrainte.h"
58 #include "ray_dte.h"
59 #include "sommet.h"
60 #include "sg.h"
61 #include "sc.h"
62 #include "polyedre.h"
63 #include "matrix.h"
64 
65 /* Pips includes */
66 #include "ri.h"
67 #include "constants.h"
68 #include "ri-util.h"
69 #include "misc.h"
70 #include "bootstrap.h"
71 #include "complexity_ri.h"
72 #include "database.h"
73 #include "graph.h"
74 #include "dg.h"
75 #include "paf_ri.h"
76 #include "parser_private.h"
77 #include "property.h"
78 #include "reduction.h"
79 #include "text.h"
80 #include "paf-util.h"
81 #include "pip.h"
82 
83 /* Macros and functions Used by the old_pip_solve version */
84 #define PIP_BIN "pip4"
85 #define PIP_OPTION "-s"
86 #define PIP_IN_FILE "pip_in"
87 #define PIP_OUT_FILE "pip_out"
88 
89 /* Variables for the direct call to PIP version */
90 #define INLENGTH 1024
91 long int cross_product, limit;/* External variables for direct call to PIP */
94 int inptr = 256;
95 int proviso = 0;
96 int verbose = 0; /* Should not be used : put here for Pip copatibility */
97 FILE *dump = NULL;
98 char dump_name[] = "XXXXXX";
99 
100 /* Global variables */
104 
105 /*===========================================================================*/
106 /* quast old_pip_solve(Psysteme ps_dep, ps_context, int nb_unknowns,
107  * int min_or_max): Pip resolution.
108  *
109  * Parameters: ps_dep: system of constraints on the unknowns
110  * (and parameters)
111  * ps_context: system of constraints on the parameters
112  * nb_unknowns: number of unknowns in "ps_dep"
113  * min_or_max: tag for min or max resolution
114  *
115  * Result: a quast giving the value of the unknowns
116  *
117  * Note: The basis of "ps_dep" must contain all the unknowns and the
118  * parameters, with first the unknowns in order to allow us to catch them using
119  * "nb_unknowns".
120  */
121 /* Obsolete, AP July 31st 95 :
122 
123  quast old_pip_solve(ps_dep, ps_context, nb_unknowns, min_or_max)
124  Psysteme ps_dep, ps_context;
125  int nb_unknowns;
126  int min_or_max;
127  {
128  Pvecteur pvect;
129  int aux, n, i, res, infinite_num;
130  char *com = "essai";
131 
132  if(min_or_max == PIP_SOLVE_MIN) {
133  ind_min_max = 0;
134  infinite_num = -1;
135  }
136  else {
137  ps_dep = converti_psysmin_psysmax(ps_dep, nb_unknowns);
138  ind_min_max = 1;
139  infinite_num = vect_size((ps_dep)->base);
140  }
141 
142  base_var_ref = base_dup((ps_dep)->base);
143  old_base_var = base_dup(base_var_ref);
144  for(i = 1, pvect = base_var_ref; i<nb_unknowns; i++) { pvect = pvect->succ; }
145  base_ref = pvect->succ;
146  pvect->succ = NULL;
147  old_base = base_dup(base_ref);
148 
149  if(! SC_EMPTY_P(ps_context))
150  ps_context->base = base_dup(base_ref);
151 
152  res = ecrit_probleme2(com, ps_dep, ps_context, nb_unknowns,
153  infinite_num, vect_size(base_ref));
154 
155  n = 1;
156  while(n & 0xff) {
157  int m;
158  m = fork();
159  while(m == -1) {
160  char answer;
161 
162  fprintf(stderr, "Fork failed for PIP\n\t Do you want to retry (y/n) ?\n");
163  scanf("%c\n", &answer);
164  if(answer == 'y')
165  m = fork();
166  else
167  exit(1);
168  fprintf(stderr, "\n");
169  }
170  if(m == 0) {
171  execlp(PIP_BIN, PIP_BIN, PIP_OPTION, PIP_IN_FILE, PIP_OUT_FILE, (char *) 0);
172  }
173 
174  wait(&n);
175  }
176 
177  if((quayyin = fopen(PIP_OUT_FILE,"r")) == NULL) {
178  fprintf(stderr, "Cannot open file %s\n", PIP_OUT_FILE);
179  exit(1);
180  }
181  aux = quayyparse();
182 
183  return(quast_act);
184  }
185 */
186 
187 /*===========================================================================*/
188 /* quast old2_pip_solve(Psysteme ps_dep, ps_context, int nb_unknowns,
189  * int min_or_max): Pip resolution. AL 6/12/93
190  *
191  * Parameters: ps_dep: system of constraints on the unknowns
192  * (and parameters)
193  * ps_context: system of constraints on the parameters
194  * nb_unknowns: number of unknowns in "ps_dep"
195  * int_or_rat: integer or rational resolution.
196  * min_or_max: tag for min or max resolution
197  *
198  * Result: a quast giving the value of the unknowns
199  *
200  * Note: The basis of "ps_dep" must contain all the unknowns and the
201  * parameters, with first the unknowns in order to allow us to catch them using
202  * "nb_unknowns".
203  *
204  * Call to PIP is direct : no input or output file are produced.
205  */
206 /* Obsolete, AP July 31st 95 :
207 
208 quast old2_pip_solve(ps_dep, ps_context, nb_unknowns, min_or_max)
209 Psysteme ps_dep, ps_context;
210 int nb_unknowns, min_or_max;
211 {
212  Pvecteur pvect;
213  int i, infinite_num;
214 
215  int q, bigparm, ni, nvar, nq, non_vide, nparm, nc, p, xq;
216  char* g;
217  Tableau *ineq, *context, *ctxt;
218 
219 
220  debug_on("PIP_DEBUG_LEVEL");
221  debug(5, "pip_solve", "begin\n");
222  if (get_debug_level()>4) {
223  debug(5, "pip_solve", "Input Psysteme:\n");
224  fprint_psysteme( stderr, ps_dep );
225  debug(5, "pip_solve", "Input Context:\n");
226  fprint_psysteme( stderr, ps_context );
227  fprintf(stderr, "Number of variables : %d\n", nb_unknowns);
228  }
229 
230  vect_erase_var(&(ps_dep->base), (Variable) TCST);
231  ps_dep->dimension = vect_size((ps_dep)->base);
232 
233  if(min_or_max == PIP_SOLVE_MIN) {
234  ind_min_max = 0;
235  infinite_num = -1;
236  }
237  else {
238  ps_dep = converti_psysmin_psysmax(ps_dep, nb_unknowns);
239 
240  vect_erase_var(&(ps_dep->base), (Variable) TCST);
241  ps_dep->dimension = vect_size((ps_dep)->base);
242 
243  ind_min_max = 1;
244  infinite_num = vect_size((ps_dep)->base);
245  }
246 
247  base_var_ref = base_dup((ps_dep)->base);
248  old_base_var = base_dup(base_var_ref);
249 
250  for(i = 1, pvect = base_var_ref; i<nb_unknowns; i++)
251  { pvect = pvect->succ; }
252  base_ref = pvect->succ;
253  pvect->succ = NULL;
254  old_base = base_dup(base_ref);
255 
256  if(! SC_EMPTY_P(ps_context) ) {
257  ps_context->base = base_dup(base_ref);
258  ps_context->dimension = vect_size( base_ref );
259  }
260 
261  nvar = nb_unknowns;
262  nparm = ps_dep->dimension - nb_unknowns;
263  ni = (ps_dep->nb_eq * 2) + ps_dep->nb_ineq;;
264  nc = ((ps_context == NULL)? 0 :
265  (ps_context->nb_eq * 2) + ps_context->nb_ineq );
266  bigparm = infinite_num;
267  nq = 1;
268  debug(5, "pip_solve", "%d %d %d %d %d %d\n",
269  nvar, nparm, ni, nc, bigparm, nq );
270 
271  limit = 0L;
272  sol_init();
273  tab_init();
274  cross_product = 0;
275  g = tab_hwm();
276  ineq = sc_to_tableau(ps_dep, nb_unknowns);
277  if (ps_context != NULL) {
278  context = sc_to_tableau(ps_context, 0);
279  }
280  else context = NULL;
281  xq = p = sol_hwm();
282 
283  if (nc) {
284  ctxt = expanser(context, nparm, nc, nparm+1, nparm, 0, 0);
285  traiter( ctxt, NULL, True, UN, nparm, 0, nc, 0, -1 );
286  non_vide = is_not_Nil(p);
287  sol_reset(p);
288  }
289  else non_vide = True;
290  if ( non_vide ) {
291  traiter( ineq, context, nq, UN, nvar, nparm, ni, nc, bigparm );
292  q = sol_hwm();
293  init_new_base();
294  while((xq = new_sol_edit(xq)) != q);
295  sol_reset(p);
296  }
297  else quast_act = quast_undefined;
298  tab_reset(g);
299 
300  if (get_debug_level()>5) {
301  imprime_quast( stderr, quast_act );
302  }
303  debug_off();
304  return(quast_act);
305 }
306 */
307 
308 
309 /*=======================================================================*/
310 /* quast pip_solve_min_with_big(Psysteme ps_dep, ps_context, int nb_unknowns,
311  * char *big): Pip resolution.
312  *
313  * Parameters: ps_dep: system of constraints on the unknowns
314  * (and parameters)
315  * ps_context: system of constraints on the parameters
316  * nb_unknowns: number of unknowns in "ps_dep"
317  * big: big parameter 's name.
318  *
319  * Result: a quast giving the value of the unknowns
320  *
321  * Note: The basis of "ps_dep" must contain all the unknowns and the
322  * parameters, with first the unknowns in order to allow us to catch them
323  * using "nb_unknowns".
324  *
325  * Call to PIP is direct : no input or output file are produced.
326  *
327  * Note: this function is the same as pip_solve_min() but it has a big
328  * parameter given by the use.
329  */
330 
331 quast pip_solve_min_with_big(ps_dep, ps_context, pv_unknowns, big)
332 
333  Psysteme ps_dep, ps_context;
334  Pvecteur pv_unknowns;
335  char *big;
336 {
337  /* FD variables */
338  int infinite_num;
339 
340  /* Pip variables */
341  int q, bigparm, ni, nvar, nq, non_vide, nparm, nc, p, xq;
342  char* g;
343  Tableau *ineq, *context, *ctxt;
344 
345  /* AC variables for the big parameter */
346  bool not_found = true;
347  list lbase;
348  entity ent;
349  int nb_unknowns, len_big;
350 
351  debug_on("PIP_DEBUG_LEVEL");
352  debug(5, "pip_solve_min_with_big", "begin\n");
353  /* trace file */
354  nb_unknowns = vect_size( pv_unknowns );
355  if (get_debug_level()>4)
356  {
357  debug(5, "pip_solve_min_with_big", "Input Psysteme:\n");
358  fprint_psysteme( stderr, ps_dep );
359  debug(5, "pip_solve_min_with_big", "Input Context:\n");
360  fprint_psysteme( stderr, ps_context );
361  fprintf(stderr, "Number of variables : %d\n", nb_unknowns);
362  }
363 
364  /* We set the env for the kind of resolution desired (i.e. Min) */
365  /* and we get the order of the bi parameter called "big" in the */
366  /* base of ps_dep */
367 
368  /* Normalize base of system ps_dep */
369  pv_unknowns = base_normalize( pv_unknowns );
370  vect_erase_var( &ps_dep->base, TCST );
371  ps_dep->base = vect_add_first(pv_unknowns, ps_dep->base);
372  ps_dep->dimension = vect_size( ps_dep->base );
373 
374  ind_min_max = 0;
375  infinite_num = 1;
376  len_big = strlen(big);
377  lbase = base_to_list(ps_dep->base);
378  while ((not_found) && (lbase != NIL))
379  {
380  ent = ENTITY(CAR(lbase));
381  if (!strncmp(entity_local_name(ent), big, len_big))
382  not_found = false;
383  else
384  {
385  infinite_num++;
386  lbase = CDR(lbase);
387  }
388  }
389  if (not_found) infinite_num = -1;
390 
391  /* Computation of the basis (unknowns and parameters)
392  * base of ps_dep is the reference for all unknowns and parameters.
393  */
394  if (ps_context != NULL) {
395  vect_erase_var( &ps_context->base, TCST);
396  ps_context->dimension = vect_size( ps_context->base );
397  base_var_ref = base_union( ps_dep->base, ps_context->base );
398  }
399  else base_var_ref = ps_dep->base;
400  base_var_ref = vect_add_first(pv_unknowns, base_var_ref);
401  base_ref = vect_substract(base_var_ref, pv_unknowns);
402 
403  old_base_var = base_dup(base_var_ref); /* Total base of ps_dep */
405 
406  if (!SC_EMPTY_P(ps_context))
407  {
408  ps_context->base = base_dup(base_ref);
409  ps_context->dimension = vect_size( base_ref );
410  }
411 
412  /* Set PIP variables. Comes from ecrit_probleme2 */
413  nvar = nb_unknowns;
414  nparm = ps_dep->dimension - nb_unknowns;
415  ni = (ps_dep->nb_eq * 2) + ps_dep->nb_ineq;;
416  nc = ((ps_context == NULL)? 0 :
417  (ps_context->nb_eq * 2) + ps_context->nb_ineq );
418  bigparm = infinite_num;
419  nq = 1;
420  debug(5, "pip_solve_min_with_big", "%d %d %d %d %d %d\n",\
421  nvar, nparm, ni, nc, bigparm, nq );
422 
423  /* Prepare to call PIP */
424  limit = 0L;
425  sol_init();
426  tab_init();
427  cross_product = 0;
428  g = tab_hwm();
429  ineq = sc_to_tableau(ps_dep, nb_unknowns);
430  if (ps_context != NULL)
431  context = sc_to_tableau(ps_context, 0);
432  else context = NULL;
433  xq = p = sol_hwm();
434 
435  /* Verification de la non vacuite du contexte */
436  if (nc)
437  {
438  ctxt = expanser(context, nparm, nc, nparm+1, nparm, 0, 0);
439  traiter( ctxt, NULL, PIP_SOLVE_RATIONAL, UN, nparm, 0, nc, 0, -1 );
440  non_vide = is_not_Nil(p);
441  sol_reset(p);
442  }
443  else non_vide = True;
444 
445  if (non_vide)
446  {
447  traiter(ineq, context, PIP_SOLVE_RATIONAL, UN, nvar, nparm, ni, nc, bigparm);
448  q = sol_hwm();
449  init_new_base();
450  /* We read solution and put it in global quast_act */
451  while((xq = rational_sol_edit(xq)) != q);
452  sol_reset(p);
453  }
454  else quast_act = quast_undefined;
455  tab_reset(g);
456 
457  if (get_debug_level()>5) imprime_quast(stderr, quast_act);
458 
459  debug_off();
460 
461  return(quast_act);
462 }
463 
464 /*=======================================================================*/
465 /* Pvecteur vect_add_first( pv1, pv2 ) AL 16 02 94
466  *
467  * Suppress all variables of pv1 in pv2 and add pv1 before pv2.
468  * Keep pv1 order, not pv2's order!
469  */
471 Pvecteur pv1, pv2;
472 {
473  Pvecteur pv, pv11, pv22;
474 
475  if (pv1 == NULL) return pv2;
476  pv11 = vect_reversal( vect_dup( pv1 ) );
477  pv22 = vect_dup( pv2 );
478 
479  for( pv = pv11 ; pv != NULL; pv = pv->succ) {
480  vect_erase_var( &pv22, pv->var );
481  if (pv->succ != NULL) continue;
482  pv->succ = pv22;
483  break;
484  }
485  return pv11;
486 }
487 
488 /*===========================================================================*/
489 /* quast pip_solve(Psysteme ps_dep, ps_context, Pvecteur pv_unknowns,
490  * int int_or_rat, int min_or_max): Pip resolution. AL 6/12/93
491  *
492  * Parameters: ps_dep: system of constraints on the unknowns
493  * (and parameters)
494  * ps_context: system of constraints on the parameters
495  * pv_unknowns: ordered vector of unknowns in "ps_dep"
496  * int_or_rat: integer (1) or rational (0) resolution.
497  * min_or_max: tag for min or max resolution
498  *
499  * Result: a quast giving the value of the unknowns
500  *
501  * Call to PIP is direct : no input or output file are produced.
502  */
503 quast pip_solve(ps_dep, ps_context, pv_unknowns, int_or_rat, min_or_max)
504 Psysteme ps_dep, ps_context;
505 Pvecteur pv_unknowns;
506 int int_or_rat, min_or_max;
507 {
508  /* FD variables */
509  int infinite_num, nb_unknowns;
510 
511  /* Pip variables */
512  int q, bigparm, ni, nvar, nq, non_vide, nparm, nc, p, xq;
513  char* g;
514  Tableau *ineq, *context, *ctxt;
515 
516 
517  /* Initialization */
518  debug_on("PIP_DEBUG_LEVEL");
519  debug(5, "pip_solve", "begin\n");
520  if (ps_dep == NULL) {
521  user_warning("new_pip_solve", "\nInput Psysteme is empty !\n");
522  return quast_undefined;
523  }
524  nb_unknowns = vect_size( pv_unknowns );
525 
526  /* trace file */
527  if (get_debug_level()>4) {
528  debug(5, "pip_solve", "Input Psysteme:\n");
529  fprint_psysteme( stderr, ps_dep );
530  debug(5, "pip_solve", "Input Context:\n");
531  fprint_psysteme( stderr, ps_context );
532  fprintf(stderr, "Number of variables : %d\n", nb_unknowns);
533  }
534 
535 
536  /* Normalize base of system ps_dep */
537  pv_unknowns = base_normalize( pv_unknowns );
538  vect_erase_var( &ps_dep->base, TCST );
539  ps_dep->base = vect_add_first(pv_unknowns, ps_dep->base);
540  ps_dep->dimension = vect_size( ps_dep->base );
541 
542 
543  /* We set the env for the kind of resolution desired (Min or Max) */
544  if(min_or_max == PIP_SOLVE_MIN) {
545  ind_min_max = 0;
546  infinite_num = -1;
547  }
548  else {
549  ps_dep = converti_psysmin_psysmax(ps_dep, nb_unknowns);
550  ind_min_max = 1;
551  infinite_num = vect_size((ps_dep)->base);
552  }
553 
554  /* Computation of the basis (unknowns and parameters)
555  * base of ps_dep is the reference for all unknowns and parameters.
556  */
557  if (ps_context != NULL) {
558  vect_erase_var( &ps_context->base, TCST);
559  ps_context->dimension = vect_size( ps_context->base );
560  base_var_ref = base_union( ps_dep->base, ps_context->base );
561  }
562  else base_var_ref = ps_dep->base;
563  base_var_ref = vect_add_first(pv_unknowns, base_var_ref);
564  base_ref = vect_substract(base_var_ref, pv_unknowns);
565 
566  old_base_var = base_dup(base_var_ref); /* Total base of ps_dep */
568 
569  if(! SC_EMPTY_P(ps_context) ) {
570  ps_context->base = base_dup(base_ref);
571  ps_context->dimension = vect_size( base_ref );
572  }
573 
574  /* Set PIP variables. Comes from ecrit_probleme2 */
575  nvar = nb_unknowns;
576  nparm = ps_dep->dimension - nb_unknowns;
577  ni = (ps_dep->nb_eq * 2) + ps_dep->nb_ineq;;
578  nc = ((ps_context == NULL)? 0 :
579  (ps_context->nb_eq * 2) + ps_context->nb_ineq );
580  bigparm = infinite_num;
581  nq = int_or_rat;
582  debug(5, "pip_solve", "%d %d %d %d %d %d\n",
583  nvar, nparm, ni, nc, bigparm, nq );
584 
585  /* Prepare to call PIP */
586  limit = 0L;
587  sol_init();
588  tab_init();
589  cross_product = 0;
590  g = tab_hwm();
591  ineq = sc_to_tableau(ps_dep, nb_unknowns);
592  if (ps_context != NULL) {
593  context = sc_to_tableau(ps_context, 0);
594  }
595  else context = NULL;
596  xq = p = sol_hwm();
597 
598  /* Verification de la non vacuite du contexte */
599  if (nc) {
600  ctxt = expanser(context, nparm, nc, nparm+1, nparm, 0, 0);
601  traiter( ctxt, NULL, nq, UN, nparm, 0, nc, 0, -1 );
602  non_vide = is_not_Nil(p);
603  sol_reset(p);
604  }
605  else non_vide = True;
606  if ( non_vide ) {
607  traiter( ineq, context, nq, UN, nvar, nparm, ni, nc, bigparm );
608  q = sol_hwm();
609  init_new_base();
610  /* We read solution and put it in global quast_act */
611  if( int_or_rat == PIP_SOLVE_INTEGER )
612  while((xq = integer_sol_edit(xq)) != q);
613  else while((xq = rational_sol_edit(xq)) != q);
614  sol_reset(p);
615  }
616  else quast_act = quast_undefined;
617  tab_reset(g);
618 
619  if (get_debug_level()>5) {
620  imprime_quast( stderr, quast_act );
621  }
622  debug_off();
623  return(quast_act);
624 }
625 
626 
627 /*===================================================================*/
628 quast pip_integer_min( ps_dep, ps_context, pv_unknowns )
629 Psysteme ps_dep, ps_context;
630 Pvecteur pv_unknowns;
631 {
632  return( pip_solve( ps_dep, ps_context, pv_unknowns,
634 }
635 
636 /*===================================================================*/
637 quast pip_integer_max( ps_dep, ps_context, pv_unknowns )
638 Psysteme ps_dep, ps_context;
639 Pvecteur pv_unknowns;
640 {
641  return( pip_solve( ps_dep, ps_context, pv_unknowns,
643 }
644 
645 /*===================================================================*/
646 quast pip_rational_min( ps_dep, ps_context, pv_unknowns )
647 Psysteme ps_dep, ps_context;
648 Pvecteur pv_unknowns;
649 {
650  return( pip_solve( ps_dep, ps_context, pv_unknowns,
652 }
653 
654 /*===================================================================*/
655 quast pip_rational_max( ps_dep, ps_context, pv_unknowns )
656 Psysteme ps_dep, ps_context;
657 Pvecteur pv_unknowns;
658 {
659  return( pip_solve( ps_dep, ps_context, pv_unknowns,
661 }
662 
663 /*===================================================================*/
664 /* void pip_solve_min(Psysteme ps_dep, ps_context, int nb_unknowns):
665  * Pip resolution for the minimum.
666  */
667 /* Obsolete, AP July 31st 95 :
668 
669  quast pip_solve_min(ps_dep, ps_context, nb_unknowns)
670  Psysteme ps_dep, ps_context;
671  int nb_unknowns;
672  {
673  return(old2_pip_solve(ps_dep, ps_context, nb_unknowns, PIP_SOLVE_MIN));
674  }
675  */
676 
677 /*===================================================================*/
678 /* void pip_solve_max(Psysteme ps_dep, ps_context, int nb_unknowns):
679  * Pip resolution for the maximum.
680  */
681 /* Obsolete, AP July 31st 95 :
682 
683  quast pip_solve_max(ps_dep, ps_context, nb_unknowns)
684  Psysteme ps_dep, ps_context;
685  int nb_unknowns;
686  {
687  return(old2_pip_solve(ps_dep, ps_context, nb_unknowns, PIP_SOLVE_MAX));
688  }
689 */
690 
691 /*===================================================================*/
692 
693 /* Useful for the sorting of the variables in the system's Pvecteur.
694 */
695 static Pbase base_for_sort = (Pbase)NULL;
696 
697 /* function for qsort.
698  * rank_of_variable returns 0 for TCST, hence the strange return
699  */
700 static int compare_variables_in_base(pv1, pv2)
701 Pvecteur *pv1, *pv2;
702 {
703  int
704  rank_1 = rank_of_variable(base_for_sort, var_of(*pv1)),
705  rank_2 = rank_of_variable(base_for_sort, var_of(*pv2));
706 
707  message_assert("variable not in global vector", rank_1>=0 && rank_2>=0);
708 
709  /* TCST must be last, but given as 0
710  */
711  return((rank_1==0 || rank_2==0) ? rank_1-rank_2 : rank_2-rank_1);
712 }
713 
714 /*===================================================================*/
715 /* void sort_psysteme(Psysteme ps, Pvecteur pv): sorts the system "ps"
716  * according to the vector "pv". In order to avoid any side effects,
717  * this vector is duplicated into a base "new_base". When the sorting
718  * is done, this new base becomes the basis of this system.
719  *
720  * "pv" MUST contain all the variables that appear in "ps".
721  * "pv" DOES NOT HAVE TO contain TCST.
722  *
723  * modified by FC, 29/12/94.
724  * I removed the vect_tri call and the associated memory leaks.
725  * sc_vect_sort called instead.
726  * maybe the sc base is lost? It depends whether it is pv or not,
727  * and what is done with pv by the caller. I would suggest a base_rm.
728  */
729 void sort_psysteme(ps, pv)
730 Psysteme ps;
731 Pvecteur pv;
732 {
733  if(SC_EMPTY_P(ps)) return;
734 
735  base_for_sort = base_dup(pv);
737 
738  ps->dimension = base_dimension(base_for_sort);
739  ps->base = base_for_sort;
740  base_for_sort = (Pbase)NULL;
741 }
742 
743 /*************************************************************************/
int rank_of_variable(Pbase base, Variable var)
this function returns the rank of the variable var in the base 0 encodes TCST, but I do not know why,...
Definition: base.c:497
Pbase base_normalize(Pbase b)
Definition: base.c:594
Pbase base_union(Pbase b1, Pbase b2)
Pbase base_union(Pbase b1, Pbase b2): compute a new basis containing all elements of b1 and all eleme...
Definition: base.c:428
bdt base
Current expression.
Definition: bdt_read_paf.c:100
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
list base_to_list(Pbase base)
Most includes are centralized here.
Tableau * expanser()
int vect_size(Pvecteur v)
package vecteur - reductions
Definition: reductions.c:47
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
#define user_warning(fn,...)
Definition: misc-local.h:262
int get_debug_level(void)
GET_DEBUG_LEVEL returns the current debugging level.
Definition: debug.c:67
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
#define message_assert(msg, ex)
Definition: newgen_assert.h:47
#define PIP_SOLVE_MIN
#define PIP_SOLVE_MAX
void imprime_quast(FILE *, quast)
===========================================================================
Definition: print.c:514
void fprint_psysteme(FILE *, Psysteme)
===========================================================================
Definition: print.c:302
#define quast_undefined
Definition: paf_ri.h:603
#define PIP_SOLVE_RATIONAL
Definition: pip-local.h:28
#define PIP_SOLVE_INTEGER
Definition: pip-local.h:27
int comptage
Definition: pip.c:92
Pvecteur vect_add_first(Pvecteur pv1, Pvecteur pv2)
======================================================================
Definition: pip.c:470
int verbose
Definition: pip.c:96
quast pip_integer_min(Psysteme ps_dep, Psysteme ps_context, Pvecteur pv_unknowns)
==================================================================
Definition: pip.c:628
quast pip_rational_min(Psysteme ps_dep, Psysteme ps_context, Pvecteur pv_unknowns)
==================================================================
Definition: pip.c:646
Pbase old_base
Base of the parameters.
Definition: pip.c:102
int inptr
Definition: pip.c:94
Pbase base_ref
Base of the unknowns.
Definition: pip.c:102
static Pbase base_for_sort
==================================================================
Definition: pip.c:695
int proviso
Definition: pip.c:95
int ind_min_max
Definition: pip.c:103
quast pip_integer_max(Psysteme ps_dep, Psysteme ps_context, Pvecteur pv_unknowns)
==================================================================
Definition: pip.c:637
long int limit
Definition: pip.c:91
Pbase old_base_var
Base of the unknowns.
Definition: pip.c:102
quast pip_rational_max(Psysteme ps_dep, Psysteme ps_context, Pvecteur pv_unknowns)
==================================================================
Definition: pip.c:655
char inbuff[INLENGTH]
Definition: pip.c:93
quast quast_act
Global variables
Definition: pip.c:101
int allocation
External variables for direct call to PIP.
Definition: pip.c:92
Pbase base_var_ref
Tag for MIN or MAX resolution.
Definition: pip.c:102
#define INLENGTH
Variables for the direct call to PIP version.
Definition: pip.c:90
void sort_psysteme(Psysteme ps, Pvecteur pv)
==================================================================
Definition: pip.c:729
char dump_name[]
Definition: pip.c:98
FILE * dump
Should not be used : put here for Pip copatibility.
Definition: pip.c:97
quast pip_solve_min_with_big(Psysteme ps_dep, Psysteme ps_context, Pvecteur pv_unknowns, char *big)
==========================================================================
Definition: pip.c:331
static int compare_variables_in_base(Pvecteur *pv1, Pvecteur *pv2)
function for qsort.
Definition: pip.c:700
quast pip_solve(Psysteme ps_dep, Psysteme ps_context, Pvecteur pv_unknowns, int int_or_rat, int min_or_max)
==========================================================================
Definition: pip.c:503
long int cross_product
Definition: pip.c:91
int sol_hwm()
Definition: sol.c:75
void sol_reset()
int is_not_Nil()
void sol_init()
Definition: sol.c:70
void tab_init()
Definition: tab.c:77
char * tab_hwm()
Definition: tab.c:92
void tab_reset()
#define UN
Definition: pip__type.h:26
#define True
Definition: pip__type.h:32
int integer_sol_edit(int i)
Useful for the sorting of the variables in the system's Pvecteur.
int rational_sol_edit(int i)
==========================================================================
Tableau * sc_to_tableau(Psysteme in_ps, int nb_var)
==========================================================================
Pvecteur vect_reversal(Pvecteur vect_in)
Pvecteur vect_reversal(Pvecteur vect_in); produces the reversal vector of the vect_in.
Definition: private.c:237
Psysteme converti_psysmin_psysmax(Psysteme p_systmin, int nb_var)
Name: converti_psysmin_psysmax
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
void sc_vect_sort(Psysteme s, int(*compare)(Pvecteur *, Pvecteur *))
the name is self explanatory, I guess.
Definition: sc_unaires.c:116
void init_new_base()
Name: init_new_base.
Definition: solpip.c:601
Definition: pip__tab.h:30
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
Variable var
Definition: vecteur-local.h:90
struct Svecteur * succ
Definition: vecteur-local.h:92
Definition: pip__tab.h:48
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: delay.c:253
void traiter()
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
struct Svecteur * Pbase
#define var_of(varval)
#define base_dimension(b)
Pvecteur vect_dup(Pvecteur v_in)
Pvecteur vect_dup(Pvecteur v_in): duplication du vecteur v_in; allocation de et copie dans v_out;.
Definition: alloc.c:51
Pbase base_dup(Pbase b)
Pbase base_dup(Pbase b) Note: this function changes the value of the pointer.
Definition: alloc.c:268
Pvecteur vect_substract(Pvecteur v1, Pvecteur v2)
Pvecteur vect_substract(Pvecteur v1, Pvecteur v2): allocation d'un vecteur v dont la valeur est la di...
Definition: binaires.c:75
void vect_erase_var(Pvecteur *ppv, Variable v)
void vect_erase_var(Pvecteur * ppv, Variable v): projection du vecteur *ppv selon la direction v (i....
Definition: unaires.c:106