Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 345c74bd authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Merge branch 'print_tree' into 'master'

Print tree

See merge request !5
parents 43b311a3 231eae15
No related branches found
No related tags found
1 merge request!5Print tree
...@@ -3,7 +3,7 @@ CFLAGS = -Iinclude -Wall -g3 ...@@ -3,7 +3,7 @@ CFLAGS = -Iinclude -Wall -g3
LDFLAGS = -lm LDFLAGS = -lm
LIBHQR=src/libhqr.a LIBHQR=src/libhqr.a
default: testing_pivgen testing_treewalk testing_treedraw default: testing_pivgen testing_treedraw
src/queue.o: include/queue.h include/common.h src/queue.o: include/queue.h include/common.h
src/libhqr.o: include/common.h include/libhqr.h src/libhqr.o: include/common.h include/libhqr.h
...@@ -21,9 +21,6 @@ $(LIBHQR): src/libhqr.o src/libhqr_dbg.o src/libhqr_systolic.o src/treewalk.o sr ...@@ -21,9 +21,6 @@ $(LIBHQR): src/libhqr.o src/libhqr_dbg.o src/libhqr_systolic.o src/treewalk.o sr
testing_pivgen : testings/testing_pivgen.o ${LIBHQR} testing_pivgen : testings/testing_pivgen.o ${LIBHQR}
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
testing_treewalk : testings/testing_treewalk.c ${LIBHQR}
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
testing_treedraw : testings/testing_treedraw.o ${LIBHQR} testing_treedraw : testings/testing_treedraw.o ${LIBHQR}
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
...@@ -34,4 +31,4 @@ clean : ...@@ -34,4 +31,4 @@ clean :
cleanall: clean cleanall: clean
rm -f ${LIBHQR} rm -f ${LIBHQR}
rm -f testing_pivgen testing_treewalk testing_treedraw tree.svg rm -f testing_pivgen testing_treedraw tree.svg
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
#define _LIBDRAW_H_ #define _LIBDRAW_H_
#include <common.h> #include <common.h>
#define WIDTH 50
#define HEIGHT 50
#define SIZE 100
BEGIN_C_DECLS BEGIN_C_DECLS
...@@ -31,11 +34,11 @@ extern char *color[4]; ...@@ -31,11 +34,11 @@ extern char *color[4];
* function for treedraw * function for treedraw
*/ */
void libhqr_writeheader(FILE *tree); void libhqr_writeheader(FILE *file);
void libhqr_writeend(FILE *tree); void libhqr_writeend(FILE *file);
void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *tree); void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *file);
void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *tree); void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *file);
void libhqr_drawline(int x1, int y1, int x2, int y2, FILE *tree); void libhqr_drawline(int x1, int y1, int x2, int y2, int k, FILE *file);
END_C_DECLS END_C_DECLS
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define _LIBHQR_H_ #define _LIBHQR_H_
#include "common.h" #include "common.h"
#include <stdio.h>
BEGIN_C_DECLS BEGIN_C_DECLS
...@@ -190,10 +191,14 @@ int libhqr_hqr_init( libhqr_tree_t *qrtree, ...@@ -190,10 +191,14 @@ int libhqr_hqr_init( libhqr_tree_t *qrtree,
void libhqr_hqr_finalize( libhqr_tree_t *qrtree ); void libhqr_hqr_finalize( libhqr_tree_t *qrtree );
/* /*
* function for treewalk * function for drawing the tree
*/ */
void libhqr_treewalk(const libhqr_tree_t *qrtree,int k); void libhqr_treewalk(const libhqr_tree_t *qrtree,int k, int *tiles, FILE *file);
void draw_rectangle(int k, int p, int m, int *tiles, FILE *file);
void draw_horizontal_line(int k, int p, int m, int *tiles, FILE *file);
void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file);
void libhqr_print_tree(const libhqr_tree_t *qrtree, libhqr_tiledesc_t *matrix);
/* /*
* Debugging functions * Debugging functions
......
...@@ -22,14 +22,14 @@ ...@@ -22,14 +22,14 @@
* Global array for color * Global array for color
*/ */
char *color[4] = {"red", "blue", "green", "purple"}; char *colortree[4] = {"red", "blue", "green", "purple"};
/* /*
* functions writing in the svg file * functions writing in the svg file
*/ */
void libhqr_writeheader(FILE *tree){ void libhqr_writeheader(FILE *file){
if(fprintf(tree, "<?xml version=\"1.0\" standalone=\"no\"?>\n" if(fprintf(file, "<?xml version=\"1.0\" standalone=\"no\"?>\n"
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
"<svg width=\"2000\" height=\"2000\" version=\"1.1\" \n xmlns=\"http://www.w3.org/2000/svg\">\n") <0) "<svg width=\"2000\" height=\"2000\" version=\"1.1\" \n xmlns=\"http://www.w3.org/2000/svg\">\n") <0)
return; return;
...@@ -44,25 +44,25 @@ void libhqr_writeheader(FILE *tree){ ...@@ -44,25 +44,25 @@ void libhqr_writeheader(FILE *tree){
* k - Factorization step for the color * k - Factorization step for the color
*/ */
void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *tree){ void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *file){
if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, color[k%4]) < 0 ) if(fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%4]) < 0 )
return; return;
} }
void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *tree){ void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *file){
if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, color[k%4]) < 0 ) if(fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%4]) < 0 )
return; return;
int x2 = x + (w / 4); int x2 = x + (w / 4);
int y2 = y + (h / 4); int y2 = y + (h / 4);
int w2 = (w / 2); int w2 = (w / 2);
int h2 = (h / 2); int h2 = (h / 2);
if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill =\"white\"/> \n", x2, y2, w2, h2) < 0 ) return; if(fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill =\"white\"/> \n", x2, y2, w2, h2) < 0 ) return;
} }
void libhqr_drawline(int x1, int y1, int x2, int y2, FILE *tree){ void libhqr_drawline(int x1, int y1, int x2, int y2, int k, FILE *file){
if(fprintf(tree,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"fill:none;stroke:black;stroke-width:2px;\"/> \n", x1, y1, x2, y2) < 0 ) return; if(fprintf(file,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"fill:none;stroke:%s;stroke-width:2px;\"/> \n", x1, y1, x2, y2, colortree[k%4]) < 0 ) return;
} }
void libhqr_writeend(FILE *tree){ void libhqr_writeend(FILE *file){
if(fprintf(tree, "</svg>") < 0) return; if(fprintf(file, "</svg>") < 0) return;
} }
...@@ -13,10 +13,55 @@ ...@@ -13,10 +13,55 @@
* @date 2017-03-21 * @date 2017-03-21
* *
*/ */
#include "libhqr.h" #include "libhqr.h"
#include "libdraw.h"
#include "queue.h" #include "queue.h"
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include <string.h>
/*
* Common prameters to the 2 following functions:
* k - Factorization step for the color
* p - annihilator
* m - tile eliminated
* file - File where the lines are drawn
* tiles - table stocking the tiles
*/
void draw_horizontal_line(int k, int p, int m, int *tiles, FILE *file){
int y, ordinate1, ordinate2, absciss1, absciss2, absciss3, absciss4;
ordinate1 = SIZE + SIZE * m;
ordinate2 = SIZE + SIZE * p;
absciss1 = (SIZE + (SIZE / 4)) + SIZE * tiles[m];
absciss3 = (SIZE + (SIZE / 4)) + SIZE * tiles[p];
/* Increasing the step */
y = libhqr_imax(tiles[m], tiles[p]) + 1;
tiles[m] = tiles[p] = y;
absciss2 = (SIZE + (SIZE / 4)) + SIZE * tiles[m];
absciss4 = (SIZE + (SIZE / 4)) + SIZE * tiles[p];
libhqr_drawline( absciss1, ordinate1, absciss2, ordinate1, k, file);
libhqr_drawline( absciss3, ordinate2, absciss4, ordinate2, k, file);
}
void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file){
int absciss, ordinate1, ordinate2;
absciss = SIZE + SIZE * tiles[m];
ordinate1 = SIZE + SIZE * m;
ordinate2 = SIZE + SIZE * p;
libhqr_drawline(absciss, ordinate1, absciss, ordinate2, k, file);
}
void draw_rectangle(int k, int p, int m, int *tiles, FILE *file){
int absciss, ordinate;
absciss = ((SIZE * 3) /4) + SIZE * tiles[m];
ordinate = ((SIZE * 3) /4) + SIZE * m;
libhqr_drawTS(absciss, ordinate, WIDTH, HEIGHT, k, file);
ordinate = ((SIZE * 3) /4) + SIZE * p;
libhqr_drawTT(absciss, ordinate, WIDTH, HEIGHT, k, file);
}
/**************************************************** /****************************************************
* LIBHQR_TREEWALK * LIBHQR_TREEWALK
...@@ -31,15 +76,20 @@ ...@@ -31,15 +76,20 @@
* @param[in] k * @param[in] k
* Factorization step * Factorization step
* *
* @param[in] tiles
* Table stocking the tiles and their step
*
* @param[in] file
* File where the tree is drawn
*
*/ */
void libhqr_treewalk(const libhqr_tree_t *qrtree, int k) void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *file)
{ {
int tsid = -1, ttid = -1; int tsid = -1, ttid = -1;
int p = k; int p = k;
int pivot = k; int pivot = k;
libhqr_queue_tile_t *tt = libhqr_queue_tile_new(); libhqr_queue_tile_t *tt = libhqr_queue_tile_new();
libhqr_queue_tile_t *ts = libhqr_queue_tile_new(); libhqr_queue_tile_t *ts = libhqr_queue_tile_new();
libhqr_queue_tile_push(&tt, k); libhqr_queue_tile_push(&tt, k);
while( tt ) while( tt )
...@@ -52,10 +102,10 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k) ...@@ -52,10 +102,10 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k)
(qrtree->prevpiv(qrtree, k, p, p) != qrtree->mt) ) (qrtree->prevpiv(qrtree, k, p, p) != qrtree->mt) )
{ {
libhqr_queue_tile_push(&tt,p); libhqr_queue_tile_push(&tt,p);
printf("PUSH TT: %d\n", p); /* printf("PUSH TT: %d\n", p); */
} }
libhqr_queue_tile_push(&ts, p); libhqr_queue_tile_push(&ts, p);
printf("PUSH TS: %d\n", p); /* printf("PUSH TS: %d\n", p); */
p = qrtree->prevpiv(qrtree, k, pivot, p); p = qrtree->prevpiv(qrtree, k, pivot, p);
assert( p != -1 ); assert( p != -1 );
} }
...@@ -65,12 +115,14 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k) ...@@ -65,12 +115,14 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k)
/* Unstack all element killed by TS, or by TT and already discovered */ /* Unstack all element killed by TS, or by TT and already discovered */
while(tsid != -1 && tsid != ttid) { while(tsid != -1 && tsid != ttid) {
printf( "TS=%d, TT=%d\n", tsid, ttid ); /* printf( "TS=%d, TT=%d\n", tsid, ttid ); */
tsid = libhqr_queue_tile_pop(&ts); tsid = libhqr_queue_tile_pop(&ts);
printf("POP TS: %d\n", tsid); /* printf("POP TS: %d\n", tsid); */
printf("Call function on (%d, %d)\n", /* printf("Call function on (%d, %d)\n",
qrtree->currpiv(qrtree, k, tsid), tsid ); qrtree->currpiv(qrtree, k, tsid), tsid ); */
draw_horizontal_line(k, qrtree->currpiv(qrtree, k, tsid), tsid, tiles, file);
draw_vertical_line(k, qrtree->currpiv(qrtree, k, tsid), tsid, tiles, file);
tsid = libhqr_queue_tile_head(&ts); tsid = libhqr_queue_tile_head(&ts);
} }
pivot = p = ttid; pivot = p = ttid;
...@@ -79,3 +131,30 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k) ...@@ -79,3 +131,30 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k)
assert(ts == NULL); assert(ts == NULL);
assert(tt == NULL); assert(tt == NULL);
} }
/****************************************************
* LIBHQR_PRINT_TREE
***************************************************/
void libhqr_print_tree(const libhqr_tree_t *qrtree, libhqr_tiledesc_t *matrix){
int maxMN, minMN, k, i;
int *tiles;
FILE *file;
maxMN = libhqr_imax(matrix->mt, matrix->nt );
minMN = libhqr_imin(matrix->mt, matrix->nt );
tiles = (int*)malloc(maxMN*sizeof(int));
memset( tiles, 0, maxMN*sizeof(int) );
file = fopen("tree.svg","w+");
libhqr_writeheader(file);
for (k = 0; k < minMN; k++){
/* Drawing the lines */
libhqr_treewalk(qrtree, k, tiles, file);
/* Drawing the rectangles */
for (i = k + 1; i < maxMN; i++){
draw_rectangle(k, qrtree->currpiv(qrtree, k, i), i, tiles, file);
}
}
libhqr_writeend(file);
fclose(file);
free(tiles);
}
...@@ -17,25 +17,21 @@ ...@@ -17,25 +17,21 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "libdraw.h" #include "libdraw.h"
#include "libhqr.h"
#define WIDTH 50
#define HEIGHT 50
int int
main(int argc, char ** argv) main(int argc, char ** argv)
{ {
FILE *tree = fopen("tree.svg","w+"); libhqr_tree_t qrtree;
int x,y,i,j; libhqr_tiledesc_t matrix;
libhqr_writeheader(tree); matrix.nodes = 1;
libhqr_drawline(125,100,125,800,tree); matrix.p = 1;
for (i = 1; i < 5; i++){ matrix.mt = 16;
for (j = 1; j < 9; j++){ matrix.nt = 4;
x = 100*i; libhqr_hqr_init( &qrtree, LIBHQR_QR, &matrix, LIBHQR_BINARY_TREE, LIBHQR_FLAT_TREE, 1, 2, 0, 0);
y = 100*j; libhqr_print_tree( &qrtree, &matrix);
libhqr_drawTS(x,y,WIDTH,HEIGHT,3,tree); libhqr_hqr_finalize( &qrtree );
} return 1;
}
libhqr_writeend(tree);
return 1;
} }
/**
*
* @file testing_treewalk.c
*
* Testing the treewalk algorithm using different kind of matrix
*
* @copyright 2012-2017 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
* Univ. Bordeaux. All rights reserved.
*
* @version 1.0.0
* @author Raphael Boucherie
* @author Mathieu Faverge
* @date 2017-03-21
*
*/
#include "libhqr.h"
#include "queue.h"
#include <stdio.h>
int
main(int argc, char ** argv)
{
libhqr_tree_t qrtree;
libhqr_tiledesc_t matrix;
int minMN, k, rc ;
/*
* Test treewalk for HQR trees
*/
matrix.nodes = 1;
matrix.p = 1;
matrix.mt = 8;
matrix.nt = 4;
libhqr_hqr_init( &qrtree, LIBHQR_QR, &matrix, LIBHQR_FIBONACCI_TREE, LIBHQR_FLAT_TREE, 1, 1, 0, 0);
minMN = libhqr_imin(matrix.mt, matrix.nt );
rc = libhqr_tree_check( &matrix, &qrtree );
printf("%d\n", rc);
for (k=0; k<minMN; k++) {
libhqr_treewalk( &qrtree, k );
}
libhqr_hqr_finalize( &qrtree );
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment