Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 47 additions & 0 deletions src/expressions/include/antares/expressions/iterators/pre-order.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,51 @@ class AST
// End iterator (indicating traversal is complete)
ASTPreOrderIterator end();
};

// PreOrder Iterator for AST const version
class ASTPreOrderIteratorConst
{
std::stack<const Node*> nodeStack;

public:
// Iterator type aliases
using iterator_category = std::forward_iterator_tag;
using value_type = Node;
using difference_type = std::ptrdiff_t;
using pointer = const Node*;
using reference = const Node&;

// Constructor
explicit ASTPreOrderIteratorConst(const Node* root = nullptr);

// Dereference operator
reference operator*() const;

// Pointer access operator
pointer operator->() const;

// Increment operator (pre-order traversal)
ASTPreOrderIteratorConst& operator++();

// Equality comparison
bool operator==(const ASTPreOrderIteratorConst& other) const;

// Inequality comparison
bool operator!=(const ASTPreOrderIteratorConst& other) const;
};

// AST container class to expose begin/end iterators
class ASTconst
{
const Node* root;

public:
explicit ASTconst(const Node* rootNode);

// Begin iterator
ASTPreOrderIteratorConst begin();

// End iterator (indicating traversal is complete)
ASTPreOrderIteratorConst end();
};
} // namespace Antares::Expressions::Nodes
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ParentNode: public Node
* @return A vector of pointers to the operands of the parent node.
*/
const std::vector<Node*>& getOperands() const;
const std::vector<const Node*> getConstOperands() const;

Node* operator[](std::size_t idx) const;

Expand Down
101 changes: 101 additions & 0 deletions src/expressions/iterators/pre-order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ std::vector<Node*> childrenLeftToRight(Node* node)
}
return {};
}

// const version
std::vector<const Node*> childrenLeftToRight(const Node* node)
{
if (auto* bin = dynamic_cast<const BinaryNode*>(node))
{
return {bin->left(), bin->right()};
}
else if (auto* unary = dynamic_cast<const UnaryNode*>(node))
{
return {unary->child()};
}
else if (auto* sum = dynamic_cast<const SumNode*>(node))
{
return sum->getConstOperands();
}
return {};
}
} // namespace

// Constructor
Expand Down Expand Up @@ -104,4 +122,87 @@ ASTPreOrderIterator AST::end()
{
return ASTPreOrderIterator(nullptr);
}

//
// CONST VERSION
//

// Constructor
ASTPreOrderIteratorConst::ASTPreOrderIteratorConst(const Node* root)
{
if (root)
{
nodeStack.push(root);
}
}

// Dereference operator
ASTPreOrderIteratorConst::reference ASTPreOrderIteratorConst::operator*() const
{
return *nodeStack.top();
}

// Pointer access operator
ASTPreOrderIteratorConst::pointer ASTPreOrderIteratorConst::operator->() const
{
return nodeStack.top();
}

// Increment operator (pre-order traversal)
ASTPreOrderIteratorConst& ASTPreOrderIteratorConst::operator++()
{
if (nodeStack.empty())
{
return *this;
}

const Node* current = nodeStack.top();
nodeStack.pop();

const auto children = childrenLeftToRight(current);
// Push children in reverse order to process them in left-to-right order
for (auto* it: children | std::views::reverse)
{
nodeStack.push(it);
}

return *this;
}

// Equality comparison
bool ASTPreOrderIteratorConst::operator==(const ASTPreOrderIteratorConst& other) const
{
if (nodeStack.empty() && other.nodeStack.empty())
{
return true;
}
if (nodeStack.empty() || other.nodeStack.empty())
{
return false;
}
return nodeStack.top() == other.nodeStack.top();
}

// Inequality comparison
bool ASTPreOrderIteratorConst::operator!=(const ASTPreOrderIteratorConst& other) const
{
return !(*this == other);
}

ASTconst::ASTconst(const Node* rootNode):
root(rootNode)
{
}

// Begin iterator
ASTPreOrderIteratorConst ASTconst::begin()
{
return ASTPreOrderIteratorConst(root);
}

// End iterator (indicating traversal is complete)
ASTPreOrderIteratorConst ASTconst::end()
{
return ASTPreOrderIteratorConst(nullptr);
}
} // namespace Antares::Expressions::Nodes
6 changes: 6 additions & 0 deletions src/expressions/nodes/ParentNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const std::vector<Node*>& ParentNode::getOperands() const
return operands_;
}

const std::vector<const Node*> ParentNode::getConstOperands() const
{
std::vector<const Node*> constOperands(operands_.begin(), operands_.end());
return constOperands;
}

size_t ParentNode::size() const
{
return operands_.size();
Expand Down
22 changes: 11 additions & 11 deletions src/io/inputs/model-converter/convertorVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ std::any ConvertorVisitor::handleDual(ExprParser::ArgListContext* context)
return node;
}

throw NoConstraintWithThisName(model_.id, constraint_id);
throw DualNoConstraintWithThisName(model_.id, constraint_id);
}

std::any ConvertorVisitor::handleReducedCost(ExprParser::ArgListContext* context)
Expand All @@ -446,18 +446,18 @@ std::any ConvertorVisitor::handleReducedCost(ExprParser::ArgListContext* context
+ params);
}

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

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

template<class T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@ class NoParameterOrVariableWithThisName final: public std::runtime_error
}
};

class NoVariableWithThisName final: public std::runtime_error
class ReducedCostNoVariableWithThisName final: public std::runtime_error
{
public:
explicit NoVariableWithThisName(const std::string& modelName, const std::string& varName):
explicit ReducedCostNoVariableWithThisName(const std::string& modelName,
const std::string& varName):
runtime_error("reduced_cost called with unknown variable '" + varName + "' in model '"
+ modelName + "'")
{
}
};

class NoConstraintWithThisName final: public std::runtime_error
class DualNoConstraintWithThisName final: public std::runtime_error
{
public:
explicit NoConstraintWithThisName(const std::string& modelName,
const std::string& constraintName):
explicit DualNoConstraintWithThisName(const std::string& modelName,
const std::string& constraintName):
runtime_error("dual called with unknown constraint '" + constraintName + "' in model '"
+ modelName + "'")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void OptimEntityContainer::addFromSystemComponents(const std::vector<Component>&
modelVariableGlobalIndices.reserve(variables.size());
for (const auto& variable: variables)
{
if (AreLocationsCompatible(variable.location(), targetLocation))
if (AreLocationsCompatibleForFillers(variable.location(), targetLocation))
{
modelVariableGlobalIndices.push_back(variableGlobalIndex);
++variableGlobalIndex;
Expand Down
1 change: 1 addition & 0 deletions src/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_subdirectory(loadFiles)
add_subdirectory(modeler)
add_subdirectory(parameters)
add_subdirectory(checks)

OMESSAGE(" :: modeler")

Expand Down
29 changes: 29 additions & 0 deletions src/modeler/checks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
set(SOURCES
checkLocation.cpp

include/antares/solver/modeler/checks/checkLocation.h
)

# Create the library
add_library(modeler-checks ${SOURCES})
add_library(Antares::modeler-checks ALIAS modeler-checks)

# Specify include directories
target_include_directories(modeler-checks
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

find_package(fmt REQUIRED)
# Link dependencies (if any)
target_link_libraries(modeler-checks
PUBLIC
Antares::antares-study-system-model
PRIVATE
modeler-lib
fmt::fmt
)

install(DIRECTORY include/antares
DESTINATION "include"
)
Loading