model/library.cpp
Go to the documentation of this file.
00001 /*************************************************************************** 00002 file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/tags/0.9.1/src/model/library.cpp $ 00003 version : $LastChangedRevision: 1656 $ $LastChangedBy: jdetaeye $ 00004 date : $LastChangedDate: 2012-03-27 19:05:34 +0200 (Tue, 27 Mar 2012) $ 00005 ***************************************************************************/ 00006 00007 /*************************************************************************** 00008 * * 00009 * Copyright (C) 2007-2012 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 // Register new types in Python 00048 int nok = 0; 00049 nok += Plan::initialize(); 00050 00051 // Initialize the solver metadata. 00052 nok += Solver::initialize(); 00053 nok += SolverIterator::initialize(); 00054 00055 // Initialize the location metadata. 00056 nok += Location::initialize(); 00057 nok += LocationDefault::initialize(); 00058 nok += LocationIterator::initialize(); 00059 00060 // Initialize the customer metadata. 00061 nok += Customer::initialize(); 00062 nok += CustomerDefault::initialize(); 00063 nok += CustomerIterator::initialize(); 00064 00065 // Initialize the calendar metadata. 00066 nok += Calendar::initialize(); 00067 nok += CalendarBool::initialize(); 00068 nok += CalendarVoid::initialize(); 00069 nok += CalendarDouble::initialize(); 00070 nok += CalendarString::initialize(); 00071 nok += CalendarInt::initialize(); 00072 nok += CalendarOperation::initialize(); 00073 nok += CalendarIterator::initialize(); 00074 00075 // Initialize the operation metadata. 00076 nok += Operation::initialize(); 00077 nok += OperationAlternate::initialize(); 00078 nok += OperationFixedTime::initialize(); 00079 nok += OperationTimePer::initialize(); 00080 nok += OperationRouting::initialize(); 00081 nok += OperationSetup::initialize(); 00082 nok += OperationIterator::initialize(); 00083 00084 // Initialize the item metadata. 00085 nok += Item::initialize(); 00086 nok += ItemDefault::initialize(); 00087 nok += ItemIterator::initialize(); 00088 00089 // Initialize the buffer metadata. 00090 nok += Buffer::initialize(); 00091 nok += BufferDefault::initialize(); 00092 nok += BufferInfinite::initialize(); 00093 nok += BufferProcure::initialize(); 00094 nok += BufferIterator::initialize(); 00095 00096 // Initialize the demand metadata. 00097 nok += Demand::initialize(); 00098 nok += DemandIterator::initialize(); 00099 nok += DemandDefault::initialize(); 00100 nok += DemandPlanIterator::initialize(); 00101 00102 // Initialize the setupmatrix metadata. 00103 nok += SetupMatrix::initialize(); 00104 nok += SetupMatrixDefault::initialize(); 00105 nok += SetupMatrixIterator::initialize(); 00106 00107 // Initialize the resource metadata. 00108 nok += Resource::initialize(); 00109 nok += ResourceDefault::initialize(); 00110 nok += ResourceInfinite::initialize(); 00111 nok += ResourceIterator::initialize(); 00112 00113 // Initialize the load metadata. 00114 nok += Load::initialize(); 00115 nok += LoadIterator::initialize(); 00116 nok += LoadPlan::initialize(); 00117 nok += LoadPlanIterator::initialize(); 00118 00119 // Initialize the flow metadata. 00120 nok += Flow::initialize(); 00121 nok += FlowIterator::initialize(); 00122 nok += FlowPlan::initialize(); 00123 nok += FlowPlanIterator::initialize(); 00124 00125 // Initialize the operationplan metadata. 00126 nok += OperationPlan::initialize(); 00127 nok += OperationPlanIterator::initialize(); 00128 00129 // Initialize the problem metadata. 00130 nok += Problem::initialize(); 00131 nok += ProblemIterator::initialize(); 00132 00133 // Initialize the pegging metadata. 00134 nok += PeggingIterator::initialize(); 00135 00136 // Exit if errors were found 00137 if (nok) throw RuntimeException("Error registering new Python types"); 00138 00139 // Register new methods in Python 00140 PythonInterpreter::registerGlobalMethod( 00141 "printsize", printModelSize, METH_NOARGS, 00142 "Print information about the memory consumption."); 00143 PythonInterpreter::registerGlobalMethod( 00144 "erase", eraseModel, METH_VARARGS, 00145 "Removes the plan data from memory, and optionally the static info too."); 00146 PythonInterpreter::registerGlobalMethod( 00147 "readXMLdata", readXMLdata, METH_VARARGS, 00148 "Processes an XML string passed as argument."); 00149 PythonInterpreter::registerGlobalMethod( 00150 "readXMLfile", readXMLfile, METH_VARARGS, 00151 "Read an XML-file."); 00152 PythonInterpreter::registerGlobalMethod( 00153 "saveXMLfile", saveXMLfile, METH_VARARGS, 00154 "Save the model to an XML-file."); 00155 PythonInterpreter::registerGlobalMethod( 00156 "saveplan", savePlan, METH_VARARGS, 00157 "Save the main plan information to a file."); 00158 PythonInterpreter::registerGlobalMethod( 00159 "buffers", BufferIterator::create, METH_NOARGS, 00160 "Returns an iterator over the buffers."); 00161 PythonInterpreter::registerGlobalMethod( 00162 "locations", LocationIterator::create, METH_NOARGS, 00163 "Returns an iterator over the locations."); 00164 PythonInterpreter::registerGlobalMethod( 00165 "customers", CustomerIterator::create, METH_NOARGS, 00166 "Returns an iterator over the customer."); 00167 PythonInterpreter::registerGlobalMethod( 00168 "items", ItemIterator::create, METH_NOARGS, 00169 "Returns an iterator over the items."); 00170 PythonInterpreter::registerGlobalMethod( 00171 "calendars", CalendarIterator::create, METH_NOARGS, 00172 "Returns an iterator over the calendars."); 00173 PythonInterpreter::registerGlobalMethod( 00174 "demands", DemandIterator::create, METH_NOARGS, 00175 "Returns an iterator over the demands."); 00176 PythonInterpreter::registerGlobalMethod( 00177 "resources", ResourceIterator::create, METH_NOARGS, 00178 "Returns an iterator over the resources."); 00179 PythonInterpreter::registerGlobalMethod( 00180 "operations", OperationIterator::create, METH_NOARGS, 00181 "Returns an iterator over the operations."); 00182 PythonInterpreter::registerGlobalMethod( 00183 "operationplans", OperationPlanIterator::create, METH_NOARGS, 00184 "Returns an iterator over the operationplans."); 00185 PythonInterpreter::registerGlobalMethod( 00186 "problems", ProblemIterator::create, METH_NOARGS, 00187 "Returns an iterator over the problems."); 00188 PythonInterpreter::registerGlobalMethod( 00189 "setupmatrices", SetupMatrixIterator::create, METH_NOARGS, 00190 "Returns an iterator over the setup matrices."); 00191 PythonInterpreter::registerGlobalMethod( 00192 "solvers", SolverIterator::create, METH_NOARGS, 00193 "Returns an iterator over the solvers."); 00194 } 00195 00196 00197 }