- Main Page
- Classes
- Files

- Search for |

# node.cpp

    00001 // "node.cpp"
    00002
    00003 // (c) OPAC Team, LIFL, January 2006
    00004
    00005 /*
    00006    Contact: paradiseo-help@lists.gforge.inria.fr
    00007 */
    00008
    00009 #include <math.h>
    00010 #include <values.h>
    00011
    00012 #include "node.h"
    00013
    00014 unsigned numNodes; /* Number of nodes */
    00015
    00016 //static unsigned * * dist; /* Square matrix of distances */
    00017
    00018 double * X_coord, * Y_coord;
    00019
    00020 double X_min = MAXDOUBLE, X_max = MINDOUBLE, Y_min = MAXDOUBLE, Y_max = MINDOUBLE;
    00021
    00022 void loadNodes (FILE * __f) {
    00023
    00024   /* Coord */
    00025
    00026   X_coord = new double [numNodes];
    00027
    00028   Y_coord = new double [numNodes];
    00029
    00030   unsigned num;
    00031
    00032   for (unsigned i = 0; i < numNodes; i ++) {
    00033
    00034     fscanf (__f, "%u%lf%lf", & num, X_coord + i, Y_coord + i);
    00035
    00036     if (X_coord [i] < X_min)
    00037       X_min = X_coord [i];
    00038     if (X_coord [i] > X_max)
    00039       X_max = X_coord [i];
    00040     if (Y_coord [i] < Y_min)
    00041       Y_min = Y_coord [i];
    00042     if (Y_coord [i] > Y_max)
    00043       Y_max = Y_coord [i];
    00044   }
    00045
    00046   /* Allocation */
    00047   /*
    00048   dist = new unsigned * [numNodes];
    00049
    00050   for (unsigned i = 0; i < numNodes; i ++)
    00051     dist [i] = new unsigned [numNodes];
    00052   */
    00053   /* Computation of the distances */
    00054
    00055   /*
    00056   for (unsigned i = 0; i < numNodes; i ++) {
    00057
    00058     dist [i] [i] = 0;
    00059
    00060     for (unsigned j = 0; j < numNodes; j ++) {
    00061
    00062       double dx = X_coord [i] - X_coord [j], dy = Y_coord [i] - Y_coord [j];
    00063
    00064       dist [i] [j] = dist [j] [i] = (unsigned) (sqrt (dx * dx + dy * dy) + 0.5) ;
    00065     }
    00066     }*/
    00067 }
    00068
    00069 unsigned distance (Node __from, Node __to) {
    00070
    00071   //  return dist [__from] [__to];
    00072
    00073   double dx = X_coord [__from] - X_coord [__to], dy = Y_coord [__from] - Y_coord [__to];
    00074
    00075   return (unsigned) (sqrt (dx * dx + dy * dy) + 0.5) ;
    00076 }
    00077