Skip to content

Commit

Permalink
allow m=0
Browse files Browse the repository at this point in the history
  • Loading branch information
dimpase committed Mar 19, 2015
1 parent 29f192e commit eae88bb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
## 'make allclean' deletes also *.exe files.
##
CC=gcc
CFLAGS=-O -g
CFLAGS=-O -g -pg
EXT=.exe

all : oneeq systeq
Expand Down
9 changes: 8 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ current directory: oneeq.exe and systeq.exe
-------------------------------------------------------------------------
oneeq.exe
*********
finds the Hilbert basis (i.e. the minimal set of generators
For c=0, finds the Hilbert basis (i.e. the minimal set of generators
of the monoid of the nonnegative solutions) of one linear equation
$\sum_{i=1}^n a_i x_i + \sum_{j=1}^m b_j y_j = c$
where a_i, b_j are greater than 0 and c is nonnegative.

For c>0, finds all the minimal solutions to the equation.
(minimal in the sense that the solution cannot be obtained
as a sum of another solution and a nontrivial solution to the
homogeneous equation).

It accepts (at most) one command-line argument, namely the name of the
file to output the elements of the basis computed.

Expand All @@ -45,6 +50,8 @@ b_j
where prtlev monitors the level of information shown during the
execution time (0-minimal, >=5 - maximal);

m can be 0; in this case, all the solutions are minimal.

save is an integer telling the program to store ( save>0 ) solutions
or not to store them (save=0)

Expand Down
2 changes: 1 addition & 1 deletion hb.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef struct _eq { /* $\sum_1^n a_i + \sum_1^m b_i = c$ */
/* each noneg. sol. of eq is given by $v+\sum_{i=1}^{ns_hom} t_i u_i$,
where $t_i>=0$, $u_i\in s_hom$, $v\in s$ if $c\ne 0$, otherwise $v=0$ */

#define SOLCHUNK 1000 /* (re)allocate memory for solutions in these
#define SOLCHUNK 20000 /* (re)allocate memory for solutions in these
bits (the number stands for # of solutions */

int hb(eq *, int **, int), nf(int, int), nexpa(int, int *, int);
Expand Down
12 changes: 7 additions & 5 deletions hb_uts.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ eq *injcom(int n, int v[], int c)
int *getmat(FILE *file, int n, int m)
{
int i, j, *a, *p;
if (n<=0 || m<=0)
if (n<0 || m<0)
{ fprintf(stderr,"\n wrong dimesions in getmat\n"); exit(1);}
if (m*n==0) return NULL;
if (NULL==(a=(int *)calloc(n*m,sizeof(int)))) oomem("getmat");

for (i=0, p=a; i<n; i++)
Expand All @@ -147,15 +148,16 @@ int *getmat(FILE *file, int n, int m)
void outmat(FILE *file, int n, int m, int *a)
{
int i, j, *p;
if (n<=0 || m<=0)
if (n<0 || m<0)
{ fprintf(stderr,"\n wrong dimesions in outmat\n"); exit(1);}

for (i=0, p=a; i<n; i++)
if (n*m)
{for (i=0, p=a; i<n; i++)
{
fprintf(file,"\n");
for (j=0; j<m; j++) fprintf(file,"%4d",*p++);
}
fprintf(file,"\n");
}
fprintf(file,"\n");
}


Expand Down
6 changes: 6 additions & 0 deletions p39
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1
1
37
0
37
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 35 37

0 comments on commit eae88bb

Please sign in to comment.