Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Feb 6, 2025
1 parent b28a867 commit a87fa28
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/io/inputs/yml-system/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ static SystemModel::Component createComponent(const YmlSystem::Component& c,

SystemModel::ComponentBuilder component_builder;

std::map<std::string, double> parameters;
std::map<std::string, Expressions::Visitors::ComponentParameter> parameters;
for (const auto& p: c.parameters)
{
parameters.try_emplace(p.id, p.value);
parameters.try_emplace(p.id,
Expressions::Visitors::ComponentParameter{.id = p.id,
.type = p.type,
.value = p.value});
}

auto component = component_builder.withId(c.id)
Expand Down
4 changes: 2 additions & 2 deletions src/io/inputs/yml-system/decoders.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ struct convert<Antares::IO::Inputs::YmlSystem::Parameter>
}
rhs.id = node["id"].as<std::string>();
rhs.type = node["type"].as<std::string>();
rhs.value = node["value"].as<double>();
// value could be filename or double in which case it'll be converted later
rhs.value = node["value"].as<std::string>();
return true;
}
};

template<>
struct convert<Antares::IO::Inputs::YmlSystem::Component>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Parameter
{
std::string id;
std::string type;
double value;
std::string value;
};

struct Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma once

#include <string>
#include <vector>

namespace Antares::Optimisation::LinearProblemApi
{
Expand All @@ -13,6 +14,10 @@ class ILinearProblemData
const unsigned scenario,
const unsigned hour)
= 0;
virtual std::vector<double> getData(const std::string& dataSetId,
const std::string& scenarioGroup,
const unsigned scenario)
= 0;
};

} // namespace Antares::Optimisation::LinearProblemApi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma once

#include <string>
#include <vector>

namespace Antares::Optimisation::LinearProblemDataImpl
{
Expand All @@ -15,6 +16,7 @@ class IDataSeries
}

virtual double getData(unsigned int rank, unsigned int hour) = 0;
virtual std::vector<double> getData(unsigned int rank) = 0;

std::string name() const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class LinearProblemData: public LinearProblemApi::ILinearProblemData
const unsigned scenario,
const unsigned hour) override;

std::vector<double> getData(const std::string& dataSetId,
const std::string& scenarioGroup,
const unsigned scenario) override;

void addScenarioGroup(const std::string& groupId, std::pair<unsigned, unsigned> scenarioToRank);
void addDataSeries(std::unique_ptr<IDataSeries> dataSeries);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TimeSeriesSet: public IDataSeries
explicit TimeSeriesSet(std::string name, unsigned height);
void add(const std::vector<double>& ts);
double getData(unsigned rank, unsigned hour) override;
std::vector<double> getData(unsigned int rank) override;

private:
unsigned height_ = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ double LinearProblemData::getData(const std::string& dataSetId,
return dataSeriesRepository_.getDataSeries(dataSetId).getData(rank, hour);
}

std::vector<double> LinearProblemData::getData(const std::string& dataSetId,
const std::string& scenarioGroup,
const unsigned scenario)
{
unsigned rank = groupRepository_.getDataRank(scenarioGroup, scenario);
return dataSeriesRepository_.getDataSeries(dataSetId).getData(rank);
}

} // namespace Antares::Optimisation::LinearProblemDataImpl
17 changes: 11 additions & 6 deletions src/optimisation/linear-problem-data-impl/timeSeriesSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ void TimeSeriesSet::add(const std::vector<double>& ts)
}

double TimeSeriesSet::getData(unsigned rank, unsigned hour)
{
if (hour > height_ - 1)
{
throw HourTooBig(name(), hour);
}

return getData(rank)[hour];
}

std::vector<double> TimeSeriesSet::getData(unsigned int rank)
{
if (tsSet_.empty())
{
Expand All @@ -32,11 +42,6 @@ double TimeSeriesSet::getData(unsigned rank, unsigned hour)
throw RankTooBig(name(), rank);
}

if (hour > height_ - 1)
{
throw HourTooBig(name(), hour);
}

return tsSet_[rank][hour];
return tsSet_[rank];
}
} // namespace Antares::Optimisation::LinearProblemDataImpl
4 changes: 2 additions & 2 deletions src/solver/optim-model-filler/ComponentFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Antares::Optimization

ComponentFiller::ComponentFiller(const Study::SystemModel::Component& component):
component_(component),
evaluationContext_(component_.getParameterValues(), {}),
/*evaluationContext_(component_.getParameterValues(), {}),*/
modelVariable_(component.getModel()->Variables())

{
Expand All @@ -53,7 +53,7 @@ void ComponentFiller::addVariables(Optimisation::LinearProblemApi::ILinearProble
// exception?
return;
}

Expressions::Visitors::EvaluationContext;
Expressions::Visitors::EvalVisitor evaluator(evaluationContext_);
for (const auto& variable: component_.getModel()->Variables() | std::views::values)
{
Expand Down
2 changes: 1 addition & 1 deletion src/study/system-model/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ComponentBuilder& ComponentBuilder::withModel(const Model* model)
* \return Reference to the ComponentBuilder object.
*/
ComponentBuilder& ComponentBuilder::withParameterValues(
std::map<std::string, double> parameter_values)
std::map<std::string, Expressions::Visitors::ComponentParameter> parameter_values)
{
data_.parameter_values = std::move(parameter_values);
return *this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <map>

#include "antares/expressions/visitors/EvaluationContext.h"

#include "model.h"

namespace Antares::Study::SystemModel
Expand All @@ -36,7 +38,7 @@ class ComponentData
public:
std::string id;
const Model* model = nullptr;
std::map<std::string, double> parameter_values;
std::map<std::string, Expressions::Visitors::ComponentParameter> parameter_values;
std::string scenario_group_id;

void reset()
Expand Down Expand Up @@ -67,12 +69,14 @@ class Component
return data_.model;
}

const std::map<std::string, double>& getParameterValues() const
const std::map<std::string, Expressions::Visitors::ComponentParameter>& getParameterValues()
const
{
return data_.parameter_values;
}

double getParameterValue(const std::string& parameter_id) const
Expressions::Visitors::ComponentParameter getParameterValue(
const std::string& parameter_id) const
{
if (!data_.parameter_values.contains(parameter_id))
{
Expand All @@ -99,7 +103,8 @@ class ComponentBuilder
public:
ComponentBuilder& withId(std::string_view id);
ComponentBuilder& withModel(const Model* model);
ComponentBuilder& withParameterValues(std::map<std::string, double> parameter_values);
ComponentBuilder& withParameterValues(
std::map<std::string, Expressions::Visitors::ComponentParameter> parameter_values);
ComponentBuilder& withScenarioGroupId(const std::string& scenario_group_id);
Component build();

Expand Down

0 comments on commit a87fa28

Please sign in to comment.