crown  1.0.0
src/crown-ilp-integrated.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 <fstream>
00023 
00024 #include <pelib/argument_parsing.hpp>
00025 #include <pelib/dl.h>
00026 #include <pelib/Scalar.hpp>
00027 
00028 #include <crown/crown-scheduler.hpp>
00029 #include <crown/CrownILPIntegrated.hpp>
00030 
00031 #ifdef debug
00032 #undef debug
00033 #endif
00034 
00035 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << (var) << "\"" << endl;
00036 
00037 using namespace std;
00038 using namespace pelib;
00039 using namespace crown;
00040 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045 struct args
00046 {
00047         double alpha, eta, zeta, kappa;
00048         pelib_argument_stream lib;
00049         bool showError, showOutput;
00050         
00051 };
00052 typedef struct args args_t;
00053 
00054 static args_t
00055 parse(char **args)
00056 {
00057         args_t out;
00058         out.showError = false;
00059         out.showOutput = false;
00060         out.alpha = 3;
00061         out.zeta = 0.649;
00062         out.eta = 0.018611;
00063         out.kappa = 52.639161335;
00064         //out.configSrc = BINARY;
00065         pelib_argument_stream_init(&out.lib);
00066 
00067         for(; args[0] != NULL; args++)
00068         {
00069                 if(strcmp(args[0], "--show-stdout") == 0)
00070                 {
00071                         out.showOutput = true;
00072                         continue;
00073                 }
00074                 if(strcmp(args[0], "--show-stderr") == 0)
00075                 {
00076                         out.showError = true;
00077                         continue;
00078                 }
00079                 if(strcmp(args[0], "--alpha") == 0)
00080                 {
00081                         args++;
00082                         stringstream str(args[0]);
00083                         str >> out.alpha;
00084                         continue;
00085                 }
00086                 if(strcmp(args[0], "--eta") == 0)
00087                 {
00088                         args++;
00089                         stringstream str(args[0]);
00090                         str >> out.eta;
00091                         continue;
00092                 }
00093                 if(strcmp(args[0], "--zeta") == 0)
00094                 {
00095                         args++;
00096                         stringstream str(args[0]);
00097                         str >> out.zeta;
00098                         continue;
00099                 }
00100                 if(strcmp(args[0], "--kappa") == 0)
00101                 {
00102                         args++;
00103                         stringstream str(args[0]);
00104                         str >> out.kappa;
00105                         continue;
00106                 }
00107                 if(strcmp(args[0], "--config") == 0)
00108                 {
00109                         args++;
00110                         args += pelib_argument_stream_parse(args, &out.lib) - 1;
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;
00129 
00130         // Convert solver output to general schedule
00131         if(args.lib.library == NULL)
00132         {
00133                 scheduler = new CrownILPIntegrated(param, NULL, args.showOutput, args.showError);
00134         }
00135         else
00136         {
00137                 char *library = args.lib.library;
00138                 void *libConfig = load_lib(library);
00139                 CrownConfig* (*config)(size_t argc, char **argv) = (CrownConfig* (*)(size_t argc, char **argv))load_function(libConfig, "crown_config");
00140                 CrownConfig* conf = config(args.lib.argc, args.lib.argv);
00141                 scheduler = new CrownILPIntegrated(param, conf, args.showOutput, args.showError);
00142                 void (*del)(CrownConfig *) = (void (*)(CrownConfig*))load_function(libConfig, "crown_delete_config");
00143                 del(conf);
00144                 destroy_lib(libConfig);
00145         }
00146 
00147         return scheduler;
00148 }
00149 
00150 #ifdef __cplusplus
00151 }
00152 #endif
00153