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

Add tests for time-series handling #2637

Merged
merged 6 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions src/expressions/visitors/EvalVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ EvaluationResult EvalVisitor::visit(const Nodes::ParameterNode* node)
timeStep <= dataSeriesKeys_.fillContext.getLastTimeStep();
++timeStep)
{
params.emplace_back(
context_.getParameterValue(context_.getSystemParameterValue(node->value()),
dataSeriesKeys_.scenarioGroup,
dataSeriesKeys_.scenario,
timeStep));
params.emplace_back(context_.getParameterValue(node->value(),
dataSeriesKeys_.scenarioGroup,
dataSeriesKeys_.scenario,
timeStep));
}
return EvaluationResult{params};
}
Expand Down
8 changes: 4 additions & 4 deletions src/io/inputs/yml-system/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ static SystemModel::Component createComponent(const YmlSystem::Component& c,

// TODO we need type
std::map<std::string, Expressions::Visitors::ContextParameter> parameters;
for (const auto& [id, type, value]: c.parameters)
for (const auto& [id, time_dependent, scenario_dependent, value]: c.parameters)
{
parameters.try_emplace(id,
Expressions::Visitors::ContextParameter{
.id = id,
.type = type == "constant" // TODO apply tolower ?
? Expressions::Visitors::ParameterType::CONSTANT
: Expressions::Visitors::ParameterType::TIMESERIE,
.type = time_dependent
? Expressions::Visitors::ParameterType::TIMESERIE
: Expressions::Visitors::ParameterType::CONSTANT,
.value = value});
}

Expand Down
3 changes: 2 additions & 1 deletion src/io/inputs/yml-system/decoders.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ struct convert<Antares::IO::Inputs::YmlSystem::Parameter>
return false;
}
rhs.id = node["id"].as<std::string>();
rhs.type = node["type"].as<std::string>();
rhs.time_dependent = node["time-dependent"].as<bool>();
rhs.scenario_dependent = node["scenario-dependent"].as<bool>();
rhs.value = node["value"].as<std::string>();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace Antares::IO::Inputs::YmlSystem
struct Parameter
{
std::string id;
std::string type;
bool time_dependent;
bool scenario_dependent;
std::string value;
};

Expand Down
8 changes: 1 addition & 7 deletions src/solver/modeler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include <antares/solver/modeler/loadFiles/loadFiles.h>
#include <antares/solver/modeler/parameters/parseModelerParameters.h>
#include <antares/solver/optim-model-filler/ComponentFiller.h>
#include "antares/optimisation/linear-problem-api/linearProblem.h"
#include "antares/optimisation/linear-problem-data-impl/timeSeriesSet.h"

using namespace Antares::Optimisation::LinearProblemMpsolverImpl;
using namespace Antares;
Expand Down Expand Up @@ -67,13 +65,9 @@ class SystemLinearProblem

LinearProblemBuilder linear_problem_builder(fillers_ptr);
LinearProblemData data(dataSeriesRepo);
// const auto number_of_timeStep = parameters.lastTimeStep - parameters.firstTimeStep + 1;
// std::vector<unsigned int> timeSteps(number_of_timeStep);
// std::ranges::generate(timeSteps, [i = parameters.firstTimeStep]() mutable { return i++;
// });

FillContext dummy_time_scenario_ctx = {parameters.firstTimeStep, parameters.lastTimeStep};
linear_problem_builder.build(pb, data, dummy_time_scenario_ctx);

}

private:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: 2.8

Scenario: 2.8.1: One model with one load and two generators, one timestep
Given the study path is "modeler/1_1"
When I run antares modeler
Then the simulation succeeds
And the objective value is 160
And the optimal value of variable node1.gen1_p_0 is 80
And the optimal value of variable node1.gen2_p_0 is 20
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
80
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
200
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
library:
id: lib_example_1_1
description: test model library

models:
- id: node_2gen_1load
description: A simple node with two generators and one load
parameters:
- id: load
time-dependent: true
scenario-dependent: false
- id: gen1_max_p
time-dependent: true
scenario-dependent: false
- id: gen1_prop_cost
time-dependent: true
scenario-dependent: false
- id: gen2_max_p
time-dependent: true
scenario-dependent: false
- id: gen2_prop_cost
time-dependent: true
scenario-dependent: false
variables:
- id: gen1_p
lower-bound: 0
upper-bound: gen1_max_p
variable-type: continuous
- id: gen2_p
lower-bound: 0
upper-bound: gen2_max_p
variable-type: continuous
constraints:
- id: balance
expression: gen1_p + gen2_p - load = 0
objective: gen1_p * gen1_prop_cost + gen2_p * gen2_prop_cost
30 changes: 30 additions & 0 deletions src/tests/resources/modeler/1_1/input/system.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
system:
id: sys_example_1_1
description: test system
model-libraries: lib_example_1_1

components:
- id: node1
model: lib_example_1_1.node_2gen_1load
scenario-group: sg
parameters:
- id: load
time-dependent: true
scenario-dependent: false
value: load_1_1
- id: gen1_max_p
time-dependent: true
scenario-dependent: false
value: gen1_max_p_1_1
- id: gen1_prop_cost
time-dependent: true
scenario-dependent: false
value: gen1_prop_cost_1_1
- id: gen2_max_p
time-dependent: true
scenario-dependent: false
value: gen2_max_p_1_1
- id: gen2_prop_cost
time-dependent: true
scenario-dependent: false
value: gen2_prop_cost_1_1
6 changes: 6 additions & 0 deletions src/tests/resources/modeler/1_1/parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
solver: xpress
solver-logs: true
solver-parameters: THREADS 1
no-output: false
first-time-step: 0
last-time-step: 0
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ system:
scenario-group: sg
parameters:
- id: load
type: constant
time-dependent: false
scenario-dependent: false
value: 100
- id: gen1_max_p
type: constant
time-dependent: false
scenario-dependent: false
value: 80
- id: gen1_prop_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 0.5
- id: gen2_max_p
type: constant
time-dependent: false
scenario-dependent: false
value: 200
- id: gen2_prop_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 6
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,30 @@ system:
scenario-group: sg
parameters:
- id: load
type: constant
time-dependent: false
scenario-dependent: false
value: 100
- id: gen1_max_p
type: constant
time-dependent: false
scenario-dependent: false
value: 80
- id: gen1_min_p
type: constant
time-dependent: false
scenario-dependent: false
value: 1
- id: gen1_prop_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 0.5
- id: gen2_max_p
type: constant
time-dependent: false
scenario-dependent: false
value: 200
- id: gen2_min_p
type: constant
time-dependent: false
scenario-dependent: false
value: 40
- id: gen2_prop_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 6
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,55 @@ system:
scenario-group: sg
parameters:
- id: load
type: constant
time-dependent: false
scenario-dependent: false
value: 100
- id: gen1_max_p
type: constant
time-dependent: false
scenario-dependent: false
value: 80
- id: gen1_prop_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 60
- id: gen2_max_p
type: constant
time-dependent: false
scenario-dependent: false
value: 200
- id: gen2_prop_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 6

- id: node2
model: lib_example2.node_2gen_1load_mingen
scenario-group: sg
parameters:
- id: load
type: constant
time-dependent: false
scenario-dependent: false
value: 1000
- id: gen1_max_p
type: constant
time-dependent: false
scenario-dependent: false
value: 650
- id: gen1_min_p
type: constant
time-dependent: false
scenario-dependent: false
value: 200
- id: gen1_prop_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 10
- id: gen2_max_p
type: constant
time-dependent: false
scenario-dependent: false
value: 1000
- id: gen2_min_p
type: constant
time-dependent: false
scenario-dependent: false
value: 500
- id: gen2_prop_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 20
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ system:
scenario-group: sg
parameters:
- id: load
type: constant
time-dependent: false
scenario-dependent: false
value: 1000
- id: gen_min_p
type: constant
time-dependent: false
scenario-dependent: false
value: 150
- id: gen_max_p
type: constant
time-dependent: false
scenario-dependent: false
value: 300
- id: gen_cluster_size
type: constant
time-dependent: false
scenario-dependent: false
value: 10
- id: gen_prop_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 0.5
- id: gen_fixed_cost
type: constant
time-dependent: false
scenario-dependent: false
value: 10
18 changes: 12 additions & 6 deletions src/tests/src/io/yml-importers/testSystemConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ BOOST_FIXTURE_TEST_CASE(full_model_system, LibraryObjects)
scenario-group: group-234
parameters:
- id: cost
type: constant
time-dependent: false
scenario-dependent: false
value: 30
)"s;

Expand All @@ -99,7 +100,8 @@ BOOST_FIXTURE_TEST_CASE(bad_param_name_in_component, LibraryObjects)
scenario-group: group-234
parameters:
- id: param_not_in_model
type: constant
time-dependent: false
scenario-dependent: false
value: 30
)"s;

Expand Down Expand Up @@ -154,7 +156,8 @@ BOOST_FIXTURE_TEST_CASE(bad_library_model_format, LibraryObjects)
scenario-group: group-234
parameters:
- id: cost
type: constant
time-dependent: false
scenario-dependent: false
value: 30
)"s;

Expand Down Expand Up @@ -242,18 +245,21 @@ BOOST_AUTO_TEST_CASE(Full_system_test)
scenario-group: group-234
parameters:
- id: cost
type: constant
time-dependent: false
scenario-dependent: false
value: 30
- id: p_max
type: constant
time-dependent: false
scenario-dependent: false
value: 100

- id: D
model: mylib.demand
scenario-group: group-qsf
parameters:
- id: demand
type: constant
time-dependent: false
scenario-dependent: false
value: 100
)"s;

Expand Down
Loading
Loading