Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
shortest path algorithm already working
[simgrid.git] / testsuite / xbt / graphxml_usage.c
1 /*      $Id$      */
2
3 /* A few basic tests for the graphxml library                               */
4
5 /* Copyright (c) 2006 Darina Dimitrova, Arnaud Legrand. All rights reserved.*/
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include <stdio.h>
11 #include <xbt/module.h>
12 #include "xbt/graph.h"
13 #include "xbt/graphxml.h"
14 #include "xbt/dynar.h"
15 #include <malloc.h>
16
17
18
19 void test(char *graph_file);
20 void test(char *graph_file)
21 {
22   int i,j;
23   unsigned long n;
24   xbt_dynar_t dynar=NULL;
25   xbt_dynar_t dynar1=NULL;
26   xbt_node_t * route=NULL;
27
28   xbt_graph_t graph = xbt_graph_read(graph_file);
29   n=xbt_dynar_length(xbt_graph_get_nodes( graph));
30
31   double *adj=xbt_graph_get_length_matrix(graph);
32  
33  
34  for(i=0;i<n;i++)
35     {
36       for(j=0;j<n;j++)
37         {
38           fprintf(stderr,"%le\t",adj[i*n+j] );
39         }
40       fprintf(stderr,"\n" );
41     }
42
43
44 route= xbt_graph_shortest_paths( graph);
45  
46   /* for(i=0;i<n;i++) */
47 /*     { */
48 /*       for(j=0;j<n;j++) */
49 /*      { */
50 /*       /\*  fprintf(stderr,"%le\t",(char*)((r[i*n+j])->data) ); *\/ */
51 /*      } */
52 /*       fprintf(stderr,"\n" ); */
53 /*     } */
54
55   
56
57  
58  
59  /*  while(xbt_dynar_length(dynar)) */
60 /*     xbt_graph_free_node(graph,*((xbt_node_t*)xbt_dynar_get_ptr(dynar,0)),NULL,NULL); */
61
62   dynar = xbt_graph_get_edges(graph);
63 while(xbt_dynar_length(dynar))
64     xbt_graph_free_edge(graph,*((xbt_edge_t*)xbt_dynar_get_ptr(dynar,0)),NULL);
65  
66   printf("%lu edges\n",xbt_dynar_length(dynar));
67  dynar1 = xbt_graph_get_nodes(graph);
68  printf("%lu nodes\n",xbt_dynar_length(dynar1));
69 /*  free(d); */
70   xbt_graph_free_graph(graph, NULL, NULL, NULL);
71 }
72
73 int main(int argc, char** argv)
74 {
75   xbt_init(&argc,argv);
76   if(argc==1) 
77     {
78      fprintf(stderr,"Usage : %s graph.xml\n",argv[0]);
79   
80      return 1;
81   }
82   test(argv[1]);
83
84   return 0;
85 }