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
LDFLAGS = -lm
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/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
testing_pivgen : testings/testing_pivgen.o ${LIBHQR}
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
testing_treewalk : testings/testing_treewalk.c ${LIBHQR}
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
testing_treedraw : testings/testing_treedraw.o ${LIBHQR}
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
......@@ -34,4 +31,4 @@ clean :
cleanall: clean
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 @@
#define _LIBDRAW_H_
#include <common.h>
#define WIDTH 50
#define HEIGHT 50
#define SIZE 100
BEGIN_C_DECLS
......@@ -31,11 +34,11 @@ extern char *color[4];
* function for treedraw
*/
void libhqr_writeheader(FILE *tree);
void libhqr_writeend(FILE *tree);
void libhqr_drawTT(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 *tree);
void libhqr_drawline(int x1, int y1, int x2, int y2, FILE *tree);
void libhqr_writeheader(FILE *file);
void libhqr_writeend(FILE *file);
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 *file);
void libhqr_drawline(int x1, int y1, int x2, int y2, int k, FILE *file);
END_C_DECLS
......
......@@ -19,6 +19,7 @@
#define _LIBHQR_H_
#include "common.h"
#include <stdio.h>
BEGIN_C_DECLS
......@@ -190,10 +191,14 @@ int libhqr_hqr_init( 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
......
......@@ -22,14 +22,14 @@
* Global array for color
*/
char *color[4] = {"red", "blue", "green", "purple"};
char *colortree[4] = {"red", "blue", "green", "purple"};
/*
* functions writing in the svg file
*/
void libhqr_writeheader(FILE *tree){
if(fprintf(tree, "<?xml version=\"1.0\" standalone=\"no\"?>\n"
void libhqr_writeheader(FILE *file){
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"
"<svg width=\"2000\" height=\"2000\" version=\"1.1\" \n xmlns=\"http://www.w3.org/2000/svg\">\n") <0)
return;
......@@ -44,25 +44,25 @@ void libhqr_writeheader(FILE *tree){
* k - Factorization step for the color
*/
void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *tree){
if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, color[k%4]) < 0 )
void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *file){
if(fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%4]) < 0 )
return;
}
void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *tree){
if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, color[k%4]) < 0 )
void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *file){
if(fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%4]) < 0 )
return;
int x2 = x + (w / 4);
int y2 = y + (h / 4);
int w2 = (w / 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){
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;
void libhqr_drawline(int x1, int y1, int x2, int y2, int k, FILE *file){
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){
if(fprintf(tree, "</svg>") < 0) return;
void libhqr_writeend(FILE *file){
if(fprintf(file, "</svg>") < 0) return;
}
......@@ -13,10 +13,55 @@
* @date 2017-03-21
*
*/
#include "libhqr.h"
#include "libdraw.h"
#include "queue.h"
#include <stdio.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
......@@ -31,15 +76,20 @@
* @param[in] k
* 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 p = k;
int pivot = k;
libhqr_queue_tile_t *tt = libhqr_queue_tile_new();
libhqr_queue_tile_t *ts = libhqr_queue_tile_new();
libhqr_queue_tile_push(&tt, k);
while( tt )
......@@ -52,10 +102,10 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k)
(qrtree->prevpiv(qrtree, k, p, p) != qrtree->mt) )
{
libhqr_queue_tile_push(&tt,p);
printf("PUSH TT: %d\n", p);
/* printf("PUSH TT: %d\n", 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);
assert( p != -1 );
}
......@@ -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 */
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);
printf("POP TS: %d\n", tsid);
printf("Call function on (%d, %d)\n",
qrtree->currpiv(qrtree, k, tsid), tsid );
/* printf("POP TS: %d\n", tsid); */
/* printf("Call function on (%d, %d)\n",
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);
}
pivot = p = ttid;
......@@ -79,3 +131,30 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k)
assert(ts == 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 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "libdraw.h"
#define WIDTH 50
#define HEIGHT 50
#include "libhqr.h"
int
main(int argc, char ** argv)
{
FILE *tree = fopen("tree.svg","w+");
int x,y,i,j;
libhqr_writeheader(tree);
libhqr_drawline(125,100,125,800,tree);
for (i = 1; i < 5; i++){
for (j = 1; j < 9; j++){
x = 100*i;
y = 100*j;
libhqr_drawTS(x,y,WIDTH,HEIGHT,3,tree);
}
}
libhqr_writeend(tree);
return 1;
libhqr_tree_t qrtree;
libhqr_tiledesc_t matrix;
matrix.nodes = 1;
matrix.p = 1;
matrix.mt = 16;
matrix.nt = 4;
libhqr_hqr_init( &qrtree, LIBHQR_QR, &matrix, LIBHQR_BINARY_TREE, LIBHQR_FLAT_TREE, 1, 2, 0, 0);
libhqr_print_tree( &qrtree, &matrix);
libhqr_hqr_finalize( &qrtree );
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.
Finish editing this message first!
Please register or to comment