- Main Page
- Classes
- Files

- File List

# OptFrame/Examples/TSP/Representation.h

    00001 #ifndef TSP_REPRESENTATION_H_
    00002 #define TSP_REPRESENTATION_H_
    00003
    00004 #include <vector>
    00005 #include "../../../OptFrame/Util/printable.h"
    00006
    00007 #include "../../../OptFrame/Util/Matrix.hpp"
    00008
    00009 #include "Memory.h"
    00010
    00011 #include <vector>
    00012
    00013 using namespace std;
    00014
    00015 // Solution Representation
    00016 typedef vector < int >  RepTSP;
    00017
    00018 #ifdef MaPI
    00019
    00020 class TSPSerializer : public MyMaPISerializer<RepTSP,MemTSP>
    00021 {
    00022 public:
    00023
    00024         virtual RepTSP KeyA_fromString(string s)
    00025         {
    00026                 //printf("\nINIT================\n");
    00027                 RepTSP r;
    00028                 //cout << "# "<< s << endl;
    00029                 //int i;
    00030                 //cin >> i;
    00031                 Scanner scan(s);
    00032                 scan.useSeparators("()[], ");
    00033
    00034                 scan.next(); // vector
    00035                 scan.next(); // int size
    00036
    00037                 while (scan.hasNext()) r.push_back(scan.nextInt());
    00038
    00039                 //cout << "##" << r << endl;
    00040
    00041                 //printf("\nFIM================\n");
    00042                 return r;
    00043         }
    00044         ;
    00045         virtual string KeyA_toString(RepTSP o)
    00046         {
    00047                 stringstream s;
    00048                 s << o;
    00049                 return s.str();
    00050         }
    00051         ;
    00052
    00053         virtual RankAndStop A_fromString(string s)
    00054         {
    00055                 RankAndStop idd;
    00056                 Scanner scan(s);
    00057                 scan.useSeparators("()[], \t\r\npair");
    00058                 idd.first = scan.nextInt();
    00059                 idd.second.first = scan.nextDouble();
    00060                 idd.second.second = scan.nextDouble();
    00061                 return idd;
    00062         }
    00063         ;
    00064         virtual string A_toString(RankAndStop o)
    00065         {
    00066                 stringstream s;
    00067                 s << o;
    00068                 return s.str();
    00069         }
    00070         ;
    00071
    00072         virtual int KeyB_fromString(string s)
    00073         {
    00074                 return atoi(s.c_str());
    00075         }
    00076         ;
    00077         virtual string KeyB_toString(int o)
    00078         {
    00079                 stringstream s;
    00080                 s << o;
    00081                 return s.str();
    00082         }
    00083         ;
    00084
    00085         virtual pair<RepTSP, double> B_fromString(string s) // TODO
    00086         {
    00087                 //printf("\nINIT================\n%s\n",s.c_str());
    00088                 //cout << "Initializing!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
    00089
    00090                 RepTSP r;
    00091                 double c;
    00092
    00093                 //cout << endl << "# "<< s << endl;
    00094
    00095                 Scanner scan(s);
    00096                 scan.useSeparators("()[], \t\n");
    00097
    00098                 scan.next(); // pair
    00099                 scan.next(); // vector
    00100
    00101 //              cout << scan.next(); // pair
    00102 //              cout << scan.next(); // -1
    00103
    00104 //              cout << scan.next(); // pair
    00105 //              cout << scan.next(); // vector
    00106
    00107                 int size = scan.nextInt(); // int size
    00108
    00109                 //cout << size << "!" << endl;
    00110
    00111                 for (int i = 0 ; i < size && scan.hasNext() ; i++) r.push_back(scan.nextInt());
    00112
    00113                 //int i;                                cin >> i;
    00114
    00115                 //cout << "rest" << scan.rest() << endl;
    00116
    00117                 c = scan.nextDouble();
    00118
    00119                 //cout << c << endl;
    00120
    00121                 //cout << "##" << r << " c=" << c << endl;
    00122                 //printf("\nFIM================\n");
    00123                 return make_pair(r,c);
    00124         }
    00125         ;
    00126         virtual string B_toString(pair<RepTSP, double> o)
    00127         {
    00128                 stringstream s;
    00129                 s << o;
    00130                 return s.str();
    00131         }
    00132         ;
    00133
    00134         virtual RepTSP C_fromString(string s)
    00135         {
    00136                 RepTSP r;
    00137                 //cout << "# "<< s << endl;
    00138                 //int i;
    00139                 //cin >> i;
    00140                 Scanner scan(s);
    00141                 scan.useSeparators("()[], ");
    00142
    00143                 scan.next(); // vector
    00144                 scan.next(); // int size
    00145
    00146                 while (scan.hasNext()) r.push_back(scan.nextInt());
    00147
    00148                 //cout << "##" << r << endl;
    00149
    00150                 return r;
    00151         }
    00152         ;
    00153         virtual string C_toString(RepTSP o)
    00154         {
    00155                 stringstream s;
    00156                 s << o;
    00157                 return s.str();
    00158         }
    00159         ;
    00160
    00161 };
    00162
    00163 #endif
    00164
    00165 #endif /*TSP_REPRESENTATION_H_*/
    00166

All Classes Functions