Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data for modeler (epic 4.1) #2577

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8459ed0
Data for new modeler : make class linearProblemData derive from an in…
guilpier-code Jan 13, 2025
df7656c
Data for new modeler (4.1) : passing new interface ILinearProblemData…
guilpier-code Jan 14, 2025
d6db716
[skip ci] Data for new modeler (4.1) : clang format
guilpier-code Jan 14, 2025
2c2b769
[skip ci] Data for new modeler (4.1) : remove commented code
guilpier-code Jan 16, 2025
7701b5b
Data for new modeler (4.1) : adding a data series repository to class…
guilpier-code Jan 16, 2025
448ca34
Data for new modeler (4.1) : separate linear problem data implementat…
guilpier-code Jan 16, 2025
252a670
Data for new modeler (4.1) : packaging a data-series-lib library
guilpier-code Jan 17, 2025
60cf26b
Data for new modeler (4.1) : clang format
guilpier-code Jan 17, 2025
a12cb4b
Data for new modeler (4.1) : coding scenario group repository
guilpier-code Jan 17, 2025
99c2a7f
Data for new modeler (4.1) : testing scenario group repository
guilpier-code Jan 17, 2025
1816792
Data for new modeler (4.1) : avoid use of std::format(..)
guilpier-code Jan 17, 2025
2ad9df2
Data for new modeler (4.1) : fix for Linux
guilpier-code Jan 17, 2025
965173f
Data for new modeler (4.1) : adding an implementation of IDataSeries …
guilpier-code Jan 17, 2025
fe02503
Data for new modeler (4.1) : coding the data series repository
guilpier-code Jan 17, 2025
a73c08d
Data for new modeler (4.1) : compilation fix
guilpier-code Jan 17, 2025
ce46a25
Data for new modeler (4.1) : clang format
guilpier-code Jan 17, 2025
12f6d0c
Data for new modeler (4.1) : unit testing for time series set
guilpier-code Jan 20, 2025
9d4d566
Data for new modeler (4.1) : clang format
guilpier-code Jan 20, 2025
35cd165
Data for new modeler (4.1) : mainly testind data series repository
guilpier-code Jan 20, 2025
62a5437
Data for new modeler (4.1) : start for testing linear problem data
guilpier-code Jan 20, 2025
3eea870
Data for new modeler (4.1) : moving linear problem data (from api to …
guilpier-code Jan 21, 2025
f7829c0
Data for new modeler (4.1) : tiny corrections
guilpier-code Jan 21, 2025
654b97e
Data for new modeler (4.1) : adding unit tests on linear problem data
guilpier-code Jan 21, 2025
6118f76
Data for new modeler (4.1) : adding unit tests on time series set
guilpier-code Jan 21, 2025
ea803e8
Merge remote-tracking branch 'remotes/origin/develop' into feature/da…
guilpier-code Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set(TARGET_LIBS #No alias
# model_antares
infeasible_problem_analysis
modeler_api
data-series-lib
modeler-ortools-impl

# solver-lib
Expand Down
10 changes: 6 additions & 4 deletions src/solver/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(api)
add_subdirectory(dataSeries)
add_subdirectory(ortoolsImpl)
add_subdirectory(loadFiles)
add_subdirectory(parameters)
Expand All @@ -22,15 +23,16 @@ target_link_libraries(modeler-lib
INTERFACE
Antares::loadModelerFiles
Antares::modelerParameters
Antares::optim-model-filler
Antares::modeler_api
# TODO FIXME don't depend on implementations
Antares::modeler-ortools-impl
Antares::optim-model-filler
Antares::modeler_api
# TODO FIXME don't depend on implementations
Antares::modeler-ortools-impl
)

target_link_libraries(antares-modeler
PRIVATE
modeler-lib
data-series-lib
)

import_std_libs(antares-modeler)
Expand Down
7 changes: 3 additions & 4 deletions src/solver/modeler/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ set(SRC_API
include/antares/solver/modeler/api/hasBounds.h
include/antares/solver/modeler/api/hasName.h

include/antares/solver/modeler/api/ILinearProblemData.h
include/antares/solver/modeler/api/linearProblem.h
include/antares/solver/modeler/api/linearProblemData.h
include/antares/solver/modeler/api/linearProblemFiller.h
include/antares/solver/modeler/api/linearProblemBuilder.h

linearProblemData.cpp
Copy link
Contributor Author

@guilpier-code guilpier-code Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class LinearProblemData was moved from here (src/solver/modeler/api) to src/solver/modeler/dataSeries

linearProblemBuilder.cpp
linearProblemBuilder.cpp
)

add_library(${PROJ} ${SRC_API})
Expand All @@ -24,5 +23,5 @@ set_target_properties(${PROJ} PROPERTIES LINKER_LANGUAGE CXX)

target_include_directories(${PROJ}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#pragma once

#include <string>

namespace Antares::Solver::Modeler::Api
{

class ILinearProblemData
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concrete class LinearProblemData now inherits from abstract class ILinearProblemData

{
virtual double getData(std::string idTimeSeriesSet,
std::string scenarioGroup,
unsigned int scenario,
unsigned int hour)
= 0;
};

} // namespace Antares::Solver::Modeler::Api
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LinearProblemBuilder
{
public:
explicit LinearProblemBuilder(const std::vector<LinearProblemFiller*>& fillers);
void build(ILinearProblem& pb, LinearProblemData& data, FillContext& ctx);
void build(ILinearProblem& pb, ILinearProblemData& data, FillContext& ctx);

private:
const std::vector<LinearProblemFiller*>& fillers_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

#include <memory>

#include <antares/solver/modeler/api/ILinearProblemData.h>
#include <antares/solver/modeler/api/linearProblem.h>
#include <antares/solver/modeler/api/linearProblemData.h>

namespace Antares::Solver::Modeler::Api
{
Expand Down Expand Up @@ -57,9 +57,9 @@ struct FillContext
class LinearProblemFiller
{
public:
virtual void addVariables(ILinearProblem& pb, LinearProblemData& data, FillContext& ctx) = 0;
virtual void addConstraints(ILinearProblem& pb, LinearProblemData& data, FillContext& ctx) = 0;
virtual void addObjective(ILinearProblem& pb, LinearProblemData& data, FillContext& ctx) = 0;
virtual void addVariables(ILinearProblem& pb, ILinearProblemData& data, FillContext& ctx) = 0;
virtual void addConstraints(ILinearProblem& pb, ILinearProblemData& data, FillContext& ctx) = 0;
virtual void addObjective(ILinearProblem& pb, ILinearProblemData& data, FillContext& ctx) = 0;
virtual ~LinearProblemFiller() = default;
};

Expand Down
2 changes: 1 addition & 1 deletion src/solver/modeler/api/linearProblemBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ LinearProblemBuilder::LinearProblemBuilder(const std::vector<LinearProblemFiller
{
}

void LinearProblemBuilder::build(ILinearProblem& pb, LinearProblemData& data, FillContext& ctx)
void LinearProblemBuilder::build(ILinearProblem& pb, ILinearProblemData& data, FillContext& ctx)
{
std::ranges::for_each(fillers_,
[&](const auto& filler) { filler->addVariables(pb, data, ctx); });
Expand Down
27 changes: 27 additions & 0 deletions src/solver/modeler/dataSeries/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

set(SRC_DATA_SERIES
include/antares/solver/modeler/dataSeries/dataSeries.h
include/antares/solver/modeler/dataSeries/timeSeriesSet.h
include/antares/solver/modeler/dataSeries/dataSeriesRepo.h
include/antares/solver/modeler/dataSeries/scenarioGroupRepo.h
include/antares/solver/modeler/dataSeries/linearProblemData.h

timeSeriesSet.cpp
dataSeriesRepo.cpp
scenarioGroupRepo.cpp
linearProblemData.cpp
)

add_library(data-series-lib ${SRC_DATA_SERIES})
set_target_properties(data-series-lib PROPERTIES LINKER_LANGUAGE CXX)

target_link_libraries(data-series-lib
PUBLIC
modeler_api
)

target_include_directories(data-series-lib
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

28 changes: 28 additions & 0 deletions src/solver/modeler/dataSeries/dataSeriesRepo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "antares/solver/modeler/dataSeries/dataSeriesRepo.h"

#include <stdexcept>

namespace Antares::Solver::Modeler::DataSeries
{
void DataSeriesRepository::addDataSeries(std::unique_ptr<IDataSeries> dataSeries)
{
std::string name = dataSeries->name();
dataSeries_[name] = std::move(dataSeries);
}

IDataSeries& DataSeriesRepository::getDataSeries(std::string setId)
{
std::string error_message = err_prefix;
if (dataSeries_.empty())
{
error_message += "empty";
throw std::invalid_argument(error_message);
}
if (!dataSeries_.contains(setId))
{
error_message += "data series '" + setId + "' does not exist";
throw std::invalid_argument(error_message);
}
return *(dataSeries_[setId]);
}
} // namespace Antares::Solver::Modeler::DataSeries
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#pragma once

#include <string>

namespace Antares::Solver::Modeler::DataSeries
{

class IDataSeries
{
public:
IDataSeries(std::string name):
name_(name)
{
}

virtual double getData(unsigned int rank, unsigned int hour) = 0;

std::string name()
{
return name_;
}

private:
std::string name_;
};

} // namespace Antares::Solver::Modeler::DataSeries
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#pragma once

#include <map>
#include <memory>
#include <string>

#include "dataSeries.h"

namespace Antares::Solver::Modeler::DataSeries
{

class DataSeriesRepository
{
public:
void addDataSeries(std::unique_ptr<IDataSeries> dataSeries);
Copy link
Contributor Author

@guilpier-code guilpier-code Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About void addDataSeries(...) : forces to std::move a unique pointer defined outside.
So the client IDataSeries gets empty after this call.
I thought it's suitable, as data series have to end up inside the data series repository and seem useless somewhere else.

IDataSeries& getDataSeries(std::string setId);

private:
std::map<std::string, std::unique_ptr<IDataSeries>> dataSeries_;
std::string err_prefix = "Data series repo : ";
};

} // namespace Antares::Solver::Modeler::DataSeries
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,26 @@

#pragma once

#include <map>
#include <string>
#include <vector>

namespace Antares::Solver::Modeler::Api
#include "antares/solver/modeler/api/ILinearProblemData.h"
#include "antares/solver/modeler/dataSeries/dataSeriesRepo.h"
#include "antares/solver/modeler/dataSeries/scenarioGroupRepo.h"

namespace Antares::Solver::Modeler::DataSeries
{

class LinearProblemData
class LinearProblemData: public Api::ILinearProblemData
{
public:
unsigned getTimeResolutionInMinutes();
bool hasScalarData(const std::string& key);
double getScalarData(const std::string& key, unsigned scenario);
bool hasTimedData(const std::string& key);
const std::vector<double>& getTimedData(const std::string& key, unsigned scenario);
double getData(std::string idTimeSeriesSet,
std::string scenarioGroup,
unsigned int scenario,
unsigned int hour) override;

private:
std::vector<int> timeStamps_;
unsigned timeResolutionInMinutes_;
std::map<std::string, std::vector<double>> scalarData_;
std::map<std::string, std::vector<std::vector<double>>> timedData_;
DataSeries::DataSeriesRepository dataSeriesRepository_;
DataSeries::ScenarioGroupRepository groupRepository_;
};

} // namespace Antares::Solver::Modeler::Api
} // namespace Antares::Solver::Modeler::DataSeries
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#pragma once
#include <map>
#include <string>

namespace Antares::Solver::Modeler::DataSeries
{
class ScenarioGroupRepository
{
public:
void addPairScenarioRankToGroup(std::string groupId,
std::pair<unsigned, unsigned> scenarioToRank);

unsigned getDataRank(std::string groupId, unsigned scenario);

private:
std::map<std::string, std::map<unsigned, unsigned>> scenarioGroups_;
};
} // namespace Antares::Solver::Modeler::DataSeries
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <string>
#include <vector>

#include "dataSeries.h"

namespace Antares::Solver::Modeler::DataSeries
{
class TimeSeriesSet: public IDataSeries
Copy link
Contributor Author

@guilpier-code guilpier-code Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class TimeSeriesSet is supposed to be out of epic 4.1's scope.
But we needed a concrete child of IDataSeries in order to unit test other classes (for instance DataSeriesRepository).
This class can end up not required and removed at some point.
It comes with unit tests (see testTimeSeriesSet.cpp).

{
public:
explicit TimeSeriesSet(std::string name, unsigned height);
void add(std::vector<double> ts);
double getData(unsigned rank, unsigned hour) override;

private:
unsigned height_ = 0;
std::vector<std::vector<double>> tsSet_;
std::string err_prefix_;
};

} // namespace Antares::Solver::Modeler::DataSeries
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,16 @@
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#include <antares/solver/modeler/api/linearProblemData.h>
#include "antares/solver/modeler/dataSeries/linearProblemData.h"

namespace Antares::Solver::Modeler::Api
namespace Antares::Solver::Modeler::DataSeries
{

unsigned LinearProblemData::getTimeResolutionInMinutes()
{
return timeResolutionInMinutes_;
}

bool LinearProblemData::hasScalarData(const std::string& key)
{
return scalarData_.contains(key);
}

double LinearProblemData::getScalarData(const std::string& key, unsigned scenario)
{
return scalarData_.at(key)[scenario];
}

bool LinearProblemData::hasTimedData(const std::string& key)
{
return timedData_.contains(key);
}

const std::vector<double>& LinearProblemData::getTimedData(const std::string& key,
unsigned scenario)
double LinearProblemData::getData(std::string idTimeSeriesSet,
std::string scenarioGroup,
unsigned int scenario,
unsigned int hour)
{
return timedData_.at(key)[scenario];
return 0.;
}

} // namespace Antares::Solver::Modeler::Api
} // namespace Antares::Solver::Modeler::DataSeries
31 changes: 31 additions & 0 deletions src/solver/modeler/dataSeries/scenarioGroupRepo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "include/antares/solver/modeler/dataSeries/scenarioGroupRepo.h"

#include <stdexcept>

namespace Antares::Solver::Modeler::DataSeries
{
void ScenarioGroupRepository::addPairScenarioRankToGroup(
std::string groupId,
std::pair<unsigned, unsigned> scenarioToRank)
{
scenarioGroups_[groupId] = {scenarioToRank};
}

unsigned ScenarioGroupRepository::getDataRank(std::string groupId, unsigned scenario)
{
if (!scenarioGroups_.contains(groupId))
{
std::string error_message = "Group '" + groupId + "' does not exist in group repo.";
throw std::invalid_argument(error_message);
}

if (!scenarioGroups_.at(groupId).contains(scenario))
{
std::string error_message = "In scenario group '" + groupId + "', scenario '"
+ std::to_string(scenario) + "' does not exist.";
throw std::invalid_argument(error_message);
}

return scenarioGroups_.at(groupId).at(scenario);
}
} // namespace Antares::Solver::Modeler::DataSeries
Loading
Loading