model/library.cpp
Go to the documentation of this file.
00001 /*************************************************************************** 00002 file : $URL: http://svn.code.sf.net/p/frepple/code/trunk/src/model/library.cpp $ 00003 version : $LastChangedRevision: 1713 $ $LastChangedBy: jdetaeye $ 00004 date : $LastChangedDate: 2012-07-18 11:46:01 +0200 (Wed, 18 Jul 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 Affero General Public License as published * 00013 * by the Free Software Foundation; either version 3 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 * 00019 * GNU Affero General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Affero General Public * 00022 * License along with this program. * 00023 * If not, see <http://www.gnu.org/licenses/>. * 00024 * * 00025 ***************************************************************************/ 00026 00027 #define FREPPLE_CORE 00028 #include "frepple/model.h" 00029 #include <sys/stat.h> 00030 00031 namespace frepple 00032 { 00033 00034 void LibraryModel::initialize() 00035 { 00036 // Initialize only once 00037 static bool init = false; 00038 if (init) 00039 { 00040 logger << "Warning: Calling frepple::LibraryModel::initialize() more " 00041 << "than once." << endl; 00042 return; 00043 } 00044 init = true; 00045 00046 // Register new types in Python 00047 int nok = 0; 00048 nok += Plan::initialize(); 00049 00050 // Initialize the solver metadata. 00051 nok += Solver::initialize(); 00052 nok += SolverIterator::initialize(); 00053 00054 // Initialize the location metadata. 00055 nok += Location::initialize(); 00056 nok += LocationDefault::initialize(); 00057 nok += LocationIterator::initialize(); 00058 00059 // Initialize the customer metadata. 00060 nok += Customer::initialize(); 00061 nok += CustomerDefault::initialize(); 00062 nok += CustomerIterator::initialize(); 00063 00064 // Initialize the calendar metadata. 00065 nok += Calendar::initialize(); 00066 nok += CalendarDouble::initialize(); 00067 nok += CalendarIterator::initialize(); 00068 00069 // Initialize the operation metadata. 00070 nok += Operation::initialize(); 00071 nok += OperationAlternate::initialize(); 00072 nok += OperationFixedTime::initialize(); 00073 nok += OperationTimePer::initialize(); 00074 nok += OperationRouting::initialize(); 00075 nok += OperationSetup::initialize(); 00076 nok += OperationIterator::initialize(); 00077 00078 // Initialize the item metadata. 00079 nok += Item::initialize(); 00080 nok += ItemDefault::initialize(); 00081 nok += ItemIterator::initialize(); 00082 00083 // Initialize the buffer metadata. 00084 nok += Buffer::initialize(); 00085 nok += BufferDefault::initialize(); 00086 nok += BufferInfinite::initialize(); 00087 nok += BufferProcure::initialize(); 00088 nok += BufferIterator::initialize(); 00089 00090 // Initialize the demand metadata. 00091 nok += Demand::initialize(); 00092 nok += DemandIterator::initialize(); 00093 nok += DemandDefault::initialize(); 00094 nok += DemandPlanIterator::initialize(); 00095 00096 // Initialize the setupmatrix metadata. 00097 nok += SetupMatrix::initialize(); 00098 nok += SetupMatrixDefault::initialize(); 00099 nok += SetupMatrixIterator::initialize(); 00100 00101 // Initialize the resource metadata. 00102 nok += Resource::initialize(); 00103 nok += ResourceDefault::initialize(); 00104 nok += ResourceInfinite::initialize(); 00105 nok += ResourceIterator::initialize(); 00106 nok += Resource::PlanIterator::initialize(); 00107 00108 // Initialize the load metadata. 00109 nok += Load::initialize(); 00110 nok += LoadIterator::initialize(); 00111 nok += LoadPlan::initialize(); 00112 nok += LoadPlanIterator::initialize(); 00113 00114 // Initialize the flow metadata. 00115 nok += Flow::initialize(); 00116 nok += FlowIterator::initialize(); 00117 nok += FlowPlan::initialize(); 00118 nok += FlowPlanIterator::initialize(); 00119 00120 // Initialize the operationplan metadata. 00121 nok += OperationPlan::initialize(); 00122 nok += OperationPlanIterator::initialize(); 00123 00124 // Initialize the problem metadata. 00125 nok += Problem::initialize(); 00126 nok += ProblemIterator::initialize(); 00127 00128 // Initialize the pegging metadata. 00129 nok += PeggingIterator::initialize(); 00130 00131 // Exit if errors were found 00132 if (nok) throw RuntimeException("Error registering new Python types"); 00133 00134 // Register new methods in Python 00135 PythonInterpreter::registerGlobalMethod( 00136 "printsize", printModelSize, METH_NOARGS, 00137 "Print information about the memory consumption."); 00138 PythonInterpreter::registerGlobalMethod( 00139 "erase", eraseModel, METH_VARARGS, 00140 "Removes the plan data from memory, and optionally the static info too."); 00141 PythonInterpreter::registerGlobalMethod( 00142 "readXMLdata", readXMLdata, METH_VARARGS, 00143 "Processes an XML string passed as argument."); 00144 PythonInterpreter::registerGlobalMethod( 00145 "readXMLfile", readXMLfile, METH_VARARGS, 00146 "Read an XML-file."); 00147 PythonInterpreter::registerGlobalMethod( 00148 "saveXMLfile", saveXMLfile, METH_VARARGS, 00149 "Save the model to an XML-file."); 00150 PythonInterpreter::registerGlobalMethod( 00151 "saveplan", savePlan, METH_VARARGS, 00152 "Save the main plan information to a file."); 00153 PythonInterpreter::registerGlobalMethod( 00154 "buffers", BufferIterator::create, METH_NOARGS, 00155 "Returns an iterator over the buffers."); 00156 PythonInterpreter::registerGlobalMethod( 00157 "locations", LocationIterator::create, METH_NOARGS, 00158 "Returns an iterator over the locations."); 00159 PythonInterpreter::registerGlobalMethod( 00160 "customers", CustomerIterator::create, METH_NOARGS, 00161 "Returns an iterator over the customer."); 00162 PythonInterpreter::registerGlobalMethod( 00163 "items", ItemIterator::create, METH_NOARGS, 00164 "Returns an iterator over the items."); 00165 PythonInterpreter::registerGlobalMethod( 00166 "calendars", CalendarIterator::create, METH_NOARGS, 00167 "Returns an iterator over the calendars."); 00168 PythonInterpreter::registerGlobalMethod( 00169 "demands", DemandIterator::create, METH_NOARGS, 00170 "Returns an iterator over the demands."); 00171 PythonInterpreter::registerGlobalMethod( 00172 "resources", ResourceIterator::create, METH_NOARGS, 00173 "Returns an iterator over the resources."); 00174 PythonInterpreter::registerGlobalMethod( 00175 "operations", OperationIterator::create, METH_NOARGS, 00176 "Returns an iterator over the operations."); 00177 PythonInterpreter::registerGlobalMethod( 00178 "operationplans", OperationPlanIterator::create, METH_NOARGS, 00179 "Returns an iterator over the operationplans."); 00180 PythonInterpreter::registerGlobalMethod( 00181 "problems", ProblemIterator::create, METH_NOARGS, 00182 "Returns an iterator over the problems."); 00183 PythonInterpreter::registerGlobalMethod( 00184 "setupmatrices", SetupMatrixIterator::create, METH_NOARGS, 00185 "Returns an iterator over the setup matrices."); 00186 PythonInterpreter::registerGlobalMethod( 00187 "solvers", SolverIterator::create, METH_NOARGS, 00188 "Returns an iterator over the solvers."); 00189 } 00190 00191 00192 }