00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #define FREPPLE_CORE
00028 #include "frepple/model.h"
00029 #include <sys/stat.h>
00030
00031 namespace frepple
00032 {
00033
00034 DECLARE_EXPORT const MetaCategory* Solver::metadata;
00035
00036
00037 DECLARE_EXPORT const MetaCategory* Load::metadata;
00038
00039
00040 DECLARE_EXPORT const MetaCategory* Location::metadata;
00041 DECLARE_EXPORT const MetaClass* LocationDefault::metadata;
00042
00043
00044 DECLARE_EXPORT const MetaCategory* Buffer::metadata;
00045 DECLARE_EXPORT const MetaClass* BufferDefault::metadata,
00046 *BufferInfinite::metadata,
00047 *BufferProcure::metadata;
00048
00049
00050 DECLARE_EXPORT const MetaCategory* Calendar::metadata;
00051 DECLARE_EXPORT const MetaCategory* Calendar::Bucket::metadata;
00052 DECLARE_EXPORT const MetaClass *CalendarVoid::metadata,
00053 *CalendarDouble::metadata,
00054 *CalendarInt::metadata,
00055 *CalendarBool::metadata,
00056 *CalendarString::metadata,
00057 *CalendarOperation::metadata;
00058
00059
00060 DECLARE_EXPORT const MetaCategory* Flow::metadata;
00061 DECLARE_EXPORT const MetaClass* FlowStart::metadata,
00062 *FlowEnd::metadata;
00063
00064
00065 DECLARE_EXPORT const MetaCategory* Operation::metadata;
00066 DECLARE_EXPORT const MetaClass* OperationFixedTime::metadata,
00067 *OperationTimePer::metadata,
00068 *OperationRouting::metadata,
00069 *OperationAlternate::metadata;
00070
00071
00072 DECLARE_EXPORT const MetaClass* OperationPlan::metadata;
00073 DECLARE_EXPORT const MetaCategory* OperationPlan::metacategory;
00074
00075
00076 DECLARE_EXPORT const MetaCategory* Resource::metadata;
00077 DECLARE_EXPORT const MetaClass* ResourceDefault::metadata;
00078 DECLARE_EXPORT const MetaClass* ResourceInfinite::metadata;
00079
00080
00081 DECLARE_EXPORT const MetaCategory* Item::metadata;
00082 DECLARE_EXPORT const MetaClass* ItemDefault::metadata;
00083
00084
00085 DECLARE_EXPORT const MetaCategory* Customer::metadata;
00086 DECLARE_EXPORT const MetaClass* CustomerDefault::metadata;
00087
00088
00089 DECLARE_EXPORT const MetaCategory* Demand::metadata;
00090 DECLARE_EXPORT const MetaClass* DemandDefault::metadata;
00091
00092
00093 DECLARE_EXPORT const MetaCategory* Plan::metadata;
00094
00095
00096 DECLARE_EXPORT const MetaCategory* Problem::metadata;
00097 DECLARE_EXPORT const MetaClass* ProblemMaterialExcess::metadata,
00098 *ProblemMaterialShortage::metadata,
00099 *ProblemExcess::metadata,
00100 *ProblemShort::metadata,
00101 *ProblemEarly::metadata,
00102 *ProblemLate::metadata,
00103 *ProblemDemandNotPlanned::metadata,
00104 *ProblemPlannedEarly::metadata,
00105 *ProblemPlannedLate::metadata,
00106 *ProblemPrecedence::metadata,
00107 *ProblemBeforeFence::metadata,
00108 *ProblemBeforeCurrent::metadata,
00109 *ProblemCapacityUnderload::metadata,
00110 *ProblemCapacityOverload::metadata;
00111
00112
00113 void LibraryModel::initialize()
00114 {
00115
00116 static bool init = false;
00117 if (init)
00118 {
00119 logger << "Warning: Calling frepple::LibraryModel::initialize() more "
00120 << "than once." << endl;
00121 return;
00122 }
00123 init = true;
00124
00125
00126 LibraryUtils::initialize();
00127
00128
00129
00130
00131
00132 Plan::thePlan = new Plan();
00133
00134
00135 Plan::metadata = new MetaCategory("plan","");
00136
00137
00138 Solver::metadata = new MetaCategory
00139 ("solver", "solvers", Solver::reader, Solver::writer);
00140
00141
00142 Location::metadata = new MetaCategory
00143 ("location", "locations", Location::reader, Location::writer);
00144 LocationDefault::metadata = new MetaClass("location", "location_default",
00145 Object::createString<LocationDefault>, true);
00146
00147
00148 Customer::metadata = new MetaCategory
00149 ("customer", "customers", Customer::reader, Customer::writer);
00150 CustomerDefault::metadata = new MetaClass(
00151 "customer",
00152 "customer_default",
00153 Object::createString<CustomerDefault>, true);
00154
00155
00156 Calendar::Bucket::metadata = new MetaCategory("bucket", "buckets");
00157 Calendar::metadata = new MetaCategory
00158 ("calendar", "calendars", Calendar::reader, Calendar::writer);
00159 CalendarVoid::metadata = new MetaClass(
00160 "calendar",
00161 "calendar_void",
00162 Object::createString<CalendarVoid>);
00163 CalendarDouble::metadata = new MetaClass(
00164 "calendar",
00165 "calendar_double",
00166 Object::createString<CalendarDouble>, true);
00167 CalendarInt::metadata = new MetaClass(
00168 "calendar",
00169 "calendar_integer",
00170 Object::createString<CalendarInt>);
00171 CalendarBool::metadata = new MetaClass(
00172 "calendar",
00173 "calendar_boolean",
00174 Object::createString<CalendarBool>);
00175 CalendarString::metadata = new MetaClass(
00176 "calendar",
00177 "calendar_string",
00178 Object::createString<CalendarString>);
00179 CalendarOperation::metadata = new MetaClass(
00180 "calendar",
00181 "calendar_operation",
00182 Object::createString<CalendarOperation>);
00183
00184
00185 Operation::metadata = new MetaCategory
00186 ("operation", "operations", Operation::reader, Operation::writer);
00187 OperationFixedTime::metadata = new MetaClass(
00188 "operation",
00189 "operation_fixed_time",
00190 Object::createString<OperationFixedTime>, true);
00191 OperationTimePer::metadata = new MetaClass(
00192 "operation",
00193 "operation_time_per",
00194 Object::createString<OperationTimePer>);
00195 OperationRouting::metadata = new MetaClass(
00196 "operation",
00197 "operation_routing",
00198 Object::createString<OperationRouting>);
00199 OperationAlternate::metadata = new MetaClass(
00200 "operation",
00201 "operation_alternate",
00202 Object::createString<OperationAlternate>);
00203
00204
00205 Item::metadata = new MetaCategory
00206 ("item", "items", Item::reader, Item::writer);
00207 ItemDefault::metadata = new MetaClass("item", "item_default",
00208 Object::createString<ItemDefault>, true);
00209
00210
00211 Buffer::metadata = new MetaCategory
00212 ("buffer", "buffers", Buffer::reader, Buffer::writer);
00213 BufferDefault::metadata = new MetaClass(
00214 "buffer",
00215 "buffer_default",
00216 Object::createString<BufferDefault>, true);
00217 BufferInfinite::metadata = new MetaClass(
00218 "buffer",
00219 "buffer_infinite",
00220 Object::createString<BufferInfinite>);
00221 BufferProcure::metadata = new MetaClass(
00222 "buffer",
00223 "buffer_procure",
00224 Object::createString<BufferProcure>);
00225
00226
00227 Demand::metadata = new MetaCategory
00228 ("demand", "demands", Demand::reader, Demand::writer);
00229 DemandDefault::metadata = new MetaClass(
00230 "demand",
00231 "demand_default",
00232 Object::createString<DemandDefault>, true);
00233
00234
00235 Resource::metadata = new MetaCategory
00236 ("resource", "resources", Resource::reader, Resource::writer);
00237 ResourceDefault::metadata = new MetaClass(
00238 "resource",
00239 "resource_default",
00240 Object::createString<ResourceDefault>,
00241 true);
00242 ResourceInfinite::metadata = new MetaClass(
00243 "resource",
00244 "resource_infinite",
00245 Object::createString<ResourceInfinite>);
00246
00247
00248 Load::metadata = new MetaCategory
00249 ("load", "loads", MetaCategory::ControllerDefault, NULL);
00250 const_cast<MetaCategory*>(Load::metadata)->registerClass(
00251 "load","load",true,Object::createDefault<Load>
00252 );
00253
00254
00255 Flow::metadata = new MetaCategory
00256 ("flow", "flows", MetaCategory::ControllerDefault);
00257 FlowStart::metadata = new MetaClass(
00258 "flow",
00259 "flow_start",
00260 Object::createDefault<FlowStart>, true);
00261 FlowEnd::metadata = new MetaClass(
00262 "flow",
00263 "flow_end",
00264 Object::createDefault<FlowEnd>);
00265
00266
00267 OperationPlan::metacategory = new MetaCategory("operationplan", "operationplans",
00268 OperationPlan::createOperationPlan, OperationPlan::writer);
00269 OperationPlan::metadata = new MetaClass("operationplan", "operationplan");
00270
00271
00272 Problem::metadata = new MetaCategory
00273 ("problem", "problems", NULL, Problem::writer);
00274 ProblemMaterialExcess::metadata = new MetaClass
00275 ("problem","material excess");
00276 ProblemMaterialShortage::metadata = new MetaClass
00277 ("problem","material shortage");
00278 ProblemExcess::metadata = new MetaClass
00279 ("problem","excess");
00280 ProblemShort::metadata = new MetaClass
00281 ("problem","short");
00282 ProblemEarly::metadata = new MetaClass
00283 ("problem","early");
00284 ProblemLate::metadata = new MetaClass
00285 ("problem","late");
00286 ProblemDemandNotPlanned::metadata = new MetaClass
00287 ("problem","unplanned");
00288 ProblemPlannedEarly::metadata = new MetaClass
00289 ("problem","planned early");
00290 ProblemPlannedLate::metadata = new MetaClass
00291 ("problem","planned late");
00292 ProblemPrecedence::metadata = new MetaClass
00293 ("problem","precedence");
00294 ProblemBeforeFence::metadata = new MetaClass
00295 ("problem","before fence");
00296 ProblemBeforeCurrent::metadata = new MetaClass
00297 ("problem","before current");
00298 ProblemCapacityUnderload::metadata = new MetaClass
00299 ("problem","underload");
00300 ProblemCapacityOverload::metadata = new MetaClass
00301 ("problem","overload");
00302
00303
00304 int nok = 0;
00305 nok += PythonPlan::initialize(PythonInterpreter::getModule());
00306 nok += PythonBuffer::initialize(PythonInterpreter::getModule());
00307 nok += PythonBufferDefault::initialize(PythonInterpreter::getModule());
00308 nok += PythonBufferInfinite::initialize(PythonInterpreter::getModule());
00309 nok += PythonBufferProcure::initialize(PythonInterpreter::getModule());
00310 nok += PythonBufferIterator::initialize(PythonInterpreter::getModule());
00311 nok += PythonCalendar::initialize(PythonInterpreter::getModule());
00312 nok += PythonCalendarIterator::initialize(PythonInterpreter::getModule());
00313 nok += PythonCalendarBucket::initialize(PythonInterpreter::getModule());
00314 nok += PythonCalendarBucketIterator::initialize(PythonInterpreter::getModule());
00315 nok += PythonCalendarBool::initialize(PythonInterpreter::getModule());
00316 nok += PythonCalendarVoid::initialize(PythonInterpreter::getModule());
00317 nok += PythonCalendarDouble::initialize(PythonInterpreter::getModule());
00318 nok += PythonCalendarString::initialize(PythonInterpreter::getModule());
00319 nok += PythonCalendarInt::initialize(PythonInterpreter::getModule());
00320 nok += PythonCalendarOperation::initialize(PythonInterpreter::getModule());
00321 nok += PythonCustomer::initialize(PythonInterpreter::getModule());
00322 nok += PythonCustomerDefault::initialize(PythonInterpreter::getModule());
00323 nok += PythonCustomerIterator::initialize(PythonInterpreter::getModule());
00324 nok += PythonDemand::initialize(PythonInterpreter::getModule());
00325 nok += PythonDemandIterator::initialize(PythonInterpreter::getModule());
00326 nok += PythonDemandDefault::initialize(PythonInterpreter::getModule());
00327 nok += PythonDemandPlanIterator::initialize(PythonInterpreter::getModule());
00328 nok += PythonPeggingIterator::initialize(PythonInterpreter::getModule());
00329 nok += PythonFlow::initialize(PythonInterpreter::getModule());
00330 nok += PythonFlowIterator::initialize(PythonInterpreter::getModule());
00331 nok += PythonFlowPlan::initialize(PythonInterpreter::getModule());
00332 nok += PythonFlowPlanIterator::initialize(PythonInterpreter::getModule());
00333 nok += PythonItem::initialize(PythonInterpreter::getModule());
00334 nok += PythonItemDefault::initialize(PythonInterpreter::getModule());
00335 nok += PythonItemIterator::initialize(PythonInterpreter::getModule());
00336 nok += PythonLoad::initialize(PythonInterpreter::getModule());
00337 nok += PythonLoadIterator::initialize(PythonInterpreter::getModule());
00338 nok += PythonLoadPlan::initialize(PythonInterpreter::getModule());
00339 nok += PythonLoadPlanIterator::initialize(PythonInterpreter::getModule());
00340 nok += PythonLocation::initialize(PythonInterpreter::getModule());
00341 nok += PythonLocationDefault::initialize(PythonInterpreter::getModule());
00342 nok += PythonLocationIterator::initialize(PythonInterpreter::getModule());
00343 nok += PythonOperation::initialize(PythonInterpreter::getModule());
00344 nok += PythonOperationAlternate::initialize(PythonInterpreter::getModule());
00345 nok += PythonOperationFixedTime::initialize(PythonInterpreter::getModule());
00346 nok += PythonOperationTimePer::initialize(PythonInterpreter::getModule());
00347 nok += PythonOperationRouting::initialize(PythonInterpreter::getModule());
00348 nok += PythonOperationIterator::initialize(PythonInterpreter::getModule());
00349 nok += PythonOperationPlan::initialize(PythonInterpreter::getModule());
00350 nok += PythonOperationPlanIterator::initialize(PythonInterpreter::getModule());
00351 nok += PythonProblem::initialize(PythonInterpreter::getModule());
00352 nok += PythonProblemIterator::initialize(PythonInterpreter::getModule());
00353 nok += PythonResource::initialize(PythonInterpreter::getModule());
00354 nok += PythonResourceDefault::initialize(PythonInterpreter::getModule());
00355 nok += PythonResourceInfinite::initialize(PythonInterpreter::getModule());
00356 nok += PythonResourceIterator::initialize(PythonInterpreter::getModule());
00357 nok += PythonSolver::initialize(PythonInterpreter::getModule());
00358 nok += PythonSolverIterator::initialize(PythonInterpreter::getModule());
00359 if (nok)
00360 throw RuntimeException("Error registering new Python types");
00361
00362
00363 PythonInterpreter::registerGlobalMethod(
00364 "loadmodule", CommandLoadLibrary::executePython, METH_VARARGS,
00365 "Dynamically load a module in memory.");
00366 PythonInterpreter::registerGlobalMethod(
00367 "printsize", CommandPlanSize::executePython, METH_NOARGS,
00368 "Print information about the memory consumption.");
00369 PythonInterpreter::registerGlobalMethod(
00370 "erase", CommandErase::executePython, METH_VARARGS,
00371 "Removes the plan data from memory, and optionally the static info too.");
00372 PythonInterpreter::registerGlobalMethod(
00373 "readXMLdata", CommandReadXMLString::executePython, METH_VARARGS,
00374 "Processes an XML string passed as argument.");
00375 PythonInterpreter::registerGlobalMethod(
00376 "readXMLfile", CommandReadXMLFile::executePython, METH_VARARGS,
00377 "Read an XML-file.");
00378 PythonInterpreter::registerGlobalMethod(
00379 "saveXMLfile", CommandSave::executePython, METH_VARARGS,
00380 "Save the model to an XML-file.");
00381 PythonInterpreter::registerGlobalMethod(
00382 "saveplan", CommandSavePlan::executePython, METH_VARARGS,
00383 "Save the main plan information to a file.");
00384 PythonInterpreter::registerGlobalMethod(
00385 "buffers", PythonBufferIterator::create, METH_NOARGS,
00386 "Returns an iterator over the buffers.");
00387 PythonInterpreter::registerGlobalMethod(
00388 "locations", PythonLocationIterator::create, METH_NOARGS,
00389 "Returns an iterator over the locations.");
00390 PythonInterpreter::registerGlobalMethod(
00391 "customers", PythonCustomerIterator::create, METH_NOARGS,
00392 "Returns an iterator over the customer.");
00393 PythonInterpreter::registerGlobalMethod(
00394 "items", PythonItemIterator::create, METH_NOARGS,
00395 "Returns an iterator over the items.");
00396 PythonInterpreter::registerGlobalMethod(
00397 "calendars", PythonCalendarIterator::create, METH_NOARGS,
00398 "Returns an iterator over the calendars.");
00399 PythonInterpreter::registerGlobalMethod(
00400 "demands", PythonDemandIterator::create, METH_NOARGS,
00401 "Returns an iterator over the demands.");
00402 PythonInterpreter::registerGlobalMethod(
00403 "resources", PythonResourceIterator::create, METH_NOARGS,
00404 "Returns an iterator over the resources.");
00405 PythonInterpreter::registerGlobalMethod(
00406 "operations", PythonOperationIterator::create, METH_NOARGS,
00407 "Returns an iterator over the operations.");
00408 PythonInterpreter::registerGlobalMethod(
00409 "operationplans", PythonOperationPlanIterator::create, METH_NOARGS,
00410 "Returns an iterator over the operationplans.");
00411 PythonInterpreter::registerGlobalMethod(
00412 "problems", PythonProblemIterator::create, METH_NOARGS,
00413 "Returns an iterator over the problems.");
00414 PythonInterpreter::registerGlobalMethod(
00415 "solvers", PythonSolverIterator::create, METH_NOARGS,
00416 "Returns an iterator over the solvers.");
00417 }
00418
00419
00420 DECLARE_EXPORT void CommandPlanSize::execute()
00421 {
00422 size_t count, memsize;
00423
00424
00425 if (getVerbose())
00426 logger << "Start size report at " << Date::now() << endl;
00427 Timer t;
00428
00429
00430 logger << endl << "Size information of frePPLe " << PACKAGE_VERSION
00431 << " (" << __DATE__ << ")" << endl << endl;
00432
00433
00434 #if defined(HAVE_SETLOCALE) || defined(_MSC_VER)
00435 logger << "Locale: " << setlocale(LC_ALL,NULL) << endl << endl;
00436 #else
00437 logger << endl;
00438 #endif
00439
00440
00441 CommandLoadLibrary::printModules();
00442
00443
00444 logger << "Clusters: " << HasLevel::getNumberOfClusters()
00445 << " (hanging: " << HasLevel::getNumberOfHangingClusters() << ")"
00446 << endl << endl;
00447
00448
00449 logger << "Memory usage:" << endl;
00450 logger << "Model \tNumber\tMemory" << endl;
00451 logger << "----- \t------\t------" << endl;
00452
00453
00454 size_t total = Plan::instance().getSize();
00455 logger << "Plan \t1\t"<< Plan::instance().getSize() << endl;
00456
00457
00458 memsize = 0;
00459 for (Location::iterator l = Location::begin(); l != Location::end(); ++l)
00460 memsize += l->getSize();
00461 logger << "Location \t" << Location::size() << "\t" << memsize << endl;
00462 total += memsize;
00463
00464
00465 memsize = 0;
00466 for (Customer::iterator c = Customer::begin(); c != Customer::end(); ++c)
00467 memsize += c->getSize();
00468 logger << "Customer \t" << Customer::size() << "\t" << memsize << endl;
00469 total += memsize;
00470
00471
00472 memsize = 0;
00473 for (Buffer::iterator b = Buffer::begin(); b != Buffer::end(); ++b)
00474 memsize += b->getSize();
00475 logger << "Buffer \t" << Buffer::size() << "\t" << memsize << endl;
00476 total += memsize;
00477
00478
00479 memsize = 0;
00480 for (Resource::iterator r = Resource::begin(); r != Resource::end(); ++r)
00481 memsize += r->getSize();
00482 logger << "Resource \t" << Resource::size() << "\t" << memsize << endl;
00483 total += memsize;
00484
00485
00486 size_t countFlows(0), memFlows(0), countLoads(0), memLoads(0);
00487 memsize = 0;
00488 for (Operation::iterator o = Operation::begin(); o != Operation::end(); ++o)
00489 {
00490 memsize += o->getSize();
00491 for (Operation::flowlist::const_iterator fl = o->getFlows().begin();
00492 fl != o->getFlows().end(); ++ fl)
00493 {
00494 ++countFlows;
00495 memFlows += fl->getSize();
00496 }
00497 for (Operation::loadlist::const_iterator ld = o->getLoads().begin();
00498 ld != o->getLoads().end(); ++ ld)
00499 {
00500 ++countLoads;
00501 memLoads += ld->getSize();
00502 }
00503 }
00504 logger << "Operation \t" << Operation::size() << "\t" << memsize << endl;
00505 logger << "Flow \t" << countFlows << "\t" << memFlows << endl;
00506 logger << "Load \t" << countLoads << "\t" << memLoads << endl;
00507 total += memsize + memFlows + memLoads;
00508
00509
00510 memsize = 0;
00511 for (Calendar::iterator cl = Calendar::begin(); cl != Calendar::end(); ++cl)
00512 memsize += cl->getSize();
00513 logger << "Calendar \t" << Calendar::size() << "\t" << memsize << endl;
00514 total += memsize;
00515
00516
00517 memsize = 0;
00518 for (Item::iterator i = Item::begin(); i != Item::end(); ++i)
00519 memsize += i->getSize();
00520 logger << "Item \t" << Item::size() << "\t" << memsize << endl;
00521 total += memsize;
00522
00523
00524 memsize = 0;
00525 for (Demand::iterator dm = Demand::begin(); dm != Demand::end(); ++dm)
00526 memsize += dm->getSize();
00527 logger << "Demand \t" << Demand::size() << "\t" << memsize << endl;
00528 total += memsize;
00529
00530
00531 size_t countloadplans(0), countflowplans(0);
00532 memsize = count = 0;
00533 for (OperationPlan::iterator j = OperationPlan::begin();
00534 j!=OperationPlan::end(); ++j)
00535 {
00536 ++count;
00537 memsize += sizeof(*j);
00538 countloadplans += j->sizeLoadPlans();
00539 countflowplans += j->sizeFlowPlans();
00540 }
00541 total += memsize;
00542 logger << "OperationPlan\t" << count << "\t" << memsize << endl;
00543
00544
00545 memsize = countflowplans * sizeof(FlowPlan);
00546 total += memsize;
00547 logger << "FlowPlan \t" << countflowplans << "\t" << memsize << endl;
00548
00549
00550 memsize = countloadplans * sizeof(LoadPlan);
00551 total += memsize;
00552 logger << "LoadPlan \t" << countloadplans << "\t" << memsize << endl;
00553
00554
00555 memsize = count = 0;
00556 for (Problem::const_iterator pr = Problem::begin(); pr!=Problem::end(); ++pr)
00557 {
00558 ++count;
00559 memsize += pr->getSize();
00560 }
00561 total += memsize;
00562 logger << "Problem \t" << count << "\t" << memsize << endl;
00563
00564
00565 logger << "Total \t\t" << total << endl << endl;
00566
00567
00568 if (getVerbose())
00569 logger << "Finished size report at " << Date::now() << " : " << t << endl;
00570 }
00571
00572
00573 }