Skip to content

Commit

Permalink
Move libObjectModel code (#2498)
Browse files Browse the repository at this point in the history
Move the code of the new dynamic modeler's system object model to
study/system-model

---------

Signed-off-by: Peter Mitri <[email protected]>
  • Loading branch information
pet-mit authored Nov 20, 2024
1 parent c257cb9 commit 5d5df42
Show file tree
Hide file tree
Showing 25 changed files with 181 additions and 183 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ if(BUILD_UI)
add_subdirectory(ui) #all antares ui libs + antares simulator
endif()

add_subdirectory(study) #antares study model
add_subdirectory(solver) #antares solver and all associated libs
add_subdirectory(analyzer) #antares analyser

Expand Down
1 change: 0 additions & 1 deletion src/solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ add_subdirectory(constraints-builder)
add_subdirectory(expressions)
add_subdirectory(hydro)
add_subdirectory(infeasible-problem-analysis)
add_subdirectory(libModelObject)
add_subdirectory(lps)
add_subdirectory(misc)
add_subdirectory(modelConverter)
Expand Down
34 changes: 0 additions & 34 deletions src/solver/libModelObject/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/solver/modelConverter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ target_include_directories(modelConverter
# Link dependencies (if any)
target_link_libraries(modelConverter
PRIVATE
Antares::antares-solver-libObjectModel
Antares::antares-study-system-model
Antares::modelParser
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright 2007-2024, RTE (https://www.rte-france.com)
* See AUTHORS.txt
Expand All @@ -22,20 +21,20 @@

#pragma once

namespace Antares::Solver
namespace Antares
{
namespace ObjectModel
namespace Study::SystemModel
{
class Library;
}

namespace ModelParser
namespace Solver::ModelParser
{
class Library;
}
} // namespace Antares::Solver
} // namespace Antares

namespace Antares::Solver::ModelConverter
{
Antares::Solver::ObjectModel::Library convert(const Antares::Solver::ModelParser::Library& library);
Antares::Study::SystemModel::Library convert(const Antares::Solver::ModelParser::Library& library);
}
110 changes: 54 additions & 56 deletions src/solver/modelConverter/modelConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,38 @@

#include <stdexcept>

#include "antares/solver/libObjectModel/constraint.h"
#include "antares/solver/libObjectModel/library.h"
#include "antares/solver/libObjectModel/model.h"
#include "antares/solver/libObjectModel/parameter.h"
#include "antares/solver/libObjectModel/port.h"
#include "antares/solver/libObjectModel/portType.h"
#include "antares/solver/libObjectModel/variable.h"
#include "antares/solver/modelParser/Library.h"
#include "antares/study/system-model/constraint.h"
#include "antares/study/system-model/library.h"
#include "antares/study/system-model/model.h"
#include "antares/study/system-model/parameter.h"
#include "antares/study/system-model/port.h"
#include "antares/study/system-model/portType.h"
#include "antares/study/system-model/variable.h"

namespace Antares::Solver::ModelConverter
{

/**
* \brief Converts parameters from ModelParser::Model to ObjectModel::Parameter.
*
* \param model The ModelParser::Model object containing parameters.
* \return A vector of ObjectModel::Parameter objects.
*/
std::vector<Antares::Solver::ObjectModel::PortType> convertTypes(
std::vector<Antares::Study::SystemModel::PortType> convertTypes(
const Antares::Solver::ModelParser::Library& library)
{
// Convert portTypes to Antares::Solver::ObjectModel::PortType
std::vector<Antares::Solver::ObjectModel::PortType> out;
// Convert portTypes to Antares::Study::SystemModel::PortType
std::vector<Antares::Study::SystemModel::PortType> out;
for (const auto& portType: library.port_types)
{
std::vector<Antares::Solver::ObjectModel::PortField> fields;
std::vector<Antares::Study::SystemModel::PortField> fields;
for (const auto& field: portType.fields)
{
fields.emplace_back(Antares::Solver::ObjectModel::PortField{field});
fields.emplace_back(Antares::Study::SystemModel::PortField{field});
}
Antares::Solver::ObjectModel::PortType portTypeModel(portType.id,
portType.description,
std::move(fields));
Antares::Study::SystemModel::PortType portTypeModel(portType.id,
portType.description,
std::move(fields));
out.emplace_back(std::move(portTypeModel));
}
return out;
Expand All @@ -68,18 +67,18 @@ std::vector<Antares::Solver::ObjectModel::PortType> convertTypes(
* \return The corresponding ObjectModel::ValueType.
* \throws std::runtime_error if the type is unknown.
*/
std::vector<Antares::Solver::ObjectModel::Parameter> convertParameters(
std::vector<Antares::Study::SystemModel::Parameter> convertParameters(
const Antares::Solver::ModelParser::Model& model)
{
std::vector<Antares::Solver::ObjectModel::Parameter> parameters;
std::vector<Antares::Study::SystemModel::Parameter> parameters;
for (const auto& parameter: model.parameters)
{
parameters.emplace_back(Antares::Solver::ObjectModel::Parameter{
parameters.emplace_back(Antares::Study::SystemModel::Parameter{
parameter.id,
Antares::Solver::ObjectModel::ValueType::FLOAT, // TODO: change to correct type
static_cast<Antares::Solver::ObjectModel::Parameter::TimeDependent>(
Antares::Study::SystemModel::ValueType::FLOAT, // TODO: change to correct type
static_cast<Antares::Study::SystemModel::Parameter::TimeDependent>(
parameter.time_dependent),
static_cast<Antares::Solver::ObjectModel::Parameter::ScenarioDependent>(
static_cast<Antares::Study::SystemModel::Parameter::ScenarioDependent>(
parameter.scenario_dependent)});
}
return parameters;
Expand All @@ -91,17 +90,17 @@ std::vector<Antares::Solver::ObjectModel::Parameter> convertParameters(
* \param model The ModelParser::Model object containing variables.
* \return A vector of ObjectModel::Variable objects.
*/
Antares::Solver::ObjectModel::ValueType convertType(Antares::Solver::ModelParser::ValueType type)
Antares::Study::SystemModel::ValueType convertType(Antares::Solver::ModelParser::ValueType type)
{
using namespace std::string_literals;
switch (type)
{
case Antares::Solver::ModelParser::ValueType::CONTINUOUS:
return Antares::Solver::ObjectModel::ValueType::FLOAT;
return Antares::Study::SystemModel::ValueType::FLOAT;
case Antares::Solver::ModelParser::ValueType::INTEGER:
return Antares::Solver::ObjectModel::ValueType::INTEGER;
return Antares::Study::SystemModel::ValueType::INTEGER;
case Antares::Solver::ModelParser::ValueType::BOOL:
return Antares::Solver::ObjectModel::ValueType::BOOL;
return Antares::Study::SystemModel::ValueType::BOOL;
default:
throw std::runtime_error("Unknown type: " + Antares::Solver::ModelParser::toString(type));
}
Expand All @@ -113,16 +112,16 @@ Antares::Solver::ObjectModel::ValueType convertType(Antares::Solver::ModelParser
* \param model The ModelParser::Model object containing ports.
* \return A vector of ObjectModel::Port objects.
*/
std::vector<Antares::Solver::ObjectModel::Variable> convertVariables(
std::vector<Antares::Study::SystemModel::Variable> convertVariables(
const Antares::Solver::ModelParser::Model& model)
{
std::vector<Antares::Solver::ObjectModel::Variable> variables;
std::vector<Antares::Study::SystemModel::Variable> variables;
for (const auto& variable: model.variables)
{
variables.emplace_back(Antares::Solver::ObjectModel::Variable{
variables.emplace_back(Antares::Study::SystemModel::Variable{
variable.id,
Antares::Solver::ObjectModel::Expression{variable.lower_bound},
Antares::Solver::ObjectModel::Expression{variable.upper_bound},
Antares::Study::SystemModel::Expression{variable.lower_bound},
Antares::Study::SystemModel::Expression{variable.upper_bound},
convertType(variable.variable_type)});
}
return variables;
Expand All @@ -134,26 +133,26 @@ std::vector<Antares::Solver::ObjectModel::Variable> convertVariables(
* \param model The ModelParser::Model object containing constraints.
* \return A vector of ObjectModel::Constraint objects.
*/
std::vector<Antares::Solver::ObjectModel::Port> convertPorts(
std::vector<Antares::Study::SystemModel::Port> convertPorts(
const Antares::Solver::ModelParser::Model& model)
{
std::vector<Antares::Solver::ObjectModel::Port> ports;
std::vector<Antares::Study::SystemModel::Port> ports;
for (const auto& port: model.ports)
{
// ports.emplace_back(Antares::Solver::ObjectModel::Port{port.name, port.type});
// ports.emplace_back(Antares::Study::SystemModel::Port{port.name, port.type});
}
return ports;
}

std::vector<Antares::Solver::ObjectModel::Constraint> convertConstraints(
std::vector<Antares::Study::SystemModel::Constraint> convertConstraints(
const Antares::Solver::ModelParser::Model& model)
{
std::vector<Antares::Solver::ObjectModel::Constraint> constraints;
std::vector<Antares::Study::SystemModel::Constraint> constraints;
for (const auto& constraint: model.constraints)
{
constraints.emplace_back(Antares::Solver::ObjectModel::Constraint{
constraints.emplace_back(Antares::Study::SystemModel::Constraint{
constraint.id,
Antares::Solver::ObjectModel::Expression{constraint.expression}});
Antares::Study::SystemModel::Expression{constraint.expression}});
}
return constraints;
}
Expand All @@ -164,21 +163,21 @@ std::vector<Antares::Solver::ObjectModel::Constraint> convertConstraints(
* \param library The ModelParser::Library object containing models.
* \return A vector of ObjectModel::Model objects.
*/
std::vector<Antares::Solver::ObjectModel::Model> convertModels(
std::vector<Antares::Study::SystemModel::Model> convertModels(
const Antares::Solver::ModelParser::Library& library)
{
std::vector<Antares::Solver::ObjectModel::Model> models;
std::vector<Antares::Study::SystemModel::Model> models;
for (const auto& model: library.models)
{
Antares::Solver::ObjectModel::ModelBuilder modelBuilder;
std::vector<Antares::Solver::ObjectModel::Parameter> parameters = convertParameters(model);
std::vector<Antares::Solver::ObjectModel::Variable> variables = convertVariables(model);
std::vector<Antares::Solver::ObjectModel::Port> ports = convertPorts(model);
std::vector<Antares::Solver::ObjectModel::Constraint> constraints = convertConstraints(
Antares::Study::SystemModel::ModelBuilder modelBuilder;
std::vector<Antares::Study::SystemModel::Parameter> parameters = convertParameters(model);
std::vector<Antares::Study::SystemModel::Variable> variables = convertVariables(model);
std::vector<Antares::Study::SystemModel::Port> ports = convertPorts(model);
std::vector<Antares::Study::SystemModel::Constraint> constraints = convertConstraints(
model);

auto modelObj = modelBuilder.withId(model.id)
.withObjective(Antares::Solver::ObjectModel::Expression{model.objective})
.withObjective(Antares::Study::SystemModel::Expression{model.objective})
.withParameters(std::move(parameters))
.withVariables(std::move(variables))
.withPorts(std::move(ports))
Expand All @@ -195,17 +194,16 @@ std::vector<Antares::Solver::ObjectModel::Model> convertModels(
* \param library The ModelParser::Library object to convert.
* \return The corresponding ObjectModel::Library object.
*/
Antares::Solver::ObjectModel::Library convert(const Antares::Solver::ModelParser::Library& library)
Antares::Study::SystemModel::Library convert(const Antares::Solver::ModelParser::Library& library)
{
Antares::Solver::ObjectModel::LibraryBuilder builder;
std::vector<Antares::Solver::ObjectModel::PortType> portTypes = convertTypes(library);
std::vector<Antares::Solver::ObjectModel::Model> models = convertModels(library);
Antares::Solver::ObjectModel::Library lib = builder.withId(library.id)
.withDescription(library.description)
.withPortTypes(std::move(portTypes))
.withModels(std::move(models))
.build();
Antares::Study::SystemModel::LibraryBuilder builder;
std::vector<Antares::Study::SystemModel::PortType> portTypes = convertTypes(library);
std::vector<Antares::Study::SystemModel::Model> models = convertModels(library);
Antares::Study::SystemModel::Library lib = builder.withId(library.id)
.withDescription(library.description)
.withPortTypes(std::move(portTypes))
.withModels(std::move(models))
.build();
return lib;
}

} // namespace Antares::Solver::ModelConverter
3 changes: 3 additions & 0 deletions src/study/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
OMESSAGE("Antares Study")

add_subdirectory(system-model)
33 changes: 33 additions & 0 deletions src/study/system-model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
project(SystemModel)

set(SRC_model
library.cpp
model.cpp
include/antares/study/system-model/library.h
include/antares/study/system-model/model.h
include/antares/study/system-model/parameter.h
include/antares/study/system-model/valueType.h
include/antares/study/system-model/variable.h
include/antares/study/system-model/constraint.h
include/antares/study/system-model/expression.h
include/antares/study/system-model/port.h
include/antares/study/system-model/portField.h
include/antares/study/system-model/portFieldDefinition.h
include/antares/study/system-model/portType.h
)

source_group("SystemModel" FILES ${SRC_model})
add_library(antares-study-system-model
${SRC_model})
add_library(Antares::antares-study-system-model ALIAS antares-study-system-model)

target_include_directories(antares-study-system-model
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
target_link_libraries(antares-study-system-model
PUBLIC
)
install(DIRECTORY include/antares
DESTINATION "include"
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "expression.h"
#include "parameter.h"

namespace Antares::Solver::ObjectModel
namespace Antares::Study::SystemModel
{

/// A constraint linking variables and parameters of a model together
Expand Down Expand Up @@ -53,4 +53,4 @@ class Constraint
Expression expression_;
};

} // namespace Antares::Solver::ObjectModel
} // namespace Antares::Study::SystemModel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <string>

namespace Antares::Solver::ObjectModel
namespace Antares::Study::SystemModel
{

class Expression
Expand All @@ -44,4 +44,4 @@ class Expression
std::string value_;
};

} // namespace Antares::Solver::ObjectModel
} // namespace Antares::Study::SystemModel
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "model.h"
#include "portType.h"

namespace Antares::Solver::ObjectModel
namespace Antares::Study::SystemModel
{

/// A library is a collection of models
Expand Down Expand Up @@ -85,4 +85,4 @@ class LibraryBuilder
Library library_;
};

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

0 comments on commit 5d5df42

Please sign in to comment.