crown  1.0.0
src/crowngen_dat.cpp
Go to the documentation of this file.
00001 /*
00002  Copyright 2015 Nicolas Melot
00003 
00004  This file is part of Crown.
00005 
00006  Crown is free software: you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation, either version 3 of the License, or
00009  (at your option) any later version.
00010 
00011  Crown is distributed in the hope that it will be useful,
00012  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  GNU General Public License for more details.
00015 
00016  You should have received a copy of the GNU General Public License
00017  along with Crown. If not, see <http://www.gnu.org/licenses/>.
00018 
00019 */
00020 
00021 
00022 #include <iostream>
00023 #include <cstdlib>
00024 #include <fstream>
00025 #include <string>
00026 #include <boost/regex.hpp>
00027 #include <iomanip>
00028 
00029 #include <pelib/AmplInput.hpp>
00030 #include <pelib/AmplOutput.hpp>
00031 
00032 #include <pelib/AmplOutputScalar.hpp>
00033 #include <pelib/AmplOutputVector.hpp>
00034 #include <pelib/AmplOutputSet.hpp>
00035 #include <pelib/AmplOutputMatrix.hpp>
00036 
00037 #include <pelib/AmplInputScalar.hpp>
00038 #include <pelib/AmplInputVector.hpp>
00039 #include <pelib/AmplInputSet.hpp>
00040 #include <pelib/AmplInputMatrix.hpp>
00041 
00042 using namespace pelib;
00043 using namespace std;
00044 
00045 const int b = 2;
00046 
00047 typedef map<int, int> TaskWidthVector;
00048 typedef map<int, int> TaskScheduleVector;
00049 typedef map<int, TaskScheduleVector> ProcScheduleMatrix;
00050 
00051 int
00052 group_size(int group, int p, int b)
00053 {
00054         return (int)(p / pow(b, floor((log(group) / log(b)))));
00055 }
00056 
00057 Algebra
00058 parse(AlgebraParser &parser, std::istream &input)
00059 {
00060         Algebra rec;
00061         
00062         try {
00063                 rec = parser.parse(input);
00064         } catch(ParseException &e)
00065         {
00066                 std::cerr << e.what() << std::endl;
00067         }
00068 
00069         return rec;
00070 }
00071 
00072 void
00073 printf_int_float_vector(map<int, float> vect)
00074 {
00075         for(map<int, float>::iterator i = vect.begin(); i != vect.end(); i++)
00076         {
00077                 cout << i->first << " " << i->second << endl;
00078         }
00079         cout << ";" << endl;
00080 }
00081 
00082 int
00083 main(int argc, char **argv)
00084 {
00085         AmplInput input(AmplInput::floatHandlers());
00086         AmplInput output(AmplInput::floatHandlers());
00087         Algebra rec;
00088 
00089         // Open input file
00090         //std::ifstream myfile;
00091         //myfile.open (argv[1], std::ios::in);
00092 
00093         // Load input file
00094         //rec = parse(input, myfile);
00095         rec = parse(input, cin);
00096 
00097         // Close input file
00098         //myfile.close();
00099 
00100         cout << setprecision(6)
00101         << setiosflags(ios::fixed)
00102         << setiosflags(ios::showpoint);
00103         
00104         //int n = rec.find<Scalar<float> >("n")->getValue();
00105         int p = (int)rec.find<Scalar<float> >("p")->getValue();
00106         int b = (int)rec.find<Scalar<float> >("b")->getValue();
00107         //Scalar<float> alpha("alpha", (float)rec.find<Scalar<float> >("alpha")->getValue());
00108         Scalar<float> alpha("alpha", 3.0);
00109         Scalar<float> L("L", (int)(log(p) / log(b)));
00110         Scalar<float> R("R", (float)(0.3));
00111 //      Vector<int, float> yy("yy", rec.find<Vector<int, float> >("group")->getValues());
00112         map<int, float> vector_tau = rec.find<Vector<int, float> >("Tau")->getValues();
00113         
00114         // Outputs all useful information for schedule evaluation
00115         output.dump(cout, &L);
00116         output.dump(cout, rec.find<Scalar<float> >("b"));
00117         output.dump(cout, rec.find<Scalar<float> >("n"));
00118         cout << endl;
00119         output.dump(cout, rec.find<Vector<int, float> >("Wi"));
00120         cout << endl;
00121         cout << "param: Tau := # Task workload" << endl;
00122         printf_int_float_vector(vector_tau);
00123         cout << endl;
00124         output.dump(cout, rec.find<Matrix<int, int, float> >("e"));
00125         cout << endl;
00126         cout << "#";
00127         output.dump(cout, rec.find<Scalar<float> >("zeta"));
00128         cout << "#";
00129         output.dump(cout, &alpha);
00130         cout << "#";
00131         output.dump(cout, &R);
00132         cout << "#";
00133         {
00134                 const Scalar<float> *M = rec.find<Scalar<float> >("M");
00135                 if(M != NULL)
00136                 {
00137                         output.dump(cout, M);
00138                 }
00139         }
00140         {
00141                 const Scalar<float> *M = rec.find<Scalar<float> >("M");
00142                 if(M != NULL)
00143                 {
00144                         output.dump(cout, M);
00145                 }
00146         }
00147         cout << "#";
00148         output.dump(cout, rec.find<Set<float> >("F"));
00149         cout << endl;
00150         cout << endl;
00151         //output.dump(cout, rec.find<Vector<int, float> >("wi"));
00152         cout << endl;
00153         cout << endl;
00154         cout << endl;
00155 //      output.dump(cout, &yy);
00156         cout << "## Frequency" << endl;
00157         output.dump(cout, rec.find<Set<float> >("F"));
00158         output.dump(cout, &alpha);
00159         cout << endl;
00160         cout << "## Cost parameters" << endl;
00161         output.dump(cout, rec.find<Scalar<float> >("M"));
00162         output.dump(cout, rec.find<Scalar<float> >("zeta"));
00163         
00164         return EXIT_SUCCESS;
00165 }