Advertisement
nicb

PrimaBozza Esame pt2

Dec 22nd, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. #ifndef MATRICE_H_INCLUDED
  2. #define MATRICE_H_INCLUDED
  3. #include <iostream>
  4. #include <fstream>
  5. #include <math.h>
  6. #include <vector>
  7. #include <limits>
  8.  
  9. using namespace std;
  10.  
  11. class matrice
  12. {
  13. private:
  14.     vector <float> matrix;
  15.     fstream prelevato;
  16.     float app;
  17.     int dimensione;
  18.     int Npath, bestDist, actualDist;
  19.     vector <float> X;
  20.     vector <float> Y;
  21.     vector <bool> visitate;
  22.     vector <int> actualPath;
  23.     vector <int> bestPath;
  24.     double DistanzaGreedy, DistanzaBack;
  25. public:
  26.     matrice(string prelevato_i)
  27.     {
  28.         prelevato.open(prelevato_i, ios::in);
  29.         prelevato>>dimensione;
  30.         dimensione=dimensione+1;
  31.         X.push_back(0);
  32.         Y.push_back(0);
  33.  
  34.         while(!prelevato.eof())
  35.         {
  36.             prelevato>>app;
  37.             X.push_back(app);
  38.             prelevato>>app;
  39.             Y.push_back(app);
  40.         }
  41.         prelevato.close();
  42.         for(int i=0; i<dimensione;i++)
  43.         {
  44.             for(int j=0; j< dimensione; j++)
  45.             {
  46.                 app=sqrt(pow(X[i]-X[j],2)+pow(Y[i]-Y[j],2));
  47.                 matrix.push_back(app);
  48.             }
  49.         }
  50.         for(int i=0; i<dimensione; i++)
  51.         {
  52.             visitate.push_back(false);
  53.         }
  54.         visitate.at(0)=true;
  55.         actualDist=0;
  56.         Npath=0;
  57.         bestDist=INT_MAX;
  58.         actualPath.push_back(0);
  59.         bestPath.push_back(0);
  60.     }
  61.     ~matrice(){;};
  62.     void stampa_matrice()
  63.     {
  64.         for (int i=0; i<dimensione; i++)
  65.         {
  66.             for(int j=0; j< dimensione; j++)
  67.             {
  68.                 cout<<matrix.at(i*dimensione+j)<<"\t\t";
  69.             }
  70.             cout<<endl;
  71.         }
  72.     }
  73.     /*void EseguiPasso(int Npath, int actualDist)
  74.     {
  75.             for(int j=0; j< dimensione; j++)
  76.             {
  77.                 if(visitate.at(j)==false)
  78.                 {
  79.                     if(actualDist + matrix.at(Npath*dimensione+j)+ matrix.at(j*dimensione+1) < bestDist)
  80.                     {
  81.                         bool esplorabile= false;
  82.                         for (int k=0; k< dimensione; k++)
  83.                             esplorabile=visitate.at(k)|esplorabile;
  84.                         if(esplorabile)
  85.                         {
  86.                             actualPath.push_back(j);
  87.                             visitate.at(j)=true;
  88.                             EseguiPasso(Npath+1,actualDist+matrix.at(Npath*dimensione+j));
  89.                             visitate.at(j)=false;
  90.                         }
  91.                     }
  92.                 }
  93.             }
  94.     }*/
  95. };
  96.  
  97.  
  98. #endif // MATRICE_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement