00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 // "node.cpp" 00004 00005 // (c) OPAC Team, LIFL, January 2006 00006 00007 /* This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Contact: cahon@lifl.fr 00022 */ 00023 00024 #include <math.h> 00025 #include <values.h> 00026 00027 #include "node.h" 00028 00029 unsigned numNodes; /* Number of nodes */ 00030 00031 //static unsigned * * dist; /* Square matrix of distances */ 00032 00033 double * X_coord, * Y_coord; 00034 00035 double X_min = MAXDOUBLE, X_max = MINDOUBLE, Y_min = MAXDOUBLE, Y_max = MINDOUBLE; 00036 00037 void loadNodes (FILE * __f) { 00038 00039 /* Coord */ 00040 00041 X_coord = new double [numNodes]; 00042 00043 Y_coord = new double [numNodes]; 00044 00045 unsigned num; 00046 00047 for (unsigned i = 0; i < numNodes; i ++) { 00048 00049 fscanf (__f, "%u%lf%lf", & num, X_coord + i, Y_coord + i); 00050 00051 if (X_coord [i] < X_min) 00052 X_min = X_coord [i]; 00053 if (X_coord [i] > X_max) 00054 X_max = X_coord [i]; 00055 if (Y_coord [i] < Y_min) 00056 Y_min = Y_coord [i]; 00057 if (Y_coord [i] > Y_max) 00058 Y_max = Y_coord [i]; 00059 } 00060 00061 /* Allocation */ 00062 /* 00063 dist = new unsigned * [numNodes]; 00064 00065 for (unsigned i = 0; i < numNodes; i ++) 00066 dist [i] = new unsigned [numNodes]; 00067 */ 00068 /* Computation of the distances */ 00069 00070 /* 00071 for (unsigned i = 0; i < numNodes; i ++) { 00072 00073 dist [i] [i] = 0; 00074 00075 for (unsigned j = 0; j < numNodes; j ++) { 00076 00077 double dx = X_coord [i] - X_coord [j], dy = Y_coord [i] - Y_coord [j]; 00078 00079 dist [i] [j] = dist [j] [i] = (unsigned) (sqrt (dx * dx + dy * dy) + 0.5) ; 00080 } 00081 }*/ 00082 } 00083 00084 unsigned distance (Node __from, Node __to) { 00085 00086 // return dist [__from] [__to]; 00087 00088 double dx = X_coord [__from] - X_coord [__to], dy = Y_coord [__from] - Y_coord [__to]; 00089 00090 return (unsigned) (sqrt (dx * dx + dy * dy) + 0.5) ; 00091 } 00092
1.4.7