model/library.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2007-2013 by Johan De Taeye, frePPLe bvba *
4  * *
5  * This library is free software; you can redistribute it and/or modify it *
6  * under the terms of the GNU Affero General Public License as published *
7  * by the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This library is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU Affero General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Affero General Public *
16  * License along with this program. *
17  * If not, see <http://www.gnu.org/licenses/>. *
18  * *
19  ***************************************************************************/
20 
21 #define FREPPLE_CORE
22 #include "frepple/model.h"
23 #include <sys/stat.h>
24 
25 namespace frepple
26 {
27 
29 {
30  // Initialize only once
31  static bool init = false;
32  if (init)
33  {
34  logger << "Warning: Calling frepple::LibraryModel::initialize() more "
35  << "than once." << endl;
36  return;
37  }
38  init = true;
39 
40  // Register new types in Python
41  int nok = 0;
42  nok += Plan::initialize();
43 
44  // Initialize the solver metadata.
45  nok += Solver::initialize();
47 
48  // Initialize the location metadata.
49  nok += Location::initialize();
52 
53  // Initialize the customer metadata.
54  nok += Customer::initialize();
57 
58  // Initialize the calendar metadata.
59  nok += Calendar::initialize();
62 
63  // Initialize the operation metadata.
64  nok += Operation::initialize();
71 
72  // Initialize the item metadata.
73  nok += Item::initialize();
74  nok += ItemDefault::initialize();
75  nok += ItemIterator::initialize();
76 
77  // Initialize the buffer metadata.
78  nok += Buffer::initialize();
83 
84  // Initialize the demand metadata.
85  nok += Demand::initialize();
89 
90  // Initialize the setupmatrix metadata.
91  nok += SetupMatrix::initialize();
94 
95  // Initialize the skill metadata
96  nok += Skill::initialize();
97  nok += SkillDefault::initialize();
99 
100  // Initialize the resource metadata.
101  nok += Resource::initialize();
106 
107  // Initialize the resourceskill metadata
108  nok += ResourceSkill::initialize();
110 
111  // Initialize the load metadata.
112  nok += Load::initialize();
113  nok += LoadIterator::initialize();
114  nok += LoadPlan::initialize();
116 
117  // Initialize the flow metadata.
118  nok += Flow::initialize();
119  nok += FlowIterator::initialize();
120  nok += FlowPlan::initialize();
122 
123  // Initialize the operationplan metadata.
124  nok += OperationPlan::initialize();
126 
127  // Initialize the problem metadata.
128  nok += Problem::initialize();
130 
131  // Initialize the pegging metadata.
133 
134  // Exit if errors were found
135  if (nok) throw RuntimeException("Error registering new Python types");
136 
137  // Register new methods in Python
138  PythonInterpreter::registerGlobalMethod(
139  "printsize", printModelSize, METH_NOARGS,
140  "Print information about the memory consumption.");
141  PythonInterpreter::registerGlobalMethod(
142  "erase", eraseModel, METH_VARARGS,
143  "Removes the plan data from memory, and optionally the static info too.");
144  PythonInterpreter::registerGlobalMethod(
145  "readXMLdata", readXMLdata, METH_VARARGS,
146  "Processes an XML string passed as argument.");
147  PythonInterpreter::registerGlobalMethod(
148  "readXMLfile", readXMLfile, METH_VARARGS,
149  "Read an XML-file.");
150  PythonInterpreter::registerGlobalMethod(
151  "saveXMLfile", saveXMLfile, METH_VARARGS,
152  "Save the model to an XML-file.");
153  PythonInterpreter::registerGlobalMethod(
154  "saveplan", savePlan, METH_VARARGS,
155  "Save the main plan information to a file.");
156  PythonInterpreter::registerGlobalMethod(
157  "buffers", BufferIterator::create, METH_NOARGS,
158  "Returns an iterator over the buffers.");
159  PythonInterpreter::registerGlobalMethod(
160  "locations", LocationIterator::create, METH_NOARGS,
161  "Returns an iterator over the locations.");
162  PythonInterpreter::registerGlobalMethod(
163  "customers", CustomerIterator::create, METH_NOARGS,
164  "Returns an iterator over the customer.");
165  PythonInterpreter::registerGlobalMethod(
166  "items", ItemIterator::create, METH_NOARGS,
167  "Returns an iterator over the items.");
168  PythonInterpreter::registerGlobalMethod(
169  "calendars", CalendarIterator::create, METH_NOARGS,
170  "Returns an iterator over the calendars.");
171  PythonInterpreter::registerGlobalMethod(
172  "demands", DemandIterator::create, METH_NOARGS,
173  "Returns an iterator over the demands.");
174  PythonInterpreter::registerGlobalMethod(
175  "resources", ResourceIterator::create, METH_NOARGS,
176  "Returns an iterator over the resources.");
177  PythonInterpreter::registerGlobalMethod(
178  "operations", OperationIterator::create, METH_NOARGS,
179  "Returns an iterator over the operations.");
180  PythonInterpreter::registerGlobalMethod(
181  "operationplans", OperationPlanIterator::create, METH_NOARGS,
182  "Returns an iterator over the operationplans.");
183  PythonInterpreter::registerGlobalMethod(
184  "problems", ProblemIterator::create, METH_NOARGS,
185  "Returns an iterator over the problems.");
186  PythonInterpreter::registerGlobalMethod(
187  "setupmatrices", SetupMatrixIterator::create, METH_NOARGS,
188  "Returns an iterator over the setup matrices.");
189  PythonInterpreter::registerGlobalMethod(
190  "solvers", SolverIterator::create, METH_NOARGS,
191  "Returns an iterator over the solvers.");
192  PythonInterpreter::registerGlobalMethod(
193  "skills", SkillIterator::create, METH_NOARGS,
194  "Returns an iterator over the skills.");
195 }
196 
197 
198 }