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

Modeler 4.7: Import connections and ports #2662

Open
wants to merge 41 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3043877
Raise exception when converting port types
payetvin Feb 24, 2025
7fc5869
Remove description from PortType class
payetvin Feb 24, 2025
0fdcc80
Correct behavior for tests when field is empty
payetvin Feb 24, 2025
ec8a1b7
Merge branch 'develop' into feature/4.7-port-connections
payetvin Feb 24, 2025
1e93123
fix comments
payetvin Feb 25, 2025
b37fb2a
Check if port id already present
payetvin Feb 25, 2025
e9d5114
fix compile
payetvin Feb 25, 2025
2c6346c
add port and portype
payetvin Feb 25, 2025
c386e5e
add base function to convert pfdef, add pfdef to system model
payetvin Feb 25, 2025
4daa665
check for port exists
payetvin Feb 25, 2025
2492c0c
add exception
payetvin Feb 26, 2025
2052ec0
remove warnings in test_full
payetvin Feb 26, 2025
3c473ed
check for field
payetvin Feb 26, 2025
dadac24
remove warning
payetvin Feb 27, 2025
c444167
Convert expression and add portfielddef
payetvin Feb 27, 2025
73992eb
rm Antares::
payetvin Feb 27, 2025
4117a1c
format
payetvin Feb 27, 2025
4c21b62
fix unit tests
payetvin Feb 27, 2025
6294d5d
fix unit tests
payetvin Feb 27, 2025
731dcfa
check for constaints
payetvin Feb 27, 2025
1d96fdd
custom exceptions
payetvin Feb 27, 2025
9bbeaaf
test empty fields
payetvin Feb 27, 2025
9dd078d
port already exists
payetvin Feb 27, 2025
37ccf22
wrong value type
payetvin Feb 27, 2025
7f27d65
test id already exists
payetvin Feb 27, 2025
7627cb5
fix port test case
payetvin Feb 27, 2025
b2c9958
test YmlModel::toString
payetvin Feb 28, 2025
e55ff51
test port id
payetvin Feb 28, 2025
7648a60
type not found
payetvin Feb 28, 2025
e94953c
constraint already exists
payetvin Feb 28, 2025
9290c7f
Basic test case for port def
payetvin Feb 28, 2025
cd2020c
add function to add pfd to builder
payetvin Feb 28, 2025
4171bc5
test pfd field and definition
payetvin Feb 28, 2025
174b020
c
payetvin Feb 28, 2025
43e7905
error cases for portfielddefintion
payetvin Feb 28, 2025
6e3fa47
move function def to begining of the header
payetvin Mar 3, 2025
e3b9d7f
emplace back
payetvin Mar 5, 2025
8410866
use iterators
payetvin Mar 7, 2025
3b51a6c
custom ex if port in definition
payetvin Mar 7, 2025
308ec27
add test base
payetvin Mar 7, 2025
0381386
Add port to convertor visitor
payetvin Mar 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,49 @@ namespace Antares::IO::Inputs::ModelConverter
class UnknownTypeException: public std::runtime_error
{
public:
explicit UnknownTypeException(YmlModel::ValueType type);
explicit UnknownTypeException(const std::string& type);
};

class PortWithThisIdAlreadyExists: public std::runtime_error
{
public:
explicit PortWithThisIdAlreadyExists(const std::string& id);
};

class PortTypeWithThisIdAlreadyExists: public std::runtime_error
{
public:
explicit PortTypeWithThisIdAlreadyExists(const std::string& id);
};

class ConstraintWithThisIdAlreadyExists: public std::runtime_error
{
public:
explicit ConstraintWithThisIdAlreadyExists(const std::string& id);
};

class PortTypeDoesntContainsFields: public std::runtime_error
{
public:
explicit PortTypeDoesntContainsFields(const std::string& id);
};

class PortTypeNotFound: public std::runtime_error
{
public:
explicit PortTypeNotFound(const std::string& portId, const std::string& portTypeId);
};

class PortNotFoundForDefinition: public std::runtime_error
{
public:
explicit PortNotFoundForDefinition(const std::string& portId);
};

class FieldNotFoundForDefinition: public std::runtime_error
{
public:
explicit FieldNotFoundForDefinition(const std::string& portId, const std::string& fieldId);
};

Study::SystemModel::Library convert(const YmlModel::Library& library);
Expand Down
268 changes: 196 additions & 72 deletions src/io/inputs/model-converter/modelConverter.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/io/inputs/yml-model/decoders.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ struct convert<Antares::IO::Inputs::YmlModel::PortFieldDefinition>
{
if (!node.IsMap())
{
// return true to avoid error ? port field definition not mandatory
return false;
}
rhs.port = node["port"].as<std::string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "constraint.h"
#include "parameter.h"
#include "port.h"
#include "portFieldDefinition.h"
#include "variable.h"

namespace Antares::Study::SystemModel
Expand Down Expand Up @@ -80,6 +81,11 @@ class Model
return ports_;
}

const std::map<std::string, PortFieldDefinition>& PortFieldDefinitions() const
{
return portFieldDefinitions_;
}

private:
friend class ModelBuilder;
std::string id_;
Expand All @@ -89,6 +95,7 @@ class Model
std::map<std::string, Variable> variables_;
std::map<std::string, Constraint> constraints_;
std::map<std::string, Port> ports_;
std::map<std::string, PortFieldDefinition> portFieldDefinitions_;
};

class ModelBuilder
Expand All @@ -102,6 +109,7 @@ class ModelBuilder
Model build();

ModelBuilder& withConstraints(std::vector<Constraint>&& constraints);
ModelBuilder& withPortFieldDefinitions(std::vector<PortFieldDefinition>&& portFieldDefinitions);

private:
Model model_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ namespace Antares::Study::SystemModel
class Port
{
public:
Port(const std::string& id, const PortType& type):
id_(id),
type_(type)
{
}

const std::string& Id() const
{
return id_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,28 @@ namespace Antares::Study::SystemModel

class PortFieldDefinition
{
PortFieldDefinition();
~PortFieldDefinition() = default;
public:
PortFieldDefinition(Port port, PortField field, Expression definition):
port_(std::move(port)),
field_(std::move(field)),
definition_(std::move(definition))
{
}

const Port& getPort() const
{
return port_;
}

const PortField& Field() const
{
return field_;
}

const Expression& Definition() const
{
return definition_;
}

private:
Port port_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ namespace Antares::Study::SystemModel
class PortType
{
public:
PortType(const std::string& id,
const std::string& description,
std::vector<PortField>&& fields):
PortType(const std::string& id, std::vector<PortField>&& fields):
id_(id),
description_(description),
fields_(std::move(fields))
{
}
Expand All @@ -45,19 +42,13 @@ class PortType
return id_;
}

const std::string& Description() const
{
return description_;
}

const std::vector<PortField>& Fields() const
{
return fields_;
}

private:
std::string id_;
std::string description_;

std::vector<PortField> fields_;
};
Expand Down
21 changes: 20 additions & 1 deletion src/study/system-model/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Model ModelBuilder::build()
{
Model model = std::move(model_);
model_ = Model(); // makes ModelBuilder re-usable
return std::move(model);
return model;
}

/**
Expand Down Expand Up @@ -136,4 +136,23 @@ ModelBuilder& ModelBuilder::withConstraints(std::vector<Constraint>&& constraint
return *this;
}

/**
* \brief Sets the ports of the model.
*
* \param ports A vector of Port objects to set.
* \return Reference to the ModelBuilder object.
*
* inputs it not garanteed to be valid after the call
*/
ModelBuilder& ModelBuilder::withPortFieldDefinitions(
std::vector<PortFieldDefinition>&& portFieldDefinitions)
{
std::transform(portFieldDefinitions.begin(),
portFieldDefinitions.end(),
std::inserter(model_.portFieldDefinitions_, model_.portFieldDefinitions_.end()),
[](/*Non const to prevent copy*/ PortFieldDefinition& pfd)
{ return std::make_pair(pfd.getPort().Id(), std::move(pfd)); });
return *this;
}

} // namespace Antares::Study::SystemModel
Loading
Loading