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/Task.hpp> 00025 #include <pelib/XMLSchedule.hpp> 00026 #include <pelib/AmplInput.hpp> 00027 #include <pelib/AmplSolver.hpp> 00028 #include <pelib/argument_parsing.hpp> 00029 #include <pelib/scheduler.h> 00030 #include <pelib/dl.h> 00031 00032 #include <crown/CrownBinaryAnnealing.hpp> 00033 #include <crown/CrownConfigBinary.hpp> 00034 #include <crown/CrownConfigOrgan.hpp> 00035 #include <crown/CrownConfigTaskgraph.hpp> 00036 00037 #ifdef debug 00038 #undef debug 00039 #endif 00040 00041 #define debug(var) cout << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #var << " = \"" << (var) << "\"" << endl; 00042 00043 using namespace std; 00044 using namespace pelib; 00045 using namespace crown; 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00051 struct args 00052 { 00053 double alpha, eta, zeta, kappa; 00054 float init_temp, cooling, temp_final, max_trans, max_new, distance; 00055 bool showError, showOutput; 00056 00057 }; 00058 typedef struct args args_t; 00059 00060 static args_t 00061 parse(char **args) 00062 { 00063 args_t out; 00064 out.showError = false; 00065 out.showOutput = false; 00066 out.alpha = 3; 00067 out.zeta = 0.649; 00068 out.eta = 0.018611; 00069 out.kappa = 52.639161335; 00070 00071 out.init_temp = 8; 00072 out.cooling = 0.6; 00073 out.temp_final = 0.9; 00074 out.max_trans = 2; 00075 out.max_new = 2; 00076 out.distance = 0.5; 00077 00078 for(; args[0] != NULL; args++) 00079 { 00080 if(strcmp(args[0], "--show-stdout") == 0) 00081 { 00082 out.showOutput = true; 00083 continue; 00084 } 00085 if(strcmp(args[0], "--show-stderr") == 0) 00086 { 00087 out.showError = true; 00088 continue; 00089 } 00090 if(strcmp(args[0], "--alpha") == 0) 00091 { 00092 args++; 00093 stringstream str(args[0]); 00094 str >> out.alpha; 00095 continue; 00096 } 00097 if(strcmp(args[0], "--eta") == 0) 00098 { 00099 args++; 00100 stringstream str(args[0]); 00101 str >> out.eta; 00102 continue; 00103 } 00104 if(strcmp(args[0], "--zeta") == 0) 00105 { 00106 args++; 00107 stringstream str(args[0]); 00108 str >> out.zeta; 00109 continue; 00110 } 00111 if(strcmp(args[0], "--kappa") == 0) 00112 { 00113 args++; 00114 stringstream str(args[0]); 00115 str >> out.kappa; 00116 continue; 00117 } 00118 if(strcmp(args[0], "--init-temperature") == 0) 00119 { 00120 args++; 00121 stringstream str(args[0]); 00122 str >> out.init_temp; 00123 continue; 00124 } 00125 if(strcmp(args[0], "--cooling-factor") == 0) 00126 { 00127 args++; 00128 stringstream str(args[0]); 00129 str >> out.cooling; 00130 continue; 00131 } 00132 if(strcmp(args[0], "--final-temperature") == 0) 00133 { 00134 args++; 00135 stringstream str(args[0]); 00136 str >> out.temp_final; 00137 continue; 00138 } 00139 if(strcmp(args[0], "--max-transformations") == 0) 00140 { 00141 args++; 00142 stringstream str(args[0]); 00143 str >> out.max_trans; 00144 continue; 00145 } 00146 if(strcmp(args[0], "--max-new-state") == 0) 00147 { 00148 args++; 00149 stringstream str(args[0]); 00150 str >> out.max_new; 00151 continue; 00152 } 00153 if(strcmp(args[0], "--distance") == 0) 00154 { 00155 args++; 00156 stringstream str(args[0]); 00157 str >> out.distance; 00158 continue; 00159 } 00160 } 00161 00162 return out; 00163 } 00164 00165 const CrownScheduler* 00166 crown_scheduler(size_t argc, char **argv, const CrownScheduler *composite) 00167 { 00168 args_t args = parse(argv); 00169 Algebra param; 00170 param.insert(new Scalar<float>("alpha", args.alpha)); 00171 param.insert(new Scalar<float>("eta", args.eta)); 00172 param.insert(new Scalar<float>("zeta", args.zeta)); 00173 param.insert(new Scalar<float>("kappa", args.kappa)); 00174 00175 // Convert solver output to general schedule 00176 return new CrownBinaryAnnealing(param, args.init_temp, args.cooling, args.temp_final, args.max_trans, args.max_new, args.distance, NULL, args.showOutput, args.showError); 00177 } 00178 00179 #ifdef __cplusplus 00180 } 00181 #endif