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: 1470 $ $LastChangedBy: jdetaeye $ 00004 date : $LastChangedDate: 2011-07-08 18:24:46 +0200 (Fri, 08 Jul 2011) $ 00005 ***************************************************************************/ 00006 00007 /*************************************************************************** 00008 * * 00009 * Copyright (C) 2007-2011 by Johan De Taeye, frePPLe bvba * 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 "printsize", printModelSize, METH_NOARGS, 00145 "Print information about the memory consumption."); 00146 PythonInterpreter::registerGlobalMethod( 00147 "erase", eraseModel, METH_VARARGS, 00148 "Removes the plan data from memory, and optionally the static info too."); 00149 PythonInterpreter::registerGlobalMethod( 00150 "readXMLdata", readXMLdata, METH_VARARGS, 00151 "Processes an XML string passed as argument."); 00152 PythonInterpreter::registerGlobalMethod( 00153 "readXMLfile", readXMLfile, METH_VARARGS, 00154 "Read an XML-file."); 00155 PythonInterpreter::registerGlobalMethod( 00156 "saveXMLfile", saveXMLfile, METH_VARARGS, 00157 "Save the model to an XML-file."); 00158 PythonInterpreter::registerGlobalMethod( 00159 "saveplan", savePlan, METH_VARARGS, 00160 "Save the main plan information to a file."); 00161 PythonInterpreter::registerGlobalMethod( 00162 "buffers", BufferIterator::create, METH_NOARGS, 00163 "Returns an iterator over the buffers."); 00164 PythonInterpreter::registerGlobalMethod( 00165 "locations", LocationIterator::create, METH_NOARGS, 00166 "Returns an iterator over the locations."); 00167 PythonInterpreter::registerGlobalMethod( 00168 "customers", CustomerIterator::create, METH_NOARGS, 00169 "Returns an iterator over the customer."); 00170 PythonInterpreter::registerGlobalMethod( 00171 "items", ItemIterator::create, METH_NOARGS, 00172 "Returns an iterator over the items."); 00173 PythonInterpreter::registerGlobalMethod( 00174 "calendars", CalendarIterator::create, METH_NOARGS, 00175 "Returns an iterator over the calendars."); 00176 PythonInterpreter::registerGlobalMethod( 00177 "demands", DemandIterator::create, METH_NOARGS, 00178 "Returns an iterator over the demands."); 00179 PythonInterpreter::registerGlobalMethod( 00180 "resources", ResourceIterator::create, METH_NOARGS, 00181 "Returns an iterator over the resources."); 00182 PythonInterpreter::registerGlobalMethod( 00183 "operations", OperationIterator::create, METH_NOARGS, 00184 "Returns an iterator over the operations."); 00185 PythonInterpreter::registerGlobalMethod( 00186 "operationplans", OperationPlanIterator::create, METH_NOARGS, 00187 "Returns an iterator over the operationplans."); 00188 PythonInterpreter::registerGlobalMethod( 00189 "problems", ProblemIterator::create, METH_NOARGS, 00190 "Returns an iterator over the problems."); 00191 PythonInterpreter::registerGlobalMethod( 00192 "setupmatrices", SetupMatrixIterator::create, METH_NOARGS, 00193 "Returns an iterator over the setup matrices."); 00194 PythonInterpreter::registerGlobalMethod( 00195 "solvers", SolverIterator::create, METH_NOARGS, 00196 "Returns an iterator over the solvers."); 00197 } 00198 00199 00200 }