FFSM++  1.1.0
French Forest Sector Model ++
MainProgram.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2015 by Laboratoire d'Economie Forestière *
3  * http://ffsm-project.org *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version, given the compliance with the *
9  * exceptions listed in the file COPYING that is distribued together *
10  * with this file. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 #include <iostream>
23 #include <clocale>
24 
25 #include "MainProgram.h"
26 #include "ThreadManager.h"
27 #include "Opt.h"
28 
29 
30 
31 
32 //constructor
34 {
35  //input_filename = input_filename_h;
36  MTHREAD = MTHREAD_h;
37  // Creating objects for the program flow:
38  // the regional data object..
39  ModelData *MD = new ModelData(MTHREAD);
40  MTHREAD->setMDPointer(MD);
42  MTHREAD->MD->loadInput(); // Unzip the ooffice input file and load it into memory
43 
44 }
45 
46 //distructor
48 
49 }
50 
51 /**
52 This is the main call of the program.
53 <br>It firstly create the objects (and keep track of them trough pointers) of the main functional objects of the program.
54 <br>Then it call the INIT object to do its jobs and when it ends, it gives control to SCD (Scheduler) for the year loops.
55 <br>Finally it clean-up and returns.
56 */
57 void
59 
60  setlocale(LC_ALL, "C"); // force to use the dot as digital separator also if we are running under the GUI
61 
62  // GIS information and methods..
63  Gis *GIS = new Gis(MTHREAD);
64  MTHREAD->setGISPointer(GIS);
65  // a test object for various 0-effects tests (sandbox)..
66  Sandbox* TEST = new Sandbox(MTHREAD);
67  MTHREAD->setTestPointer(TEST);
68  // the Init object, it schedule the pre-simulation phase..
69  Init *INIT = new Init(MTHREAD);
70  MTHREAD->setINITPointer(INIT);
71  // the scheduler object. It manage the simulation loops..
72  Scheduler *SCD = new Scheduler(MTHREAD);
73  MTHREAD->setSCDPointer(SCD);
74  // the core of the model
75  ModelCore *CORE = new ModelCore(MTHREAD);
76  MTHREAD->setCOREPointer(CORE);
77  // the core of the model (spatial version)
79  MTHREAD->setSCOREPointer(SCORE);
80  // the market optimisation algorithm
81  Opt *OPT = new Opt(MTHREAD);
82  MTHREAD->setOPTPointer(OPT);
83  // manage the printing of data needed for scenario-analisys. The "message output" (needed to see "what is it happening?" are instead simply printed with msgOut()..
84  Output *DO = new Output(MTHREAD);
85  MTHREAD->setDOPointer(DO);
86  // the carbon balance
87  Carbon *CBAL = new Carbon(MTHREAD);
88  MTHREAD->setCBALPointer(CBAL);
89 
90  // Creating an istance of INIT and delegating to it the Initialization phase..
91  MTHREAD->INIT->setInitLevel(1); // Initial environment setting and agent rising
92  refreshGUI();
93  MTHREAD->INIT->setInitLevel(3); // assigning resources to agents and evenutal env reallocation
94  refreshGUI();
95  MTHREAD->INIT->setInitLevel(5); // starting simulations. Once INIT has ended it is the turn of SCD (Scheduler) to manage the simulation...
96  refreshGUI();
97  MTHREAD->INIT->setInitLevel(6); // ending simulations
98  refreshGUI();
99 
100  // Deleting the pointers...
101  // 20070102: if I delete the pointers I can not access the legend after simulation has ended
102  // 20070109: pointers (e.g. INIT) are deleted in ThreadManager when a new simulation start
103 }
104 
void setSCDPointer(Scheduler *SCD_h)
the scheduler object. It manage the simulation loops..
Manage the yearly loops.
Definition: Scheduler.h:42
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
ModelData * MD
the model data object
Definition: ThreadManager.h:72
Init * INIT
the Init object (pre-simulation scheduler)
Definition: ThreadManager.h:74
Init the environment, the objects and the agents of the model
Definition: Init.h:45
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
Definition: ThreadManager.h:65
void setSCOREPointer(ModelCoreSpatial *SCORE_h)
Perform the algorithms of the model.
Regional data, including macros and settings.
Definition: ModelData.h:80
Output methods
Definition: Output.h:48
void setCOREPointer(ModelCore *CORE_h)
Perform the algorithms of the model.
void loadInput()
Unzip the OpenOffice input file (NEW 2008.05.13)
Definition: ModelData.cpp:1527
void setTestPointer(Sandbox *TEST_h)
the sandbox object for within-development quick tests
void setINITPointer(Init *INIT_h)
the Init object, it schedule the pre-simulation phase..
Class to manage the spatial dimension.
Definition: Gis.h:67
void setCBALPointer(Carbon *CBAL_h)
Module that account for the Carbon Balance.
Class responsable to keep the logbook of the Carbon Balance.
Definition: Carbon.h:50
void setGISPointer(Gis *GIS_h)
GIS information and methods..
Definition: Opt.h:52
void setInitLevel(int level_h)
Wrapper to the correct setInitLevelX()
Definition: Init.cpp:48
void refreshGUI() const
Ping to periodically return the control to the GUI.
Definition: BaseClass.cpp:142
void run()
Run the program.
Definition: MainProgram.cpp:58
string getBaseDirectory()
Definition: ThreadManager.h:98
MainProgram(ThreadManager *MTHREAD)
Definition: MainProgram.cpp:33
The core of the model (spatial version).
void setMDPointer(ModelData *MD_h)
the regional data object..
void setOPTPointer(Ipopt::SmartPtr< Ipopt::TNLP > OPT_h)
Perform the market optimisation.
void setDOPointer(Output *DO_h)
manage the printing of data needed for scenario-analisys. The "message output" (needed to see "what i...
void setBaseDiretory(string baseDirectory_h)
Definition: ModelData.h:183