Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d438209
Base to ckecl expression
Nov 26, 2025
0c70ad6
reduced cost
Nov 26, 2025
e6317b8
dual handling
Nov 26, 2025
c20bf08
add loop on lib and models
Nov 26, 2025
9242a94
continue
Nov 26, 2025
78f22ae
move code related to functions node in another functiong
Nov 26, 2025
6e5b2f0
fix segfault when reduced cost with parameter
Nov 26, 2025
4273f3f
quality
Nov 26, 2025
fb73142
Construct var node
Nov 27, 2025
d76ed93
format
Nov 27, 2025
8d91f61
better name for exception
Nov 27, 2025
67297cd
rm lambda
Nov 27, 2025
c517057
handle portfieldsum
Nov 27, 2025
54ad5fc
rm lambda
Nov 27, 2025
80efcc3
add checklocation cpp
Nov 28, 2025
adc0b57
Move code to checkLocation.cpp
Nov 28, 2025
8a94e32
improve exception message
Nov 28, 2025
65383ea
improve exception message
Nov 28, 2025
e12d570
specialize exceptions, handle pfsum
Nov 28, 2025
c76d4d0
create the error msg once
Nov 28, 2025
df66c1d
use correct port id
Dec 1, 2025
388522f
const AST and function
Dec 1, 2025
1a5aa3c
move check for hybrid
Dec 1, 2025
a3be6a2
add a separated header
Dec 1, 2025
4f49a07
add unit test file
Dec 1, 2025
b76c467
test for dual and reduced cost
Dec 1, 2025
28cce06
base to test portfield
Dec 1, 2025
c64b181
portfield test
Dec 1, 2025
8c0e03d
location to str and compatible
Dec 1, 2025
b868d4b
stricter location
Dec 1, 2025
988ca55
test location compatible for expressions
Dec 1, 2025
34890df
format
Dec 1, 2025
db6d39d
move function to cpp file
Dec 2, 2025
8d9a982
Add a test with valid portfield
Dec 2, 2025
29f88c8
Add test for portfield sum
Dec 2, 2025
59960dd
check for port id
Dec 2, 2025
f528667
comments 1
Dec 3, 2025
59ec64f
comments 2 fmt
Dec 3, 2025
2d89de1
create a separated check folder
Dec 3, 2025
badd38a
format
Dec 3, 2025
ba60c37
Update src/io/inputs/model-converter/convertorVisitor.cpp
flomnes Dec 9, 2025
806901f
mege conflicts
Dec 9, 2025
f389db3
Merge branch 'feature/valid-location' of https://github.com/AntaresSi…
Dec 9, 2025
d06de83
add const to checks
Dec 9, 2025
99686f4
loop on components
Dec 9, 2025
f3fbc9d
unit tests
Dec 9, 2025
316ef0e
Merge remote-tracking branch 'origin' into feature/valid-location
Dec 9, 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
18 changes: 8 additions & 10 deletions src/io/inputs/model-converter/convertorVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,18 +444,16 @@ std::any ConvertorVisitor::handleReducedCost(ExprParser::ArgListContext* context
+ params);
}

std::vector<Node*> nodes;
try
for (const auto& var: model_.variables)
{
nodes = std::any_cast<std::vector<Node*>>(context->accept(this));
}
catch (const NoParameterOrVariableWithThisName&) // to print accurate message
{
throw NoVariableWithThisName(model_.id, context->expr(0)->getText());
if (var.id == variableId.at(0)->getText())
{
std::vector<Node*> nodes = std::any_cast<std::vector<Node*>>(context->accept(this));
return static_cast<Node*>(
registry_.create<FunctionNode>(FunctionNodeType::reduced_cost, nodes.at(0)));
}
}

return static_cast<Node*>(
registry_.create<FunctionNode>(FunctionNodeType::reduced_cost, nodes.at(0)));
throw NoVariableWithThisName(model_.id, context->expr(0)->getText());
}

template<class T>
Expand Down
132 changes: 132 additions & 0 deletions src/modeler/modeler/Modeler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

#include <chrono>
#include <fstream>
#include <stdexcept>

#include <antares/expressions/iterators/pre-order.h>
#include <antares/logs/logs.h>
#include <antares/optimisation/linear-problem-api/linearProblem.h>
#include <antares/optimisation/linear-problem-api/linearProblemBuilder.h>
Expand All @@ -36,6 +38,8 @@
#include "antares/solver/modeler/IWriter.h"
#include "antares/utils/utils.h"

#include "include/antares/solver/modeler/data.h"

using namespace Antares::Optimisation::LinearProblemMpsolverImpl;
using namespace Antares;
using namespace Antares::Optimization;
Expand Down Expand Up @@ -103,6 +107,133 @@
BendersDecomposition* bendersDecomposition_ = nullptr;
};

void checkFunctionNode(Antares::Expressions::Nodes::Node& node,
Antares::ModelerStudy::SystemModel::Model& model)
{
// dual and reduced_cost can only be used in subproblems
if (auto* functionNode = dynamic_cast<Antares::Expressions::Nodes::FunctionNode*>(&node);
functionNode)
{
if (functionNode->type() == Antares::Expressions::Nodes::FunctionNodeType::reduced_cost)
{
const auto varNode = dynamic_cast<Nodes::VariableNode*>(

Check warning on line 119 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change this declaration specifying the "pointer" part outside of auto.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrAk50-wNnx40IUmtwx&open=AZrAk50-wNnx40IUmtwx&pullRequest=3258
functionNode->getOperands().at(0));
for (const auto& variable: model.Variables())
{
if (variable.Id() == varNode->value())
{
if (variable.location() != Antares::Modeler::Config::Location::SUBPROBLEMS)

Check warning on line 125 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kM8&open=AZrA9E2KsPOyFzXT2kM8&pullRequest=3258
{
throw std::runtime_error("Reduced costs can only be used in subproblems");

Check warning on line 127 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define and throw a dedicated exception instead of using a generic one.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kM9&open=AZrA9E2KsPOyFzXT2kM9&pullRequest=3258
}
}
}
}

if (functionNode->type() == Antares::Expressions::Nodes::FunctionNodeType::dual)
{
// This node contains the constraint name
const auto n = dynamic_cast<Nodes::LiteralNode*>(functionNode->getOperands().at(0));

Check warning on line 136 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Change this declaration specifying the "pointer" part outside of auto.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrAnuXIcOV86U77DKyo&open=AZrAnuXIcOV86U77DKyo&pullRequest=3258
for (const auto& constraint: model.Constraints())
{
if (constraint.Id() == n->name())
{
if (constraint.location() != Antares::Modeler::Config::Location::SUBPROBLEMS)

Check warning on line 141 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kM-&open=AZrA9E2KsPOyFzXT2kM-&pullRequest=3258
{
throw std::runtime_error("Duals can only be used in subproblems");

Check warning on line 143 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define and throw a dedicated exception instead of using a generic one.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrAnuXIcOV86U77DKyq&open=AZrAnuXIcOV86U77DKyq&pullRequest=3258
}
}
}
}
}
}

void checkExpression(Antares::Expressions::Nodes::Node* expression,
const Antares::Modeler::Config::Location& location,
Antares::ModelerStudy::SystemModel::Model& model)
{
for (auto& node: Antares::Expressions::Nodes::AST(expression))
{
auto checkVariableLocation =
[&model](const std::string& varName, const Antares::Modeler::Config::Location& location)

Check warning on line 158 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

declaration shadows a local variable

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrAnuXIcOV86U77DKym&open=AZrAnuXIcOV86U77DKym&pullRequest=3258
{
for (const auto& variable: model.Variables())
{
if (variable.Id() == varName)
{
if (!AreLocationsCompatible(variable.location(), location))

Check warning on line 164 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kM_&open=AZrA9E2KsPOyFzXT2kM_&pullRequest=3258
{
throw std::runtime_error("Variable mismatch locations");

Check warning on line 166 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define and throw a dedicated exception instead of using a generic one.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kNA&open=AZrA9E2KsPOyFzXT2kNA&pullRequest=3258
}
}
}
};

// base variable
if (auto* varNode = dynamic_cast<Antares::Expressions::Nodes::VariableNode*>(&node);
varNode)
{
checkVariableLocation(varNode->value(), location);
continue;
}

// Portfields can contains variables, we recursively check their expressions
auto checkPortFieldExpr = [&](auto* n)
{
ModelerStudy::SystemModel::PortFieldKey key(n->getPortName(), n->getFieldName());
checkExpression(model.PortFieldDefinitions().at(key).Definition().RootNode(),
location,
model);
};

if (auto* n = dynamic_cast<Antares::Expressions::Nodes::PortFieldNode*>(&node); n)
{
checkPortFieldExpr(n);
continue;
}

/*if (auto* n = dynamic_cast<Antares::Expressions::Nodes::PortFieldSumNode*>(&node); n)*/

Check warning on line 195 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kNB&open=AZrA9E2KsPOyFzXT2kNB&pullRequest=3258
/*{*/

Check warning on line 196 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kNC&open=AZrA9E2KsPOyFzXT2kNC&pullRequest=3258
/* checkPortFieldExpr(n);*/

Check warning on line 197 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kND&open=AZrA9E2KsPOyFzXT2kND&pullRequest=3258
/* continue;*/

Check warning on line 198 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kNE&open=AZrA9E2KsPOyFzXT2kNE&pullRequest=3258
/*}*/

Check warning on line 199 in src/modeler/modeler/Modeler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=AntaresSimulatorTeam_Antares_Simulator&issues=AZrA9E2KsPOyFzXT2kNF&open=AZrA9E2KsPOyFzXT2kNF&pullRequest=3258

checkFunctionNode(node, model);
}
}

void checkModel(Antares::ModelerStudy::SystemModel::Model& model)
{
for (const auto& constraint: model.Constraints())
{
checkExpression(constraint.expression().RootNode(), constraint.location(), model);
}

for (const auto& objective: model.Objectives())
{
checkExpression(objective.expression().RootNode(), objective.location(), model);
}

// Extra outputs must be evaluated, they need to contain only subproblem objects
for (const auto& [_, extraOutput]: model.ExtraOutputs())
{
checkExpression(extraOutput.expression().RootNode(),
Antares::Modeler::Config::Location::SUBPROBLEMS,
model);
}
}

void checkLocations(Antares::Modeler::Data& data)
{
for (auto& lib: data.libraries)
{
for (auto& [modelName, model]: lib.Models())
{
checkModel(model);
}
}
}

void Modeler::run() const
{
Antares::Solver::ModelerParameters parameters;
Expand All @@ -113,6 +244,7 @@
parameters = loader_.loadParameters();
logs.info() << "Parameters loaded";
data = loader_.loadAll();
checkLocations(data);
}
catch (const LoadFiles::ErrorLoadingYaml&)
{
Expand Down
Loading