crown
1.0.0
|
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 <fstream> 00023 00024 #include <pelib/argument_parsing.hpp> 00025 #include <pelib/dl.h> 00026 #include <pelib/Scalar.hpp> 00027 00028 #include <crown/CrownCompositeConsolidation.hpp> 00029 00030 #ifdef debug 00031 #undef debug 00032 #endif 00033 00034 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << (var) << "\"" << endl; 00035 00036 using namespace std; 00037 using namespace pelib; 00038 using namespace crown; 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 struct args 00045 { 00046 double alpha, eta, zeta, kappa; 00047 vector<pelib_argument_stream> composite; 00048 bool showError, showOutput; 00049 00050 }; 00051 typedef struct args args_t; 00052 00053 static args_t 00054 parse(char **args) 00055 { 00056 args_t out; 00057 out.showError = false; 00058 out.showOutput = false; 00059 out.alpha = 3; 00060 out.zeta = 0.649; 00061 out.eta = 0.018611; 00062 out.kappa = 52.639161335; 00063 00064 for(; args[0] != NULL; args++) 00065 { 00066 if(strcmp(args[0], "--show-stdout") == 0) 00067 { 00068 out.showOutput = true; 00069 continue; 00070 } 00071 if(strcmp(args[0], "--show-stderr") == 0) 00072 { 00073 out.showError = true; 00074 continue; 00075 } 00076 if(strcmp(args[0], "--alpha") == 0) 00077 { 00078 args++; 00079 stringstream str(args[0]); 00080 str >> out.alpha; 00081 continue; 00082 } 00083 if(strcmp(args[0], "--eta") == 0) 00084 { 00085 args++; 00086 stringstream str(args[0]); 00087 str >> out.eta; 00088 continue; 00089 } 00090 if(strcmp(args[0], "--zeta") == 0) 00091 { 00092 args++; 00093 stringstream str(args[0]); 00094 str >> out.zeta; 00095 continue; 00096 } 00097 if(strcmp(args[0], "--kappa") == 0) 00098 { 00099 args++; 00100 stringstream str(args[0]); 00101 str >> out.kappa; 00102 continue; 00103 } 00104 if(strcmp(args[0], "--composite") == 0) 00105 { 00106 args++; 00107 pelib_argument_stream compo; 00108 pelib_argument_stream_init(&compo); 00109 args += pelib_argument_stream_parse(args, &compo) - 1; 00110 out.composite.push_back(compo); 00111 continue; 00112 } 00113 } 00114 00115 return out; 00116 } 00117 00118 const CrownScheduler* 00119 crown_scheduler(size_t argc, char **argv, const CrownScheduler *composite) 00120 { 00121 args_t args = parse(argv); 00122 Algebra param; 00123 param.insert(new Scalar<float>("alpha", args.alpha)); 00124 param.insert(new Scalar<float>("eta", args.eta)); 00125 param.insert(new Scalar<float>("zeta", args.zeta)); 00126 param.insert(new Scalar<float>("kappa", args.kappa)); 00127 00128 CrownScheduler *scheduler = NULL; 00129 for(vector<pelib_argument_stream>::iterator i = args.composite.begin(); i != args.composite.end(); i++) 00130 { 00131 pelib_argument_stream compo = *i; 00132 void *libCompo = load_lib(compo.library); 00133 const CrownScheduler* (*sched)(size_t argc, char **argv, const CrownScheduler*) = (const CrownScheduler* (*)(size_t argc, char **argv, const CrownScheduler*))load_function(libCompo, "crown_scheduler"); 00134 const CrownScheduler *new_scheduler = sched(compo.argc, compo.argv, scheduler); 00135 if(scheduler != NULL) 00136 { 00137 delete scheduler; 00138 } 00139 scheduler = new_scheduler->clone(); 00140 void (*del)(const CrownScheduler*) = (void (*)(const CrownScheduler*))load_function(libCompo, "crown_delete_scheduler"); 00141 del(new_scheduler); 00142 destroy_lib(libCompo); 00143 } 00144 00145 CrownCompositeConsolidation *final = new CrownCompositeConsolidation(param, scheduler, args.showOutput, args.showError); 00146 00147 if(scheduler != NULL) 00148 { 00149 delete scheduler; 00150 } 00151 00152 return final; 00153 } 00154 00155 #ifdef __cplusplus 00156 } 00157 #endif 00158