Skip to content

Commit

Permalink
scenario rules
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Jul 19, 2024
1 parent 2da0e70 commit 05aaac0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 29 deletions.
6 changes: 1 addition & 5 deletions src/libs/antares/study/include/antares/study/study.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,6 @@ class Study: public Yuni::NonCopyable<Study>, public LayerData
** \brief Re-Initialize/Re-Load the scenario builder data
*/
void scenarioRulesCreate();
/*!
** \brief Re-Initialize/Re-Load the scenario builder data but consider a single ruleset only
*/
void scenarioRulesCreate(const RulesScenarioName& thisoneonly);

/*!
** \brief Release the scenario builder
Expand Down Expand Up @@ -586,7 +582,7 @@ class Study: public Yuni::NonCopyable<Study>, public LayerData
//! \name Scenario Builder
//@{
//! Rules for building scenarios (can be null)
ScenarioBuilder::Sets* scenarioRules = nullptr;
std::shared_ptr<ScenarioBuilder::Sets> scenarioRules;
//@}

TimeSeries::TS scenarioInitialHydroLevels;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Study::~Study()

void Study::clear()
{
FreeAndNil(scenarioRules);
scenarioRules.reset();
FreeAndNil(uiinfo);

// areas
Expand Down
24 changes: 4 additions & 20 deletions src/libs/antares/study/study.extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,24 @@ String StudyIconFile;
void Study::scenarioRulesCreate()
{
// releasing the previous instance of the scenario builder
delete scenarioRules;
scenarioRules.reset();

// When ran from the solver, the scenario builder must be present
scenarioRules = new ScenarioBuilder::Sets();
scenarioRules->loadFromStudy(*this);
}

void Study::scenarioRulesCreate(const RulesScenarioName& /*thisoneonly*/)
{
// releasing the previous instance of the scenario builder
delete scenarioRules;
// When ran from the solver, the scenario builder must be present
scenarioRules = new ScenarioBuilder::Sets();
scenarioRules = std::make_shared<ScenarioBuilder::Sets>();
scenarioRules->loadFromStudy(*this);
}

void Study::scenarioRulesDestroy()
{
if (scenarioRules)
{
// releasing the previous instance of the scenario builder
// safety dereferencing for the interface if running
ScenarioBuilder::Sets* sb = scenarioRules;
scenarioRules = nullptr;
delete sb;
}
scenarioRules.reset();
}

void Study::scenarioRulesLoadIfNotAvailable()
{
if (!scenarioRules)
{
// When ran from the solver, the scenario builder must be present
scenarioRules = new ScenarioBuilder::Sets();
scenarioRules = std::make_shared<ScenarioBuilder::Sets>();
scenarioRules->loadFromStudy(*this);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/inmemory-study/in-memory-study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ averageResults OutputRetriever::thermalNbUnitsON(ThermalCluster* cluster)
ScenarioBuilderRule::ScenarioBuilderRule(Study& study)
{
study.scenarioRulesCreate();
ScenarioBuilder::Sets* sets = study.scenarioRules;
auto sets = study.scenarioRules;
if (sets && !sets->empty())
{
rules_ = sets->createNew("Custom");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ struct commonFixture
study->bindingConstraintsGroups.add("group3");

// Scenario builder initialization
study->scenarioRules = new ScenarioBuilder::Sets();
study->scenarioRules = std::make_shared<ScenarioBuilder::Sets>();
study->scenarioRules->setStudy(*study);
my_rule = study->scenarioRules->createNew("my rule name");
BOOST_CHECK(my_rule->reset());
Expand Down
2 changes: 1 addition & 1 deletion src/ui/simulator/application/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ void ApplWnd::onSectionNotebookPageChanging(Component::Notebook::Page& page)
auto* job = new JobLoadScenarioBuilder(*study);
wxTheApp->Yield();
job->run();
study->scenarioRules = job->scenarioBuilder();
study->scenarioRules.reset(job->scenarioBuilder());
job->Destroy();
}

Expand Down

0 comments on commit 05aaac0

Please sign in to comment.