model/library.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/trunk/src/model/library.cpp $ 00003 version : $LastChangedRevision: 1315 $ $LastChangedBy: jdetaeye $ 00004 date : $LastChangedDate: 2010-07-17 18:08:53 +0200 (Sat, 17 Jul 2010) $ 00005 ***************************************************************************/ 00006 00007 /*************************************************************************** 00008 * * 00009 * Copyright (C) 2007-2010 by Johan De Taeye * 00010 * * 00011 * This library is free software; you can redistribute it and/or modify it * 00012 * under the terms of the GNU Lesser General Public License as published * 00013 * by the Free Software Foundation; either version 2.1 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00019 * General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * 00024 * USA * 00025 * * 00026 ***************************************************************************/ 00027 00028 #define FREPPLE_CORE 00029 #include "frepple/model.h" 00030 #include <sys/stat.h> 00031 00032 namespace frepple 00033 { 00034 00035 void LibraryModel::initialize() 00036 { 00037 // Initialize only once 00038 static bool init = false; 00039 if (init) 00040 { 00041 logger << "Warning: Calling frepple::LibraryModel::initialize() more " 00042 << "than once." << endl; 00043 return; 00044 } 00045 init = true; 00046 00047 // Initialize the utilities library 00048 LibraryUtils::initialize(); 00049 00050 // Register new types in Python 00051 int nok = 0; 00052 nok += Plan::initialize(); 00053 00054 // Initialize the solver metadata. 00055 nok += Solver::initialize(); 00056 nok += SolverIterator::initialize(); 00057 00058 // Initialize the location metadata. 00059 nok += Location::initialize(); 00060 nok += LocationDefault::initialize(); 00061 nok += LocationIterator::initialize(); 00062 00063 // Initialize the customer metadata. 00064 nok += Customer::initialize(); 00065 nok += CustomerDefault::initialize(); 00066 nok += CustomerIterator::initialize(); 00067 00068 // Initialize the calendar metadata. 00069 nok += Calendar::initialize(); 00070 nok += CalendarBool::initialize(); 00071 nok += CalendarVoid::initialize(); 00072 nok += CalendarDouble::initialize(); 00073 nok += CalendarString::initialize(); 00074 nok += CalendarInt::initialize(); 00075 nok += CalendarOperation::initialize(); 00076 nok += CalendarIterator::initialize(); 00077 00078 // Initialize the operation metadata. 00079 nok += Operation::initialize(); 00080 nok += OperationAlternate::initialize(); 00081 nok += OperationFixedTime::initialize(); 00082 nok += OperationTimePer::initialize(); 00083 nok += OperationRouting::initialize(); 00084 nok += OperationSetup::initialize(); 00085 nok += OperationIterator::initialize(); 00086 00087 // Initialize the item metadata. 00088 nok += Item::initialize(); 00089 nok += ItemDefault::initialize(); 00090 nok += ItemIterator::initialize(); 00091 00092 // Initialize the buffer metadata. 00093 nok += Buffer::initialize(); 00094 nok += BufferDefault::initialize(); 00095 nok += BufferInfinite::initialize(); 00096 nok += BufferProcure::initialize(); 00097 nok += BufferIterator::initialize(); 00098 00099 // Initialize the demand metadata. 00100 nok += Demand::initialize(); 00101 nok += DemandIterator::initialize(); 00102 nok += DemandDefault::initialize(); 00103 nok += DemandPlanIterator::initialize(); 00104 00105 // Initialize the setupmatrix metadata. 00106 nok += SetupMatrix::initialize(); 00107 nok += SetupMatrixDefault::initialize(); 00108 nok += SetupMatrixIterator::initialize(); 00109 00110 // Initialize the resource metadata. 00111 nok += Resource::initialize(); 00112 nok += ResourceDefault::initialize(); 00113 nok += ResourceInfinite::initialize(); 00114 nok += ResourceIterator::initialize(); 00115 00116 // Initialize the load metadata. 00117 nok += Load::initialize(); 00118 nok += LoadIterator::initialize(); 00119 nok += LoadPlan::initialize(); 00120 nok += LoadPlanIterator::initialize(); 00121 00122 // Initialize the flow metadata. 00123 nok += Flow::initialize(); 00124 nok += FlowIterator::initialize(); 00125 nok += FlowPlan::initialize(); 00126 nok += FlowPlanIterator::initialize(); 00127 00128 // Initialize the operationplan metadata. 00129 nok += OperationPlan::initialize(); 00130 nok += OperationPlanIterator::initialize(); 00131 00132 // Initialize the problem metadata. 00133 nok += Problem::initialize(); 00134 nok += ProblemIterator::initialize(); 00135 00136 // Initialize the pegging metadata. 00137 nok += PeggingIterator::initialize(); 00138 00139 // Exit if errors were found 00140 if (nok) throw RuntimeException("Error registering new Python types"); 00141 00142 // Register new methods in Python 00143 PythonInterpreter::registerGlobalMethod( 00144 "loadmodule", CommandLoadLibrary::executePython, METH_VARARGS, 00145 "Dynamically load a module in memory."); 00146 PythonInterpreter::registerGlobalMethod( 00147 "printsize", CommandPlanSize::executePython, METH_NOARGS, 00148 "Print information about the memory consumption."); 00149 PythonInterpreter::registerGlobalMethod( 00150 "erase", CommandErase::executePython, METH_VARARGS, 00151 "Removes the plan data from memory, and optionally the static info too."); 00152 PythonInterpreter::registerGlobalMethod( 00153 "readXMLdata", CommandReadXMLString::executePython, METH_VARARGS, 00154 "Processes an XML string passed as argument."); 00155 PythonInterpreter::registerGlobalMethod( 00156 "readXMLfile", CommandReadXMLFile::executePython, METH_VARARGS, 00157 "Read an XML-file."); 00158 PythonInterpreter::registerGlobalMethod( 00159 "saveXMLfile", CommandSave::executePython, METH_VARARGS, 00160 "Save the model to an XML-file."); 00161 PythonInterpreter::registerGlobalMethod( 00162 "saveplan", CommandSavePlan::executePython, METH_VARARGS, 00163 "Save the main plan information to a file."); 00164 PythonInterpreter::registerGlobalMethod( 00165 "buffers", BufferIterator::create, METH_NOARGS, 00166 "Returns an iterator over the buffers."); 00167 PythonInterpreter::registerGlobalMethod( 00168 "locations", LocationIterator::create, METH_NOARGS, 00169 "Returns an iterator over the locations."); 00170 PythonInterpreter::registerGlobalMethod( 00171 "customers", CustomerIterator::create, METH_NOARGS, 00172 "Returns an iterator over the customer."); 00173 PythonInterpreter::registerGlobalMethod( 00174 "items", ItemIterator::create, METH_NOARGS, 00175 "Returns an iterator over the items."); 00176 PythonInterpreter::registerGlobalMethod( 00177 "calendars", CalendarIterator::create, METH_NOARGS, 00178 "Returns an iterator over the calendars."); 00179 PythonInterpreter::registerGlobalMethod( 00180 "demands", DemandIterator::create, METH_NOARGS, 00181 "Returns an iterator over the demands."); 00182 PythonInterpreter::registerGlobalMethod( 00183 "resources", ResourceIterator::create, METH_NOARGS, 00184 "Returns an iterator over the resources."); 00185 PythonInterpreter::registerGlobalMethod( 00186 "operations", OperationIterator::create, METH_NOARGS, 00187 "Returns an iterator over the operations."); 00188 PythonInterpreter::registerGlobalMethod( 00189 "operationplans", OperationPlanIterator::create, METH_NOARGS, 00190 "Returns an iterator over the operationplans."); 00191 PythonInterpreter::registerGlobalMethod( 00192 "problems", ProblemIterator::create, METH_NOARGS, 00193 "Returns an iterator over the problems."); 00194 PythonInterpreter::registerGlobalMethod( 00195 "setupmatrices", SetupMatrixIterator::create, METH_NOARGS, 00196 "Returns an iterator over the setup matrices."); 00197 PythonInterpreter::registerGlobalMethod( 00198 "solvers", SolverIterator::create, METH_NOARGS, 00199 "Returns an iterator over the solvers."); 00200 } 00201 00202 00203 DECLARE_EXPORT void CommandPlanSize::execute() 00204 { 00205 size_t count, memsize; 00206 00207 // Log 00208 if (getVerbose()) 00209 logger << "Start size report at " << Date::now() << endl; 00210 Timer t; 00211 00212 // Intro 00213 logger << endl << "Size information of frePPLe " << PACKAGE_VERSION 00214 << " (" << __DATE__ << ")" << endl << endl; 00215 00216 // Print current locale 00217 #if defined(HAVE_SETLOCALE) || defined(_MSC_VER) 00218 logger << "Locale: " << setlocale(LC_ALL,NULL) << endl << endl; 00219 #else 00220 logger << endl; 00221 #endif 00222 00223 // Print loaded modules 00224 CommandLoadLibrary::printModules(); 00225 00226 // Print the number of clusters 00227 logger << "Clusters: " << HasLevel::getNumberOfClusters() 00228 << " (hanging: " << HasLevel::getNumberOfHangingClusters() << ")" 00229 << endl << endl; 00230 00231 // Header for memory size 00232 logger << "Memory usage:" << endl; 00233 logger << "Model \tNumber\tMemory" << endl; 00234 logger << "----- \t------\t------" << endl; 00235 00236 // Plan 00237 size_t total = Plan::instance().getSize(); 00238 logger << "Plan \t1\t"<< Plan::instance().getSize() << endl; 00239 00240 // Locations 00241 memsize = 0; 00242 for (Location::iterator l = Location::begin(); l != Location::end(); ++l) 00243 memsize += l->getSize(); 00244 logger << "Location \t" << Location::size() << "\t" << memsize << endl; 00245 total += memsize; 00246 00247 // Customers 00248 memsize = 0; 00249 for (Customer::iterator c = Customer::begin(); c != Customer::end(); ++c) 00250 memsize += c->getSize(); 00251 logger << "Customer \t" << Customer::size() << "\t" << memsize << endl; 00252 total += memsize; 00253 00254 // Buffers 00255 memsize = 0; 00256 for (Buffer::iterator b = Buffer::begin(); b != Buffer::end(); ++b) 00257 memsize += b->getSize(); 00258 logger << "Buffer \t" << Buffer::size() << "\t" << memsize << endl; 00259 total += memsize; 00260 00261 // Setup matrices 00262 memsize = 0; 00263 for (SetupMatrix::iterator s = SetupMatrix::begin(); s != SetupMatrix::end(); ++s) 00264 memsize += s->getSize(); 00265 logger << "Setup matrix \t" << SetupMatrix::size() << "\t" << memsize << endl; 00266 total += memsize; 00267 00268 // Resources 00269 memsize = 0; 00270 for (Resource::iterator r = Resource::begin(); r != Resource::end(); ++r) 00271 memsize += r->getSize(); 00272 logger << "Resource \t" << Resource::size() << "\t" << memsize << endl; 00273 total += memsize; 00274 00275 // Operations, flows and loads 00276 size_t countFlows(0), memFlows(0), countLoads(0), memLoads(0); 00277 memsize = 0; 00278 for (Operation::iterator o = Operation::begin(); o != Operation::end(); ++o) 00279 { 00280 memsize += o->getSize(); 00281 for (Operation::flowlist::const_iterator fl = o->getFlows().begin(); 00282 fl != o->getFlows().end(); ++ fl) 00283 { 00284 ++countFlows; 00285 memFlows += fl->getSize(); 00286 } 00287 for (Operation::loadlist::const_iterator ld = o->getLoads().begin(); 00288 ld != o->getLoads().end(); ++ ld) 00289 { 00290 ++countLoads; 00291 memLoads += ld->getSize(); 00292 } 00293 } 00294 logger << "Operation \t" << Operation::size() << "\t" << memsize << endl; 00295 logger << "Flow \t" << countFlows << "\t" << memFlows << endl; 00296 logger << "Load \t" << countLoads << "\t" << memLoads << endl; 00297 total += memsize + memFlows + memLoads; 00298 00299 // Calendars (which includes the buckets) 00300 memsize = 0; 00301 for (Calendar::iterator cl = Calendar::begin(); cl != Calendar::end(); ++cl) 00302 memsize += cl->getSize(); 00303 logger << "Calendar \t" << Calendar::size() << "\t" << memsize << endl; 00304 total += memsize; 00305 00306 // Items 00307 memsize = 0; 00308 for (Item::iterator i = Item::begin(); i != Item::end(); ++i) 00309 memsize += i->getSize(); 00310 logger << "Item \t" << Item::size() << "\t" << memsize << endl; 00311 total += memsize; 00312 00313 // Demands 00314 memsize = 0; 00315 for (Demand::iterator dm = Demand::begin(); dm != Demand::end(); ++dm) 00316 memsize += dm->getSize(); 00317 logger << "Demand \t" << Demand::size() << "\t" << memsize << endl; 00318 total += memsize; 00319 00320 // Operationplans 00321 size_t countloadplans(0), countflowplans(0); 00322 memsize = count = 0; 00323 for (OperationPlan::iterator j = OperationPlan::begin(); 00324 j!=OperationPlan::end(); ++j) 00325 { 00326 ++count; 00327 memsize += sizeof(*j); 00328 countloadplans += j->sizeLoadPlans(); 00329 countflowplans += j->sizeFlowPlans(); 00330 } 00331 total += memsize; 00332 logger << "OperationPlan\t" << count << "\t" << memsize << endl; 00333 00334 // Flowplans 00335 memsize = countflowplans * sizeof(FlowPlan); 00336 total += memsize; 00337 logger << "FlowPlan \t" << countflowplans << "\t" << memsize << endl; 00338 00339 // Loadplans 00340 memsize = countloadplans * sizeof(LoadPlan); 00341 total += memsize; 00342 logger << "LoadPlan \t" << countloadplans << "\t" << memsize << endl; 00343 00344 // Problems 00345 memsize = count = 0; 00346 for (Problem::const_iterator pr = Problem::begin(); pr!=Problem::end(); ++pr) 00347 { 00348 ++count; 00349 memsize += pr->getSize(); 00350 } 00351 total += memsize; 00352 logger << "Problem \t" << count << "\t" << memsize << endl; 00353 00354 // TOTAL 00355 logger << "Total \t\t" << total << endl << endl; 00356 00357 // Log 00358 if (getVerbose()) 00359 logger << "Finished size report at " << Date::now() << " : " << t << endl; 00360 } 00361 00362 00363 }
Documentation generated for frePPLe by
