PIPS
sol.c File Reference
#include "pip__type.h"
#include <stdio.h>
+ Include dependency graph for sol.c:

Go to the source code of this file.

Data Structures

struct  S
 Base of the parameters. More...
 

Macros

#define Nil   1
 
#define If   2
 
#define List   3
 
#define Form   4
 
#define New   5
 
#define Div   6
 
#define Val   7
 

Functions

Entier sol_mod ()
 
Entier sol_pgcd (Entier x, Entier y)
 
Entier sol_ppcm (Entier x, Entier y)
 
void sol_init ()
 
int sol_hwm ()
 
void sol_reset (int p)
 
struct Ssol_alloc ()
 
void sol_nil ()
 
int is_not_Nil (int p)
 
void sol_if ()
 
void sol_list (int n)
 
void sol_forme (int l)
 
void sol_new (int k)
 
void sol_div ()
 
void sol_val (Entier n, Entier d)
 
int sol_edit (FILE *foo, int i)
 

Variables

long int cross_product
 
long int limit
 
int verbose
 
FILE * dump
 Should not be used : put here for Pip copatibility. More...
 
struct S sol_space [SOL_SIZE]
 
static int sol_free
 

Macro Definition Documentation

◆ Div

#define Div   6

Definition at line 45 of file sol.c.

◆ Form

#define Form   4

Definition at line 43 of file sol.c.

◆ If

#define If   2

Definition at line 41 of file sol.c.

◆ List

#define List   3

Definition at line 42 of file sol.c.

◆ New

#define New   5

Definition at line 44 of file sol.c.

◆ Nil

#define Nil   1

Definition at line 40 of file sol.c.

◆ Val

#define Val   7

Definition at line 46 of file sol.c.

Function Documentation

◆ is_not_Nil()

int is_not_Nil ( int  p)

Definition at line 112 of file sol.c.

114 {
115  return(sol_space[p].flags != Nil);
116 }
struct S sol_space[SOL_SIZE]
Definition: sol.c:48
#define Nil
Definition: sol.c:40

References S::flags, Nil, and sol_space.

◆ sol_alloc()

struct S* sol_alloc ( )

Definition at line 90 of file sol.c.

91 {struct S *r;
92  r = sol_space + sol_free;
93  sol_free++;
94  if(sol_free >= SOL_SIZE)
95  {fprintf(stderr, "grosse solution!!! : sol\n");
96  exit(26);
97  }
98  return(r);
99 }
#define exit(code)
Definition: misc-local.h:54
#define SOL_SIZE
Modification by Alexis Platonoff: we need a greater solution size.
Definition: pip__type.h:30
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
static int sol_free
Definition: sol.c:49
Base of the parameters.
Definition: pip_interface.c:89

References exit, fprintf(), sol_free, SOL_SIZE, and sol_space.

Referenced by sol_div(), sol_forme(), sol_if(), sol_list(), sol_new(), sol_nil(), and sol_val().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sol_div()

void sol_div ( )

Definition at line 151 of file sol.c.

152 {
153  struct S *r;
154  r = sol_alloc();
155  r -> flags = Div;
156 }
#define Div
Definition: sol.c:45
struct S * sol_alloc()
Definition: sol.c:90
int flags
Definition: pip_interface.c:90

References Div, S::flags, and sol_alloc().

Referenced by integrer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sol_edit()

int sol_edit ( FILE *  foo,
int  i 
)

Definition at line 168 of file sol.c.

171 {int j, n;
172  struct S *p;
173  Entier N, D, d;
174  debut : p = sol_space + i;
175  switch(p->flags)
176  {case Nil : fprintf(foo, "()\n");
177  if(verbose>0)fprintf(dump, "()\n");
178  i++; break;
179  case If : fprintf(foo, "(if ");
180  if(verbose>0)fprintf(dump, "(if ");
181  i = sol_edit(foo, ++i);
182  i = sol_edit(foo, i);
183  i = sol_edit(foo, i);
184  fprintf(foo, ")\n");
185  if(verbose>0)fprintf(dump, ")\n");
186  break;
187  case List: fprintf(foo, "(list ");
188  if(verbose>0)fprintf(dump, "(list ");
189  n = p->param1;
190  i++;
191  while(n--) i = sol_edit(foo, i);
192  fprintf(foo, ")\n");
193  if(verbose>0)fprintf(dump, ")\n");
194  break;
195  case Form: fprintf(foo, "#[");
196  if(verbose>0)fprintf(dump, "#[");
197  n = p->param1;
198  for(j = 0; j<n; j++)
199  {i++; p++;
200  N = p->param1; D = p->param2;
201  d = sol_pgcd(N, D);
202  if(d == D){putc(' ', foo);
203  fprintf(foo, FORMAT, N/d);
204  if(verbose>0){
205  putc(' ', dump);
206  fprintf(dump, FORMAT, N/d);
207  }
208  }
209  else{putc(' ', foo);
210  fprintf(foo,FORMAT,N/d);
211  fprintf(foo,"/");
212  fprintf(foo,FORMAT, D/d);
213  if(verbose>0)
214  {putc(' ', dump);
215  fprintf(dump,FORMAT,N/d);
216  fprintf(dump,"/");
217  fprintf(dump,FORMAT, D/d);
218  }
219  }
220  }
221  fprintf(foo, "]\n");
222  if(verbose>0)fprintf(dump, "]\n");
223  i++;
224  break;
225  case New : n = p->param1;
226  fprintf(foo, "(newparm %d ", n);
227  if(verbose>0)fprintf(dump, "(newparm %d ", n);
228  i = sol_edit(foo, ++i);
229  fprintf(foo, ")\n");
230  if(verbose>0)fprintf(dump, ")\n");
231  goto debut;
232  case Div : fprintf(foo, "(div ");
233  if(verbose>0)fprintf(dump, "(div ");
234  i = sol_edit(foo, ++i);
235  i = sol_edit(foo, i);
236  fprintf(foo, ")\n");
237  if(verbose>0)fprintf(dump, ")\n");
238  break;
239  case Val : N = p->param1; D = p->param2;
240  d = sol_pgcd(N, D);
241  if(d == D){putc(' ', foo);
242  fprintf(foo, FORMAT, N/d);
243  if(verbose>0)
244  {putc(' ', dump);
245  fprintf(dump, FORMAT, N/d);
246  }
247  }
248  else{putc(' ', foo);
249  fprintf(foo, FORMAT, N/d);
250  fprintf(foo, "/");
251  fprintf(foo, FORMAT, D/d);
252  if(verbose>0)
253  {putc(' ', dump);
254  fprintf(dump, FORMAT, N/d);
255  fprintf(dump, "/");
256  fprintf(dump, FORMAT, D/d);
257  }
258  }
259  i++;
260  break;
261  default : fprintf(foo, "Inconnu : sol\n");
262  if(verbose>0)fprintf(dump, "Inconnu : sol\n");
263  }
264  return(i);
265 }
#define D(A)
Definition: iabrev.h:56
#define Entier
Definition: pip__type.h:24
#define FORMAT
Definition: pip__type.h:25
int verbose
Definition: maind.c:45
#define If
Definition: sol.c:41
Entier sol_pgcd(Entier x, Entier y)
Definition: sol.c:53
#define Form
Definition: sol.c:43
int sol_edit(FILE *foo, int i)
Definition: sol.c:168
#define New
Definition: sol.c:44
FILE * dump
Should not be used : put here for Pip copatibility.
Definition: pip.c:97
#define Val
Definition: sol.c:46
#define List
Definition: sol.c:42
Entier param1
Definition: pip_interface.c:91
Entier param2
Definition: pip_interface.c:91

References D, Div, dump, Entier, S::flags, Form, FORMAT, fprintf(), If, List, New, Nil, S::param1, S::param2, sol_pgcd(), sol_space, Val, and verbose.

+ Here is the call graph for this function:

◆ sol_forme()

void sol_forme ( int  l)

Definition at line 133 of file sol.c.

135 {
136  struct S *r;
137  r = sol_alloc();
138  r -> flags = Form;
139  r -> param1 = l;
140 }

References S::flags, Form, S::param1, and sol_alloc().

Referenced by integrer(), solution(), and traiter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sol_hwm()

int sol_hwm ( )

Definition at line 75 of file sol.c.

76 {
77  return(sol_free);
78 }

References sol_free.

Referenced by compa_test(), pip_solve(), and pip_solve_min_with_big().

+ Here is the caller graph for this function:

◆ sol_if()

void sol_if ( )

Definition at line 118 of file sol.c.

119 {
120  struct S *r;
121  r = sol_alloc();
122  r -> flags = If;
123 }

References S::flags, If, and sol_alloc().

Referenced by traiter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sol_init()

void sol_init ( )

Definition at line 70 of file sol.c.

71 {
72  sol_free = 0;
73 }

References sol_free.

Referenced by pip_solve(), and pip_solve_min_with_big().

+ Here is the caller graph for this function:

◆ sol_list()

void sol_list ( int  n)

Definition at line 125 of file sol.c.

127 {struct S * r;
128  r = sol_alloc();
129  r->flags = List;
130  r->param1 = n;
131 }

References S::flags, List, S::param1, and sol_alloc().

+ Here is the call graph for this function:

◆ sol_mod()

Entier sol_mod ( )

Referenced by sol_pgcd().

+ Here is the caller graph for this function:

◆ sol_new()

void sol_new ( int  k)

Definition at line 142 of file sol.c.

144 {
145  struct S *r;
146  r = sol_alloc();
147  r -> flags = New;
148  r -> param1 = k;
149 }

References S::flags, New, S::param1, and sol_alloc().

+ Here is the call graph for this function:

◆ sol_nil()

void sol_nil ( )

Definition at line 101 of file sol.c.

102 {
103  struct S * r;
104  r = sol_alloc();
105  r -> flags = Nil;
106  if(verbose > 0)
107  {fprintf(dump, "sol_nil\n");
108  fflush(dump);
109  }
110 }

References dump, S::flags, fprintf(), Nil, sol_alloc(), and verbose.

Referenced by traiter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sol_pgcd()

Entier sol_pgcd ( Entier  x,
Entier  y 
)

Definition at line 53 of file sol.c.

55 {Entier r;
56  while(y)
57  {r = sol_mod(x, y);
58  x = y;
59  y = r;
60  }
61  return(x>= 0? x : -x);
62 }
Entier sol_mod()
static char * x
Definition: split_file.c:159

References Entier, sol_mod(), and x.

Referenced by sol_edit(), and sol_ppcm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sol_ppcm()

Entier sol_ppcm ( Entier  x,
Entier  y 
)

Definition at line 64 of file sol.c.

65 {
66  Entier gcd = sol_pgcd(x, y), lcm = x * (y/gcd);
67  return lcm>=0 ? lcm: -lcm;
68 }

References Entier, sol_pgcd(), and x.

+ Here is the call graph for this function:

◆ sol_reset()

void sol_reset ( int  p)

Definition at line 80 of file sol.c.

82 {
83  if(p<0 || p>=SOL_SIZE)
84  {fprintf(stderr, "salades de saison .... : sol\n");
85  exit(40);
86  }
87  sol_free = p;
88 }

References exit, fprintf(), sol_free, and SOL_SIZE.

+ Here is the call graph for this function:

◆ sol_val()

void sol_val ( Entier  n,
Entier  d 
)

Definition at line 158 of file sol.c.

160 {
161  struct S *r;
162  r = sol_alloc();
163  r -> flags = Val;
164  r -> param1 = n;
165  r -> param2 = d;
166 }

References S::flags, S::param1, S::param2, sol_alloc(), and Val.

+ Here is the call graph for this function:

Variable Documentation

◆ cross_product

long int cross_product
extern

Definition at line 91 of file pip.c.

◆ dump

FILE* dump
extern

Should not be used : put here for Pip copatibility.

Definition at line 97 of file pip.c.

Referenced by sol_edit(), and sol_nil().

◆ limit

long int limit

Definition at line 31 of file sol.c.

◆ sol_free

int sol_free
static

Definition at line 49 of file sol.c.

Referenced by sol_alloc(), sol_hwm(), sol_init(), and sol_reset().

◆ sol_space

struct S sol_space[SOL_SIZE]

Definition at line 33 of file sol.c.

Referenced by integer_sol_edit(), is_not_Nil(), new_sol_edit(), rational_sol_edit(), sol_alloc(), and sol_edit().

◆ verbose

int verbose
extern

Definition at line 45 of file maind.c.

Referenced by dgetc(), dscanf(), pivoter(), sol_edit(), and sol_nil().