crown
1.0.0
|
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 #include <pelib/Algebra.hpp> 00021 #include <pelib/Scalar.hpp> 00022 #include <pelib/AmplSolver.hpp> 00023 #include <pelib/Vector.hpp> 00024 #include <pelib/Matrix.hpp> 00025 #include <pelib/AmplInput.hpp> 00026 00027 #include <crown/CrownILPIntegrated.hpp> 00028 #include <crown/CrownScheduler.hpp> 00029 #include <crown/CrownConfigBinary.hpp> 00030 #include <crown/CrownException.hpp> 00031 00032 #ifdef debug 00033 #undef debug 00034 #endif 00035 00036 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << (var) << "\"" << endl; 00037 00038 using namespace std; 00039 using namespace pelib; 00040 using namespace crown; 00041 00042 extern char _binary_crown_integrated_mod_start; 00043 extern char _binary_crown_integrated_mod_end; 00044 extern char _binary_crown_integrated_run_start; 00045 extern char _binary_crown_integrated_run_end; 00046 00047 Algebra 00048 CrownILPIntegrated::solve(const Algebra &tg, const Algebra &pt, const pelib::Algebra ¶m, std::map<const std::basic_string<char>, double> &statistics) const 00049 { 00050 map<const string, const Algebra> data; 00051 data.insert(pair<const string, const Algebra>(string("taskgraph.dat"), tg)); 00052 data.insert(pair<const string, const Algebra>(string("platform.dat"), pt)); 00053 data.insert(pair<const string, const Algebra>(string("parameters.dat"), param)); 00054 00055 // Build model and run scripts input streams 00056 stringstream model(string(&_binary_crown_integrated_mod_start, &_binary_crown_integrated_mod_end)); 00057 stringstream run(string(&_binary_crown_integrated_run_start, &_binary_crown_integrated_run_end)); 00058 // Run the solver 00059 const Algebra *solution = AmplSolver(model, string("model.mod"), run, data, this->showOutput, this->showError).solve(statistics); 00060 Algebra alg = *solution; 00061 00062 return alg; 00063 } 00064 00065 Schedule 00066 CrownILPIntegrated::schedule(const Taskgraph &tg, const Platform &pt, const Algebra ¶m, map<const string, double> &statistics) const 00067 { 00068 // Build input collection 00069 //map<const string, const Algebra> data; 00070 Algebra taskgraph = tg.buildAlgebra(pt); 00071 00072 if(taskgraph.find<Vector<int, string> >("name") == NULL) 00073 { 00074 CrownException("Cannot find tasks' vector name in Taskgraph conversion to Algebra record."); 00075 } 00076 Vector<int, string> name = *taskgraph.find<Vector<int, string> >("name"); 00077 taskgraph.remove("name"); 00078 00079 Algebra p = this->addCrownConfig(tg, pt, param, statistics); 00080 float time_config = 0; 00081 const Scalar<float> *time_config_scalar = p.find<Scalar<float> >("time_crown_config"); 00082 if(time_config_scalar != NULL) 00083 { 00084 time_config = time_config_scalar->getValue(); 00085 } 00086 00087 //AmplInput(AmplInput::intFloatHandlers()).dump(cout, pt.buildAlgebra()); 00088 // Solve the problem 00089 Algebra res = solve(taskgraph, pt.buildAlgebra(), p, statistics); 00090 00091 map<const string, double>::iterator ii = statistics.find("time"); 00092 if(ii != statistics.end()) 00093 { 00094 double time = ii->second; 00095 statistics.erase(ii); 00096 statistics.insert(pair<const string, double>("time_schedule", time)); 00097 statistics.insert(pair<const string, double>("time_config", time_config)); 00098 statistics.insert(pair<const string, double>("time_global", time + time_config)); 00099 } 00100 00101 // Insert back tasks' names 00102 res.insert(new Vector<int, string>(name)); 00103 00104 if(statistics.find("feasible")->second != 0) 00105 { 00106 res = crownToSchedule(res); 00107 res = Schedule::addStartTime(res, tg, pt); 00108 Schedule sched("Crown ILP Integrated", tg.getName(), res); 00109 00110 return sched; 00111 } 00112 else 00113 { 00114 return Schedule("Crown ILP Integrated", tg.getName(), Schedule::table()); 00115 } 00116 } 00117 00118 Schedule 00119 CrownILPIntegrated::schedule(const Taskgraph &tg, const Platform &pt, map<const string, double> &statistics) const 00120 { 00121 return schedule(tg, pt, param, statistics); 00122 } 00123 00124 CrownILPIntegrated::CrownILPIntegrated(const CrownConfig* config, bool showOutput, bool showError) : CrownScheduler(config, showOutput, showError) 00125 { 00126 /* Do nothing else */ 00127 } 00128 00129 CrownILPIntegrated::CrownILPIntegrated(const Algebra ¶m, const CrownConfig* config, bool showOutput, bool showError) : CrownScheduler(param, config, showOutput, showError) 00130 { 00131 /* Do nothing else */ 00132 } 00133 00134 CrownILPIntegrated::CrownILPIntegrated(const Taskgraph &tg, const Platform &pt, const Algebra ¶m, const CrownConfig* config, bool showOutput, bool showError) : CrownScheduler(tg, pt, param, config, showOutput, showError) 00135 { 00136 /* Do nothing else */ 00137 } 00138 00139 CrownILPIntegrated::CrownILPIntegrated(const CrownILPIntegrated &src) : CrownScheduler(src.tg, src.pt, src.param, src.config, src.showOutput, src.showError) 00140 { 00141 /* Do nothing else */ 00142 } 00143 00144 string 00145 CrownILPIntegrated::getShortDescription() const 00146 { 00147 float alpha = this->param.find<Scalar<float> >("alpha")->getValue(); 00148 float kappa = this->param.find<Scalar<float> >("kappa")->getValue(); 00149 float eta = this->param.find<Scalar<float> >("eta")->getValue(); 00150 float zeta = this->param.find<Scalar<float> >("zeta")->getValue(); 00151 stringstream ss; 00152 00153 const CrownConfig *config = this->config; 00154 if(config == NULL) 00155 { 00156 config = getDefaultConfig(); 00157 } 00158 00159 std::streamsize p = ss.precision(); 00160 ss.precision(4); 00161 ss << "Cr.ILP.Int-" << config->getShortDescription() << "(a=" << alpha << ",k=" << kappa << ",e=" << eta << ",z=" << zeta << ")"; 00162 ss.precision(p); 00163 00164 if(this->config == NULL) 00165 { 00166 delete config; 00167 } 00168 return ss.str(); 00169 } 00170 00171 float 00172 CrownILPIntegrated::complexity(const Algebra &problem) const 00173 { 00174 return 0; 00175 } 00176 00177 float 00178 CrownILPIntegrated::complexity(const Taskgraph &tg, const Platform &pt, const Algebra ¶m) const 00179 { 00180 return 0; 00181 } 00182 00183 CrownILPIntegrated* 00184 CrownILPIntegrated::clone() const 00185 { 00186 return new CrownILPIntegrated(*this); 00187 } 00188