pelib  2.0.0
src/DeadlineFormula.cpp
Go to the documentation of this file.
00001 /*
00002  Copyright 2015 Nicolas Melot
00003 
00004  This file is part of Pelib.
00005 
00006  Pelib 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  Pelib 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 Pelib. If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 #include <cmath>
00022 
00023 #include <pelib/DeadlineFormula.hpp>
00024 #include <pelib/Scalar.hpp>
00025 #include <pelib/Set.hpp>
00026 #include <pelib/Matrix.hpp>
00027 #include <pelib/Vector.hpp>
00028 #include <pelib/ParseException.hpp>
00029 #include <pelib/CastException.hpp>
00030 
00031 #include <pelib/pelib_exprtk.hpp>
00032 
00033 #ifdef debug
00034 #undef debug
00035 #endif
00036 
00037 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << var << "\"" << endl;
00038 
00039 using namespace pelib;
00040 using namespace std;
00041 
00042 DeadlineFormula::DeadlineFormula(string formula) : formula(formula) {}
00043 
00044 double
00045 DeadlineFormula::calculate(const Taskgraph &tg, const Platform &arch) const
00046 {
00047         if(!arch.isHomogeneous())
00048         {
00049                 throw CastException("Cannot compute a deadline for a taskgraph with a heterogeneous platform.");
00050         }
00051 
00052         // Vector of tasks ids, vector of task workloads tau, vector of task max load
00053         vector<double> n, p, F, tau, W;
00054         for(set<Task>::const_iterator iter = tg.getTasks().begin(); iter != tg.getTasks().end(); iter++)
00055         {
00056                 n.push_back((double)std::distance(tg.getTasks().begin(), iter) + 1);
00057                 tau.push_back((double)iter->getWorkload());
00058                 W.push_back((double)iter->getMaxWidth());
00059         }
00060 
00061         for(double i = 1; i <= (double)arch.getCores().size(); i++)
00062         {
00063                 p.push_back(i);
00064         }
00065 
00066         for(set<float>::const_iterator i = (*(arch.getCores().begin()))->getFrequencies().begin(); i != (*(arch.getCores().begin()))->getFrequencies().end(); i++)
00067         {
00068                 F.push_back(*i);
00069         }
00070 
00071         double output = parseDeadline(formula, tg.getTasks(), arch, n, p, F, tau, W);
00072         if(std::isnan(output))
00073         {
00074                 throw ParseException("Error while parsing formula: " + formula);
00075         }       
00076 
00077         return output;
00078 }