Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 026739a8 authored by BOUCHERIE Raphael's avatar BOUCHERIE Raphael
Browse files

Treewalk is working

parent d106ce7d
No related branches found
No related tags found
1 merge request!4Treewalk
......@@ -20,7 +20,7 @@
BEGIN_C_DECLS
typedef struct libhqr_queue_tile_s{
typedef struct libhqr_queue_tile_s {
struct libhqr_queue_tile_s *prev;
struct libhqr_queue_tile_s *next;
int numero;
......@@ -35,6 +35,11 @@ void libhqr_queue_tile_prev (libhqr_queue_tile_t ** queue_tile);
void libhqr_queue_tile_last (libhqr_queue_tile_t ** queue_tile);
void libhqr_queue_tile_next (libhqr_queue_tile_t ** queue_tile);
void libhqr_queue_tile_push (libhqr_queue_tile_t ** queue_tile, int numero);
int libhqr_queue_tile_head (libhqr_queue_tile_t ** queue_tile);
int libhqr_queue_tile_pop (libhqr_queue_tile_t ** queue_tile);
void libhqr_queue_tile_delete(libhqr_queue_tile_t ** queue_tile);
END_C_DECLS
#endif /* _QUEUE_H_ */
......@@ -16,6 +16,7 @@
#include "queue.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
/****************************************************
* Generic functions for queue
......@@ -26,6 +27,62 @@ libhqr_queue_tile_t *libhqr_queue_tile_new (void)
return (NULL);
}
void libhqr_queue_tile_push (libhqr_queue_tile_t ** queue_tile, int numero)
{
if (queue_tile != NULL)
{
libhqr_queue_tile_t *p_l = NULL;
libhqr_queue_tile_t *p_p = NULL;
assert( (*queue_tile) == NULL || (*queue_tile)->prev == NULL );
p_l = *queue_tile;
p_p = malloc (sizeof (*p_p));
if (p_p != NULL)
{
p_p->numero = numero;
p_p->next = p_l;
p_p->prev = NULL;
if (p_l != NULL)
p_l->prev = p_p;
*queue_tile = p_p;
}
else
{
fprintf (stderr, "Memoire insuffisante\n");
exit (EXIT_FAILURE);
}
}
return;
}
int libhqr_queue_tile_head (libhqr_queue_tile_t ** queue_tile)
{
if (queue_tile != NULL && *queue_tile != NULL)
{
return (*queue_tile)->numero;
}
return -1;
}
int libhqr_queue_tile_pop (libhqr_queue_tile_t ** queue_tile)
{
int ret = -1;
if (queue_tile != NULL)
{
libhqr_queue_tile_t *p_l = NULL;
libhqr_queue_tile_t *p_p = NULL;
p_l = *queue_tile;
p_p = p_l->next;
if (p_p != NULL)
p_p->prev = NULL;
ret = p_l->numero;
free (p_l);
*queue_tile = p_p;
}
return (ret);
}
void libhqr_queue_tile_first (libhqr_queue_tile_t ** queue_tile)
{
if (queue_tile != NULL && *queue_tile != NULL)
......
......@@ -16,6 +16,7 @@
#include "libhqr.h"
#include "queue.h"
#include <stdio.h>
#include <assert.h>
/****************************************************
* LIBHQR_TREEWALK
......@@ -31,35 +32,50 @@
* Factorization step
*
*/
void libhqr_treewalk(const libhqr_tree_t *qrtree, int k)
{
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();
void libhqr_treewalk(const libhqr_tree_t *qrtree,int k){
int pivot = qrtree->mt;
printf("%d\n" , pivot);
int p = pivot;
printf("%d\n" , qrtree->prevpiv(qrtree, k, pivot, p));
int a,b;
libhqr_queue_tile_t *tt = libhqr_queue_tile_new();
libhqr_queue_tile_t *ts = libhqr_queue_tile_new();
while(p = qrtree->prevpiv(qrtree, k, pivot, p)){
while(p = qrtree->nextpiv(qrtree, k, pivot, p)){
if(qrtree->gettype(qrtree, k, p)){
libhqr_queue_tile_post(&tt,p);
}
libhqr_queue_tile_post(&ts, p);
}
libhqr_queue_tile_last(&ts);
libhqr_queue_tile_last(&tt);
a = ts->numero;
printf("%d\n" , a);
b = tt->numero;
printf("%d\n" , b);
while(a != b){
libhqr_queue_tile_get(&ts);
libhqr_queue_tile_last(&ts);
a = ts->numero;
printf("%d\n" , a);
}
libhqr_queue_tile_last(&tt);
libhqr_queue_tile_get(&tt);
}
libhqr_queue_tile_push(&tt, k);
while( tt )
{
/* Stack all elements killed on the way down */
p = qrtree->prevpiv(qrtree, k, pivot, p);
while( p != qrtree->mt ) {
/* If it's a TS tile, or a TT at the bottom of the tree that kills noone */
if( (qrtree->gettype(qrtree, k, p) == 0) ||
(qrtree->prevpiv(qrtree, k, p, p) != qrtree->mt) )
{
libhqr_queue_tile_push(&tt,p);
printf("PUSH TT: %d\n", p);
}
libhqr_queue_tile_push(&ts, p);
printf("PUSH TS: %d\n", p);
p = qrtree->prevpiv(qrtree, k, pivot, p);
assert( p != -1 );
}
tsid = libhqr_queue_tile_head(&ts);
ttid = libhqr_queue_tile_pop(&tt);
/* 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 );
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 );
tsid = libhqr_queue_tile_head(&ts);
}
pivot = p = ttid;
}
assert(ts == NULL);
assert(tt == NULL);
}
......@@ -27,16 +27,18 @@ main(int argc, char ** argv)
* Test treewalk for HQR trees
*/
matrix.nodes = 1;
matrix.p = 1;
matrix.mt = 4;
matrix.nt = 13;
matrix.p = 1;
matrix.mt = 8;
matrix.nt = 4;
int matrix2[matrix.mt][matrix.nt];
libhqr_hqr_init( &qrtree, LIBHQR_QR, &matrix, -1 , -1 , -1 , -1, 0, 0);
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_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