- Main Page
- Classes
- Files

- File List

# OptFrame/Examples/TSP/ProblemInstance.hpp

    00001 #ifndef TSP_PROBLEMINSTANCE_HPP_
    00002 #define TSP_PROBLEMINSTANCE_HPP_
    00003
    00004 #include <iostream>
    00005
    00006 #include "../../../OptFrame/Util/Scanner++/Scanner.h"
    00007
    00008 using namespace std;
    00009
    00010 #include <iostream>
    00011 #include <values.h>
    00012
    00013 #include "../../../OptFrame/Util/Scanner++/Scanner.h"
    00014 #include "../../../OptFrame/Util/Matrix.hpp"
    00015
    00016 using namespace std;
    00017
    00018 class TSPProblemInstance
    00019 {
    00020 public:
    00021         TSPProblemInstance(Scanner& scanner)
    00022         {
    00023                 n = scanner.nextInt();
    00024
    00025                 cout << n << endl;
    00026
    00027                 // Initializing values
    00028                 xvalues = new vector<double>(n);
    00029                 yvalues = new vector<double>(n);
    00030
    00031
    00032                 // Initializing distance matrix
    00033                 dist = new Matrix<double>( n, n );
    00034                 //dist->fill(INT_MAX);
    00035
    00036                 for(int i=0;i<n;i++)
    00037                 {
    00038                         //cout << scanner.next(); << "\t"; // id
    00039                         scanner.next();
    00040                         (*xvalues)[i] = scanner.nextDouble(); // x
    00041                         //cout << (*xvalues)[i] << "\t";
    00042                         (*yvalues)[i] = scanner.nextDouble(); // y
    00043                         //cout << (*yvalues)[i] << endl;
    00044                 }
    00045
    00046                 cout << "All data read ok!" << endl;
    00047
    00048
    00049                 // Calculating the distances
    00050                 for(int i=0;i<n;i++)
    00051                         for(int j=0;j<n;j++)
    00052                                 (*dist)(i,j)=distance(xvalues->at(i),yvalues->at(i),xvalues->at(j),yvalues->at(j));
    00053
    00054                 //cout << (*dist);
    00055         }
    00056
    00057 //private:
    00058         // Your private vars
    00059         int n;
    00060
    00061         Matrix<double>* dist;
    00062
    00063         vector<double>* xvalues;
    00064         vector<double>* yvalues;
    00065
    00066         double distance(double x1, double y1, double x2, double y2)
    00067         {
    00068                 return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
    00069         }
    00070
    00071 };
    00072
    00073
    00074 #endif /*TSP_PROBLEMINSTANCE_HPP_*/

All Classes Functions