N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/OrbisQuartus/control/ksection_test.cpp

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
00033  */
00034 
00035 
00036 #include <test.h>
00037 #include <configuration.h>
00038 #include "network_graph.h"
00039 #include "ksection.h"
00040 
00041 
00042 #define MAX_SCALE   7
00043 
00044 
00045 int main(int argc, char *argv[])
00046 {
00047         int error = 0, i, j, k = 4;
00048         int max_scale = MAX_SCALE;
00049 
00050         if (argc > 1)
00051                 max_scale = atoi(argv[1]);
00052 
00053         printf("\n");
00054         for (i = 2; i <= max_scale; i++) {
00055                 int num_nodes = (int) pow(2.0, (double) i);
00056                 FILE *file;
00057                 Configuration config("WGS 84");
00058 
00059                 if ((file = fopen("test_tmp.cfg", "w")) == NULL) {
00060                     perror("test_tmp.cfg");
00061                     return -errno;
00062                 }
00063 
00064                 fprintf(file, "<?xml version=\"1.0\"?>\n");
00065                 fprintf(file, "<sensor_net>\n");
00066                 fprintf(file, "  <topology>\n");
00067                 fprintf(file, "    <name>Test %d</name>\n", i);
00068                 fprintf(file, "    <viewpoint>\n");
00069                 fprintf(file, "      <latitude>35.871334</latitude>\n");
00070                 fprintf(file, "      <longitude>-106.326067</longitude>\n");
00071                 fprintf(file, "      <range>500</range>\n");
00072                 fprintf(file, "      <tilt>0</tilt>\n");
00073                 fprintf(file, "      <heading>0</heading>\n");
00074                 fprintf(file, "    </viewpoint>\n");
00075                 for (j = 0; j < num_nodes; j++) {
00076                         fprintf(file, "    <node id=\"%d\">\n", j);
00077                         fprintf(file, "      <random size=\"500\"/>\n");
00078                         fprintf(file, "    </node>\n");
00079                 }
00080                 fprintf(file, "  </topology>\n");
00081                 fprintf(file, "  <network_data>\n");
00082                 fprintf(file, "  </network_data>\n");
00083                 fprintf(file, "</sensor_net>\n");
00084                 fclose(file);
00085 
00086                 if ((error = config.open("test_tmp.cfg")) < 0) {
00087                         printf("Failed to load %d-node config.\n", 
00088                                num_nodes);
00089                         goto end;
00090                 }
00091 
00092 
00093                 Network_graph g(&config);
00094                 Ksection assignments(&g, k);
00095                 printf("%d-section successfully drawn from %d-node graph.\n",
00096                        k, num_nodes);
00097 
00098 #if 0           /* enable for detailed output */
00099                 assignments.print();
00100 #endif
00101         }
00102 
00103  end:
00104         return error;
00105 }


© 2007, Los Alamos National Security, LLC.