Skip to content

Commit

Permalink
Modeler API [ANT-1876] (#2286)
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin authored Sep 10, 2024
1 parent cda5d42 commit 24256a1
Show file tree
Hide file tree
Showing 26 changed files with 1,462 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ add_subdirectory(simulation)
add_subdirectory(ts-generator)
add_subdirectory(utils)
add_subdirectory(variable)
add_subdirectory(modeler)
add_subdirectory(expressions)

#
# Resource file for Windows
#
Expand Down Expand Up @@ -113,4 +115,4 @@ INSTALL(EXPORT antares-solver
)


#########
#########
2 changes: 2 additions & 0 deletions src/solver/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(api)
add_subdirectory(ortoolsImpl)
27 changes: 27 additions & 0 deletions src/solver/modeler/api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
set(PROJ optim_api)

set(SRC_API
include/antares/solver/modeler/api/mipVariable.h
include/antares/solver/modeler/api/mipSolution.h
include/antares/solver/modeler/api/mipConstraint.h

include/antares/solver/modeler/api/hasBounds.h
include/antares/solver/modeler/api/hasName.h

include/antares/solver/modeler/api/linearProblem.h
include/antares/solver/modeler/api/linearProblemData.h
include/antares/solver/modeler/api/linearProblemFiller.h
include/antares/solver/modeler/api/linearProblemBuilder.h

linearProblemData.cpp
)

add_library(${PROJ} ${SRC_API})
add_library(Antares::${PROJ} ALIAS ${PROJ})

set_target_properties(${PROJ} PROPERTIES LINKER_LANGUAGE CXX)

target_include_directories(${PROJ}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2007-2024, 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/>.
*/

#pragma once

namespace Antares::Solver::Modeler::Api
{

/// Used to handle bounds for IMipVariable and IMipConstraint
class IHasBounds
{
public:
virtual ~IHasBounds() = default;

virtual void setLb(double lb) = 0;
virtual void setUb(double ub) = 0;

virtual void setBounds(double lb, double ub) = 0;

virtual double getLb() const = 0;
virtual double getUb() const = 0;
};

} // namespace Antares::Solver::Modeler::Api
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2007-2024, 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/>.
*/

#pragma once

#include <string>

namespace Antares::Solver::Modeler::Api
{

/// Inherited by IMipVariable and IMipConstraint
class IHasName
{
public:
virtual ~IHasName() = default;
virtual const std::string& getName() const = 0;
};

} // namespace Antares::Solver::Modeler::Api
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2007-2024, 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/>.
*/

#pragma once

#include <map>
#include <string>

#include "mipConstraint.h"
#include "mipSolution.h"
#include "mipVariable.h"

/// Namespace for the classes related to the linear problem API
namespace Antares::Solver::Modeler::Api
{

/**
* Linear Problem
* This class is aimed at creating and manipulating variables/constraints
* Also used to to control the objective, maximization or minimization, and to solve the problem
*/
class ILinearProblem
{
public:
virtual ~ILinearProblem() = default;

/// Create a continuous variable
virtual IMipVariable* addNumVariable(double lb, double ub, const std::string& name) = 0;
/// Create a integer variable
virtual IMipVariable* addIntVariable(double lb, double ub, const std::string& name) = 0;
virtual IMipVariable* getVariable(const std::string& name) const = 0;

/// Add a bounded constraint to the problem
virtual IMipConstraint* addConstraint(double lb, double ub, const std::string& name) = 0;
virtual IMipConstraint* getConstraint(const std::string& name) const = 0;

/// Set the objective coefficient for a given variable
virtual void setObjectiveCoefficient(IMipVariable* var, double coefficient) = 0;
virtual double getObjectiveCoefficient(const IMipVariable* var) const = 0;

/// Sets the optimization direction to minimize
virtual void setMinimization() = 0;
/// Sets the optimization direction to maximize
virtual void setMaximization() = 0;

virtual bool isMinimization() const = 0;
virtual bool isMaximization() const = 0;

/// Solve the problem, returns a IMipSolution
virtual IMipSolution* solve(bool verboseSolver) = 0;
};

} // namespace Antares::Solver::Modeler::Api
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2007-2024, 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/>.
*/

#pragma once

#include <vector>

#include "linearProblemFiller.h"
#include "mipSolution.h"

namespace Antares::Solver::Modeler::Api
{

class LinearProblemBuilder
{
public:
virtual void LinearProblemBuilder(std::vector<LinearProblemFiller*> fillers) = 0;
virtual void build(LinearProblemData* data) = 0;
virtual MipSolution* solve() = 0;
};

} // namespace Antares::Solver::Modeler::Api
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2007-2024, 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/>.
*/

#pragma once

#include <map>
#include <string>
#include <vector>

namespace Antares::Solver::Modeler::Api
{

class LinearProblemData
{
public:
unsigned getTimeResolutionInMinutes();
bool hasScalarData(const std::string& key);
double getScalarData(const std::string& key, unsigned scenario);
bool hasTimedData(const std::string& key);
const std::vector<double>& getTimedData(const std::string& key, unsigned scenario);

private:
std::vector<int> timeStamps_;
unsigned timeResolutionInMinutes_;
std::map<std::string, std::vector<double>> scalarData_;
std::map<std::string, std::vector<std::vector<double>>> timedData_;
};

} // namespace Antares::Solver::Modeler::Api
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2007-2024, 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/>.
*/

#pragma once

#include <antares/solver/modeler/api/linearProblem.h>
#include <antares/solver/modeler/api/linearProblemData.h>

namespace Antares::Solver::Modeler::Api
{

class LinearProblemFiller
{
public:
virtual void addVariables(LinearProblem* problem, LinearProblemData* data) = 0;
virtual void addConstraints(LinearProblem* problem, LinearProblemData* data) = 0;
virtual void addObjectiveCoefficients(LinearProblem* problem, LinearProblemData* data) = 0;
};

} // namespace Antares::Solver::Modeler::Api
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2007-2024, 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/>.
*/

#pragma once

#include "mipVariable.h"

namespace Antares::Solver::Modeler::Api
{

class IMipConstraint: public IHasBounds, public IHasName
{
public:
virtual void setCoefficient(IMipVariable* var, double coefficient) = 0;

virtual double getCoefficient(IMipVariable* var) = 0;
};

} // namespace Antares::Solver::Modeler::Api
Loading

0 comments on commit 24256a1

Please sign in to comment.