Update of /cvsroot/avl/avl/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14056/src
Modified Files:
Makefile avl.cpp test.cpp test.h
Log Message:
Final version up, please test comparate method
Index: test.h
===================================================================
RCS file: /cvsroot/avl/avl/src/test.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** test.h 7 Sep 2004 14:37:01 -0000 1.10
--- test.h 8 Sep 2004 17:59:54 -0000 1.11
***************
*** 39,42 ****
--- 39,43 ----
Avlt* getAvlt();
Bst* getBst();
+ char* getResultLog();
private:
***************
*** 52,56 ****
double change_timer;
int tree_dimensions;
!
};
#endif
--- 53,57 ----
double change_timer;
int tree_dimensions;
! char* result_log;
};
#endif
Index: avl.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/avl.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** avl.cpp 7 Sep 2004 15:33:42 -0000 1.16
--- avl.cpp 8 Sep 2004 17:59:54 -0000 1.17
***************
*** 22,25 ****
--- 22,31 ----
#include <cstdlib>
+ /*
+ A seconda che sia stata scelta la GUI GTK o no
+ vengono compilate funzioni differenti
+ per la raccolta dei dati e il report
+ */
+
using namespace std;
***************
*** 38,41 ****
--- 44,48 ----
GtkWidget *spinbutton2=NULL;
+ // le prossime tre funzioni sono associate al radio button per la scelta del test
void bst_select() {
choice=1;
***************
*** 49,52 ****
--- 56,62 ----
choice=2;
}
+
+ // linkato col bottone start. Fa partire il test scelto e poi aggiorna a video
+ // la visualizzazione dell'albero o il report comparativo.
void start() {
***************
*** 84,88 ****
gtk_widget_show (box1);
! view= gtk_label_new ("Tree display disabled\nComparation test choosen");
gtk_container_add (GTK_CONTAINER (box1), view);
gtk_widget_show (view);
--- 94,99 ----
gtk_widget_show (box1);
! //view= gtk_label_new ("Tree display disabled\nComparation test choosen");
! view=gtk_label_new(prova->getResultLog());
gtk_container_add (GTK_CONTAINER (box1), view);
gtk_widget_show (view);
***************
*** 98,102 ****
}
!
GtkWidget* node_list_start() {
--- 109,113 ----
}
! //inizializza una lista vuota, dopo il test verrà aggiornata con l'albero o il report
GtkWidget* node_list_start() {
***************
*** 168,172 ****
prova = new Test(2,upperbound,base_tree);
}
!
if (choice==0) aux_avl->print_best_look();
if (choice==1) aux_bst->print_best_look();
--- 179,183 ----
prova = new Test(2,upperbound,base_tree);
}
! // stampa colorata
if (choice==0) aux_avl->print_best_look();
if (choice==1) aux_bst->print_best_look();
***************
*** 186,202 ****
GtkWidget *label=NULL;
gtk_init (&argc, &argv);
char* fullname="AVL-BST Tree Visualization";
!
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
gtk_window_set_title (GTK_WINDOW (window), fullname);
gtk_widget_set_usize(window, (int)(gdk_screen_width()*3/4), (int)(gdk_screen_height()*3/4));
-
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
-
gtk_container_set_border_width (GTK_CONTAINER (window), 15);
vpaned1 = gtk_vpaned_new ();
gtk_container_add (GTK_CONTAINER (window), vpaned1);
--- 197,212 ----
GtkWidget *label=NULL;
+ //inizializza GTK
gtk_init (&argc, &argv);
char* fullname="AVL-BST Tree Visualization";
! //crea la main window
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), fullname);
gtk_widget_set_usize(window, (int)(gdk_screen_width()*3/4), (int)(gdk_screen_height()*3/4));
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 15);
+ //crea i due pannelli verticali
vpaned1 = gtk_vpaned_new ();
gtk_container_add (GTK_CONTAINER (window), vpaned1);
***************
*** 206,209 ****
--- 216,220 ----
gtk_widget_show (vpaned2);
+ //crea cinque contenitori orizzontali
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (vpaned2), box1);
***************
*** 230,233 ****
--- 241,245 ----
gtk_widget_show (box5);
+ //il contenitore per la scelta dei test
label = gtk_label_new ("What do you want to test?");
gtk_label_set_justify(GTK_LABEL (label),GTK_JUSTIFY_LEFT);
***************
*** 253,256 ****
--- 265,269 ----
gtk_widget_show (button);
+ //scelta del numero dei nodi
label = gtk_label_new ("Select the number of nodes of the tree");
gtk_label_set_justify(GTK_LABEL (label),GTK_JUSTIFY_LEFT);
***************
*** 266,269 ****
--- 279,283 ----
gtk_widget_show (spinbutton1);
+ //scelta del numero delle modifiche
label = gtk_label_new ("Select the number of operations on the tree");
gtk_label_set_justify(GTK_LABEL (label),GTK_JUSTIFY_LEFT);
***************
*** 279,282 ****
--- 293,297 ----
gtk_widget_show (spinbutton2);
+ //start e quit button
button = gtk_button_new_with_label ("start");
g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (start), G_OBJECT (window));
***************
*** 289,292 ****
--- 304,308 ----
gtk_widget_show (button);
+ //finalizzazione e display
node_list=node_list_start();
***************
*** 302,305 ****
#endif
! return EXIT_SUCCESS;
}
--- 318,321 ----
#endif
! return EXIT_SUCCESS; //vuol dire che ha funzionato senza seg. fault!
}
Index: Makefile
===================================================================
RCS file: /cvsroot/avl/avl/src/Makefile,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Makefile 7 Sep 2004 15:33:42 -0000 1.8
--- Makefile 8 Sep 2004 17:59:54 -0000 1.9
***************
*** 2,6 ****
ifdef gtk_gui
! CC=g++ -O2 -Wall -W `pkg-config gtk+-2.0 --cflags` -DGUI
else
CC=g++ -O2 -Wall -W
--- 2,6 ----
ifdef gtk_gui
! CC=g++ -O2 -Wall -W `pkg-config gtk+-2.0 --cflags` -DGUI
else
CC=g++ -O2 -Wall -W
***************
*** 30,34 ****
$(BINARY): $(LIBS)
$(CC) -o $(BINARY) $(LIBS) $(GTKLIBS)
! strip $(BINARY)
clean:
--- 30,34 ----
$(BINARY): $(LIBS)
$(CC) -o $(BINARY) $(LIBS) $(GTKLIBS)
! # strip $(BINARY)
clean:
Index: test.cpp
===================================================================
RCS file: /cvsroot/avl/avl/src/test.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** test.cpp 7 Sep 2004 15:33:42 -0000 1.13
--- test.cpp 8 Sep 2004 17:59:54 -0000 1.14
***************
*** 17,24 ****
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-
#include "test.h"
Test::~Test() {
--- 17,30 ----
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "test.h"
+ //concatena i risultati del test comparato in una stringa
+ char* Test::getResultLog(){
+
+ return result_log;
+
+ }
+
Test::~Test() {
***************
*** 30,33 ****
--- 36,40 ----
}
+ //ritorna l'albero avl
Avlt* Test::getAvlt() {
***************
*** 35,43 ****
}
Bst* Test::getBst() {
return bst;
}
! //inizializza l'albero voluto
void Test::Test_Init(int base_limit,int kind=0) {
--- 42,53 ----
}
+ //ritorna l'albero bst
Bst* Test::getBst() {
return bst;
}
!
! //inizializza l'albero voluto (avl o bst) inserendo il numero scelto di nodi
! //funziona anche come contatore e time report
void Test::Test_Init(int base_limit,int kind=0) {
***************
*** 85,88 ****
--- 95,100 ----
//testa un AVL
+ // fa un numero scelto di modifiche, scegliendo in modo casuale cancellazioni e inserimenti
+ // di numeri random
void Test::Avl_Test(int upper_limit){
***************
*** 133,136 ****
--- 145,150 ----
}
//testa un BST
+ // fa un numero scelto di modifiche, scegliendo in modo casuale cancellazioni e inserimenti
+ // di numeri random
void Test::Bst_Test(int upper_limit) {
***************
*** 178,181 ****
--- 192,196 ----
//questo metodo fa un confronto delle prestazioni di un AVL e un BST
+ // e riporta i risultati ottenuti
void Test::comparation(int base_tree_size, int upperbound ) {
***************
*** 186,206 ****
GtkWidget *dialog=NULL;
#endif
!
bst=new Bst();
avlt=new Avlt();
Test_Init(base_tree_size,1); //bst
temp_timer=getInitTimer();
! sleep(5);
Test_Init(base_tree_size,0); //avl
#ifndef GUI
! printf("\nInit Result:\nBST -> %lf, AVL -> %lf\n",temp_timer,getInitTimer());
! if ((temp_timer-getInitTimer())>double(0)) printf("***************************\nAVL faster\n***************************\n");
! if ((temp_timer-getInitTimer())<double(0)) printf("***************************\nBST faster\n***************************\n");
! if ((temp_timer-getInitTimer())==double(0)) printf("***************************\nNo real differences found\n***************************\n");
#else
! if ((temp_timer-getInitTimer())>double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Init Result:\nBST -> %lf, AVL -> %lf\n***************************\nAVL faster\n***************************\n",temp_timer,getInitTimer());
! if ((temp_timer-getInitTimer())<double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Init Result:\nBST -> %lf, AVL -> %lf\n***************************\nBST faster\n***************************\n",temp_timer,getInitTimer());
! if ((temp_timer-getInitTimer())==double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Init Result:\nBST -> %lf, AVL -> %lf\n***************************\nNo real differences found\n***************************\n",temp_timer,getInitTimer());
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
--- 201,224 ----
GtkWidget *dialog=NULL;
#endif
! char* msg;
! char buffer[400];
bst=new Bst();
avlt=new Avlt();
+ msg=(char*)malloc(400);
+
Test_Init(base_tree_size,1); //bst
temp_timer=getInitTimer();
! sleep(2);
Test_Init(base_tree_size,0); //avl
+
+ sprintf(buffer,"\nInit Result:\nBST -> %lf, AVL -> %lf\n",temp_timer,getInitTimer());
+ if ((temp_timer-getInitTimer())>double(0)) strcat(buffer,"***************************\nAVL faster\n***************************\n");
+ if ((temp_timer-getInitTimer())<double(0)) strcat(buffer,"***************************\nBST faster\n***************************\n");
+ if ((temp_timer-getInitTimer())==double(0)) strcat(buffer,"***************************\nNo real differences found\n***************************\n");
#ifndef GUI
! printf("%s\n",buffer);
#else
! dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO,GTK_BUTTONS_CLOSE,buffer);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
***************
*** 208,222 ****
Bst_Test(upperbound);
temp_timer=getChangeTimer();
! sleep(5);
Avl_Test(upperbound);
#ifndef GUI
! printf("Random modification test\n");
! if ((temp_timer-getChangeTimer())>double(0)) printf("***************************\nAVL faster\n***************************\n");
! if ((temp_timer-getChangeTimer())<double(0)) printf("***************************\nBST faster\n***************************\n");
! if ((temp_timer-getChangeTimer())==double(0)) printf("***************************\nNo real differences found\n***************************\n");
#else
! if ((temp_timer-getChangeTimer())>double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Random modification test\n***************************\nAVL faster\n***************************\n");
! if ((temp_timer-getChangeTimer())<double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Random modification test\n***************************\nBST faster\n***************************\n");
! if ((temp_timer-getChangeTimer())==double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"Random modification test\n***************************\nNo real differences found\n***************************\n");
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
--- 226,240 ----
Bst_Test(upperbound);
temp_timer=getChangeTimer();
! sleep(2);
Avl_Test(upperbound);
+ sprintf(msg,"%s",buffer);
+ sprintf(buffer,"Random modification test\n");
+ if ((temp_timer-getChangeTimer())>double(0)) strcat(buffer,"***************************\nAVL faster\n***************************\n");
+ if ((temp_timer-getChangeTimer())<double(0)) strcat(buffer,"***************************\nBST faster\n***************************\n");
+ if ((temp_timer-getChangeTimer())==double(0)) strcat(buffer,"***************************\nNo real differences found\n***************************\n");
#ifndef GUI
! printf("%s\n",buffer);
#else
! dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO,GTK_BUTTONS_CLOSE,buffer);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
***************
*** 234,251 ****
end=clock();
temp_timer=((double) (end - start)) / CLOCKS_PER_SEC;
#ifndef GUI
! printf("BST search time of its max value (%d):%lf\nAVL search time of its max value (%d):%lf\n",bst->max()->getValue(),search_timer,max,temp_timer);
! if ((temp_timer-search_timer)<double(0)) printf("***************************\nAVL faster\n***************************\n");
! if ((temp_timer-search_timer)>double(0)) printf("***************************\nBST faster\n***************************\n");
! if ((temp_timer-search_timer)==double(0)) printf("***************************\nNo real differences found\n***************************\n");
#else
! if ((temp_timer-search_timer)<double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"BST search time of its max value (%d):%lf\nAVL search time of its max value (%d):%lf\n***************************\nAVL faster\n***************************\n",bst->max()->getValue(),search_timer,max,temp_timer);
! if ((temp_timer-search_timer)>double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"BST search time of its max value (%d):%lf\nAVL search time of its max value (%d):%lf\n***************************\nBST faster\n***************************\n",bst->max()->getValue(),search_timer,max,temp_timer);
! if ((temp_timer-search_timer)==double(0)) dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,"BST search time of its max value (%d):%lf\nAVL search time of its max value (%d):%lf\n***************************\nNo real differences found\n***************************\n",bst->max()->getValue(),search_timer,max,temp_timer);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
#endif
}
Test::Test(int kind, int upperbound, int base_tree_size) {
--- 252,274 ----
end=clock();
temp_timer=((double) (end - start)) / CLOCKS_PER_SEC;
+ sprintf(msg,"%s %s",msg,buffer);
+ sprintf(buffer,"BST search time of its max value (%d):%lf\nAVL search time of its max value (%d):%lf\n",bst->max()->getValue(),search_timer,max,temp_timer);
+ if ((temp_timer-search_timer)<double(0)) strcat(buffer,"***************************\nAVL faster\n***************************\n");
+ if ((temp_timer-search_timer)>double(0)) strcat(buffer,"***************************\nBST faster\n***************************\n");
+ if ((temp_timer-search_timer)==double(0)) strcat(buffer,"***************************\nNo real differences found\n***************************\n");
#ifndef GUI
! printf("%s\n",buffer);
#else
! dialog=gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO,GTK_BUTTONS_CLOSE,buffer);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
#endif
+ result_log=(char*)malloc(sizeof(msg)+sizeof(buffer));
+ sprintf(result_log,"%s %s",msg,buffer);
+ if(msg) free(msg);
+
}
+ //costruttore
Test::Test(int kind, int upperbound, int base_tree_size) {
***************
*** 259,262 ****
--- 282,286 ----
bst = avlt = NULL;
+ result_log="";
tree_dimensions=base_tree_size;
switch (kind){
***************
*** 280,283 ****
--- 304,308 ----
}
+ //tempo di inizializzazione
double Test::getInitTimer() {
***************
*** 285,288 ****
--- 310,314 ----
}
+ //tempo per le modifiche
double Test::getChangeTimer() {
|