-
Notifications
You must be signed in to change notification settings - Fork 29
Modeler 6.5: valid location [ANT-4045] #3258
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
Changes from 16 commits
d438209
0c70ad6
e6317b8
c20bf08
9242a94
78f22ae
6e5b2f0
4273f3f
fb73142
d76ed93
8d91f61
67297cd
c517057
54ad5fc
80efcc3
adc0b57
8a94e32
65383ea
e12d570
c76d4d0
df66c1d
388522f
1a5aa3c
a3be6a2
4f49a07
b76c467
28cce06
c64b181
8c0e03d
b868d4b
988ca55
34890df
db6d39d
8d9a982
29f88c8
59960dd
f528667
59ec64f
2d89de1
badd38a
ba60c37
806901f
f389db3
d06de83
99686f4
f3fbc9d
316ef0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /* | ||
| * Copyright 2007-2025, RTE (https://www.rte-france.com) | ||
| * See AUTHORS.txt | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| * This file is part of Antares-Simulator, | ||
| * Adequacy and Performance assessment for interconnected energy networks. | ||
| * | ||
| * Antares_Simulator is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Mozilla Public Licence 2.0 as published by | ||
| * the Mozilla Foundation, either version 2 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * Antares_Simulator is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Mozilla Public Licence 2.0 for more details. | ||
| * | ||
| * You should have received a copy of the Mozilla Public Licence 2.0 | ||
| * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>. | ||
| */ | ||
|
|
||
| #include <antares/expressions/iterators/pre-order.h> | ||
| #include <antares/expressions/nodes/ExpressionsNodes.h> | ||
| #include <antares/solver/modeler/data.h> | ||
| #include <antares/solver/modeler/loadFiles/loadFiles.h> | ||
|
|
||
| using namespace Antares::Expressions::Nodes; | ||
| using namespace Antares::ModelerStudy::SystemModel; | ||
| using namespace Antares::Modeler::Config; | ||
|
|
||
| namespace Antares::Solver::LoadFiles | ||
| { | ||
|
|
||
| void checkFunctionNode(Node& node, Model& model) | ||
payetvin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // dual and reduced_cost can only be used in subproblems | ||
| if (auto* functionNode = dynamic_cast<FunctionNode*>(&node); functionNode) | ||
| { | ||
| if (functionNode->type() == FunctionNodeType::reduced_cost) | ||
| { | ||
| const auto* varNode = dynamic_cast<VariableNode*>(functionNode->getOperands().at(0)); | ||
| for (const auto& variable: model.Variables()) | ||
| { | ||
| if (variable.Id() == varNode->value() | ||
| && variable.location() != Location::SUBPROBLEMS) | ||
| { | ||
| throw std::runtime_error("Reduced costs can only be used in subproblems"); | ||
|
Check warning on line 47 in src/modeler/loadFiles/checkLocation.cpp
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| if (functionNode->type() == FunctionNodeType::dual) | ||
| { | ||
| // This node contains the constraint name | ||
| const auto* n = dynamic_cast<LiteralNode*>(functionNode->getOperands().at(0)); | ||
| for (const auto& constraint: model.Constraints()) | ||
| { | ||
| if (constraint.Id() == n->name()) | ||
| { | ||
| if (constraint.location() != Location::SUBPROBLEMS) | ||
|
Check warning on line 60 in src/modeler/loadFiles/checkLocation.cpp
|
||
| { | ||
| throw std::runtime_error("Duals can only be used in subproblems"); | ||
|
Check warning on line 62 in src/modeler/loadFiles/checkLocation.cpp
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void checkExpression(Node* expression, const Location& location, Model& model) | ||
payetvin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| for (auto& node: AST(expression)) | ||
| { | ||
| // base variable | ||
| if (const auto* varNode = dynamic_cast<VariableNode*>(&node); varNode) | ||
| { | ||
| for (const auto& variable: model.Variables()) | ||
| { | ||
| if (variable.Id() == varNode->value() | ||
| && !AreLocationsCompatible(variable.location(), location)) | ||
| { | ||
| throw std::runtime_error("Variable mismatch locations"); // TODO Better ex | ||
|
Check warning on line 82 in src/modeler/loadFiles/checkLocation.cpp
|
||
| } | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| // Portfields can contains variables, we recursively check their expressions | ||
| if (const auto* n = dynamic_cast<PortFieldNode*>(&node); n) | ||
| { | ||
| PortFieldKey key(n->getPortName(), n->getFieldName()); | ||
| checkExpression(model.PortFieldDefinitions().at(key).Definition().RootNode(), | ||
| location, | ||
| model); | ||
| continue; | ||
| } | ||
|
|
||
| if (const auto* portFieldSumNode = dynamic_cast<PortFieldSumNode*>(&node); portFieldSumNode) | ||
| { | ||
| for (const auto& connection: model.ComponentConnections()) | ||
| { | ||
| auto* n = connection.component()->nodeAtPortField(portFieldSumNode->getPortName(), | ||
| portFieldSumNode->getFieldName()); | ||
| checkExpression(n, location, *connection.component()->getModel()); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
| checkFunctionNode(node, model); | ||
| } | ||
| } | ||
|
|
||
| void checkModel(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(), Location::SUBPROBLEMS, model); | ||
| } | ||
| } | ||
|
|
||
| void checkLocations(Modeler::Data& data) | ||
|
||
| { | ||
| for (auto& lib: data.libraries) | ||
| { | ||
| for (auto& [modelName, model]: lib.Models()) | ||
| { | ||
| checkModel(model); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } // namespace Antares::Solver::LoadFiles | ||
Uh oh!
There was an error while loading. Please reload this page.