Skip to content

Commit

Permalink
Fix for replanning
Browse files Browse the repository at this point in the history
  • Loading branch information
gcyr committed Nov 18, 2024
1 parent 3584463 commit 547ff60
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Examples/C++/doplanning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main(int argc, char* argv[])
else {
primarylocation = "D:/CC_modele_feu/WS_CC/Feux_2023_ouest_V01.pri";
scenario = "PlayBack_CC";
length = 20;
length = 1;
objectivevalue = 16849;
}
Parser::FMTmodelparser modelparser;
Expand Down
6 changes: 3 additions & 3 deletions Examples/C++/maptoFMTforest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ int main(int argc, char* argv[])
maplocation = argv[2];// modellocation + "/Carte/TWD_land.shp";
writelocation = argv[3];// "../../tests/maptoFMTforest/";
}else {
primarylocation = "T:/Donnees/Usagers/PICBR1/Prototype_Dec2023/PC_7002071_UA08152_FINAL.pri";
scenario = "3_RegProv_apsp";
primarylocation = "T:/Donnees/Usagers/PICBR1/PC9424_U08551_DET/PC_9424_U08551_4_Vg1_2023_vSSP03.pri";
scenario = "14_Sc5_Determin_apsp";
side = 196;
maplocation = "T:/Donnees/Usagers/PICBR1/Prototype_Dec2023/Carte/PC_7002071_UA_U08152.shp";// modellocation + "/Carte/TWD_land.shp";
maplocation = "T:/Donnees/Usagers/PICBR1/PC9424_U08551_DET/Carte/PC_9424_UA_U08551.shp";// modellocation + "/Carte/TWD_land.shp";
writelocation = "../../tests/maptoFMTforest/";
}

Expand Down
15 changes: 9 additions & 6 deletions Examples/C++/replanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ int main(int argc, char *argv[])
else
{
primlocation = "D:/CC_modele_feu/WS_CC/Feux_2023_ouest_V01.pri";
length = 5;
replicate = 5;
allscenarios.push_back("strategique_Minimisation_Risque_CC"); //Pour test le lancé d'erreur
length = 20;
replicate = 100;
allscenarios.push_back("strategique_AllEnrqc_CC"); //Pour test le lancé d'erreur
//allscenarios.push_back("strategique");
allscenarios.push_back("stochastique_CC_2pics");
allscenarios.push_back("stochastique_CC_2pics_SansFeu");
//allscenarios.push_back("tactique");
allscenarios.push_back("tactique_Minimisation_Risque_CC");
allscenarios.push_back("tactique_AllEnrqc_CC");
}

Parser::FMTmodelparser modelparser;
modelparser.setTerminateStack();
modelparser.setdefaultexceptionhandler();
std::vector<Exception::FMTexc> errors;
errors.push_back(Exception::FMTexc::FMTmissingyield);
Expand Down Expand Up @@ -82,7 +83,9 @@ int main(int argc, char *argv[])
"OSUPTBE" , "SUPERFICIE_RECUP_TBE",
"OCATTBE_C1" ,"OCATTBE_C2" ,"OCATTBE_C3",
"OCATTBE_C4","OCATTBE_C5","OCATTBE_C6","OTBECOMP","OSUPADMATBE",
"ORISQUE","ORISQUE_FEU","ORISQUE_TBE","ORISQUE_FEU_NOR","ORISQUE_TBE_NOR","ORISQUE_NOR","OVOLGFIREC","OVOLGFTREC","OVOLGRREC"};
"ORISQUE","ORISQUE_FEU","ORISQUE_TBE","ORISQUE_FEU_NOR","ORISQUE_TBE_NOR","ORISQUE_NOR","OVOLGFIREC","OVOLGFTREC","OVOLGRREC",
"SS_10","SS_25","SS_50","SS_100","SS_200","SS_400","SR_10","SR_25","SR_50","SR_100","SR_200","SR_400",
"REST_10","REST_25","REST_50","REST_100","REST_200","REST_400" };
std::vector<Core::FMToutput>selectedoutputs;
for (const Core::FMToutput& output : global.getoutputs())
{
Expand Down
2 changes: 1 addition & 1 deletion FMTWrapperCore/Source/TransformationCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Models::FMTmodel FMTWrapperCore::Transformation::buildAction(const Models::FMTmo
{
Parser::FMTscheduleparser SCHEDULE_PARSER;
const std::vector<Core::FMTschedule> NEW_SCHEDULE = BUILDED_MODEL.buildSchedule(*BUILDED_MODEL.getactions().begin(), SCHEDULES);
SCHEDULE_PARSER.write(NEW_SCHEDULE, outputPath + p_scenario_name + ".seq");
SCHEDULE_PARSER.write(NEW_SCHEDULE, outputPath + p_scenario_name + "._seq");
}
}
catch (...) {
Expand Down
2 changes: 1 addition & 1 deletion FMTWrapperCore/tests/testWrapperCoreBuildAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char* argv[])
}
else
{
pathPri = "T:/Donnees/02_Courant/07_Outil_moyen_methode/01_Entretien_developpement/09_FMT/Modeles_test/Prototype_Dec2023_TBE/PC_7002071_UA08152_FINAL.pri";
pathPri = "T:/Donnees/02_Courant/07_Outil_moyen_methode/01_Entretien_developpement/Interne/FMT/Entretien/Modeles_test/Prototype_Dec2023_TBE/PC_7002071_UA08152_FINAL.pri";
actionName = "TBE";
targetYield = "YV_S_MORT";
scenarioName = "20_Regl_prov";
Expand Down
1 change: 0 additions & 1 deletion Include/FMTexceptionhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ namespace Exception
ar& BOOST_SERIALIZATION_NVP(_logger);
ar& BOOST_SERIALIZATION_NVP(usenestedexceptions);
}

};

}
Expand Down
2 changes: 1 addition & 1 deletion Include/FMTlist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ namespace Core
}
}
data.swap(newdata);*/
FMTlist::update();
//FMTlist::update();
//data.shrink_to_fit();
}catch (...)
{
Expand Down
10 changes: 10 additions & 0 deletions Include/FMTobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ class FMTEXPORT FMTobject
Change the number of warning raise before silenced.
*/
void setmaxwarningsbeforesilenced(const size_t& maxwarningcount);
// DocString: FMTexceptionhandler::setTerminateStack
/**
@brief will write the stack in the log when terminate called and raise a function failed.
*/
static void setTerminateStack();
// DocString: FMTobject::serialize
/**
Serialize function is for serialization, used to do multiprocessing across multiple cpus (pickle in Pyhton)
Expand Down Expand Up @@ -244,6 +249,11 @@ class FMTEXPORT FMTobject
With the clock time calculate time spent in second and return a string.
*/
static std::string getdurationinseconds(const std::chrono::time_point<std::chrono::high_resolution_clock>& startclock);
// DocString: FMTexceptionhandler::_terminate
/**
@brief Raise an error with the boost stacktrace.
*/
static void _terminate();


};
Expand Down
56 changes: 35 additions & 21 deletions Include/FMTtaskhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
#include <memory>
#include "FMTobject.h"

namespace boost
{
class thread;
}

/// Namespace for parallel tasking may include multithreading / multiprocessing
namespace Parallel
{
Expand All @@ -20,27 +25,7 @@ namespace Parallel
*/
class FMTEXPORT FMTtaskhandler : public Core::FMTobject
{
// DocString: FMTtaskhandler::maxnumberofthread
///Maximal number of threads
unsigned int maxnumberofthread;
// DocString: FMTtaskhandler::alltasks
///All the tasks that are running
std::vector<std::unique_ptr<FMTtask>>alltasks;
// DocString: FMTtaskhandler::splittasks
/**
Will split all task in alltasks and replace it with new splitted tasks
*/
void splittasks();
// DocString: FMTtaskhandler::finalize
/**
This function will call the FMTtask::finalize function when the last task is done.
*/
void finalize(std::unique_ptr<FMTtask>& lasttask);
// DocString: FMTtaskhandler::logtasktime
/**
Juste write down all the time it took to run all tasks
*/
void logtasktime(const std::chrono::time_point<std::chrono::high_resolution_clock>& startime) const;

public:
// DocString: FMTtaskhandler::FMTtaskhandler(const std::unique_ptr<FMTtask>&,unsigned int)
/**
Expand Down Expand Up @@ -110,6 +95,35 @@ namespace Parallel
We need to override the passinlogger for the osisolverinterface
*/
void passinlogger(const std::unique_ptr<Logging::FMTlogger>& logger) override;
private:
// DocString: FMTtaskhandler::maxnumberofthread
///Maximal number of threads
unsigned int maxnumberofthread;
// DocString: FMTtaskhandler::alltasks
///All the tasks that are running
std::vector<std::unique_ptr<FMTtask>>alltasks;
// DocString: FMTtaskhandler::splittasks
/**
Will split all task in alltasks and replace it with new splitted tasks
*/
void splittasks();
// DocString: FMTtaskhandler::finalize
/**
This function will call the FMTtask::finalize function when the last task is done.
*/
void finalize(std::unique_ptr<FMTtask>& lasttask);
// DocString: FMTtaskhandler::logtasktime
/**
Juste write down all the time it took to run all tasks
*/
void logtasktime(const std::chrono::time_point<std::chrono::high_resolution_clock>& startime) const;
// DocString: FMTtaskhandler::_interruptWork
/**
@brief interupt the work of a thread in case on a exception to make sure to dont get a std::terminate if joinable.
@p_threads the threads to interrupt
*/
static void _interruptWork(boost::thread& p_thread);

};

}
Expand Down
1 change: 1 addition & 0 deletions Source/FMTexceptionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
#include <boost/algorithm/string/replace.hpp>
#include <boost/lexical_cast.hpp>


#if defined FMTWITHR
#include "Rcpp.h"
#endif
Expand Down
1 change: 1 addition & 0 deletions Source/FMTlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
#include "CoinMessageHandler.hpp"
#endif


namespace Logging
{

Expand Down
6 changes: 3 additions & 3 deletions Source/FMTlpmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ std::vector<std::map<int, double>> FMTlpmodel::locatenodes(const std::vector<Cor
{
writeLP((boost::filesystem::current_path() += boost::filesystem::path::preferred_separator).string());
}
_exhandler->printexceptions("", "FMTlpmodel::initialsolve", __LINE__, __FILE__);
_exhandler->printexceptions(getname(), "FMTlpmodel::initialsolve", __LINE__, __FILE__);
}

return false;
Expand Down Expand Up @@ -2255,7 +2255,7 @@ std::vector<std::map<int, double>> FMTlpmodel::locatenodes(const std::vector<Cor
}
}catch(...)
{
_exhandler->raisefromcatch("", "FMTlpmodel::build", __LINE__, __FILE__);
_exhandler->raisefromcatch(getname(), "FMTlpmodel::build", __LINE__, __FILE__);
}
return true;
}
Expand All @@ -2267,7 +2267,7 @@ std::vector<std::map<int, double>> FMTlpmodel::locatenodes(const std::vector<Cor
optimal = this->initialsolve();
}catch(...)
{
_exhandler->raisefromcatch("", "FMTlpmodel::solve", __LINE__, __FILE__);
_exhandler->raisefromcatch(getname(), "FMTlpmodel::solve", __LINE__, __FILE__);
}
return optimal;
}
Expand Down
6 changes: 3 additions & 3 deletions Source/FMTmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ namespace Models{
try {
const std::vector<std::string>ATTRIBUTES{ "PRE","POST" };
newModel.pushTheme("~FMT_THEME_" + p_actionName, ATTRIBUTES);
Core::FMTaction newAction("~FMT_" + p_actionName,false,true);
Core::FMTtransition newTransition("~FMT_" + p_actionName);
Core::FMTaction newAction(p_actionName,false,true);
Core::FMTtransition newTransition(p_actionName);
std::string BMask;
for (size_t themeId = 0; themeId < newModel.themes.size() - 1; ++themeId)
{
Expand Down Expand Up @@ -2844,7 +2844,7 @@ bool FMTmodel::doplanning(const bool& solve,std::vector<Core::FMTschedule> sched
}
this->swap_ptr(presolved_model);
}catch(...){
_exhandler->raisefromcatch("", " FMTmodel::doplanning", __LINE__, __FILE__);
_exhandler->raisefromcatch(getname(), " FMTmodel::doplanning", __LINE__, __FILE__);
}
return optimal_solved;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/FMTnssmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ namespace Models
simulationdone = true;
}catch(...)
{
_exhandler->raisefromcatch("", "FMTnssmodel::solve", __LINE__, __FILE__);
_exhandler->raisefromcatch(getname(), "FMTnssmodel::build", __LINE__, __FILE__);
}
return simulationdone;
}
Expand Down
15 changes: 15 additions & 0 deletions Source/FMTobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
#include "FMTfreeexceptionhandler.h"
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/stacktrace.hpp>
#include <exception>
#include <chrono>

#if defined __MINGW64__||__CYGWIN__
Expand Down Expand Up @@ -168,6 +170,19 @@ namespace Core

}

void FMTobject::setTerminateStack()
{
std::set_terminate(&FMTobject::_terminate);
}

void FMTobject::_terminate()
{
const std::string TRACE = boost::stacktrace::to_string(boost::stacktrace::stacktrace());
*_logger <<"Terminate due to error\n"<< TRACE << "\n";
_logger->closefilestream();
}


FMTobject::FMTobject(const std::unique_ptr<Exception::FMTexceptionhandler> exhandler)
{
_exhandler = std::move(exhandler->Clone());
Expand Down
8 changes: 5 additions & 3 deletions Source/FMTreplanningtask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ namespace Parallel

for (int replanningperiod = 1; replanningperiod <= replanningperiods; ++replanningperiod)
{

if (replanningperiod != 1)
{
//boost::lock_guard<boost::recursive_mutex> guard(taskmutex);
Expand Down Expand Up @@ -420,7 +419,8 @@ namespace Parallel
setstatus(true);
}catch (...)
{
_exhandler->raisefromthreadcatch("","FMTreplanningtask::work", __LINE__, __FILE__);
const std::string LOCATION = "On thread " + getthreadid() + " on replicate " + std::to_string(getiteration());
_exhandler->raisefromthreadcatch(LOCATION,"FMTreplanningtask::work", __LINE__, __FILE__);
}

}
Expand Down Expand Up @@ -505,7 +505,9 @@ namespace Parallel
return std::move(modelcpy);
}catch (...)
{
_exhandler->raisefromcatch("", "FMTreplanningtask::domodelplanning", __LINE__, __FILE__);
const std::string LOCATION = "Thread:" + getthreadid() + " " + model->getname() +
" replanning period "+std::to_string(replanningperiod) +" replicate " + std::to_string(getiteration());
_exhandler->raisefromcatch(LOCATION, "FMTreplanningtask::domodelplanning", __LINE__, __FILE__);
}
return std::move(std::unique_ptr<Models::FMTmodel>(nullptr));
}
Expand Down
Loading

0 comments on commit 547ff60

Please sign in to comment.