Skip to content

Commit

Permalink
Binding constraint RHS scenarization (#1219)
Browse files Browse the repository at this point in the history
* Extract methode

* Remove useless variable

* Break some cyclical include dependencies

* Add new unit test for binding constraints

* BindingConstraint group property: RED

* BindingConstraint group property: GREEN

* Refactor test: generate file in TEMP instead of datafiles

* BoundingConstraints load group: RED

* BoundingConstraints load group: GREEN

* BoundingConstraints load RHS properly

* Store TS Numbers

* Save scenario builder for BC

* Save scenario builder for BC with all rules

* Use matrix type to save time series numbers

* Properly load time series numbers

* Fix store time series numbers

* Add test store timeseries number to unit tests

* Renaming constraint -> bindingConstraint

* Update for BCTimeSeries [FAIL]

* Load BC TimeSeries [PASS]

* Test that reading different TS size fail [PASS]

* Test that all BC have the same type [PASS]

* Rename "series" member of DataSeries types as "time_series"

* Fix compilation for all plateformes

* Simple test binding constraint use time series [FAIL]

* Use vector instead of c-style array for binding constraints RTI

* Fix resizeAllTimeseriesNumbers

* Simple test binding constraint use time series [PASS]

* Rename upper_bound/lower_bound time series as greater_than/lesser_than to avoid confusion

* Simple test binding constraint use time series [PASS]

* Time series are scenarised by BindingConstraint not groups

* WIP Time series in BC

* Only load timeseries for the bionding constraint operator

* Use time_series and ts_numbers for simulation

* Handle Daily BC

* Binding constraints weekly

* Refactor test

* Lesser and Greater inequality binding constraints

* Refactor: squash a switch case split in two

* Rename time_series -> time_series_numbers for structure in BindingConstraintsList

* Binding Constraints works with multiple time series

* Binding Constraints works with several years only one TS

* Binding Constraints works with several years only one TS

* Load time_series empty files as a column of 0s

* [DEV] Add legacy loading function for time series

* Fix for 1 TS several years

* Empty TS file is an error (BC not loaded)

* [GIT] Modify githook regex to allow capitals

* [FIX] Add intermediate matrix

* RNG ts numbers for BC

* Handle range type

* Handle range type

* Use shared_ptr instead of raw pointers for binding constraints

* f

* Code clean up

* Extract methode "SeparateValue"

Remove duplication to read Link or cluster values while parsing binding constraints

* Fix ui compilation

* Rename to StoreTimeSeriesNumbersIntoOuput to be accurate

* Remove unimplemented function to store BC TSNumbers

* Initialize TSNumbers so that they exist for sizing and filling

* Properly set TSNumbers from RNG.

* Assert when trying to load wrong operator BC for study pre-860

* Remove dead code

* Extract code to save bBindingCosntraint in dedicated class

* Constness and remove "not" for "!"

* Refactoring: minor sonar issues

* Move time series loading into BindingConstraintLoader

* Refactor building file_name to save/load time series

* Code cleanup: DeadCode, Sonar issues, etc.

* Update memoryUsage

* Remove dead code BindingConstraintTimeSeries

* Minor fix

* Remove nbTimeSeriesBindingConstraints in parameters

* Fix post rebase

* Remove TODO

* Binding constraints are never used with TS-generator

* time_series -> TimeSeries

* Fix warnings

* Remove return value of "ForceReload"

This value is never used

* Update constraintBuilder

* Update ensureDataAreLoadedForAllBindingConstraints

* Check all time series in a group have the same width

* Simplification

Co-authored-by: Florian Omnès <[email protected]>

* Simplify InitializeTSNumbers

* f time series count

* f time series count

* Remove dead code

* Reintroduce code wrongly deleted in constraintBuilder

* Minor fix

Co-authored-by: Florian Omnès <[email protected]>

* Fix virtual issues in TimeSeriesNumbersWriter

* Add log in case loadTimeSeries fail

* Fix compilation error

* Remove bindingConstraint value from timeSeries enum

Only used for ts generator and intramodal.

* Don't clear Study::bindingConstraints in StudyRuntimeInfos::initializeBindingConstraints

* Class Renaming TimeSeriesNumbersWriter -> BindingConstraintsTimeSeriesNumbersWriter

* Fix typo

* Pluralize vector variable name

* Separate members and functions

* Rename variables for clarity

* Remove duplication

* Remove commented code

* Rename section

* Fix windows compilation issue

* Fix warning message on conversions issue uint/size_t/singed int

* Reorganize end to end tests

* Fix windows compilation

* Use macro to import win32sock transparently

* Legacy binding constraints end at 8.7

* Fix not passing parameter properly for legacy studies

* Remove left over code

* Fix opLess case when loading legacy BCs

* Resize timeseries when loading legacy BCs

* Use resize instead of reserve, fix size

* Test for legacy studies

* Handle legacy studies

Use "id" instead of name for time_series files to match legacy behaviour

* Code formatting

* Rename timeSeries -> RHSTimeSeries

* Disable kirchhof tests for now

* [sc-builder] Don't draw BC timeseries number if only one TS (#1336)

* Study on stack generate overflow, declare on head instead

* Disable tests

* Update version 8.7.0-RC1

* Set Beta1

* Invalidate cache by changing key, BETA++

* Fix version parser

* BETA++

* Revert workflows

* Give same name and id to both constraints to ensure they are processed in the same order as before

* Fix unit test, less brittle to binding constraint list order

* Fix typo

* Remove deadcode

* Fix indent

* Rename map TimeSeriesNumbers -> GroupToTimeSeriesNumbers

* When loading legacy study, place them in the same group

---------

Co-authored-by: Vincent Payet <[email protected]>
Co-authored-by: Florian Omnès <[email protected]>
Co-authored-by: Jason Marechal <[email protected]>
  • Loading branch information
4 people authored Jun 21, 2023
1 parent 588a381 commit 4e3ebfa
Show file tree
Hide file tree
Showing 133 changed files with 3,451 additions and 2,090 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ LC_ALL=C

local_branch="$(git rev-parse --abbrev-ref HEAD)"

valid_branch_regex="^(feature|features|fix|release|doc)\/[a-z0-9._-]+$"
valid_branch_regex="^(feature|features|fix|release|doc)\/[a-zA-Z0-9._-]+$"

message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again."

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ jobs:
ctest -C ${{ matrix.buildtype }} --output-on-failure -L "unit|end-to-end"
- name: Run kirchhoff constraints tests
if: ${{ false }}
shell: bash
run: |
tar xvf src/tests/kirchhoff-cbuilder/reference.tar.gz -C src/tests/kirchhoff-cbuilder/
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ jobs:
ctest -C ${{ matrix.buildtype }} --output-on-failure -L "unit|end-to-end" -LE ortools
- name: Run kirchhoff-constraint-tests
if: ${{ false }}
shell: bash
run: |
tar xvf src/tests/kirchhoff-cbuilder/reference.tar.gz -C src/tests/kirchhoff-cbuilder/
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sonar.projectName=Antares_Simulator
sonar.projectKey=AntaresSimulatorTeam_Antares_Simulator
sonar.organization=antaressimulatorteam
sonar.projectVersion=8.6.0
sonar.projectVersion=8.7.0

# =====================================================
# Properties that will be shared amongst all modules
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14) # FetchContent_MakeAvailable

# Version
set(ANTARES_VERSION_HI 8)
set(ANTARES_VERSION_LO 6)
set(ANTARES_VERSION_LO 7)
set(ANTARES_VERSION_REVISION 0)
set(ANTARES_VERSION_YEAR 2023)

Expand All @@ -14,7 +14,7 @@ set(ANTARES_WEBSITE "https://antares-simulator.org/")
set(ANTARES_ONLINE_DOC "https://antares-simulator.readthedocs.io/")

# Beta release
set(ANTARES_BETA 0)
set(ANTARES_BETA 3)
set(ANTARES_RC 0)

# OR-Tools tag
Expand Down
17 changes: 15 additions & 2 deletions src/libs/antares/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ set(SRC_STUDY_SCENARIO_BUILDER
study/scenario-builder/sets.cpp
study/scenario-builder/updater.hxx
study/scenario-builder/scBuilderUtils.h
study/scenario-builder/scBuilderUtils.cpp)
study/scenario-builder/scBuilderUtils.cpp
study/scenario-builder/BindingConstraintsTSNumbersData.cpp
)
source_group("study\\scenario builder" FILES ${SRC_MATRIX})

set(SRC_STUDY_ACTIONS
Expand Down Expand Up @@ -304,7 +306,18 @@ set(SRC_STUDY_BINDING_CONSTRAINT
study/binding_constraint/BindingConstraint.h
study/binding_constraint/BindingConstraint.hxx
study/binding_constraint/BindingConstraint.cpp
study/binding_constraint/BindingConstraintsList.h
study/binding_constraint/BindingConstraintsList.hxx
study/binding_constraint/BindingConstraintsList.cpp
study/binding_constraint/BindingConstraintTimeSeriesNumbers.cpp
study/binding_constraint/BindingConstraintTimeSeriesNumbers.h
study/binding_constraint/BindingConstraintLoader.cpp
study/binding_constraint/BindingConstraintLoader.h
study/binding_constraint/BindingConstraintSaver.cpp
study/binding_constraint/BindingConstraintSaver.h
study/binding_constraint/EnvForLoading.h
)

source_group("study\\constraint" FILES ${SRC_STUDY_BINDING_CONSTRAINT})

set(SRC_LOGS
Expand Down Expand Up @@ -517,7 +530,6 @@ set(SRC
)



add_library( libantares-core-calendar
# separated target to reduce multiple unit compilations introduced by swap mode
date.h
Expand Down Expand Up @@ -586,3 +598,4 @@ target_link_libraries(libantares-core
result_writer
)

import_std_libs(libantares-core)
4 changes: 2 additions & 2 deletions src/libs/antares/array/correlation.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
#include "../inifile.h"
#include "../study/fwd.h"
#include "../study/version.h"
#include "../study/fwd.h"

namespace Antares
{
namespace Data
{

class Correlation final
{
public:
Expand Down Expand Up @@ -130,7 +130,7 @@ class Correlation final
void copyFrom(const Correlation& source,
const Study& studySource,
const AreaName& areaSource,
const Area::NameMapping& mapping,
const AreaNameMapping& mapping,
const Study& study);

/*!
Expand Down
1 change: 1 addition & 0 deletions src/libs/antares/array/correlation.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
#ifndef __ANTARES_LIBS_ARRAY_CORRELATION_HXX__
#define __ANTARES_LIBS_ARRAY_CORRELATION_HXX__
#include "antares/study/area/area.h"

namespace Antares
{
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/benchmarking/info_collectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ void StudyInfoCollector::enabledThermalClustersCountToFileContent(FileContent& f

void StudyInfoCollector::enabledBindingConstraintsCountToFileContent(FileContent& file_content)
{
unsigned int nbEnabledBC = study_.runtime->bindingConstraintCount;
unsigned int nbEnabledBC = study_.runtime->bindingConstraints.size();
unsigned int nbEnabledHourlyBC(0), nbEnabledDailyBC(0), nbEnabledWeeklyBC(0);

for (uint i = 0; i < nbEnabledBC; i++)
{
switch (study_.runtime->bindingConstraint[i].type)
switch (study_.runtime->bindingConstraints[i].type)
{
case BindingConstraint::Type::typeHourly:
nbEnabledHourlyBC++;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/action/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Context
//! The original cluster name
Data::ThermalCluster* originalPlant;
//! The current constraint
Data::BindingConstraint* constraint;
std::shared_ptr<Data::BindingConstraint> constraint;

//! Views
Views view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/

#include "ts-generator.h"
#include "antares/study/parts/load/prepro.h"

using namespace Yuni;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool Comments::performWL(Context& ctx)
Antares::Data::ConstraintName id;
TransformNameIntoID(pOriginalConstraintName, id);

Data::BindingConstraint* source = ctx.extStudy->bindingConstraints.find(id);
auto source = ctx.extStudy->bindingConstraints.find(id);

if (source && source != ctx.constraint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
*/

#include "create.h"
#include <memory>
#include "../../../../../utils.h"
#include "antares/study/fwd.h"
#include "data.h"
#include "comments.h"
#include "weights.h"
Expand Down Expand Up @@ -88,7 +90,7 @@ bool Create::prepareWL(Context& ctx)

// Computing the futur ID of the area
Antares::Data::ConstraintName id;
const Antares::Data::BindingConstraint* constraintFound = nullptr;
std::shared_ptr<Antares::Data::BindingConstraint> constraintFound = nullptr;

// the suffix
const String& suffix = ctx.property["constraint.name.suffix"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ bool Data::performWL(Context& ctx)
Antares::Data::ConstraintName id;
TransformNameIntoID(pOriginalConstraintName, id);

Antares::Data::BindingConstraint* source = ctx.extStudy->bindingConstraints.find(id);
auto source = ctx.extStudy->bindingConstraints.find(id);

if (source && source != ctx.constraint)
{
source->matrix().forceReload(true);
assert(source->matrix().width > 0);
assert(source->matrix().height > 0);
ctx.constraint->matrix() = source->matrix();
source->matrix().unloadFromMemory();
//Deleted some code. UI is deprecated but not yet removed
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool Enabled::performWL(Context& ctx)
Antares::Data::ConstraintName id;
TransformNameIntoID(pOriginalConstraintName, id);

Data::BindingConstraint* source = ctx.extStudy->bindingConstraints.find(id);
auto source = ctx.extStudy->bindingConstraints.find(id);

if (source && source != ctx.constraint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool Offsets::performWL(Context& ctx)
Antares::Data::ConstraintName id;
TransformNameIntoID(pOriginalConstraintName, id);

Data::BindingConstraint* source = ctx.extStudy->bindingConstraints.find(id);
auto source = ctx.extStudy->bindingConstraints.find(id);

if (source && source != ctx.constraint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool Weights::performWL(Context& ctx)
Antares::Data::ConstraintName id;
TransformNameIntoID(pOriginalConstraintName, id);

Data::BindingConstraint* source = ctx.extStudy->bindingConstraints.find(id);
auto source = ctx.extStudy->bindingConstraints.find(id);

if (source && source != ctx.constraint)
{
Expand Down
25 changes: 9 additions & 16 deletions src/libs/antares/study/area/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,17 @@
*/

#include <yuni/yuni.h>
#include <yuni/io/directory.h>
#include <assert.h>
#include <cassert>
#include "../study.h"
#include "area.h"
#include "../../logs.h"
#include "../memory-usage.h"
#include "../filter.h"
#include "constants.h"
#include "ui.h"
#include "scratchpad.h"
#include "antares/study/parts/load/prepro.h"

using namespace Yuni;

namespace Antares
{
namespace Data
namespace Antares::Data
{
void Area::internalInitialize()
{
Expand Down Expand Up @@ -76,7 +71,7 @@ Area::Area(const AnyString& name, uint nbParallelYears) :
spreadSpilledEnergyCost(0.),
filterSynthesis(filterAll),
filterYearByYear(filterAll),
ui(NULL),
ui(nullptr),
nbYearsInParallel(nbParallelYears),
invalidateJIT(false)
{
Expand Down Expand Up @@ -155,8 +150,7 @@ AreaLink* Area::findExistingLinkWith(Area& with)
}
if (!with.links.empty())
{
const AreaLink::Map::iterator end = with.links.end();
for (AreaLink::Map::iterator i = with.links.begin(); i != end; ++i)
for (auto i = with.links.begin(); i != with.links.end(); ++i)
{
if (i->second->from == this or i->second->with == this)
return i->second;
Expand All @@ -171,17 +165,17 @@ const AreaLink* Area::findExistingLinkWith(const Area& with) const
{
if (not links.empty())
{
const AreaLink::Map::const_iterator end = links.end();
for (AreaLink::Map::const_iterator i = links.begin(); i != end; ++i)
const auto end = links.end();
for (auto i = links.begin(); i != end; ++i)
{
if (i->second->from == &with or i->second->with == &with)
return i->second;
}
}
if (!with.links.empty())
{
const AreaLink::Map::const_iterator end = with.links.end();
for (AreaLink::Map::const_iterator i = with.links.begin(); i != end; ++i)
const auto end = with.links.end();
for (auto i = with.links.begin(); i != end; ++i)
{
if (i->second->from == this or i->second->with == this)
return i->second;
Expand Down Expand Up @@ -536,5 +530,4 @@ void Area::buildLinksIndexes()
}
}

} // namespace Data
} // namespace Antares
3 changes: 2 additions & 1 deletion src/libs/antares/study/area/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <set>
#include "links.h"
#include "ui.h"
#include "antares/study/parameters/adq-patch-params.h"

namespace Antares
{
Expand Down Expand Up @@ -128,7 +129,7 @@ class Area final : private Yuni::NonCopyable<Area>
*/
void detachLinkFromID(const AreaName& id);

void detachLink(const AreaLink* lnk);
static void detachLink(const AreaLink* lnk);

/*!
** \brief Remove a link from its raw pointer
Expand Down
14 changes: 5 additions & 9 deletions src/libs/antares/study/area/area.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
**
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/
#ifndef __ANTARES_LIBS_STUDY_AREAS_HXX__
#define __ANTARES_LIBS_STUDY_AREAS_HXX__
#pragma once

#include "../../utils.h"
#include "antares/study/parts/parts.h"
#include "antares/study/parts/load/prepro.h"

namespace Antares
{
namespace Data
namespace Antares::Data
{
struct CompareAreaName final
{
Expand Down Expand Up @@ -206,7 +205,4 @@ inline AreaList::const_reverse_iterator AreaList::rend() const
return areas.rend();
}

} // namespace Data
} // namespace Antares

#endif // __ANTARES_LIBS_STUDY_AREAS_HXX__
} // namespace Antares
2 changes: 2 additions & 0 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "../../config.h"
#include "../filter.h"
#include "constants.h"
#include "antares/study/parts/parts.h"
#include "antares/study/parts/load/prepro.h"

#define SEP IO::Separator

Expand Down
2 changes: 0 additions & 2 deletions src/libs/antares/study/area/store-timeseries-numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions
*/

#include <yuni/yuni.h>
#include <yuni/io/file.h>
#include <i_writer.h>
#include "../study.h"
#include "../../logs.h"
Expand Down
Loading

0 comments on commit 4e3ebfa

Please sign in to comment.