From 1fe63ce63b91d30e5083b6450689392e0d10d7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= Date: Mon, 30 Jan 2023 11:10:07 +0100 Subject: [PATCH] Feature/adq patch final (#1062) * 7. re-pack CSR run into weeklyOptProblem->solve method * adopt RTE syntax for switch/case * remove comments * change RC number * change beta release number * unit test for CSR-calculateAreaFlowBalance * small refacto * unit test bug fix * 4. remove unused * 6.1 MemAllocMemset * 5. remove return * 3. remove debug log * 2. move to csr * 1. refacto * 6.2 hide column * 6.2 * 3. move log * 3. move log.. * clean * small fix year count * hot start * relax var bounds * remove ENS <= densNew constraint, set as var bound * remove set values to NaN if csr solver fails * relax bining constrains for csr solver * make csr crash log more expressive * clean some logs * beta 3 -> beta 4 * wrong relaxation of bc - bug fix * logg out triggered csr hours * refacto 1e-3 * logg out csr warnings - refacto * update antares output dens value * more expressive log * update dens and use it as pto * dont include linear cost coeff - temporary beta6 only * beta5->beta6 * 10. bring back type of var to origin quad solver - mistake * 2. remove default values for the solver accuracy * change function name to ADQ_PATCH_CSR * 6. remove comments * 7. remove nused transport cost * 9. remove comments * 11. refacto - int NumberOfVariables * 8. remove NomDeLaContrainte * bring back linear hurdle costs * set to zero ENS & spillage if below threshold (avoid LOLP=100% dummy values) * small refacto * 4. make subfunction CSR_DEBUG_BLAH * 1. move csr problem functions to separate directory * 12. Add "Include hurdle cost" false/true button * refacto avoid bugs * refacto avoid bugs * refacto bugs * Fix build Rename LinkCapacityForAdequacyPatchFirstStep -> ntcSetToZeroStatus_AdqPatchStep1 * 1. Make NumberOfVariables a reference var * change function name CSR_DEBUG_ * 3. test Probleme.ExistenceDUneSolution directly * 2. Slightly clearer version * 4. make hoursRequiringCurtailmentSharing const var * 5. avoid cast sumENS[i] to int! * 17. move default thresholds to adequacy_patch.h * 20. use A.size() in addArray function * 19. create dedicated method solveCSR * 7. name change * 8. make methods of AdequacyPatchOptimization private * 11. 14. 16 delete unused logs * 9. delete forward declaration of HOURLY_CSR_PROBLEM * 15. remove Double definition. * 12. 13 update copyright & Authors for adq-patch files * make solveCSR private method * use auto instead of std::unique_ptr * float->double * remove saveIntermediateResults * code smells parameters.cpp * critical-CodeSmell-adequacy_patch.cpp * critical-codeSmells- set_problem_cost.cpp * info-CodeSmell - remove todo-s * CodeSmells - global var should be const * NULL->nullptr * use default destructor * protected->private in adq-patch-area-grid.h * use default constructor in adequacy-patch-areas * Add the "explicit" keyword to AdequacyPatchAreas constructor * NULL->nullptr in adequacy-patch-options.cpp * = default, AdequacyPatchOptions * Add the "explicit" keyword to AdequacyPatchOptions constructor * Remove these useless parentheses * Remove these useless parentheses * Remove the unused parameter "weekNb", * Move these 4 #include directives to the top of the file * declaration shadows a local variable * Value stored to 'ProblemeAResoudre' is never read * function should be declared "const" * Use "std::make_unique" to construct "std::unique_ptr * Value stored to 'out' during its initialization is never read * major-CodeSmells-adequacy-patch-options.cpp * remove "never read" variables * const& buttonType in updateButton * Replace this "enum" with "enum class" AdqPatchPTO * double*->const double* in addArray * MinorCodeSmell-s construct_LHS * MinorCodeSmell-s construct_RHS * MinorCodeSmell-s construct_variables * MinorCodeSmell-s cost_function * MinorCodeSmell-s set_var_bounds * MinorCodeSmell-s solve_problem * MinorCodeSmell-s economy.cpp * Remove redundant public access specifier * Remove this redundant access specifier * MinorCodeSmell-s adq-patch-unit-tests * Concatenate namespace with the nested ones. * Use "override" or "final" instead of "virtual". * Remove public redundant access specifier; * MinorCodeSmell-s adequacy-patch-areas.h * Concatenate namespace with the nested ones. * Make the type of auto& study ; a reference-to-const * MinorCodeSmell-s AdequacyPatchOptions * "not"-> "!" , "and"-> "&&" * Add adequacy-patch CSR study format changes (#817) * beta 7 * create GUI for csr var relax button * connect GUI to logic * threshold e-3 >e-5 * fix (GUI wont pass smaller than 10^-6) * Value stored to 'PaliersThermiquesDuPays' is never read * "std::string" -> "std::string_view" * make getHoursRequiringCurtailmentSharing const method * remove unused var * assign ProblemeAResoudre properly * Reporting of DENS_new in GUI result for all hours * Check CSR cost-fun-value prior&after CSR-opt - GUI * refacto due to pre-calculating dens_new for all hours prior to csr optim * add "SpilledenergyAfterCSR" column * TODO: densNewValues * Correction of MRG.PRICE Price Cap in hours LOLE>0.5 after CSR * refacto "DENS_new" parameter calc, same thing at the end!? * add DTG. MRG INT/FIN columns to GUI * copy-paste spilled Energy values into spilled Energy values after CSR prior to CSR * Check CSR cost value prior to and after - UNTESTED * refacto on DTG MRG CSR columns GUI * change log to info in "Check CSR cost value" * test implementation csr fun cost prior/after * refacto LMR violations according to the agreement with Daniel + clean * csr-postProcess - adjust ENS value and calc dtgMrgCsr * small refacto * refacto - adjust mrgPrice after caclulating dtgMrgCsr and new Ens * log update * refacto setToZeroIfBelowThreshold * update/refacto log csr-solver * refacto logs @ solve_problem.cpp * typo * beta7 -> beta8 * add prefix [adq-patch] to info logs * move adqPatchPostProcess after HydroRemix * refactor + change - storeOrDisregardInteriorPointResults * beta 9.1 * refactor solveCSR * add "- dtgMrg" to densNew formula * beta 10 * fix error * update 13-file-format.md for adq-patch CSR * update 14-adequacy-patch.md for adq-patch CSR * change CSR objective function (Elia) * change CSR objective function (Elia) - doc update * beta11 * change CSR objective function (Elia) - doc update * 14-adq-patch-doc-bug fix (unrecognized characters) * 14-adq-patch-doc-bug fix (unrecognized characters)-2 * Fix build (linking KO b/c of missing functions) * Fix build * Apply clang-format * [UI] Fix build * Fix code smells reported as bugs * Use BOOST_CHECK_EQUAL to check equality (#1056) To display a more expressive error message in case of failure, for example src/tests/src/solver/optimisation/adequacy_patch.cpp(481): error: in "calculateAreaFlowBalanceForOneTimeStep_outside_inside_IncludeOut_negativeFlow_initEnsEqualTo0": check densNew == 0.1 has failed [0 != 0.10000000000000001] * Adequacy patch refactoring (#962) * [FIX] Refactored var names * [REFAC] Changed class and var names in economy.h/cpp * [REFAC] More correction of PR 903 * Fix build after rebase Co-authored-by: Florian OMNES * Refactor adq patch (part 2) (#964) * [FIX] Refactored var names * [REFAC] Changed class and var names in economy.h/cpp * [REFAC] More correction of PR 903 * Fix build after rebase * Refactor adq patch (by gp) : lowering the solvers dependence to "state" * Refactor adq patch (by gp) : lowering the solvers dependence to "state" (part 2) * Refactor adq patch (by gp) : remove solveCSR from classic optimization problem * Restore function setBoundsAdqPatch * Fix build Co-authored-by: Vincent Payet Co-authored-by: Florian OMNES * Adequacy patch : refactor economy (weekly optimization) (#968) * [FIX] Refactored var names * [REFAC] Changed class and var names in economy.h/cpp * [REFAC] More correction of PR 903 * Fix build after rebase * Refactor adq patch (by gp) : lowering the solvers dependence to "state" * Refactor adq patch (by gp) : lowering the solvers dependence to "state" (part 2) * Refactor adq patch (by gp) : remove solveCSR from classic optimization problem * Refactor adq patch (by gp) : correction after merge (to get compilation done) * adq patch - refactor economy : renaming * adq patch - refactor economy : define a weekyOptimization for each problemeHebdo * solveCSR => implementation in separate file * adq patch - refactor economy : correction to avoid conflict in the next merge * adq patch - refactor economy : move declaration of class interfaceWeeklyOptimization in a new file * adq patch - refactor economy : extract weekly optimization classes in separate source files * adq patch - refactor economy : correction due to review * adq patch - refactor economy : remove useless function arguments due to sonar review * Fix build * Restore function setBoundsAdqPatch * Add virtual dtors * Remove useless return statement * Nested namespaces, formatting * Make protected members const Co-authored-by: Vincent Payet Co-authored-by: Florian OMNES * Adequacy patch : refactor curtailment sharing (#971) * Adequacy patch CSR - final (#958) * change origin/extremityAreaType to AreaMode * refacto function SetNTCForAdequacyFirstStep * LinkCapacityForAdqPatchFirstStepFromAreaOutsideToAreaInsideAdq name change * name change for LinkCapacityForAdequacyPatchFirstStep * remove returnNTC form adq functions. * remove unnecessary break * make readAdqPatchMode function * make ini file more expressive * remove additional check for ini file * refacto * make version 8.3.0 * Revert "make version 8.3.0" * fix * fix * synchronize names setToZeroNTCfrom.. * synchronize names pBtn... * synchronize adequacy-patch-options.cpp * synchronize names adqm.. * synchronize names AreaType to AreaMode * synchronize names LinkCapacity.. * synchronize name physicalAreaInsideAdqPatch * 1. do not modify Yuni library * 3. AdequacyPatchPTO name change * 3. update * 2-8. replace seeds with two thresholds * 9. resetAdqPatchParameters * 10. re-name lmrViolations.h * 25-26. re-name AdequacyPatchConfigure to AdequacyPatchOptions * 27. cellValue change * 28. is already implemented + small refacto * small refacto * 29. updateButton function * 13. renaming * 14. refactoring * 15. remove redundancy * 16. refactoring * 20. separate LHS to functions * 20. separate RHS to functions * clean * 23. separate Costs into functions * 22. separate Bounds into functions * 21. separate Construction of variables into functions * 19. separate quad-solver into sub-functions * 11. separate getHoursRequiringCurtailmentSharing into two sub-functions * 17+18+24. make OPT_ functions private methods and make public run method * clean * clean * clean * 0 as a default value, and (value > threshold) * 4. add else if for AdqPatchPTO::isDens * bring back some debugg logs for easy result check * 2. make calculateCsrParameters method of HOURLY_CSR_PROBLEM * clean * 1. use std::vector for sumENS * 9. repack CSR ui input data in parameters.h * 8. placing all functions inside adequacy_patch.h to namespace Adequcy patch * 7. re-pack CSR run into weeklyOptProblem->solve method * adopt RTE syntax for switch/case * remove comments * change RC number * change beta release number * unit test for CSR-calculateAreaFlowBalance * small refacto * unit test bug fix * 4. remove unused * 6.1 MemAllocMemset * 5. remove return * 3. remove debug log * 2. move to csr * 1. refacto * 6.2 hide column * 6.2 * 3. move log * 3. move log.. * clean * small fix year count * hot start * relax var bounds * remove ENS <= densNew constraint, set as var bound * remove set values to NaN if csr solver fails * relax bining constrains for csr solver * make csr crash log more expressive * clean some logs * beta 3 -> beta 4 * wrong relaxation of bc - bug fix * logg out triggered csr hours * refacto 1e-3 * logg out csr warnings - refacto * update antares output dens value * more expressive log * update dens and use it as pto * dont include linear cost coeff - temporary beta6 only * beta5->beta6 * 10. bring back type of var to origin quad solver - mistake * 2. remove default values for the solver accuracy * change function name to ADQ_PATCH_CSR * 6. remove comments * 7. remove nused transport cost * 9. remove comments * 11. refacto - int NumberOfVariables * 8. remove NomDeLaContrainte * bring back linear hurdle costs * set to zero ENS & spillage if below threshold (avoid LOLP=100% dummy values) * small refacto * 4. make subfunction CSR_DEBUG_BLAH * 1. move csr problem functions to separate directory * 12. Add "Include hurdle cost" false/true button * refacto avoid bugs * refacto avoid bugs * refacto bugs * Fix build Rename LinkCapacityForAdequacyPatchFirstStep -> ntcSetToZeroStatus_AdqPatchStep1 * 1. Make NumberOfVariables a reference var * change function name CSR_DEBUG_ * 3. test Probleme.ExistenceDUneSolution directly * 2. Slightly clearer version * 4. make hoursRequiringCurtailmentSharing const var * 5. avoid cast sumENS[i] to int! * 17. move default thresholds to adequacy_patch.h * 20. use A.size() in addArray function * 19. create dedicated method solveCSR * 7. name change * 8. make methods of AdequacyPatchOptimization private * 11. 14. 16 delete unused logs * 9. delete forward declaration of HOURLY_CSR_PROBLEM * 15. remove Double definition. * 12. 13 update copyright & Authors for adq-patch files * make solveCSR private method * use auto instead of std::unique_ptr * float->double * remove saveIntermediateResults * code smells parameters.cpp * critical-CodeSmell-adequacy_patch.cpp * critical-codeSmells- set_problem_cost.cpp * info-CodeSmell - remove todo-s * CodeSmells - global var should be const * NULL->nullptr * use default destructor * protected->private in adq-patch-area-grid.h * use default constructor in adequacy-patch-areas * Add the "explicit" keyword to AdequacyPatchAreas constructor * NULL->nullptr in adequacy-patch-options.cpp * = default, AdequacyPatchOptions * Add the "explicit" keyword to AdequacyPatchOptions constructor * Remove these useless parentheses * Remove these useless parentheses * Remove the unused parameter "weekNb", * Move these 4 #include directives to the top of the file * declaration shadows a local variable * Value stored to 'ProblemeAResoudre' is never read * function should be declared "const" * Use "std::make_unique" to construct "std::unique_ptr * Value stored to 'out' during its initialization is never read * major-CodeSmells-adequacy-patch-options.cpp * remove "never read" variables * const& buttonType in updateButton * Replace this "enum" with "enum class" AdqPatchPTO * double*->const double* in addArray * MinorCodeSmell-s construct_LHS * MinorCodeSmell-s construct_RHS * MinorCodeSmell-s construct_variables * MinorCodeSmell-s cost_function * MinorCodeSmell-s set_var_bounds * MinorCodeSmell-s solve_problem * MinorCodeSmell-s economy.cpp * Remove redundant public access specifier * Remove this redundant access specifier * MinorCodeSmell-s adq-patch-unit-tests * Concatenate namespace with the nested ones. * Use "override" or "final" instead of "virtual". * Remove public redundant access specifier; * MinorCodeSmell-s adequacy-patch-areas.h * Concatenate namespace with the nested ones. * Make the type of auto& study ; a reference-to-const * MinorCodeSmell-s AdequacyPatchOptions * "not"-> "!" , "and"-> "&&" * beta 7 * create GUI for csr var relax button * connect GUI to logic * threshold e-3 >e-5 * fix (GUI wont pass smaller than 10^-6) * Value stored to 'PaliersThermiquesDuPays' is never read * "std::string" -> "std::string_view" * make getHoursRequiringCurtailmentSharing const method * remove unused var * assign ProblemeAResoudre properly * Reporting of DENS_new in GUI result for all hours * Check CSR cost-fun-value prior&after CSR-opt - GUI * refacto due to pre-calculating dens_new for all hours prior to csr optim * add "SpilledenergyAfterCSR" column * TODO: densNewValues * Correction of MRG.PRICE Price Cap in hours LOLE>0.5 after CSR * refacto "DENS_new" parameter calc, same thing at the end!? * add DTG. MRG INT/FIN columns to GUI * copy-paste spilled Energy values into spilled Energy values after CSR prior to CSR * Check CSR cost value prior to and after - UNTESTED * refacto on DTG MRG CSR columns GUI * change log to info in "Check CSR cost value" * test implementation csr fun cost prior/after * refacto LMR violations according to the agreement with Daniel + clean * csr-postProcess - adjust ENS value and calc dtgMrgCsr * small refacto * refacto - adjust mrgPrice after caclulating dtgMrgCsr and new Ens * log update * refacto setToZeroIfBelowThreshold * update/refacto log csr-solver * refacto logs @ solve_problem.cpp * typo * beta7 -> beta8 * add prefix [adq-patch] to info logs * move adqPatchPostProcess after HydroRemix * refactor + change - storeOrDisregardInteriorPointResults * beta 9.1 * refactor solveCSR * add "- dtgMrg" to densNew formula * beta 10 Co-authored-by: hugo-antoine-rtei <73881097+hugo-antoine-rtei@users.noreply.github.com> Co-authored-by: rtei-pw Co-authored-by: rtei-pw Co-authored-by: Florian OMNES Co-authored-by: Hugo ANTOINE (RTEi) * [FIX] FIx compile error * [FIX] Refactored var names * [REFAC] Changed class and var names in economy.h/cpp * [REFAC] More correction of PR 903 * Refactor adq patch (by gp) : lowering the solvers dependence to "state" * Refactor adq patch (by gp) : lowering the solvers dependence to "state" (part 2) * Refactor adq patch (by gp) : correction after merge (to get compilation done) * adq patch - refactor economy : renaming * Refactor adq patch (by gp) : remove solveCSR from classic optimization problem * adq patch - refactor economy : define a weekyOptimization for each problemeHebdo * adq patch - refactor economy : correction to avoid conflict in the next merge * adq patch - refactor economy : move declaration of class interfaceWeeklyOptimization in a new file * adq patch - refactor economy : extract weekly optimization classes in separate source files * adq patch - refactor economy : correction due to review * adq patch - refactor economy : remove useless function arguments due to sonar review * adq patch - refactor csr : simplify and remove useless things * adq patch - refactor csr : split adequacy_patch.h/.cpp into local matching and curtailment sharing sources files * Clean up headers Co-authored-by: Milos <97689304+Milos-RTEi@users.noreply.github.com> Co-authored-by: hugo-antoine-rtei <73881097+hugo-antoine-rtei@users.noreply.github.com> Co-authored-by: rtei-pw Co-authored-by: rtei-pw Co-authored-by: Florian OMNES Co-authored-by: Hugo ANTOINE (RTEi) Co-authored-by: Vincent Payet * Adequacy patch vincent final (#1087) * [FIX] Namespace concatenation in src/solver/simulation/ * [DEV] Moved reset csr and lm in dedicated structs * [DEV] Create class CsrQuadraticProblem and moved functions in * [DEV] Refactored functions in CsrQuadraticProblem class * [DEV] FIx reference * Pass hourlyCsrProblem.hourInWeekTriggeredCsr, not hourlyCsrProblem * Nested namespaces * Fix build, use non-const ref in class `CsrQuadraticProblem` * [DEV] Concatenate namespace before merge Co-authored-by: Florian OMNES * Remove state from interpolateWaterValue * [DEV] Concatenate namespace done (#1094) * Check for incompatible hurdle cost options (#1096) * [DEV] Add rte banner in files missing it (#1097) * [FIX] Adequacy code smells (#1100) * [FIX] First batch of code smell * [FIX] More smell fixes * [FIX] Fix nested if and fort * [FIX] Remove using Antares::Data::AdequacyPatch and solved compiles errors related * [FIX] More code smells * [FIX] Compile errors * [FIX] Clarify condition * [CSR] Clarify implicit var convention (#1095) * CSR : clarify implicit convention on variable numbers for links * CSR: clarify debug logs * Renaming after PR remarks * Pass hour instead of hourlyCsrProblem (#1098) * Pass hour instead of hourlyCsrProblem * Pass int for hour instead of a struct containing it * move calculation of LMR violations from CSR source file to adq patch weekly problem (#1102) * Move var declaration to right scope (#1103) * [FIX] Move var declaration to right scope * Fix infinite loop, possible other bug (#1107) * Preparatory refactor to use own instance of PROBLEME_A_RESOUDRE (#1099) * Simplify UtiliserLaToleranceDAdmissibiliteParDefaut, etc. * Use PROBLEME_POINT_INTERIEUR for calculateCsrCostFunctionValue * Pass hour instead of HOURLY_CSR_PROBLEM& * Use PROBLEME_POINT_INTERIEUR for CSR_DEBUG_HANDLE, handleInteriorPointError * PR remarks (use ref on object, not unique_ptr) * Rename HOURLY_CSR_PROBLEM -> HourlyCSRProblem * Apply clang-format * Move files * Move csr_quadratic_problem.h,cpp * Remove unused fwd declaration * Don't instantiate HourlyCSRProblem for every hour, setHour instead * Rename OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique_CSR * Use std::vector::data instead of malloc/free * Some renaming * Add forgotten '{' * Use our own instance of `PROBLEME_ANTARES_A_RESOUDRE` (#1105) * Simplify UtiliserLaToleranceDAdmissibiliteParDefaut, etc. * Use PROBLEME_POINT_INTERIEUR for calculateCsrCostFunctionValue * Pass hour instead of HOURLY_CSR_PROBLEM& * Use PROBLEME_POINT_INTERIEUR for CSR_DEBUG_HANDLE, handleInteriorPointError * PR remarks (use ref on object, not unique_ptr) * Rename HOURLY_CSR_PROBLEM -> HourlyCSRProblem * Apply clang-format * Move files * Move csr_quadratic_problem.h,cpp * Remove unused fwd declaration * Don't instantiate HourlyCSRProblem for every hour, setHour instead * Rename OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique_CSR * Use std::vector::data instead of malloc/free * Some renaming * Use our own instance of PROBLEME_ANTARES_A_RESOUDRE * Refactor 2 more functions OPT_InitialiserLeSecondMembreDuProblemeQuadratique_CSR OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeQuadratique_CSR * Use reference instead of raw pointer * Extract allocation function for PROBLEME_ANTARES_A_RESOUDRE * Use std::fill_n instead of memset * PR remark * Extract OPT_FreeOptimizationData * Handle memory allocation/deallocation * UpperCamelCase for some classes, move sources to adequacy_patch_csr (#1108) * [FIX] UpperCamelCase for some classes * [FIX] Moved csr files in adequacy_patch_csr/ * [FIX] Swap DefaultWeeklyOptimization WeeklyOptimization names * [FIX] Add Antares::Data::Optimization namespace * Remove `OPT_*_CSR` functions (#1111) * Remove OPT_*_CSR functions * Rename hourInWeekTriggeredCsr -> triggeredHour * Fix regression related to while loop and unitialized quadratic costs (#1112) * Fix regression related to while loop * Fix 2nd regression related to unitialized quadratic cost * Fix build after merge * Fix a few more code smells (#1113) * Fix a few code smells * Apply clang-format * Remove unused function ResetButtonSpecify * Code smells (#1114) * [FIX] Code smells * Temporarily disable all release tests * Use simtest v8.5.0b * Refactor optimization post process (#1109) * move calculation of LMR violations from CSR source file to adq patch weekly problem * Refactor Optimization post processes : first work : add abstractions for post-process commands and for a list of them. * Refactor Optimization post processes : move the first post process in the list of post processes to be run * Refactor Optimization post processes : fixing a regression * Refactor Optimization post processes : moving the code of the post process associated to dispatchable margin into the command class * Refactor Optimization post processes : some cleaning (see details in the commit's body) - Narrow arguments of optimization post process functions. For example, study is passes while we only need the study's collection of areas - Not pass the constant "nbHoursInAWeek" as an argument, rather make it a constant visible by every function using it. - Remove some useless headers * Refactor Optimization post processes : fixing a crash * Refactor Optimization post processes : adding hydro levels update to list of post process * Refactor Optimization post processes : adding hydro remix to the list of post process * Refactor Optimization post processes : adding DTG margin for adq patch to the list of post process * Refactor Optimization post processes : forgot to remove adqPatchPostProcess function from curtailment sharing problem * Refactor Optimization post processes : adding hydro levels update (after remix) to list of post process * Refactor Optimization post processes : adding post process "interpolate water value" to list of post process * Refactor Optimization post processes : adding post process "Hydro Levels Final Update" to list of post process * [skip ci] Refactor Optimization post processes : adding an empty CSR command to list of post process (to be filled later) * Refactor Optimization post processes : correction after code review * [skip ci] Refactor Optimization post processes : make destructors virtual * [FIX] Changed ProblemeHebdo to problemeHebdo (#1124) * Fix linking issue in libmodel * Move CSR from adq patch to post process cmd (#1118) * move calculation of LMR violations from CSR source file to adq patch weekly problem * Refactor Optimization post processes : first work : add abstractions for post-process commands and for a list of them. * Refactor Optimization post processes : move the first post process in the list of post processes to be run * Refactor Optimization post processes : fixing a regression * Refactor Optimization post processes : moving the code of the post process associated to dispatchable margin into the command class * Refactor Optimization post processes : some cleaning (see details in the commit's body) - Narrow arguments of optimization post process functions. For example, study is passes while we only need the study's collection of areas - Not pass the constant "nbHoursInAWeek" as an argument, rather make it a constant visible by every function using it. - Remove some useless headers * Refactor Optimization post processes : fixing a crash * Refactor Optimization post processes : adding hydro levels update to list of post process * Refactor Optimization post processes : adding hydro remix to the list of post process * Refactor Optimization post processes : adding DTG margin for adq patch to the list of post process * Refactor Optimization post processes : forgot to remove adqPatchPostProcess function from curtailment sharing problem * Refactor Optimization post processes : adding hydro levels update (after remix) to list of post process * Refactor Optimization post processes : adding post process "interpolate water value" to list of post process * Refactor Optimization post processes : adding post process "Hydro Levels Final Update" to list of post process * [skip ci] Refactor Optimization post processes : adding an empty CSR command to list of post process (to be filled later) * Refactor Optimization post processes : correction after code review * [skip ci] Refactor Optimization post processes : make destructors virtual * Moving curtailment sharing from adequacy patch to a post process command * [skip ci] Moving CSR to a post process command : cleaning * Remove `struct`, clean up * Apply clang-format Co-authored-by: Florian OMNES * [FIX] Add local_matching subdir (#1125) * Change Var to var (#1126) * [FIX] Change Var to var in optimisation folder * [FIX] Refactored old code * Fix/move csr to post process cmd (#1128) * move calculation of LMR violations from CSR source file to adq patch weekly problem * Refactor Optimization post processes : first work : add abstractions for post-process commands and for a list of them. * Refactor Optimization post processes : move the first post process in the list of post processes to be run * Refactor Optimization post processes : fixing a regression * Refactor Optimization post processes : moving the code of the post process associated to dispatchable margin into the command class * Refactor Optimization post processes : some cleaning (see details in the commit's body) - Narrow arguments of optimization post process functions. For example, study is passes while we only need the study's collection of areas - Not pass the constant "nbHoursInAWeek" as an argument, rather make it a constant visible by every function using it. - Remove some useless headers * Refactor Optimization post processes : fixing a crash * Refactor Optimization post processes : adding hydro levels update to list of post process * Refactor Optimization post processes : adding hydro remix to the list of post process * Refactor Optimization post processes : adding DTG margin for adq patch to the list of post process * Refactor Optimization post processes : forgot to remove adqPatchPostProcess function from curtailment sharing problem * Refactor Optimization post processes : adding hydro levels update (after remix) to list of post process * Refactor Optimization post processes : adding post process "interpolate water value" to list of post process * Refactor Optimization post processes : adding post process "Hydro Levels Final Update" to list of post process * [skip ci] Refactor Optimization post processes : adding an empty CSR command to list of post process (to be filled later) * Refactor Optimization post processes : correction after code review * [skip ci] Refactor Optimization post processes : make destructors virtual * Moving curtailment sharing from adequacy patch to a post process command * [skip ci] Moving CSR to a post process command : cleaning * Remove `struct`, clean up * Apply clang-format * Remove `struct`, clean up --------- Co-authored-by: Guillaume PIERRE * Restore tests for releases * Add adequacy-patch-CSR * Re-order format change documentation --------- Co-authored-by: Milos A Co-authored-by: Milos <97689304+Milos-RTEi@users.noreply.github.com> Co-authored-by: rtei-pw Co-authored-by: Hugo ANTOINE (RTEi) Co-authored-by: hugo-antoine-rtei <73881097+hugo-antoine-rtei@users.noreply.github.com> Co-authored-by: payetvin <113102157+payetvin@users.noreply.github.com> Co-authored-by: guilpier-code <62292552+guilpier-code@users.noreply.github.com> Co-authored-by: Vincent Payet Co-authored-by: rtei-pw Co-authored-by: Jason Marechal Co-authored-by: Guillaume PIERRE --- .github/workflows/ubuntu.yml | 10 +- .github/workflows/windows-release.yml | 8 + docs/reference-guide/03-commands.md | 46 +- docs/reference-guide/13-file-format.md | 16 + docs/reference-guide/14-adequacy-patch.md | 183 ++++- src/libs/antares/exception/LoadingError.cpp | 5 + src/libs/antares/exception/LoadingError.hpp | 6 + src/libs/antares/study/fwd.h | 27 +- src/libs/antares/study/parameters.cpp | 104 ++- src/libs/antares/study/parameters.h | 39 +- .../antares/study/parts/hydro/container.cpp | 13 +- .../antares/study/parts/hydro/container.h | 16 +- src/solver/application.cpp | 16 + src/solver/cmake/simulation.cmake | 3 +- src/solver/cmake/solver.cmake | 40 +- src/solver/cmake/variable.cmake | 3 + src/solver/optimisation/adequacy_patch.cpp | 171 ----- .../adq_patch_curtailment_sharing.cpp | 221 ++++++ .../adq_patch_curtailment_sharing.h | 68 ++ .../construct_problem_constraints_RHS.cpp | 154 +++++ .../construct_problem_variables.cpp | 139 ++++ .../count_constraints_variables.cpp | 94 +++ .../count_constraints_variables.h | 36 + .../csr_quadratic_problem.cpp | 278 ++++++++ .../csr_quadratic_problem.h | 55 ++ .../set_problem_cost_function.cpp | 150 +++++ .../set_variable_boundaries.cpp | 194 ++++++ .../adequacy_patch_csr/solve_problem.cpp | 278 ++++++++ .../adq_patch_local_matching.cpp | 166 +++++ .../adq_patch_local_matching.h} | 38 +- .../adequacy_patch_weekly_optimization.cpp | 71 ++ .../adequacy_patch_weekly_optimization.h | 45 ++ .../adq_patch_post_process_list.cpp | 55 ++ .../adq_patch_post_process_list.h | 22 + .../optimisation/base_weekly_optimization.cpp | 52 ++ .../optimisation/base_weekly_optimization.h | 49 ++ src/solver/optimisation/hourly_csr_problem.h | 121 ++++ .../opt_alloc_probleme_a_optimiser.cpp | 215 +++--- .../opt_appel_solveur_lineaire.cpp | 54 +- .../opt_appel_solveur_quadratique.cpp | 49 +- .../opt_calcul_des_pmin_MUT_MDT.cpp | 38 +- .../optimisation/opt_chainage_intercos.cpp | 28 +- ...nstruction_contraintes_couts_demarrage.cpp | 154 ++--- ...n_matrice_des_contraintes_cas_lineaire.cpp | 454 ++++++------- ...atrice_des_contraintes_cas_quadratique.cpp | 32 +- ...onstruction_variables_couts_demarrages.cpp | 12 +- ...truction_variables_optimisees_lineaire.cpp | 48 +- ...ction_variables_optimisees_quadratique.cpp | 10 +- .../opt_decompte_variables_et_contraintes.cpp | 76 +-- ...riables_et_contraintes_couts_demarrage.cpp | 8 +- .../optimisation/opt_export_structure.cpp | 16 +- .../optimisation/opt_export_structure.h | 4 +- src/solver/optimisation/opt_fonctions.h | 6 +- .../opt_gestion_des_bornes_cas_lineaire.cpp | 338 +++++----- ...opt_gestion_des_bornes_cas_quadratique.cpp | 48 +- ...opt_gestion_des_bornes_couts_demarrage.cpp | 58 +- .../opt_gestion_des_couts_cas_lineaire.cpp | 216 +++--- .../opt_gestion_des_couts_cas_quadratique.cpp | 20 +- .../opt_gestion_des_couts_couts_demarrage.cpp | 36 +- .../optimisation/opt_gestion_des_pmax.cpp | 8 +- .../optimisation/opt_gestion_des_pmin.cpp | 8 +- ...opt_gestion_second_membre_cas_lineaire.cpp | 130 ++-- ..._gestion_second_membre_cas_quadratique.cpp | 12 +- ..._gestion_second_membre_couts_demarrage.cpp | 12 +- .../opt_init_contraintes_hydrauliques.cpp | 44 +- ...pt_init_minmax_groupes_couts_demarrage.cpp | 10 +- .../opt_liberation_problemes_simplexe.cpp | 14 +- ...e_min_groupes_demarres_couts_demarrage.cpp | 32 +- .../opt_numero_de_jour_du_pas_de_temps.cpp | 20 +- .../opt_optimisation_lineaire.cpp | 60 +- .../opt_period_string_generator_base.h | 27 + .../opt_pilotage_optimisation_lineaire.cpp | 52 +- .../opt_pilotage_optimisation_quadratique.cpp | 22 +- .../opt_restaurer_les_donnees.cpp | 78 +-- ..._verification_presence_reserve_jmoins1.cpp | 12 +- .../optimisation/optim_post_process_list.cpp | 45 ++ .../optimisation/optim_post_process_list.h | 22 + .../optimisation/post_process_commands.cpp | 286 ++++++++ .../optimisation/post_process_commands.h | 110 +++ .../optimisation/weekly_optimization.cpp | 43 ++ src/solver/optimisation/weekly_optimization.h | 42 ++ src/solver/simulation/adequacy-draft.cpp | 10 +- src/solver/simulation/adequacy-draft.h | 10 +- src/solver/simulation/adequacy.cpp | 33 +- src/solver/simulation/adequacy.h | 10 +- src/solver/simulation/apply-scenario.cpp | 7 +- src/solver/simulation/apply-scenario.h | 7 +- src/solver/simulation/base_post_process.cpp | 46 ++ src/solver/simulation/base_post_process.h | 68 ++ .../simulation/common-dispatchable-margin.cpp | 83 --- src/solver/simulation/common-eco-adq.cpp | 10 +- src/solver/simulation/common-eco-adq.h | 50 +- src/solver/simulation/common-hydro-levels.cpp | 66 +- src/solver/simulation/common-hydro-remix.cpp | 40 +- src/solver/simulation/economy.cpp | 117 +--- src/solver/simulation/economy.h | 43 +- src/solver/simulation/opt_time_writer.cpp | 26 + src/solver/simulation/opt_time_writer.h | 26 + .../simulation/sim_alloc_probleme_hebdo.cpp | 9 + .../simulation/sim_allocation_tableaux.cpp | 1 - .../simulation/sim_calcul_economique.cpp | 20 +- .../sim_extern_variables_globales.h | 2 +- .../sim_structure_probleme_economique.h | 25 +- src/solver/simulation/simulation.h | 2 +- src/solver/simulation/solver.data.cpp | 13 +- src/solver/simulation/solver.data.h | 13 +- src/solver/simulation/solver.h | 10 +- src/solver/simulation/solver.hxx | 10 +- src/solver/simulation/solver.utils.h | 32 +- src/solver/simulation/timeseries-numbers.h | 10 +- src/solver/utils/mps_utils.cpp | 4 +- src/solver/utils/mps_utils.h | 2 +- src/solver/variable/economy/all.h | 92 +-- .../variable/economy/dtgMarginAfterCsr.h | 278 ++++++++ .../economy/localMatchingRuleViolations.h | 274 ++++++++ .../variable/economy/spilledEnergyAfterCSR.h | 279 ++++++++ src/solver/variable/state.cpp | 12 +- src/solver/variable/state.h | 13 +- .../solver/optimisation/adequacy_patch.cpp | 380 ++++++++++- .../simulator/application/main/internal-ids.h | 3 + src/ui/simulator/application/main/main.cpp | 5 + src/ui/simulator/application/main/main.h | 6 + src/ui/simulator/application/main/menu.cpp | 17 + src/ui/simulator/application/main/options.cpp | 16 + src/ui/simulator/cmake/components.cmake | 2 + src/ui/simulator/cmake/windows-options.cmake | 4 + .../components/datagrid/gridhelper.cpp | 20 + .../toolbox/components/datagrid/renderer.h | 4 + .../renderer/adequacy-patch-area-grid.cpp | 155 +++++ .../renderer/adequacy-patch-area-grid.h | 89 +++ .../adequacy-patch/adequacy-patch-areas.cpp | 140 ++++ .../adequacy-patch/adequacy-patch-areas.h | 65 ++ .../adequacy-patch/adequacy-patch-options.cpp | 637 ++++++++++++++++++ .../adequacy-patch/adequacy-patch-options.h | 103 +++ .../options/optimization/optimization.cpp | 139 +--- .../options/optimization/optimization.h | 6 +- 136 files changed, 7372 insertions(+), 2173 deletions(-) delete mode 100644 src/solver/optimisation/adequacy_patch.cpp create mode 100644 src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.cpp create mode 100644 src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.h create mode 100644 src/solver/optimisation/adequacy_patch_csr/construct_problem_constraints_RHS.cpp create mode 100644 src/solver/optimisation/adequacy_patch_csr/construct_problem_variables.cpp create mode 100644 src/solver/optimisation/adequacy_patch_csr/count_constraints_variables.cpp create mode 100644 src/solver/optimisation/adequacy_patch_csr/count_constraints_variables.h create mode 100644 src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp create mode 100644 src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.h create mode 100644 src/solver/optimisation/adequacy_patch_csr/set_problem_cost_function.cpp create mode 100644 src/solver/optimisation/adequacy_patch_csr/set_variable_boundaries.cpp create mode 100644 src/solver/optimisation/adequacy_patch_csr/solve_problem.cpp create mode 100644 src/solver/optimisation/adequacy_patch_local_matching/adq_patch_local_matching.cpp rename src/solver/optimisation/{adequacy_patch.h => adequacy_patch_local_matching/adq_patch_local_matching.h} (55%) create mode 100644 src/solver/optimisation/adequacy_patch_weekly_optimization.cpp create mode 100644 src/solver/optimisation/adequacy_patch_weekly_optimization.h create mode 100644 src/solver/optimisation/adq_patch_post_process_list.cpp create mode 100644 src/solver/optimisation/adq_patch_post_process_list.h create mode 100644 src/solver/optimisation/base_weekly_optimization.cpp create mode 100644 src/solver/optimisation/base_weekly_optimization.h create mode 100644 src/solver/optimisation/hourly_csr_problem.h create mode 100644 src/solver/optimisation/optim_post_process_list.cpp create mode 100644 src/solver/optimisation/optim_post_process_list.h create mode 100644 src/solver/optimisation/post_process_commands.cpp create mode 100644 src/solver/optimisation/post_process_commands.h create mode 100644 src/solver/optimisation/weekly_optimization.cpp create mode 100644 src/solver/optimisation/weekly_optimization.h create mode 100644 src/solver/simulation/base_post_process.cpp create mode 100644 src/solver/simulation/base_post_process.h delete mode 100644 src/solver/simulation/common-dispatchable-margin.cpp create mode 100644 src/solver/variable/economy/dtgMarginAfterCsr.h create mode 100644 src/solver/variable/economy/localMatchingRuleViolations.h create mode 100644 src/solver/variable/economy/spilledEnergyAfterCSR.h create mode 100644 src/ui/simulator/toolbox/components/datagrid/renderer/adequacy-patch-area-grid.cpp create mode 100644 src/ui/simulator/toolbox/components/datagrid/renderer/adequacy-patch-area-grid.h create mode 100644 src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-areas.cpp create mode 100644 src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-areas.h create mode 100644 src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-options.cpp create mode 100644 src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-options.h diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 2246599755..591d497948 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -139,6 +139,14 @@ jobs: path: 'simtest.json' prop_path: 'version' + - name: Run tests for adequacy patch (CSR) + if: ${{ env.IS_PUSH == 'true' }} + uses: ./.github/workflows/run-tests + with: + simtest-tag: ${{steps.simtest-version.outputs.prop}} + batch-name: adequacy-patch-CSR + os: ${{ matrix.test-platform }} + - name: Run tests about infinity on BCs RHS if: ${{ env.IS_PUSH == 'true' }} uses: ./.github/workflows/run-tests @@ -154,7 +162,7 @@ jobs: simtest-tag: ${{steps.simtest-version.outputs.prop}} batch-name: short-tests os: ${{ matrix.test-platform }} - + - name: Run mps tests if: ${{ env.IS_PUSH == 'true' }} uses: ./.github/workflows/run-tests diff --git a/.github/workflows/windows-release.yml b/.github/workflows/windows-release.yml index 6d9e6ca29a..ed39bc80f3 100644 --- a/.github/workflows/windows-release.yml +++ b/.github/workflows/windows-release.yml @@ -149,6 +149,14 @@ jobs: path: 'simtest.json' prop_path: 'version' + - name: Run tests for adequacy patch (CSR) + if: ${{ env.IS_PUSH == 'true' }} + uses: ./.github/workflows/run-tests + with: + simtest-tag: ${{steps.simtest-version.outputs.prop}} + batch-name: adequacy-patch-CSR + os: ${{ matrix.test-platform }} + - name: Run medium-tests uses: ./.github/workflows/run-tests with: diff --git a/docs/reference-guide/03-commands.md b/docs/reference-guide/03-commands.md index fcff4f2915..88ccaf07c8 100644 --- a/docs/reference-guide/03-commands.md +++ b/docs/reference-guide/03-commands.md @@ -6,7 +6,7 @@ The Antares GUI gives access to a general menu of commands whose name and meanin - **New** Create a new empty study to be defined entirely from scratch (network topology, interconnections ratings, thermal power plants list, fuel costs, hydro inflows stats, wind speed stats, load profiles ,etc.) - + - **Open** Load in memory data located in a specified Antares study folder. Once loaded, these data may be reviewed, updated, deleted, and simulations may be performed. If "open" is performed while a study was already opened, the former study will be automatically closed. @@ -63,13 +63,13 @@ those not selected beforehand. ## Input -- **Name of the study** Give a reference name to the study. The default name is identical to that of +- **Name of the study** Give a reference name to the study. The default name is identical to that of the study's folder but the user may modify it. The default name of a new study is "no title" - **Author(s)** Set the study's author(s) name. Default value is "memory" The other "input" subcommands here below are used to move from one active window to another. -Note that the availability of the __Wind__, __Solar__, and __Renewable__ subcommands depend on the advanced +Note that the availability of the __Wind__, __Solar__, and __Renewable__ subcommands depend on the advanced parameter *"Renewable Generation modeling"* described in [miscellaneous](08-miscellaneous.md). - **System Maps** @@ -129,7 +129,7 @@ extraction query on any given specific variable (e.g. "monthly amounts of CO2 to all available years of simulation. The results of such queries are automatically stored within the output file structures, so as to -be available at very short notice if they have to be examined later in another session (extractions may require +be available at very short notice if they have to be examined later in another session (extractions may require a significant computer time when there are many Monte-Carlo years to process). - **Open in Windows Explorer** This command displays the list of available simulation results and allows @@ -144,7 +144,7 @@ If hardware resources and simulation settings allow it, simulations benefit from (see [System requirements](09-system_requirements.md)) - **Time-series Generators** Runs any or all of the Antares stochastic time-series generators, -depending on the values of the parameters set in the "simulation" active window (see [Simulation window](04-active_windows.md#simulation)), and +depending on the values of the parameters set in the "simulation" active window (see [Simulation window](04-active_windows.md#simulation)), and each cluster's "Generate TS" parameter (see [Thermal window](04-active_windows.md#thermal)) - **Time-series Analyzer** Runs the Antares historical time-series analyzer. @@ -164,13 +164,13 @@ the Output data to produce at the end of the simulation, or trimmed from it. In - **Geographic Trimming** Opens an auxiliary window that allows multiple selection of the results to store at the end of a simulation: Choice of areas, interconnections, temporal aggregations (hourly, daily, etc.). Note that in addition to this feature, alternative access to the function is available -(see [Active windows](04-active_windows.md), "output profile"). Geographic Trimming does not reduce actual computation -time but can bring some benefits on total runtime (fewer files to write). Geographic Trimming can save large +(see [Active windows](04-active_windows.md), "output profile"). Geographic Trimming does not reduce actual computation +time but can bring some benefits on total runtime (fewer files to write). Geographic Trimming can save large amounts of storage space in simulations where only a few Areas and Links are of interest. -- **Regional Districts** Allows selecting a set of areas to bundle them together in a "district". -These are used in the course of simulations to aggregate results over several areas. -They can be given almost any name (a "@" prefix is automatically added by Antares). +- **Regional Districts** Allows selecting a set of areas to bundle them together in a "district". +These are used in the course of simulations to aggregate results over several areas. +They can be given almost any name (a "@" prefix is automatically added by Antares). Bypassing the GUI is possible (see [Miscellaneous](08-miscellaneous.md)). - **MC Scenario builder** For each Monte-Carlo year of the simulation defined in the "Simulation" window, @@ -180,7 +180,7 @@ the available set (be it ready-made or Antares-generated) _**OR**_ should take a Regarding Hydro time-series, the scenario builder gives, in addition to the assignment of a specific number to use for the inflows time-series, the ability to define the initial reservoir level to use for each MC year. -- **MC Scenario playlist** For each Monte-Carlo year of the simulation defined in the "Simulation" active window, +- **MC Scenario playlist** For each Monte-Carlo year of the simulation defined in the "Simulation" active window, this command allows to state whether a MC year prepared for the simulation should be actually simulated or not. This feature allows, for instance, to refine a previous simulation by excluding a small number of "raw" MC years whose detailed analysis may have shown that they were not physically realistic. A different typical use consists @@ -193,11 +193,11 @@ values of a given variable were encountered in a previous simulation). - **Optimization preferences** Defines a set of options related to the optimization core used in the simulations. The set of preferences is study-specific; it can be changed at any time and saved along with study data. -Options refer to objects (binding constraints, etc.) that are presented in subsequent sections of this document. +Options refer to objects (binding constraints, etc.) that are presented in subsequent sections of this document. The values set in this menu overlay the local parameters but do not change their value: for instance, if the LOCAL -parameter "set to infinite" is activated for some interconnections, and if the GLOBAL preference regarding transmission +parameter "set to infinite" is activated for some interconnections, and if the GLOBAL preference regarding transmission capacities is "set to null", the simulation will be carried out as if there were no longer any grid BUT the local -values will remain untouched. If the preference is afterwards set to "local values", the interconnections will be +values will remain untouched. If the preference is afterwards set to "local values", the interconnections will be given back their regular capacities (infinite for those being set on "set to infinite"). - _Binding constraints (include / ignore)_ @@ -211,9 +211,21 @@ given back their regular capacities (infinite for those being set on "set to inf - _Export mps (false/true)_ - _Simplex optimization range [^4] (day / week)_ - _Unfeasible problems behavior (Error Dry/ Error Verbose/ Warning Dry/ Warning Verbose_ - - _Enable Adequacy patch (false / true)_ - - _NTC from physical areas outside to physical areas inside adequacy patch (set to null / local values)_ - - _NTC between physical areas outside adequacy patch (set to null / local values)_ + +- **Adequacy Patch** Auxiliary window [Options] Defines a set of options related to the adequacy patch. +The set of preferences is study-specific; it can be changed at any time and saved along with study data. +Auxiliary window [Areas] Opens a window in which a choice can be made regarding the individual area adequacy patch mode. + +- _Enable Adequacy patch (false / true)_ +- _NTC from physical areas outside to physical areas inside adequacy patch (set to null / local values)_ +- _NTC between physical areas outside adequacy patch (set to null / local values)_ +- _Price taking order (DENS / Load)_ +- _Include hurdle cost in CSR optimization (false / true)_ +- _Check CSR cost function value prior and after CSR (false / true)_ +- _Thresholds:_ + - _Initiate curtailment sharing rule_ + - _Display local maching rule violations_ + - _Relax CSR variable boundaries_ - **Advanced parameters** Advanced Parameters allow to adjust the simulation behavior regarding issues that are more numerical than physical. The set of parameters is study-specific and can be updated at any time. diff --git a/docs/reference-guide/13-file-format.md b/docs/reference-guide/13-file-format.md index 68f96e6673..c60592fe27 100644 --- a/docs/reference-guide/13-file-format.md +++ b/docs/reference-guide/13-file-format.md @@ -1,6 +1,22 @@ # Study format changes This is a list of all recent changes that came with new Antares Simulator features. The main goal of this document is to lower the costs of changing existing interfaces, both GUI and scripts. +## v8.5.0 +### Input +In file **settings/generaldata.ini**, in section `adequacy patch`, add properties + +* `price-taking-order` [string] can take values `DENS` (default value) and `Load`. +* `include-hurdle-cost-csr` [bool]. Default value = `false` +* `check-csr-cost-function` [bool]. Default value = `false` +* `threshold-initiate-curtailment-sharing-rule` [double]. Default value = `0.0` +* `threshold-display-local-matching-rule-violations` [double]. Default value = `0.0` +* `threshold-csr-variable-bounds-relaxation` [int]. Default value = `3` + +### Output +* If `include-adq-patch` is set to `true`, add column `LMR VIOL.` in files **values-<period>.txt** (mc-all & mc-ind) +* If `include-adq-patch` is set to `true`, add column `SPIL. ENRG. CSR` in files **values-<period>.txt** (mc-all & mc-ind) +* If `include-adq-patch` is set to `true`, add column `DTG MRG CSR` in files **values-<period>.txt** (mc-all & mc-ind) + ## v8.4.0 ### Input #### Zero/infinite capacity for physical links only diff --git a/docs/reference-guide/14-adequacy-patch.md b/docs/reference-guide/14-adequacy-patch.md index 35f587e823..22ae1e15b5 100644 --- a/docs/reference-guide/14-adequacy-patch.md +++ b/docs/reference-guide/14-adequacy-patch.md @@ -9,7 +9,7 @@ It should be noted that, in the current implementation of the patch within Antar 1. Local matching constraint. -2. The implemented solution does not yet consider secondary problem of sharing of curtailment by the quadratic term. +2. Secondary problem of sharing of curtailment by the quadratic term. 3. The implemented solution does not yet consider the feature in EUPHEMIA, related to ‘minimization of curtailment’ in the primal problem which includes an extra penalty term directly in the global objective function in EUPHEMIA by multiplying the maximum curtailment ratio with a large M pre-factor in the total welfare. @@ -53,8 +53,185 @@ Once the first iteration is completed, we have access to the DENS value, which r During the second iteration, all link capacities between physical nodes are set to the values provided as input data (as it is done in the current Antares version). The only change compared to a simulation without the adequacy patch is that the upper bound of the ENS on the areas included in the patch is now constrained by the DENS found during the first iteration. This is introduced in the optimization problem for physical areas that are declared in the adequacy patch domain (areas declared as "physical inside"): -- ENS <= DENS +- ENS $\le$ DENS (for all physical areas inside the adequacy patch). ## Curtailment sharing rule -The curtailment sharing rule will be implemented in Antares Simulator 8.4. It will include an hourly post-processing phase. + +The second implemented rule is called the « Curtailment Sharing » rule (henceforth CSR). + +The idea is that when countries on the network have positive DENS, they should have relatively similar levels of unsupplied energy (as the name suggests, so that the curtailment is shared). The quantity that is to be measured and compared across countries is: ENS/PTO where PTO is the Price Taking Orders. There are different options of defining the PTOs. In this development we will consider two: + +- PTOs are the DENS of the country +- PTOs are the Load of the country + +The considered countries are only nodes “2” (areas defined as physical areas inside the adequacy patch), the problem to be solved is an hourly problem. Precisely, the hourly problem to be solved concerns only hours for which of the sum of the ENS in all nodes “2” is exceeding a user-defined threshold. If it is not the case, all the treatments described below should be ignored for this hour and the algorithm should then consider the next hour. So, at that step, we will solve the CSR quadratic optimization problem on a reduced domain, limited to nodes “2” and the links that exist between these nodes 2. + +_**Notes**_ + +- _Local matching and curtailment sharing rule are only part of the economic mode of Antares (Not the Adequacy or Draft mode);_ + +_**Convention**_: + +- _A is any node of type “2” in the network, an area that is defined as a physical area inside the adequacy patch. Each variable/parameter/constraint applied on A is implicitly applied to any node of type "2”;_ +- _B represents any node of type "2” linked to A;_ +- _A is alphabetically before B, therefore their link in Antares would be called A/B. Furthermore, regarding the flow on this link (variable that contains the algebraic value of the power flow between the 2 nodes to be optimized):_ + - _if the flow value is positive, the power flow goes from node A to node B, it is an export for node A and an import for node B;_ + - _if the flow value is negative, the power flow goes from node B to node A, it is an import for node A and an export for node B._ + +### Variable definitions + +- Flows over links variables (3 set of variables: “Flow”, “Flow_direct” and “Flow_indirect"): +Inside the optimization problem, the “flow” variable is actually split in 2 positive variables for the resolution. It is required in order to write some constraints. We define the 2 positive variables, “Flow_direct” and “Flow_indirect” with this simple relation: +Flow = Flow_direct – Flow_indirect + +- “net_position” variable: +“net_position (node A)” is the balance between node A and all other nodes “2” connected to node A. + +- “ENS” variable: +“ENS (node A)” contains the ENS to be optimized for that node. + +- “Spillage” variable: +“Spillage (node A)” contains the Spillage to be optimized for that node. + +### Parameter definitions + +- “net_position_init” parameter: +The “net_position_init (node A)” parameter value is the value of the “net_position” calculated from the output of the Antares calculation for node A, considering results we get from the Antares calculation at the end of Local matching rule optimization. + +- “ENS_init” parameter: +The “ENS_init (node A)” parameter value is the value of the “ENS” obtained from the output of the Antares calculation for node A at the end of Local matching rule optimization. + +- “DENS_new” parameter: The “DENS_new (node A)” parameter value is an update of the value of the “DENS” parameter which takes into account the result of Antares calculation (therefore different than the one estimated in Local matching rule optimization). + +- “Spillage_init” parameter: +The “Spillage_init (node A)” parameter value is the value of the “Spillage” obtained from the output of the Antares calculation for node A at the end of Local matching rule optimization. + +- “Hurdle cost” parameter on links: +This parameter, fixed on links, is kept from the Antares optimization problem. +Like “flows” we can split “Hurdle cost” in “Hurdle_cost_direct” and “Hurdle_cost_indirect” + +### Constraints and relations between variables + +- **Constraints on “Flows”, “Flow_direct” and “Flow_indirect” variables:** +These variables should have exactly the same constraints than the ones considered in the Antares problem: + + - NTC constrains (independent lower and upper bounds for each link). + - Flowbased binding constraints to be extracted from the hourly binding constraint list. + +- **Relation between “Flows” over links and “net_position” on nodes:** +The value of “net_position (node A)” is deduced from “flow” variable as follows: + + - net_position (node A) = $\sum$ algebraic “Flows” over links involving node A + Remember that: + + - a “Flow” that goes from another node “2” to node A is an import for node A and should be counted positively + - a “Flow” that goes from node A to another node “2” is an export for node A and should be counted negatively. + +- **The detailed formulation for calculating the value of “net_position (node A)” is, for all “nodes 2 upstream” and all “nodes 2 downstream”:** + - net_position (node A) = $\sum$ flow_direct (node 2 upstream -> node A) + $\sum$ flow_indirect (node A <- node 2 downstream) - $\sum$ flow_indirect (node 2 upstream <- node A) - $\sum$ flow_direct (node A -> node 2 downstream) + + Considering that: + + - “Node 2 upstream” is any node “2” which name in alphabetic order is before node A + - “Node 2 downstream” is any node “2” which name in alphabetic order is after node A + +- **Formula for calculating DENS_new parameter:** + - DENS_new (node A) = max [ 0; ENS_init (node A) + net_position_init (node A) - DTG.MRG (node A)] + + Depending on the parameter in the GUI that includes or not possible imports from nodes “1” to nodes “2” in the DENS calculation, we should modify this formula. Precisely, it is when “NTC from physical areas outside to physical areas inside adequacy patch” is set to null then the formulation such be modified as follows: + + - DENS_new (node A) = max [ 0; ENS_init (node A) + net_position_init (node A) + $\sum$ flows (node 1 -> node A) - DTG.MRG (node A)] + + The detailed formulation for calculating the last term is, for all “nodes 1 upstream” and all “nodes 1 downstream”: + + - $\sum$ flows (node 1 -> node A) = $\sum$ flow_direct (node 1 upstream -> node A) + $\sum$ flow_indirect (node A <- node 1 downstream) + + Considering that: + - “Node 1 upstream” is any node “1” which name in alphabetic order is before node A + - “Node 1 downstream” is any node “1” which name in alphabetic order is after node A + + The consideration of a correct DENS_new as presented above should ensure that the Local Matching Approach is respected, (node A) can’t be "Exporting” and having ENS after CSR. + +- **Relation induced by node balancing conservation:** + - ENS (node A) + net_position (node A) – spillage (node A) = ENS_init (node A) + net_position_init (node A) – spillage_init (node A) + + Actually, this simplified formulation takes into account that these variables are the only ones we are allowed to update by this optimization (power generation for all nodes and power flows between other nodes than nodes “2” will not be modified). + +- **Constraint induced by Local matching rule:** + + - ENS (node A) $\le$ DENS_new(node A) + +- **Positivity constraints:** + + - ENS (node A) $\ge$ 0 + - spillage (node A) $\ge$ 0 + +_**Notes**_ + +- _“Spillage” variable and “Spillage_init” parameter have been introduced only to deal with some situations for which “Flowbased” constraints, combining with adequacy patch rules, lead to an increase of Total ENS over the different nodes “2”. Such increase of Total ENS could happen for 2 reasons:_ + + - _We have new violations of Local Matching rule and the optimal solution found by Antares is no longer a valid solution, regards to this rule;_ + - _The curtailment sharing rule target is to minimize $\sum$(ENS$^2$/PTO) and such objective is not exactly equivalent than minimizing Total ENS._ + + _As a matter of fact, if we sum over all nodes “2” the relation induced by node balancing conservation, as the sum of all “net_position” is null, it leads to:_ + + - _Total ENS – Total Spillage = Total ENS_init – Total Spillage_init, over all nodes “2”_ + + _So, an increase of Total ENS will necessarily leads to the same increase of Total Spillage._ + +- _Spillage results after curtailment sharing rule quadratic optimization are presented in the separate column inside Antares output, titled “SPIL. ENRG. CSR” so the user has access to the spillage results both prior to and after CSR optimization._ + +- _In order to avoid solver issues, lower and upper boundaries of the ENS and Spillage variables can be relaxed using GUI option “Relax CSR variable boundaries”. Following relaxations can be imposed:_ + - -10$^-$$^m$ $\le$ ENS (node A) $\le$ DENS_new (node A) + 10$^-$$^m$ + - -10$^-$$^m$ $\le$ spillage (node A) $\le$ + infinity + Where _m_ is an integer defined by the user. + +### Objective function + +- Minimize [$\sum$(ENS$^2$/PTO) + $\sum$(hurdle_cost_direct x flow_direct) + $\sum$(hurdle_cost_indirect x flow_indirect)] + +The 2 latest terms are introduced to minimize loop flows in the considering domain. +In order to assess the quality of the CSR solution additional verification can be imposed by activating GUI option “Check CSR cost function value prior and after CSR optimization”. Values of the objective function prior to and after quadratic optimization will be calculated and compared. If the objective function value after the quadratic optimization has decreased, the new CSR solution will be accepted and presented in the Antares output. However, if after quadratic optimization the objective function value has increased (or stayed the same), LMR solution will be adopted as the final one and warning will be logged out with the appropriate information (year, hour cost prior to quad optimization, cost after quadratic optimization). + +- QUAD$_0$ = [$\sum$(ENS_init$^2$/PTO) + $\sum$(hurdle_cost_direct x flow_direct_init) + $\sum$(hurdle_cost_indirect x flow_indirect_init)] +- QUAD$_1$ = [$\sum$(ENS_final$^2$/PTO) + $\sum$(hurdle_cost_direct x flow_direct_final) + $\sum$(hurdle_cost_indirect x flow_indirect_final)] + +If: + +- QUAD$_0$ $\le$ QUAD$_1$ +(CSR does not improve QUAD) then the “_init” solution is kept and the CSR solution is hence disregarded. +- QUAD$_0$ > QUAD$_1$ +(CSR does improve QUAD) then the “CSR” solution is kept as final result updating the “_init” solution as stated above. + +### Post-optimization process + +For the CSR triggered hours, if after quadratic optimization, area inside adequacy patch still experiences unsupplied energy: + +- ENS (node A) > 0 + +following adjustments will be performed. Available dispatchable margin “DTG MRG” will be used to compensate for the residual unsupplied energy ENS: + +- ENS (node A) = max[0.0, ENS (node A) - DTG.MRG (node A)] + +Remaining dispatchable margin after above-described post-optimisation calculation is stored inside new column “DTG MRG CSR” + +- DTG.MRG.CSR (node A) = max[0.0, DTG.MRG (node A) - ENS (node A)] + +Note that for all the hours for which curtailment sharing rule was not triggered, as well as for the hours for which curtailment sharing rule was triggered but after quadratic optimization ENS (node A) is equal to zero, DTG.MRG.CSR (node A) will be equal to DTG.MRG (node A). For the curtailment sharing rule triggered hours, if after quadratic optimization and above-described post calculation process, area inside adequacy patch still experiences unsupplied energy, marginal price “MRG.PRICE” will be aligned with the price cap in the model (set to Unsupplied Energy Cost in the results). + +- MRG.PRICE (node A) = Unsupplied Energy Cost (node A) + +_**Notes**_ + +- _SPIL. ENRG. CSR and DTG MRG CSR outputs of Antares, for all selected areas, are available in the General values tab, as year-by-year and synthetic results. All the statistic values for it are calculated as well (min, max, mean, standard deviation). For the areas not part of the patch, the default output is set to 0._ +- _LMR VIOL. outputs of Antares, for all selected areas, are available in the General values tab, as year-by-year and synthetic results. For the areas not part of the patch, the default output is set to 0. +LMR violation check is performed for all hours (CSR triggered or not) after LMR linear optimization (prior to CSR quadratic optimization). Hourly value of LMR violation is set to value one if all following conditions are met:_ + + - _ENS_init (node A) > 0;_ + - _net_position_init (node A) + $\sum$ flows (node 1 -> node A) < 0;_ + - _Abs[net_position_init (node A) + $\sum$ flows (node 1 -> node A)] > ENS_init (node A) + GUI_defined_threshold._ + + _Second equation is satisfied if the area is exporting power. Depending on the GUI option member ($\sum$ flows (node 1 -> node A)) is optional._ + + diff --git a/src/libs/antares/exception/LoadingError.cpp b/src/libs/antares/exception/LoadingError.cpp index b393fd7795..390ada2e8f 100644 --- a/src/libs/antares/exception/LoadingError.cpp +++ b/src/libs/antares/exception/LoadingError.cpp @@ -133,6 +133,11 @@ NoAreaInsideAdqPatchMode::NoAreaInsideAdqPatchMode() : { } +IncompatibleHurdleCostCSR::IncompatibleHurdleCostCSR() : + LoadingError("Incompatible options include.hurdleCost and curtailmentSharing.includeHurdleCost") +{ +} + IncompatibleOutputOptions::IncompatibleOutputOptions(const std::string& text) : LoadingError(text) { } diff --git a/src/libs/antares/exception/LoadingError.hpp b/src/libs/antares/exception/LoadingError.hpp index a75ddbec30..b90d40df31 100644 --- a/src/libs/antares/exception/LoadingError.hpp +++ b/src/libs/antares/exception/LoadingError.hpp @@ -179,6 +179,12 @@ class NoAreaInsideAdqPatchMode : public LoadingError NoAreaInsideAdqPatchMode(); }; +class IncompatibleHurdleCostCSR : public LoadingError +{ +public: + IncompatibleHurdleCostCSR(); +}; + class IncompatibleOutputOptions : public LoadingError { public: diff --git a/src/libs/antares/study/fwd.h b/src/libs/antares/study/fwd.h index dd28cbfc93..c9c69411c2 100644 --- a/src/libs/antares/study/fwd.h +++ b/src/libs/antares/study/fwd.h @@ -575,11 +575,7 @@ class Sets; } // namespace Data } // namespace Antares -namespace Antares -{ -namespace Data -{ -namespace AdequacyPatch +namespace Antares::Data::AdequacyPatch { /*! ** \brief Types of Adequacy patch mode @@ -597,21 +593,32 @@ enum AdequacyPatchMode /*! ** \brief Setting Link Capacity (NTC) for Adequacy patch first step */ -enum LinkCapacityForAdequacyPatchFirstStep +enum class NtcSetToZeroStatus_AdqPatchStep1 { //! Leave NTC local values leaveLocalValues = 0, //! Set NTC to zero setToZero, //! set only origine->extremity NTC to zero - setOrigineExtremityToZero, + setOriginExtremityToZero, //! set only extremity->origine NTC to zero setExtremityOriginToZero }; // enum NTC -} // namespace AdequacyPatch -} // namespace Data -} // namespace Antares + +/*! +** \brief Types of Price Taking Order (PTO) for Adequacy Patch +*/ +enum class AdqPatchPTO +{ + //! PTO is DENS + isDens = 0, + //! PTO is Load + isLoad + +}; // enum AdqPatchPTO + +} // namespace Antares::Data::AdequacyPatch namespace Benchmarking { diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index b0e8bf8301..0c3640eb53 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -41,15 +41,14 @@ #include #include #include "../solver/variable/economy/all.h" +#include "../solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.h" #include #include using namespace Yuni; -namespace Antares -{ -namespace Data +namespace Antares::Data { //! Hard coded maximum number of MC years const uint maximumMCYears = 100000; @@ -207,6 +206,39 @@ const char* StudyModeToCString(StudyMode mode) } return "Unknown"; } +bool StringToPriceTakingOrder(const AnyString& PTO_as_string, AdequacyPatch::AdqPatchPTO& PTO_as_enum) +{ + CString<24, false> s = PTO_as_string; + s.trim(); + s.toLower(); + if (s == "dens") + { + PTO_as_enum = AdequacyPatch::AdqPatchPTO::isDens; + return true; + } + if (s == "load") + { + PTO_as_enum = AdequacyPatch::AdqPatchPTO::isLoad; + return true; + } + + logs.warning() << "parameters: invalid price taking order. Got '" << PTO_as_string << "'"; + + return false; +} + +const char* PriceTakingOrderToString(AdequacyPatch::AdqPatchPTO pto) +{ + switch (pto) + { + case AdequacyPatch::AdqPatchPTO::isDens: + return "DENS"; + case AdequacyPatch::AdqPatchPTO::isLoad: + return "Load"; + default: + return ""; + } +} Parameters::Parameters() : noOutput(false) { @@ -228,12 +260,36 @@ void Parameters::resetSeeds() for (auto i = (uint)seedTsGenLoad; i != seedMax; ++i) seed[i] = (s += increment); } +void Parameters::resetThresholdsAdqPatch() +{ + // Initialize all thresholds values for adequacy patch + adqPatch.curtailmentSharing.thresholdRun + = Antares::Data::AdequacyPatch::defaultThresholdToRunCurtailmentSharing; + adqPatch.curtailmentSharing.thresholdDisplayViolations + = Antares::Data::AdequacyPatch::defaultThresholdDisplayLocalMatchingRuleViolations; + adqPatch.curtailmentSharing.thresholdVarBoundsRelaxation + = Antares::Data::AdequacyPatch::defaultValueThresholdVarBoundsRelaxation; +} + +void Parameters::AdequacyPatch::LocalMatching::reset() +{ + setToZeroOutsideInsideLinks = true; + setToZeroOutsideOutsideLinks = true; +} + +void Parameters::AdequacyPatch::CurtailmentSharing::reset() +{ + priceTakingOrder = Data::AdequacyPatch::AdqPatchPTO::isDens; + includeHurdleCost = false; + checkCsrCostFunction = false; +} void Parameters::resetAdqPatchParameters() { adqPatch.enabled = false; - adqPatch.localMatching.setToZeroOutsideInsideLinks = true; - adqPatch.localMatching.setToZeroOutsideOutsideLinks = true; + adqPatch.localMatching.reset(); + adqPatch.curtailmentSharing.reset(); + resetThresholdsAdqPatch(); } void Parameters::resetPlayedYears(uint nbOfYears) @@ -674,6 +730,22 @@ static bool SGDIntLoadFamily_AdqPatch(Parameters& d, return value.to(d.adqPatch.localMatching.setToZeroOutsideInsideLinks); if (key == "set-to-null-ntc-between-physical-out-for-first-step") return value.to(d.adqPatch.localMatching.setToZeroOutsideOutsideLinks); + // Price taking order + if (key == "price-taking-order") + return StringToPriceTakingOrder(value, d.adqPatch.curtailmentSharing.priceTakingOrder); + // Include Hurdle Cost + if (key == "include-hurdle-cost-csr") + return value.to(d.adqPatch.curtailmentSharing.includeHurdleCost); + // Check CSR cost function prior and after CSR + if (key == "check-csr-cost-function") + return value.to(d.adqPatch.curtailmentSharing.checkCsrCostFunction); + // Thresholds + if (key == "threshold-initiate-curtailment-sharing-rule") + return value.to(d.adqPatch.curtailmentSharing.thresholdRun); + if (key == "threshold-display-local-matching-rule-violations") + return value.to(d.adqPatch.curtailmentSharing.thresholdDisplayViolations); + if (key == "threshold-csr-variable-bounds-relaxation") + return value.to(d.adqPatch.curtailmentSharing.thresholdVarBoundsRelaxation); return false; } @@ -1713,7 +1785,19 @@ void Parameters::saveToINI(IniFile& ini) const adqPatch.localMatching.setToZeroOutsideInsideLinks); section->add("set-to-null-ntc-between-physical-out-for-first-step", adqPatch.localMatching.setToZeroOutsideOutsideLinks); + section->add("price-taking-order", + PriceTakingOrderToString(adqPatch.curtailmentSharing.priceTakingOrder)); + section->add("include-hurdle-cost-csr", adqPatch.curtailmentSharing.includeHurdleCost); + section->add("check-csr-cost-function", adqPatch.curtailmentSharing.checkCsrCostFunction); + // Thresholds + section->add("threshold-initiate-curtailment-sharing-rule", + adqPatch.curtailmentSharing.thresholdRun); + section->add("threshold-display-local-matching-rule-violations", + adqPatch.curtailmentSharing.thresholdDisplayViolations); + section->add("threshold-csr-variable-bounds-relaxation", + adqPatch.curtailmentSharing.thresholdVarBoundsRelaxation); } + // Other preferences { auto* section = ini.addSection("other preferences"); @@ -1890,7 +1974,12 @@ void Parameters::RenewableGeneration::addExcludedVariables(std::vector& out) const { if (!enabled) - out.emplace_back("dens"); + { + out.emplace_back("DENS"); + out.emplace_back("LMR VIOL."); + out.emplace_back("SPIL. ENRG. CSR"); + out.emplace_back("DTG MRG CSR"); + } } bool Parameters::haveToImport(int tsKind) const @@ -1929,5 +2018,4 @@ bool Parameters::RenewableGeneration::isClusters() const return rgModelling == Antares::Data::rgClusters; } -} // namespace Data -} // namespace Antares +} // namespace Antares::Data diff --git a/src/libs/antares/study/parameters.h b/src/libs/antares/study/parameters.h index 7590fe3413..a0106d8cab 100644 --- a/src/libs/antares/study/parameters.h +++ b/src/libs/antares/study/parameters.h @@ -41,9 +41,8 @@ #include -namespace Antares -{ -namespace Data + +namespace Antares::Data { /*! ** \brief General data for a study @@ -136,6 +135,10 @@ class Parameters final */ void resetSeeds(); /*! + ** \brief Reset to default all threshold values in adequacy patch + */ + void resetThresholdsAdqPatch(); + /*! ** \brief Reset to default all adequacy patch values */ void resetAdqPatchParameters(); @@ -501,10 +504,37 @@ class Parameters final //! NTC is set to null (if true) only in the first step of adequacy patch local matching //! rule. bool setToZeroOutsideOutsideLinks = true; + /*! + ** \brief Reset to default values related to local matching + */ + void reset(); }; bool enabled; LocalMatching localMatching; + + struct CurtailmentSharing + { + //! PTO (Price Taking Order) for adequacy patch. User can choose between DENS and Load. + Data::AdequacyPatch::AdqPatchPTO priceTakingOrder; + //! Threshold to initiate curtailment sharing rule + double thresholdRun; + //! Threshold to display Local Matching Rule violations + double thresholdDisplayViolations; + //! CSR Variables relaxation threshold + int thresholdVarBoundsRelaxation; + //! Include hurdle cost in CSR cost function + bool includeHurdleCost; + //! Check CSR cost function prior & after CSR optimization + bool checkCsrCostFunction; + /*! + ** \brief Reset to default values related to curtailment sharing + */ + void reset(); + }; + CurtailmentSharing curtailmentSharing; + void addExcludedVariables(std::vector&) const; + }; AdequacyPatch adqPatch; @@ -565,8 +595,7 @@ const char* StudyModeToCString(StudyMode mode); */ bool StringToStudyMode(StudyMode& mode, Yuni::CString<20, false> text); -} // namespace Data -} // namespace Antares +} // namespace Antares::Data #include "parameters.hxx" diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index 6869ccf19d..9b90d92f24 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -987,19 +987,18 @@ void PartHydro::copyFrom(const PartHydro& rhs) void getWaterValue(const double& level /* format : in % of reservoir capacity */, const Matrix& waterValues, const uint day, - h2oValueWorkVarsType& workVar, double& waterValueToReturn) { assert((level >= 0. && level <= 100.) && "getWaterValue function : invalid level"); - workVar.levelUp = ceil(level); - workVar.levelDown = floor(level); + double levelUp = ceil(level); + double levelDown = floor(level); - if ((int)(workVar.levelUp) == (int)(workVar.levelDown)) - waterValueToReturn = waterValues[(int)(workVar.levelUp)][day]; + if ((int)(levelUp) == (int)(levelDown)) + waterValueToReturn = waterValues[(int)(levelUp)][day]; else waterValueToReturn - = waterValues[(int)(workVar.levelUp)][day] * (level - workVar.levelDown) - + waterValues[(int)(workVar.levelDown)][day] * (workVar.levelUp - level); + = waterValues[(int)(levelUp)][day] * (level - levelDown) + + waterValues[(int)(levelDown)][day] * (levelUp - level); } double getWeeklyModulation(const double& level /* format : in % of reservoir capacity */, diff --git a/src/libs/antares/study/parts/hydro/container.h b/src/libs/antares/study/parts/hydro/container.h index 7b2aff91e3..5636b348a9 100644 --- a/src/libs/antares/study/parts/hydro/container.h +++ b/src/libs/antares/study/parts/hydro/container.h @@ -32,9 +32,7 @@ #include "../../fwd.h" #include "allocation.h" -namespace Antares -{ -namespace Data +namespace Antares::Data { /*! ** \brief Hydro for a single area @@ -176,14 +174,6 @@ class PartHydro }; // class PartHydro -// Type encapsulating working variables for next function : -// As the next function can be called a lot of times, passing an already created variable -// avoids the overhead of local variables creation -struct h2oValueWorkVarsType -{ - double levelUp; - double levelDown; -}; // Interpolates a water value from a table according to a level and a day. // As this function can be called a lot of times, we pass working variables and returned variables @@ -192,7 +182,6 @@ struct h2oValueWorkVarsType void getWaterValue(const double& level, const Matrix& waterValues, const uint day, - h2oValueWorkVarsType& workVar, double& waterValueToReturn); // Interpolates a rate from the credit modulation table according to a level @@ -200,8 +189,7 @@ double getWeeklyModulation(const double& level /* format : in % of reservoir cap Matrix& creditMod, int modType); -} // namespace Data -} // namespace Antares +} // namespace Antares::Data #include "../../area.h" diff --git a/src/solver/application.cpp b/src/solver/application.cpp index b26019dc9a..d1fe9453ec 100644 --- a/src/solver/application.cpp +++ b/src/solver/application.cpp @@ -115,6 +115,18 @@ void checkAdqPatchContainsAdqPatchArea(const bool adqPatchOn, const Antares::Dat } } +void checkAdqPatchIncludeHurdleCost(const bool adqPatchOn, + const bool includeHurdleCost, + const bool includeHurdleCostCsr) +{ + // No need to check if adq-patch is disabled + if (!adqPatchOn) + return; + + if (includeHurdleCostCsr && !includeHurdleCost) + throw Error::IncompatibleHurdleCostCSR(); +} + void checkMinStablePower(bool tsGenThermal, const Antares::Data::AreaList& areas) { if (tsGenThermal) @@ -282,7 +294,11 @@ void Application::prepare(int argc, char* argv[]) checkSimplexRangeHydroHeuristic(pParameters->simplexOptimizationRange, pStudy->areas); checkAdqPatchStudyModeEconomyOnly(pParameters->adqPatch.enabled, pParameters->mode); + checkAdqPatchContainsAdqPatchArea(pParameters->adqPatch.enabled, pStudy->areas); + checkAdqPatchIncludeHurdleCost(pParameters->adqPatch.enabled, + pParameters->include.hurdleCosts, + pParameters->adqPatch.curtailmentSharing.includeHurdleCost); bool tsGenThermal = (0 != (pParameters->timeSeriesToGenerate & Antares::Data::TimeSeries::timeSeriesThermal)); diff --git a/src/solver/cmake/simulation.cmake b/src/solver/cmake/simulation.cmake index ce46c09d02..63e9e8f69b 100644 --- a/src/solver/cmake/simulation.cmake +++ b/src/solver/cmake/simulation.cmake @@ -34,13 +34,14 @@ set(SRC_SIMULATION simulation/common-eco-adq.cpp simulation/common-hydro-remix.cpp simulation/common-hydro-levels.cpp - simulation/common-dispatchable-margin.cpp simulation/adequacy-draft.h simulation/adequacy-draft.cpp simulation/adequacy.h simulation/adequacy.cpp simulation/economy.h simulation/economy.cpp + simulation/base_post_process.h + simulation/base_post_process.cpp simulation/opt_time_writer.h simulation/opt_time_writer.cpp ) diff --git a/src/solver/cmake/solver.cmake b/src/solver/cmake/solver.cmake index e48ebc38ac..95cc1ccd82 100644 --- a/src/solver/cmake/solver.cmake +++ b/src/solver/cmake/solver.cmake @@ -1,4 +1,5 @@ + #TODO : define flags with CMake way if(NOT MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -Wno-unused-variable") @@ -40,7 +41,7 @@ set(RTESOLVER_OPT optimisation/opt_liberation_problemes_simplexe.cpp optimisation/opt_restaurer_les_donnees.cpp optimisation/opt_gestion_des_couts_cas_quadratique.cpp - optimisation/opt_construction_contraintes_couts_demarrage.cpp + optimisation/opt_construction_contraintes_couts_demarrage.cpp optimisation/opt_construction_variables_couts_demarrages.cpp optimisation/opt_gestion_des_bornes_couts_demarrage.cpp optimisation/opt_gestion_des_couts_couts_demarrage.cpp @@ -51,8 +52,32 @@ set(RTESOLVER_OPT optimisation/opt_nombre_min_groupes_demarres_couts_demarrage.cpp optimisation/opt_export_structure.h optimisation/opt_export_structure.cpp - optimisation/adequacy_patch.h - optimisation/adequacy_patch.cpp + optimisation/base_weekly_optimization.h + optimisation/base_weekly_optimization.cpp + optimisation/adequacy_patch_weekly_optimization.h + optimisation/adequacy_patch_weekly_optimization.cpp + optimisation/weekly_optimization.h + optimisation/weekly_optimization.cpp + optimisation/optim_post_process_list.h + optimisation/optim_post_process_list.cpp + optimisation/adq_patch_post_process_list.h + optimisation/adq_patch_post_process_list.cpp + optimisation/post_process_commands.h + optimisation/post_process_commands.cpp + optimisation/adequacy_patch_local_matching/adq_patch_local_matching.h + optimisation/adequacy_patch_local_matching/adq_patch_local_matching.cpp + optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.h + optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.cpp + optimisation/adequacy_patch_csr/solve_problem.cpp + optimisation/adequacy_patch_csr/set_variable_boundaries.cpp + optimisation/adequacy_patch_csr/set_problem_cost_function.cpp + optimisation/adequacy_patch_csr/construct_problem_variables.cpp + optimisation/adequacy_patch_csr/construct_problem_constraints_RHS.cpp + optimisation/adequacy_patch_csr/csr_quadratic_problem.h + optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp + optimisation/adequacy_patch_csr/count_constraints_variables.h + optimisation/adequacy_patch_csr/count_constraints_variables.cpp + optimisation/opt_period_string_generator_base.h utils/ortools_utils.h @@ -74,4 +99,11 @@ set(SRC_MODEL ) add_library(libmodel_antares ${SRC_MODEL}) -target_link_libraries(libmodel_antares PUBLIC libantares-core ortools::ortools sirius_solver infeasible_problem_analysis) +target_link_libraries(libmodel_antares + PUBLIC + libantares-core + ortools::ortools + sirius_solver + infeasible_problem_analysis + libantares-solver-simulation + ) diff --git a/src/solver/cmake/variable.cmake b/src/solver/cmake/variable.cmake index b4cf1e5d89..189782ae3c 100644 --- a/src/solver/cmake/variable.cmake +++ b/src/solver/cmake/variable.cmake @@ -134,6 +134,9 @@ set(SRC_VARIABLE_ECONOMY variable/economy/hydroCost.h variable/economy/unsupliedEnergy.h variable/economy/domesticUnsuppliedEnergy.h + variable/economy/localMatchingRuleViolations.h + variable/economy/spilledEnergyAfterCSR.h + variable/economy/dtgMarginAfterCsr.h variable/economy/spilledEnergy.h variable/economy/dispatchableGeneration.h variable/economy/productionByDispatchablePlant.h diff --git a/src/solver/optimisation/adequacy_patch.cpp b/src/solver/optimisation/adequacy_patch.cpp deleted file mode 100644 index 3ea91a796e..0000000000 --- a/src/solver/optimisation/adequacy_patch.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* -** Copyright 2007-2018 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** 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 -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ - -#include "../simulation/simulation.h" -#include "adequacy_patch.h" -#include - -namespace Antares::Data::AdequacyPatch -{ -/*! - * Determines restriction type for transmission links for first step of adequacy patch, when start - * node is inside adq path (type 2). - * - * @param ExtremityNodeAdequacyPatchType uint: The adq type of the node at the end of the link. - * - * @return uint from an enumeration that describes the type of restrictions to put on this link for - * adq purposes. - */ -static LinkCapacityForAdequacyPatchFirstStep getNTC_OriginNodeInside( - AdequacyPatchMode extremityType) -{ - switch (extremityType) - { - case physicalAreaInsideAdqPatch: - case physicalAreaOutsideAdqPatch: - return setToZero; - default: - return leaveLocalValues; - } -} - -/*! - * Determines restriction type for transmission links for first step of adequacy patch, when start - * node is outside adq path (type 1). - * - * @param extremityType uint: The adq type of the node at the end of the link. - * - * @param SetToZero12Links bool: Switch to cut links from nodes outside adq patch - * (type 1) towards nodes inside adq patch (type 2). - * - * @param SetToZero11Links bool: Switch to cut links between nodes outside adq patch - * (type 1). - * - * @return uint from an enumeration that describes the type of restrictions to put on this link for - * adq purposes. - */ -static LinkCapacityForAdequacyPatchFirstStep getNTC_OriginNodeOutside( - AdequacyPatchMode extremityType, - bool SetToZero12Links, - bool SetToZero11Links) -{ - switch (extremityType) - { - case physicalAreaInsideAdqPatch: - return SetToZero12Links ? setToZero : setExtremityOriginToZero; - case physicalAreaOutsideAdqPatch: - return SetToZero11Links ? setToZero : leaveLocalValues; - default: - return leaveLocalValues; - } -} - -/*! - * Determines restriction type for transmission links for first step of adequacy patch. - * - * @param originType uint: The adq type of the node at the start of the link. - * - * @param extremityType uint: The adq type of the node at the end of the link. - * - * @param SetToZero12Links bool: Switch to cut links from nodes outside adq patch - * (type 1) towards nodes inside adq patch (type 2). - * - * @param SetToZero11Links bool: Switch to cut links between nodes outside adq patch - * (type 1). - * - * @return uint from an enumeration that describes the type of restrictions to put on this link for - * adq purposes. - */ -static LinkCapacityForAdequacyPatchFirstStep getNTCStatus(const PROBLEME_HEBDO* ProblemeHebdo, - const int Interco) -{ - assert(ProblemeHebdo); - assert(ProblemeHebdo); - - const AdequacyPatchMode originType - = ProblemeHebdo->adequacyPatchRuntimeData.originAreaType[Interco]; - const AdequacyPatchMode extremityType - = ProblemeHebdo->adequacyPatchRuntimeData.extremityAreaType[Interco]; - const bool SetToZero12Links = ProblemeHebdo->adqPatchParams->SetNTCOutsideToInsideToZero; - const bool SetToZero11Links = ProblemeHebdo->adqPatchParams->SetNTCOutsideToOutsideToZero; - - switch (originType) - { - case physicalAreaInsideAdqPatch: - return getNTC_OriginNodeInside(extremityType); - - case physicalAreaOutsideAdqPatch: - return getNTC_OriginNodeOutside(extremityType, SetToZero12Links, SetToZero11Links); - default: - return leaveLocalValues; - } -} - -void setBoundsAdqPatch(double& Xmax, - double& Xmin, - VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeNTC, - const int Interco, - PROBLEME_HEBDO* ProblemeHebdo) -{ - const auto ntcToZeroStatus = getNTCStatus(ProblemeHebdo, Interco); - switch (ntcToZeroStatus) - { - case setToZero: - { - Xmax = 0.; - Xmin = 0.; - break; - } - case setOrigineExtremityToZero: - { - Xmax = 0.; - Xmin = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]); - break; - } - case setExtremityOriginToZero: - { - Xmax = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco]; - Xmin = 0.; - break; - } - default: - { - setBoundsNoAdqPatch(Xmax, Xmin, ValeursDeNTC, Interco); - break; - } - } -} - -void setBoundsNoAdqPatch(double& Xmax, - double& Xmin, - VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeNTC, - const int Interco) -{ - Xmax = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco]; - Xmin = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]); -} -} // namespace Antares::Data::AdequacyPatch diff --git a/src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.cpp b/src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.cpp new file mode 100644 index 0000000000..5bbd557fdf --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.cpp @@ -0,0 +1,221 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "adq_patch_curtailment_sharing.h" +#include "../opt_fonctions.h" +#include "csr_quadratic_problem.h" +#include "count_constraints_variables.h" + +#include +#include "../study/area/scratchpad.h" + +using namespace Yuni; + +namespace Antares::Data::AdequacyPatch +{ +double LmrViolationAreaHour(const PROBLEME_HEBDO* problemeHebdo, + double totalNodeBalance, + int Area, + int hour) +{ + double ensInit + = problemeHebdo->ResultatsHoraires[Area]->ValeursHorairesDeDefaillancePositive[hour]; + double threshold = problemeHebdo->adqPatchParams->ThresholdDisplayLocalMatchingRuleViolations; + + problemeHebdo->ResultatsHoraires[Area]->ValeursHorairesLmrViolations[hour] = 0; + // check LMR violations + if ((ensInit > 0.0) && (totalNodeBalance < 0.0) + && (std::fabs(totalNodeBalance) > ensInit + std::fabs(threshold))) + { + problemeHebdo->ResultatsHoraires[Area]->ValeursHorairesLmrViolations[hour] = 1; + return std::fabs(totalNodeBalance); + } + return 0.0; +} + +std::tuple calculateAreaFlowBalance(PROBLEME_HEBDO* problemeHebdo, + int Area, + int hour) +{ + double netPositionInit = 0; + double flowsNode1toNodeA = 0; + double densNew; + bool includeFlowsOutsideAdqPatchToDensNew + = !problemeHebdo->adqPatchParams->SetNTCOutsideToInsideToZero; + + int Interco = problemeHebdo->IndexDebutIntercoOrigine[Area]; + while (Interco >= 0) + { + if (problemeHebdo->adequacyPatchRuntimeData.extremityAreaMode[Interco] + == physicalAreaInsideAdqPatch) + { + netPositionInit -= problemeHebdo->ValeursDeNTC[hour]->ValeurDuFlux[Interco]; + } + else if (problemeHebdo->adequacyPatchRuntimeData.extremityAreaMode[Interco] + == physicalAreaOutsideAdqPatch) + { + flowsNode1toNodeA + -= std::min(0.0, problemeHebdo->ValeursDeNTC[hour]->ValeurDuFlux[Interco]); + } + Interco = problemeHebdo->IndexSuivantIntercoOrigine[Interco]; + } + Interco = problemeHebdo->IndexDebutIntercoExtremite[Area]; + while (Interco >= 0) + { + if (problemeHebdo->adequacyPatchRuntimeData.originAreaMode[Interco] + == physicalAreaInsideAdqPatch) + { + netPositionInit += problemeHebdo->ValeursDeNTC[hour]->ValeurDuFlux[Interco]; + } + else if (problemeHebdo->adequacyPatchRuntimeData.originAreaMode[Interco] + == physicalAreaOutsideAdqPatch) + { + flowsNode1toNodeA + += std::max(0.0, problemeHebdo->ValeursDeNTC[hour]->ValeurDuFlux[Interco]); + } + Interco = problemeHebdo->IndexSuivantIntercoExtremite[Interco]; + } + + double ensInit + = problemeHebdo->ResultatsHoraires[Area]->ValeursHorairesDeDefaillancePositive[hour]; + if (includeFlowsOutsideAdqPatchToDensNew) + { + densNew = std::max(0.0, ensInit + netPositionInit + flowsNode1toNodeA); + return std::make_tuple(netPositionInit, densNew, netPositionInit + flowsNode1toNodeA); + } + else + { + densNew = std::max(0.0, ensInit + netPositionInit); + return std::make_tuple(netPositionInit, densNew, netPositionInit); + } +} + +} // namespace Antares::Data::AdequacyPatch + +void HourlyCSRProblem::calculateCsrParameters() +{ + double netPositionInit; + int hour = triggeredHour; + + for (int Area = 0; Area < problemeHebdo_->NombreDePays; Area++) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[Area] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + // set DTG MRG CSR in all areas inside adq-path for all CSR triggered hours to -1.0 + problemeHebdo_->ResultatsHoraires[Area]->ValeursHorairesDtgMrgCsr[hour] = -1.0; + // calculate netPositionInit and the RHS of the AreaBalance constraints + std::tie(netPositionInit, std::ignore, std::ignore) + = Antares::Data::AdequacyPatch::calculateAreaFlowBalance(problemeHebdo_, Area, hour); + + double ensInit + = problemeHebdo_->ResultatsHoraires[Area]->ValeursHorairesDeDefaillancePositive[hour]; + double spillageInit + = problemeHebdo_->ResultatsHoraires[Area]->ValeursHorairesDeDefaillanceNegative[hour]; + + rhsAreaBalanceValues[Area] = ensInit + netPositionInit - spillageInit; + } + } +} + +void HourlyCSRProblem::resetProblem() +{ + OPT_FreeOptimizationData(&problemeAResoudre_); +} + +void HourlyCSRProblem::allocateProblem() +{ + using namespace Antares::Data::AdequacyPatch; + int nbConst; + + problemeAResoudre_.NombreDeVariables = countVariables(problemeHebdo_); + nbConst = problemeAResoudre_.NombreDeContraintes = countConstraints(problemeHebdo_); + int nbTerms + = 3 * nbConst; // This is a rough estimate, reallocations may happen later if it's too low + OPT_AllocateFromNumberOfVariableConstraints(&problemeAResoudre_, nbTerms); +} + +void HourlyCSRProblem::buildProblemVariables() +{ + logs.debug() << "[CSR] variable list:"; + + constructVariableENS(); + constructVariableSpilledEnergy(); + constructVariableFlows(); +} + +void HourlyCSRProblem::buildProblemConstraintsLHS() +{ + Antares::Solver::Optimization::CsrQuadraticProblem csrProb(problemeHebdo_, problemeAResoudre_, *this); + csrProb.buildConstraintMatrix(); +} + +void HourlyCSRProblem::setVariableBounds() +{ + for (int var = 0; var < problemeAResoudre_.NombreDeVariables; var++) + problemeAResoudre_.AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = nullptr; + + logs.debug() << "[CSR] bounds"; + setBoundsOnENS(); + setBoundsOnSpilledEnergy(); + setBoundsOnFlows(); +} + +void HourlyCSRProblem::buildProblemConstraintsRHS() +{ + logs.debug() << "[CSR] RHS: "; + setRHSvalueOnFlows(); + setRHSnodeBalanceValue(); + setRHSbindingConstraintsValue(); +} + +void HourlyCSRProblem::setProblemCost() +{ + logs.debug() << "[CSR] cost"; + std::fill_n(problemeAResoudre_.CoutLineaire, problemeAResoudre_.NombreDeVariables, 0.); + std::fill_n(problemeAResoudre_.CoutQuadratique, problemeAResoudre_.NombreDeVariables, 0.); + + setQuadraticCost(); + if (problemeHebdo_->adqPatchParams->IncludeHurdleCostCsr) + setLinearCost(); +} + +void HourlyCSRProblem::solveProblem(uint week, int year) +{ + ADQ_PATCH_CSR(problemeAResoudre_, *this, week, year); +} + +void HourlyCSRProblem::run(uint week, uint year) +{ + calculateCsrParameters(); + buildProblemVariables(); + buildProblemConstraintsLHS(); + setVariableBounds(); + buildProblemConstraintsRHS(); + setProblemCost(); + solveProblem(week, year); +} diff --git a/src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.h b/src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.h new file mode 100644 index 0000000000..7e32a30502 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.h @@ -0,0 +1,68 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#pragma once + +#include "../simulation/sim_structure_probleme_economique.h" + +namespace Antares::Data::AdequacyPatch +{ +//! A default threshold value for initiate curtailment sharing rule +const double defaultThresholdToRunCurtailmentSharing = 0.0; +//! A default threshold value for display local matching rule violations +const double defaultThresholdDisplayLocalMatchingRuleViolations = 0.0; +//! CSR variables relaxation threshold +const int defaultValueThresholdVarBoundsRelaxation = 3; + + +/*! + * Calculates curtailment sharing rule parameters netPositionInit, densNew and totalNodeBalance per + * given area and hour. + */ +std::tuple calculateAreaFlowBalance(PROBLEME_HEBDO* problemeHebdo, + int Area, + int hour); + +/*! + * Calculate total local matching rule violation per one area, per one hour. + */ +double LmrViolationAreaHour(const PROBLEME_HEBDO* problemeHebdo, + double totalNodeBalance, + int Area, + int hour); + +/*! + * Calculate densNew values for all hours and areas inside adequacy patch and places them into + * problemeHebdo->ResultatsHoraires[Area]->ValeursHorairesDENS[hour] to be displayed in output. + * copy-pastes spilled Energy values into spilled Energy values after CSR + * calculates total LMR violations and LMR violations per area per hour inside + * problemeHebdo->ResultatsHoraires[Area]->ValeursHorairesLmrViolations[hour] + */ +double calculateDensNewAndTotalLmrViolation(PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + uint numSpace); +} // namespace Antares::Data::AdequacyPatch diff --git a/src/solver/optimisation/adequacy_patch_csr/construct_problem_constraints_RHS.cpp b/src/solver/optimisation/adequacy_patch_csr/construct_problem_constraints_RHS.cpp new file mode 100644 index 0000000000..492978e580 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/construct_problem_constraints_RHS.cpp @@ -0,0 +1,154 @@ +/* +** Copyright 2007-2022 RTE +** Authors: RTE-international / Redstork / Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "../solver/optimisation/opt_structure_probleme_a_resoudre.h" +#include "../solver/simulation/simulation.h" +#include "../hourly_csr_problem.h" + +void HourlyCSRProblem::setRHSvalueOnFlows() +{ + // constraint: Flow = Flow_direct - Flow_indirect (+ loop flow) for links between nodes of + // type 2. + for (int Interco = 0; Interco < problemeHebdo_->NombreDInterconnexions; Interco++) + { + if (problemeHebdo_->adequacyPatchRuntimeData.originAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch + && problemeHebdo_->adequacyPatchRuntimeData.extremityAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + std::map::iterator it = numberOfConstraintCsrFlowDissociation.find(Interco); + if (it != numberOfConstraintCsrFlowDissociation.end()) + { + int Cnt = it->second; + problemeAResoudre_.SecondMembre[Cnt] = 0.; + logs.debug() << Cnt << "Flow=D-I: RHS[" << Cnt + << "] = " << problemeAResoudre_.SecondMembre[Cnt]; + } + } + } +} + +void HourlyCSRProblem::setRHSnodeBalanceValue() +{ + // constraint: + // ENS(node A) + + // [ Sum flow_direct(node 2 upstream -> node A) + Sum flow_indirect(node A <- node 2 downstream) + // – Sum flow_indirect(node 2 upstream <- node A) – Sum flow_direct(node A -> node 2 downstream) + // ] – spillage(node A) = ENS_init(node A) + net_position_init(node A) – spillage_init(node A) + // for all areas inside adequacy patch + + for (int Area = 0; Area < problemeHebdo_->NombreDePays; Area++) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[Area] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + std::map::iterator it = numberOfConstraintCsrAreaBalance.find(Area); + if (it != numberOfConstraintCsrAreaBalance.end()) + { + int Cnt = it->second; + problemeAResoudre_.SecondMembre[Cnt] = rhsAreaBalanceValues[Area]; + logs.debug() << Cnt << ": Area Balance: RHS[" << Cnt + << "] = " << problemeAResoudre_.SecondMembre[Cnt] + << " (Area = " << Area << ")"; + } + } + } +} + +void HourlyCSRProblem::setRHSbindingConstraintsValue() +{ + double csrSolverRelaxationRHS = problemeHebdo_->adqPatchParams->ThresholdCSRVarBoundsRelaxation; + double* SecondMembre = problemeAResoudre_.SecondMembre; + + // constraint: + // user defined Binding constraints between transmission flows + // and/or power generated from generating units. + for (int CntCouplante = 0; CntCouplante < problemeHebdo_->NombreDeContraintesCouplantes; + CntCouplante++) + { + if (numberOfConstraintCsrHourlyBinding.find(CntCouplante) + == numberOfConstraintCsrHourlyBinding.end()) + continue; + + const CONTRAINTES_COUPLANTES* MatriceDesContraintesCouplantes + = problemeHebdo_->MatriceDesContraintesCouplantes[CntCouplante]; + + int Cnt = numberOfConstraintCsrHourlyBinding[CntCouplante]; + + // 1. The original RHS of bingding constraint + SecondMembre[Cnt] = MatriceDesContraintesCouplantes + ->SecondMembreDeLaContrainteCouplante[triggeredHour]; + + // 2. RHS part 2: flow other than 2<->2 + int NbInterco + = MatriceDesContraintesCouplantes->NombreDInterconnexionsDansLaContrainteCouplante; + for (int Index = 0; Index < NbInterco; Index++) + { + int Interco = MatriceDesContraintesCouplantes->NumeroDeLInterconnexion[Index]; + double Poids = MatriceDesContraintesCouplantes->PoidsDeLInterconnexion[Index]; + + if (problemeHebdo_->adequacyPatchRuntimeData.originAreaMode[Interco] + != Data::AdequacyPatch::physicalAreaInsideAdqPatch + || problemeHebdo_->adequacyPatchRuntimeData.extremityAreaMode[Interco] + != Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + double ValueOfFlow + = problemeHebdo_->ValeursDeNTC[triggeredHour]->ValeurDuFlux[Interco]; + SecondMembre[Cnt] -= ValueOfFlow * Poids; + } + } + + // 3. RHS part 3: - cluster + int NbClusters + = MatriceDesContraintesCouplantes->NombreDePaliersDispatchDansLaContrainteCouplante; + + for (int Index = 0; Index < NbClusters; Index++) + { + int Area = MatriceDesContraintesCouplantes->PaysDuPalierDispatch[Index]; + + int IndexNumeroDuPalierDispatch + = MatriceDesContraintesCouplantes->NumeroDuPalierDispatch[Index]; + + double Poids = MatriceDesContraintesCouplantes->PoidsDuPalierDispatch[Index]; + + double ValueOfVar = problemeHebdo_->ResultatsHoraires[Area] + ->ProductionThermique[triggeredHour] + ->ProductionThermiqueDuPalier[IndexNumeroDuPalierDispatch]; + + SecondMembre[Cnt] -= ValueOfVar * Poids; + } + if (MatriceDesContraintesCouplantes->SensDeLaContrainteCouplante == '<') + { + SecondMembre[Cnt] += csrSolverRelaxationRHS; + } + else if (MatriceDesContraintesCouplantes->SensDeLaContrainteCouplante == '>') + { + SecondMembre[Cnt] -= csrSolverRelaxationRHS; + } + logs.debug() << Cnt << ": Hourly bc: -RHS[" << Cnt << "] = " << SecondMembre[Cnt]; + } +} diff --git a/src/solver/optimisation/adequacy_patch_csr/construct_problem_variables.cpp b/src/solver/optimisation/adequacy_patch_csr/construct_problem_variables.cpp new file mode 100644 index 0000000000..fa379e6cf2 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/construct_problem_variables.cpp @@ -0,0 +1,139 @@ +/* +** Copyright 2007-2022 RTE +** Authors: RTE-international / Redstork / Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "../solver/optimisation/opt_structure_probleme_a_resoudre.h" +#include "../solver/simulation/simulation.h" +#include "../solver/simulation/sim_structure_donnees.h" +#include "../hourly_csr_problem.h" + +#include "pi_constantes_externes.h" +void HourlyCSRProblem::constructVariableENS() +{ + int& NumberOfVariables = problemeAResoudre_.NombreDeVariables; + NumberOfVariables = 0; + auto CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[triggeredHour]; + + // variables: ENS of each area inside adq patch + logs.debug() << " ENS of each area inside adq patch: "; + for (int area = 0; area < problemeHebdo_->NombreDePays; ++area) + { + // Only ENS for areas inside adq patch are considered as variables + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[area] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[area] + = NumberOfVariables; + problemeAResoudre_.TypeDeVariable[NumberOfVariables] = VARIABLE_BORNEE_DES_DEUX_COTES; + varToBeSetToZeroIfBelowThreshold.insert(NumberOfVariables); + ensVariablesInsideAdqPatch.insert(NumberOfVariables); + logs.debug() << NumberOfVariables << " ENS[" << area << "].-[" + << problemeHebdo_->NomsDesPays[area] << "]."; + + NumberOfVariables++; + } + } +} + +void HourlyCSRProblem::constructVariableSpilledEnergy() +{ + auto CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[triggeredHour]; + int& NumberOfVariables = problemeAResoudre_.NombreDeVariables; + + // variables: Spilled Energy of each area inside adq patch + logs.debug() << " Spilled Energy of each area inside adq patch: "; + for (int area = 0; area < problemeHebdo_->NombreDePays; ++area) + { + // Only Spilled Energy for areas inside adq patch are considered as variables + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[area] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[area] + = NumberOfVariables; + problemeAResoudre_.TypeDeVariable[NumberOfVariables] = VARIABLE_BORNEE_INFERIEUREMENT; + varToBeSetToZeroIfBelowThreshold.insert(NumberOfVariables); + logs.debug() << NumberOfVariables << " Spilled Energy[" << area << "].-[" + << problemeHebdo_->NomsDesPays[area] << "]."; + + NumberOfVariables++; + } + } +} + +void HourlyCSRProblem::constructVariableFlows() +{ + auto CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[triggeredHour]; + int& NumberOfVariables = problemeAResoudre_.NombreDeVariables; + + // variables: transmissin flows (flow, direct_direct and flow_indirect). For links between 2 + // and 2. + logs.debug() + << " transmissin flows (flow, flow_direct and flow_indirect). For links between 2 and 2:"; + for (int Interco = 0; Interco < problemeHebdo_->NombreDInterconnexions; Interco++) + { + // only consider link between 2 and 2 + if (problemeHebdo_->adequacyPatchRuntimeData.originAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch + && problemeHebdo_->adequacyPatchRuntimeData.extremityAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + int algebraicFluxVar; + int directVar; + int indirectVar; + algebraicFluxVar + = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco] + = NumberOfVariables; + problemeAResoudre_.TypeDeVariable[NumberOfVariables] = VARIABLE_BORNEE_DES_DEUX_COTES; + logs.debug() + << NumberOfVariables << " flow[" << Interco << "]. [" + << problemeHebdo_ + ->NomsDesPays[problemeHebdo_->PaysExtremiteDeLInterconnexion[Interco]] + << "]-[" + << problemeHebdo_->NomsDesPays[problemeHebdo_->PaysOrigineDeLInterconnexion[Interco]] + << "]."; + NumberOfVariables++; + + directVar = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[Interco] + = NumberOfVariables; + problemeAResoudre_.TypeDeVariable[NumberOfVariables] = VARIABLE_BORNEE_DES_DEUX_COTES; + logs.debug() << NumberOfVariables << " direct flow[" << Interco << "]. "; + NumberOfVariables++; + + indirectVar = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[Interco] + = NumberOfVariables; + problemeAResoudre_.TypeDeVariable[NumberOfVariables] = VARIABLE_BORNEE_DES_DEUX_COTES; + logs.debug() << NumberOfVariables << " indirect flow[" << Interco << "]. "; + NumberOfVariables++; + + linkInsideAdqPatch[algebraicFluxVar] = LinkVariable(directVar, indirectVar); + } + } +} diff --git a/src/solver/optimisation/adequacy_patch_csr/count_constraints_variables.cpp b/src/solver/optimisation/adequacy_patch_csr/count_constraints_variables.cpp new file mode 100644 index 0000000000..8e814c521c --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/count_constraints_variables.cpp @@ -0,0 +1,94 @@ +/* +** Copyright 2007-2022 RTE +** Authors: RTE-international / Redstork / Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "count_constraints_variables.h" + +namespace Antares::Data::AdequacyPatch +{ +int countConstraints(const PROBLEME_HEBDO* problemeHebdo) +{ + int numberOfConstraints = 0; + // constraint: Flow = Flow_direct - Flow_indirect (+ loop flow) for links between nodes of + // type 2. + for (int Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) + { + if (problemeHebdo->adequacyPatchRuntimeData.originAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch + && problemeHebdo->adequacyPatchRuntimeData.extremityAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) + numberOfConstraints++; + } + + // constraint: + // ENS(node A) + + // - flow (A -> 2) or (+ flow (2 -> A)) there should be only one of them, otherwise double-count + // - spillage(node A) = + // ENS_init(node A) + net_position_init(node A) – spillage_init(node A) + // for all areas inside adequacy patch + for (int Area = 0; Area < problemeHebdo->NombreDePays; ++Area) + { + if (problemeHebdo->adequacyPatchRuntimeData.areaMode[Area] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + numberOfConstraints++; + } + // Special case of the hourly binding constraints + const auto MatrixBindingConstraints = problemeHebdo->MatriceDesContraintesCouplantes; + for (int CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; + CntCouplante++) + { + if (MatrixBindingConstraints[CntCouplante]->TypeDeContrainteCouplante == CONTRAINTE_HORAIRE) + numberOfConstraints++; + } + return numberOfConstraints; +} + +int countVariables(const PROBLEME_HEBDO* problemeHebdo) +{ + int numberOfVariables = 0; + // variables: ENS of each area inside adq patch + for (int area = 0; area < problemeHebdo->NombreDePays; ++area) + { + // Only ENS for areas inside adq patch are considered as variables + if (problemeHebdo->adequacyPatchRuntimeData.areaMode[area] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + numberOfVariables += 2; // ENS, spilled energy + } + + for (int Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) + { + // only consider link between 2 and 2 + if (problemeHebdo->adequacyPatchRuntimeData.originAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch + && problemeHebdo->adequacyPatchRuntimeData.extremityAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + numberOfVariables += 3; // algebraic flow, direct flow, indirect flow + } + } + return numberOfVariables; +} +} // namespace Antares::Data::AdequacyPatch diff --git a/src/solver/optimisation/adequacy_patch_csr/count_constraints_variables.h b/src/solver/optimisation/adequacy_patch_csr/count_constraints_variables.h new file mode 100644 index 0000000000..4d82c4a09a --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/count_constraints_variables.h @@ -0,0 +1,36 @@ +/* +** Copyright 2007-2022 RTE +** Authors: RTE-international / Redstork / Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#pragma once + +#include "../../simulation/sim_structure_probleme_economique.h" + +namespace Antares::Data::AdequacyPatch +{ +int countConstraints(const PROBLEME_HEBDO* problemeHebdo); +int countVariables(const PROBLEME_HEBDO* problemeHebdo); +} // namespace Antares::Data::AdequacyPatch diff --git a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp new file mode 100644 index 0000000000..6da54ffbc4 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.cpp @@ -0,0 +1,278 @@ +/* +** Copyright 2007-2022 RTE +** Authors: RTE-international / Redstork / Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include +#include "../solver/optimisation/opt_structure_probleme_a_resoudre.h" + +#include "../solver/simulation/simulation.h" +#include "../solver/simulation/sim_structure_donnees.h" +#include "../solver/optimisation/opt_fonctions.h" +#include "csr_quadratic_problem.h" +#include "../hourly_csr_problem.h" + +using namespace Antares::Data; + +namespace Antares::Solver::Optimization +{ + +void CsrQuadraticProblem::setConstraintsOnFlows(double* Pi, int* Colonne) +{ + int hour = hourlyCsrProblem_.triggeredHour; + const CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[hour]; + + // constraint: Flow = Flow_direct - Flow_indirect (+ loop flow) for links between nodes of + // type 2. + for (int Interco = 0; Interco < problemeHebdo_->NombreDInterconnexions; Interco++) + { + if (problemeHebdo_->adequacyPatchRuntimeData.originAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch + && problemeHebdo_->adequacyPatchRuntimeData.extremityAreaMode[Interco] + == Antares::Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + int NombreDeTermes = 0; + int var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + if (var >= 0) + { + Pi[NombreDeTermes] = 1.0; + Colonne[NombreDeTermes] = var; + NombreDeTermes++; + } + var = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[Interco]; + if (var >= 0) + { + Pi[NombreDeTermes] = -1.0; + Colonne[NombreDeTermes] = var; + NombreDeTermes++; + } + var = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[Interco]; + if (var >= 0) + { + Pi[NombreDeTermes] = 1.0; + Colonne[NombreDeTermes] = var; + NombreDeTermes++; + } + + hourlyCsrProblem_.numberOfConstraintCsrFlowDissociation[Interco] + = problemeAResoudre_.NombreDeContraintes; + + std::string NomDeLaContrainte = "flow=d-i, Interco:" + std::to_string(Interco); + logs.debug() << "C Interco: " << problemeAResoudre_.NombreDeContraintes << ": " + << NomDeLaContrainte; + + OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + &problemeAResoudre_, Pi, Colonne, NombreDeTermes, '='); + } + } +} + +void CsrQuadraticProblem::setNodeBalanceConstraints(double* Pi, int* Colonne) +{ + int hour = hourlyCsrProblem_.triggeredHour; + const CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[hour]; + + // constraint: + // ENS(node A) + + // - flow (A -> 2) or (+ flow (2 -> A)) there should be only one of them, otherwise double-count + // - spillage(node A) = + // ENS_init(node A) + net_position_init(node A) – spillage_init(node A) + // for all areas inside adequacy patch + + for (int Area = 0; Area < problemeHebdo_->NombreDePays; ++Area) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[Area] + != Data::AdequacyPatch::physicalAreaInsideAdqPatch) + continue; + + // + ENS + int NombreDeTermes = 0; + int var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[Area]; + if (var >= 0) + { + Pi[NombreDeTermes] = 1.0; + Colonne[NombreDeTermes] = var; + NombreDeTermes++; + } + + // - export flows + int Interco = problemeHebdo_->IndexDebutIntercoOrigine[Area]; + while (Interco >= 0) + { + if (problemeHebdo_->adequacyPatchRuntimeData.extremityAreaMode[Interco] + != Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + Interco = problemeHebdo_->IndexSuivantIntercoOrigine[Interco]; + continue; + } + + var = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableDeLInterconnexion[Interco]; // flow (A->2) + if (var >= 0) + { + Pi[NombreDeTermes] = -1.0; + Colonne[NombreDeTermes] = var; + NombreDeTermes++; + logs.debug() + << "S-Interco number: [" << std::to_string(Interco) << "] between: [" + << problemeHebdo_->NomsDesPays[Area] << "]-[" + << problemeHebdo_ + ->NomsDesPays[problemeHebdo_->PaysExtremiteDeLInterconnexion[Interco]] + << "]"; + } + Interco = problemeHebdo_->IndexSuivantIntercoOrigine[Interco]; + } + + // or + import flows + Interco = problemeHebdo_->IndexDebutIntercoExtremite[Area]; + while (Interco >= 0) + { + if (problemeHebdo_->adequacyPatchRuntimeData.originAreaMode[Interco] + != Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + Interco = problemeHebdo_->IndexSuivantIntercoExtremite[Interco]; + continue; + } + var = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableDeLInterconnexion[Interco]; // flow (2 -> A) + if (var >= 0) + { + Pi[NombreDeTermes] = 1.0; + Colonne[NombreDeTermes] = var; + NombreDeTermes++; + logs.debug() + << "E-Interco number: [" << std::to_string(Interco) << "] between: [" + << problemeHebdo_->NomsDesPays[Area] << "]-[" + << problemeHebdo_ + ->NomsDesPays[problemeHebdo_->PaysOrigineDeLInterconnexion[Interco]] + << "]"; + } + Interco = problemeHebdo_->IndexSuivantIntercoExtremite[Interco]; + } + + // - Spilled Energy + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[Area]; + if (var >= 0) + { + Pi[NombreDeTermes] = -1.0; + Colonne[NombreDeTermes] = var; + NombreDeTermes++; + } + + hourlyCsrProblem_.numberOfConstraintCsrAreaBalance[Area] + = problemeAResoudre_.NombreDeContraintes; + + std::string NomDeLaContrainte + = "Area Balance, Area:" + std::to_string(Area) + "; " + problemeHebdo_->NomsDesPays[Area]; + + logs.debug() << "C: " << problemeAResoudre_.NombreDeContraintes << ": " + << NomDeLaContrainte; + + OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + &problemeAResoudre_, Pi, Colonne, NombreDeTermes, '='); + } +} + +void CsrQuadraticProblem::setBindingConstraints(double* Pi, int* Colonne) +{ + int hour = hourlyCsrProblem_.triggeredHour; + + // Special case of the binding constraints + for (int CntCouplante = 0; CntCouplante < problemeHebdo_->NombreDeContraintesCouplantes; + CntCouplante++) + { + const CONTRAINTES_COUPLANTES* MatriceDesContraintesCouplantes + = problemeHebdo_->MatriceDesContraintesCouplantes[CntCouplante]; + + if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante != CONTRAINTE_HORAIRE) + continue; + + int NbInterco + = MatriceDesContraintesCouplantes->NombreDInterconnexionsDansLaContrainteCouplante; + int NombreDeTermes = 0; + for (int Index = 0; Index < NbInterco; Index++) + { + int Interco = MatriceDesContraintesCouplantes->NumeroDeLInterconnexion[Index]; + double Poids = MatriceDesContraintesCouplantes->PoidsDeLInterconnexion[Index]; + + if (problemeHebdo_->adequacyPatchRuntimeData.originAreaMode[Interco] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch + && problemeHebdo_->adequacyPatchRuntimeData.extremityAreaMode[Interco] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + int var = problemeHebdo_->CorrespondanceVarNativesVarOptim[hour] + ->NumeroDeVariableDeLInterconnexion[Interco]; + + if (var >= 0) + { + Pi[NombreDeTermes] = Poids; + Colonne[NombreDeTermes] = var; + NombreDeTermes++; + } + } + } + + if (NombreDeTermes > 0) // current binding constraint contains an interco type 2<->2 + { + hourlyCsrProblem_.numberOfConstraintCsrHourlyBinding[CntCouplante] + = problemeAResoudre_.NombreDeContraintes; + + std::string NomDeLaContrainte + = "bc::hourly::" + std::to_string(hour) + + "::" + MatriceDesContraintesCouplantes->NomDeLaContrainteCouplante; + + logs.debug() << "C (bc): " << problemeAResoudre_.NombreDeContraintes << ": " + << NomDeLaContrainte; + + OPT_ChargerLaContrainteDansLaMatriceDesContraintes( + &problemeAResoudre_, + Pi, + Colonne, + NombreDeTermes, + MatriceDesContraintesCouplantes->SensDeLaContrainteCouplante); + } + } +} + +void CsrQuadraticProblem::buildConstraintMatrix() +{ + logs.debug() << "[CSR] constraint list:"; + + std::vector Pi(problemeAResoudre_.NombreDeVariables); + std::vector Colonne(problemeAResoudre_.NombreDeVariables); + + problemeAResoudre_.NombreDeContraintes = 0; + problemeAResoudre_.NombreDeTermesDansLaMatriceDesContraintes = 0; + + setConstraintsOnFlows(Pi.data(), Colonne.data()); + setNodeBalanceConstraints(Pi.data(), Colonne.data()); + setBindingConstraints(Pi.data(), Colonne.data()); +} + +} //namespace Antares::Solver::Optimization diff --git a/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.h b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.h new file mode 100644 index 0000000000..baa9764267 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/csr_quadratic_problem.h @@ -0,0 +1,55 @@ +/* +** Copyright 2007-2023 RTE +** Authors: RTE-international / Redstork / Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#pragma once + +class HourlyCSRProblem; + +namespace Antares::Solver::Optimization +{ + +class CsrQuadraticProblem +{ +public: + CsrQuadraticProblem(const PROBLEME_HEBDO* p, PROBLEME_ANTARES_A_RESOUDRE& pa, HourlyCSRProblem& hourly) : + problemeHebdo_(p), problemeAResoudre_(pa), hourlyCsrProblem_(hourly) + { + } + + void buildConstraintMatrix(); + +private: + const PROBLEME_HEBDO* problemeHebdo_; + PROBLEME_ANTARES_A_RESOUDRE& problemeAResoudre_; + HourlyCSRProblem& hourlyCsrProblem_; + + void setConstraintsOnFlows(double* Pi, int* Colonne); + void setNodeBalanceConstraints(double* Pi, int* Colonne); + void setBindingConstraints(double* Pi, int* Colonne); +}; + +} //namespace Antares::Solver::Optimization diff --git a/src/solver/optimisation/adequacy_patch_csr/set_problem_cost_function.cpp b/src/solver/optimisation/adequacy_patch_csr/set_problem_cost_function.cpp new file mode 100644 index 0000000000..71debace93 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/set_problem_cost_function.cpp @@ -0,0 +1,150 @@ +/* +** Copyright 2007-2022 RTE +** Authors: RTE-international / Redstork / Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include + +#include "../solver/optimisation/opt_structure_probleme_a_resoudre.h" + +#include "../solver/simulation/simulation.h" +#include "../solver/simulation/sim_structure_donnees.h" +#include "../solver/simulation/sim_extern_variables_globales.h" + +#include "../solver/optimisation/opt_fonctions.h" + +namespace +{ +double calculateQuadraticCost(const PROBLEME_HEBDO* problemeHebdo, int hour, int area) +{ + double priceTakingOrders = 0.0; // PTO + if (problemeHebdo->adqPatchParams->PriceTakingOrder == Data::AdequacyPatch::AdqPatchPTO::isLoad) + { + priceTakingOrders + = problemeHebdo->ConsommationsAbattues[hour]->ConsommationAbattueDuPays[area] + + problemeHebdo->AllMustRunGeneration[hour]->AllMustRunGenerationOfArea[area]; + } + else if (problemeHebdo->adqPatchParams->PriceTakingOrder + == Data::AdequacyPatch::AdqPatchPTO::isDens) + { + priceTakingOrders = problemeHebdo->ResultatsHoraires[area]->ValeursHorairesDENS[hour]; + } + + if (priceTakingOrders <= 0.0) + return 0.0; + else + return (1. / priceTakingOrders); +} +} // namespace + +void HourlyCSRProblem::setQuadraticCost() +{ + const CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; + CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[triggeredHour]; + + // variables: ENS for each area inside adq patch + // obj function term is: 1 / (PTO) * ENS * ENS + // => quadratic cost: 1 / (PTO) + // => linear cost: 0 + // PTO can take two different values according to option: + // 1. from DENS + // 2. from load + for (int area = 0; area < problemeHebdo_->NombreDePays; ++area) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[area] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + int var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[area]; + if (var >= 0 && var < problemeAResoudre_.NombreDeVariables) + { + problemeAResoudre_.CoutQuadratique[var] + = calculateQuadraticCost(problemeHebdo_, triggeredHour, area); + logs.debug() << var << ". Quad C = " << problemeAResoudre_.CoutQuadratique[var]; + } + } + } +} + +void HourlyCSRProblem::setLinearCost() +{ + int var; + const COUTS_DE_TRANSPORT* TransportCost; + const CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; + CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[triggeredHour]; + + // variables: transmission cost for links between nodes of type 2 (area inside adequacy patch) + // obj function term is: Sum ( hurdle_cost_direct x flow_direct )+ Sum ( hurdle_cost_indirect x + // flow_indirect ) + // => quadratic cost: 0 + // => linear cost: hurdle_cost_direct or hurdle_cost_indirect + // these members of objective functions are considered only if IntercoGereeAvecDesCouts = + // OUI_ANTARES (use hurdle cost option is true). otherwise these members are zero. + + for (int Interco = 0; Interco < problemeHebdo_->NombreDInterconnexions; Interco++) + { + if (problemeHebdo_->adequacyPatchRuntimeData.originAreaMode[Interco] + != Data::AdequacyPatch::physicalAreaInsideAdqPatch + || problemeHebdo_->adequacyPatchRuntimeData.extremityAreaMode[Interco] + != Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + continue; + } + + TransportCost = problemeHebdo_->CoutDeTransport[Interco]; + // flow + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + if (var >= 0 && var < problemeAResoudre_.NombreDeVariables) + { + problemeAResoudre_.CoutLineaire[var] = 0.0; + logs.debug() << var << ". Linear C = " << problemeAResoudre_.CoutLineaire[var]; + } + // direct / indirect flow + var = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[Interco]; + if (var >= 0 && var < problemeAResoudre_.NombreDeVariables) + { + if (TransportCost->IntercoGereeAvecDesCouts == NON_ANTARES) + problemeAResoudre_.CoutLineaire[var] = 0; + else + problemeAResoudre_.CoutLineaire[var] + = TransportCost->CoutDeTransportOrigineVersExtremite[triggeredHour]; + logs.debug() << var << ". Linear C = " << problemeAResoudre_.CoutLineaire[var]; + } + + var = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[Interco]; + if (var >= 0 && var < problemeAResoudre_.NombreDeVariables) + { + if (TransportCost->IntercoGereeAvecDesCouts == NON_ANTARES) + problemeAResoudre_.CoutLineaire[var] = 0; + else + problemeAResoudre_.CoutLineaire[var] + = TransportCost->CoutDeTransportExtremiteVersOrigine[triggeredHour]; + logs.debug() << var << ". Linear C = " << problemeAResoudre_.CoutLineaire[var]; + } + } +} diff --git a/src/solver/optimisation/adequacy_patch_csr/set_variable_boundaries.cpp b/src/solver/optimisation/adequacy_patch_csr/set_variable_boundaries.cpp new file mode 100644 index 0000000000..4626e052c8 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/set_variable_boundaries.cpp @@ -0,0 +1,194 @@ +/* +** Copyright 2007-2022 RTE +** Authors: RTE-international / Redstork / Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "../solver/optimisation/opt_structure_probleme_a_resoudre.h" + +#include "../solver/simulation/simulation.h" +#include "../solver/simulation/sim_structure_donnees.h" +#include "../solver/simulation/sim_extern_variables_globales.h" + +#include "../solver/optimisation/opt_fonctions.h" + +#include "pi_constantes_externes.h" + +#include +#include + +using namespace Yuni; + +void HourlyCSRProblem::setBoundsOnENS() +{ + double* AdresseDuResultat; + const CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; + CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[triggeredHour]; + double csrSolverRelaxation = problemeHebdo_->adqPatchParams->ThresholdCSRVarBoundsRelaxation; + + // variables: ENS for each area inside adq patch + for (int area = 0; area < problemeHebdo_->NombreDePays; ++area) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[area] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + int var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[area]; + + problemeAResoudre_.Xmin[var] = -csrSolverRelaxation; + problemeAResoudre_.Xmax[var] + = problemeHebdo_->ResultatsHoraires[area]->ValeursHorairesDENS[triggeredHour] + + csrSolverRelaxation; + + problemeAResoudre_.X[var] + = problemeHebdo_->ResultatsHoraires[area] + ->ValeursHorairesDeDefaillancePositive[triggeredHour]; + + AdresseDuResultat = &(problemeHebdo_->ResultatsHoraires[area] + ->ValeursHorairesDeDefaillancePositive[triggeredHour]); + + problemeAResoudre_.AdresseOuPlacerLaValeurDesVariablesOptimisees[var] + = AdresseDuResultat; + + logs.debug() << var << ": " << problemeAResoudre_.Xmin[var] << ", " + << problemeAResoudre_.Xmax[var]; + } + } +} + +void HourlyCSRProblem::setBoundsOnSpilledEnergy() +{ + const auto* CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[triggeredHour]; + double csrSolverRelaxation = problemeHebdo_->adqPatchParams->ThresholdCSRVarBoundsRelaxation; + + // variables: Spilled Energy for each area inside adq patch + for (int area = 0; area < problemeHebdo_->NombreDePays; ++area) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[area] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + int var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[area]; + + problemeAResoudre_.Xmin[var] = -csrSolverRelaxation; + problemeAResoudre_.Xmax[var] = LINFINI_ANTARES; + + problemeAResoudre_.X[var] + = problemeHebdo_->ResultatsHoraires[area] + ->ValeursHorairesDeDefaillanceNegative[triggeredHour]; + + double* AdresseDuResultat + = &(problemeHebdo_->ResultatsHoraires[area] + ->ValeursHorairesSpilledEnergyAfterCSR[triggeredHour]); + + problemeAResoudre_.AdresseOuPlacerLaValeurDesVariablesOptimisees[var] + = AdresseDuResultat; + + logs.debug() << var << ": " << problemeAResoudre_.Xmin[var] << ", " + << problemeAResoudre_.Xmax[var]; + } + } +} + +void HourlyCSRProblem::setBoundsOnFlows() +{ + double csrSolverRelaxation = problemeHebdo_->adqPatchParams->ThresholdCSRVarBoundsRelaxation; + const CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim + = problemeHebdo_->CorrespondanceVarNativesVarOptim[triggeredHour]; + double* Xmin = problemeAResoudre_.Xmin; + double* Xmax = problemeAResoudre_.Xmax; + VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeNTC + = problemeHebdo_->ValeursDeNTC[triggeredHour]; + + // variables bounds: transmissin flows (flow, direct_direct and flow_indirect). For links + // between nodes of type 2. Set hourly bounds for links between nodes of type 2, depending on + // the user input (max direct and indirect flow). + for (int Interco = 0; Interco < problemeHebdo_->NombreDInterconnexions; ++Interco) + { + // only consider link between 2 and 2 + if (problemeHebdo_->adequacyPatchRuntimeData.originAreaMode[Interco] + != Data::AdequacyPatch::physicalAreaInsideAdqPatch + || problemeHebdo_->adequacyPatchRuntimeData.extremityAreaMode[Interco] + != Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + continue; + } + + // flow + int var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + Xmax[var] = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco] + csrSolverRelaxation; + Xmin[var] = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]) - csrSolverRelaxation; + problemeAResoudre_.X[var] = ValeursDeNTC->ValeurDuFlux[Interco]; + + if (Math::Infinite(Xmax[var]) == 1) + { + if (Math::Infinite(Xmin[var]) == -1) + problemeAResoudre_.TypeDeVariable[var] = VARIABLE_NON_BORNEE; + else + problemeAResoudre_.TypeDeVariable[var] = VARIABLE_BORNEE_INFERIEUREMENT; + } + else + { + if (Math::Infinite(Xmin[var]) == -1) + problemeAResoudre_.TypeDeVariable[var] = VARIABLE_BORNEE_SUPERIEUREMENT; + else + problemeAResoudre_.TypeDeVariable[var] = VARIABLE_BORNEE_DES_DEUX_COTES; + } + + double* AdresseDuResultat = &(ValeursDeNTC->ValeurDuFlux[Interco]); + problemeAResoudre_.AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; + + logs.debug() << var << ": " << problemeAResoudre_.Xmin[var] << ", " + << problemeAResoudre_.Xmax[var]; + + // direct / indirect flow + var = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[Interco]; + + Xmin[var] = -csrSolverRelaxation; + Xmax[var] = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco] + csrSolverRelaxation; + problemeAResoudre_.TypeDeVariable[var] = VARIABLE_BORNEE_DES_DEUX_COTES; + if (Math::Infinite(Xmax[var]) == 1) + { + problemeAResoudre_.TypeDeVariable[var] = VARIABLE_BORNEE_INFERIEUREMENT; + } + + logs.debug() << var << ": " << problemeAResoudre_.Xmin[var] << ", " + << problemeAResoudre_.Xmax[var]; + + var = CorrespondanceVarNativesVarOptim + ->NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[Interco]; + + Xmin[var] = -csrSolverRelaxation; + Xmax[var] = ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco] + csrSolverRelaxation; + problemeAResoudre_.TypeDeVariable[var] = VARIABLE_BORNEE_DES_DEUX_COTES; + if (Math::Infinite(Xmax[var]) == 1) + { + problemeAResoudre_.TypeDeVariable[var] = VARIABLE_BORNEE_INFERIEUREMENT; + } + + logs.debug() << var << ": " << problemeAResoudre_.Xmin[var] << ", " + << problemeAResoudre_.Xmax[var]; + } +} diff --git a/src/solver/optimisation/adequacy_patch_csr/solve_problem.cpp b/src/solver/optimisation/adequacy_patch_csr/solve_problem.cpp new file mode 100644 index 0000000000..8584f7f04c --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_csr/solve_problem.cpp @@ -0,0 +1,278 @@ +/* +** Copyright 2007-2022 RTE +** Authors: RTE-international / Redstork / Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include + +#include "../solver/optimisation/opt_structure_probleme_a_resoudre.h" + +#include "../solver/simulation/simulation.h" +#include "../solver/simulation/sim_structure_donnees.h" +#include "../solver/simulation/sim_structure_probleme_economique.h" +#include "../solver/simulation/sim_structure_probleme_adequation.h" +#include "../solver/simulation/sim_extern_variables_globales.h" + +#include "../solver/optimisation/opt_fonctions.h" + +/* + pi_define.h doesn't include this header, yet it uses struct jmp_buf. + It would be nice to remove this include, but would require to change pi_define.h, + which isn't part of Antares +*/ +#include + +extern "C" +{ +#include "pi_define.h" +#include "pi_definition_arguments.h" +#include "pi_fonctions.h" +} + +#include + +using namespace Antares; + +std::unique_ptr buildInteriorPointProblem( + PROBLEME_ANTARES_A_RESOUDRE& ProblemeAResoudre) +{ + auto Probleme = std::make_unique(); + + Probleme->NombreMaxDIterations = -1; + Probleme->CoutQuadratique = ProblemeAResoudre.CoutQuadratique; + Probleme->CoutLineaire = ProblemeAResoudre.CoutLineaire; + Probleme->X = ProblemeAResoudre.X; + Probleme->Xmin = ProblemeAResoudre.Xmin; + Probleme->Xmax = ProblemeAResoudre.Xmax; + Probleme->NombreDeVariables = ProblemeAResoudre.NombreDeVariables; + Probleme->TypeDeVariable = ProblemeAResoudre.TypeDeVariable; + + Probleme->VariableBinaire = (char*)ProblemeAResoudre.CoutsReduits; + + Probleme->NombreDeContraintes = ProblemeAResoudre.NombreDeContraintes; + Probleme->IndicesDebutDeLigne = ProblemeAResoudre.IndicesDebutDeLigne; + Probleme->NombreDeTermesDesLignes = ProblemeAResoudre.NombreDeTermesDesLignes; + Probleme->IndicesColonnes = ProblemeAResoudre.IndicesColonnes; + Probleme->CoefficientsDeLaMatriceDesContraintes + = ProblemeAResoudre.CoefficientsDeLaMatriceDesContraintes; + Probleme->Sens = ProblemeAResoudre.Sens; + Probleme->SecondMembre = ProblemeAResoudre.SecondMembre; + + Probleme->AffichageDesTraces = NON_PI; + + Probleme->UtiliserLaToleranceDAdmissibiliteParDefaut = OUI_PI; + Probleme->UtiliserLaToleranceDeStationnariteParDefaut = OUI_PI; + Probleme->UtiliserLaToleranceDeComplementariteParDefaut = OUI_PI; + + Probleme->CoutsMarginauxDesContraintes = ProblemeAResoudre.CoutsMarginauxDesContraintes; + + Probleme->CoutsMarginauxDesContraintesDeBorneInf = ProblemeAResoudre.CoutsReduits; + Probleme->CoutsMarginauxDesContraintesDeBorneSup = ProblemeAResoudre.CoutsReduits; + + return Probleme; +} + +void setToZeroIfBelowThreshold(PROBLEME_ANTARES_A_RESOUDRE& ProblemeAResoudre, + HourlyCSRProblem& hourlyCsrProblem) +{ + for (int var = 0; var < ProblemeAResoudre.NombreDeVariables; var++) + { + bool inSet = hourlyCsrProblem.varToBeSetToZeroIfBelowThreshold.find(var) + != hourlyCsrProblem.varToBeSetToZeroIfBelowThreshold.end(); + bool belowLimit = ProblemeAResoudre.X[var] < hourlyCsrProblem.belowThisThresholdSetToZero; + if (inSet && belowLimit) + ProblemeAResoudre.X[var] = 0.0; + } +} + +void storeInteriorPointResults(const PROBLEME_ANTARES_A_RESOUDRE& ProblemeAResoudre) +{ + for (int var = 0; var < ProblemeAResoudre.NombreDeVariables; var++) + { + if (double* pt = ProblemeAResoudre.AdresseOuPlacerLaValeurDesVariablesOptimisees[var]; pt) + *pt = ProblemeAResoudre.X[var]; + + logs.debug() << "[CSR] X[" << var << "] = " << ProblemeAResoudre.X[var]; + } +} + +void storeOrDisregardInteriorPointResults(const PROBLEME_ANTARES_A_RESOUDRE& ProblemeAResoudre, + const HourlyCSRProblem& hourlyCsrProblem, + uint weekNb, + int yearNb, + double costPriorToCsr, + double costAfterCsr) +{ + const int hoursInWeek = 168; + const bool checkCost + = hourlyCsrProblem.problemeHebdo_->adqPatchParams->CheckCsrCostFunctionValue; + double deltaCost = costAfterCsr - costPriorToCsr; + + if (checkCost) + { + logs.info() << "[adq-patch] costPriorToCsr: " << costPriorToCsr + << ", costAfterCsr: " << costAfterCsr + << ", deltaCost: " << costAfterCsr - costPriorToCsr; + } + + if (!checkCost || (checkCost && deltaCost < 0.0)) + storeInteriorPointResults(ProblemeAResoudre); + else if (checkCost && deltaCost >= 0.0) + logs.warning() + << "[adq-patch] CSR optimization is providing solution with greater costs, optimum " + "solution is set as LMR . year: " + << yearNb + 1 << ". hour: " << weekNb * hoursInWeek + hourlyCsrProblem.triggeredHour + 1; +} + +double calculateCsrCostFunctionValue(const PROBLEME_POINT_INTERIEUR& Probleme, + const HourlyCSRProblem& hourlyCsrProblem) +{ + logs.debug() << "calculateCsrCostFunctionValue! "; + double cost = 0.0; + if (!hourlyCsrProblem.problemeHebdo_->adqPatchParams->CheckCsrCostFunctionValue) + { + logs.debug() << "CheckCsrCostFunctionValue = FALSE"; + return cost; + } + + for (int i = 0; i < Probleme.NombreDeVariables; i++) + { + logs.debug() << "i: " << i; + if (hourlyCsrProblem.ensVariablesInsideAdqPatch.find(i) + != hourlyCsrProblem.ensVariablesInsideAdqPatch.end()) + { + cost += Probleme.X[i] * Probleme.X[i] * Probleme.CoutQuadratique[i]; + logs.debug() << "X-Q: " << Probleme.X[i] * 1e3; + logs.debug() << "CoutQ: " << Probleme.CoutQuadratique[i] * 1e3; + logs.debug() << "TotalCost: " << cost * 1e3; + } + + auto itLink = hourlyCsrProblem.linkInsideAdqPatch.find(i); + if ((itLink == hourlyCsrProblem.linkInsideAdqPatch.end()) + || hourlyCsrProblem.problemeHebdo_->adqPatchParams->IncludeHurdleCostCsr + || !itLink->second.check()) + continue; + + if (Probleme.X[i] >= 0) + { + const int varDirect = itLink->second.directVar; + if (varDirect < 0) + { + logs.warning() << "VarDirect < 0 detected, this should not happen"; + continue; + } + cost += Probleme.X[i] * Probleme.CoutLineaire[varDirect]; + logs.debug() << "X+: " << Probleme.X[i] * 1e3; + logs.debug() << "CoutL: " << Probleme.CoutLineaire[varDirect] * 1e3; + logs.debug() << "TotalCost: " << cost * 1e3; + } + else + { + const int varIndirect = itLink->second.indirectVar; + if (varIndirect < 0) + { + logs.warning() << "VarIndirect < 0 detected, this should not happen"; + continue; + + } + cost -= Probleme.X[i] * Probleme.CoutLineaire[varIndirect]; + logs.debug() << "X-: " << Probleme.X[i] * 1e3; + logs.debug() << "CoutL: " << Probleme.CoutLineaire[varIndirect] * 1e3; + logs.debug() << "TotalCost: " << cost * 1e3; + } + } + return cost; +} + +void CSR_DEBUG_HANDLE(const PROBLEME_POINT_INTERIEUR& Probleme) +{ + logs.info(); + logs.info() << LOG_UI_DISPLAY_MESSAGES_OFF; + logs.info() << "Here is the trace:"; + + for (int i = 0; i < Probleme.NombreDeVariables; i++) + { + logs.info().appendFormat("Variable %ld cout lineaire %e cout quadratique %e", + i, + Probleme.CoutLineaire[i], + Probleme.CoutQuadratique[i]); + } + for (int Cnt = 0; Cnt < Probleme.NombreDeContraintes; Cnt++) + { + logs.info().appendFormat( + "Constraint %ld sens %c B %e", Cnt, Probleme.Sens[Cnt], Probleme.SecondMembre[Cnt]); + + int il = Probleme.IndicesDebutDeLigne[Cnt]; + int ilMax = il + Probleme.NombreDeTermesDesLignes[Cnt]; + for (; il < ilMax; ++il) + { + int var = Probleme.IndicesColonnes[il]; + logs.info().appendFormat(" coeff %e var %ld xmin %e xmax %e type %ld", + Probleme.CoefficientsDeLaMatriceDesContraintes[il], + var, + Probleme.Xmin[var], + Probleme.Xmax[var], + Probleme.TypeDeVariable[var]); + } + } +} + +void handleInteriorPointError(const PROBLEME_POINT_INTERIEUR& Probleme, + int hour, + uint weekNb, + int yearNb) +{ + const int hoursInWeek = 168; + logs.warning() + << "No further optimization for CSR is possible, optimum solution is set as LMR . year: " + << yearNb + 1 << ". hour: " << weekNb * hoursInWeek + hour + 1; + +#ifndef NDEBUG + CSR_DEBUG_HANDLE(Probleme); +#endif +} + +bool ADQ_PATCH_CSR(PROBLEME_ANTARES_A_RESOUDRE& ProblemeAResoudre, + HourlyCSRProblem& hourlyCsrProblem, + uint weekNb, + int yearNb) +{ + auto Probleme = buildInteriorPointProblem(ProblemeAResoudre); + double costPriorToCsr = calculateCsrCostFunctionValue(*Probleme, hourlyCsrProblem); + PI_Quamin(Probleme.get()); // resolution + if (Probleme->ExistenceDUneSolution == OUI_PI) + { + setToZeroIfBelowThreshold(ProblemeAResoudre, hourlyCsrProblem); + double costAfterCsr = calculateCsrCostFunctionValue(*Probleme, hourlyCsrProblem); + storeOrDisregardInteriorPointResults( + ProblemeAResoudre, hourlyCsrProblem, weekNb, yearNb, costPriorToCsr, costAfterCsr); + return true; + } + else + { + handleInteriorPointError(*Probleme, hourlyCsrProblem.triggeredHour, weekNb, yearNb); + return false; + } +} diff --git a/src/solver/optimisation/adequacy_patch_local_matching/adq_patch_local_matching.cpp b/src/solver/optimisation/adequacy_patch_local_matching/adq_patch_local_matching.cpp new file mode 100644 index 0000000000..9af08efff3 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_local_matching/adq_patch_local_matching.cpp @@ -0,0 +1,166 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "adq_patch_local_matching.h" + +namespace Antares::Data::AdequacyPatch +{ +/*! + * Determines restriction type for transmission links for first step of adequacy patch, when start + * node is inside adq path (type 2). + * + * @param ExtremityNodeAdequacyPatchType uint: The adq type of the node at the end of the link. + * + * @return uint from an enumeration that describes the type of restrictions to put on this link for + * adq purposes. + */ +static NtcSetToZeroStatus_AdqPatchStep1 SetNTCForAdequacyFirstStepOriginNodeInsideAdq( + AdequacyPatchMode ExtremityNodeAdequacyPatchType) +{ + switch (ExtremityNodeAdequacyPatchType) + { + case physicalAreaInsideAdqPatch: + case physicalAreaOutsideAdqPatch: + return NtcSetToZeroStatus_AdqPatchStep1::setToZero; + default: + return NtcSetToZeroStatus_AdqPatchStep1::leaveLocalValues; + } +} + +/*! + * Determines restriction type for transmission links for first step of adequacy patch, when start + * node is outside adq path (type 1). + * + * @param ExtremityNodeAdequacyPatchType uint: The adq type of the node at the end of the link. + * + * @param setToZeroNTCfromOutToIn_AdqPatch bool: Switch to cut links from nodes outside adq patch + * (type 1) towards nodes inside adq patch (type 2). + * + * @param setToZeroNTCfromOutToOut_AdqPatch bool: Switch to cut links between nodes outside adq + * patch (type 1). + * + * @return uint from an enumeration that describes the type of restrictions to put on this link for + * adq purposes. + */ +static NtcSetToZeroStatus_AdqPatchStep1 getNTCtoZeroStatusOriginNodeOutsideAdq( + AdequacyPatchMode ExtremityNodeAdequacyPatchType, + bool setToZeroNTCfromOutToIn_AdqPatch, + bool setToZeroNTCfromOutToOut_AdqPatch) +{ + switch (ExtremityNodeAdequacyPatchType) + { + case physicalAreaInsideAdqPatch: + return setToZeroNTCfromOutToIn_AdqPatch ? NtcSetToZeroStatus_AdqPatchStep1::setToZero + : NtcSetToZeroStatus_AdqPatchStep1::setExtremityOriginToZero; + case physicalAreaOutsideAdqPatch: + return setToZeroNTCfromOutToOut_AdqPatch ? NtcSetToZeroStatus_AdqPatchStep1::setToZero + : NtcSetToZeroStatus_AdqPatchStep1::leaveLocalValues; + default: + return NtcSetToZeroStatus_AdqPatchStep1::leaveLocalValues; + } +} + +/*! + * Determines restriction type for transmission links for first step of adequacy patch. + * + * @param problemeHebdo PROBLEME_HEBDO*: Weekly problem structure. + * + * @param Interco int: Index of the link. + * + * @return uint from an enumeration that describes the type of restrictions to put on this link for + * adq purposes. + */ +static NtcSetToZeroStatus_AdqPatchStep1 getNTCtoZeroStatus(PROBLEME_HEBDO* problemeHebdo, + int Interco) +{ + AdequacyPatchMode OriginNodeAdequacyPatchType + = problemeHebdo->adequacyPatchRuntimeData.originAreaMode[Interco]; + AdequacyPatchMode ExtremityNodeAdequacyPatchType + = problemeHebdo->adequacyPatchRuntimeData.extremityAreaMode[Interco]; + bool setToZeroNTCfromOutToIn_AdqPatch + = problemeHebdo->adqPatchParams->SetNTCOutsideToInsideToZero; + bool setToZeroNTCfromOutToOut_AdqPatch + = problemeHebdo->adqPatchParams->SetNTCOutsideToOutsideToZero; + + switch (OriginNodeAdequacyPatchType) + { + case physicalAreaInsideAdqPatch: + return SetNTCForAdequacyFirstStepOriginNodeInsideAdq(ExtremityNodeAdequacyPatchType); + + case physicalAreaOutsideAdqPatch: + return getNTCtoZeroStatusOriginNodeOutsideAdq(ExtremityNodeAdequacyPatchType, + setToZeroNTCfromOutToIn_AdqPatch, + setToZeroNTCfromOutToOut_AdqPatch); + default: + return NtcSetToZeroStatus_AdqPatchStep1::leaveLocalValues; + } +} + +void setNTCbounds(double& Xmax, + double& Xmin, + const VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeNTC, + const int Interco, + PROBLEME_HEBDO* problemeHebdo) +{ + NtcSetToZeroStatus_AdqPatchStep1 ntcToZeroStatusForAdqPatch; + + // set as default values + Xmax = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco]; + Xmin = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]); + + // set for adq patch first step + if (problemeHebdo->adqPatchParams && problemeHebdo->adqPatchParams->AdequacyFirstStep) + { + ntcToZeroStatusForAdqPatch = getNTCtoZeroStatus(problemeHebdo, Interco); + + switch (ntcToZeroStatusForAdqPatch) + { + case NtcSetToZeroStatus_AdqPatchStep1::setToZero: + { + Xmax = 0.; + Xmin = 0.; + break; + } + case NtcSetToZeroStatus_AdqPatchStep1::setOriginExtremityToZero: + { + Xmax = 0.; + Xmin = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]); + break; + } + case NtcSetToZeroStatus_AdqPatchStep1::setExtremityOriginToZero: + { + Xmax = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco]; + Xmin = 0.; + break; + } + default: + return; + } + } +} + +} // namespace Antares::Data::AdequacyPatch diff --git a/src/solver/optimisation/adequacy_patch.h b/src/solver/optimisation/adequacy_patch_local_matching/adq_patch_local_matching.h similarity index 55% rename from src/solver/optimisation/adequacy_patch.h rename to src/solver/optimisation/adequacy_patch_local_matching/adq_patch_local_matching.h index 37c73faa6f..01f0ad3c23 100644 --- a/src/solver/optimisation/adequacy_patch.h +++ b/src/solver/optimisation/adequacy_patch_local_matching/adq_patch_local_matching.h @@ -1,5 +1,5 @@ /* -** Copyright 2007-2018 RTE +** Copyright 2007-2023 RTE ** Authors: Antares_Simulator Team ** ** This file is part of Antares_Simulator. @@ -25,34 +25,20 @@ ** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions */ -#ifndef __SOLVER_ADEQUACY_FUNCTIONS_H__ -#define __SOLVER_ADEQUACY_FUNCTIONS_H__ +#pragma once -#include #include "../simulation/sim_structure_probleme_economique.h" -namespace Antares -{ -namespace Data -{ -namespace AdequacyPatch +namespace Antares::Data::AdequacyPatch { /*! - * Sets link bounds for first step of adequacy patch. + * Sets link bounds for first step of adequacy patch or leaves default values if adequacy patch is + * not used. */ -void setBoundsAdqPatch(double& Xmax, - double& Xmin, - VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeNTC, - const int Interco, - PROBLEME_HEBDO* ProblemeHebdo); -/*! - * Sets link bounds when adequacy patch is not used or when first step of adequacy patch is false. - */ -void setBoundsNoAdqPatch(double& Xmax, - double& Xmin, - VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeNTC, - const int Interco); -} // namespace AdequacyPatch -} // end namespace Data -} // namespace Antares -#endif /* __SOLVER_ADEQUACY_FUNCTIONS_H__ */ +void setNTCbounds(double& Xmax, + double& Xmin, + const VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeNTC, + const int Interco, + PROBLEME_HEBDO* problemeHebdo); + +} // namespace Antares::Data::AdequacyPatch diff --git a/src/solver/optimisation/adequacy_patch_weekly_optimization.cpp b/src/solver/optimisation/adequacy_patch_weekly_optimization.cpp new file mode 100644 index 0000000000..d4cbd42b11 --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_weekly_optimization.cpp @@ -0,0 +1,71 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "adequacy_patch_csr/adq_patch_curtailment_sharing.h" +#include "adequacy_patch_weekly_optimization.h" +#include "opt_fonctions.h" +#include "../simulation/simulation.h" +#include "antares/study/area/scratchpad.h" +#include "antares/study/fwd.h" + +const int nbHoursInAWeek = 168; + +using namespace Antares::Data::AdequacyPatch; + +namespace Antares::Solver::Optimization +{ +AdequacyPatchOptimization::AdequacyPatchOptimization(PROBLEME_HEBDO* problemeHebdo, + uint thread_number) : + WeeklyOptimization(problemeHebdo, thread_number) +{ +} +void AdequacyPatchOptimization::solve(uint weekInTheYear, int hourInTheYear) +{ + problemeHebdo_->adqPatchParams->AdequacyFirstStep = true; + OPT_OptimisationHebdomadaire(problemeHebdo_, thread_number_); + problemeHebdo_->adqPatchParams->AdequacyFirstStep = false; + + for (int pays = 0; pays < problemeHebdo_->NombreDePays; ++pays) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[pays] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + memcpy(problemeHebdo_->ResultatsHoraires[pays]->ValeursHorairesDENS, + problemeHebdo_->ResultatsHoraires[pays]->ValeursHorairesDeDefaillancePositive, + problemeHebdo_->NombreDePasDeTemps * sizeof(double)); + else + memset(problemeHebdo_->ResultatsHoraires[pays]->ValeursHorairesDENS, + 0, + problemeHebdo_->NombreDePasDeTemps * sizeof(double)); + } + + // TODO check if we need to cut SIM_RenseignementProblemeHebdo and just pick out the + // part that we need + ::SIM_RenseignementProblemeHebdo(*problemeHebdo_, weekInTheYear, thread_number_, hourInTheYear); + OPT_OptimisationHebdomadaire(problemeHebdo_, thread_number_); +} + +} // namespace Antares::Solver::Optimization diff --git a/src/solver/optimisation/adequacy_patch_weekly_optimization.h b/src/solver/optimisation/adequacy_patch_weekly_optimization.h new file mode 100644 index 0000000000..d2703fdd0d --- /dev/null +++ b/src/solver/optimisation/adequacy_patch_weekly_optimization.h @@ -0,0 +1,45 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#pragma once + +#include "base_weekly_optimization.h" +#include "../simulation/sim_structure_probleme_economique.h" +#include "antares/study/area/area.h" + +using Antares::Data::AreaList; + +namespace Antares::Solver::Optimization +{ +class AdequacyPatchOptimization : public WeeklyOptimization +{ +public: + explicit AdequacyPatchOptimization(PROBLEME_HEBDO* problemeHebdo, uint numSpace); + ~AdequacyPatchOptimization() override = default; + void solve(uint weekInTheYear, int hourInTheYear) override; +}; +} // namespace Antares::Solver::Optimization diff --git a/src/solver/optimisation/adq_patch_post_process_list.cpp b/src/solver/optimisation/adq_patch_post_process_list.cpp new file mode 100644 index 0000000000..e2350557dc --- /dev/null +++ b/src/solver/optimisation/adq_patch_post_process_list.cpp @@ -0,0 +1,55 @@ +#include "adq_patch_post_process_list.h" +#include "post_process_commands.h" + + +namespace Antares::Solver::Simulation +{ + +AdqPatchPostProcessList::AdqPatchPostProcessList(PROBLEME_HEBDO* problemeHebdo, + uint thread_number, + AreaList& areas, + SheddingPolicy sheddingPolicy, + SimplexOptimization splxOptimization, + Calendar& calendar) + : interfacePostProcessList(problemeHebdo, thread_number) +{ + post_process_list.push_back(std::make_unique( + problemeHebdo_, + thread_number_, + areas)); + // Here a post process particular to adq patch + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + thread_number_)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + false, + false)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + sheddingPolicy, + splxOptimization, + thread_number)); + // Here a post process particular to adq patch + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + thread_number)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + true, + false)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + calendar)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas)); +} + +} // namespace Antares::Solver::Simulation \ No newline at end of file diff --git a/src/solver/optimisation/adq_patch_post_process_list.h b/src/solver/optimisation/adq_patch_post_process_list.h new file mode 100644 index 0000000000..bf0fb82867 --- /dev/null +++ b/src/solver/optimisation/adq_patch_post_process_list.h @@ -0,0 +1,22 @@ +#pragma once + + +#include "../simulation/base_post_process.h" + +namespace Antares::Solver::Simulation +{ + +class AdqPatchPostProcessList : public interfacePostProcessList +{ +public: + AdqPatchPostProcessList(PROBLEME_HEBDO* problemeHebdo, + uint thread_number, + AreaList& areas, + SheddingPolicy sheddingPolicy, + SimplexOptimization splxOptimization, + Calendar& calendar); + + virtual ~AdqPatchPostProcessList() = default; +}; + +} // namespace Antares::Solver::Simulation diff --git a/src/solver/optimisation/base_weekly_optimization.cpp b/src/solver/optimisation/base_weekly_optimization.cpp new file mode 100644 index 0000000000..c98e433c10 --- /dev/null +++ b/src/solver/optimisation/base_weekly_optimization.cpp @@ -0,0 +1,52 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include +#include "base_weekly_optimization.h" +#include "weekly_optimization.h" +#include "adequacy_patch_weekly_optimization.h" + +namespace Antares::Solver::Optimization +{ +WeeklyOptimization::WeeklyOptimization(PROBLEME_HEBDO* problemesHebdo, + uint thread_number) : + problemeHebdo_(problemesHebdo), thread_number_(thread_number) +{ +} + +std::unique_ptr WeeklyOptimization::create( + bool adqPatchEnabled, + PROBLEME_HEBDO* problemeHebdo, + uint thread_number) +{ + if (adqPatchEnabled) + return std::make_unique(problemeHebdo, thread_number); + else + return std::make_unique(problemeHebdo, thread_number); +} + +} // namespace Antares::Solver::Optimization diff --git a/src/solver/optimisation/base_weekly_optimization.h b/src/solver/optimisation/base_weekly_optimization.h new file mode 100644 index 0000000000..715f23a829 --- /dev/null +++ b/src/solver/optimisation/base_weekly_optimization.h @@ -0,0 +1,49 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#pragma once + +#include // for "uint" definition +#include "../simulation/sim_structure_probleme_economique.h" + +namespace Antares::Solver::Optimization +{ +class WeeklyOptimization +{ +public: + virtual void solve(uint weekInTheYear, int hourInTheYear) = 0; + virtual ~WeeklyOptimization() = default; + static std::unique_ptr create(bool adqPatchEnabled, + PROBLEME_HEBDO* problemesHebdo, + uint numSpace); + +protected: + explicit WeeklyOptimization(PROBLEME_HEBDO* problemesHebdo, uint numSpace); + PROBLEME_HEBDO* const problemeHebdo_ = nullptr; + const uint thread_number_ = 0; +}; +} // namespace Antares::Solver::Optimization diff --git a/src/solver/optimisation/hourly_csr_problem.h b/src/solver/optimisation/hourly_csr_problem.h new file mode 100644 index 0000000000..ecb1d6a71f --- /dev/null +++ b/src/solver/optimisation/hourly_csr_problem.h @@ -0,0 +1,121 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#pragma once + +class HourlyCSRProblem +{ +private: + void calculateCsrParameters(); + + void buildProblemVariables(); + void setVariableBounds(); + void buildProblemConstraintsLHS(); + void buildProblemConstraintsRHS(); + void setProblemCost(); + void solveProblem(uint week, int year); + void allocateProblem(); + void resetProblem(); + + // variable construction + void constructVariableENS(); + void constructVariableSpilledEnergy(); + void constructVariableFlows(); + + // variable bounds + void setBoundsOnENS(); + void setBoundsOnSpilledEnergy(); + void setBoundsOnFlows(); + + // Constraints + void setRHSvalueOnFlows(); + void setRHSnodeBalanceValue(); + void setRHSbindingConstraintsValue(); + + // Costs + void setQuadraticCost(); + void setLinearCost(); + +public: + void run(uint week, uint year); + + // TODO[FOM] Make these members private + int triggeredHour; + double belowThisThresholdSetToZero; + PROBLEME_HEBDO* problemeHebdo_; + PROBLEME_ANTARES_A_RESOUDRE problemeAResoudre_; + explicit HourlyCSRProblem(PROBLEME_HEBDO* p) : problemeHebdo_(p) + { + belowThisThresholdSetToZero = p->adqPatchParams->ThresholdCSRVarBoundsRelaxation; + allocateProblem(); + } + + ~HourlyCSRProblem() + { + resetProblem(); + } + + HourlyCSRProblem(const HourlyCSRProblem&) = delete; + HourlyCSRProblem& operator=(const HourlyCSRProblem&) = delete; + + inline void setHour(int hour) + { + triggeredHour = hour; + } + + std::map numberOfConstraintCsrEns; + std::map numberOfConstraintCsrAreaBalance; + std::map numberOfConstraintCsrFlowDissociation; + std::map numberOfConstraintCsrHourlyBinding; // length is number of binding constraint + // contains interco 2-2 + + std::map rhsAreaBalanceValues; + std::set varToBeSetToZeroIfBelowThreshold; // place inside only ENS and Spillage variable + std::set ensVariablesInsideAdqPatch; // place inside only ENS inside adq-patch + struct LinkVariable + { + LinkVariable() : directVar(-1), indirectVar(-1) + { + } + LinkVariable(int direct, int indirect) : directVar(direct), indirectVar(indirect) + { + } + inline bool check() const + { + if (directVar < 0) + logs.warning() << "directVar < 0 detected, this should not happen"; + if (indirectVar < 0) + logs.warning() << "indirectVar < 0 detected, this should not happen"; + + return (directVar >= 0) && (indirectVar >= 0); + } + int directVar; + int indirectVar; + }; + std::map + linkInsideAdqPatch; // links between two areas inside the adq-patch domain +}; diff --git a/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp b/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp index a1ae757ea2..7885d77626 100644 --- a/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp +++ b/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp @@ -52,35 +52,103 @@ using namespace Antares; #define SNPRINTF snprintf #endif -static void optimisationAllocateProblem(PROBLEME_HEBDO* ProblemeHebdo, const int mxPaliers) +void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, + int NbTermes) +{ + const size_t szNbVarsDouble = ProblemeAResoudre->NombreDeVariables * sizeof(double); + const size_t szNbVarsint = ProblemeAResoudre->NombreDeVariables * sizeof(int); + const size_t szNbContint = ProblemeAResoudre->NombreDeContraintes * sizeof(int); + + ProblemeAResoudre->Sens + = (char*)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(char)); + ProblemeAResoudre->IndicesDebutDeLigne = (int*)MemAlloc(szNbContint); + ProblemeAResoudre->NombreDeTermesDesLignes = (int*)MemAlloc(szNbContint); + + ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes + = (double*)MemAlloc(NbTermes * sizeof(double)); + ProblemeAResoudre->IndicesColonnes = (int*)MemAlloc(NbTermes * sizeof(int)); + + ProblemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes = NbTermes; + ProblemeAResoudre->IncrementDAllocationMatriceDesContraintes = (int)(0.1 * NbTermes); + + ProblemeAResoudre->CoutQuadratique = (double*)MemAlloc(szNbVarsDouble); + ProblemeAResoudre->CoutLineaire = (double*)MemAlloc(szNbVarsDouble); + ProblemeAResoudre->TypeDeVariable = (int*)MemAlloc(szNbVarsint); + ProblemeAResoudre->Xmin = (double*)MemAlloc(szNbVarsDouble); + ProblemeAResoudre->Xmax = (double*)MemAlloc(szNbVarsDouble); + ProblemeAResoudre->X = (double*)MemAlloc(szNbVarsDouble); + + ProblemeAResoudre->SecondMembre + = (double*)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(double)); + + ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees + = (double**)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(void*)); + ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsReduits + = (double**)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(void*)); + ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux + = (double**)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(void*)); + + ProblemeAResoudre->CoutsMarginauxDesContraintes + = (double*)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(double)); + ProblemeAResoudre->CoutsReduits = (double*)MemAlloc(szNbVarsDouble); + + ProblemeAResoudre->PositionDeLaVariable + = (int*)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(int)); + ProblemeAResoudre->ComplementDeLaBase + = (int*)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(int)); + + ProblemeAResoudre->Pi + = (double*)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(double)); + ProblemeAResoudre->Colonne = (int*)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(int)); + + ProblemeAResoudre->NomDesVariables.resize(ProblemeAResoudre->NombreDeVariables); + ProblemeAResoudre->NomDesContraintes.resize(ProblemeAResoudre->NombreDeContraintes); +} + +void OPT_FreeOptimizationData(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre) +{ + MemFree(ProblemeAResoudre->Sens); + MemFree(ProblemeAResoudre->IndicesDebutDeLigne); + MemFree(ProblemeAResoudre->NombreDeTermesDesLignes); + MemFree(ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes); + MemFree(ProblemeAResoudre->IndicesColonnes); + MemFree(ProblemeAResoudre->CoutQuadratique); + MemFree(ProblemeAResoudre->CoutLineaire); + MemFree(ProblemeAResoudre->TypeDeVariable); + MemFree(ProblemeAResoudre->Xmin); + MemFree(ProblemeAResoudre->Xmax); + MemFree(ProblemeAResoudre->X); + MemFree(ProblemeAResoudre->SecondMembre); + MemFree(ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees); + MemFree(ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsReduits); + MemFree(ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux); + MemFree(ProblemeAResoudre->CoutsMarginauxDesContraintes); + MemFree(ProblemeAResoudre->CoutsReduits); + + MemFree(ProblemeAResoudre->PositionDeLaVariable); + MemFree(ProblemeAResoudre->ComplementDeLaBase); + MemFree(ProblemeAResoudre->Pi); + MemFree(ProblemeAResoudre->Colonne); + + ProblemeAResoudre->NomDesVariables.clear(); + ProblemeAResoudre->NomDesContraintes.clear(); +} + +static void optimisationAllocateProblem(PROBLEME_HEBDO* problemeHebdo, const int mxPaliers) { int NbTermes; int NbIntervalles; int NumIntervalle; - size_t szNbVarsDouble; - size_t szNbVarsint; - size_t szNbContint; int NombreDePasDeTempsPourUneOptimisation; int Adder; int Sparsity; - PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - szNbVarsDouble = ProblemeAResoudre->NombreDeVariables * sizeof(double); - szNbVarsint = ProblemeAResoudre->NombreDeVariables * sizeof(int); - szNbContint = ProblemeAResoudre->NombreDeContraintes * sizeof(int); - - ProblemeAResoudre->Sens - = (char*)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(char)); - ProblemeAResoudre->IndicesDebutDeLigne = (int*)MemAlloc(szNbContint); - ProblemeAResoudre->NombreDeTermesDesLignes = (int*)MemAlloc(szNbContint); - - Sparsity = (int)mxPaliers * ProblemeHebdo->NombreDePays; - Sparsity += ProblemeHebdo->NombreDInterconnexions; + Sparsity = (int)mxPaliers * problemeHebdo->NombreDePays; + Sparsity += problemeHebdo->NombreDInterconnexions; if (Sparsity > 100) Sparsity = 100; @@ -89,38 +157,38 @@ static void optimisationAllocateProblem(PROBLEME_HEBDO* ProblemeHebdo, const int Adder = (int)mxPaliers; Adder += 4; - Adder *= ProblemeHebdo->NombreDePays; - Adder += 2 * ProblemeHebdo->NombreDInterconnexions; + Adder *= problemeHebdo->NombreDePays; + Adder += 2 * problemeHebdo->NombreDInterconnexions; Adder *= NombreDePasDeTempsPourUneOptimisation; NbTermes += Adder; NbTermes += Adder; - Adder = 3 * ProblemeHebdo->NombreDInterconnexions * NombreDePasDeTempsPourUneOptimisation; + Adder = 3 * problemeHebdo->NombreDInterconnexions * NombreDePasDeTempsPourUneOptimisation; NbTermes += Adder; - Adder = Sparsity * ProblemeHebdo->NombreDeContraintesCouplantes; + Adder = Sparsity * problemeHebdo->NombreDeContraintesCouplantes; Adder *= (NombreDePasDeTempsPourUneOptimisation); - Adder += Sparsity * (7 + 7) * ProblemeHebdo->NombreDeContraintesCouplantes; + Adder += Sparsity * (7 + 7) * problemeHebdo->NombreDeContraintesCouplantes; NbTermes += Adder; - NbTermes += 3 * ProblemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation; - NbTermes += ProblemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation * 4; - NbTermes += ProblemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation * 5; + NbTermes += 3 * problemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation; + NbTermes += problemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation * 4; + NbTermes += problemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation * 5; - NbTermes += ProblemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation + NbTermes += problemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation * 2; /*inequality constraint on final hydros level*/ NbTermes += 1; /* constraint includes hydro generation, pumping and final level */ NbTermes += 101; /* constraint expressing final level as a sum of stock layers */ - NbTermes += ProblemeHebdo->NbTermesContraintesPourLesCoutsDeDemarrage; + NbTermes += problemeHebdo->NbTermesContraintesPourLesCoutsDeDemarrage; logs.info(); logs.info() << " Starting Memory Allocation for a Weekly Optimization problem in Canonical form "; - logs.info() << " ( Problem Size :" << ProblemeAResoudre->NombreDeVariables << " Variables " + logs.info() << " ( Problem Size :" << ProblemeAResoudre->NombreDeVariables << " variables " << ProblemeAResoudre->NombreDeContraintes << " Constraints) "; logs.info() << " Expected Number of Non-zero terms in Problem Matrix : " << NbTermes; logs.info(); @@ -131,70 +199,32 @@ static void optimisationAllocateProblem(PROBLEME_HEBDO* ProblemeHebdo, const int AntaresSolverEmergencyShutdown(); } - ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes - = (double*)MemAlloc(NbTermes * sizeof(double)); - ProblemeAResoudre->IndicesColonnes = (int*)MemAlloc(NbTermes * sizeof(int)); - - ProblemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes = NbTermes; - ProblemeAResoudre->IncrementDAllocationMatriceDesContraintes = (int)(0.1 * NbTermes); - - ProblemeAResoudre->CoutQuadratique = (double*)MemAlloc(szNbVarsDouble); - ProblemeAResoudre->CoutLineaire = (double*)MemAlloc(szNbVarsDouble); - ProblemeAResoudre->TypeDeVariable = (int*)MemAlloc(szNbVarsint); - ProblemeAResoudre->Xmin = (double*)MemAlloc(szNbVarsDouble); - ProblemeAResoudre->Xmax = (double*)MemAlloc(szNbVarsDouble); - ProblemeAResoudre->X = (double*)MemAlloc(szNbVarsDouble); - - ProblemeAResoudre->SecondMembre - = (double*)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(double)); - - ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees - = (double**)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(void*)); - ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsReduits - = (double**)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(void*)); - ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux - = (double**)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(void*)); - - ProblemeAResoudre->CoutsMarginauxDesContraintes - = (double*)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(double)); - ProblemeAResoudre->CoutsReduits = (double*)MemAlloc(szNbVarsDouble); + OPT_AllocateFromNumberOfVariableConstraints(problemeHebdo->ProblemeAResoudre, NbTermes); NbIntervalles - = (int)(ProblemeHebdo->NombreDePasDeTemps / NombreDePasDeTempsPourUneOptimisation); + = (int)(problemeHebdo->NombreDePasDeTemps / NombreDePasDeTempsPourUneOptimisation); ProblemeAResoudre->ProblemesSpx = (PROBLEMES_SIMPLEXE*)MemAlloc(sizeof(PROBLEMES_SIMPLEXE)); ProblemeAResoudre->ProblemesSpx->ProblemeSpx = (void**)MemAlloc(NbIntervalles * sizeof(void*)); for (NumIntervalle = 0; NumIntervalle < NbIntervalles; NumIntervalle++) ProblemeAResoudre->ProblemesSpx->ProblemeSpx[NumIntervalle] = NULL; - ProblemeAResoudre->PositionDeLaVariable - = (int*)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(int)); - ProblemeAResoudre->ComplementDeLaBase - = (int*)MemAlloc(ProblemeAResoudre->NombreDeContraintes * sizeof(int)); - - ProblemeAResoudre->Pi - = (double*)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(double)); - ProblemeAResoudre->Colonne = (int*)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(int)); - - ProblemeAResoudre->NomDesVariables.resize(ProblemeAResoudre->NombreDeVariables); - ProblemeAResoudre->NomDesContraintes.resize(ProblemeAResoudre->NombreDeContraintes); - logs.info(); logs.info() << " Status of Preliminary Allocations for Generic Problem Resolution : Successful"; logs.info(); } -void OPT_AllocDuProblemeAOptimiser(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_AllocDuProblemeAOptimiser(PROBLEME_HEBDO* problemeHebdo) { int mxPaliers; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; ProblemeAResoudre = (PROBLEME_ANTARES_A_RESOUDRE*)MemAllocMemset(sizeof(PROBLEME_ANTARES_A_RESOUDRE)); - ProblemeHebdo->ProblemeAResoudre = ProblemeAResoudre; + problemeHebdo->ProblemeAResoudre = ProblemeAResoudre; - OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(ProblemeHebdo, &mxPaliers); + OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(problemeHebdo, &mxPaliers); - optimisationAllocateProblem(ProblemeHebdo, mxPaliers); + optimisationAllocateProblem(problemeHebdo, mxPaliers); } void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre) @@ -224,49 +254,18 @@ void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes = NbTermes; } -void OPT_LiberationMemoireDuProblemeAOptimiser(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_LiberationMemoireDuProblemeAOptimiser(PROBLEME_HEBDO* problemeHebdo) { - PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; - + PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; if (ProblemeAResoudre) { - MemFree(ProblemeAResoudre->Sens); - MemFree(ProblemeAResoudre->IndicesDebutDeLigne); - MemFree(ProblemeAResoudre->NombreDeTermesDesLignes); - MemFree(ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes); - MemFree(ProblemeAResoudre->IndicesColonnes); - MemFree(ProblemeAResoudre->CoutQuadratique); - MemFree(ProblemeAResoudre->CoutLineaire); - MemFree(ProblemeAResoudre->TypeDeVariable); - MemFree(ProblemeAResoudre->Xmin); - MemFree(ProblemeAResoudre->Xmax); - MemFree(ProblemeAResoudre->X); - MemFree(ProblemeAResoudre->SecondMembre); - MemFree(ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees); - MemFree(ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsReduits); - MemFree(ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux); - MemFree(ProblemeAResoudre->CoutsMarginauxDesContraintes); - MemFree(ProblemeAResoudre->CoutsReduits); - + OPT_FreeOptimizationData(ProblemeAResoudre); if (ProblemeAResoudre->ProblemesSpx) { MemFree(ProblemeAResoudre->ProblemesSpx->ProblemeSpx); MemFree(ProblemeAResoudre->ProblemesSpx); } - - MemFree(ProblemeAResoudre->PositionDeLaVariable); - MemFree(ProblemeAResoudre->ComplementDeLaBase); - MemFree(ProblemeAResoudre->Pi); - MemFree(ProblemeAResoudre->Colonne); - - ProblemeAResoudre->NomDesVariables.clear(); - ProblemeAResoudre->NomDesContraintes.clear(); - MemFree(ProblemeAResoudre); - ProblemeAResoudre = nullptr; } - return; } diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index 5261a02851..4768cd9a22 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -95,37 +95,27 @@ class TimeMeasurement clock::time_point end_; }; -bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* ProblemeHebdo, +bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* problemeHebdo, int NumIntervalle, const int optimizationNumber, std::shared_ptr optPeriodStringGenerator) { - int Var; - int Cnt; - double* pt; - char PremierPassage; - double CoutOpt; - long long solveTime; - PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - - PROBLEME_SPX* ProbSpx; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; Optimization::PROBLEME_SIMPLEXE_NOMME Probleme(ProblemeAResoudre->NomDesVariables, ProblemeAResoudre->NomDesContraintes, ProblemeAResoudre->StatutDesVariables, ProblemeAResoudre->StatutDesContraintes); - PremierPassage = OUI_ANTARES; - MPSolver* solver; + char PremierPassage = OUI_ANTARES; - ProbSpx = (PROBLEME_SPX*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]); - solver = (MPSolver*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]); + PROBLEME_SPX* ProbSpx = (PROBLEME_SPX*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]); + MPSolver* solver = (MPSolver*)(ProblemeAResoudre->ProblemesSpx->ProblemeSpx[(int)NumIntervalle]); auto study = Data::Study::Current::Get(); bool ortoolsUsed = study->parameters.ortoolsUsed; const int opt = optimizationNumber - 1; assert(opt >= 0 && opt < 2); - OptimizationStatistics* optimizationStatistics = &(ProblemeHebdo->optimizationStatistics[opt]); + OptimizationStatistics* optimizationStatistics = &(problemeHebdo->optimizationStatistics[opt]); RESOLUTION: @@ -136,7 +126,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* ProblemeHebdo, } else { - if (ProblemeHebdo->ReinitOptimisation == OUI_ANTARES) + if (problemeHebdo->ReinitOptimisation == OUI_ANTARES) { if (ortoolsUsed && solver != nullptr) { @@ -246,7 +236,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* ProblemeHebdo, } const std::string filename = createMPSfilename(optPeriodStringGenerator, optimizationNumber); mpsWriterFactory mps_writer_factory( - ProblemeHebdo, optimizationNumber, &Probleme, ortoolsUsed, solver); + problemeHebdo, optimizationNumber, &Probleme, ortoolsUsed, solver); auto mps_writer = mps_writer_factory.create(); mps_writer->runIfNeeded(study->resultWriter, filename); @@ -269,7 +259,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* ProblemeHebdo, } } measure.tick(); - solveTime = measure.duration_ms(); + long long solveTime = measure.duration_ms(); optimizationStatistics->addSolveTime(solveTime); ProblemeAResoudre->ExistenceDUneSolution = Probleme.ExistenceDUneSolution; @@ -315,32 +305,34 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* ProblemeHebdo, { logs.info() << " Solver: Safe resolution succeeded"; } - CoutOpt = 0.0; - for (Var = 0; Var < ProblemeAResoudre->NombreDeVariables; Var++) + double *pt; + double CoutOpt = 0.0; + + for (int i = 0; i < ProblemeAResoudre->NombreDeVariables; i++) { - CoutOpt += ProblemeAResoudre->CoutLineaire[Var] * ProblemeAResoudre->X[Var]; + CoutOpt += ProblemeAResoudre->CoutLineaire[i] * ProblemeAResoudre->X[i]; - pt = ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; + pt = ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[i]; if (pt != nullptr) - *pt = ProblemeAResoudre->X[Var]; + *pt = ProblemeAResoudre->X[i]; - pt = ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsReduits[Var]; + pt = ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsReduits[i]; if (pt != nullptr) - *pt = ProblemeAResoudre->CoutsReduits[Var]; + *pt = ProblemeAResoudre->CoutsReduits[i]; } if (optimizationNumber == PREMIERE_OPTIMISATION) { - ProblemeHebdo->coutOptimalSolution1[NumIntervalle] = CoutOpt; - ProblemeHebdo->tempsResolution1[NumIntervalle] = solveTime; + problemeHebdo->coutOptimalSolution1[NumIntervalle] = CoutOpt; + problemeHebdo->tempsResolution1[NumIntervalle] = solveTime; } else { - ProblemeHebdo->coutOptimalSolution2[NumIntervalle] = CoutOpt; - ProblemeHebdo->tempsResolution2[NumIntervalle] = solveTime; + problemeHebdo->coutOptimalSolution2[NumIntervalle] = CoutOpt; + problemeHebdo->tempsResolution2[NumIntervalle] = solveTime; } - for (Cnt = 0; Cnt < ProblemeAResoudre->NombreDeContraintes; Cnt++) + for (int Cnt = 0; Cnt < ProblemeAResoudre->NombreDeContraintes; Cnt++) { pt = ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt]; if (pt != nullptr) diff --git a/src/solver/optimisation/opt_appel_solveur_quadratique.cpp b/src/solver/optimisation/opt_appel_solveur_quadratique.cpp index 3ce5b777fa..ba9063e954 100644 --- a/src/solver/optimisation/opt_appel_solveur_quadratique.cpp +++ b/src/solver/optimisation/opt_appel_solveur_quadratique.cpp @@ -58,25 +58,16 @@ using namespace Antares; bool OPT_AppelDuSolveurQuadratique(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, const int PdtHebdo) { - int Var; - double* pt; - double ToleranceSurLAdmissibilite; - int ChoixToleranceParDefautSurLAdmissibilite; - double ToleranceSurLaStationnarite; - int ChoixToleranceParDefautSurLaStationnarite; - double ToleranceSurLaComplementarite; - int ChoixToleranceParDefautSurLaComplementarite; - PROBLEME_POINT_INTERIEUR Probleme; - ToleranceSurLAdmissibilite = 1.e-5; - ChoixToleranceParDefautSurLAdmissibilite = OUI_PI; + double ToleranceSurLAdmissibilite = 1.e-5; + int ChoixToleranceParDefautSurLAdmissibilite = OUI_PI; - ToleranceSurLaStationnarite = 1.e-5; - ChoixToleranceParDefautSurLaStationnarite = OUI_PI; + double ToleranceSurLaStationnarite = 1.e-5; + int ChoixToleranceParDefautSurLaStationnarite = OUI_PI; - ToleranceSurLaComplementarite = 1.e-5; - ChoixToleranceParDefautSurLaComplementarite = OUI_PI; + double ToleranceSurLaComplementarite = 1.e-5; + int ChoixToleranceParDefautSurLaComplementarite = OUI_PI; Probleme.NombreMaxDIterations = -1; Probleme.CoutQuadratique = ProblemeAResoudre->CoutQuadratique; @@ -121,11 +112,11 @@ bool OPT_AppelDuSolveurQuadratique(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudr ProblemeAResoudre->ExistenceDUneSolution = Probleme.ExistenceDUneSolution; if (ProblemeAResoudre->ExistenceDUneSolution == OUI_PI) { - for (Var = 0; Var < ProblemeAResoudre->NombreDeVariables; Var++) + for (int i = 0; i < ProblemeAResoudre->NombreDeVariables; i++) { - pt = ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; + double *pt = ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[i]; if (pt) - *pt = ProblemeAResoudre->X[Var]; + *pt = ProblemeAResoudre->X[i]; } return true; @@ -134,9 +125,9 @@ bool OPT_AppelDuSolveurQuadratique(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudr { logs.warning() << "Quadratic Optimisation: No solution, hour " << PdtHebdo; - for (Var = 0; Var < ProblemeAResoudre->NombreDeVariables; Var++) + for (int i = 0; i < ProblemeAResoudre->NombreDeVariables; i++) { - pt = ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var]; + double *pt = ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[i]; if (pt) *pt = std::numeric_limits::quiet_NaN(); } @@ -149,12 +140,12 @@ bool OPT_AppelDuSolveurQuadratique(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudr logs.info() << LOG_UI_DISPLAY_MESSAGES_OFF; logs.info() << "Here is the trace:"; - for (Var = 0; Var < ProblemeAResoudre->NombreDeVariables; Var++) + for (int i = 0; i < ProblemeAResoudre->NombreDeVariables; i++) { logs.info().appendFormat("Variable %ld cout lineaire %e cout quadratique %e", - Var, - ProblemeAResoudre->CoutLineaire[Var], - ProblemeAResoudre->CoutQuadratique[Var]); + i, + ProblemeAResoudre->CoutLineaire[i], + ProblemeAResoudre->CoutQuadratique[i]); } for (int Cnt = 0; Cnt < ProblemeAResoudre->NombreDeContraintes; Cnt++) { @@ -167,14 +158,14 @@ bool OPT_AppelDuSolveurQuadratique(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudr int ilMax = il + ProblemeAResoudre->NombreDeTermesDesLignes[Cnt]; for (; il < ilMax; ++il) { - Var = ProblemeAResoudre->IndicesColonnes[il]; + int var = ProblemeAResoudre->IndicesColonnes[il]; logs.info().appendFormat( " coeff %e var %ld xmin %e xmax %e type %ld", ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes[il], - Var, - ProblemeAResoudre->Xmin[Var], - ProblemeAResoudre->Xmax[Var], - ProblemeAResoudre->TypeDeVariable[Var]); + var, + ProblemeAResoudre->Xmin[var], + ProblemeAResoudre->Xmax[var], + ProblemeAResoudre->TypeDeVariable[var]); } } } diff --git a/src/solver/optimisation/opt_calcul_des_pmin_MUT_MDT.cpp b/src/solver/optimisation/opt_calcul_des_pmin_MUT_MDT.cpp index 5f88dcab74..4f4e812501 100644 --- a/src/solver/optimisation/opt_calcul_des_pmin_MUT_MDT.cpp +++ b/src/solver/optimisation/opt_calcul_des_pmin_MUT_MDT.cpp @@ -42,14 +42,12 @@ double OPT_CalculerAireMaxPminJour(int PremierPdt, int* NbGrpCourbeGuide, int* NbGrpOpt) { - double Cout; - int NbMx; int T; int i; - Cout = 0.0; + double Cout = 0.0; + int NbMx = 0; - NbMx = 0; for (T = 0; T < PremierPdt; T++) { if (NbGrpCourbeGuide[T] > NbMx) @@ -95,13 +93,8 @@ double OPT_CalculerAireMaxPminJour(int PremierPdt, return (Cout); } -void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO* problemeHebdo) { - int Pays; - int Palier; - int Pdt; - double P; - int NombreDePasDeTemps; int MUTetMDT; double* PminDuPalierThermiquePendantUneHeure; double* TailleUnitaireDUnGroupeDuPalierThermique; @@ -111,7 +104,6 @@ void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO* ProblemeH int* NbGrpOpt; double EcartOpt; int iOpt; - int i; double Ecart; int PremierPdt; int IntervalleDAjustement; @@ -123,14 +115,14 @@ void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO* ProblemeH PALIERS_THERMIQUES* PaliersThermiquesDuPays; int* minUpDownTime; - NombreDePasDeTemps = ProblemeHebdo->NombreDePasDeTemps; - NbGrpCourbeGuide = ProblemeHebdo->NbGrpCourbeGuide; - NbGrpOpt = ProblemeHebdo->NbGrpOpt; + int NombreDePasDeTemps = problemeHebdo->NombreDePasDeTemps; + NbGrpCourbeGuide = problemeHebdo->NbGrpCourbeGuide; + NbGrpOpt = problemeHebdo->NbGrpOpt; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; ++Pays) + for (int Pays = 0; Pays < problemeHebdo->NombreDePays; ++Pays) { - ResultatsHoraires = ProblemeHebdo->ResultatsHoraires[Pays]; - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + ResultatsHoraires = problemeHebdo->ResultatsHoraires[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; PminDuPalierThermiquePendantUneHeure = PaliersThermiquesDuPays->PminDuPalierThermiquePendantUneHeure; TailleUnitaireDUnGroupeDuPalierThermique @@ -139,7 +131,7 @@ void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO* ProblemeH ProductionThermiqueOptimale = ResultatsHoraires->ProductionThermique; - for (Palier = 0; Palier < PaliersThermiquesDuPays->NombreDePaliersThermiques; Palier++) + for (int Palier = 0; Palier < PaliersThermiquesDuPays->NombreDePaliersThermiques; Palier++) { PuissanceDispoEtCout = PaliersThermiquesDuPays->PuissanceDisponibleEtCout[Palier]; PuissanceMinDuPalierThermique = PuissanceDispoEtCout->PuissanceMinDuPalierThermique; @@ -149,9 +141,9 @@ void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO* ProblemeH if (fabs(PminDuPalierThermiquePendantUneHeure[Palier]) < ZERO_PMIN) continue; - for (Pdt = 0; Pdt < NombreDePasDeTemps; Pdt++) + for (int Pdt = 0; Pdt < NombreDePasDeTemps; Pdt++) { - P = ProductionThermiqueOptimale[Pdt]->ProductionThermiqueDuPalier[Palier]; + double P = ProductionThermiqueOptimale[Pdt]->ProductionThermiqueDuPalier[Palier]; NbGrpCourbeGuide[Pdt] = 0; if (fabs(P) < ZERO_PMIN) @@ -176,7 +168,7 @@ void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO* ProblemeH if (IntervalleDAjustement < 0) IntervalleDAjustement = 0; - for (i = 0; i <= IntervalleDAjustement; i++) + for (int i = 0; i <= IntervalleDAjustement; i++) { PremierPdt = i; DernierPdt = NombreDePasDeTemps - IntervalleDAjustement + i; @@ -195,10 +187,12 @@ void OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(PROBLEME_HEBDO* ProblemeH PremierPdt = iOpt; DernierPdt = NombreDePasDeTemps - IntervalleDAjustement + iOpt; + //TODO vpayet: how is getting the return value useful ? + //Ecart is only assigned in the next loop Ecart = OPT_CalculerAireMaxPminJour( PremierPdt, DernierPdt, MUTetMDT, NombreDePasDeTemps, NbGrpCourbeGuide, NbGrpOpt); - for (Pdt = 0; Pdt < NombreDePasDeTemps; Pdt++) + for (int Pdt = 0; Pdt < NombreDePasDeTemps; Pdt++) { if (PminDuPalierThermiquePendantUneHeure[Palier] * NbGrpOpt[Pdt] > PuissanceMinDuPalierThermique[Pdt]) diff --git a/src/solver/optimisation/opt_chainage_intercos.cpp b/src/solver/optimisation/opt_chainage_intercos.cpp index fe54a0043b..17e6127241 100644 --- a/src/solver/optimisation/opt_chainage_intercos.cpp +++ b/src/solver/optimisation/opt_chainage_intercos.cpp @@ -32,7 +32,7 @@ #include "opt_fonctions.h" -void OPT_ChainagesDesIntercoPartantDUnNoeud(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_ChainagesDesIntercoPartantDUnNoeud(PROBLEME_HEBDO* problemeHebdo) { int Pays; int Interco; @@ -40,23 +40,23 @@ void OPT_ChainagesDesIntercoPartantDUnNoeud(PROBLEME_HEBDO* ProblemeHebdo) int NoeudOrigine; int NoeudExtremite; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - ProblemeHebdo->IndexDebutIntercoOrigine[Pays] = -1; - ProblemeHebdo->IndexDebutIntercoExtremite[Pays] = -1; + problemeHebdo->IndexDebutIntercoOrigine[Pays] = -1; + problemeHebdo->IndexDebutIntercoExtremite[Pays] = -1; } - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { - NoeudOrigine = ProblemeHebdo->PaysOrigineDeLInterconnexion[Interco]; - Index = ProblemeHebdo->IndexDebutIntercoOrigine[NoeudOrigine]; - ProblemeHebdo->IndexDebutIntercoOrigine[NoeudOrigine] = Interco; - ProblemeHebdo->IndexSuivantIntercoOrigine[Interco] = Index; - - NoeudExtremite = ProblemeHebdo->PaysExtremiteDeLInterconnexion[Interco]; - Index = ProblemeHebdo->IndexDebutIntercoExtremite[NoeudExtremite]; - ProblemeHebdo->IndexDebutIntercoExtremite[NoeudExtremite] = Interco; - ProblemeHebdo->IndexSuivantIntercoExtremite[Interco] = Index; + NoeudOrigine = problemeHebdo->PaysOrigineDeLInterconnexion[Interco]; + Index = problemeHebdo->IndexDebutIntercoOrigine[NoeudOrigine]; + problemeHebdo->IndexDebutIntercoOrigine[NoeudOrigine] = Interco; + problemeHebdo->IndexSuivantIntercoOrigine[Interco] = Index; + + NoeudExtremite = problemeHebdo->PaysExtremiteDeLInterconnexion[Interco]; + Index = problemeHebdo->IndexDebutIntercoExtremite[NoeudExtremite]; + problemeHebdo->IndexDebutIntercoExtremite[NoeudExtremite] = Interco; + problemeHebdo->IndexSuivantIntercoExtremite[Interco] = Index; } return; diff --git a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp index ab00ad85b3..a172486b24 100644 --- a/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_construction_contraintes_couts_demarrage.cpp @@ -42,7 +42,7 @@ #include "../simulation/sim_structure_donnees.h" void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( - PROBLEME_HEBDO* ProblemeHebdo, + PROBLEME_HEBDO* problemeHebdo, char Simulation) { int Index; @@ -58,7 +58,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( double PminDUnGroupeDuPalierThermique; double PmaxDUnGroupeDuPalierThermique; int NbTermesContraintesPourLesCoutsDeDemarrage; - int Var; + int var; CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; CORRESPONDANCES_DES_CONTRAINTES* CorrespondanceCntNativesCntOptim; PALIERS_THERMIQUES* PaliersThermiquesDuPays; @@ -68,18 +68,18 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( int Pdtmoins1; CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptimTmoins1; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; Pi = ProblemeAResoudre->Pi; Colonne = ProblemeAResoudre->Colonne; NbTermesContraintesPourLesCoutsDeDemarrage = 0; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { @@ -93,18 +93,18 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { CorrespondanceVarNativesVarOptim - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; + = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; NombreDeTermes = 0; if (Simulation == NON_ANTARES) { - Var + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -113,12 +113,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( if (Simulation == NON_ANTARES) { - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = -PmaxDUnGroupeDuPalierThermique; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -140,12 +140,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( if (Simulation == NON_ANTARES) { - Var + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -154,12 +154,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( if (Simulation == NON_ANTARES) { - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = -PminDUnGroupeDuPalierThermique; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -180,9 +180,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { @@ -192,23 +192,23 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { CorrespondanceVarNativesVarOptim - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; + = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; Pdtmoins1 = Pdt - 1; if (Pdtmoins1 < 0) Pdtmoins1 = NombreDePasDeTempsPourUneOptimisation + Pdtmoins1; CorrespondanceVarNativesVarOptimTmoins1 - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdtmoins1]; + = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdtmoins1]; NombreDeTermes = 0; if (Simulation == NON_ANTARES) { - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -217,12 +217,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( if (Simulation == NON_ANTARES) { - Var = CorrespondanceVarNativesVarOptimTmoins1 + var = CorrespondanceVarNativesVarOptimTmoins1 ->NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = -1; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -231,13 +231,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( if (Simulation == NON_ANTARES) { - Var + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesQuiDemarrentDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = -1; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -246,13 +246,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( if (Simulation == NON_ANTARES) { - Var + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -273,9 +273,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { @@ -285,7 +285,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { CorrespondanceCntNativesCntOptim - = ProblemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; + = problemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; CorrespondanceCntNativesCntOptim ->NumeroDeContrainteDesContraintesDeDureeMinDeMarche[Palier] = -1; @@ -293,13 +293,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( NombreDeTermes = 0; if (Simulation == NON_ANTARES) { - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariableDuNombreDeGroupesQuiTombentEnPanneDuPalierThermique [Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -308,13 +308,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( if (Simulation == NON_ANTARES) { - Var - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var + = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -336,9 +336,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( } #if VARIABLES_MMOINS_MOINS_BORNEES_DES_2_COTES != OUI_ANTARES - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { @@ -348,22 +348,22 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { CorrespondanceCntNativesCntOptim - = ProblemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; + = problemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; CorrespondanceCntNativesCntOptim ->NumeroDeLaDeuxiemeContrainteDesContraintesDesGroupesQuiTombentEnPanne[Palier] = -1; NombreDeTermes = 0; - Var = 0; + var = 0; if (Simulation == NON_ANTARES) { - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariableDuNombreDeGroupesQuiTombentEnPanneDuPalierThermique [Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -390,9 +390,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( } #endif - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { @@ -406,7 +406,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { CorrespondanceCntNativesCntOptim - = ProblemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; + = problemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; CorrespondanceCntNativesCntOptim ->NumeroDeContrainteDesContraintesDeDureeMinDeMarche[Palier] = -1; @@ -414,12 +414,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( NombreDeTermes = 0; if (Simulation == NON_ANTARES) { - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -434,13 +434,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( if (Simulation == NON_ANTARES) { - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[t1] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[t1] ->NumeroDeVariableDuNombreDeGroupesQuiDemarrentDuPalierThermique [Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -449,14 +449,14 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( if (Simulation == NON_ANTARES) { - Var - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[t1] + var + = problemeHebdo->CorrespondanceVarNativesVarOptim[t1] ->NumeroDeVariableDuNombreDeGroupesQuiTombentEnPanneDuPalierThermique [Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -482,9 +482,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { @@ -496,13 +496,13 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { CorrespondanceCntNativesCntOptim - = ProblemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; + = problemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; CorrespondanceCntNativesCntOptim ->NumeroDeContrainteDesContraintesDeDureeMinDArret[Palier] = -1; CorrespondanceVarNativesVarOptim - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; + = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; if (Simulation == NON_ANTARES) { @@ -514,12 +514,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( NombreDeTermes = 0; if (Simulation == NON_ANTARES) { - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -533,16 +533,16 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( t1 = NombreDePasDeTempsPourUneOptimisation + t1; CorrespondanceVarNativesVarOptim - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[t1]; + = problemeHebdo->CorrespondanceVarNativesVarOptim[t1]; if (Simulation == NON_ANTARES) { - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique [Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -568,7 +568,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage( } if (Simulation == OUI_ANTARES) - ProblemeHebdo->NbTermesContraintesPourLesCoutsDeDemarrage + problemeHebdo->NbTermesContraintesPourLesCoutsDeDemarrage = NbTermesContraintesPourLesCoutsDeDemarrage; return; diff --git a/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_lineaire.cpp b/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_lineaire.cpp index af3c52ab49..d4d030fc6e 100644 --- a/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_lineaire.cpp +++ b/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_lineaire.cpp @@ -38,13 +38,13 @@ using namespace Antares::Data; -void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* problemeHebdo) { int Interco; int Index; int Pays; int Pdt; - int Var; + int var; int Palier; int layerindex; int NbInterco, NbClusters; @@ -58,9 +58,9 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro int Semaine; int* NumeroDeJourDuPasDeTemps; int Pdt1; - int Var1; - int Var2; - int Var3; + int var1; + int var2; + int var3; int Offset; char Simulation; @@ -80,14 +80,14 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro std::string NomDeLaContrainte; Study::Ptr study = Study::Current::Get(); - const bool exportStructure = ProblemeHebdo->ExportStructure; - const bool firstWeekOfSimulation = ProblemeHebdo->firstWeekOfSimulation; + const bool exportStructure = problemeHebdo->ExportStructure; + const bool firstWeekOfSimulation = problemeHebdo->firstWeekOfSimulation; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - NombreDePasDeTempsDUneJournee = ProblemeHebdo->NombreDePasDeTempsDUneJournee; - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; - NumeroDeJourDuPasDeTemps = ProblemeHebdo->NumeroDeJourDuPasDeTemps; + NombreDePasDeTempsDUneJournee = problemeHebdo->NombreDePasDeTempsDUneJournee; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + NumeroDeJourDuPasDeTemps = problemeHebdo->NumeroDeJourDuPasDeTemps; Pi = ProblemeAResoudre->Pi; Colonne = ProblemeAResoudre->Colonne; @@ -102,78 +102,78 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { - int timeStepInYear = ProblemeHebdo->weekInTheYear * 168 + Pdt; + int timeStepInYear = problemeHebdo->weekInTheYear * 168 + Pdt; - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; - CorrespondanceCntNativesCntOptim = ProblemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; + CorrespondanceCntNativesCntOptim = problemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { NombreDeTermes = 0; - Interco = ProblemeHebdo->IndexDebutIntercoOrigine[Pays]; + Interco = problemeHebdo->IndexDebutIntercoOrigine[Pays]; while (Interco >= 0) { - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable( varname, - Var, + var, Enum::ExportStructDict::ValeurDeNTCOrigineVersExtremite, timeStepInYear, // TODO[FOM] remove Pays, Interco); } } - Interco = ProblemeHebdo->IndexSuivantIntercoOrigine[Interco]; + Interco = problemeHebdo->IndexSuivantIntercoOrigine[Interco]; } - Interco = ProblemeHebdo->IndexDebutIntercoExtremite[Pays]; + Interco = problemeHebdo->IndexDebutIntercoExtremite[Pays]; while (Interco >= 0) { - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable( varname, - Var, + var, Enum::ExportStructDict::ValeurDeNTCOrigineVersExtremite, timeStepInYear, // TODO[FOM] remove Pays, Interco); } } - Interco = ProblemeHebdo->IndexSuivantIntercoExtremite[Interco]; + Interco = problemeHebdo->IndexSuivantIntercoExtremite[Interco]; } - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { Palier = PaliersThermiquesDuPays->NumeroDuPalierDansLEnsembleDesPaliersThermiques[Index]; - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable(varname, - Var, + var, Enum::ExportStructDict::PalierThermique, timeStepInYear, // TODO[FOM] remove Pays, @@ -182,55 +182,55 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable( - varname, Var, Enum::ExportStructDict::ProdHyd, timeStepInYear, Pays); + varname, var, Enum::ExportStructDict::ProdHyd, timeStepInYear, Pays); } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable(varname, - Var, + var, Enum::ExportStructDict::DefaillancePositive, timeStepInYear, // TODO[FOM] remove Pays); } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable(varname, - Var, + var, Enum::ExportStructDict::DefaillanceNegative, timeStepInYear, // TODO[FOM] remove Pays); @@ -245,22 +245,22 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro NombreDeTermes = 0; - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { Palier = PaliersThermiquesDuPays->NumeroDuPalierDansLEnsembleDesPaliersThermiques[Index]; - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable(varname, - Var, + var, Enum::ExportStructDict::PalierThermique, timeStepInYear, // TODO[FOM] remove Pays, @@ -269,31 +269,31 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; + if (var >= 0) { - Pi[NombreDeTermes] = -ProblemeHebdo->DefaillanceNegativeUtiliserHydro[Pays]; - Colonne[NombreDeTermes] = Var; + Pi[NombreDeTermes] = -problemeHebdo->DefaillanceNegativeUtiliserHydro[Pays]; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable( - varname, Var, Enum::ExportStructDict::ProdHyd, timeStepInYear, Pays); + varname, var, Enum::ExportStructDict::ProdHyd, timeStepInYear, Pays); } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable(varname, - Var, + var, Enum::ExportStructDict::DefaillanceNegative, timeStepInYear, // TODO[FOM] remove Pays); @@ -304,65 +304,65 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro = ProblemeAResoudre->NombreDeContraintes; NomDeLaContrainte = "fict_load::" + std::to_string(timeStepInYear + 1) - + "::" + ProblemeHebdo->NomsDesPays[Pays]; + + "::" + problemeHebdo->NomsDesPays[Pays]; OPT_ChargerLaContrainteDansLaMatriceDesContraintes( ProblemeAResoudre, Pi, Colonne, NombreDeTermes, '<', NomDeLaContrainte); } - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { - CoutDeTransport = ProblemeHebdo->CoutDeTransport[Interco]; + CoutDeTransport = problemeHebdo->CoutDeTransport[Interco]; if (CoutDeTransport->IntercoGereeAvecDesCouts == OUI_ANTARES) { NombreDeTermes = 0; - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable(varname, - Var, + var, Enum::ExportStructDict::DefaillanceNegative, timeStepInYear, // TODO[FOM] remove Pays); } } - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[Interco]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable( varname, - Var, + var, Enum::ExportStructDict::CoutOrigineVersExtremiteDeLInterconnexion, timeStepInYear, // TODO[FOM] remove Interco); } } - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[Interco]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable( varname, - Var, + var, Enum::ExportStructDict::CoutExtremiteVersOrigineDeLInterconnexion, timeStepInYear, // TODO[FOM] remove Interco); @@ -377,11 +377,11 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } } - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { MatriceDesContraintesCouplantes - = ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; + = problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante == CONTRAINTE_HORAIRE) { @@ -400,17 +400,17 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } else { - Pdt1 = (Pdt + Offset + ProblemeHebdo->NombreDePasDeTemps) + Pdt1 = (Pdt + Offset + problemeHebdo->NombreDePasDeTemps) % NombreDePasDeTempsPourUneOptimisation; } - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] ->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = Poids; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -420,7 +420,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro for (Index = 0; Index < NbClusters; Index++) { Pays = MatriceDesContraintesCouplantes->PaysDuPalierDispatch[Index]; - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; Palier = PaliersThermiquesDuPays->NumeroDuPalierDansLEnsembleDesPaliersThermiques [MatriceDesContraintesCouplantes->NumeroDuPalierDispatch[Index]]; @@ -434,24 +434,24 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } else { - Pdt1 = (Pdt + Offset + ProblemeHebdo->NombreDePasDeTemps) + Pdt1 = (Pdt + Offset + problemeHebdo->NombreDePasDeTemps) % NombreDePasDeTempsPourUneOptimisation; } - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] ->NumeroDeVariableDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = Poids; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; if (exportStructure) { OPT_Export_add_variable( varname, - Var, + var, Enum::ExportStructDict::CorrespondanceVarNativesVarOptim, Pdt1, // TODO[FOM] remove Palier); @@ -477,11 +477,11 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } } - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { MatriceDesContraintesCouplantes - = ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; + = problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante == CONTRAINTE_JOURNALIERE) { NbInterco @@ -493,7 +493,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro { Jour = NumeroDeJourDuPasDeTemps[PdtDebut]; CorrespondanceCntNativesCntOptimJournalieres - = ProblemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[Jour]; + = problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[Jour]; NombreDeTermes = 0; for (Index = 0; Index < NbInterco; Index++) @@ -510,16 +510,16 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } else { - Pdt1 = (Pdt + Offset + ProblemeHebdo->NombreDePasDeTemps) + Pdt1 = (Pdt + Offset + problemeHebdo->NombreDePasDeTemps) % NombreDePasDeTempsPourUneOptimisation; } - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] ->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = Poids; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -528,7 +528,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro for (Index = 0; Index < NbClusters; Index++) { Pays = MatriceDesContraintesCouplantes->PaysDuPalierDispatch[Index]; - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; Palier = PaliersThermiquesDuPays->NumeroDuPalierDansLEnsembleDesPaliersThermiques [MatriceDesContraintesCouplantes->NumeroDuPalierDispatch[Index]]; @@ -544,16 +544,16 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } else { - Pdt1 = (Pdt + Offset + ProblemeHebdo->NombreDePasDeTemps) + Pdt1 = (Pdt + Offset + problemeHebdo->NombreDePasDeTemps) % NombreDePasDeTempsPourUneOptimisation; } - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] ->NumeroDeVariableDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = Poids; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -579,17 +579,17 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } } - if (ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation - > ProblemeHebdo->NombreDePasDeTempsDUneJournee) + if (problemeHebdo->NombreDePasDeTempsPourUneOptimisation + > problemeHebdo->NombreDePasDeTempsDUneJournee) { Semaine = 0; CorrespondanceCntNativesCntOptimHebdomadaires - = ProblemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires[Semaine]; - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires[Semaine]; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { MatriceDesContraintesCouplantes - = ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; + = problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante == CONTRAINTE_HEBDOMADAIRE) { @@ -609,16 +609,16 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } else { - Pdt1 = (Pdt + Offset + ProblemeHebdo->NombreDePasDeTemps) + Pdt1 = (Pdt + Offset + problemeHebdo->NombreDePasDeTemps) % NombreDePasDeTempsPourUneOptimisation; } - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] ->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = Poids; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -629,7 +629,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro for (Index = 0; Index < NbClusters; Index++) { Pays = MatriceDesContraintesCouplantes->PaysDuPalierDispatch[Index]; - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; Palier = PaliersThermiquesDuPays->NumeroDuPalierDansLEnsembleDesPaliersThermiques [MatriceDesContraintesCouplantes->NumeroDuPalierDispatch[Index]]; @@ -644,16 +644,16 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } else { - Pdt1 = (Pdt + Offset + ProblemeHebdo->NombreDePasDeTemps) + Pdt1 = (Pdt + Offset + problemeHebdo->NombreDePasDeTemps) % NombreDePasDeTempsPourUneOptimisation; } - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] ->NumeroDeVariableDuPalierThermique[Palier]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = Poids; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -677,14 +677,14 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { char presenceHydro - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; char TurbEntreBornes - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; char presencePompage - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable; if (presenceHydro == OUI_ANTARES && TurbEntreBornes == NON_ANTARES) { NombreDeTermes = 0; @@ -692,12 +692,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro { for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } @@ -706,82 +706,82 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro { for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariablesDePompage[Pays]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PumpingRatio; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PumpingRatio; Pi[NombreDeTermes] *= -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } } - ProblemeHebdo->NumeroDeContrainteEnergieHydraulique[Pays] + problemeHebdo->NumeroDeContrainteEnergieHydraulique[Pays] = ProblemeAResoudre->NombreDeContraintes; OPT_ChargerLaContrainteDansLaMatriceDesContraintes( ProblemeAResoudre, Pi, Colonne, NombreDeTermes, '='); } else - ProblemeHebdo->NumeroDeContrainteEnergieHydraulique[Pays] = -1; + problemeHebdo->NumeroDeContrainteEnergieHydraulique[Pays] = -1; } - if (ProblemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) + if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) { - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable != OUI_ANTARES) continue; for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { CorrespondanceVarNativesVarOptim - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; + = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; NombreDeTermes = 0; - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } Pdt1 = Pdt + 1; if (Pdt1 >= NombreDePasDeTempsPourUneOptimisation) Pdt1 = 0; - Var1 = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] + var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt1] ->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var1 >= 0) + if (var1 >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var1; + Colonne[NombreDeTermes] = var1; NombreDeTermes++; } - Var2 + var2 = CorrespondanceVarNativesVarOptim->NumeroDeVariablesVariationHydALaBaisse[Pays]; - if (Var2 >= 0) + if (var2 >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var2; + Colonne[NombreDeTermes] = var2; NombreDeTermes++; } - Var3 + var3 = CorrespondanceVarNativesVarOptim->NumeroDeVariablesVariationHydALaHausse[Pays]; - if (Var3 >= 0) + if (var3 >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var3; + Colonne[NombreDeTermes] = var3; NombreDeTermes++; } @@ -790,32 +790,32 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } } } - else if (ProblemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_VARIATION_MAX) + else if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_VARIATION_MAX) { - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable != OUI_ANTARES) continue; for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { CorrespondanceVarNativesVarOptim - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; + = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; NombreDeTermes = 0; - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - Var1 = ProblemeHebdo->CorrespondanceVarNativesVarOptim[0] + var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[0] ->NumeroDeVariablesVariationHydALaBaisse[Pays]; - if (Var1 >= 0) + if (var1 >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var1; + Colonne[NombreDeTermes] = var1; NombreDeTermes++; } @@ -823,18 +823,18 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro ProblemeAResoudre, Pi, Colonne, NombreDeTermes, '<'); NombreDeTermes = 0; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - Var1 = ProblemeHebdo->CorrespondanceVarNativesVarOptim[0] + var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[0] ->NumeroDeVariablesVariationHydALaHausse[Pays]; - if (Var1 >= 0) + if (var1 >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var1; + Colonne[NombreDeTermes] = var1; NombreDeTermes++; } @@ -844,152 +844,152 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { const char presenceHydro - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; const char presencePompage - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable; const char TurbEntreBornes - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; if (presenceHydro == OUI_ANTARES && (TurbEntreBornes == OUI_ANTARES || presencePompage == OUI_ANTARES)) { NombreDeTermes = 0; for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } - ProblemeHebdo->NumeroDeContrainteMinEnergieHydraulique[Pays] + problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[Pays] = ProblemeAResoudre->NombreDeContraintes; OPT_ChargerLaContrainteDansLaMatriceDesContraintes( ProblemeAResoudre, Pi, Colonne, NombreDeTermes, '>'); } else - ProblemeHebdo->NumeroDeContrainteMinEnergieHydraulique[Pays] = -1; + problemeHebdo->NumeroDeContrainteMinEnergieHydraulique[Pays] = -1; if (presenceHydro == OUI_ANTARES && (TurbEntreBornes == OUI_ANTARES - || ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable + || problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable == OUI_ANTARES)) { NombreDeTermes = 0; for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } - ProblemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[Pays] + problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[Pays] = ProblemeAResoudre->NombreDeContraintes; OPT_ChargerLaContrainteDansLaMatriceDesContraintes( ProblemeAResoudre, Pi, Colonne, NombreDeTermes, '<'); } else - ProblemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[Pays] = -1; + problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique[Pays] = -1; } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable == OUI_ANTARES) { NombreDeTermes = 0; for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { - Var = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] + var = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt] ->NumeroDeVariablesDePompage[Pays]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } - ProblemeHebdo->NumeroDeContrainteMaxPompage[Pays] + problemeHebdo->NumeroDeContrainteMaxPompage[Pays] = ProblemeAResoudre->NombreDeContraintes; OPT_ChargerLaContrainteDansLaMatriceDesContraintes( ProblemeAResoudre, Pi, Colonne, NombreDeTermes, '<'); } else - ProblemeHebdo->NumeroDeContrainteMaxPompage[Pays] = -1; + problemeHebdo->NumeroDeContrainteMaxPompage[Pays] = -1; } for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; - CorrespondanceCntNativesCntOptim = ProblemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; + CorrespondanceCntNativesCntOptim = problemeHebdo->CorrespondanceCntNativesCntOptim[Pdt]; - int timeStepInYear = ProblemeHebdo->weekInTheYear * 168 + Pdt; + int timeStepInYear = problemeHebdo->weekInTheYear * 168 + Pdt; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire == OUI_ANTARES) { NombreDeTermes = 0; - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeNiveau[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeNiveau[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } if (Pdt > 0) { - Var1 = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt - 1] + var1 = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt - 1] ->NumeroDeVariablesDeNiveau[Pays]; - if (Var1 >= 0) + if (var1 >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var1; + Colonne[NombreDeTermes] = var1; NombreDeTermes++; } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays]; + if (var >= 0) { Pi[NombreDeTermes] - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PumpingRatio; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PumpingRatio; Pi[NombreDeTermes] *= -1; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeDebordement[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeDebordement[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = 1.; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } @@ -997,7 +997,7 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro = ProblemeAResoudre->NombreDeContraintes; NomDeLaContrainte = "hydro_level::" + std::to_string(timeStepInYear + 1) - + "::" + ProblemeHebdo->NomsDesPays[Pays]; + + "::" + problemeHebdo->NomsDesPays[Pays]; OPT_ChargerLaContrainteDansLaMatriceDesContraintes( ProblemeAResoudre, Pi, Colonne, NombreDeTermes, '=', NomDeLaContrainte); @@ -1008,59 +1008,59 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } /* For each area with ad hoc properties, two possible sets of two additional constraints */ - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES - && ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->DirectLevelAccess == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES + && problemeHebdo->CaracteristiquesHydrauliques[Pays]->DirectLevelAccess == OUI_ANTARES) /* equivalence constraint : StockFinal- Niveau[T]= 0*/ { NombreDeTermes = 0; - Var = ProblemeHebdo->NumeroDeVariableStockFinal[Pays]; - if (Var >= 0) + var = problemeHebdo->NumeroDeVariableStockFinal[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - Var = ProblemeHebdo + var = problemeHebdo ->CorrespondanceVarNativesVarOptim[NombreDePasDeTempsPourUneOptimisation - 1] ->NumeroDeVariablesDeNiveau[Pays]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - ProblemeHebdo->NumeroDeContrainteEquivalenceStockFinal[Pays] + problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[Pays] = ProblemeAResoudre->NombreDeContraintes; OPT_ChargerLaContrainteDansLaMatriceDesContraintes( ProblemeAResoudre, Pi, Colonne, NombreDeTermes, '='); } - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) /* expression constraint : - StockFinal +sum (stocklayers) = 0*/ { NombreDeTermes = 0; - Var = ProblemeHebdo->NumeroDeVariableStockFinal[Pays]; - if (Var >= 0) + var = problemeHebdo->NumeroDeVariableStockFinal[Pays]; + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } for (layerindex = 0; layerindex < 100; layerindex++) { - Var = ProblemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][layerindex]; + var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][layerindex]; - if (Var >= 0) + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } } - ProblemeHebdo->NumeroDeContrainteExpressionStockFinal[Pays] + problemeHebdo->NumeroDeContrainteExpressionStockFinal[Pays] = ProblemeAResoudre->NombreDeContraintes; OPT_ChargerLaContrainteDansLaMatriceDesContraintes( @@ -1068,10 +1068,10 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro } } - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) { Simulation = NON_ANTARES; - OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(ProblemeHebdo, + OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(problemeHebdo, Simulation); } @@ -1080,12 +1080,12 @@ void OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(PROBLEME_HEBDO* Pro { if (firstWeekOfSimulation) { - OPT_ExportInterco(study->resultWriter, ProblemeHebdo); + OPT_ExportInterco(study->resultWriter, problemeHebdo); OPT_ExportAreaName(study->resultWriter, study->areas); } const auto filename = getFilenameWithExtension( - "variables", "txt", ProblemeHebdo->year, ProblemeHebdo->weekInTheYear, 0); + "variables", "txt", problemeHebdo->year, problemeHebdo->weekInTheYear, 0); OPT_ExportVariables(study->resultWriter, varname, filename); } diff --git a/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_quadratique.cpp b/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_quadratique.cpp index 7f6c2f69f8..d47d046e9b 100644 --- a/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_quadratique.cpp +++ b/src/solver/optimisation/opt_construction_matrice_des_contraintes_cas_quadratique.cpp @@ -32,56 +32,56 @@ #include "../simulation/sim_extern_variables_globales.h" #include "opt_fonctions.h" -void OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique(PROBLEME_HEBDO* problemeHebdo) { int Interco; int Pays; - int Var; + int var; int NombreDeTermes; double* Pi; int* Colonne; CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; Pi = (double*)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(double)); Colonne = (int*)MemAlloc(ProblemeAResoudre->NombreDeVariables * sizeof(int)); ProblemeAResoudre->NombreDeContraintes = 0; ProblemeAResoudre->NombreDeTermesDansLaMatriceDesContraintes = 0; - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[0]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[0]; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays - 1; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays - 1; Pays++) { NombreDeTermes = 0; - Interco = ProblemeHebdo->IndexDebutIntercoOrigine[Pays]; + Interco = problemeHebdo->IndexDebutIntercoOrigine[Pays]; while (Interco >= 0) { - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + if (var >= 0) { Pi[NombreDeTermes] = 1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - Interco = ProblemeHebdo->IndexSuivantIntercoOrigine[Interco]; + Interco = problemeHebdo->IndexSuivantIntercoOrigine[Interco]; } - Interco = ProblemeHebdo->IndexDebutIntercoExtremite[Pays]; + Interco = problemeHebdo->IndexDebutIntercoExtremite[Pays]; while (Interco >= 0) { - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + if (var >= 0) { Pi[NombreDeTermes] = -1.0; - Colonne[NombreDeTermes] = Var; + Colonne[NombreDeTermes] = var; NombreDeTermes++; } - Interco = ProblemeHebdo->IndexSuivantIntercoExtremite[Interco]; + Interco = problemeHebdo->IndexSuivantIntercoExtremite[Interco]; } - ProblemeHebdo->NumeroDeContrainteDeSoldeDEchange[Pays] + problemeHebdo->NumeroDeContrainteDeSoldeDEchange[Pays] = ProblemeAResoudre->NombreDeContraintes; OPT_ChargerLaContrainteDansLaMatriceDesContraintes( diff --git a/src/solver/optimisation/opt_construction_variables_couts_demarrages.cpp b/src/solver/optimisation/opt_construction_variables_couts_demarrages.cpp index 389f07e390..dcebad6f81 100644 --- a/src/solver/optimisation/opt_construction_variables_couts_demarrages.cpp +++ b/src/solver/optimisation/opt_construction_variables_couts_demarrages.cpp @@ -37,7 +37,7 @@ #include "spx_constantes_externes.h" void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaireCoutsDeDemarrage( - PROBLEME_HEBDO* ProblemeHebdo, + PROBLEME_HEBDO* problemeHebdo, char Simulation) { int Pays; @@ -50,14 +50,14 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaireCoutsDeDemarra PALIERS_THERMIQUES* PaliersThermiquesDuPays; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; NombreDeVariables = ProblemeAResoudre->NombreDeVariables; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { @@ -72,7 +72,7 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaireCoutsDeDemarra continue; } CorrespondanceVarNativesVarOptim - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; + = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[Palier] diff --git a/src/solver/optimisation/opt_construction_variables_optimisees_lineaire.cpp b/src/solver/optimisation/opt_construction_variables_optimisees_lineaire.cpp index 646d57bfa0..69532c6df0 100644 --- a/src/solver/optimisation/opt_construction_variables_optimisees_lineaire.cpp +++ b/src/solver/optimisation/opt_construction_variables_optimisees_lineaire.cpp @@ -35,7 +35,7 @@ #include "spx_constantes_externes.h" -void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBDO* problemeHebdo) { int Interco; int Pays; @@ -50,24 +50,24 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD COUTS_DE_TRANSPORT* CoutDeTransport; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; NombreDeVariables = 0; for (Pdt = 0; Pdt < NombreDePasDeTempsPourUneOptimisation; Pdt++) { - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[Pdt]; - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco] = NombreDeVariables; ProblemeAResoudre->TypeDeVariable[NombreDeVariables] = VARIABLE_BORNEE_DES_DEUX_COTES; NombreDeVariables++; - CoutDeTransport = ProblemeHebdo->CoutDeTransport[Interco]; + CoutDeTransport = problemeHebdo->CoutDeTransport[Interco]; if (CoutDeTransport->IntercoGereeAvecDesCouts == OUI_ANTARES) { CorrespondanceVarNativesVarOptim @@ -85,9 +85,9 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { Palier @@ -112,9 +112,9 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD NombreDeVariables++; } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable == OUI_ANTARES) { CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays] @@ -128,10 +128,10 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD CorrespondanceVarNativesVarOptim->NumeroDeVariablesVariationHydALaBaisse[Pays] = -1; CorrespondanceVarNativesVarOptim->NumeroDeVariablesVariationHydALaHausse[Pays] = -1; - if (ProblemeHebdo->TypeDeLissageHydraulique + if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable == OUI_ANTARES) { CorrespondanceVarNativesVarOptim->NumeroDeVariablesVariationHydALaBaisse[Pays] @@ -146,10 +146,10 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD NombreDeVariables++; } } - else if (ProblemeHebdo->TypeDeLissageHydraulique + else if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_VARIATION_MAX) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable == OUI_ANTARES) { if (Pdt == 0) @@ -172,7 +172,7 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD } } - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable == OUI_ANTARES) { CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays] @@ -184,7 +184,7 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD else CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays] = -1; - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire == OUI_ANTARES) { CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeNiveau[Pays] @@ -206,17 +206,17 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) { - ProblemeHebdo->NumeroDeVariableStockFinal[Pays] = NombreDeVariables; + problemeHebdo->NumeroDeVariableStockFinal[Pays] = NombreDeVariables; ProblemeAResoudre->TypeDeVariable[NombreDeVariables] = VARIABLE_NON_BORNEE; NombreDeVariables++; for (uint nblayer = 0; nblayer < 100; nblayer++) { - ProblemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][nblayer] = NombreDeVariables; + problemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][nblayer] = NombreDeVariables; ProblemeAResoudre->TypeDeVariable[NombreDeVariables] = VARIABLE_BORNEE_DES_DEUX_COTES; NombreDeVariables++; @@ -224,20 +224,20 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(PROBLEME_HEBD } else { - ProblemeHebdo->NumeroDeVariableStockFinal[Pays] = -1; + problemeHebdo->NumeroDeVariableStockFinal[Pays] = -1; for (uint nblayer = 0; nblayer < 100; nblayer++) { - ProblemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][nblayer] = -1; + problemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][nblayer] = -1; } } } ProblemeAResoudre->NombreDeVariables = NombreDeVariables; - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) { Simulation = NON_ANTARES; - OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaireCoutsDeDemarrage(ProblemeHebdo, + OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaireCoutsDeDemarrage(problemeHebdo, Simulation); } diff --git a/src/solver/optimisation/opt_construction_variables_optimisees_quadratique.cpp b/src/solver/optimisation/opt_construction_variables_optimisees_quadratique.cpp index 46440a51c9..37671d8f36 100644 --- a/src/solver/optimisation/opt_construction_variables_optimisees_quadratique.cpp +++ b/src/solver/optimisation/opt_construction_variables_optimisees_quadratique.cpp @@ -35,7 +35,7 @@ #include "pi_constantes_externes.h" -void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeQuadratique(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeQuadratique(PROBLEME_HEBDO* problemeHebdo) { PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; int Interco; @@ -43,12 +43,12 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeQuadratique(PROBLEME_H CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; assert(ProblemeAResoudre != NULL); - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[0]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[0]; - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco] = NombreDeVariables; @@ -56,4 +56,4 @@ void OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeQuadratique(PROBLEME_H NombreDeVariables++; } ProblemeAResoudre->NombreDeVariables = NombreDeVariables; -} +} \ No newline at end of file diff --git a/src/solver/optimisation/opt_decompte_variables_et_contraintes.cpp b/src/solver/optimisation/opt_decompte_variables_et_contraintes.cpp index 5ea3de10e5..80aeb1ec61 100644 --- a/src/solver/optimisation/opt_decompte_variables_et_contraintes.cpp +++ b/src/solver/optimisation/opt_decompte_variables_et_contraintes.cpp @@ -38,7 +38,7 @@ using namespace Antares; -void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO* ProblemeHebdo, +void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO* problemeHebdo, int* MxPalierThermique) { int Pays; @@ -48,34 +48,34 @@ void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO int NombreDeJoursDansUnIntervalleOptimise; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; MxPaliers = 0; - ProblemeAResoudre->NombreDeVariables = ProblemeHebdo->NombreDInterconnexions; + ProblemeAResoudre->NombreDeVariables = problemeHebdo->NombreDInterconnexions; - ProblemeAResoudre->NombreDeVariables += 2 * ProblemeHebdo->NombreDInterconnexions; + ProblemeAResoudre->NombreDeVariables += 2 * problemeHebdo->NombreDInterconnexions; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { ProblemeAResoudre->NombreDeVariables - += ProblemeHebdo->PaliersThermiquesDuPays[Pays]->NombreDePaliersThermiques; + += problemeHebdo->PaliersThermiquesDuPays[Pays]->NombreDePaliersThermiques; - MxPaliers += ProblemeHebdo->PaliersThermiquesDuPays[Pays]->NombreDePaliersThermiques; + MxPaliers += problemeHebdo->PaliersThermiquesDuPays[Pays]->NombreDePaliersThermiques; - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable == OUI_ANTARES) { ProblemeAResoudre->NombreDeVariables++; } - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable == OUI_ANTARES) { ProblemeAResoudre->NombreDeVariables++; } - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire == OUI_ANTARES) { ProblemeAResoudre->NombreDeVariables++; ProblemeAResoudre->NombreDeVariables++; @@ -85,25 +85,25 @@ void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO } ProblemeAResoudre->NombreDeVariables *= NombreDePasDeTempsPourUneOptimisation; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) { ProblemeAResoudre->NombreDeVariables += 1; /* Final Stock Level */ ProblemeAResoudre->NombreDeVariables += 100; /* Reservoir layers */ } } - ProblemeAResoudre->NombreDeContraintes = ProblemeHebdo->NombreDePays; + ProblemeAResoudre->NombreDeContraintes = problemeHebdo->NombreDePays; - ProblemeAResoudre->NombreDeContraintes += ProblemeHebdo->NombreDePays; + ProblemeAResoudre->NombreDeContraintes += problemeHebdo->NombreDePays; - ProblemeAResoudre->NombreDeContraintes += ProblemeHebdo->NombreDInterconnexions; + ProblemeAResoudre->NombreDeContraintes += problemeHebdo->NombreDInterconnexions; - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { - if (ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]->TypeDeContrainteCouplante + if (problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]->TypeDeContrainteCouplante == CONTRAINTE_HORAIRE) { ProblemeAResoudre->NombreDeContraintes++; @@ -111,30 +111,30 @@ void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO } ProblemeAResoudre->NombreDeContraintes *= NombreDePasDeTempsPourUneOptimisation; - if (NombreDePasDeTempsPourUneOptimisation > ProblemeHebdo->NombreDePasDeTempsDUneJournee) + if (NombreDePasDeTempsPourUneOptimisation > problemeHebdo->NombreDePasDeTempsDUneJournee) { NombreDeJoursDansUnIntervalleOptimise - = ProblemeHebdo->NombreDePasDeTemps / ProblemeHebdo->NombreDePasDeTempsDUneJournee; + = problemeHebdo->NombreDePasDeTemps / problemeHebdo->NombreDePasDeTempsDUneJournee; } else NombreDeJoursDansUnIntervalleOptimise = 1; - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { - if (ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]->TypeDeContrainteCouplante + if (problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]->TypeDeContrainteCouplante == CONTRAINTE_JOURNALIERE) { ProblemeAResoudre->NombreDeContraintes += NombreDeJoursDansUnIntervalleOptimise; } } - if (NombreDePasDeTempsPourUneOptimisation > ProblemeHebdo->NombreDePasDeTempsDUneJournee) + if (NombreDePasDeTempsPourUneOptimisation > problemeHebdo->NombreDePasDeTempsDUneJournee) { - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { - if (ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante] + if (problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante] ->TypeDeContrainteCouplante == CONTRAINTE_HEBDOMADAIRE) { @@ -143,18 +143,18 @@ void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - char Pump = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable; + char Pump = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable; char TurbEntreBornes - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; char MonitorHourlyLev - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire; if (Pump == NON_ANTARES && TurbEntreBornes == NON_ANTARES && MonitorHourlyLev == NON_ANTARES) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable == OUI_ANTARES) { ProblemeAResoudre->NombreDeContraintes++; @@ -239,19 +239,19 @@ void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable == OUI_ANTARES) { - if (ProblemeHebdo->TypeDeLissageHydraulique + if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) { ProblemeAResoudre->NombreDeVariables += NombreDePasDeTempsPourUneOptimisation * 2; ProblemeAResoudre->NombreDeContraintes += NombreDePasDeTempsPourUneOptimisation; } - else if (ProblemeHebdo->TypeDeLissageHydraulique + else if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_VARIATION_MAX) { ProblemeAResoudre->NombreDeVariables += 2; @@ -260,9 +260,9 @@ void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) { ProblemeAResoudre->NombreDeContraintes += 2; /* Final Stock Level : (1 equivalence cnt + 1 expression cnt )*/ @@ -271,9 +271,9 @@ void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO *MxPalierThermique = MxPaliers; - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) { - OPT_DecompteDesVariablesEtDesContraintesCoutsDeDemarrage(ProblemeHebdo); + OPT_DecompteDesVariablesEtDesContraintesCoutsDeDemarrage(problemeHebdo); } return; diff --git a/src/solver/optimisation/opt_decompte_variables_et_contraintes_couts_demarrage.cpp b/src/solver/optimisation/opt_decompte_variables_et_contraintes_couts_demarrage.cpp index ddeac416e8..1f6dd158c0 100644 --- a/src/solver/optimisation/opt_decompte_variables_et_contraintes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_decompte_variables_et_contraintes_couts_demarrage.cpp @@ -33,19 +33,19 @@ #include "opt_fonctions.h" -void OPT_DecompteDesVariablesEtDesContraintesCoutsDeDemarrage(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_DecompteDesVariablesEtDesContraintesCoutsDeDemarrage(PROBLEME_HEBDO* problemeHebdo) { char Simulation; - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == NON_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == NON_ANTARES) return; Simulation = OUI_ANTARES; - OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(ProblemeHebdo, + OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaireCoutsDeDemarrage(problemeHebdo, Simulation); - OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaireCoutsDeDemarrage(ProblemeHebdo, + OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaireCoutsDeDemarrage(problemeHebdo, Simulation); return; diff --git a/src/solver/optimisation/opt_export_structure.cpp b/src/solver/optimisation/opt_export_structure.cpp index 3079b4281d..775b7dfc10 100644 --- a/src/solver/optimisation/opt_export_structure.cpp +++ b/src/solver/optimisation/opt_export_structure.cpp @@ -60,15 +60,15 @@ const std::initializer_list& getNames() } // namespace Antares void OPT_ExportInterco(const Antares::Solver::IResultWriter::Ptr writer, - PROBLEME_HEBDO* ProblemeHebdo) + PROBLEME_HEBDO* problemeHebdo) { Yuni::Clob Flot; - for (int i(0); i < ProblemeHebdo->NombreDInterconnexions; ++i) + for (int i(0); i < problemeHebdo->NombreDInterconnexions; ++i) { Flot.appendFormat("%d %d %d\n", i, - ProblemeHebdo->PaysOrigineDeLInterconnexion[i], - ProblemeHebdo->PaysExtremiteDeLInterconnexion[i]); + problemeHebdo->PaysOrigineDeLInterconnexion[i], + problemeHebdo->PaysExtremiteDeLInterconnexion[i]); } // TODO[FOM] "interco.txt" std::string filename = "interco-1-1.txt"; @@ -89,16 +89,16 @@ void OPT_ExportAreaName(Antares::Solver::IResultWriter::Ptr writer, } void OPT_Export_add_variable(std::vector& varname, - int Var, + int var, Antares::Data::Enum::ExportStructDict structDict, int ts, // TODO remove int firstVal, std::optional secondVal) { - if ((int)varname.size() > Var && varname[Var].empty()) + if ((int)varname.size() > var && varname[var].empty()) { std::stringstream buffer; - buffer << Var << " "; + buffer << var << " "; buffer << Antares::Data::Enum::toString(structDict) << " "; buffer << firstVal << " "; if (secondVal.has_value()) @@ -106,7 +106,7 @@ void OPT_Export_add_variable(std::vector& varname, buffer << secondVal.value() << " "; } buffer << ts << " "; - varname[Var] = buffer.str(); + varname[var] = buffer.str(); } } diff --git a/src/solver/optimisation/opt_export_structure.h b/src/solver/optimisation/opt_export_structure.h index 3e3c53b521..672fd656f5 100644 --- a/src/solver/optimisation/opt_export_structure.h +++ b/src/solver/optimisation/opt_export_structure.h @@ -65,13 +65,13 @@ class Study; struct PROBLEME_HEBDO; void OPT_Export_add_variable(std::vector& varname, - int Var, + int var, Antares::Data::Enum::ExportStructDict structDict, int ts, // TODO remove int firstVal, std::optional secondVal = std::nullopt); void OPT_ExportInterco(const Antares::Solver::IResultWriter::Ptr writer, - PROBLEME_HEBDO* ProblemeHebdo); + PROBLEME_HEBDO* problemeHebdo); void OPT_ExportAreaName(Antares::Solver::IResultWriter::Ptr writer, const Antares::Data::AreaList& areas); void OPT_ExportVariables(const Antares::Solver::IResultWriter::Ptr writer, diff --git a/src/solver/optimisation/opt_fonctions.h b/src/solver/optimisation/opt_fonctions.h index c802fdd88b..36e1e5b622 100644 --- a/src/solver/optimisation/opt_fonctions.h +++ b/src/solver/optimisation/opt_fonctions.h @@ -30,6 +30,7 @@ #include "../config.h" #include "opt_structure_probleme_a_resoudre.h" #include "../simulation/sim_structure_donnees.h" +#include "hourly_csr_problem.h" #include "opt_period_string_generator_base.h" void OPT_OptimisationHebdomadaire(PROBLEME_HEBDO*, uint); @@ -52,8 +53,8 @@ void OPT_InitialiserLeSecondMembreDuProblemeQuadratique(PROBLEME_HEBDO*, int); void OPT_InitialiserLesCoutsLineaire(PROBLEME_HEBDO*, const int, const int, uint); void OPT_InitialiserLesCoutsQuadratiques(PROBLEME_HEBDO*, int); void OPT_ControleDesPminPmaxThermiques(PROBLEME_HEBDO*); - bool OPT_AppelDuSolveurQuadratique(PROBLEME_ANTARES_A_RESOUDRE*, const int); +bool ADQ_PATCH_CSR(PROBLEME_ANTARES_A_RESOUDRE&, HourlyCSRProblem&, uint week, int year); bool OPT_PilotageOptimisationLineaire(PROBLEME_HEBDO*, uint); void OPT_VerifierPresenceReserveJmoins1(PROBLEME_HEBDO*); @@ -85,6 +86,9 @@ void OPT_ChargerLaContrainteDansLaMatriceDesContraintes(PROBLEME_ANTARES_A_RESOU const std::string& NomDeLaContrainte = ""); void OPT_ChainagesDesIntercoPartantDUnNoeud(PROBLEME_HEBDO*); +void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, + int); +void OPT_FreeOptimizationData(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre); void OPT_AllocDuProblemeAOptimiser(PROBLEME_HEBDO*); void OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO*, int*); void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(PROBLEME_ANTARES_A_RESOUDRE*); diff --git a/src/solver/optimisation/opt_gestion_des_bornes_cas_lineaire.cpp b/src/solver/optimisation/opt_gestion_des_bornes_cas_lineaire.cpp index e3b3a1c146..5822cb4bd7 100644 --- a/src/solver/optimisation/opt_gestion_des_bornes_cas_lineaire.cpp +++ b/src/solver/optimisation/opt_gestion_des_bornes_cas_lineaire.cpp @@ -34,7 +34,7 @@ #include "../simulation/sim_extern_variables_globales.h" #include "opt_fonctions.h" -#include "adequacy_patch.h" +#include "adequacy_patch_local_matching/adq_patch_local_matching.h" #include #include #include @@ -50,37 +50,37 @@ using namespace Antares::Data; using namespace Yuni; -void OPT_MaxDesPmaxHydrauliques(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_MaxDesPmaxHydrauliques(PROBLEME_HEBDO* problemeHebdo) { int Pays; int PdtHebdo; double PmaxHyd; double* ContrainteDePmaxHydrauliqueHoraire; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->MaxDesPmaxHydrauliques = 0.0; - ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->MaxDesPmaxHydrauliquesRef = 0.0; - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + problemeHebdo->CaracteristiquesHydrauliques[Pays]->MaxDesPmaxHydrauliques = 0.0; + problemeHebdo->CaracteristiquesHydrauliques[Pays]->MaxDesPmaxHydrauliquesRef = 0.0; + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable != OUI_ANTARES) continue; ContrainteDePmaxHydrauliqueHoraire - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->ContrainteDePmaxHydrauliqueHoraire; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->ContrainteDePmaxHydrauliqueHoraire; PmaxHyd = -1; - for (PdtHebdo = 0; PdtHebdo < ProblemeHebdo->NombreDePasDeTemps; PdtHebdo++) + for (PdtHebdo = 0; PdtHebdo < problemeHebdo->NombreDePasDeTemps; PdtHebdo++) { if (ContrainteDePmaxHydrauliqueHoraire[PdtHebdo] > PmaxHyd) PmaxHyd = ContrainteDePmaxHydrauliqueHoraire[PdtHebdo]; } - ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->MaxDesPmaxHydrauliques = PmaxHyd; - ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->MaxDesPmaxHydrauliquesRef = PmaxHyd; + problemeHebdo->CaracteristiquesHydrauliques[Pays]->MaxDesPmaxHydrauliques = PmaxHyd; + problemeHebdo->CaracteristiquesHydrauliques[Pays]->MaxDesPmaxHydrauliquesRef = PmaxHyd; } return; } -double OPT_SommeDesPminThermiques(PROBLEME_HEBDO* ProblemeHebdo, int Pays, int PdtHebdo) +double OPT_SommeDesPminThermiques(PROBLEME_HEBDO* problemeHebdo, int Pays, int PdtHebdo) { int Index; double SommeDesPminThermiques; @@ -88,7 +88,7 @@ double OPT_SommeDesPminThermiques(PROBLEME_HEBDO* ProblemeHebdo, int Pays, int P PALIERS_THERMIQUES* PaliersThermiquesDuPays; SommeDesPminThermiques = 0.0; - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; PuissanceDisponibleEtCout = PaliersThermiquesDuPays->PuissanceDisponibleEtCout; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) @@ -100,42 +100,42 @@ double OPT_SommeDesPminThermiques(PROBLEME_HEBDO* ProblemeHebdo, int Pays, int P return (SommeDesPminThermiques); } -void setBoundsForUnsuppliedEnergy(PROBLEME_HEBDO* ProblemeHebdo, +void setBoundsForUnsuppliedEnergy(PROBLEME_HEBDO* problemeHebdo, const int PremierPdtDeLIntervalle, const int DernierPdtDeLIntervalle, const int optimizationNumber) { // OUTPUT - double* Xmin = ProblemeHebdo->ProblemeAResoudre->Xmin; - double* Xmax = ProblemeHebdo->ProblemeAResoudre->Xmax; + double* Xmin = problemeHebdo->ProblemeAResoudre->Xmin; + double* Xmax = problemeHebdo->ProblemeAResoudre->Xmax; double** AdresseOuPlacerLaValeurDesVariablesOptimisees - = ProblemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees; + = problemeHebdo->ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees; - const bool reserveJm1 = (ProblemeHebdo->YaDeLaReserveJmoins1 == OUI_ANTARES); + const bool reserveJm1 = (problemeHebdo->YaDeLaReserveJmoins1 == OUI_ANTARES); const bool opt1 = (optimizationNumber == PREMIERE_OPTIMISATION); for (int PdtHebdo = PremierPdtDeLIntervalle, PdtJour = 0; PdtHebdo < DernierPdtDeLIntervalle; PdtHebdo++, PdtJour++) { const CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim - = ProblemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; + = problemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; const ALL_MUST_RUN_GENERATION* AllMustRunGeneration - = ProblemeHebdo->AllMustRunGeneration[PdtHebdo]; + = problemeHebdo->AllMustRunGeneration[PdtHebdo]; const CONSOMMATIONS_ABATTUES* ConsommationsAbattues - = ProblemeHebdo->ConsommationsAbattues[PdtHebdo]; + = problemeHebdo->ConsommationsAbattues[PdtHebdo]; - for (int Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (int Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { double ResidualLoadInArea = ConsommationsAbattues->ConsommationAbattueDuPays[Pays]; if (reserveJm1 && opt1) { ResidualLoadInArea - += ProblemeHebdo->ReserveJMoins1[Pays]->ReserveHoraireJMoins1[PdtHebdo]; + += problemeHebdo->ReserveJMoins1[Pays]->ReserveHoraireJMoins1[PdtHebdo]; } - int Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[Pays]; - Xmin[Var] = 0.0; + int var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[Pays]; + Xmin[var] = 0.0; double MaxAllMustRunGenerationOfArea = 0.; if (AllMustRunGeneration->AllMustRunGenerationOfArea[Pays] > 0.) @@ -144,29 +144,29 @@ void setBoundsForUnsuppliedEnergy(PROBLEME_HEBDO* ProblemeHebdo, ResidualLoadInArea += MaxAllMustRunGenerationOfArea; if (ResidualLoadInArea >= 0.) - Xmax[Var] = ResidualLoadInArea + 1e-5; + Xmax[var] = ResidualLoadInArea + 1e-5; else - Xmax[Var] = 0.; + Xmax[var] = 0.; // adq patch: update ENS <= DENS in 2nd run - if (ProblemeHebdo->adqPatchParams - && ProblemeHebdo->adqPatchParams->AdequacyFirstStep == false - && ProblemeHebdo->adequacyPatchRuntimeData.areaMode[Pays] + if (problemeHebdo->adqPatchParams + && problemeHebdo->adqPatchParams->AdequacyFirstStep == false + && problemeHebdo->adequacyPatchRuntimeData.areaMode[Pays] == Data::AdequacyPatch::physicalAreaInsideAdqPatch) - Xmax[Var] = std::min( - Xmax[Var], ProblemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDENS[PdtHebdo]); + Xmax[var] = std::min( + Xmax[var], problemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDENS[PdtHebdo]); - ProblemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDeDefaillancePositive[PdtHebdo] + problemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDeDefaillancePositive[PdtHebdo] = 0.0; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] - = &(ProblemeHebdo->ResultatsHoraires[Pays] + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] + = &(problemeHebdo->ResultatsHoraires[Pays] ->ValeursHorairesDeDefaillancePositive[PdtHebdo]); } } } -void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHebdo, +void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire(PROBLEME_HEBDO* problemeHebdo, const int PremierPdtDeLIntervalle, const int DernierPdtDeLIntervalle, const int optimizationNumber) @@ -176,7 +176,7 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire(PROBLEME_HEBDO* Prob int Interco; int Pays; int Palier; - int Var; + int var; int Index; double* AdresseDuResultat; int maxThermalPlant; @@ -185,7 +185,7 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire(PROBLEME_HEBDO* Prob double* Xmin; double* Xmax; int* TypeDeVariable; - + VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeNTC; CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; PALIERS_THERMIQUES* PaliersThermiquesDuPays; @@ -193,7 +193,7 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire(PROBLEME_HEBDO* Prob COUTS_DE_TRANSPORT* CoutDeTransport; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; AdresseOuPlacerLaValeurDesVariablesOptimisees = ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees; @@ -203,282 +203,278 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire(PROBLEME_HEBDO* Prob Xmax = ProblemeAResoudre->Xmax; TypeDeVariable = ProblemeAResoudre->TypeDeVariable; - for (Var = 0; Var < ProblemeAResoudre->NombreDeVariables; Var++) + for (var = 0; var < ProblemeAResoudre->NombreDeVariables; var++) { - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; } for (PdtHebdo = PremierPdtDeLIntervalle, PdtJour = 0; PdtHebdo < DernierPdtDeLIntervalle; PdtHebdo++, PdtJour++) { - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; - ValeursDeNTC = ProblemeHebdo->ValeursDeNTC[PdtHebdo]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; + ValeursDeNTC = problemeHebdo->ValeursDeNTC[PdtHebdo]; - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; - CoutDeTransport = ProblemeHebdo->CoutDeTransport[Interco]; + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + CoutDeTransport = problemeHebdo->CoutDeTransport[Interco]; - if (ProblemeHebdo->adqPatchParams && ProblemeHebdo->adqPatchParams->AdequacyFirstStep) - AdequacyPatch::setBoundsAdqPatch( - Xmax[Var], Xmin[Var], ValeursDeNTC, Interco, ProblemeHebdo); - else - AdequacyPatch::setBoundsNoAdqPatch(Xmax[Var], Xmin[Var], ValeursDeNTC, Interco); + AdequacyPatch::setNTCbounds(Xmax[var], Xmin[var], ValeursDeNTC, Interco, problemeHebdo); - if (Math::Infinite(Xmax[Var]) == 1) + if (Math::Infinite(Xmax[var]) == 1) { - if (Math::Infinite(Xmin[Var]) == -1) - TypeDeVariable[Var] = VARIABLE_NON_BORNEE; + if (Math::Infinite(Xmin[var]) == -1) + TypeDeVariable[var] = VARIABLE_NON_BORNEE; else - TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + TypeDeVariable[var] = VARIABLE_BORNEE_INFERIEUREMENT; } else { - if (Math::Infinite(Xmin[Var]) == -1) - TypeDeVariable[Var] = VARIABLE_BORNEE_SUPERIEUREMENT; + if (Math::Infinite(Xmin[var]) == -1) + TypeDeVariable[var] = VARIABLE_BORNEE_SUPERIEUREMENT; else - TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; + TypeDeVariable[var] = VARIABLE_BORNEE_DES_DEUX_COTES; } - AdresseDuResultat = &(ProblemeHebdo->VariablesDualesDesContraintesDeNTC[PdtHebdo] + AdresseDuResultat = &(problemeHebdo->VariablesDualesDesContraintesDeNTC[PdtHebdo] ->VariableDualeParInterconnexion[Interco]); - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = AdresseDuResultat; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = AdresseDuResultat; AdresseDuResultat = &(ValeursDeNTC->ValeurDuFlux[Interco]); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; if (CoutDeTransport->IntercoGereeAvecDesCouts == OUI_ANTARES) { - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[Interco]; if (CoutDeTransport->IntercoGereeAvecLoopFlow == OUI_ANTARES) - Xmax[Var] = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco] + Xmax[var] = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco] - ValeursDeNTC->ValeurDeLoopFlowOrigineVersExtremite[Interco]; else - Xmax[Var] = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco]; + Xmax[var] = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco]; - Xmax[Var] += 0.01; - TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; - if (Math::Infinite(Xmax[Var]) == 1) + Xmax[var] += 0.01; + TypeDeVariable[var] = VARIABLE_BORNEE_DES_DEUX_COTES; + if (Math::Infinite(Xmax[var]) == 1) { - TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + TypeDeVariable[var] = VARIABLE_BORNEE_INFERIEUREMENT; } - Xmin[Var] = 0.0; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; + Xmin[var] = 0.0; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[Interco]; if (CoutDeTransport->IntercoGereeAvecLoopFlow == OUI_ANTARES) - Xmax[Var] = ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco] + Xmax[var] = ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco] + ValeursDeNTC->ValeurDeLoopFlowOrigineVersExtremite[Interco]; else - Xmax[Var] = ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]; + Xmax[var] = ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]; - Xmax[Var] += 0.01; - TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; - if (Math::Infinite(Xmax[Var]) == 1) + Xmax[var] += 0.01; + TypeDeVariable[var] = VARIABLE_BORNEE_DES_DEUX_COTES; + if (Math::Infinite(Xmax[var]) == 1) { - TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + TypeDeVariable[var] = VARIABLE_BORNEE_INFERIEUREMENT; } - Xmin[Var] = 0.0; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; + Xmin[var] = 0.0; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; maxThermalPlant = PaliersThermiquesDuPays->NombreDePaliersThermiques; for (Index = 0; Index < maxThermalPlant; Index++) { Palier = PaliersThermiquesDuPays->NumeroDuPalierDansLEnsembleDesPaliersThermiques[Index]; - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; PuissanceDisponibleEtCout = PaliersThermiquesDuPays->PuissanceDisponibleEtCout[Index]; - Xmin[Var] = PuissanceDisponibleEtCout->PuissanceMinDuPalierThermique[PdtHebdo]; + Xmin[var] = PuissanceDisponibleEtCout->PuissanceMinDuPalierThermique[PdtHebdo]; - Xmax[Var] + Xmax[var] = PuissanceDisponibleEtCout->PuissanceDisponibleDuPalierThermique[PdtHebdo]; - AdresseDuResultat = &(ProblemeHebdo->ResultatsHoraires[Pays] + AdresseDuResultat = &(problemeHebdo->ResultatsHoraires[Pays] ->ProductionThermique[PdtHebdo] ->ProductionThermiqueDuPalier[Index]); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; - ProblemeHebdo->ResultatsHoraires[Pays]->TurbinageHoraire[PdtHebdo] = 0.0; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; + problemeHebdo->ResultatsHoraires[Pays]->TurbinageHoraire[PdtHebdo] = 0.0; + if (var >= 0) { - Xmin[Var] = 0.0; - Xmax[Var] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + Xmin[var] = 0.0; + Xmax[var] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->ContrainteDePmaxHydrauliqueHoraire[PdtHebdo]; AdresseDuResultat - = &(ProblemeHebdo->ResultatsHoraires[Pays]->TurbinageHoraire[PdtHebdo]); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + = &(problemeHebdo->ResultatsHoraires[Pays]->TurbinageHoraire[PdtHebdo]); + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; } - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable == OUI_ANTARES) { - if (ProblemeHebdo->TypeDeLissageHydraulique + if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) { - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariablesVariationHydALaBaisse[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - Xmin[Var] = 0.0; - Xmax[Var] = LINFINI_ANTARES; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; + Xmin[var] = 0.0; + Xmax[var] = LINFINI_ANTARES; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; } - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariablesVariationHydALaHausse[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - Xmin[Var] = 0.0; - Xmax[Var] = LINFINI_ANTARES; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; + Xmin[var] = 0.0; + Xmax[var] = LINFINI_ANTARES; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; } } - else if (ProblemeHebdo->TypeDeLissageHydraulique + else if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_VARIATION_MAX) { if (PdtJour == 0) { - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariablesVariationHydALaBaisse[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - Xmin[Var] = 0.0; - Xmax[Var] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + Xmin[var] = 0.0; + Xmax[var] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->MaxDesPmaxHydrauliques; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; } - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariablesVariationHydALaHausse[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - Xmin[Var] = 0.0; - Xmax[Var] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + Xmin[var] = 0.0; + Xmax[var] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->MaxDesPmaxHydrauliques; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; } } } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays]; - ProblemeHebdo->ResultatsHoraires[Pays]->PompageHoraire[PdtHebdo] = 0.0; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays]; + problemeHebdo->ResultatsHoraires[Pays]->PompageHoraire[PdtHebdo] = 0.0; + if (var >= 0) { - Xmin[Var] = 0.0; - Xmax[Var] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + Xmin[var] = 0.0; + Xmax[var] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->ContrainteDePmaxPompageHoraire[PdtHebdo]; AdresseDuResultat - = &(ProblemeHebdo->ResultatsHoraires[Pays]->PompageHoraire[PdtHebdo]); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + = &(problemeHebdo->ResultatsHoraires[Pays]->PompageHoraire[PdtHebdo]); + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeDebordement[Pays]; + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeDebordement[Pays]; - ProblemeHebdo->ResultatsHoraires[Pays]->debordementsHoraires[PdtHebdo] = 0.; - if (Var >= 0) + problemeHebdo->ResultatsHoraires[Pays]->debordementsHoraires[PdtHebdo] = 0.; + if (var >= 0) { - Xmin[Var] = 0.0; - Xmax[Var] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + Xmin[var] = 0.0; + Xmax[var] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->ApportNaturelHoraire[PdtHebdo]; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeNiveau[Pays]; - if (Var >= 0) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeNiveau[Pays]; + if (var >= 0) { - Xmin[Var] - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->NiveauHoraireInf[PdtHebdo]; - Xmax[Var] - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->NiveauHoraireSup[PdtHebdo]; + Xmin[var] + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->NiveauHoraireInf[PdtHebdo]; + Xmax[var] + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->NiveauHoraireSup[PdtHebdo]; AdresseDuResultat - = &(ProblemeHebdo->ResultatsHoraires[Pays]->niveauxHoraires[PdtHebdo]); - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + = &(problemeHebdo->ResultatsHoraires[Pays]->niveauxHoraires[PdtHebdo]); + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; } { - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[Pays]; + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[Pays]; - Xmin[Var] = 0.0; + Xmin[var] = 0.0; - Xmax[Var] = LINFINI_ANTARES; + Xmax[var] = LINFINI_ANTARES; - ProblemeHebdo->ResultatsHoraires[Pays] + problemeHebdo->ResultatsHoraires[Pays] ->ValeursHorairesDeDefaillanceNegative[PdtHebdo] = 0.0; - AdresseDuResultat = &(ProblemeHebdo->ResultatsHoraires[Pays] + AdresseDuResultat = &(problemeHebdo->ResultatsHoraires[Pays] ->ValeursHorairesDeDefaillanceNegative[PdtHebdo]); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; } - ProblemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDeDefaillanceEnReserve[PdtHebdo] + problemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDeDefaillanceEnReserve[PdtHebdo] = 0.0; } } setBoundsForUnsuppliedEnergy( - ProblemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle, optimizationNumber); + problemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle, optimizationNumber); - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) { - Var = ProblemeHebdo->NumeroDeVariableStockFinal[Pays]; - if (Var >= 0) + var = problemeHebdo->NumeroDeVariableStockFinal[Pays]; + if (var >= 0) { - Xmin[Var] = -(LINFINI_ANTARES); - Xmax[Var] = LINFINI_ANTARES; + Xmin[var] = -(LINFINI_ANTARES); + Xmax[var] = LINFINI_ANTARES; - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; // Note: if there were a single optimization run instead of two; the following // could be used: AdresseDuResultat = - //&(ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->LevelForTimeInterval); - // AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + //&(problemeHebdo->CaracteristiquesHydrauliques[Pays]->LevelForTimeInterval); + // AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; } for (uint nblayer = 0; nblayer < 100; nblayer++) { - Var = ProblemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][nblayer]; - if (Var >= 0) + var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][nblayer]; + if (var >= 0) { - Xmin[Var] = 0; - Xmax[Var] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->TailleReservoir + Xmin[var] = 0; + Xmax[var] = problemeHebdo->CaracteristiquesHydrauliques[Pays]->TailleReservoir / double(100); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; - AdresseOuPlacerLaValeurDesCoutsReduits[Var] = NULL; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; + AdresseOuPlacerLaValeurDesCoutsReduits[var] = NULL; } } } } - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) { OPT_InitialiserLesBornesDesVariablesDuProblemeLineaireCoutsDeDemarrage( - ProblemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle); + problemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle); } return; diff --git a/src/solver/optimisation/opt_gestion_des_bornes_cas_quadratique.cpp b/src/solver/optimisation/opt_gestion_des_bornes_cas_quadratique.cpp index 233720ad33..094e905e28 100644 --- a/src/solver/optimisation/opt_gestion_des_bornes_cas_quadratique.cpp +++ b/src/solver/optimisation/opt_gestion_des_bornes_cas_quadratique.cpp @@ -42,55 +42,55 @@ using namespace Yuni; -void OPT_InitialiserLesBornesDesVariablesDuProblemeQuadratique(PROBLEME_HEBDO* ProblemeHebdo, +void OPT_InitialiserLesBornesDesVariablesDuProblemeQuadratique(PROBLEME_HEBDO* problemeHebdo, int PdtHebdo) { int Interco; - int Var; + int var; double* AdresseDuResultat; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeNTC; CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - for (Var = 0; Var < ProblemeAResoudre->NombreDeVariables; Var++) - ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = NULL; + for (var = 0; var < ProblemeAResoudre->NombreDeVariables; var++) + ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = NULL; - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[0]; - ValeursDeNTC = ProblemeHebdo->ValeursDeNTC[PdtHebdo]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[0]; + ValeursDeNTC = problemeHebdo->ValeursDeNTC[PdtHebdo]; - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; - ProblemeAResoudre->Xmax[Var] = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco]; - ProblemeAResoudre->Xmin[Var] = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]); + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + ProblemeAResoudre->Xmax[var] = ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco]; + ProblemeAResoudre->Xmin[var] = -(ValeursDeNTC->ValeurDeNTCExtremiteVersOrigine[Interco]); - if (ProblemeAResoudre->Xmax[Var] - ProblemeAResoudre->Xmin[Var] + if (ProblemeAResoudre->Xmax[var] - ProblemeAResoudre->Xmin[var] < ZERO_POUR_LES_VARIABLES_FIXES) { - ProblemeAResoudre->X[Var] - = 0.5 * (ProblemeAResoudre->Xmax[Var] - ProblemeAResoudre->Xmin[Var]); - ProblemeAResoudre->TypeDeVariable[Var] = VARIABLE_FIXE; + ProblemeAResoudre->X[var] + = 0.5 * (ProblemeAResoudre->Xmax[var] - ProblemeAResoudre->Xmin[var]); + ProblemeAResoudre->TypeDeVariable[var] = VARIABLE_FIXE; } else { - if (Math::Infinite(ProblemeAResoudre->Xmax[Var]) == 1) + if (Math::Infinite(ProblemeAResoudre->Xmax[var]) == 1) { - if (Math::Infinite(ProblemeAResoudre->Xmin[Var]) == -1) - ProblemeAResoudre->TypeDeVariable[Var] = VARIABLE_NON_BORNEE; + if (Math::Infinite(ProblemeAResoudre->Xmin[var]) == -1) + ProblemeAResoudre->TypeDeVariable[var] = VARIABLE_NON_BORNEE; else - ProblemeAResoudre->TypeDeVariable[Var] = VARIABLE_BORNEE_INFERIEUREMENT; + ProblemeAResoudre->TypeDeVariable[var] = VARIABLE_BORNEE_INFERIEUREMENT; } else { - if (Math::Infinite(ProblemeAResoudre->Xmin[Var]) == -1) - ProblemeAResoudre->TypeDeVariable[Var] = VARIABLE_BORNEE_SUPERIEUREMENT; + if (Math::Infinite(ProblemeAResoudre->Xmin[var]) == -1) + ProblemeAResoudre->TypeDeVariable[var] = VARIABLE_BORNEE_SUPERIEUREMENT; else - ProblemeAResoudre->TypeDeVariable[Var] = VARIABLE_BORNEE_DES_DEUX_COTES; + ProblemeAResoudre->TypeDeVariable[var] = VARIABLE_BORNEE_DES_DEUX_COTES; } } AdresseDuResultat = &(ValeursDeNTC->ValeurDuFlux[Interco]); - ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; } -} +} \ No newline at end of file diff --git a/src/solver/optimisation/opt_gestion_des_bornes_couts_demarrage.cpp b/src/solver/optimisation/opt_gestion_des_bornes_couts_demarrage.cpp index d36a4c64bc..4df8e50b22 100644 --- a/src/solver/optimisation/opt_gestion_des_bornes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_gestion_des_bornes_couts_demarrage.cpp @@ -45,7 +45,7 @@ using namespace Yuni; void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaireCoutsDeDemarrage( - PROBLEME_HEBDO* ProblemeHebdo, + PROBLEME_HEBDO* problemeHebdo, const int PremierPdtDeLIntervalle, const int DernierPdtDeLIntervalle) { @@ -53,7 +53,7 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaireCoutsDeDemarrage( int PdtJour; int Pays; int Palier; - int Var; + int var; int Index; double* AdresseDuResultat; double** AdresseOuPlacerLaValeurDesVariablesOptimisees; @@ -70,8 +70,8 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaireCoutsDeDemarrage( PDISP_ET_COUTS_HORAIRES_PAR_PALIER* PuissanceDisponibleEtCout; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; AdresseOuPlacerLaValeurDesVariablesOptimisees = ProblemeAResoudre->AdresseOuPlacerLaValeurDesVariablesOptimisees; @@ -81,11 +81,11 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaireCoutsDeDemarrage( for (PdtHebdo = PremierPdtDeLIntervalle, PdtJour = 0; PdtHebdo < DernierPdtDeLIntervalle; PdtHebdo++, PdtJour++) { - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { @@ -98,58 +98,58 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaireCoutsDeDemarrage( NombreMinDeGroupesEnMarcheDuPalierThermique = PuissanceDisponibleEtCout->NombreMinDeGroupesEnMarcheDuPalierThermique; - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[Palier]; - Xmax[Var] = NombreMaxDeGroupesEnMarcheDuPalierThermique[PdtHebdo]; - Xmin[Var] = NombreMinDeGroupesEnMarcheDuPalierThermique[PdtHebdo]; + Xmax[var] = NombreMaxDeGroupesEnMarcheDuPalierThermique[PdtHebdo]; + Xmin[var] = NombreMinDeGroupesEnMarcheDuPalierThermique[PdtHebdo]; - AdresseDuResultat = &(ProblemeHebdo->ResultatsHoraires[Pays] + AdresseDuResultat = &(problemeHebdo->ResultatsHoraires[Pays] ->ProductionThermique[PdtHebdo] ->NombreDeGroupesEnMarcheDuPalier[Index]); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesQuiDemarrentDuPalierThermique[Palier]; - Xmax[Var] = LINFINI_ANTARES; - Xmin[Var] = 0; - AdresseDuResultat = &(ProblemeHebdo->ResultatsHoraires[Pays] + Xmax[var] = LINFINI_ANTARES; + Xmin[var] = 0; + AdresseDuResultat = &(problemeHebdo->ResultatsHoraires[Pays] ->ProductionThermique[PdtHebdo] ->NombreDeGroupesQuiDemarrentDuPalier[Index]); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique[Palier]; - Xmax[Var] = LINFINI_ANTARES; - Xmin[Var] = 0; - AdresseDuResultat = &(ProblemeHebdo->ResultatsHoraires[Pays] + Xmax[var] = LINFINI_ANTARES; + Xmin[var] = 0; + AdresseDuResultat = &(problemeHebdo->ResultatsHoraires[Pays] ->ProductionThermique[PdtHebdo] ->NombreDeGroupesQuiSArretentDuPalier[Index]); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; - Var + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesQuiTombentEnPanneDuPalierThermique[Palier]; - Xmin[Var] = 0; + Xmin[var] = 0; #if VARIABLES_MMOINS_MOINS_BORNEES_DES_2_COTES != OUI_ANTARES - Xmax[Var] = LINFINI_ANTARES; + Xmax[var] = LINFINI_ANTARES; #else t1 = PdtHebdo; t1moins1 = t1 - 1; if (t1moins1 < 0) t1moins1 = NombreDePasDeTempsPourUneOptimisation + t1moins1; - Xmax[Var] = 0; + Xmax[var] = 0; if (NombreMaxDeGroupesEnMarcheDuPalierThermique[t1moins1] - NombreMaxDeGroupesEnMarcheDuPalierThermique[t1] > 0) { - Xmax[Var] = NombreMaxDeGroupesEnMarcheDuPalierThermique[t1moins1] + Xmax[var] = NombreMaxDeGroupesEnMarcheDuPalierThermique[t1moins1] - NombreMaxDeGroupesEnMarcheDuPalierThermique[t1]; } #endif - AdresseDuResultat = &(ProblemeHebdo->ResultatsHoraires[Pays] + AdresseDuResultat = &(problemeHebdo->ResultatsHoraires[Pays] ->ProductionThermique[PdtHebdo] ->NombreDeGroupesQuiTombentEnPanneDuPalier[Index]); - AdresseOuPlacerLaValeurDesVariablesOptimisees[Var] = AdresseDuResultat; + AdresseOuPlacerLaValeurDesVariablesOptimisees[var] = AdresseDuResultat; } } } diff --git a/src/solver/optimisation/opt_gestion_des_couts_cas_lineaire.cpp b/src/solver/optimisation/opt_gestion_des_couts_cas_lineaire.cpp index 8d9b6ff6d8..e3971724c5 100644 --- a/src/solver/optimisation/opt_gestion_des_couts_cas_lineaire.cpp +++ b/src/solver/optimisation/opt_gestion_des_couts_cas_lineaire.cpp @@ -40,15 +40,13 @@ #include "spx_constantes_externes.h" -static void ComputeMinMaxValueForLoad(PROBLEME_HEBDO* ProblemeHebdo, +static void ComputeMinMaxValueForLoad(PROBLEME_HEBDO* problemeHebdo, const int PremierPasDeTempsHebdo, const int DernierPasDeTempsHebdo, uint numSpace) { using namespace Antares::Data; - double d; - auto& study = *Antares::Data::Study::Current::Get(); const Area::Map::const_iterator end = study.areas.end(); for (Area::Map::const_iterator i = study.areas.begin(); i != end; ++i) @@ -60,7 +58,7 @@ static void ComputeMinMaxValueForLoad(PROBLEME_HEBDO* ProblemeHebdo, for (int i = PremierPasDeTempsHebdo; i < DernierPasDeTempsHebdo; ++i) { - d = ProblemeHebdo->ConsommationsAbattues[i]->ConsommationAbattueDuPays[area.index]; + double d = problemeHebdo->ConsommationsAbattues[i]->ConsommationAbattueDuPays[area.index]; if (d < scratchpad.consoMin) scratchpad.consoMin = d; if (d > scratchpad.consoMax) @@ -69,147 +67,139 @@ static void ComputeMinMaxValueForLoad(PROBLEME_HEBDO* ProblemeHebdo, } } -void OPT_InitialiserLesCoutsLineaire(PROBLEME_HEBDO* ProblemeHebdo, +void OPT_InitialiserLesCoutsLineaire(PROBLEME_HEBDO* problemeHebdo, const int PremierPdtDeLIntervalle, const int DernierPdtDeLIntervalle, uint numSpace) { - int PdtJour; - int Interco; - int Pays; - int Palier; - int Var; - int Index; - int PdtHebdo; - double P; - int layerindex; CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; PALIERS_THERMIQUES* PaliersThermiquesDuPays; COUTS_DE_TRANSPORT* CoutDeTransport; - PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; auto& study = *Antares::Data::Study::Current::Get(); - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - PdtJour = 0; + int PdtJour = 0; memset((char*)ProblemeAResoudre->CoutQuadratique, 0, ProblemeAResoudre->NombreDeVariables * sizeof(double)); ComputeMinMaxValueForLoad( - ProblemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle, numSpace); + problemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle, numSpace); - for (PdtHebdo = PremierPdtDeLIntervalle; PdtHebdo < DernierPdtDeLIntervalle; PdtHebdo++) + for (int PdtHebdo = PremierPdtDeLIntervalle; PdtHebdo < DernierPdtDeLIntervalle; PdtHebdo++) { - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; + int var; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (int Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { - CoutDeTransport = ProblemeHebdo->CoutDeTransport[Interco]; + CoutDeTransport = problemeHebdo->CoutDeTransport[Interco]; - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] = 0.0; + ProblemeAResoudre->CoutLineaire[var] = 0.0; } if (CoutDeTransport->IntercoGereeAvecDesCouts == OUI_ANTARES) { - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableCoutOrigineVersExtremiteDeLInterconnexion[Interco]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] + ProblemeAResoudre->CoutLineaire[var] = CoutDeTransport->CoutDeTransportOrigineVersExtremite[PdtHebdo]; } - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableCoutExtremiteVersOrigineDeLInterconnexion[Interco]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] + ProblemeAResoudre->CoutLineaire[var] = CoutDeTransport->CoutDeTransportExtremiteVersOrigine[PdtHebdo]; } } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; ++Pays) + for (int Pays = 0; Pays < problemeHebdo->NombreDePays; ++Pays) { assert((unsigned int)Pays < study.areas.size()); - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; - for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; + for (int Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { - Palier + int Palier = PaliersThermiquesDuPays->NumeroDuPalierDansLEnsembleDesPaliersThermiques[Index]; - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDuPalierThermique[Palier]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] + ProblemeAResoudre->CoutLineaire[var] = PaliersThermiquesDuPays->PuissanceDisponibleEtCout[Index] ->CoutHoraireDeProductionDuPalierThermique[PdtHebdo]; } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) - ProblemeAResoudre->CoutLineaire[Var] = 0.0; + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeLaProdHyd[Pays]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) + ProblemeAResoudre->CoutLineaire[var] = 0.0; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] - = ProblemeHebdo - ->BruitSurCoutHydraulique[Pays][ProblemeHebdo->HeureDansLAnnee + PdtHebdo]; + ProblemeAResoudre->CoutLineaire[var] + = problemeHebdo + ->BruitSurCoutHydraulique[Pays][problemeHebdo->HeureDansLAnnee + PdtHebdo]; - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == NON_ANTARES) - ProblemeAResoudre->CoutLineaire[Var] - += ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + ProblemeAResoudre->CoutLineaire[var] + += problemeHebdo->CaracteristiquesHydrauliques[Pays] ->WeeklyWaterValueStateRegular; } - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable == OUI_ANTARES) { - if (ProblemeHebdo->TypeDeLissageHydraulique + double P; + if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_SOMME_DES_VARIATIONS) { - P = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + P = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->PenalisationDeLaVariationDeProductionHydrauliqueSurSommeDesVariations; - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariablesVariationHydALaBaisse[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) - ProblemeAResoudre->CoutLineaire[Var] = P; - Var = CorrespondanceVarNativesVarOptim + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) + ProblemeAResoudre->CoutLineaire[var] = P; + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariablesVariationHydALaHausse[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) - ProblemeAResoudre->CoutLineaire[Var] = P; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) + ProblemeAResoudre->CoutLineaire[var] = P; } - else if (ProblemeHebdo->TypeDeLissageHydraulique + else if (problemeHebdo->TypeDeLissageHydraulique == LISSAGE_HYDRAULIQUE_SUR_VARIATION_MAX) { if (PdtJour == 0) { - P = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + P = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->PenalisationDeLaVariationDeProductionHydrauliqueSurVariationMax; - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariablesVariationHydALaBaisse[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) - ProblemeAResoudre->CoutLineaire[Var] = P; - Var = CorrespondanceVarNativesVarOptim + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) + ProblemeAResoudre->CoutLineaire[var] = P; + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariablesVariationHydALaHausse[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) - ProblemeAResoudre->CoutLineaire[Var] = -P; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) + ProblemeAResoudre->CoutLineaire[var] = -P; } } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDePompage[Pays]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { /* Sets the cost of the pumping variable when such a variable is actually defined - (i.e. Var>=0) + (i.e. var>=0) 1- When the "AccurateWaterValue" optimization mode is not used, the pumping @@ -230,38 +220,38 @@ void OPT_InitialiserLesCoutsLineaire(PROBLEME_HEBDO* ProblemeHebdo, */ - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == NON_ANTARES) { - ProblemeAResoudre->CoutLineaire[Var] - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + ProblemeAResoudre->CoutLineaire[var] + = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->WeeklyWaterValueStateRegular; - ProblemeAResoudre->CoutLineaire[Var] - *= ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PumpingRatio; - ProblemeAResoudre->CoutLineaire[Var] *= -1.; + ProblemeAResoudre->CoutLineaire[var] + *= problemeHebdo->CaracteristiquesHydrauliques[Pays]->PumpingRatio; + ProblemeAResoudre->CoutLineaire[var] *= -1.; - ProblemeAResoudre->CoutLineaire[Var] + ProblemeAResoudre->CoutLineaire[var] += 2. - * fabs(ProblemeHebdo - ->BruitSurCoutHydraulique[Pays][ProblemeHebdo->HeureDansLAnnee + * fabs(problemeHebdo + ->BruitSurCoutHydraulique[Pays][problemeHebdo->HeureDansLAnnee + PdtHebdo]); } else { - ProblemeAResoudre->CoutLineaire[Var] + ProblemeAResoudre->CoutLineaire[var] = 2. - * fabs(ProblemeHebdo - ->BruitSurCoutHydraulique[Pays][ProblemeHebdo->HeureDansLAnnee + * fabs(problemeHebdo + ->BruitSurCoutHydraulique[Pays][problemeHebdo->HeureDansLAnnee + PdtHebdo]); } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeDebordement[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeDebordement[Pays]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { /* Sets the cost of the overflow variable when such a variable is actually defined - (i.e. Var>=0) + (i.e. var>=0) 1- When the "AccurateWaterValue" optimization mode is not used, the overflow @@ -278,74 +268,74 @@ void OPT_InitialiserLesCoutsLineaire(PROBLEME_HEBDO* ProblemeHebdo, */ - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == NON_ANTARES) { - ProblemeAResoudre->CoutLineaire[Var] - = ProblemeHebdo->CoutDeDefaillanceNegative[Pays]; + ProblemeAResoudre->CoutLineaire[var] + = problemeHebdo->CoutDeDefaillanceNegative[Pays]; - ProblemeAResoudre->CoutLineaire[Var] - += ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + ProblemeAResoudre->CoutLineaire[var] + += problemeHebdo->CaracteristiquesHydrauliques[Pays] ->WeeklyWaterValueStateRegular; } else { - ProblemeAResoudre->CoutLineaire[Var] - = ProblemeHebdo->CoutDeDefaillanceNegative[Pays]; + ProblemeAResoudre->CoutLineaire[var] + = problemeHebdo->CoutDeDefaillanceNegative[Pays]; } } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeNiveau[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariablesDeNiveau[Pays]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] = 0; + ProblemeAResoudre->CoutLineaire[var] = 0; } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillancePositive[Pays]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] - = ProblemeHebdo->CoutDeDefaillancePositive[Pays]; + ProblemeAResoudre->CoutLineaire[var] + = problemeHebdo->CoutDeDefaillancePositive[Pays]; } - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDefaillanceNegative[Pays]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] - = ProblemeHebdo->CoutDeDefaillanceNegative[Pays]; + ProblemeAResoudre->CoutLineaire[var] + = problemeHebdo->CoutDeDefaillanceNegative[Pays]; } } PdtJour++; } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; ++Pays) + for (int Pays = 0; Pays < problemeHebdo->NombreDePays; ++Pays) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) { - Var = ProblemeHebdo->NumeroDeVariableStockFinal[Pays]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + int var = problemeHebdo->NumeroDeVariableStockFinal[Pays]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] = 0; + ProblemeAResoudre->CoutLineaire[var] = 0; } - for (layerindex = 0; layerindex < 100; layerindex++) + for (int layerindex = 0; layerindex < 100; layerindex++) { - Var = ProblemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][layerindex]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + var = problemeHebdo->NumeroDeVariableDeTrancheDeStock[Pays][layerindex]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - ProblemeAResoudre->CoutLineaire[Var] - = -ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + ProblemeAResoudre->CoutLineaire[var] + = -problemeHebdo->CaracteristiquesHydrauliques[Pays] ->WaterLayerValues[layerindex]; } } } } - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) { OPT_InitialiserLesCoutsLineaireCoutsDeDemarrage( - ProblemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle); + problemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle); } return; diff --git a/src/solver/optimisation/opt_gestion_des_couts_cas_quadratique.cpp b/src/solver/optimisation/opt_gestion_des_couts_cas_quadratique.cpp index 5761cf1341..2a4701340a 100644 --- a/src/solver/optimisation/opt_gestion_des_couts_cas_quadratique.cpp +++ b/src/solver/optimisation/opt_gestion_des_couts_cas_quadratique.cpp @@ -33,27 +33,27 @@ #include "opt_fonctions.h" -void OPT_InitialiserLesCoutsQuadratiques(PROBLEME_HEBDO* ProblemeHebdo, int PdtHebdo) +void OPT_InitialiserLesCoutsQuadratiques(PROBLEME_HEBDO* problemeHebdo, int PdtHebdo) { int Interco; - int Var; + int var; CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; VALEURS_DE_NTC_ET_RESISTANCES* ValeursDeResistances; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; memset((char*)ProblemeAResoudre->CoutLineaire, 0, ProblemeAResoudre->NombreDeVariables * sizeof(double)); - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[0]; - ValeursDeResistances = ProblemeHebdo->ValeursDeNTC[PdtHebdo]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[0]; + ValeursDeResistances = problemeHebdo->ValeursDeNTC[PdtHebdo]; - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { - Var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) - ProblemeAResoudre->CoutQuadratique[Var] + var = CorrespondanceVarNativesVarOptim->NumeroDeVariableDeLInterconnexion[Interco]; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) + ProblemeAResoudre->CoutQuadratique[var] = ValeursDeResistances->ResistanceApparente[Interco]; } -} +} \ No newline at end of file diff --git a/src/solver/optimisation/opt_gestion_des_couts_couts_demarrage.cpp b/src/solver/optimisation/opt_gestion_des_couts_couts_demarrage.cpp index 972ebeeb49..d255399705 100644 --- a/src/solver/optimisation/opt_gestion_des_couts_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_gestion_des_couts_couts_demarrage.cpp @@ -40,14 +40,14 @@ #include "spx_constantes_externes.h" -void OPT_InitialiserLesCoutsLineaireCoutsDeDemarrage(PROBLEME_HEBDO* ProblemeHebdo, +void OPT_InitialiserLesCoutsLineaireCoutsDeDemarrage(PROBLEME_HEBDO* problemeHebdo, const int PremierPdtDeLIntervalle, const int DernierPdtDeLIntervalle) { int PdtJour; int Pays; int Palier; - int Var; + int var; int Index; int PdtHebdo; CORRESPONDANCES_DES_VARIABLES* CorrespondanceVarNativesVarOptim; @@ -55,50 +55,50 @@ void OPT_InitialiserLesCoutsLineaireCoutsDeDemarrage(PROBLEME_HEBDO* ProblemeHeb PALIERS_THERMIQUES* PaliersThermiquesDuPays; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; CoutLineaire = ProblemeAResoudre->CoutLineaire; for (PdtHebdo = PremierPdtDeLIntervalle, PdtJour = 0; PdtHebdo < DernierPdtDeLIntervalle; PdtHebdo++, PdtJour++) { - CorrespondanceVarNativesVarOptim = ProblemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; + CorrespondanceVarNativesVarOptim = problemeHebdo->CorrespondanceVarNativesVarOptim[PdtJour]; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { Palier = PaliersThermiquesDuPays->NumeroDuPalierDansLEnsembleDesPaliersThermiques[Index]; - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesEnMarcheDuPalierThermique[Palier]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - CoutLineaire[Var] + CoutLineaire[var] = PaliersThermiquesDuPays->CoutFixeDeMarcheDUnGroupeDuPalierThermique[Index]; } - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesQuiSArretentDuPalierThermique[Palier]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - CoutLineaire[Var] + CoutLineaire[var] = PaliersThermiquesDuPays->CoutDArretDUnGroupeDuPalierThermique[Index]; } - Var + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesQuiTombentEnPanneDuPalierThermique[Palier]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) - CoutLineaire[Var] = 0; + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) + CoutLineaire[var] = 0; - Var = CorrespondanceVarNativesVarOptim + var = CorrespondanceVarNativesVarOptim ->NumeroDeVariableDuNombreDeGroupesQuiDemarrentDuPalierThermique[Palier]; - if (Var >= 0 && Var < ProblemeAResoudre->NombreDeVariables) + if (var >= 0 && var < ProblemeAResoudre->NombreDeVariables) { - CoutLineaire[Var] + CoutLineaire[var] = PaliersThermiquesDuPays->CoutDeDemarrageDUnGroupeDuPalierThermique[Index]; } } diff --git a/src/solver/optimisation/opt_gestion_des_pmax.cpp b/src/solver/optimisation/opt_gestion_des_pmax.cpp index 8a23066a2a..baec02c6e0 100644 --- a/src/solver/optimisation/opt_gestion_des_pmax.cpp +++ b/src/solver/optimisation/opt_gestion_des_pmax.cpp @@ -33,7 +33,7 @@ #include "opt_fonctions.h" -void OPT_SauvegarderLesPmaxThermiques(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_SauvegarderLesPmaxThermiques(PROBLEME_HEBDO* problemeHebdo) { int Pays; int Palier; @@ -43,9 +43,9 @@ void OPT_SauvegarderLesPmaxThermiques(PROBLEME_HEBDO* ProblemeHebdo) PALIERS_THERMIQUES* PaliersThermiquesDuPays; PDISP_ET_COUTS_HORAIRES_PAR_PALIER* PuissanceDisponibleEtCout; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Palier = 0; Palier < PaliersThermiquesDuPays->NombreDePaliersThermiques; Palier++) { @@ -57,7 +57,7 @@ void OPT_SauvegarderLesPmaxThermiques(PROBLEME_HEBDO* ProblemeHebdo) memcpy((char*)PuissanceDisponibleDuPalierThermiqueRef_SV, (char*)PuissanceDisponibleDuPalierThermiqueRef, - ProblemeHebdo->NombreDePasDeTempsRef * sizeof(double)); + problemeHebdo->NombreDePasDeTempsRef * sizeof(double)); } } return; diff --git a/src/solver/optimisation/opt_gestion_des_pmin.cpp b/src/solver/optimisation/opt_gestion_des_pmin.cpp index c915139458..bcf3e2c89c 100644 --- a/src/solver/optimisation/opt_gestion_des_pmin.cpp +++ b/src/solver/optimisation/opt_gestion_des_pmin.cpp @@ -37,7 +37,7 @@ #define ZERO 1.e-2 -void OPT_InitialiserLesPminHebdo(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_InitialiserLesPminHebdo(PROBLEME_HEBDO* problemeHebdo) { int Pays; int Palier; @@ -48,11 +48,11 @@ void OPT_InitialiserLesPminHebdo(PROBLEME_HEBDO* ProblemeHebdo) double* PuissanceMinDuPalierThermique_SV; int NombreDePasDeTempsProblemeHebdo; - NombreDePasDeTempsProblemeHebdo = ProblemeHebdo->NombreDePasDeTempsRef; + NombreDePasDeTempsProblemeHebdo = problemeHebdo->NombreDePasDeTempsRef; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; PuissanceDisponibleEtCout = PaliersThermiquesDuPays->PuissanceDisponibleEtCout; for (Palier = 0; Palier < PaliersThermiquesDuPays->NombreDePaliersThermiques; Palier++) { diff --git a/src/solver/optimisation/opt_gestion_second_membre_cas_lineaire.cpp b/src/solver/optimisation/opt_gestion_second_membre_cas_lineaire.cpp index b8fa0616f8..037dd06299 100644 --- a/src/solver/optimisation/opt_gestion_second_membre_cas_lineaire.cpp +++ b/src/solver/optimisation/opt_gestion_second_membre_cas_lineaire.cpp @@ -43,7 +43,7 @@ using namespace Antares; using namespace Antares::Data; using namespace Yuni; -void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHebdo, +void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* problemeHebdo, int PremierPdtDeLIntervalle, int DernierPdtDeLIntervalle, int NumeroDeLIntervalle, @@ -81,27 +81,27 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb CORRESPONDANCES_DES_CONTRAINTES_JOURNALIERES* CorrespondanceCntNativesCntOptimJournalieres; CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES* CorrespondanceCntNativesCntOptimHebdomadaires; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; SecondMembre = ProblemeAResoudre->SecondMembre; AdresseOuPlacerLaValeurDesCoutsMarginaux = ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; - NumeroDeJourDuPasDeTemps = ProblemeHebdo->NumeroDeJourDuPasDeTemps; - NombreDePasDeTempsDUneJournee = ProblemeHebdo->NombreDePasDeTempsDUneJournee; - NumeroDeContrainteEnergieHydraulique = ProblemeHebdo->NumeroDeContrainteEnergieHydraulique; + NumeroDeJourDuPasDeTemps = problemeHebdo->NumeroDeJourDuPasDeTemps; + NombreDePasDeTempsDUneJournee = problemeHebdo->NombreDePasDeTempsDUneJournee; + NumeroDeContrainteEnergieHydraulique = problemeHebdo->NumeroDeContrainteEnergieHydraulique; NumeroDeContrainteMinEnergieHydraulique - = ProblemeHebdo->NumeroDeContrainteMinEnergieHydraulique; + = problemeHebdo->NumeroDeContrainteMinEnergieHydraulique; NumeroDeContrainteMaxEnergieHydraulique - = ProblemeHebdo->NumeroDeContrainteMaxEnergieHydraulique; - NumeroDeContrainteMaxPompage = ProblemeHebdo->NumeroDeContrainteMaxPompage; - NombreDePasDeTempsDUneJournee = ProblemeHebdo->NombreDePasDeTempsDUneJournee; + = problemeHebdo->NumeroDeContrainteMaxEnergieHydraulique; + NumeroDeContrainteMaxPompage = problemeHebdo->NumeroDeContrainteMaxPompage; + NombreDePasDeTempsDUneJournee = problemeHebdo->NombreDePasDeTempsDUneJournee; DefaillanceNegativeUtiliserConsoAbattue - = ProblemeHebdo->DefaillanceNegativeUtiliserConsoAbattue; + = problemeHebdo->DefaillanceNegativeUtiliserConsoAbattue; DefaillanceNegativeUtiliserPMinThermique - = ProblemeHebdo->DefaillanceNegativeUtiliserPMinThermique; + = problemeHebdo->DefaillanceNegativeUtiliserPMinThermique; for (Cnt = 0; Cnt < ProblemeAResoudre->NombreDeContraintes; Cnt++) { @@ -113,25 +113,25 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb for (PdtJour = 0, PdtHebdo = PremierPdtDeLIntervalle; PdtHebdo < DernierPdtDeLIntervalle; PdtHebdo++, PdtJour++) { - CorrespondanceCntNativesCntOptim = ProblemeHebdo->CorrespondanceCntNativesCntOptim[PdtJour]; + CorrespondanceCntNativesCntOptim = problemeHebdo->CorrespondanceCntNativesCntOptim[PdtJour]; - ConsommationsAbattues = ProblemeHebdo->ConsommationsAbattues[PdtHebdo]; - AllMustRunGeneration = ProblemeHebdo->AllMustRunGeneration[PdtHebdo]; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + ConsommationsAbattues = problemeHebdo->ConsommationsAbattues[PdtHebdo]; + AllMustRunGeneration = problemeHebdo->AllMustRunGeneration[PdtHebdo]; + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { Cnt = CorrespondanceCntNativesCntOptim->NumeroDeContrainteDesBilansPays[Pays]; SecondMembre[Cnt] = -ConsommationsAbattues->ConsommationAbattueDuPays[Pays]; - bool reserveJm1 = (ProblemeHebdo->YaDeLaReserveJmoins1 == OUI_ANTARES); + bool reserveJm1 = (problemeHebdo->YaDeLaReserveJmoins1 == OUI_ANTARES); bool opt1 = (optimizationNumber == PREMIERE_OPTIMISATION); if (reserveJm1 && opt1) { SecondMembre[Cnt] - -= ProblemeHebdo->ReserveJMoins1[Pays]->ReserveHoraireJMoins1[PdtHebdo]; + -= problemeHebdo->ReserveJMoins1[Pays]->ReserveHoraireJMoins1[PdtHebdo]; } AdresseDuResultat - = &(ProblemeHebdo->ResultatsHoraires[Pays]->CoutsMarginauxHoraires[PdtHebdo]); + = &(problemeHebdo->ResultatsHoraires[Pays]->CoutsMarginauxHoraires[PdtHebdo]); AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] = AdresseDuResultat; Cnt = CorrespondanceCntNativesCntOptim @@ -155,21 +155,21 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb if (DefaillanceNegativeUtiliserPMinThermique[Pays] == 0) { - SecondMembre[Cnt] -= OPT_SommeDesPminThermiques(ProblemeHebdo, Pays, PdtHebdo); + SecondMembre[Cnt] -= OPT_SommeDesPminThermiques(problemeHebdo, Pays, PdtHebdo); } AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] = NULL; } - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { - CoutDeTransport = ProblemeHebdo->CoutDeTransport[Interco]; + CoutDeTransport = problemeHebdo->CoutDeTransport[Interco]; if (CoutDeTransport->IntercoGereeAvecDesCouts == OUI_ANTARES) { Cnt = CorrespondanceCntNativesCntOptim ->NumeroDeContrainteDeDissociationDeFlux[Interco]; if (CoutDeTransport->IntercoGereeAvecLoopFlow == OUI_ANTARES) - SecondMembre[Cnt] = ProblemeHebdo->ValeursDeNTC[PdtHebdo] + SecondMembre[Cnt] = problemeHebdo->ValeursDeNTC[PdtHebdo] ->ValeurDeLoopFlowOrigineVersExtremite[Interco]; else SecondMembre[Cnt] = 0.; @@ -177,11 +177,11 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb } } - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { MatriceDesContraintesCouplantes - = ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; + = problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante == CONTRAINTE_HORAIRE) { Cnt = CorrespondanceCntNativesCntOptim @@ -191,7 +191,7 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb SecondMembre[Cnt] = MatriceDesContraintesCouplantes ->SecondMembreDeLaContrainteCouplante[PdtHebdo]; AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] - = ProblemeHebdo->ResultatsContraintesCouplantes[CntCouplante].variablesDuales + = problemeHebdo->ResultatsContraintesCouplantes[CntCouplante].variablesDuales + PdtHebdo; } } @@ -201,21 +201,21 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb for (PdtHebdo = PremierPdtDeLIntervalle; PdtHebdo < DernierPdtDeLIntervalle;) { Jour = NumeroDeJourDuPasDeTemps[PdtHebdo]; - if (ProblemeHebdo->OptimisationAuPasHebdomadaire == NON_ANTARES) + if (problemeHebdo->OptimisationAuPasHebdomadaire == NON_ANTARES) { CorrespondanceCntNativesCntOptimJournalieres - = ProblemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[0]; + = problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[0]; } else { CorrespondanceCntNativesCntOptimJournalieres - = ProblemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[Jour]; + = problemeHebdo->CorrespondanceCntNativesCntOptimJournalieres[Jour]; } - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { MatriceDesContraintesCouplantes - = ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; + = problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante == CONTRAINTE_JOURNALIERE) { @@ -226,7 +226,7 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb SecondMembre[Cnt] = MatriceDesContraintesCouplantes->SecondMembreDeLaContrainteCouplante[Jour]; AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] - = ProblemeHebdo->ResultatsContraintesCouplantes[CntCouplante].variablesDuales + = problemeHebdo->ResultatsContraintesCouplantes[CntCouplante].variablesDuales + Jour; } } @@ -234,17 +234,17 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb PdtHebdo += NombreDePasDeTempsDUneJournee; } - if (ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation - > ProblemeHebdo->NombreDePasDeTempsDUneJournee) + if (problemeHebdo->NombreDePasDeTempsPourUneOptimisation + > problemeHebdo->NombreDePasDeTempsDUneJournee) { Semaine = 0; CorrespondanceCntNativesCntOptimHebdomadaires - = ProblemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires[Semaine]; - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + = problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires[Semaine]; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { MatriceDesContraintesCouplantes - = ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; + = problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante == CONTRAINTE_HEBDOMADAIRE) { @@ -255,40 +255,40 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb SecondMembre[Cnt] = MatriceDesContraintesCouplantes ->SecondMembreDeLaContrainteCouplante[Semaine]; AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] - = ProblemeHebdo->ResultatsContraintesCouplantes[CntCouplante].variablesDuales + = problemeHebdo->ResultatsContraintesCouplantes[CntCouplante].variablesDuales + Semaine; } } } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { Cnt = NumeroDeContrainteEnergieHydraulique[Pays]; if (Cnt >= 0) { - SecondMembre[Cnt] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + SecondMembre[Cnt] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->CntEnergieH2OParIntervalleOptimise[NumeroDeLIntervalle]; AdresseDuResultat = NULL; AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] = AdresseDuResultat; } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { char presenceHydro - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; char TurbEntreBornes - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; if (presenceHydro == OUI_ANTARES && (TurbEntreBornes == OUI_ANTARES - || ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable + || problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable == OUI_ANTARES)) { Cnt = NumeroDeContrainteMinEnergieHydraulique[Pays]; if (Cnt >= 0) { - SecondMembre[Cnt] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + SecondMembre[Cnt] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->MinEnergieHydrauParIntervalleOptimise[NumeroDeLIntervalle]; AdresseDuResultat = NULL; AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] = AdresseDuResultat; @@ -296,21 +296,21 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { char presenceHydro - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; char TurbEntreBornes - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; if (presenceHydro == OUI_ANTARES && (TurbEntreBornes == OUI_ANTARES - || ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable + || problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable == OUI_ANTARES)) { Cnt = NumeroDeContrainteMaxEnergieHydraulique[Pays]; if (Cnt >= 0) { - SecondMembre[Cnt] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + SecondMembre[Cnt] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->MaxEnergieHydrauParIntervalleOptimise[NumeroDeLIntervalle]; AdresseDuResultat = NULL; AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] = AdresseDuResultat; @@ -318,15 +318,15 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable == OUI_ANTARES) { Cnt = NumeroDeContrainteMaxPompage[Pays]; if (Cnt >= 0) { - SecondMembre[Cnt] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + SecondMembre[Cnt] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->MaxEnergiePompageParIntervalleOptimise[NumeroDeLIntervalle]; AdresseDuResultat = NULL; AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] = AdresseDuResultat; @@ -337,21 +337,21 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb for (PdtJour = 0, PdtHebdo = PremierPdtDeLIntervalle; PdtHebdo < DernierPdtDeLIntervalle; PdtHebdo++, PdtJour++) { - CorrespondanceCntNativesCntOptim = ProblemeHebdo->CorrespondanceCntNativesCntOptim[PdtJour]; + CorrespondanceCntNativesCntOptim = problemeHebdo->CorrespondanceCntNativesCntOptim[PdtJour]; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->SuiviNiveauHoraire == OUI_ANTARES) { Cnt = CorrespondanceCntNativesCntOptim->NumeroDeContrainteDesNiveauxPays[Pays]; if (Cnt >= 0) { - SecondMembre[Cnt] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + SecondMembre[Cnt] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->ApportNaturelHoraire[PdtHebdo]; if (PdtHebdo == 0) { - SecondMembre[Cnt] += ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + SecondMembre[Cnt] += problemeHebdo->CaracteristiquesHydrauliques[Pays] ->NiveauInitialReservoir; } AdresseDuResultat = NULL; @@ -361,12 +361,12 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES - && ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->DirectLevelAccess == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES + && problemeHebdo->CaracteristiquesHydrauliques[Pays]->DirectLevelAccess == OUI_ANTARES) { - Cnt = ProblemeHebdo->NumeroDeContrainteEquivalenceStockFinal[Pays]; + Cnt = problemeHebdo->NumeroDeContrainteEquivalenceStockFinal[Pays]; if (Cnt >= 0) { SecondMembre[Cnt] = 0; @@ -374,9 +374,9 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb AdresseOuPlacerLaValeurDesCoutsMarginaux[Cnt] = NULL; } } - if (ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) + if (problemeHebdo->CaracteristiquesHydrauliques[Pays]->AccurateWaterValue == OUI_ANTARES) { - Cnt = ProblemeHebdo->NumeroDeContrainteExpressionStockFinal[Pays]; + Cnt = problemeHebdo->NumeroDeContrainteExpressionStockFinal[Pays]; if (Cnt >= 0) { SecondMembre[Cnt] = 0; @@ -386,10 +386,10 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* ProblemeHeb } } - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) { OPT_InitialiserLeSecondMembreDuProblemeLineaireCoutsDeDemarrage( - ProblemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle); + problemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle); } return; diff --git a/src/solver/optimisation/opt_gestion_second_membre_cas_quadratique.cpp b/src/solver/optimisation/opt_gestion_second_membre_cas_quadratique.cpp index 5a18c70e63..44d09cd775 100644 --- a/src/solver/optimisation/opt_gestion_second_membre_cas_quadratique.cpp +++ b/src/solver/optimisation/opt_gestion_second_membre_cas_quadratique.cpp @@ -32,18 +32,18 @@ #include "opt_fonctions.h" -void OPT_InitialiserLeSecondMembreDuProblemeQuadratique(PROBLEME_HEBDO* ProblemeHebdo, int PdtHebdo) +void OPT_InitialiserLeSecondMembreDuProblemeQuadratique(PROBLEME_HEBDO* problemeHebdo, int PdtHebdo) { int Cnt; int Pays; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays - 1; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays - 1; Pays++) { - Cnt = ProblemeHebdo->NumeroDeContrainteDeSoldeDEchange[Pays]; + Cnt = problemeHebdo->NumeroDeContrainteDeSoldeDEchange[Pays]; ProblemeAResoudre->SecondMembre[Cnt] - = ProblemeHebdo->SoldeMoyenHoraire[PdtHebdo]->SoldeMoyenDuPays[Pays]; + = problemeHebdo->SoldeMoyenHoraire[PdtHebdo]->SoldeMoyenDuPays[Pays]; } -} +} \ No newline at end of file diff --git a/src/solver/optimisation/opt_gestion_second_membre_couts_demarrage.cpp b/src/solver/optimisation/opt_gestion_second_membre_couts_demarrage.cpp index e09d3fdb06..564abe39c7 100644 --- a/src/solver/optimisation/opt_gestion_second_membre_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_gestion_second_membre_couts_demarrage.cpp @@ -43,7 +43,7 @@ using namespace Antares; using namespace Antares::Data; using namespace Yuni; -void OPT_InitialiserLeSecondMembreDuProblemeLineaireCoutsDeDemarrage(PROBLEME_HEBDO* ProblemeHebdo, +void OPT_InitialiserLeSecondMembreDuProblemeLineaireCoutsDeDemarrage(PROBLEME_HEBDO* problemeHebdo, int PremierPdtDeLIntervalle, int DernierPdtDeLIntervalle) { @@ -66,17 +66,17 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaireCoutsDeDemarrage(PROBLEME_HE PALIERS_THERMIQUES* PaliersThermiquesDuPays; CORRESPONDANCES_DES_CONTRAINTES* CorrespondanceCntNativesCntOptim; - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; SecondMembre = ProblemeAResoudre->SecondMembre; AdresseOuPlacerLaValeurDesCoutsMarginaux = ProblemeAResoudre->AdresseOuPlacerLaValeurDesCoutsMarginaux; - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { @@ -93,7 +93,7 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaireCoutsDeDemarrage(PROBLEME_HE PdtHebdo++, PdtJour++) { CorrespondanceCntNativesCntOptim - = ProblemeHebdo->CorrespondanceCntNativesCntOptim[PdtJour]; + = problemeHebdo->CorrespondanceCntNativesCntOptim[PdtJour]; #if VARIABLES_MMOINS_MOINS_BORNEES_DES_2_COTES != OUI_ANTARES Cnt = CorrespondanceCntNativesCntOptim diff --git a/src/solver/optimisation/opt_init_contraintes_hydrauliques.cpp b/src/solver/optimisation/opt_init_contraintes_hydrauliques.cpp index 07cfe109a8..d9165aa513 100644 --- a/src/solver/optimisation/opt_init_contraintes_hydrauliques.cpp +++ b/src/solver/optimisation/opt_init_contraintes_hydrauliques.cpp @@ -37,7 +37,7 @@ #include "../simulation/sim_structure_probleme_adequation.h" void OPT_InitialiserLesContrainteDEnergieHydrauliqueParIntervalleOptimise( - PROBLEME_HEBDO* ProblemeHebdo) + PROBLEME_HEBDO* problemeHebdo) { int NombreDePasDeTempsPourUneOptimisation; int NbIntervallesOptimises; @@ -55,29 +55,29 @@ void OPT_InitialiserLesContrainteDEnergieHydrauliqueParIntervalleOptimise( double* CntEnergieH2OParJour; double InflowSum; - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; NbIntervallesOptimises - = (int)(ProblemeHebdo->NombreDePasDeTemps / NombreDePasDeTempsPourUneOptimisation); + = (int)(problemeHebdo->NombreDePasDeTemps / NombreDePasDeTempsPourUneOptimisation); NombreDeJoursParIntervalle - = (int)(NombreDePasDeTempsPourUneOptimisation / ProblemeHebdo->NombreDePasDeTempsDUneJournee); + = (int)(NombreDePasDeTempsPourUneOptimisation / problemeHebdo->NombreDePasDeTempsDUneJournee); - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { char presenceHydro - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; char TurbEntreBornes - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; if (presenceHydro == OUI_ANTARES && TurbEntreBornes == NON_ANTARES) { - CntEnergieH2OParIntervalleOptimise = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + CntEnergieH2OParIntervalleOptimise = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->CntEnergieH2OParIntervalleOptimise; CntEnergieH2OParIntervalleOptimiseRef - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->CntEnergieH2OParIntervalleOptimiseRef; CntEnergieH2OParJour - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->CntEnergieH2OParJour; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->CntEnergieH2OParJour; Jour = 0; for (i = 0; i < NbIntervallesOptimises; i++) @@ -100,25 +100,25 @@ void OPT_InitialiserLesContrainteDEnergieHydrauliqueParIntervalleOptimise( double* MinEnergieHydrauParIntervalleOptimise; double* MaxEnergieHydrauParIntervalleOptimise; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { char presenceHydro - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDHydrauliqueModulable; char TurbEntreBornes - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->TurbinageEntreBornes; if (presenceHydro == OUI_ANTARES && (TurbEntreBornes == OUI_ANTARES - || ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable + || problemeHebdo->CaracteristiquesHydrauliques[Pays]->PresenceDePompageModulable == OUI_ANTARES)) { MinEnergieHydrauParIntervalleOptimise - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->MinEnergieHydrauParIntervalleOptimise; MaxEnergieHydrauParIntervalleOptimise - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->MaxEnergieHydrauParIntervalleOptimise; CntEnergieH2OParJour - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->CntEnergieH2OParJour; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->CntEnergieH2OParJour; Jour = 0; for (i = 0; i < NbIntervallesOptimises; i++) { @@ -129,7 +129,7 @@ void OPT_InitialiserLesContrainteDEnergieHydrauliqueParIntervalleOptimise( CntMinEParIntervalle += MinEnergieHydrauParIntervalleOptimise[Jour]; CntMaxEParIntervalle += MaxEnergieHydrauParIntervalleOptimise[Jour]; - CntEnergieH2OParJour[Jour] = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + CntEnergieH2OParJour[Jour] = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->MaxEnergieHydrauParIntervalleOptimise[Jour]; } MinEnergieHydrauParIntervalleOptimise[i] = CntMinEParIntervalle; @@ -140,9 +140,9 @@ void OPT_InitialiserLesContrainteDEnergieHydrauliqueParIntervalleOptimise( double* MaxEnergiePompageParIntervalleOptimise; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - MaxEnergiePompageParIntervalleOptimise = ProblemeHebdo->CaracteristiquesHydrauliques[Pays] + MaxEnergiePompageParIntervalleOptimise = problemeHebdo->CaracteristiquesHydrauliques[Pays] ->MaxEnergiePompageParIntervalleOptimise; Jour = 0; @@ -159,10 +159,10 @@ void OPT_InitialiserLesContrainteDEnergieHydrauliqueParIntervalleOptimise( double* InflowForTimeInterval; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { InflowForTimeInterval - = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]->InflowForTimeInterval; + = problemeHebdo->CaracteristiquesHydrauliques[Pays]->InflowForTimeInterval; Jour = 0; for (i = 0; i < NbIntervallesOptimises; i++) { diff --git a/src/solver/optimisation/opt_init_minmax_groupes_couts_demarrage.cpp b/src/solver/optimisation/opt_init_minmax_groupes_couts_demarrage.cpp index 69c6c7a70c..1f36db0255 100644 --- a/src/solver/optimisation/opt_init_minmax_groupes_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_init_minmax_groupes_couts_demarrage.cpp @@ -33,7 +33,7 @@ #include "opt_fonctions.h" -void OPT_InitialiserNombreMinEtMaxDeGroupesCoutsDeDemarrage(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_InitialiserNombreMinEtMaxDeGroupesCoutsDeDemarrage(PROBLEME_HEBDO* problemeHebdo) { int Pays; int Index; @@ -48,14 +48,14 @@ void OPT_InitialiserNombreMinEtMaxDeGroupesCoutsDeDemarrage(PROBLEME_HEBDO* Prob int* NombreMinDeGroupesEnMarcheDuPalierThermique; double* PuissanceDisponibleDuPalierThermiqueRef_SV; - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == NON_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == NON_ANTARES) return; - NombreDePasDeTempsProblemeHebdo = ProblemeHebdo->NombreDePasDeTemps; + NombreDePasDeTempsProblemeHebdo = problemeHebdo->NombreDePasDeTemps; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; PuissanceDisponibleEtCout = PaliersThermiquesDuPays->PuissanceDisponibleEtCout; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) diff --git a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp index 5af6e39e7e..ff2c0eb0b3 100644 --- a/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp +++ b/src/solver/optimisation/opt_liberation_problemes_simplexe.cpp @@ -45,7 +45,7 @@ extern "C" using namespace Antares; -void OPT_LiberationProblemesSimplexe(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_LiberationProblemesSimplexe(PROBLEME_HEBDO* problemeHebdo) { PROBLEME_SPX* ProbSpx; PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; @@ -54,24 +54,24 @@ void OPT_LiberationProblemesSimplexe(PROBLEME_HEBDO* ProblemeHebdo) int NombreDePasDeTempsPourUneOptimisation; MPSolver* solver; - if (ProblemeHebdo->OptimisationAuPasHebdomadaire == NON_ANTARES) + if (problemeHebdo->OptimisationAuPasHebdomadaire == NON_ANTARES) { - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsDUneJournee; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsDUneJournee; } else { - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTemps; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTemps; } NbIntervalles - = (int)(ProblemeHebdo->NombreDePasDeTemps / NombreDePasDeTempsPourUneOptimisation); + = (int)(problemeHebdo->NombreDePasDeTemps / NombreDePasDeTempsPourUneOptimisation); - ProblemeAResoudre = ProblemeHebdo->ProblemeAResoudre; + ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; if (ProblemeAResoudre) { auto& study = *Data::Study::Current::Get(); bool ortoolsUsed = study.parameters.ortoolsUsed; - if (ProblemeHebdo->LeProblemeADejaEteInstancie == NON_ANTARES) + if (problemeHebdo->LeProblemeADejaEteInstancie == NON_ANTARES) { for (NumIntervalle = 0; NumIntervalle < NbIntervalles; NumIntervalle++) { diff --git a/src/solver/optimisation/opt_nombre_min_groupes_demarres_couts_demarrage.cpp b/src/solver/optimisation/opt_nombre_min_groupes_demarres_couts_demarrage.cpp index dcea01ad6b..ea5d48c7b3 100644 --- a/src/solver/optimisation/opt_nombre_min_groupes_demarres_couts_demarrage.cpp +++ b/src/solver/optimisation/opt_nombre_min_groupes_demarres_couts_demarrage.cpp @@ -61,7 +61,7 @@ void OPT_PbLineairePourAjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage(PROBL int, int); -void OPT_AjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_AjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage(PROBLEME_HEBDO* problemeHebdo) { int Pays; int Index; @@ -89,23 +89,23 @@ void OPT_AjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage(PROBLEME_HEBDO* Pro PDISP_ET_COUTS_HORAIRES_PAR_PALIER** PuissanceDisponibleEtCout; PALIERS_THERMIQUES* PaliersThermiquesDuPays; - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == NON_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == NON_ANTARES) return; - NombreDePasDeTempsProblemeHebdo = ProblemeHebdo->NombreDePasDeTemps; + NombreDePasDeTempsProblemeHebdo = problemeHebdo->NombreDePasDeTemps; Eps = 1.e-3; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; ++Pays) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; ++Pays) { - ResultatsHoraires = ProblemeHebdo->ResultatsHoraires[Pays]; + ResultatsHoraires = problemeHebdo->ResultatsHoraires[Pays]; ProductionThermique = ResultatsHoraires->ProductionThermique; - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; PuissanceDisponibleEtCout = PaliersThermiquesDuPays->PuissanceDisponibleEtCout; for (Index = 0; Index < PaliersThermiquesDuPays->NombreDePaliersThermiques; Index++) { - if (ProblemeHebdo->Expansion) + if (problemeHebdo->Expansion) { NombreMinDeGroupesEnMarcheDuPalierThermique = PuissanceDisponibleEtCout[Index]->NombreMinDeGroupesEnMarcheDuPalierThermique; @@ -207,7 +207,7 @@ void OPT_AjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage(PROBLEME_HEBDO* Pro } OPT_PbLineairePourAjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage( - ProblemeHebdo, NombreMinDeGroupesEnMarcheDuPalierThermique, Pays, Index); + problemeHebdo, NombreMinDeGroupesEnMarcheDuPalierThermique, Pays, Index); for (PdtHebdo = 0; PdtHebdo < NombreDePasDeTempsProblemeHebdo; PdtHebdo++) { @@ -231,7 +231,7 @@ void OPT_AjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage(PROBLEME_HEBDO* Pro } void OPT_PbLineairePourAjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage( - PROBLEME_HEBDO* ProblemeHebdo, + PROBLEME_HEBDO* problemeHebdo, int* NbMinOptDeGroupesEnMarche, int Pays, int Index) @@ -270,16 +270,16 @@ void OPT_PbLineairePourAjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage( int* PositionDeLaVariable; int* ComplementDeLaBase; int ResoudreLeProblemeLineaire; - int Var; + int var; PRODUCTION_THERMIQUE_OPTIMALE** ProductionThermique; PROBLEME_SIMPLEXE Probleme; PROBLEME_SPX* ProbSpx; - NombreDePasDeTempsProblemeHebdo = ProblemeHebdo->NombreDePasDeTemps; + NombreDePasDeTempsProblemeHebdo = problemeHebdo->NombreDePasDeTemps; NombreDePasDeTemps = NombreDePasDeTempsProblemeHebdo; - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; NombreMaxDeGroupesEnMarcheDuPalierThermique = PaliersThermiquesDuPays->PuissanceDisponibleEtCout[Index] ->NombreMaxDeGroupesEnMarcheDuPalierThermique; @@ -288,7 +288,7 @@ void OPT_PbLineairePourAjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage( DureeMinimaleDArretDUnGroupeDuPalierThermique = PaliersThermiquesDuPays->DureeMinimaleDArretDUnGroupeDuPalierThermique[Index]; - ProductionThermique = ProblemeHebdo->ResultatsHoraires[Pays]->ProductionThermique; + ProductionThermique = problemeHebdo->ResultatsHoraires[Pays]->ProductionThermique; ResoudreLeProblemeLineaire = NON_ANTARES; @@ -576,17 +576,17 @@ void OPT_PbLineairePourAjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage( } NombreDeContraintes++; #else - Var = NumeroDeVariableDeMMoinsMoins[Pdt]; + var = NumeroDeVariableDeMMoinsMoins[Pdt]; t1 = Pdt; t1moins1 = t1 - 1; if (t1moins1 < 0) t1moins1 = NombreDePasDeTemps + t1moins1; - Xmax[Var] = 0; + Xmax[var] = 0; if (NombreMaxDeGroupesEnMarcheDuPalierThermique[t1moins1] - NombreMaxDeGroupesEnMarcheDuPalierThermique[t1] > 0) { - Xmax[Var] = NombreMaxDeGroupesEnMarcheDuPalierThermique[t1moins1] + Xmax[var] = NombreMaxDeGroupesEnMarcheDuPalierThermique[t1moins1] - NombreMaxDeGroupesEnMarcheDuPalierThermique[t1]; } #endif diff --git a/src/solver/optimisation/opt_numero_de_jour_du_pas_de_temps.cpp b/src/solver/optimisation/opt_numero_de_jour_du_pas_de_temps.cpp index 6cf8f1743a..cb64e99398 100644 --- a/src/solver/optimisation/opt_numero_de_jour_du_pas_de_temps.cpp +++ b/src/solver/optimisation/opt_numero_de_jour_du_pas_de_temps.cpp @@ -33,28 +33,28 @@ #include "opt_fonctions.h" -void OPT_NumeroDeJourDuPasDeTemps(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_NumeroDeJourDuPasDeTemps(PROBLEME_HEBDO* problemeHebdo) { double X; int PdtHebdo; - ProblemeHebdo->NombreDeJours - = (int)(ProblemeHebdo->NombreDePasDeTemps / ProblemeHebdo->NombreDePasDeTempsDUneJournee); - for (PdtHebdo = 0; PdtHebdo < ProblemeHebdo->NombreDePasDeTemps; PdtHebdo++) + problemeHebdo->NombreDeJours + = (int)(problemeHebdo->NombreDePasDeTemps / problemeHebdo->NombreDePasDeTempsDUneJournee); + for (PdtHebdo = 0; PdtHebdo < problemeHebdo->NombreDePasDeTemps; PdtHebdo++) { - X = PdtHebdo / ProblemeHebdo->NombreDePasDeTempsDUneJournee; - ProblemeHebdo->NumeroDeJourDuPasDeTemps[PdtHebdo] = (int)floor(X); + X = PdtHebdo / problemeHebdo->NombreDePasDeTempsDUneJournee; + problemeHebdo->NumeroDeJourDuPasDeTemps[PdtHebdo] = (int)floor(X); } return; } -void OPT_NumeroDIntervalleOptimiseDuPasDeTemps(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_NumeroDIntervalleOptimiseDuPasDeTemps(PROBLEME_HEBDO* problemeHebdo) { double X; int PdtHebdo; - for (PdtHebdo = 0; PdtHebdo < ProblemeHebdo->NombreDePasDeTemps; PdtHebdo++) + for (PdtHebdo = 0; PdtHebdo < problemeHebdo->NombreDePasDeTemps; PdtHebdo++) { - X = PdtHebdo / ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; - ProblemeHebdo->NumeroDIntervalleOptimiseDuPasDeTemps[PdtHebdo] = (int)floor(X); + X = PdtHebdo / problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + problemeHebdo->NumeroDIntervalleOptimiseDuPasDeTemps[PdtHebdo] = (int)floor(X); } return; } diff --git a/src/solver/optimisation/opt_optimisation_lineaire.cpp b/src/solver/optimisation/opt_optimisation_lineaire.cpp index b28bfd039e..98e233acf0 100644 --- a/src/solver/optimisation/opt_optimisation_lineaire.cpp +++ b/src/solver/optimisation/opt_optimisation_lineaire.cpp @@ -46,7 +46,7 @@ double OPT_ObjectiveFunctionResult(const PROBLEME_HEBDO* Probleme, return Probleme->coutOptimalSolution2[NumeroDeLIntervalle]; } -bool OPT_OptimisationLineaire(PROBLEME_HEBDO* ProblemeHebdo, uint numSpace) +bool OPT_OptimisationLineaire(PROBLEME_HEBDO* problemeHebdo, uint numSpace) { int PdtHebdo; int PremierPdtDeLIntervalle; @@ -55,69 +55,69 @@ bool OPT_OptimisationLineaire(PROBLEME_HEBDO* ProblemeHebdo, uint numSpace) int NombreDePasDeTempsPourUneOptimisation; int optimizationNumber = PREMIERE_OPTIMISATION; - ProblemeHebdo->NombreDePasDeTemps = ProblemeHebdo->NombreDePasDeTempsRef; - ProblemeHebdo->NombreDePasDeTempsDUneJournee = ProblemeHebdo->NombreDePasDeTempsDUneJourneeRef; + problemeHebdo->NombreDePasDeTemps = problemeHebdo->NombreDePasDeTempsRef; + problemeHebdo->NombreDePasDeTempsDUneJournee = problemeHebdo->NombreDePasDeTempsDUneJourneeRef; - if (ProblemeHebdo->OptimisationAuPasHebdomadaire == NON_ANTARES) + if (problemeHebdo->OptimisationAuPasHebdomadaire == NON_ANTARES) { - ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation - = ProblemeHebdo->NombreDePasDeTempsDUneJournee; + problemeHebdo->NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsDUneJournee; } else { - ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTemps; + problemeHebdo->NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTemps; } - NombreDePasDeTempsPourUneOptimisation = ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; + NombreDePasDeTempsPourUneOptimisation = problemeHebdo->NombreDePasDeTempsPourUneOptimisation; - OPT_NumeroDeJourDuPasDeTemps(ProblemeHebdo); + OPT_NumeroDeJourDuPasDeTemps(problemeHebdo); - OPT_NumeroDIntervalleOptimiseDuPasDeTemps(ProblemeHebdo); + OPT_NumeroDIntervalleOptimiseDuPasDeTemps(problemeHebdo); - OPT_RestaurerLesDonnees(ProblemeHebdo, optimizationNumber); + OPT_RestaurerLesDonnees(problemeHebdo, optimizationNumber); - OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(ProblemeHebdo); + OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeLineaire(problemeHebdo); - OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(ProblemeHebdo); + OPT_ConstruireLaMatriceDesContraintesDuProblemeLineaire(problemeHebdo); OptimisationHebdo: - for (PdtHebdo = 0, NumeroDeLIntervalle = 0; PdtHebdo < ProblemeHebdo->NombreDePasDeTemps; + for (PdtHebdo = 0, NumeroDeLIntervalle = 0; PdtHebdo < problemeHebdo->NombreDePasDeTemps; PdtHebdo = DernierPdtDeLIntervalle, NumeroDeLIntervalle++) { PremierPdtDeLIntervalle = PdtHebdo; DernierPdtDeLIntervalle = PdtHebdo + NombreDePasDeTempsPourUneOptimisation; OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire( - ProblemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle, optimizationNumber); + problemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle, optimizationNumber); - OPT_InitialiserLeSecondMembreDuProblemeLineaire(ProblemeHebdo, + OPT_InitialiserLeSecondMembreDuProblemeLineaire(problemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle, NumeroDeLIntervalle, optimizationNumber); OPT_InitialiserLesCoutsLineaire( - ProblemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle, numSpace); + problemeHebdo, PremierPdtDeLIntervalle, DernierPdtDeLIntervalle, numSpace); // An optimization period represents a sequence as - or --, // depending whether the optimization is daily or weekly. // These sequences are used when building the names of MPS or criterion files. auto optPeriodStringGenerator - = createOptPeriodAsString(ProblemeHebdo->OptimisationAuPasHebdomadaire, + = createOptPeriodAsString(problemeHebdo->OptimisationAuPasHebdomadaire, NumeroDeLIntervalle, - ProblemeHebdo->weekInTheYear, - ProblemeHebdo->year); + problemeHebdo->weekInTheYear, + problemeHebdo->year); if (!OPT_AppelDuSimplexe( - ProblemeHebdo, NumeroDeLIntervalle, optimizationNumber, optPeriodStringGenerator)) + problemeHebdo, NumeroDeLIntervalle, optimizationNumber, optPeriodStringGenerator)) return false; - if (ProblemeHebdo->ExportMPS != Data::mpsExportStatus::NO_EXPORT - || ProblemeHebdo->Expansion == OUI_ANTARES) + if (problemeHebdo->ExportMPS != Data::mpsExportStatus::NO_EXPORT + || problemeHebdo->Expansion == OUI_ANTARES) { double optimalSolutionCost - = OPT_ObjectiveFunctionResult(ProblemeHebdo, NumeroDeLIntervalle, optimizationNumber); + = OPT_ObjectiveFunctionResult(problemeHebdo, NumeroDeLIntervalle, optimizationNumber); OPT_EcrireResultatFonctionObjectiveAuFormatTXT( optimalSolutionCost, optPeriodStringGenerator, optimizationNumber); } @@ -125,21 +125,21 @@ bool OPT_OptimisationLineaire(PROBLEME_HEBDO* ProblemeHebdo, uint numSpace) if (optimizationNumber == PREMIERE_OPTIMISATION) { - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == NON_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == NON_ANTARES) { - OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(ProblemeHebdo); + OPT_CalculerLesPminThermiquesEnFonctionDeMUTetMDT(problemeHebdo); } - else if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) + else if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) { - OPT_AjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage(ProblemeHebdo); + OPT_AjusterLeNombreMinDeGroupesDemarresCoutsDeDemarrage(problemeHebdo); } else - printf("BUG: l'indicateur ProblemeHebdo->OptimisationAvecCoutsDeDemarrage doit etre " + printf("BUG: l'indicateur problemeHebdo->OptimisationAvecCoutsDeDemarrage doit etre " "initialise a OUI_ANTARES ou NON_ANTARES\n"); optimizationNumber = DEUXIEME_OPTIMISATION; - if (ProblemeHebdo->Expansion == NON_ANTARES) + if (problemeHebdo->Expansion == NON_ANTARES) goto OptimisationHebdo; } diff --git a/src/solver/optimisation/opt_period_string_generator_base.h b/src/solver/optimisation/opt_period_string_generator_base.h index 6dac592a54..2a5d2f2d12 100644 --- a/src/solver/optimisation/opt_period_string_generator_base.h +++ b/src/solver/optimisation/opt_period_string_generator_base.h @@ -1,3 +1,30 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + #pragma once #include diff --git a/src/solver/optimisation/opt_pilotage_optimisation_lineaire.cpp b/src/solver/optimisation/opt_pilotage_optimisation_lineaire.cpp index acd665ecff..9992a30c10 100644 --- a/src/solver/optimisation/opt_pilotage_optimisation_lineaire.cpp +++ b/src/solver/optimisation/opt_pilotage_optimisation_lineaire.cpp @@ -36,56 +36,56 @@ #include "spx_definition_arguments.h" #include "spx_fonctions.h" -bool OPT_PilotageOptimisationLineaire(PROBLEME_HEBDO* ProblemeHebdo, uint numSpace) +bool OPT_PilotageOptimisationLineaire(PROBLEME_HEBDO* problemeHebdo, uint numSpace) { - if (ProblemeHebdo->LeProblemeADejaEteInstancie == NON_ANTARES) + if (problemeHebdo->LeProblemeADejaEteInstancie == NON_ANTARES) { - if (ProblemeHebdo->TypeDOptimisation == OPTIMISATION_LINEAIRE) + if (problemeHebdo->TypeDOptimisation == OPTIMISATION_LINEAIRE) { - for (int Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (int Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - ProblemeHebdo->CoutDeDefaillanceEnReserve[Pays] = 1.e+6; + problemeHebdo->CoutDeDefaillanceEnReserve[Pays] = 1.e+6; } - ProblemeHebdo->NombreDePasDeTempsRef = ProblemeHebdo->NombreDePasDeTemps; - ProblemeHebdo->NombreDePasDeTempsDUneJourneeRef - = ProblemeHebdo->NombreDePasDeTempsDUneJournee; - ProblemeHebdo->NombreDeJours = (int)(ProblemeHebdo->NombreDePasDeTemps - / ProblemeHebdo->NombreDePasDeTempsDUneJournee); + problemeHebdo->NombreDePasDeTempsRef = problemeHebdo->NombreDePasDeTemps; + problemeHebdo->NombreDePasDeTempsDUneJourneeRef + = problemeHebdo->NombreDePasDeTempsDUneJournee; + problemeHebdo->NombreDeJours = (int)(problemeHebdo->NombreDePasDeTemps + / problemeHebdo->NombreDePasDeTempsDUneJournee); - if (ProblemeHebdo->OptimisationAuPasHebdomadaire == NON_ANTARES) + if (problemeHebdo->OptimisationAuPasHebdomadaire == NON_ANTARES) { - ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation - = ProblemeHebdo->NombreDePasDeTempsDUneJournee; + problemeHebdo->NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTempsDUneJournee; } else { - ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation - = ProblemeHebdo->NombreDePasDeTemps; + problemeHebdo->NombreDePasDeTempsPourUneOptimisation + = problemeHebdo->NombreDePasDeTemps; } - OPT_AllocDuProblemeAOptimiser(ProblemeHebdo); + OPT_AllocDuProblemeAOptimiser(problemeHebdo); - OPT_ChainagesDesIntercoPartantDUnNoeud(ProblemeHebdo); + OPT_ChainagesDesIntercoPartantDUnNoeud(problemeHebdo); } - ProblemeHebdo->LeProblemeADejaEteInstancie = OUI_ANTARES; + problemeHebdo->LeProblemeADejaEteInstancie = OUI_ANTARES; } - OPT_VerifierPresenceReserveJmoins1(ProblemeHebdo); + OPT_VerifierPresenceReserveJmoins1(problemeHebdo); - OPT_SauvegarderLesPmaxThermiques(ProblemeHebdo); + OPT_SauvegarderLesPmaxThermiques(problemeHebdo); - OPT_InitialiserLesPminHebdo(ProblemeHebdo); + OPT_InitialiserLesPminHebdo(problemeHebdo); - OPT_InitialiserLesContrainteDEnergieHydrauliqueParIntervalleOptimise(ProblemeHebdo); + OPT_InitialiserLesContrainteDEnergieHydrauliqueParIntervalleOptimise(problemeHebdo); - OPT_MaxDesPmaxHydrauliques(ProblemeHebdo); + OPT_MaxDesPmaxHydrauliques(problemeHebdo); - if (ProblemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) + if (problemeHebdo->OptimisationAvecCoutsDeDemarrage == OUI_ANTARES) { - OPT_InitialiserNombreMinEtMaxDeGroupesCoutsDeDemarrage(ProblemeHebdo); + OPT_InitialiserNombreMinEtMaxDeGroupesCoutsDeDemarrage(problemeHebdo); } - return OPT_OptimisationLineaire(ProblemeHebdo, numSpace); + return OPT_OptimisationLineaire(problemeHebdo, numSpace); } diff --git a/src/solver/optimisation/opt_pilotage_optimisation_quadratique.cpp b/src/solver/optimisation/opt_pilotage_optimisation_quadratique.cpp index 98deb1413f..17f8200e93 100644 --- a/src/solver/optimisation/opt_pilotage_optimisation_quadratique.cpp +++ b/src/solver/optimisation/opt_pilotage_optimisation_quadratique.cpp @@ -39,37 +39,37 @@ extern "C" #include "spx_fonctions.h" } -bool OPT_PilotageOptimisationQuadratique(PROBLEME_HEBDO* ProblemeHebdo) +bool OPT_PilotageOptimisationQuadratique(PROBLEME_HEBDO* problemeHebdo) { int PdtHebdo; - if (ProblemeHebdo->LeProblemeADejaEteInstancie == NON_ANTARES) + if (problemeHebdo->LeProblemeADejaEteInstancie == NON_ANTARES) { - OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeQuadratique(ProblemeHebdo); + OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeQuadratique(problemeHebdo); - OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique(ProblemeHebdo); + OPT_ConstruireLaMatriceDesContraintesDuProblemeQuadratique(problemeHebdo); - ProblemeHebdo->LeProblemeADejaEteInstancie = OUI_ANTARES; + problemeHebdo->LeProblemeADejaEteInstancie = OUI_ANTARES; } bool result = true; - if (ProblemeHebdo->NombreDInterconnexions > 0) + if (problemeHebdo->NombreDInterconnexions > 0) { - for (PdtHebdo = 0; PdtHebdo < ProblemeHebdo->NombreDePasDeTemps; PdtHebdo++) + for (PdtHebdo = 0; PdtHebdo < problemeHebdo->NombreDePasDeTemps; PdtHebdo++) { #ifdef dbgInfos printf("*********** Optimisation quadratique du pas de temps %ld ***********\n", PdtHebdo); #endif - OPT_InitialiserLesBornesDesVariablesDuProblemeQuadratique(ProblemeHebdo, PdtHebdo); + OPT_InitialiserLesBornesDesVariablesDuProblemeQuadratique(problemeHebdo, PdtHebdo); - OPT_InitialiserLeSecondMembreDuProblemeQuadratique(ProblemeHebdo, PdtHebdo); + OPT_InitialiserLeSecondMembreDuProblemeQuadratique(problemeHebdo, PdtHebdo); - OPT_InitialiserLesCoutsQuadratiques(ProblemeHebdo, PdtHebdo); + OPT_InitialiserLesCoutsQuadratiques(problemeHebdo, PdtHebdo); result - = OPT_AppelDuSolveurQuadratique(ProblemeHebdo->ProblemeAResoudre, PdtHebdo) && result; + = OPT_AppelDuSolveurQuadratique(problemeHebdo->ProblemeAResoudre, PdtHebdo) && result; } } diff --git a/src/solver/optimisation/opt_restaurer_les_donnees.cpp b/src/solver/optimisation/opt_restaurer_les_donnees.cpp index 616f971219..95242d2d86 100644 --- a/src/solver/optimisation/opt_restaurer_les_donnees.cpp +++ b/src/solver/optimisation/opt_restaurer_les_donnees.cpp @@ -34,7 +34,7 @@ #include "opt_fonctions.h" #include -void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizationNumber) +void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* problemeHebdo, const int optimizationNumber) { int Pays; int Interco; @@ -61,15 +61,15 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati COUTS_DE_TRANSPORT* CoutDeTransport; int* NumeroDeJourDuPasDeTemps; - DernierPasDeTemps = ProblemeHebdo->NombreDePasDeTemps; - NumeroDeJourDuPasDeTemps = ProblemeHebdo->NumeroDeJourDuPasDeTemps; + DernierPasDeTemps = problemeHebdo->NombreDePasDeTemps; + NumeroDeJourDuPasDeTemps = problemeHebdo->NumeroDeJourDuPasDeTemps; for (Pdt = 0; Pdt < DernierPasDeTemps; Pdt++) { - ValeursDeNTCRef = ProblemeHebdo->ValeursDeNTCRef[Pdt]; - ValeursDeNTC = ProblemeHebdo->ValeursDeNTC[Pdt]; + ValeursDeNTCRef = problemeHebdo->ValeursDeNTCRef[Pdt]; + ValeursDeNTC = problemeHebdo->ValeursDeNTC[Pdt]; - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { ValeursDeNTC->ValeurDeNTCOrigineVersExtremite[Interco] = ValeursDeNTCRef->ValeurDeNTCOrigineVersExtremite[Interco]; @@ -82,9 +82,9 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati for (Pdt = 0; Pdt < DernierPasDeTemps; Pdt++) { - for (Interco = 0; Interco < ProblemeHebdo->NombreDInterconnexions; Interco++) + for (Interco = 0; Interco < problemeHebdo->NombreDInterconnexions; Interco++) { - CoutDeTransport = ProblemeHebdo->CoutDeTransport[Interco]; + CoutDeTransport = problemeHebdo->CoutDeTransport[Interco]; if (CoutDeTransport->IntercoGereeAvecDesCouts == OUI_ANTARES) { CoutDeTransport->CoutDeTransportOrigineVersExtremite[Pdt] @@ -97,23 +97,23 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati for (Pdt = 0; Pdt < DernierPasDeTemps; Pdt++) { - ConsommationsAbattuesRef = ProblemeHebdo->ConsommationsAbattuesRef[Pdt]; - ConsommationsAbattues = ProblemeHebdo->ConsommationsAbattues[Pdt]; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + ConsommationsAbattuesRef = problemeHebdo->ConsommationsAbattuesRef[Pdt]; + ConsommationsAbattues = problemeHebdo->ConsommationsAbattues[Pdt]; + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { ConsommationsAbattues->ConsommationAbattueDuPays[Pays] = ConsommationsAbattuesRef->ConsommationAbattueDuPays[Pays]; } } - if (ProblemeHebdo->YaDeLaReserveJmoins1 == OUI_ANTARES + if (problemeHebdo->YaDeLaReserveJmoins1 == OUI_ANTARES && optimizationNumber == PREMIERE_OPTIMISATION) { for (Pdt = 0; Pdt < DernierPasDeTemps; Pdt++) { - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - ReserveJMoins1 = ProblemeHebdo->ReserveJMoins1[Pays]; + ReserveJMoins1 = problemeHebdo->ReserveJMoins1[Pays]; ReserveJMoins1->ReserveHoraireJMoins1[Pdt] = ReserveJMoins1->ReserveHoraireJMoins1Ref[Pdt]; } @@ -122,9 +122,9 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati for (Pdt = 0; Pdt < DernierPasDeTemps; Pdt++) { - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - CaracteristiquesHydrauliques = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]; + CaracteristiquesHydrauliques = problemeHebdo->CaracteristiquesHydrauliques[Pays]; if (CaracteristiquesHydrauliques->PresenceDHydrauliqueModulable != OUI_ANTARES) continue; @@ -135,14 +135,14 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati continue; Jour = NumeroDeJourDuPasDeTemps[Pdt]; PmaxHydEcretee = CaracteristiquesHydrauliques->CntEnergieH2OParJour[Jour]; - PmaxHydEcretee *= ProblemeHebdo->CoefficientEcretementPMaxHydraulique[Pays]; - PmaxHydEcretee /= (double)ProblemeHebdo->NombreDePasDeTempsDUneJournee; + PmaxHydEcretee *= problemeHebdo->CoefficientEcretementPMaxHydraulique[Pays]; + PmaxHydEcretee /= (double)problemeHebdo->NombreDePasDeTempsDUneJournee; // The primary generating power allowance may need to be uplifted to match pumping power // allowance if (CaracteristiquesHydrauliques->PresenceDePompageModulable == OUI_ANTARES) { PmaxHydUplift = CaracteristiquesHydrauliques->ContrainteDePmaxPompageHoraire[Pdt]; - PmaxHydUplift *= ProblemeHebdo->CoefficientEcretementPMaxHydraulique[Pays]; + PmaxHydUplift *= problemeHebdo->CoefficientEcretementPMaxHydraulique[Pays]; if (PmaxHydEcretee < PmaxHydUplift) PmaxHydEcretee = PmaxHydUplift; @@ -160,11 +160,11 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati for (Pdt = 0; Pdt < DernierPasDeTemps;) { - Intervalle = ProblemeHebdo->NumeroDIntervalleOptimiseDuPasDeTemps[Pdt]; - Pdt += ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + Intervalle = problemeHebdo->NumeroDIntervalleOptimiseDuPasDeTemps[Pdt]; + Pdt += problemeHebdo->NombreDePasDeTempsPourUneOptimisation; + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - CaracteristiquesHydrauliques = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]; + CaracteristiquesHydrauliques = problemeHebdo->CaracteristiquesHydrauliques[Pays]; if (CaracteristiquesHydrauliques->PresenceDHydrauliqueModulable == OUI_ANTARES) { CaracteristiquesHydrauliques->CntEnergieH2OParIntervalleOptimise[Intervalle] @@ -173,9 +173,9 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati } } - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - CaracteristiquesHydrauliques = ProblemeHebdo->CaracteristiquesHydrauliques[Pays]; + CaracteristiquesHydrauliques = problemeHebdo->CaracteristiquesHydrauliques[Pays]; if (CaracteristiquesHydrauliques->PresenceDHydrauliqueModulable == OUI_ANTARES) { CaracteristiquesHydrauliques->MaxDesPmaxHydrauliques @@ -185,9 +185,9 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati for (Pdt = 0; Pdt < DernierPasDeTemps; Pdt++) { - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Palier = 0; Palier < PaliersThermiquesDuPays->NombreDePaliersThermiques; Palier++) { PuissanceDisponibleEtCout @@ -200,9 +200,9 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati for (Pdt = 0; Pdt < DernierPasDeTemps; Pdt++) { - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { - PaliersThermiquesDuPays = ProblemeHebdo->PaliersThermiquesDuPays[Pays]; + PaliersThermiquesDuPays = problemeHebdo->PaliersThermiquesDuPays[Pays]; for (Palier = 0; Palier < PaliersThermiquesDuPays->NombreDePaliersThermiques; Palier++) { PuissanceDisponibleEtCout @@ -237,11 +237,11 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati for (Pdt = 0; Pdt < DernierPasDeTemps; Pdt++) { - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { MatriceDesContraintesCouplantes - = ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; + = problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante == CONTRAINTE_HORAIRE) { @@ -253,13 +253,13 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati for (Pdt = 0; Pdt < DernierPasDeTemps;) { - Jour = ProblemeHebdo->NumeroDeJourDuPasDeTemps[Pdt]; - Pdt += ProblemeHebdo->NombreDePasDeTempsDUneJournee; - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + Jour = problemeHebdo->NumeroDeJourDuPasDeTemps[Pdt]; + Pdt += problemeHebdo->NombreDePasDeTempsDUneJournee; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { MatriceDesContraintesCouplantes - = ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; + = problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante == CONTRAINTE_JOURNALIERE) { @@ -269,15 +269,15 @@ void OPT_RestaurerLesDonnees(PROBLEME_HEBDO* ProblemeHebdo, const int optimizati } } - if (ProblemeHebdo->NombreDePasDeTempsPourUneOptimisation - > ProblemeHebdo->NombreDePasDeTempsDUneJournee) + if (problemeHebdo->NombreDePasDeTempsPourUneOptimisation + > problemeHebdo->NombreDePasDeTempsDUneJournee) { Semaine = 0; - for (CntCouplante = 0; CntCouplante < ProblemeHebdo->NombreDeContraintesCouplantes; + for (CntCouplante = 0; CntCouplante < problemeHebdo->NombreDeContraintesCouplantes; CntCouplante++) { MatriceDesContraintesCouplantes - = ProblemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; + = problemeHebdo->MatriceDesContraintesCouplantes[CntCouplante]; if (MatriceDesContraintesCouplantes->TypeDeContrainteCouplante == CONTRAINTE_HEBDOMADAIRE) { diff --git a/src/solver/optimisation/opt_verification_presence_reserve_jmoins1.cpp b/src/solver/optimisation/opt_verification_presence_reserve_jmoins1.cpp index f72a8e451c..58878d9b90 100644 --- a/src/solver/optimisation/opt_verification_presence_reserve_jmoins1.cpp +++ b/src/solver/optimisation/opt_verification_presence_reserve_jmoins1.cpp @@ -36,27 +36,27 @@ #include "spx_definition_arguments.h" #include "spx_fonctions.h" -void OPT_VerifierPresenceReserveJmoins1(PROBLEME_HEBDO* ProblemeHebdo) +void OPT_VerifierPresenceReserveJmoins1(PROBLEME_HEBDO* problemeHebdo) { int Pays; int Pdt; double* ReserveHoraireJMoins1Ref; RESERVE_JMOINS1** ReserveJMoins1; - ProblemeHebdo->YaDeLaReserveJmoins1 = NON_ANTARES; + problemeHebdo->YaDeLaReserveJmoins1 = NON_ANTARES; if (RESERVE_J_MOINS_1 == NON_ANTARES) return; - ReserveJMoins1 = ProblemeHebdo->ReserveJMoins1; + ReserveJMoins1 = problemeHebdo->ReserveJMoins1; - for (Pays = 0; Pays < ProblemeHebdo->NombreDePays; Pays++) + for (Pays = 0; Pays < problemeHebdo->NombreDePays; Pays++) { ReserveHoraireJMoins1Ref = ReserveJMoins1[Pays]->ReserveHoraireJMoins1Ref; - for (Pdt = 0; Pdt < ProblemeHebdo->NombreDePasDeTempsRef; Pdt++) + for (Pdt = 0; Pdt < problemeHebdo->NombreDePasDeTempsRef; Pdt++) { if (fabs(ReserveHoraireJMoins1Ref[Pdt]) > ZERO_RESERVE_J_MOINS1) { - ProblemeHebdo->YaDeLaReserveJmoins1 = OUI_ANTARES; + problemeHebdo->YaDeLaReserveJmoins1 = OUI_ANTARES; return; } } diff --git a/src/solver/optimisation/optim_post_process_list.cpp b/src/solver/optimisation/optim_post_process_list.cpp new file mode 100644 index 0000000000..2da47adb62 --- /dev/null +++ b/src/solver/optimisation/optim_post_process_list.cpp @@ -0,0 +1,45 @@ +#include "optim_post_process_list.h" +#include "post_process_commands.h" + +namespace Antares::Solver::Simulation +{ + +OptPostProcessList::OptPostProcessList(PROBLEME_HEBDO* problemeHebdo, + uint thread_number, + AreaList& areas, + SheddingPolicy sheddingPolicy, + SimplexOptimization splxOptimization, + Calendar& calendar) + + : interfacePostProcessList(problemeHebdo, thread_number) +{ + post_process_list.push_back(std::make_unique( + problemeHebdo_, + thread_number_, + areas)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + false, + false)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + sheddingPolicy, + splxOptimization, + thread_number)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + true, + false)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas, + calendar)); + post_process_list.push_back(std::make_unique( + problemeHebdo_, + areas)); +} + +} // namespace Antares::Solver::Simulation \ No newline at end of file diff --git a/src/solver/optimisation/optim_post_process_list.h b/src/solver/optimisation/optim_post_process_list.h new file mode 100644 index 0000000000..246a6534f0 --- /dev/null +++ b/src/solver/optimisation/optim_post_process_list.h @@ -0,0 +1,22 @@ +#pragma once + +#include "../simulation/base_post_process.h" + + +namespace Antares::Solver::Simulation +{ + +class OptPostProcessList : public interfacePostProcessList +{ +public: + OptPostProcessList(PROBLEME_HEBDO* problemeHebdo, + uint thread_number, + AreaList& areas, + SheddingPolicy sheddingPolicy, + SimplexOptimization splxOptimization, + Calendar& calendar); + + virtual ~OptPostProcessList() = default; +}; + +} // namespace Antares::Solver::Simulation diff --git a/src/solver/optimisation/post_process_commands.cpp b/src/solver/optimisation/post_process_commands.cpp new file mode 100644 index 0000000000..0834b27864 --- /dev/null +++ b/src/solver/optimisation/post_process_commands.cpp @@ -0,0 +1,286 @@ + +#include "post_process_commands.h" +#include "../simulation/common-eco-adq.h" +#include "adequacy_patch_weekly_optimization.h" +#include "adequacy_patch_csr/adq_patch_curtailment_sharing.h" + +namespace Antares::Solver::Simulation +{ +const uint nbHoursInWeek = 168; +// ----------------------------- +// Dispatchable Margin +// ----------------------------- +DispatchableMarginPostProcessCmd::DispatchableMarginPostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + unsigned int thread_number, + AreaList& areas) : + basePostProcessCommand(problemeHebdo), thread_number_(thread_number), area_list_(areas) +{ +} + +void DispatchableMarginPostProcessCmd::execute(const optRuntimeData& opt_runtime_data) +{ + unsigned int hourInYear = opt_runtime_data.hourInTheYear; + + area_list_.each([&](Data::Area& area) { + double* dtgmrg = area.scratchpad[thread_number_]->dispatchableGenerationMargin; + for (uint h = 0; h != nbHoursInWeek; ++h) + dtgmrg[h] = 0.; + + if (not area.thermal.list.empty()) + { + auto& hourlyResults = *(problemeHebdo_->ResultatsHoraires[area.index]); + auto end = area.thermal.list.end(); + + for (auto i = area.thermal.list.begin(); i != end; ++i) + { + auto& cluster = *(i->second); + uint chro = NumeroChroniquesTireesParPays[thread_number_][area.index] + ->ThermiqueParPalier[cluster.areaWideIndex]; + auto& matrix = cluster.series->series; + assert(chro < matrix.width); + auto& column = matrix.entry[chro]; + assert(hourInYear + nbHoursInWeek <= matrix.height && "index out of bounds"); + + for (uint h = 0; h != nbHoursInWeek; ++h) + { + double production = hourlyResults.ProductionThermique[h] + ->ProductionThermiqueDuPalier[cluster.index]; + dtgmrg[h] += column[h + hourInYear] - production; + } + } + } + }); +} + +// ----------------------------- +// Hydro levels update +// ----------------------------- +HydroLevelsUpdatePostProcessCmd::HydroLevelsUpdatePostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + bool remixWasRun, + bool computeAnyway) : + basePostProcessCommand(problemeHebdo), + area_list_(areas), + remixWasRun_(remixWasRun), + computeAnyway_(computeAnyway) +{ +} + +void HydroLevelsUpdatePostProcessCmd::execute(const optRuntimeData& opt_runtime_data) +{ + computingHydroLevels(area_list_, *problemeHebdo_, remixWasRun_, computeAnyway_); +} + +// ----------------------------- +// Remix Hydro +// ----------------------------- +RemixHydroPostProcessCmd::RemixHydroPostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + SheddingPolicy sheddingPolicy, + SimplexOptimization simplexOptimization, + unsigned int thread_number) : + basePostProcessCommand(problemeHebdo), + area_list_(areas), + shedding_policy_(sheddingPolicy), + splx_optimization_(simplexOptimization), + thread_number_(thread_number) +{ +} + +void RemixHydroPostProcessCmd::execute(const optRuntimeData& opt_runtime_data) +{ + unsigned int hourInYear = opt_runtime_data.hourInTheYear; + RemixHydroForAllAreas(area_list_, + *problemeHebdo_, + shedding_policy_, + splx_optimization_, + thread_number_, + hourInYear); +} + +// ----------------------------- +// DTG margin for adq patch +// ----------------------------- +using namespace Antares::Data::AdequacyPatch; + +DTGmarginForAdqPatchPostProcessCmd::DTGmarginForAdqPatchPostProcessCmd( + PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + unsigned int thread_number) : + basePostProcessCommand(problemeHebdo), area_list_(areas), thread_number_(thread_number) +{ +} + +/*! +** Calculate Dispatchable margin for all areas after CSR optimization and adjust ENS +** values if neccessary. If LOLD=1, Sets MRG COST to the max value (unsupplied energy cost) +** */ +void DTGmarginForAdqPatchPostProcessCmd::execute(const optRuntimeData& opt_runtime_data) +{ + for (int Area = 0; Area < problemeHebdo_->NombreDePays; Area++) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[Area] != physicalAreaInsideAdqPatch) + continue; + + for (int hour = 0; hour < nbHoursInWeek; hour++) + { + // define access to the required variables + const auto& scratchpad = *(area_list_[Area]->scratchpad[thread_number_]); + double dtgMrg = scratchpad.dispatchableGenerationMargin[hour]; + + auto& hourlyResults = *(problemeHebdo_->ResultatsHoraires[Area]); + double& dtgMrgCsr = hourlyResults.ValeursHorairesDtgMrgCsr[hour]; + double& ens = hourlyResults.ValeursHorairesDeDefaillancePositive[hour]; + double& mrgCost = hourlyResults.CoutsMarginauxHoraires[hour]; + // calculate DTG MRG CSR and adjust ENS if neccessary + if (dtgMrgCsr == -1.0) // area is inside adq-patch and it is CSR triggered hour + { + dtgMrgCsr = std::max(0.0, dtgMrg - ens); + ens = std::max(0.0, ens - dtgMrg); + // set MRG PRICE to value of unsupplied energy cost, if LOLD=1.0 (ENS>0.5) + if (ens > 0.5) + mrgCost = -area_list_[Area]->thermal.unsuppliedEnergyCost; + } + else + dtgMrgCsr = dtgMrg; + } + } +} + +// ----------------------------- +// Interpolate Water Values +// ----------------------------- + +InterpolateWaterValuePostProcessCmd::InterpolateWaterValuePostProcessCmd( + PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + const Date::Calendar& calendar) : + basePostProcessCommand(problemeHebdo), area_list_(areas), calendar_(calendar) +{ +} + +void InterpolateWaterValuePostProcessCmd::execute(const optRuntimeData& opt_runtime_data) +{ + unsigned int hourInYear = opt_runtime_data.hourInTheYear; + interpolateWaterValue(area_list_, *problemeHebdo_, calendar_, hourInYear); +} + +// ----------------------------- +// Hydro Levels Final Update +// ----------------------------- +// HydroLevelsFinalUpdatePostProcessCmd +HydroLevelsFinalUpdatePostProcessCmd::HydroLevelsFinalUpdatePostProcessCmd( + PROBLEME_HEBDO* problemeHebdo, + AreaList& areas) : + basePostProcessCommand(problemeHebdo), area_list_(areas) +{ +} + +void HydroLevelsFinalUpdatePostProcessCmd::execute(const optRuntimeData& opt_runtime_data) +{ + updatingWeeklyFinalHydroLevel(area_list_, *problemeHebdo_); +} + +// -------------------------------------- +// Curtailment sharing for adq patch +// -------------------------------------- +CurtailmentSharingPostProcessCmd::CurtailmentSharingPostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + unsigned int thread_number) : + basePostProcessCommand(problemeHebdo), area_list_(areas), thread_number_(thread_number) +{ +} + +void CurtailmentSharingPostProcessCmd::execute(const optRuntimeData& opt_runtime_data) +{ + unsigned int year = opt_runtime_data.year; + unsigned int week = opt_runtime_data.week; + + double totalLmrViolation = calculateDensNewAndTotalLmrViolation(); + logs.info() << "[adq-patch] Year:" << year + 1 << " Week:" << week + 1 + << ".Total LMR violation:" << totalLmrViolation; + const std::set hoursRequiringCurtailmentSharing = getHoursRequiringCurtailmentSharing(); + HourlyCSRProblem hourlyCsrProblem(problemeHebdo_); + for (int hourInWeek : hoursRequiringCurtailmentSharing) + { + logs.info() << "[adq-patch] CSR triggered for Year:" << year + 1 + << " Hour:" << week * nbHoursInWeek + hourInWeek + 1; + hourlyCsrProblem.setHour(hourInWeek); + hourlyCsrProblem.run(week, year); + } +} + +double CurtailmentSharingPostProcessCmd::calculateDensNewAndTotalLmrViolation() +{ + double totalLmrViolation = 0.0; + + for (int Area = 0; Area < problemeHebdo_->NombreDePays; Area++) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[Area] == physicalAreaInsideAdqPatch) + { + for (int hour = 0; hour < nbHoursInWeek; hour++) + { + const auto [netPositionInit, densNew, totalNodeBalance] + = calculateAreaFlowBalance(problemeHebdo_, Area, hour); + // adjust densNew according to the new specification/request by ELIA + /* DENS_new (node A) = max [ 0; ENS_init (node A) + net_position_init (node A) + + ? flows (node 1 -> node A) - DTG.MRG(node A)] */ + const auto& scratchpad = *(area_list_[Area]->scratchpad[thread_number_]); + double dtgMrg = scratchpad.dispatchableGenerationMargin[hour]; + // write down densNew values for all the hours + problemeHebdo_->ResultatsHoraires[Area]->ValeursHorairesDENS[hour] + = std::max(0.0, densNew - dtgMrg); + ; + // copy spilled Energy values into spilled Energy values after CSR + problemeHebdo_->ResultatsHoraires[Area]->ValeursHorairesSpilledEnergyAfterCSR[hour] + = problemeHebdo_->ResultatsHoraires[Area] + ->ValeursHorairesDeDefaillanceNegative[hour]; + // check LMR violations + totalLmrViolation + += LmrViolationAreaHour(problemeHebdo_, totalNodeBalance, Area, hour); + } + } + } + return totalLmrViolation; +} + +std::set CurtailmentSharingPostProcessCmd::getHoursRequiringCurtailmentSharing() const +{ + const auto sumENS = calculateENSoverAllAreasForEachHour(); + return identifyHoursForCurtailmentSharing(sumENS); +} + +std::set CurtailmentSharingPostProcessCmd::identifyHoursForCurtailmentSharing( + std::vector sumENS) const +{ + double threshold = problemeHebdo_->adqPatchParams->ThresholdRunCurtailmentSharingRule; + std::set triggerCsrSet; + for (int i = 0; i < nbHoursInWeek; ++i) + { + if (sumENS[i] > threshold) + { + triggerCsrSet.insert(i); + } + } + logs.debug() << "number of triggered hours: " << triggerCsrSet.size(); + return triggerCsrSet; +} + +std::vector CurtailmentSharingPostProcessCmd::calculateENSoverAllAreasForEachHour() const +{ + std::vector sumENS(nbHoursInWeek, 0.0); + for (int area = 0; area < problemeHebdo_->NombreDePays; ++area) + { + if (problemeHebdo_->adequacyPatchRuntimeData.areaMode[area] + == Data::AdequacyPatch::physicalAreaInsideAdqPatch) + { + const double* ENS + = problemeHebdo_->ResultatsHoraires[area]->ValeursHorairesDeDefaillancePositive; + for (uint h = 0; h < nbHoursInWeek; ++h) + sumENS[h] += ENS[h]; + } + } + return sumENS; +} + +} // namespace Antares::Solver::Simulation diff --git a/src/solver/optimisation/post_process_commands.h b/src/solver/optimisation/post_process_commands.h new file mode 100644 index 0000000000..4c7aee999c --- /dev/null +++ b/src/solver/optimisation/post_process_commands.h @@ -0,0 +1,110 @@ +#pragma once + +#include "../simulation/base_post_process.h" + +namespace Antares::Solver::Simulation +{ +class DispatchableMarginPostProcessCmd : public basePostProcessCommand +{ +public: + DispatchableMarginPostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + unsigned int thread_number, + AreaList& areas); + void execute(const optRuntimeData& opt_runtime_data) override; + +private: + unsigned int thread_number_ = 0; + const AreaList& area_list_; +}; + +class HydroLevelsUpdatePostProcessCmd : public basePostProcessCommand +{ +public: + HydroLevelsUpdatePostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + bool remixWasRun, + bool computeAnyway); + void execute(const optRuntimeData& opt_runtime_data) override; + +private: + const AreaList& area_list_; + bool remixWasRun_ = false; + bool computeAnyway_ = false; +}; + +class RemixHydroPostProcessCmd : public basePostProcessCommand +{ +public: + RemixHydroPostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + SheddingPolicy sheddingPolicy, + SimplexOptimization simplexOptimization, + unsigned int thread_number); + void execute(const optRuntimeData& opt_runtime_data) override; + +private: + const AreaList& area_list_; + unsigned int thread_number_ = 0; + SheddingPolicy shedding_policy_; + SimplexOptimization splx_optimization_; +}; + +class DTGmarginForAdqPatchPostProcessCmd : public basePostProcessCommand +{ +public: + DTGmarginForAdqPatchPostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + unsigned int thread_number); + + void execute(const optRuntimeData& opt_runtime_data) override; + +private: + const AreaList& area_list_; + unsigned int thread_number_ = 0; +}; + +class InterpolateWaterValuePostProcessCmd : public basePostProcessCommand +{ +public: + InterpolateWaterValuePostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + const Date::Calendar& calendar); + + void execute(const optRuntimeData& opt_runtime_data) override; + +private: + const AreaList& area_list_; + const Date::Calendar& calendar_; +}; + +class HydroLevelsFinalUpdatePostProcessCmd : public basePostProcessCommand +{ +public: + HydroLevelsFinalUpdatePostProcessCmd(PROBLEME_HEBDO* problemeHebdo, AreaList& areas); + + void execute(const optRuntimeData& opt_runtime_data) override; + +private: + const AreaList& area_list_; +}; + +class CurtailmentSharingPostProcessCmd : public basePostProcessCommand +{ +public: + CurtailmentSharingPostProcessCmd(PROBLEME_HEBDO* problemeHebdo, + AreaList& areas, + unsigned int thread_number); + + void execute(const optRuntimeData& opt_runtime_data) override; + +private: + double calculateDensNewAndTotalLmrViolation(); + std::vector calculateENSoverAllAreasForEachHour() const; + std::set identifyHoursForCurtailmentSharing(std::vector sumENS) const; + std::set getHoursRequiringCurtailmentSharing() const; + + const AreaList& area_list_; + unsigned int thread_number_ = 0; +}; + +} // namespace Antares::Solver::Simulation diff --git a/src/solver/optimisation/weekly_optimization.cpp b/src/solver/optimisation/weekly_optimization.cpp new file mode 100644 index 0000000000..5edff63005 --- /dev/null +++ b/src/solver/optimisation/weekly_optimization.cpp @@ -0,0 +1,43 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "weekly_optimization.h" +#include "opt_fonctions.h" + +namespace Antares::Solver::Optimization +{ +DefaultWeeklyOptimization::DefaultWeeklyOptimization(PROBLEME_HEBDO* problemeHebdo, uint thread_number) : + WeeklyOptimization(problemeHebdo, thread_number) +{ +} + +void DefaultWeeklyOptimization::solve(uint, int) +{ + OPT_OptimisationHebdomadaire(problemeHebdo_, thread_number_); +} + +} // namespace Antares::Solver::Optimization diff --git a/src/solver/optimisation/weekly_optimization.h b/src/solver/optimisation/weekly_optimization.h new file mode 100644 index 0000000000..7ebde3bc12 --- /dev/null +++ b/src/solver/optimisation/weekly_optimization.h @@ -0,0 +1,42 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#pragma once + +#include "base_weekly_optimization.h" +#include "../simulation/sim_structure_probleme_economique.h" + +namespace Antares::Solver::Optimization +{ +class DefaultWeeklyOptimization : public WeeklyOptimization +{ +public: + explicit DefaultWeeklyOptimization(PROBLEME_HEBDO* problemeHebdo, uint numSpace); + ~DefaultWeeklyOptimization() override = default; + void solve(uint, int) override; +}; +} // namespace Antares::Solver::Optimization diff --git a/src/solver/simulation/adequacy-draft.cpp b/src/solver/simulation/adequacy-draft.cpp index 7da3f716a3..f28fcdfcd8 100644 --- a/src/solver/simulation/adequacy-draft.cpp +++ b/src/solver/simulation/adequacy-draft.cpp @@ -33,11 +33,7 @@ #include "../optimisation/opt_fonctions.h" #include "../aleatoire/alea_fonctions.h" -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { AdequacyDraft::AdequacyDraft(Data::Study& study) : study(study), preproOnly(false) { @@ -116,6 +112,4 @@ void AdequacyDraft::prepareClustersInMustRunMode(uint) { } -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/adequacy-draft.h b/src/solver/simulation/adequacy-draft.h index 430f4579db..955c79c5cc 100644 --- a/src/solver/simulation/adequacy-draft.h +++ b/src/solver/simulation/adequacy-draft.h @@ -33,11 +33,7 @@ #include "solver.h" -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { class AdequacyDraft { @@ -98,8 +94,6 @@ class AdequacyDraft }; // class AdequacyDraft -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation #endif // __SOLVER_SIMULATION_ADEQUACY_DRAFT_H__ diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index eba31227f6..020463e6ac 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -32,11 +32,7 @@ using namespace Yuni; -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { enum { @@ -174,7 +170,7 @@ bool Adequacy::year(Progression::Task& progression, pProblemesHebdo[numSpace]->HeureDansLAnnee = hourInTheYear; ::SIM_RenseignementProblemeHebdo( - *pProblemesHebdo[numSpace], state, numSpace, hourInTheYear); + *pProblemesHebdo[numSpace], state.weekInTheYear, numSpace, hourInTheYear); // Reinit optimisation if needed pProblemesHebdo[numSpace]->ReinitOptimisation = reinitOptim ? OUI_ANTARES : NON_ANTARES; @@ -225,12 +221,16 @@ bool Adequacy::year(Progression::Task& progression, { OPT_OptimisationHebdomadaire(pProblemesHebdo[numSpace], numSpace); - computingHydroLevels(study, *pProblemesHebdo[numSpace], nbHoursInAWeek, false); + computingHydroLevels(study.areas, *pProblemesHebdo[numSpace], false); - RemixHydroForAllAreas( - study, *pProblemesHebdo[numSpace], numSpace, hourInTheYear, nbHoursInAWeek); + RemixHydroForAllAreas(study.areas, + *pProblemesHebdo[numSpace], + study.parameters.shedding.policy, + study.parameters.simplexOptimizationRange, + numSpace, + hourInTheYear); - computingHydroLevels(study, *pProblemesHebdo[numSpace], nbHoursInAWeek, true); + computingHydroLevels(study.areas, *pProblemesHebdo[numSpace], true); } catch (Data::AssertionError& ex) { @@ -320,13 +320,12 @@ bool Adequacy::year(Progression::Task& progression, } } - computingHydroLevels(study, *pProblemesHebdo[numSpace], nbHoursInAWeek, false, true); + computingHydroLevels(study.areas, *pProblemesHebdo[numSpace], false, true); } - interpolateWaterValue( - study, *pProblemesHebdo[numSpace], state, hourInTheYear, nbHoursInAWeek); + interpolateWaterValue(study.areas, *pProblemesHebdo[numSpace], study.calendar, hourInTheYear); - updatingWeeklyFinalHydroLevel(study, *pProblemesHebdo[numSpace], nbHoursInAWeek); + updatingWeeklyFinalHydroLevel(study.areas, *pProblemesHebdo[numSpace]); variables.weekBegin(state); uint previousHourInTheYear = state.hourInTheYear; @@ -360,7 +359,7 @@ bool Adequacy::year(Progression::Task& progression, ++progression; } - updatingAnnualFinalHydroLevel(study, *pProblemesHebdo[numSpace]); + updatingAnnualFinalHydroLevel(study.areas, *pProblemesHebdo[numSpace]); optWriter.finalize(); finalizeOptimizationStatistics(*pProblemesHebdo[numSpace], state); @@ -404,6 +403,4 @@ void Adequacy::prepareClustersInMustRunMode(uint numSpace) PrepareDataFromClustersInMustrunMode(study, numSpace); } -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/adequacy.h b/src/solver/simulation/adequacy.h index 86abf5e8fc..27b373a497 100644 --- a/src/solver/simulation/adequacy.h +++ b/src/solver/simulation/adequacy.h @@ -35,11 +35,7 @@ #include "solver.h" // for definition of type yearRandomNumbers -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { class Adequacy { @@ -108,8 +104,6 @@ class Adequacy }; // class Adequacy -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation #endif // __SOLVER_SIMULATION_ADEQUACY_H__ diff --git a/src/solver/simulation/apply-scenario.cpp b/src/solver/simulation/apply-scenario.cpp index a9ec93265b..ed9fb74b23 100644 --- a/src/solver/simulation/apply-scenario.cpp +++ b/src/solver/simulation/apply-scenario.cpp @@ -28,9 +28,7 @@ #include "apply-scenario.h" #include -namespace Antares -{ -namespace Solver +namespace Antares::Solver { void ApplyCustomScenario(Data::Study& study) { @@ -59,5 +57,4 @@ void ApplyCustomScenario(Data::Study& study) logs.info(); } -} // namespace Solver -} // namespace Antares \ No newline at end of file +} // namespace Antares::Solver diff --git a/src/solver/simulation/apply-scenario.h b/src/solver/simulation/apply-scenario.h index 839571f01e..3db0d7c523 100644 --- a/src/solver/simulation/apply-scenario.h +++ b/src/solver/simulation/apply-scenario.h @@ -29,12 +29,9 @@ #include -namespace Antares -{ -namespace Solver +namespace Antares::Solver { void ApplyCustomScenario(Data::Study& study); -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver #endif // __SOLVER_SIMULATION_APPLY_SCENARIO_H__ diff --git a/src/solver/simulation/base_post_process.cpp b/src/solver/simulation/base_post_process.cpp new file mode 100644 index 0000000000..891b4edc75 --- /dev/null +++ b/src/solver/simulation/base_post_process.cpp @@ -0,0 +1,46 @@ + +#include +#include "base_post_process.h" +#include "../optimisation/optim_post_process_list.h" +#include "../optimisation/adq_patch_post_process_list.h" + +namespace Antares::Solver::Simulation +{ + +basePostProcessCommand::basePostProcessCommand(PROBLEME_HEBDO* problemeHebdo) + : problemeHebdo_(problemeHebdo) +{ +} + +interfacePostProcessList::interfacePostProcessList(PROBLEME_HEBDO* problemesHebdo, uint numSpace) : + problemeHebdo_(problemesHebdo), thread_number_(numSpace) +{ +} + + +std::unique_ptr interfacePostProcessList::create( + bool adqPatchEnabled, + PROBLEME_HEBDO* problemeHebdo, + uint thread_number, + AreaList& areas, + SheddingPolicy sheddingPolicy, + SimplexOptimization splxOptimization, + Calendar& calendar) +{ + if (adqPatchEnabled) + return std::make_unique( + problemeHebdo, thread_number, areas, sheddingPolicy, splxOptimization, calendar); + else + return std::make_unique( + problemeHebdo, thread_number, areas, sheddingPolicy, splxOptimization, calendar); +} + +void interfacePostProcessList::runAll(const optRuntimeData& opt_runtime_data) +{ + for (auto& post_process : post_process_list) + { + post_process->execute(opt_runtime_data); + } +} + +} // namespace Antares::Solver::Simulation \ No newline at end of file diff --git a/src/solver/simulation/base_post_process.h b/src/solver/simulation/base_post_process.h new file mode 100644 index 0000000000..8274146b85 --- /dev/null +++ b/src/solver/simulation/base_post_process.h @@ -0,0 +1,68 @@ +#pragma once + +#include +#include + +#include "../simulation/sim_structure_probleme_economique.h" + +using namespace Antares::Data; +using namespace Antares::Date; + +namespace Antares::Solver::Simulation +{ + + +struct optRuntimeData +{ + optRuntimeData(unsigned int y, unsigned int w, unsigned int h) : + year(y), week(w), hourInTheYear(h) + {} + + unsigned int year = 0; + unsigned int week = 0; + unsigned int hourInTheYear = 0; +}; + +class basePostProcessCommand +{ +public: + virtual ~basePostProcessCommand() = default; + virtual void execute(const optRuntimeData& opt_runtime_data) = 0; + +protected: + // Memeber functions + basePostProcessCommand(PROBLEME_HEBDO* problemeHebdo); + + // Data members + PROBLEME_HEBDO* problemeHebdo_; +}; + +class interfacePostProcessList +{ +public: + virtual ~interfacePostProcessList() = default; + + // gp : we should put all these arguments in a structure, so that we pass a structure + // gp : to the create(...) method, and to underlying calls to constructors. + // gp : In case we need new data for a new post process, we would not have to change + // gp : the constructors' signatures of the post process list classes. + static std::unique_ptr create(bool adqPatchEnabled, + PROBLEME_HEBDO* problemeHebdo, + uint thread_number, + AreaList& areas, + SheddingPolicy sheddingPolicy, + SimplexOptimization splxOptimization, + Calendar& calendar); + void runAll(const optRuntimeData& opt_runtime_data); + +protected: + // Member functions + interfacePostProcessList(PROBLEME_HEBDO* problemeHebdo, uint thread_number); + + // Data mambers + PROBLEME_HEBDO* const problemeHebdo_ = nullptr; + const unsigned int thread_number_ = 0; + std::vector> post_process_list; +}; + +} // namespace Antares::Solver::Simulation \ No newline at end of file diff --git a/src/solver/simulation/common-dispatchable-margin.cpp b/src/solver/simulation/common-dispatchable-margin.cpp deleted file mode 100644 index 65c6aefd39..0000000000 --- a/src/solver/simulation/common-dispatchable-margin.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* -** Copyright 2007-2018 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** 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 -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ - -#include -#include -#include -#include -#include "common-eco-adq.h" -#include "sim_structure_donnees.h" -#include "sim_structure_probleme_economique.h" - -namespace Antares -{ -namespace Solver -{ -namespace Simulation -{ -void DispatchableMarginForAllAreas(const Data::Study& study, - PROBLEME_HEBDO& problem, - uint numSpace, - uint hourInYear) -{ - assert(study.parameters.mode == Data::stdmEconomy); - const uint nbHours = 168; - - study.areas.each([&](Data::Area& area) { - double* dtgmrg = area.scratchpad[numSpace]->dispatchableGenerationMargin; - for (uint i = 0; i != nbHours; ++i) - dtgmrg[i] = 0.; - - if (not area.thermal.list.empty()) - { - auto& hourlyResults = *(problem.ResultatsHoraires[area.index]); - auto end = area.thermal.list.end(); - - for (auto i = area.thermal.list.begin(); i != end; ++i) - { - auto& cluster = *(i->second); - uint chro = NumeroChroniquesTireesParPays[numSpace][area.index] - ->ThermiqueParPalier[cluster.areaWideIndex]; - auto& matrix = cluster.series->series; - assert(chro < matrix.width); - auto& column = matrix.entry[chro]; - assert(hourInYear + nbHours <= matrix.height && "index out of bounds"); - - for (uint y = 0; y != nbHours; ++y) - { - double production = hourlyResults.ProductionThermique[y] - ->ProductionThermiqueDuPalier[cluster.index]; - dtgmrg[y] += column[y + hourInYear] - production; - } - } - } - }); -} - -} // namespace Simulation -} // namespace Solver -} // namespace Antares diff --git a/src/solver/simulation/common-eco-adq.cpp b/src/solver/simulation/common-eco-adq.cpp index c643437cee..34a0a6c435 100644 --- a/src/solver/simulation/common-eco-adq.cpp +++ b/src/solver/simulation/common-eco-adq.cpp @@ -41,11 +41,7 @@ using namespace Yuni; -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { static void RecalculDesEchangesMoyens(Data::Study& study, PROBLEME_HEBDO& problem, @@ -416,6 +412,4 @@ void finalizeOptimizationStatistics(PROBLEME_HEBDO& problem, secondOptStat.reset(); } -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/common-eco-adq.h b/src/solver/simulation/common-eco-adq.h index 0ed292fee7..86fed8394d 100644 --- a/src/solver/simulation/common-eco-adq.h +++ b/src/solver/simulation/common-eco-adq.h @@ -88,16 +88,16 @@ void ComputeFlowQuad(Data::Study& study, /*! ** \brief Hydro Remix ** -** \param study The Antares study +** \param areas : the areas of study ** \param problem The weekly problem, from the solver ** \param hourInYear The hour in the year of the first hour in the current week -** \param nbHours The number of hour for a week */ -void RemixHydroForAllAreas(const Data::Study& study, +void RemixHydroForAllAreas(const Data::AreaList& areas, PROBLEME_HEBDO& problem, + Data::SheddingPolicy sheddingPolicy, + Data::SimplexOptimization splxOptimization, uint numSpace, - uint hourInYear, - uint nbHours); + uint hourInYear); /* ** \brief Computing levels from hydro generation, natural and pumping inflows @@ -106,67 +106,49 @@ void RemixHydroForAllAreas(const Data::Study& study, *heuristic ** If hydro remix was done, levels are computed only for areas for which we use the heuristic */ -void computingHydroLevels(const Data::Study& study, +void computingHydroLevels(const Data::AreaList& areas, PROBLEME_HEBDO& problem, - uint nbHoursInAWeek, bool remixWasRun, bool computeAnyway = false); -/*! -** \brief Calculate the Dispatchable margin for all areas -** -** \param study The Antares study -** \param problem The weekly problem, from the solver -** \param hourInYear The hour in the year of the first hour in the current week -** \param nbHours The number of hour for a week -*/ -void DispatchableMarginForAllAreas(const Data::Study& study, - PROBLEME_HEBDO& problem, - uint numSpace, - uint hourInYear); /* ** \brief Interpolates water values related to reservoir levels for outputs only ** -** \param study The Antares study +** \param areas : the areas of study ** \param problem The weekly problem, from the solver -** \param state The simulation's current state (variable values to be stored and read at different *point of weekly simulation) ** \param hourInYear The hour in the year of the first hour in the current week -** \param nbHoursInAWeek Number of hours in a week ** ** For any hour, the computed water values are related to the beginning of the hour, not the end. */ -void interpolateWaterValue(const Data::Study& study, +void interpolateWaterValue(const Data::AreaList& areas, PROBLEME_HEBDO& problem, - Antares::Solver::Variable::State& state, - int hourInTheYear, - uint nbHoursInAWeek); + const Date::Calendar& calendar, + int hourInTheYear); /* ** \brief Updating the weekly simulation final reservoir level, to be used as a start for the next *week. ** -** \param study The Antares study +** \param areas : the areas of study ** \param problem The weekly problem, from the solver -** \param nbHoursInAWeek Number of hours in a week */ -void updatingWeeklyFinalHydroLevel(const Data::Study& study, - PROBLEME_HEBDO& problem, - uint nbHoursInAWeek); +void updatingWeeklyFinalHydroLevel(const Data::AreaList& areas, + PROBLEME_HEBDO& problem); /* ** \brief Updating the year final reservoir level, to be used as a start for the year. ** -** \param study The Antares study +** \param areas : the areas of study ** \param problem The weekly problem, living over the whole simuation. */ -void updatingAnnualFinalHydroLevel(const Data::Study& study, PROBLEME_HEBDO& problem); +void updatingAnnualFinalHydroLevel(const Data::AreaList& areas, PROBLEME_HEBDO& problem); /* ** \brief Compute the weighted average NTC for a link ** -** \param study The Antares study +** \param areas : the areas of study ** \param link The link ** \param Weighted average NTC for the direct direction ** \param Weighted average NTC for the indirect direction diff --git a/src/solver/simulation/common-hydro-levels.cpp b/src/solver/simulation/common-hydro-levels.cpp index e142449610..cd0bf1fdac 100644 --- a/src/solver/simulation/common-hydro-levels.cpp +++ b/src/solver/simulation/common-hydro-levels.cpp @@ -25,32 +25,26 @@ ** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions */ -#include -#include #include -#include #include "common-eco-adq.h" -#include -#include #include "simulation.h" -#include #include -namespace Antares +namespace Antares::Solver::Simulation { -namespace Solver -{ -namespace Simulation -{ -void computingHydroLevels(const Data::Study& study, + +const unsigned int nbHoursInAWeek = 168; + + +void computingHydroLevels(const Data::AreaList& areas, PROBLEME_HEBDO& problem, - uint nbHoursInAWeek, bool remixWasRun, bool computeAnyway) { - assert(study.parameters.mode != Data::stdmAdequacyDraft); + // gp : we do not care : will be removed very soon + // assert(study.parameters.mode != Data::stdmAdequacyDraft); - study.areas.each([&](const Data::Area& area) { + areas.each([&](const Data::Area& area) { if (!area.hydro.reservoirManagement) return; @@ -95,21 +89,20 @@ void computingHydroLevels(const Data::Study& study, }); } -void interpolateWaterValue(const Data::Study& study, +void interpolateWaterValue(const Data::AreaList& areas, PROBLEME_HEBDO& problem, - Antares::Solver::Variable::State& state, - int firstHourOfTheWeek, - uint nbHoursInAWeek) + const Date::Calendar& calendar, + int firstHourOfTheWeek) { uint daysOfWeek[7] = {0, 0, 0, 0, 0, 0, 0}; - const uint weekFirstDay = study.calendar.hours[firstHourOfTheWeek].dayYear; + const uint weekFirstDay = calendar.hours[firstHourOfTheWeek].dayYear; daysOfWeek[0] = weekFirstDay; for (int d = 1; d < 7; d++) daysOfWeek[d] = weekFirstDay + d; - study.areas.each([&](const Data::Area& area) { + areas.each([&](const Data::Area& area) { uint index = area.index; RESULTATS_HORAIRES* weeklyResults = problem.ResultatsHoraires[index]; @@ -130,25 +123,24 @@ void interpolateWaterValue(const Data::Study& study, double* niv = weeklyResults->niveauxHoraires; Antares::Data::getWaterValue( - problem.previousSimulationFinalLevel[index] * 100 / reservoirCapacity, - area.hydro.waterValues, - weekFirstDay, - state.h2oValueWorkVars, - waterVal[0]); + problem.previousSimulationFinalLevel[index] * 100 / reservoirCapacity, + area.hydro.waterValues, + weekFirstDay, + waterVal[0]); for (uint h = 1; h < nbHoursInAWeek; h++) - Antares::Data::getWaterValue(niv[h - 1], + { + Antares::Data::getWaterValue(niv[h - 1], area.hydro.waterValues, - daysOfWeek[h / 24], - state.h2oValueWorkVars, + daysOfWeek[h / 24], waterVal[h]); + } }); } -void updatingWeeklyFinalHydroLevel(const Data::Study& study, - PROBLEME_HEBDO& problem, - uint nbHoursInAWeek) +void updatingWeeklyFinalHydroLevel(const Data::AreaList& areas, + PROBLEME_HEBDO& problem) { - study.areas.each([&](const Data::Area& area) { + areas.each([&](const Data::Area& area) { if (!area.hydro.reservoirManagement) return; @@ -165,12 +157,12 @@ void updatingWeeklyFinalHydroLevel(const Data::Study& study, }); } -void updatingAnnualFinalHydroLevel(const Data::Study& study, PROBLEME_HEBDO& problem) +void updatingAnnualFinalHydroLevel(const Data::AreaList& areas, PROBLEME_HEBDO& problem) { if (!problem.hydroHotStart) return; - study.areas.each([&](const Data::Area& area) { + areas.each([&](const Data::Area& area) { if (!area.hydro.reservoirManagement) return; @@ -183,6 +175,4 @@ void updatingAnnualFinalHydroLevel(const Data::Study& study, PROBLEME_HEBDO& pro }); } -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/common-hydro-remix.cpp b/src/solver/simulation/common-hydro-remix.cpp index ad5bf728d7..d064bc0601 100644 --- a/src/solver/simulation/common-hydro-remix.cpp +++ b/src/solver/simulation/common-hydro-remix.cpp @@ -40,14 +40,10 @@ using namespace Yuni; #define EPSILON 1e-6 -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { template -static bool Remix(const Data::Study& study, PROBLEME_HEBDO& problem, uint numSpace, uint hourInYear) +static bool Remix(const Data::AreaList& areas, PROBLEME_HEBDO& problem, uint numSpace, uint hourInYear) { double HE[168]; @@ -59,7 +55,7 @@ static bool Remix(const Data::Study& study, PROBLEME_HEBDO& problem, uint numSpa bool status = true; - study.areas.each([&](const Data::Area& area) { + areas.each([&](const Data::Area& area) { auto index = area.index; auto& weeklyResults = *(problem.ResultatsHoraires[index]); @@ -212,27 +208,31 @@ static bool Remix(const Data::Study& study, PROBLEME_HEBDO& problem, uint numSpa return status; } -void RemixHydroForAllAreas(const Data::Study& study, +void RemixHydroForAllAreas(const Data::AreaList& areas, PROBLEME_HEBDO& problem, + Data::SheddingPolicy sheddingPolicy, + Data::SimplexOptimization simplexOptimizationRange, uint numSpace, - uint hourInYear, - uint nbHour) + uint hourInYear) { - assert(nbHour == 168 && "endHour seems invalid"); - (void)nbHour; - assert(study.parameters.mode != Data::stdmAdequacyDraft); - - if (study.parameters.shedding.policy == Data::shpShavePeaks) + // gp : useless ==> we remove it + // assert(nbHour == 168 && "endHour seems invalid"); + // (void)nbHour; + + // gp : we do not care : will be removed very soon + // assert(study.parameters.mode != Data::stdmAdequacyDraft); + + if (sheddingPolicy == Data::shpShavePeaks) { bool result = true; - switch (study.parameters.simplexOptimizationRange) + switch (simplexOptimizationRange) { case Data::sorWeek: - result = Remix<168>(study, problem, numSpace, hourInYear); + result = Remix<168>(areas, problem, numSpace, hourInYear); break; case Data::sorDay: - result = Remix<24>(study, problem, numSpace, hourInYear); + result = Remix<24>(areas, problem, numSpace, hourInYear); break; case Data::sorUnknown: logs.fatal() << "invalid simplex optimization range"; @@ -246,6 +246,4 @@ void RemixHydroForAllAreas(const Data::Study& study, } } } -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index 2bbfeb663d..12f205f6c0 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -28,80 +28,21 @@ #include "economy.h" #include #include +#include "simulation.h" +#include "../optimisation/opt_fonctions.h" +#include "../optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.h" +#include "common-eco-adq.h" #include "opt_time_writer.h" using namespace Yuni; -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { enum { - nbHoursInAWeek = 168, }; -EconomyWeeklyOptimization::EconomyWeeklyOptimization(PROBLEME_HEBDO** problemesHebdo) : - pProblemesHebdo(problemesHebdo) -{ -} - -EconomyWeeklyOptimization::Ptr EconomyWeeklyOptimization::create(bool adqPatchEnabled, - PROBLEME_HEBDO** problemesHebdo) -{ - if (adqPatchEnabled) - return std::make_unique(problemesHebdo); - else - return std::make_unique(problemesHebdo); - - return nullptr; -} - -// Adequacy patch -AdequacyPatchOptimization::AdequacyPatchOptimization(PROBLEME_HEBDO** problemesHebdo) : - EconomyWeeklyOptimization(problemesHebdo) -{ -} -void AdequacyPatchOptimization::solve(Variable::State& state, int hourInTheYear, uint numSpace) -{ - auto problemeHebdo = pProblemesHebdo[numSpace]; - problemeHebdo->adqPatchParams->AdequacyFirstStep = true; - OPT_OptimisationHebdomadaire(problemeHebdo, numSpace); - problemeHebdo->adqPatchParams->AdequacyFirstStep = false; - - for (int pays = 0; pays < problemeHebdo->NombreDePays; ++pays) - { - if (problemeHebdo->adequacyPatchRuntimeData.areaMode[pays] - == Data::AdequacyPatch::physicalAreaInsideAdqPatch) - memcpy(problemeHebdo->ResultatsHoraires[pays]->ValeursHorairesDENS, - problemeHebdo->ResultatsHoraires[pays]->ValeursHorairesDeDefaillancePositive, - problemeHebdo->NombreDePasDeTemps * sizeof(double)); - else - memset(problemeHebdo->ResultatsHoraires[pays]->ValeursHorairesDENS, - 0, - problemeHebdo->NombreDePasDeTemps * sizeof(double)); - } - - // TODO check if we need to cut SIM_RenseignementProblemeHebdo and just pick out the - // part that we need - ::SIM_RenseignementProblemeHebdo(*problemeHebdo, state, numSpace, hourInTheYear); - OPT_OptimisationHebdomadaire(problemeHebdo, numSpace); -} - -// No adequacy patch -NoAdequacyPatchOptimization::NoAdequacyPatchOptimization(PROBLEME_HEBDO** problemesHebdo) : - EconomyWeeklyOptimization(problemesHebdo) -{ -} -void NoAdequacyPatchOptimization::solve(Variable::State&, int, uint numSpace) -{ - auto problemeHebdo = pProblemesHebdo[numSpace]; - OPT_OptimisationHebdomadaire(problemeHebdo, numSpace); -} - Economy::Economy(Data::Study& study) : study(study), preproOnly(false), pProblemesHebdo(nullptr) { } @@ -148,6 +89,9 @@ bool Economy::simulationBegin() if (!preproOnly) { pProblemesHebdo = new PROBLEME_HEBDO*[pNbMaxPerformedYearsInParallel]; + weeklyOptProblems_.resize(pNbMaxPerformedYearsInParallel); + postProcessesList_.resize(pNbMaxPerformedYearsInParallel); + for (uint numSpace = 0; numSpace < pNbMaxPerformedYearsInParallel; numSpace++) { pProblemesHebdo[numSpace] = new PROBLEME_HEBDO(); @@ -159,10 +103,21 @@ bool Economy::simulationBegin() logs.fatal() << "internal error"; return false; } - } - weeklyOptProblem - = EconomyWeeklyOptimization::create(study.parameters.adqPatch.enabled, pProblemesHebdo); + weeklyOptProblems_[numSpace] = + Antares::Solver::Optimization::WeeklyOptimization::create( + study.parameters.adqPatch.enabled, + pProblemesHebdo[numSpace], + numSpace); + postProcessesList_[numSpace] = + interfacePostProcessList::create(study.parameters.adqPatch.enabled, + pProblemesHebdo[numSpace], + numSpace, + study.areas, + study.parameters.shedding.policy, + study.parameters.simplexOptimizationRange, + study.calendar); + } SIM_InitialisationResultats(); } @@ -178,6 +133,7 @@ bool Economy::simulationBegin() return true; } + bool Economy::year(Progression::Task& progression, Variable::State& state, uint numSpace, @@ -207,7 +163,7 @@ bool Economy::year(Progression::Task& progression, pProblemesHebdo[numSpace]->HeureDansLAnnee = hourInTheYear; ::SIM_RenseignementProblemeHebdo( - *pProblemesHebdo[numSpace], state, numSpace, hourInTheYear); + *pProblemesHebdo[numSpace], state.weekInTheYear, numSpace, hourInTheYear); // Reinit optimisation if needed pProblemesHebdo[numSpace]->ReinitOptimisation = reinitOptim ? OUI_ANTARES : NON_ANTARES; @@ -215,22 +171,11 @@ bool Economy::year(Progression::Task& progression, try { - weeklyOptProblem->solve(state, hourInTheYear, numSpace); - - DispatchableMarginForAllAreas( - study, *pProblemesHebdo[numSpace], numSpace, hourInTheYear); - - computingHydroLevels(study, *pProblemesHebdo[numSpace], nbHoursInAWeek, false); - - RemixHydroForAllAreas( - study, *pProblemesHebdo[numSpace], numSpace, hourInTheYear, nbHoursInAWeek); - - computingHydroLevels(study, *pProblemesHebdo[numSpace], nbHoursInAWeek, true); - - interpolateWaterValue( - study, *pProblemesHebdo[numSpace], state, hourInTheYear, nbHoursInAWeek); + weeklyOptProblems_[numSpace]->solve(w, hourInTheYear); - updatingWeeklyFinalHydroLevel(study, *pProblemesHebdo[numSpace], nbHoursInAWeek); + // Runs all the post processes in the list of post-process commands + optRuntimeData opt_runtime_data(state.year, w, hourInTheYear); + postProcessesList_[numSpace]->runAll(opt_runtime_data); variables.weekBegin(state); uint previousHourInTheYear = state.hourInTheYear; @@ -296,7 +241,7 @@ bool Economy::year(Progression::Task& progression, ++progression; } - updatingAnnualFinalHydroLevel(study, *pProblemesHebdo[numSpace]); + updatingAnnualFinalHydroLevel(study.areas, *pProblemesHebdo[numSpace]); optWriter.finalize(); finalizeOptimizationStatistics(*pProblemesHebdo[numSpace], state); @@ -340,6 +285,4 @@ void Economy::prepareClustersInMustRunMode(uint numSpace) PrepareDataFromClustersInMustrunMode(study, numSpace); } -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation diff --git a/src/solver/simulation/economy.h b/src/solver/simulation/economy.h index c77bca98ae..f3a42914f1 100644 --- a/src/solver/simulation/economy.h +++ b/src/solver/simulation/economy.h @@ -30,42 +30,14 @@ #include "../variable/variable.h" #include "../variable/economy/all.h" #include "../variable/state.h" -#include "common-eco-adq.h" -#include "solver.h" // for definition of type yearRandomNumbers - -namespace Antares -{ -namespace Solver -{ -namespace Simulation -{ -class EconomyWeeklyOptimization -{ -public: - using Ptr = std::unique_ptr; - virtual void solve(Variable::State& state, int hourInTheYear, uint numSpace) = 0; - static Ptr create(bool adqPatchEnabled, PROBLEME_HEBDO** pProblemesHebdo); +#include "../optimisation/base_weekly_optimization.h" +#include "base_post_process.h" -protected: - explicit EconomyWeeklyOptimization(PROBLEME_HEBDO** pProblemesHebdo); - PROBLEME_HEBDO** pProblemesHebdo; -}; - -class AdequacyPatchOptimization : public EconomyWeeklyOptimization -{ -public: - explicit AdequacyPatchOptimization(PROBLEME_HEBDO** problemesHebdo); - void solve(Variable::State& state, int hourInTheYear, uint numSpace) override; -}; +#include "solver.h" // for definition of type yearRandomNumbers -class NoAdequacyPatchOptimization : public EconomyWeeklyOptimization +namespace Antares::Solver::Simulation { -public: - explicit NoAdequacyPatchOptimization(PROBLEME_HEBDO** problemesHebdo); - void solve(Variable::State&, int, uint numSpace) override; -}; - class Economy { public: @@ -127,11 +99,10 @@ class Economy uint pNbMaxPerformedYearsInParallel; bool pPreproOnly; PROBLEME_HEBDO** pProblemesHebdo; - EconomyWeeklyOptimization::Ptr weeklyOptProblem; + std::vector> weeklyOptProblems_; + std::vector> postProcessesList_; }; // class Economy -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation #endif // __SOLVER_SIMULATION_ECONOMY_H__ diff --git a/src/solver/simulation/opt_time_writer.cpp b/src/solver/simulation/opt_time_writer.cpp index 30eb68a726..378b39b5b9 100644 --- a/src/solver/simulation/opt_time_writer.cpp +++ b/src/solver/simulation/opt_time_writer.cpp @@ -1,3 +1,29 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ #include "opt_time_writer.h" OptimizationStatisticsWriter::OptimizationStatisticsWriter( diff --git a/src/solver/simulation/opt_time_writer.h b/src/solver/simulation/opt_time_writer.h index e60ef31514..44ca477c7d 100644 --- a/src/solver/simulation/opt_time_writer.h +++ b/src/solver/simulation/opt_time_writer.h @@ -1,3 +1,29 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ #pragma once #include #include diff --git a/src/solver/simulation/sim_alloc_probleme_hebdo.cpp b/src/solver/simulation/sim_alloc_probleme_hebdo.cpp index ff675772c7..e2c4969497 100644 --- a/src/solver/simulation/sim_alloc_probleme_hebdo.cpp +++ b/src/solver/simulation/sim_alloc_probleme_hebdo.cpp @@ -451,6 +451,12 @@ void SIM_AllocationProblemeHebdo(PROBLEME_HEBDO& problem, int NombreDePasDeTemps = (double*)MemAlloc(NombreDePasDeTemps * sizeof(double)); problem.ResultatsHoraires[k]->ValeursHorairesDENS = (double*)MemAlloc(NombreDePasDeTemps * sizeof(double)); // adq patch + problem.ResultatsHoraires[k]->ValeursHorairesLmrViolations + = (int*)MemAllocMemset(NombreDePasDeTemps * sizeof(int)); // adq patch + problem.ResultatsHoraires[k]->ValeursHorairesSpilledEnergyAfterCSR + = (double*)MemAllocMemset(NombreDePasDeTemps * sizeof(double)); // adq patch + problem.ResultatsHoraires[k]->ValeursHorairesDtgMrgCsr + = (double*)MemAllocMemset(NombreDePasDeTemps * sizeof(double)); // adq patch problem.ResultatsHoraires[k]->ValeursHorairesDeDefaillancePositiveUp = (double*)MemAlloc(NombreDePasDeTemps * sizeof(double)); problem.ResultatsHoraires[k]->ValeursHorairesDeDefaillancePositiveDown @@ -815,6 +821,9 @@ void SIM_DesallocationProblemeHebdo(PROBLEME_HEBDO& problem) MemFree(problem.PaliersThermiquesDuPays[k]); MemFree(problem.ResultatsHoraires[k]->ValeursHorairesDeDefaillancePositive); MemFree(problem.ResultatsHoraires[k]->ValeursHorairesDENS); + MemFree(problem.ResultatsHoraires[k]->ValeursHorairesLmrViolations); + MemFree(problem.ResultatsHoraires[k]->ValeursHorairesSpilledEnergyAfterCSR); + MemFree(problem.ResultatsHoraires[k]->ValeursHorairesDtgMrgCsr); MemFree(problem.ResultatsHoraires[k]->ValeursHorairesDeDefaillancePositiveUp); MemFree(problem.ResultatsHoraires[k]->ValeursHorairesDeDefaillancePositiveDown); MemFree(problem.ResultatsHoraires[k]->ValeursHorairesDeDefaillancePositiveAny); diff --git a/src/solver/simulation/sim_allocation_tableaux.cpp b/src/solver/simulation/sim_allocation_tableaux.cpp index 18426bdd6c..b8f271b212 100644 --- a/src/solver/simulation/sim_allocation_tableaux.cpp +++ b/src/solver/simulation/sim_allocation_tableaux.cpp @@ -1,4 +1,3 @@ - /* ** Copyright 2007-2018 RTE ** Authors: Antares_Simulator Team diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index de5d2a1ae7..3982e4ff04 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -58,11 +58,22 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study, problem.adqPatchParams = std::unique_ptr(new AdequacyPatchParameters()); // AdequacyFirstStep will be initialized during the economy solve - // AdqBehaviorMap will be initialized during the economy solve problem.adqPatchParams->SetNTCOutsideToInsideToZero = parameters.adqPatch.localMatching.setToZeroOutsideInsideLinks; problem.adqPatchParams->SetNTCOutsideToOutsideToZero = parameters.adqPatch.localMatching.setToZeroOutsideOutsideLinks; + problem.adqPatchParams->PriceTakingOrder + = parameters.adqPatch.curtailmentSharing.priceTakingOrder; + problem.adqPatchParams->IncludeHurdleCostCsr + = parameters.adqPatch.curtailmentSharing.includeHurdleCost; + problem.adqPatchParams->CheckCsrCostFunctionValue + = parameters.adqPatch.curtailmentSharing.checkCsrCostFunction; + problem.adqPatchParams->ThresholdRunCurtailmentSharingRule + = parameters.adqPatch.curtailmentSharing.thresholdRun; + problem.adqPatchParams->ThresholdDisplayLocalMatchingRuleViolations + = parameters.adqPatch.curtailmentSharing.thresholdDisplayViolations; + double temp = pow(10, -parameters.adqPatch.curtailmentSharing.thresholdVarBoundsRelaxation); + problem.adqPatchParams->ThresholdCSRVarBoundsRelaxation = temp < 0.1 ? temp : 0.1; problem.adequacyPatchRuntimeData.initialize(study); } @@ -308,7 +319,7 @@ void SIM_InitialisationResultats() } void SIM_RenseignementProblemeHebdo(PROBLEME_HEBDO& problem, - Antares::Solver::Variable::State& state, + uint weekInTheYear, uint numSpace, const int PasDeTempsDebut) { @@ -436,14 +447,14 @@ void SIM_RenseignementProblemeHebdo(PROBLEME_HEBDO& problem, double nivInit = problem.CaracteristiquesHydrauliques[k]->NiveauInitialReservoir; if (nivInit < 0.) { - logs.fatal() << "Area " << area.name << ", week " << problem.weekInTheYear + 1 + logs.fatal() << "Area " << area.name << ", week " << weekInTheYear + 1 << " : initial level < 0"; AntaresSolverEmergencyShutdown(); } if (nivInit > area.hydro.reservoirCapacity) { - logs.fatal() << "Area " << area.name << ", week " << problem.weekInTheYear + 1 + logs.fatal() << "Area " << area.name << ", week " << weekInTheYear + 1 << " : initial level over capacity"; AntaresSolverEmergencyShutdown(); } @@ -469,7 +480,6 @@ void SIM_RenseignementProblemeHebdo(PROBLEME_HEBDO& problem, problem.previousSimulationFinalLevel[k] * 100 / area.hydro.reservoirCapacity, area.hydro.waterValues, weekFirstDay, - state.h2oValueWorkVars, problem.CaracteristiquesHydrauliques[k]->WeeklyWaterValueStateRegular); } diff --git a/src/solver/simulation/sim_extern_variables_globales.h b/src/solver/simulation/sim_extern_variables_globales.h index 2d54ac604c..9b5195aaaa 100644 --- a/src/solver/simulation/sim_extern_variables_globales.h +++ b/src/solver/simulation/sim_extern_variables_globales.h @@ -41,7 +41,7 @@ extern NUMERO_CHRONIQUES_TIREES_PAR_INTERCONNEXION** NumeroChroniquesTireesParIn /* Optimisation */ /*-Economique-*/ -// extern PROBLEME_HEBDO ProblemeHebdo; +// extern PROBLEME_HEBDO problemeHebdo; /*-Adequation-*/ extern PROBLEME_HORAIRE_ADEQUATION ProblemeHoraireAdequation; extern VALEURS_ANNUELLES** ValeursAnnuellesAdequation; diff --git a/src/solver/simulation/sim_structure_probleme_economique.h b/src/solver/simulation/sim_structure_probleme_economique.h index 5f708db89d..83b4a63ec9 100644 --- a/src/solver/simulation/sim_structure_probleme_economique.h +++ b/src/solver/simulation/sim_structure_probleme_economique.h @@ -308,8 +308,8 @@ class AdequacyPatchRuntimeData public: std::vector areaMode; - std::vector originAreaType; - std::vector extremityAreaType; + std::vector originAreaMode; + std::vector extremityAreaMode; void initialize(Antares::Data::Study& study) { for (uint i = 0; i != study.areas.size(); ++i) @@ -320,8 +320,8 @@ class AdequacyPatchRuntimeData for (uint i = 0; i < study.runtime->interconnectionsCount; ++i) { auto& link = *(study.runtime->areaLink[i]); - originAreaType.push_back(link.from->adequacyPatchMode); - extremityAreaType.push_back(link.with->adequacyPatchMode); + originAreaMode.push_back(link.from->adequacyPatchMode); + extremityAreaMode.push_back(link.with->adequacyPatchMode); } } }; @@ -432,7 +432,10 @@ typedef struct typedef struct { double* ValeursHorairesDeDefaillancePositive; - double* ValeursHorairesDENS; // adq patch domestic unsupplied energy + double* ValeursHorairesDENS; // adq patch domestic unsupplied energy + int* ValeursHorairesLmrViolations; // adq patch lmr violations + double* ValeursHorairesSpilledEnergyAfterCSR; // adq patch spillage after CSR + double* ValeursHorairesDtgMrgCsr; // adq patch DTG MRG after CSR double* ValeursHorairesDeDefaillancePositiveUp; double* ValeursHorairesDeDefaillancePositiveDown; double* ValeursHorairesDeDefaillancePositiveAny; @@ -484,6 +487,12 @@ struct AdequacyPatchParameters bool AdequacyFirstStep; bool SetNTCOutsideToInsideToZero; bool SetNTCOutsideToOutsideToZero; + bool IncludeHurdleCostCsr; + bool CheckCsrCostFunctionValue; + Antares::Data::AdequacyPatch::AdqPatchPTO PriceTakingOrder; + double ThresholdRunCurtailmentSharingRule; + double ThresholdDisplayLocalMatchingRuleViolations; + double ThresholdCSRVarBoundsRelaxation; }; struct PROBLEME_HEBDO @@ -685,8 +694,8 @@ struct PROBLEME_HEBDO int* FlexUpDemandPoolOfNode; int* FlexDownOfferPoolOfNode; int* FlexDownDemandPoolOfNode; - #endif + public: /* Unknown status */ int* NbGrpCourbeGuide; // ? @@ -695,9 +704,5 @@ struct PROBLEME_HEBDO PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre; double maxPminThermiqueByDay[366]; - - /* Debug */ - char debugFolder[1024]; }; - #endif diff --git a/src/solver/simulation/simulation.h b/src/solver/simulation/simulation.h index dd819b471d..7b254b454a 100644 --- a/src/solver/simulation/simulation.h +++ b/src/solver/simulation/simulation.h @@ -64,7 +64,7 @@ void SIM_InitialisationProblemeHebdo(Antares::Data::Study& study, void SIM_PreallocationTableaux(void); void SIM_RenseignementProblemeHebdo(PROBLEME_HEBDO& problem, - Antares::Solver::Variable::State& state, + uint weekInTheYear, uint numSpace, const int); diff --git a/src/solver/simulation/solver.data.cpp b/src/solver/simulation/solver.data.cpp index 601270e1d8..bcf45d0bd8 100644 --- a/src/solver/simulation/solver.data.cpp +++ b/src/solver/simulation/solver.data.cpp @@ -28,13 +28,7 @@ #include "solver.data.h" #include -namespace Antares -{ -namespace Solver -{ -namespace Private -{ -namespace Simulation +namespace Antares::Solver::Private::Simulation { namespace { @@ -63,7 +57,4 @@ void CacheData::initialize(const Antares::Data::Parameters& parameters) refreshIntervalThermal = parameters.refreshIntervalThermal; } -} // namespace Simulation -} // namespace Private -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Private::Simulation diff --git a/src/solver/simulation/solver.data.h b/src/solver/simulation/solver.data.h index ebbca7cb3b..aa57748624 100644 --- a/src/solver/simulation/solver.data.h +++ b/src/solver/simulation/solver.data.h @@ -30,13 +30,7 @@ #include #include -namespace Antares -{ -namespace Solver -{ -namespace Private -{ -namespace Simulation +namespace Antares::Solver::Private::Simulation { class CacheData { @@ -71,9 +65,6 @@ class CacheData }; // class CacheData -} // namespace Simulation -} // namespace Private -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Private::Simulation #endif // __SOLVER_SIMULATION_SOLVER_H__ diff --git a/src/solver/simulation/solver.h b/src/solver/simulation/solver.h index a394bcee98..4f5aaf099f 100644 --- a/src/solver/simulation/solver.h +++ b/src/solver/simulation/solver.h @@ -43,11 +43,7 @@ #include -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { template class yearJob; @@ -188,9 +184,7 @@ class ISimulation : public Impl //! Result writer Antares::Solver::IResultWriter::Ptr pResultWriter = nullptr; }; // class ISimulation -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation #include "solver.hxx" diff --git a/src/solver/simulation/solver.hxx b/src/solver/simulation/solver.hxx index 62a3566d52..b4c3acbf8d 100644 --- a/src/solver/simulation/solver.hxx +++ b/src/solver/simulation/solver.hxx @@ -45,11 +45,7 @@ #include #include -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { template class yearJob final : public Yuni::Job::IJob @@ -1632,8 +1628,6 @@ void ISimulation::loopThroughYears(uint firstYear, } } -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation #endif // __SOLVER_SIMULATION_SOLVER_HXX__ diff --git a/src/solver/simulation/solver.utils.h b/src/solver/simulation/solver.utils.h index 64287285f3..f5ccdc20e3 100644 --- a/src/solver/simulation/solver.utils.h +++ b/src/solver/simulation/solver.utils.h @@ -39,41 +39,37 @@ #define SEP Yuni::IO::Separator -namespace Antares -{ -namespace Solver -{ -namespace Simulation +namespace Antares::Solver::Simulation { struct setOfParallelYears { - // Un lot d'anne excuter en parallle. - // En fonction d'une ventuelle play-list, certaines seront joues et d'autres non. + // Un lot d'année à exécuter en parallèle. + // En fonction d'une éventuelle play-list, certaines seront jouées et d'autres non. public: - // Numeros des annees en parallele pour ce lot (certaines ne seront pas joues en cas de - // play-list "troue") + // Numeros des annees en parallele pour ce lot (certaines ne seront pas jouées en cas de + // play-list "trouée") std::vector yearsIndices; - // Une annee doit-elle tre rejoue ? + // Une annee doit-elle être rejouée ? std::map yearFailed; - // Associe le numero d'une anne joue l'indice de l'espace + // Associe le numero d'une année jouée à l'indice de l'espace std::map performedYearToSpace; - // L'inverse : pour une anne joue, associe l'indice de l'espace au numero de l'anne + // L'inverse : pour une année jouée, associe l'indice de l'espace au numero de l'année std::map spaceToPerformedYear; - // Pour chaque anne, est-elle la premire devoir tre joue dans son lot d'annes ? + // Pour chaque année, est-elle la première à devoir être jouée dans son lot d'années ? std::map isFirstPerformedYearOfASet; - // Pour chaque anne du lot, est-elle joue ou non ? + // Pour chaque année du lot, est-elle jouée ou non ? std::map isYearPerformed; - // Nbre d'annes en parallele vraiment joues pour ce lot + // Nbre d'années en parallele vraiment jouées pour ce lot unsigned int nbPerformedYears; - // Nbre d'annes en parallele joues ou non pour ce lot + // Nbre d'années en parallele jouées ou non pour ce lot unsigned int nbYears; // Regenere-t-on des times series avant de jouer les annees du lot courant @@ -438,8 +434,6 @@ struct compareHydroCostsNoises return (std::abs(hcnr1.getValue()) < std::abs(hcnr2.getValue())) ? true : false; } }; -} // namespace Simulation -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Simulation #endif // __SOLVER_SIMULATION_SOLVER_H__ diff --git a/src/solver/simulation/timeseries-numbers.h b/src/solver/simulation/timeseries-numbers.h index 07a6a830d7..df5be2834f 100644 --- a/src/solver/simulation/timeseries-numbers.h +++ b/src/solver/simulation/timeseries-numbers.h @@ -31,11 +31,7 @@ #include #include -namespace Antares -{ -namespace Solver -{ -namespace TimeSeriesNumbers +namespace Antares::Solver::TimeSeriesNumbers { /*! ** \brief Generate all time-series numbers for a given set @@ -46,8 +42,6 @@ void StoreTimeseriesIntoOuput(Data::Study& study); // Exported for unit-tests bool checkAllElementsIdenticalOrOne(const std::vector& w); -} // namespace TimeSeriesNumbers -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::TimeSeriesNumbers #endif // __SOLVER_SIMULATION_GENERATE_TIMESERIES_H__ diff --git a/src/solver/utils/mps_utils.cpp b/src/solver/utils/mps_utils.cpp index 95a2fd7ae4..0be433599b 100644 --- a/src/solver/utils/mps_utils.cpp +++ b/src/solver/utils/mps_utils.cpp @@ -136,12 +136,12 @@ void fullOrToolsMPSwriter::runIfNeeded(Solver::IResultWriter::Ptr writer, ORTOOLS_EcrireJeuDeDonneesLineaireAuFormatMPS(solver_, writer, filename); } -mpsWriterFactory::mpsWriterFactory(PROBLEME_HEBDO* ProblemeHebdo, +mpsWriterFactory::mpsWriterFactory(PROBLEME_HEBDO* problemeHebdo, const int current_optim_number, PROBLEME_SIMPLEXE_NOMME* named_splx_problem, bool ortoolsUsed, MPSolver* solver) : - pb_hebdo_(ProblemeHebdo), + pb_hebdo_(problemeHebdo), named_splx_problem_(named_splx_problem), ortools_used_(ortoolsUsed), solver_(solver), diff --git a/src/solver/utils/mps_utils.h b/src/solver/utils/mps_utils.h index c470030f1b..086604a9e9 100644 --- a/src/solver/utils/mps_utils.h +++ b/src/solver/utils/mps_utils.h @@ -67,7 +67,7 @@ class nullMPSwriter : public I_MPS_writer class mpsWriterFactory { public: - mpsWriterFactory(PROBLEME_HEBDO* ProblemeHebdo, + mpsWriterFactory(PROBLEME_HEBDO* problemeHebdo, const int current_optim_number, PROBLEME_SIMPLEXE_NOMME* named_splx_problem, bool ortoolsUsed, diff --git a/src/solver/variable/economy/all.h b/src/solver/variable/economy/all.h index beaab5ef10..5ea0064f48 100644 --- a/src/solver/variable/economy/all.h +++ b/src/solver/variable/economy/all.h @@ -61,6 +61,9 @@ #include "hydroCost.h" #include "unsupliedEnergy.h" #include "domesticUnsuppliedEnergy.h" +#include "localMatchingRuleViolations.h" +#include "spilledEnergyAfterCSR.h" +#include "dtgMarginAfterCsr.h" #include "spilledEnergy.h" #include "lold.h" @@ -93,13 +96,7 @@ // Output variables associated to binding constraints #include "bindingConstraints/bindingConstraintsMarginalCost.h" -namespace Antares -{ -namespace Solver -{ -namespace Variable -{ -namespace Economy +namespace Antares::Solver::Variable::Economy { /*! ** \brief All variables for a single link (economy) @@ -152,18 +149,24 @@ typedef // Prices >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> VariablesPerArea; /*! @@ -222,31 +225,41 @@ typedef // Prices Common::SpatialAggregate< DomesticUnsuppliedEnergy, Common::SpatialAggregate< - SpilledEnergy, - // LOLD + LMRViolations, Common::SpatialAggregate< - LOLD, + SpilledEnergy, Common::SpatialAggregate< - LOLP, - + SpilledEnergyAfterCSR, + // LOLD Common::SpatialAggregate< - AvailableDispatchGen, + LOLD, Common::SpatialAggregate< - DispatchableGenMargin, + LOLP, Common::SpatialAggregate< - Marge, - - // Detail Prices + AvailableDispatchGen, Common::SpatialAggregate< - NonProportionalCost, // MBO 13/05/2014 - // - refs: #21 - - // Number Of Dispatched Units + DispatchableGenMargin, Common::SpatialAggregate< - NbOfDispatchedUnits // MBO - // 25/02/2016 - // - refs: #55 - >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + DtgMarginCsr, + Common::SpatialAggregate< + Marge, + + // Detail Prices + Common::SpatialAggregate< + NonProportionalCost, // MBO + // 13/05/2014 + // - + // refs: + // #21 + + // Number Of Dispatched Units + Common::SpatialAggregate< + NbOfDispatchedUnits // MBO + // 25/02/2016 + // - + // refs: + // #55 + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> VariablesPerSetOfAreas; typedef BindingConstMarginCost< // Marginal cost for a binding constraint @@ -269,10 +282,7 @@ typedef Variable::Join< */ typedef Container::List AllVariables; -} // namespace Economy -} // namespace Variable -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Variable::Economy // post include #include "links.h" diff --git a/src/solver/variable/economy/dtgMarginAfterCsr.h b/src/solver/variable/economy/dtgMarginAfterCsr.h new file mode 100644 index 0000000000..7601204b1f --- /dev/null +++ b/src/solver/variable/economy/dtgMarginAfterCsr.h @@ -0,0 +1,278 @@ +/* +** Copyright 2007-2018 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ +#ifndef __SOLVER_VARIABLE_ECONOMY_DtgMarginCsr_H__ +#define __SOLVER_VARIABLE_ECONOMY_DtgMarginCsr_H__ + +#include "../variable.h" + +namespace Antares::Solver::Variable::Economy +{ +struct VCardDtgMarginCsr +{ + //! Caption + static const char* Caption() + { + return "DTG MRG CSR"; + } + //! Unit + static const char* Unit() + { + return "MWh"; + } + //! The short description of the variable + static const char* Description() + { + return "Dispatchable Generation Margin (after CSR optimization)"; + } + + //! The expecte results + typedef Results>>>> + ResultsType; + + //! The VCard to look for for calculating spatial aggregates + typedef VCardDtgMarginCsr VCardForSpatialAggregate; + + enum + { + //! Data Level + categoryDataLevel = Category::area, + //! File level (provided by the type of the results) + categoryFileLevel = ResultsType::categoryFile & (Category::id | Category::va), + //! Precision (views) + precision = Category::all, + //! Indentation (GUI) + nodeDepthForGUI = +0, + //! Decimal precision + decimal = 0, + //! Number of columns used by the variable (One ResultsType per column) + columnCount = 1, + //! The Spatial aggregation + spatialAggregate = Category::spatialAggregateSum, + spatialAggregateMode = Category::spatialAggregateEachYear, + spatialAggregatePostProcessing = 0, + //! Intermediate values + hasIntermediateValues = 1, + //! Can this variable be non applicable (0 : no, 1 : yes) + isPossiblyNonApplicable = 0, + }; + + typedef IntermediateValues IntermediateValuesBaseType; + typedef IntermediateValues* IntermediateValuesType; + + typedef IntermediateValuesBaseType* IntermediateValuesTypeForSpatialAg; + +}; // class VCard + +/*! +** \brief C02 Average value of the overrall DtgMarginCsr emissions expected from all +** the thermal dispatchable clusters +*/ +template +class DtgMarginCsr + : public Variable::IVariable, NextT, VCardDtgMarginCsr> +{ +public: + //! Type of the next static variable + typedef NextT NextType; + //! VCard + typedef VCardDtgMarginCsr VCardType; + //! Ancestor + typedef Variable::IVariable, NextT, VCardType> AncestorType; + + //! List of expected results + typedef typename VCardType::ResultsType ResultsType; + + typedef VariableAccessor VariableAccessorType; + + enum + { + //! How many items have we got + count = 1 + NextT::count, + }; + + template + struct Statistics + { + enum + { + count + = ((VCardType::categoryDataLevel & CDataLevel && VCardType::categoryFileLevel & CFile) + ? (NextType::template Statistics::count + + VCardType::columnCount * ResultsType::count) + : NextType::template Statistics::count), + }; + }; + + ~DtgMarginCsr() + { + delete[] pValuesForTheCurrentYear; + } + + void initializeFromStudy(Data::Study& study) + { + pNbYearsParallel = study.maxNbYearsInParallel; + + // Intermediate values + InitializeResultsFromStudy(AncestorType::pResults, study); + + pValuesForTheCurrentYear = new VCardType::IntermediateValuesBaseType[pNbYearsParallel]; + for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) + pValuesForTheCurrentYear[numSpace].initializeFromStudy(study); + + // Next + NextType::initializeFromStudy(study); + } + + template + static void InitializeResultsFromStudy(R& results, Data::Study& study) + { + VariableAccessorType::InitializeAndReset(results, study); + } + + void initializeFromArea(Data::Study* study, Data::Area* area) + { + // Next + NextType::initializeFromArea(study, area); + } + + void initializeFromLink(Data::Study* study, Data::AreaLink* link) + { + // Next + NextType::initializeFromAreaLink(study, link); + } + + void simulationBegin() + { + for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) + pValuesForTheCurrentYear[numSpace].reset(); + // Next + NextType::simulationBegin(); + } + + void simulationEnd() + { + NextType::simulationEnd(); + } + + void yearBegin(unsigned int year, unsigned int numSpace) + { + // Reset the values for the current year + pValuesForTheCurrentYear[numSpace].reset(); + + // Next variable + NextType::yearBegin(year, numSpace); + } + + void yearEndBuild(State& state, unsigned int year) + { + // Next variable + NextType::yearEndBuild(state, year); + } + + void yearEnd(unsigned int year, unsigned int numSpace) + { + // Compute all statistics for the current year (daily,weekly,monthly) + pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear(); + + // Next variable + NextType::yearEnd(year, numSpace); + } + + void computeSummary(std::map& numSpaceToYear, + unsigned int nbYearsForCurrentSummary) + { + for (unsigned int numSpace = 0; numSpace < nbYearsForCurrentSummary; ++numSpace) + { + // Merge all those values with the global results + AncestorType::pResults.merge(numSpaceToYear[numSpace] /*year*/, + pValuesForTheCurrentYear[numSpace]); + } + + // Next variable + NextType::computeSummary(numSpaceToYear, nbYearsForCurrentSummary); + } + + void hourBegin(unsigned int hourInTheYear) + { + // Next variable + NextType::hourBegin(hourInTheYear); + } + + void hourForEachArea(State& state, unsigned int numSpace) + { + // Total DtgMarginCsr + pValuesForTheCurrentYear[numSpace][state.hourInTheYear] + = state.hourlyResults->ValeursHorairesDtgMrgCsr[state.hourInTheWeek]; + + // Next variable + NextType::hourForEachArea(state, numSpace); + } + + void hourEnd(State& state, unsigned int hourInTheYear) + { + // Next variable + NextType::hourEnd(state, hourInTheYear); + } + + Antares::Memory::Stored::ConstReturnType retrieveRawHourlyValuesForCurrentYear( + unsigned int, + unsigned int numSpace) const + { + return pValuesForTheCurrentYear[numSpace].hour; + } + + void localBuildAnnualSurveyReport(SurveyResults& results, + int fileLevel, + int precision, + unsigned int numSpace) const + { + // Initializing external pointer on current variable non applicable status + results.isCurrentVarNA = AncestorType::isNonApplicable; + + if (AncestorType::isPrinted[0]) + { + // Write the data for the current year + results.variableCaption = VCardType::Caption(); + pValuesForTheCurrentYear[numSpace].template buildAnnualSurveyReport( + results, fileLevel, precision); + } + } + +private: + //! Intermediate values for each year + typename VCardType::IntermediateValuesType pValuesForTheCurrentYear; + unsigned int pNbYearsParallel; + +}; // class DtgMarginCsr + +} // namespace Antares::Solver::Variable::Economy + +#endif // __SOLVER_VARIABLE_ECONOMY_DtgMarginCsr_H__ diff --git a/src/solver/variable/economy/localMatchingRuleViolations.h b/src/solver/variable/economy/localMatchingRuleViolations.h new file mode 100644 index 0000000000..19d5b96769 --- /dev/null +++ b/src/solver/variable/economy/localMatchingRuleViolations.h @@ -0,0 +1,274 @@ +/* +** Copyright 2007-2018 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ +#ifndef __SOLVER_VARIABLE_ECONOMY_LMR_VIOLATIONS_H__ +#define __SOLVER_VARIABLE_ECONOMY_LMR_VIOLATIONS_H__ + +#include "../variable.h" + +namespace Antares::Solver::Variable::Economy +{ +struct VCardLMRViolations +{ + //! Caption + static const char* Caption() + { + return "LMR VIOL."; + } + //! Unit + static const char* Unit() + { + return " "; + } + + //! The short description of the variable + static const char* Description() + { + return "Local Matching Rule is violated more than the provided threshold"; + } + + //! The expecte results + typedef Results> + ResultsType; + + //! The VCard to look for for calculating spatial aggregates + typedef VCardLMRViolations VCardForSpatialAggregate; + + enum + { + //! Data Level + categoryDataLevel = Category::area, + //! File level (provided by the type of the results) + categoryFileLevel = ResultsType::categoryFile & (Category::id | Category::va), + //! Precision (views) + precision = Category::all, + //! Indentation (GUI) + nodeDepthForGUI = +0, + //! Decimal precision + decimal = 0, + //! Number of columns used by the variable (One ResultsType per column) + columnCount = 1, + //! The Spatial aggregation + spatialAggregate = Category::spatialAggregateSum, + spatialAggregateMode = Category::spatialAggregateEachYear, + spatialAggregatePostProcessing = 0, + //! Intermediate values + hasIntermediateValues = 1, + //! Can this variable be non applicable (0 : no, 1 : yes) + isPossiblyNonApplicable = 0, + }; + + typedef IntermediateValues IntermediateValuesBaseType; + typedef IntermediateValues* IntermediateValuesType; + + typedef IntermediateValuesBaseType* IntermediateValuesTypeForSpatialAg; + +}; // class VCard + +/*! +** \brief C02 Average value of the overrall CO2 emissions expected from all +** the thermal dispatchable clusters +*/ +template +class LMRViolations : public Variable::IVariable, NextT, VCardLMRViolations> +{ +public: + //! Type of the next static variable + typedef NextT NextType; + //! VCard + typedef VCardLMRViolations VCardType; + //! Ancestor + typedef Variable::IVariable, NextT, VCardType> AncestorType; + + //! List of expected results + typedef typename VCardType::ResultsType ResultsType; + + typedef VariableAccessor VariableAccessorType; + + enum + { + //! How many items have we got + count = 1 + NextT::count, + }; + + template + struct Statistics + { + enum + { + count + = ((VCardType::categoryDataLevel & CDataLevel && VCardType::categoryFileLevel & CFile) + ? (NextType::template Statistics::count + + VCardType::columnCount * ResultsType::count) + : NextType::template Statistics::count), + }; + }; + + + ~LMRViolations() + { + delete[] pValuesForTheCurrentYear; + } + + void initializeFromStudy(Data::Study& study) + { + pNbYearsParallel = study.maxNbYearsInParallel; + + // Intermediate values + InitializeResultsFromStudy(AncestorType::pResults, study); + + pValuesForTheCurrentYear = new VCardType::IntermediateValuesBaseType[pNbYearsParallel]; + for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) + pValuesForTheCurrentYear[numSpace].initializeFromStudy(study); + + // Next + NextType::initializeFromStudy(study); + } + + template + static void InitializeResultsFromStudy(R& results, Data::Study& study) + { + VariableAccessorType::InitializeAndReset(results, study); + } + + void initializeFromArea(Data::Study* study, Data::Area* area) + { + // Next + NextType::initializeFromArea(study, area); + } + + void initializeFromLink(Data::Study* study, Data::AreaLink* link) + { + // Next + NextType::initializeFromAreaLink(study, link); + } + + void simulationBegin() + { + for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) + pValuesForTheCurrentYear[numSpace].reset(); + // Next + NextType::simulationBegin(); + } + + void simulationEnd() + { + NextType::simulationEnd(); + } + + void yearBegin(unsigned int year, unsigned int numSpace) + { + // Reset the values for the current year + pValuesForTheCurrentYear[numSpace].reset(); + // Next variable + NextType::yearBegin(year, numSpace); + } + + void yearEndBuild(State& state, unsigned int year) + { + // Next variable + NextType::yearEndBuild(state, year); + } + + void yearEnd(unsigned int year, unsigned int numSpace) + { + // Compute all statistics for the current year (daily,weekly,monthly) + pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear(); + + // Next variable + NextType::yearEnd(year, numSpace); + } + + void computeSummary(std::map& numSpaceToYear, + unsigned int nbYearsForCurrentSummary) + { + for (unsigned int numSpace = 0; numSpace < nbYearsForCurrentSummary; ++numSpace) + { + // Merge all those values with the global results + AncestorType::pResults.merge(numSpaceToYear[numSpace] /*year*/, + pValuesForTheCurrentYear[numSpace]); + } + + // Next variable + NextType::computeSummary(numSpaceToYear, nbYearsForCurrentSummary); + } + + void hourBegin(unsigned int hourInTheYear) + { + // Next variable + NextType::hourBegin(hourInTheYear); + } + + void hourForEachArea(State& state, unsigned int numSpace) + { + // Total LocalMatchingRule Violations + pValuesForTheCurrentYear[numSpace][state.hourInTheYear] + = state.hourlyResults->ValeursHorairesLmrViolations[state.hourInTheWeek]; + + // Next variable + NextType::hourForEachArea(state, numSpace); + } + + void hourEnd(State& state, unsigned int hourInTheYear) + { + NextType::hourEnd(state, hourInTheYear); + } + + Antares::Memory::Stored::ConstReturnType retrieveRawHourlyValuesForCurrentYear( + unsigned int, + unsigned int numSpace) const + { + return pValuesForTheCurrentYear[numSpace].hour; + } + + void localBuildAnnualSurveyReport(SurveyResults& results, + int fileLevel, + int precision, + unsigned int numSpace) const + { + // Initializing external pointer on current variable non applicable status + results.isCurrentVarNA = AncestorType::isNonApplicable; + + if (AncestorType::isPrinted[0]) + { + // Write the data for the current year + results.variableCaption = VCardType::Caption(); + pValuesForTheCurrentYear[numSpace].template buildAnnualSurveyReport( + results, fileLevel, precision); + } + } + +private: + //! Intermediate values for each year + typename VCardType::IntermediateValuesType pValuesForTheCurrentYear; + unsigned int pNbYearsParallel; + +}; // class LMRViolations + +} + +#endif // __SOLVER_VARIABLE_ECONOMY_LMR_VIOLATIONS_H__ diff --git a/src/solver/variable/economy/spilledEnergyAfterCSR.h b/src/solver/variable/economy/spilledEnergyAfterCSR.h new file mode 100644 index 0000000000..f7274212ac --- /dev/null +++ b/src/solver/variable/economy/spilledEnergyAfterCSR.h @@ -0,0 +1,279 @@ +/* +** Copyright 2007-2018 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ +#ifndef __SOLVER_VARIABLE_ECONOMY_SpilledEnergyAfterCSR_H__ +#define __SOLVER_VARIABLE_ECONOMY_SpilledEnergyAfterCSR_H__ + +#include "../variable.h" + +namespace Antares::Solver::Variable::Economy +{ +struct VCardSpilledEnergyAfterCSR +{ + //! Caption + static const char* Caption() + { + return "SPIL. ENRG. CSR"; + } + //! Unit + static const char* Unit() + { + return "MWh"; + } + //! The short description of the variable + static const char* Description() + { + return "Spilled Energy After CSR Optimization (generation that cannot be satisfied) " + "after CSR optimization"; + } + + //! The expecte results + typedef Results>>>> + ResultsType; + + //! The VCard to look for for calculating spatial aggregates + typedef VCardSpilledEnergyAfterCSR VCardForSpatialAggregate; + + enum + { + //! Data Level + categoryDataLevel = Category::area, + //! File level (provided by the type of the results) + categoryFileLevel = ResultsType::categoryFile & (Category::id | Category::va), + //! Precision (views) + precision = Category::all, + //! Indentation (GUI) + nodeDepthForGUI = +0, + //! Decimal precision + decimal = 0, + //! Number of columns used by the variable (One ResultsType per column) + columnCount = 1, + //! The Spatial aggregation + spatialAggregate = Category::spatialAggregateSum, + spatialAggregateMode = Category::spatialAggregateEachYear, + spatialAggregatePostProcessing = 0, + //! Intermediate values + hasIntermediateValues = 1, + //! Can this variable be non applicable (0 : no, 1 : yes) + isPossiblyNonApplicable = 0, + }; + + typedef IntermediateValues IntermediateValuesBaseType; + typedef IntermediateValues* IntermediateValuesType; + + typedef IntermediateValuesBaseType* IntermediateValuesTypeForSpatialAg; + +}; // class VCard + +/*! +** \brief C02 Average value of the overrall SpilledEnergyAfterCSR emissions expected from all +** the thermal dispatchable clusters +*/ +template +class SpilledEnergyAfterCSR + : public Variable::IVariable, NextT, VCardSpilledEnergyAfterCSR> +{ +public: + //! Type of the next static variable + typedef NextT NextType; + //! VCard + typedef VCardSpilledEnergyAfterCSR VCardType; + //! Ancestor + typedef Variable::IVariable, NextT, VCardType> AncestorType; + + //! List of expected results + typedef typename VCardType::ResultsType ResultsType; + + typedef VariableAccessor VariableAccessorType; + + enum + { + //! How many items have we got + count = 1 + NextT::count, + }; + + template + struct Statistics + { + enum + { + count + = ((VCardType::categoryDataLevel & CDataLevel && VCardType::categoryFileLevel & CFile) + ? (NextType::template Statistics::count + + VCardType::columnCount * ResultsType::count) + : NextType::template Statistics::count), + }; + }; + + ~SpilledEnergyAfterCSR() + { + delete[] pValuesForTheCurrentYear; + } + + void initializeFromStudy(Data::Study& study) + { + pNbYearsParallel = study.maxNbYearsInParallel; + + // Intermediate values + InitializeResultsFromStudy(AncestorType::pResults, study); + + pValuesForTheCurrentYear = new VCardType::IntermediateValuesBaseType[pNbYearsParallel]; + for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) + pValuesForTheCurrentYear[numSpace].initializeFromStudy(study); + + // Next + NextType::initializeFromStudy(study); + } + + template + static void InitializeResultsFromStudy(R& results, Data::Study& study) + { + VariableAccessorType::InitializeAndReset(results, study); + } + + void initializeFromArea(Data::Study* study, Data::Area* area) + { + // Next + NextType::initializeFromArea(study, area); + } + + void initializeFromLink(Data::Study* study, Data::AreaLink* link) + { + // Next + NextType::initializeFromAreaLink(study, link); + } + + void simulationBegin() + { + for (unsigned int numSpace = 0; numSpace < pNbYearsParallel; numSpace++) + pValuesForTheCurrentYear[numSpace].reset(); + // Next + NextType::simulationBegin(); + } + + void simulationEnd() + { + NextType::simulationEnd(); + } + + void yearBegin(unsigned int year, unsigned int numSpace) + { + // Reset the values for the current year + pValuesForTheCurrentYear[numSpace].reset(); + + // Next variable + NextType::yearBegin(year, numSpace); + } + + void yearEndBuild(State& state, unsigned int year) + { + // Next variable + NextType::yearEndBuild(state, year); + } + + void yearEnd(unsigned int year, unsigned int numSpace) + { + // Compute all statistics for the current year (daily,weekly,monthly) + pValuesForTheCurrentYear[numSpace].computeStatisticsForTheCurrentYear(); + + // Next variable + NextType::yearEnd(year, numSpace); + } + + void computeSummary(std::map& numSpaceToYear, + unsigned int nbYearsForCurrentSummary) + { + for (unsigned int numSpace = 0; numSpace < nbYearsForCurrentSummary; ++numSpace) + { + // Merge all those values with the global results + AncestorType::pResults.merge(numSpaceToYear[numSpace] /*year*/, + pValuesForTheCurrentYear[numSpace]); + } + + // Next variable + NextType::computeSummary(numSpaceToYear, nbYearsForCurrentSummary); + } + + void hourBegin(unsigned int hourInTheYear) + { + // Next variable + NextType::hourBegin(hourInTheYear); + } + + void hourForEachArea(State& state, unsigned int numSpace) + { + // Total SpilledEnergyAfterCSR emissions + pValuesForTheCurrentYear[numSpace][state.hourInTheYear] + = state.hourlyResults->ValeursHorairesSpilledEnergyAfterCSR[state.hourInTheWeek]; + + // Next variable + NextType::hourForEachArea(state, numSpace); + } + + void hourEnd(State& state, unsigned int hourInTheYear) + { + // Next variable + NextType::hourEnd(state, hourInTheYear); + } + + Antares::Memory::Stored::ConstReturnType retrieveRawHourlyValuesForCurrentYear( + unsigned int, + unsigned int numSpace) const + { + return pValuesForTheCurrentYear[numSpace].hour; + } + + void localBuildAnnualSurveyReport(SurveyResults& results, + int fileLevel, + int precision, + unsigned int numSpace) const + { + // Initializing external pointer on current variable non applicable status + results.isCurrentVarNA = AncestorType::isNonApplicable; + + if (AncestorType::isPrinted[0]) + { + // Write the data for the current year + results.variableCaption = VCardType::Caption(); + pValuesForTheCurrentYear[numSpace].template buildAnnualSurveyReport( + results, fileLevel, precision); + } + } + +private: + //! Intermediate values for each year + typename VCardType::IntermediateValuesType pValuesForTheCurrentYear; + unsigned int pNbYearsParallel; + +}; // class SpilledEnergyAfterCSR + +} // namespace Antares::Solver::Variable::Economy + +#endif // __SOLVER_VARIABLE_ECONOMY_SpilledEnergyAfterCSR_H__ diff --git a/src/solver/variable/state.cpp b/src/solver/variable/state.cpp index f926be0df8..dccfdc4e65 100644 --- a/src/solver/variable/state.cpp +++ b/src/solver/variable/state.cpp @@ -31,11 +31,7 @@ using namespace Yuni; -namespace Antares -{ -namespace Solver -{ -namespace Variable +namespace Antares::Solver::Variable { State::State(Data::Study& s) : hourInTheSimulation(0u), @@ -50,8 +46,6 @@ State::State(Data::Study& s) : averageOptimizationTime1(0.), averageOptimizationTime2(0.) { - h2oValueWorkVars.levelUp = 0.; - h2oValueWorkVars.levelDown = 0.; } void State::initFromThermalClusterIndex(const uint clusterAreaWideIndex, uint numSpace) @@ -515,6 +509,4 @@ void State::yearEndBuildFromThermalClusterIndex(const uint clusterAreaWideIndex, } } -} // namespace Variable -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Variable diff --git a/src/solver/variable/state.h b/src/solver/variable/state.h index 62a7f6d96a..e2b983c84b 100644 --- a/src/solver/variable/state.h +++ b/src/solver/variable/state.h @@ -34,11 +34,7 @@ #include "../simulation/sim_structure_probleme_economique.h" #include "../simulation/sim_extern_variables_globales.h" -namespace Antares -{ -namespace Solver -{ -namespace Variable +namespace Antares::Solver::Variable { class State { @@ -240,9 +236,6 @@ class State */ bool simplexHasBeenRan; - // Working variable for output water values computation - Antares::Data::h2oValueWorkVarsType h2oValueWorkVars; - // Annual costs to be printed in output into separate files // ----------------------------------------------------------------- // Sum over all year's hours of : @@ -262,9 +255,7 @@ class State // ----------------------------------------------------------------- }; // class State -} // namespace Variable -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver::Variable #include "state.hxx" diff --git a/src/tests/src/solver/optimisation/adequacy_patch.cpp b/src/tests/src/solver/optimisation/adequacy_patch.cpp index 0b8bf48a50..adeff96a24 100644 --- a/src/tests/src/solver/optimisation/adequacy_patch.cpp +++ b/src/tests/src/solver/optimisation/adequacy_patch.cpp @@ -4,7 +4,8 @@ #include -#include "adequacy_patch.h" +#include "adequacy_patch_local_matching/adq_patch_local_matching.h" +#include "adequacy_patch_csr/adq_patch_curtailment_sharing.h" #include #include @@ -24,11 +25,11 @@ std::pair setNTCboundsForOneTimeStep(AdequacyPatchMode originTyp bool SetNTCOutsideToInsideToZero) { PROBLEME_HEBDO problem; - problem.adequacyPatchRuntimeData.originAreaType.resize(1); - problem.adequacyPatchRuntimeData.extremityAreaType.resize(1); + problem.adequacyPatchRuntimeData.originAreaMode.resize(1); + problem.adequacyPatchRuntimeData.extremityAreaMode.resize(1); - problem.adequacyPatchRuntimeData.originAreaType[0] = originType; - problem.adequacyPatchRuntimeData.extremityAreaType[0] = extremityType; + problem.adequacyPatchRuntimeData.originAreaMode[0] = originType; + problem.adequacyPatchRuntimeData.extremityAreaMode[0] = extremityType; problem.adqPatchParams = std::unique_ptr(new AdequacyPatchParameters()); auto& adqPatchParams = problem.adqPatchParams; @@ -44,11 +45,83 @@ std::pair setNTCboundsForOneTimeStep(AdequacyPatchMode originTyp double Xmin; double Xmax; - setBoundsAdqPatch(Xmax, Xmin, &ValeursDeNTC, 0, &problem); + setNTCbounds(Xmax, Xmin, &ValeursDeNTC, 0, &problem); return std::make_pair(Xmin, Xmax); } +static const double flowArea0toArea1_positive = 10; +static const double flowArea0toArea1_negative = -10; +static const double flowArea2toArea0_positive = 30; +static const double flowArea2toArea0_negative = -30; +static const double positiveEnsInit = 50.0; + +std::pair calculateAreaFlowBalanceForOneTimeStep( + double ensInit, + bool includeFlowsOutsideAdqPatchToDensNew, + AdequacyPatchMode Area1Mode, + AdequacyPatchMode Area2Mode, + double flowToArea1, + double flowFromArea2) +{ + PROBLEME_HEBDO problem; + int Area = 0; + uint hour = 0; + + // allocate memory + problem.adequacyPatchRuntimeData.originAreaMode.resize(3); + problem.adequacyPatchRuntimeData.extremityAreaMode.resize(3); + + problem.adqPatchParams = std::make_unique(); + const auto& adqPatchParams = problem.adqPatchParams; + + problem.ResultatsHoraires = new RESULTATS_HORAIRES*; + problem.ResultatsHoraires[0] = new RESULTATS_HORAIRES; + problem.ResultatsHoraires[0]->ValeursHorairesDeDefaillancePositive = new double; + problem.ValeursDeNTC = new VALEURS_DE_NTC_ET_RESISTANCES*; + problem.ValeursDeNTC[0] = new VALEURS_DE_NTC_ET_RESISTANCES; + problem.ValeursDeNTC[0]->ValeurDuFlux = new double[3]; + problem.IndexSuivantIntercoOrigine = new int[3]; + problem.IndexSuivantIntercoExtremite = new int[3]; + problem.IndexDebutIntercoOrigine = new int[1]; + problem.IndexDebutIntercoExtremite = new int[1]; + + // input values + adqPatchParams->SetNTCOutsideToInsideToZero = !includeFlowsOutsideAdqPatchToDensNew; + problem.ResultatsHoraires[Area]->ValeursHorairesDeDefaillancePositive[hour] = ensInit; + int Interco = 1; + problem.IndexDebutIntercoOrigine[Area] = Interco; + problem.adequacyPatchRuntimeData.extremityAreaMode[Interco] = Area1Mode; + problem.ValeursDeNTC[hour]->ValeurDuFlux[Interco] = flowToArea1; + problem.IndexSuivantIntercoOrigine[Interco] = -1; + + Interco = 2; + problem.IndexDebutIntercoExtremite[Area] = Interco; + problem.adequacyPatchRuntimeData.originAreaMode[Interco] = Area2Mode; + problem.ValeursDeNTC[hour]->ValeurDuFlux[Interco] = flowFromArea2; + problem.IndexSuivantIntercoExtremite[Interco] = -1; + + // get results + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew, std::ignore) = calculateAreaFlowBalance(&problem, Area, hour); + + // free memory + delete[] problem.IndexDebutIntercoExtremite; + delete[] problem.IndexSuivantIntercoExtremite; + delete[] problem.IndexDebutIntercoOrigine; + delete[] problem.IndexSuivantIntercoOrigine; + delete[] problem.ValeursDeNTC[0]->ValeurDuFlux; + delete problem.ValeursDeNTC[0]; + delete problem.ValeursDeNTC; + delete problem.ResultatsHoraires[0]->ValeursHorairesDeDefaillancePositive; + delete problem.ResultatsHoraires[0]; + delete problem.ResultatsHoraires; + + // return + return std::make_pair(netPositionInit, densNew); +} + // Virtual -> Virtual (0 -> 0) // No change in bounds is expected BOOST_AUTO_TEST_CASE(setNTCboundsForOneTimeStep_virtual_virtual_no_change_expected) @@ -56,8 +129,8 @@ BOOST_AUTO_TEST_CASE(setNTCboundsForOneTimeStep_virtual_virtual_no_change_expect double Xmin, Xmax; std::tie(Xmin, Xmax) = setNTCboundsForOneTimeStep( virtualArea, virtualArea, true /*SetNTCOutsideToOutsideToZero*/, false); - BOOST_TEST(Xmax == origineExtremite); - BOOST_TEST(Xmin == -extremiteOrigine); + BOOST_CHECK_EQUAL(Xmax, origineExtremite); + BOOST_CHECK_EQUAL(Xmin, -extremiteOrigine); } // Virtual -> physical area inside adq-patch (0 -> 2) @@ -67,8 +140,8 @@ BOOST_AUTO_TEST_CASE(setNTCboundsForOneTimeStep_virtual_inside_no_change_expecte double Xmin, Xmax; std::tie(Xmin, Xmax) = setNTCboundsForOneTimeStep( virtualArea, physicalAreaInsideAdqPatch, true /*SetNTCOutsideToOutsideToZero*/, false); - BOOST_TEST(Xmax == origineExtremite); - BOOST_TEST(Xmin == -extremiteOrigine); + BOOST_CHECK_EQUAL(Xmax, origineExtremite); + BOOST_CHECK_EQUAL(Xmin, -extremiteOrigine); } // Virtual -> physical area outside adq-patch (0 -> 1) @@ -78,8 +151,8 @@ BOOST_AUTO_TEST_CASE(setNTCboundsForOneTimeStep_virtual_outside_no_change_expect double Xmin, Xmax; std::tie(Xmin, Xmax) = setNTCboundsForOneTimeStep( virtualArea, physicalAreaOutsideAdqPatch, true /*SetNTCOutsideToOutsideToZero*/, false); - BOOST_TEST(Xmax == origineExtremite); - BOOST_TEST(Xmin == -extremiteOrigine); + BOOST_CHECK_EQUAL(Xmax, origineExtremite); + BOOST_CHECK_EQUAL(Xmin, -extremiteOrigine); } // physical area outside adq-patch -> physical area outside adq-patch (1 -> 1) @@ -91,8 +164,8 @@ BOOST_AUTO_TEST_CASE(setNTCboundsForOneTimeStep_outside_outside_zero_expected_bo physicalAreaOutsideAdqPatch, true /*SetNTCOutsideToOutsideToZero*/, false); - BOOST_TEST(Xmax == 0); - BOOST_TEST(Xmin == 0); + BOOST_CHECK_EQUAL(Xmax, 0); + BOOST_CHECK_EQUAL(Xmin, 0); } // physical area outside adq-patch -> physical area outside adq-patch (1 -> 1) @@ -104,8 +177,8 @@ BOOST_AUTO_TEST_CASE(setNTCboundsForOneTimeStep_outside_outside_no_change_expect std::tie(Xmin, Xmax) = setNTCboundsForOneTimeStep( physicalAreaOutsideAdqPatch, physicalAreaOutsideAdqPatch, false, false); - BOOST_TEST(Xmax == origineExtremite); - BOOST_TEST(Xmin == -extremiteOrigine); + BOOST_CHECK_EQUAL(Xmax, origineExtremite); + BOOST_CHECK_EQUAL(Xmin, -extremiteOrigine); } // physical area inside adq-patch -> physical area outside adq-patch (2 -> 1) @@ -115,8 +188,8 @@ BOOST_AUTO_TEST_CASE(setNTCboundsForOneTimeStep_inside_outside_zero_expected_bot double Xmin, Xmax; std::tie(Xmin, Xmax) = setNTCboundsForOneTimeStep( physicalAreaInsideAdqPatch, physicalAreaOutsideAdqPatch, false, false); - BOOST_TEST(Xmax == 0); - BOOST_TEST(Xmin == 0); + BOOST_CHECK_EQUAL(Xmax, 0); + BOOST_CHECK_EQUAL(Xmin, 0); } // physical area outside adq-patch -> physical area inside adq-patch (1 -> 2) @@ -128,8 +201,8 @@ BOOST_AUTO_TEST_CASE(setNTCboundsForOneTimeStep_outside_inside_zero_expected_bot physicalAreaInsideAdqPatch, false, true /*SetNTCOutsideToInsideToZero*/); - BOOST_TEST(Xmax == 0); - BOOST_TEST(Xmin == 0); + BOOST_CHECK_EQUAL(Xmax, 0); + BOOST_CHECK_EQUAL(Xmin, 0); } // physical area outside adq-patch -> physical area inside adq-patch (1 -> 2) @@ -140,6 +213,269 @@ BOOST_AUTO_TEST_CASE(setNTCboundsForOneTimeStep_outside_inside_change_expected_o double Xmin, Xmax; std::tie(Xmin, Xmax) = setNTCboundsForOneTimeStep( physicalAreaOutsideAdqPatch, physicalAreaInsideAdqPatch, false, false); - BOOST_TEST(Xmax == origineExtremite); - BOOST_TEST(Xmin == 0); + BOOST_CHECK_EQUAL(Xmax, origineExtremite); + BOOST_CHECK_EQUAL(Xmin, 0); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 virtual-area, and Area2-virtual area +// flow from Area0 -> Area1 is positive +// flow from Area2 -> Area0 is positive +// DensNew parameter should NOT include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE( + calculateAreaFlowBalanceForOneTimeStep_virtual_virtual_NotIncludeOut_positiveFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) = calculateAreaFlowBalanceForOneTimeStep( + 0.0, false, virtualArea, virtualArea, flowArea0toArea1_positive, flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(netPositionInit, 0.0); + BOOST_CHECK_EQUAL(densNew, 0.0); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area inside adq-patch, and Area2-virtual area +// flow from Area0 -> Area1 is positive +// flow from Area2 -> Area0 is positive +// DensNew parameter should NOT include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE( + calculateAreaFlowBalanceForOneTimeStep_inside_virtual_NotIncludeOut_positiveFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(0.0, + false, + physicalAreaInsideAdqPatch, + virtualArea, + flowArea0toArea1_positive, + flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(netPositionInit, -flowArea0toArea1_positive); + BOOST_CHECK_EQUAL(densNew, 0.0); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area inside adq-patch, and Area2-virtual area +// flow from Area0 -> Area1 is positive +// flow from Area2 -> Area0 is positive +// DensNew parameter should NOT include flows from areas outside adq patch +// ensInit = 50.0 +BOOST_AUTO_TEST_CASE( + calculateAreaFlowBalanceForOneTimeStep_inside_virtual_NotIncludeOut_positiveFlow_ensInitGraterThanZero) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(positiveEnsInit, + false, + physicalAreaInsideAdqPatch, + virtualArea, + flowArea0toArea1_positive, + flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(netPositionInit, -flowArea0toArea1_positive); + BOOST_CHECK_EQUAL(densNew, positiveEnsInit-flowArea0toArea1_positive); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area inside adq-patch, and Area2 physical area outside adq-patch +// flow from Area0 -> Area1 is positive +// flow from Area2 -> Area0 is positive +// DensNew parameter should NOT include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE( + calculateAreaFlowBalanceForOneTimeStep_inside_outside_NotIncludeOut_positiveFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(0.0, + false, + physicalAreaInsideAdqPatch, + physicalAreaOutsideAdqPatch, + flowArea0toArea1_positive, + flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(netPositionInit, -flowArea0toArea1_positive); + BOOST_CHECK_EQUAL(densNew, 0.0); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area inside adq-patch, and Area2 physical area inside adq-patch +// flow from Area0 -> Area1 is positive +// flow from Area2 -> Area0 is positive +// DensNew parameter should NOT include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE( + calculateAreaFlowBalanceForOneTimeStep_inside_inside_NotIncludeOut_positiveFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(0.0, + false, + physicalAreaInsideAdqPatch, + physicalAreaInsideAdqPatch, + flowArea0toArea1_positive, + flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(netPositionInit, -flowArea0toArea1_positive + flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(densNew, -flowArea0toArea1_positive + flowArea2toArea0_positive); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area inside adq-patch, and Area2 physical area outside adq-patch +// flow from Area0 -> Area1 is positive +// flow from Area2 -> Area0 is positive +// DensNew parameter SHOULD include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE(calculateAreaFlowBalanceForOneTimeStep_inside_outside_IncludeOut_positiveFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(0.0, + true, + physicalAreaInsideAdqPatch, + physicalAreaOutsideAdqPatch, + flowArea0toArea1_positive, + flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(netPositionInit, -flowArea0toArea1_positive); + BOOST_CHECK_EQUAL(densNew, -flowArea0toArea1_positive + flowArea2toArea0_positive); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area outside adq-patch, and Area2 physical area outside adq-patch +// flow from Area0 -> Area1 is positive +// flow from Area2 -> Area0 is positive +// DensNew parameter SHOULD include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE(calculateAreaFlowBalanceForOneTimeStep_outside_outside_IncludeOut_positiveFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(0.0, + true, + physicalAreaOutsideAdqPatch, + physicalAreaOutsideAdqPatch, + flowArea0toArea1_positive, + flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(netPositionInit, 0.0); + BOOST_CHECK_EQUAL(densNew, flowArea2toArea0_positive); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area outside adq-patch, and Area2 physical area inside adq-patch +// flow from Area0 -> Area1 is positive +// flow from Area2 -> Area0 is positive +// DensNew parameter SHOULD include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE(calculateAreaFlowBalanceForOneTimeStep_outside_inside_IncludeOut_positiveFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(0.0, + true, + physicalAreaOutsideAdqPatch, + physicalAreaInsideAdqPatch, + flowArea0toArea1_positive, + flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(netPositionInit, +flowArea2toArea0_positive); + BOOST_CHECK_EQUAL(densNew, +flowArea2toArea0_positive); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area inside adq-patch, and Area2 physical area outside adq-patch +// flow from Area0 -> Area1 is negative +// flow from Area2 -> Area0 is negative +// DensNew parameter SHOULD include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE(calculateAreaFlowBalanceForOneTimeStep_inside_outside_IncludeOut_negativeFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(0.0, + true, + physicalAreaInsideAdqPatch, + physicalAreaOutsideAdqPatch, + flowArea0toArea1_negative, + flowArea2toArea0_negative); + BOOST_CHECK_EQUAL(netPositionInit, -flowArea0toArea1_negative); + BOOST_CHECK_EQUAL(densNew, -flowArea0toArea1_negative); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area outside adq-patch, and Area2 physical area outside adq-patch +// flow from Area0 -> Area1 is negative +// flow from Area2 -> Area0 is negative +// DensNew parameter SHOULD include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE(calculateAreaFlowBalanceForOneTimeStep_outside_outside_IncludeOut_negativeFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(0.0, + true, + physicalAreaOutsideAdqPatch, + physicalAreaOutsideAdqPatch, + flowArea0toArea1_negative, + flowArea2toArea0_negative); + BOOST_CHECK_EQUAL(netPositionInit, 0.0); + BOOST_CHECK_EQUAL(densNew, -flowArea0toArea1_negative); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area outside adq-patch, and Area2 physical area inside adq-patch +// flow from Area0 -> Area1 is negative +// flow from Area2 -> Area0 is negative +// DensNew parameter SHOULD include flows from areas outside adq patch +BOOST_AUTO_TEST_CASE(calculateAreaFlowBalanceForOneTimeStep_outside_inside_IncludeOut_negativeFlow) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(0.0, + true, + physicalAreaOutsideAdqPatch, + physicalAreaInsideAdqPatch, + flowArea0toArea1_negative, + flowArea2toArea0_negative); + BOOST_CHECK_EQUAL(netPositionInit, flowArea2toArea0_negative); + BOOST_CHECK_EQUAL(densNew, 0.0); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area inside adq-patch, and Area2 physical area inside adq-patch +// flow from Area0 -> Area1 is positiive +// flow from Area2 -> Area0 is negative +// DensNew parameter SHOULD include flows from areas outside adq patch +// ensInit = 50.0 +BOOST_AUTO_TEST_CASE(calculateAreaFlowBalanceForOneTimeStep_outside_inside_IncludeOut_negativeFlow_initEnsEqualTo50) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(positiveEnsInit, + true, + physicalAreaInsideAdqPatch, + physicalAreaInsideAdqPatch, + flowArea0toArea1_positive, + flowArea2toArea0_negative); + BOOST_CHECK_EQUAL(netPositionInit, -flowArea0toArea1_positive + flowArea2toArea0_negative); + BOOST_CHECK_EQUAL(densNew, positiveEnsInit+netPositionInit); +} + +// Area 0 is physical area inside adq-patch connected to two areas: +// Area1 physical area inside adq-patch, and Area2 physical area inside adq-patch +// flow from Area0 -> Area1 is positiive +// flow from Area2 -> Area0 is negative +// DensNew parameter SHOULD include flows from areas outside adq patch +// ensInit = 2.0 +BOOST_AUTO_TEST_CASE(calculateAreaFlowBalanceForOneTimeStep_outside_inside_IncludeOut_negativeFlow_initEnsEqualTo0) +{ + double netPositionInit; + double densNew; + std::tie(netPositionInit, densNew) + = calculateAreaFlowBalanceForOneTimeStep(2.0, + true, + physicalAreaInsideAdqPatch, + physicalAreaInsideAdqPatch, + flowArea0toArea1_positive, + flowArea2toArea0_negative); + BOOST_CHECK_EQUAL(netPositionInit, -flowArea0toArea1_positive + flowArea2toArea0_negative); + BOOST_CHECK_EQUAL(densNew, 0.0); } diff --git a/src/ui/simulator/application/main/internal-ids.h b/src/ui/simulator/application/main/internal-ids.h index 0680f4d712..643beb7db0 100644 --- a/src/ui/simulator/application/main/internal-ids.h +++ b/src/ui/simulator/application/main/internal-ids.h @@ -134,6 +134,9 @@ enum MenusID mnIDOptionConfigureMCScenarioPlaylist, mnIDOptionOptimizationPrefs, mnIDOptionAdvanced, + mnIDOptionAdequacyPatchOptions, + mnIDOptionAdequacyPatchAreas, + //@} //! \name Window diff --git a/src/ui/simulator/application/main/main.cpp b/src/ui/simulator/application/main/main.cpp index f104c2156f..f73a3a80ed 100644 --- a/src/ui/simulator/application/main/main.cpp +++ b/src/ui/simulator/application/main/main.cpp @@ -159,6 +159,8 @@ EVT_MENU(mnIDOptionConfigureMCScenarioPlaylist, ApplWnd::evtOnOptionsMCPlaylist) EVT_MENU(mnIDOptionConfigureMCScenarioBuilder, ApplWnd::evtOnOptionsMCScenarioBuilder) EVT_MENU(mnIDOptionOptimizationPrefs, ApplWnd::evtOnOptionsOptimizationPrefs) EVT_MENU(mnIDOptionAdvanced, ApplWnd::evtOnOptionsAdvanced) +EVT_MENU(mnIDOptionAdequacyPatchOptions, ApplWnd::evtOnOptionsAdequacyPatchOptions) +EVT_MENU(mnIDOptionAdequacyPatchAreas, ApplWnd::evtOnOptionsAdequacyPatchAreas) // Window EVT_MENU(mnIDFullscreen, ApplWnd::evtOnFullscreen) @@ -219,6 +221,7 @@ ApplWnd::ApplWnd() : pMenuSimulation(nullptr), pMenuOptions(nullptr), pMenuGeographicTrimming(nullptr), + pMenuAdequacyPatch(nullptr), pMenuWindow(nullptr), pMenuTools(nullptr), pMenuHelp(nullptr), @@ -463,6 +466,8 @@ void ApplWnd::evtOnUpdateGUIAfterStudyIO(bool opened) EnableItem(menu, mnIDOptionConfigureMCScenarioPlaylist, opened); EnableItem(menu, mnIDOptionOptimizationPrefs, opened); EnableItem(menu, mnIDOptionAdvanced, opened); + EnableItem(menu, mnIDOptionAdequacyPatchOptions, opened); + EnableItem(menu, mnIDOptionAdequacyPatchAreas, opened); EnableItem(menu, mnIDInspector, opened); diff --git a/src/ui/simulator/application/main/main.h b/src/ui/simulator/application/main/main.h index 54d40c2069..bfcbe90084 100644 --- a/src/ui/simulator/application/main/main.h +++ b/src/ui/simulator/application/main/main.h @@ -521,6 +521,10 @@ class ApplWnd final : public Component::Frame::WxLocalFrame, public Yuni::IEvent void evtOnOptionsOptimizationPrefs(wxCommandEvent& evt); //! Advanced parameters void evtOnOptionsAdvanced(wxCommandEvent& evt); + //! Adequacy Patch Configure + void evtOnOptionsAdequacyPatchOptions(wxCommandEvent& evt); + //! Adequacy Patch Areas + void evtOnOptionsAdequacyPatchAreas(wxCommandEvent& evt); //@} //! \name Event: Menu: Window @@ -634,6 +638,8 @@ class ApplWnd final : public Component::Frame::WxLocalFrame, public Yuni::IEvent wxMenu* pMenuOptions; //! SubMenu: Options > Geographic trimming wxMenuItem* pMenuGeographicTrimming; + //! SubMenu: Options > Adequacy Patch + wxMenuItem* pMenuAdequacyPatch; //! Menu: Window wxMenu* pMenuWindow; //! Menu: Tools diff --git a/src/ui/simulator/application/main/menu.cpp b/src/ui/simulator/application/main/menu.cpp index f04698f533..d996c659fd 100644 --- a/src/ui/simulator/application/main/menu.cpp +++ b/src/ui/simulator/application/main/menu.cpp @@ -447,6 +447,23 @@ wxMenu* ApplWnd::createMenuOptions() wxT("Advanced parameters"), "images/16x16/empty.png", wxT("Set advanced parameters")); + + delete pMenuAdequacyPatch; + pMenuAdequacyPatch + = pMenuOptions->AppendSubMenu(new wxMenu(), wxT("Adequacy Patch...")); + + wxMenu* adqPatchSubMenu = pMenuAdequacyPatch->GetSubMenu(); + Menu::CreateItem(adqPatchSubMenu, + mnIDOptionAdequacyPatchOptions, + wxT("Options"), + "images/16x16/filter.png", + wxT("Adequacy Patch Options")); + Menu::CreateItem(adqPatchSubMenu, + mnIDOptionAdequacyPatchAreas, + wxT("Areas"), + "images/16x16/filter.png", + wxT("Adequacy Patch Areas")); + it->Enable(false); return pMenuOptions; diff --git a/src/ui/simulator/application/main/options.cpp b/src/ui/simulator/application/main/options.cpp index c3b3c05ba0..4f52f51864 100644 --- a/src/ui/simulator/application/main/options.cpp +++ b/src/ui/simulator/application/main/options.cpp @@ -32,6 +32,8 @@ #include "../../windows/options/select-output/select-output.h" #include "../../windows/options/playlist/playlist.h" #include "../../windows/options/optimization/optimization.h" +#include "../../windows/options/adequacy-patch/adequacy-patch-options.h" +#include "../../windows/options/adequacy-patch/adequacy-patch-areas.h" #include "../../windows/options/advanced/advanced.h" #include "../../windows/message.h" @@ -124,5 +126,19 @@ void ApplWnd::evtOnOptionsAdvanced(wxCommandEvent&) Dispatcher::GUI::CreateAndShowModal(this); } +void ApplWnd::evtOnOptionsAdequacyPatchOptions(wxCommandEvent&) +{ + Forms::Disabler disabler(*this); + if (Data::Study::Current::Valid()) + Dispatcher::GUI::CreateAndShowModal(this); +} + +void ApplWnd::evtOnOptionsAdequacyPatchAreas(wxCommandEvent&) +{ + Forms::Disabler disabler(*this); + if (Data::Study::Current::Valid()) + Dispatcher::GUI::CreateAndShowModal(this); +} + } // namespace Forms } // namespace Antares diff --git a/src/ui/simulator/cmake/components.cmake b/src/ui/simulator/cmake/components.cmake index c0cb395626..2b7c0119dd 100644 --- a/src/ui/simulator/cmake/components.cmake +++ b/src/ui/simulator/cmake/components.cmake @@ -48,6 +48,8 @@ SET(SRC_TOOLBOX_COM_DBGRID_RENDERERS toolbox/components/datagrid/renderer.h toolbox/components/datagrid/renderer.hxx toolbox/components/datagrid/renderer.cpp + toolbox/components/datagrid/renderer/adequacy-patch-area-grid.h + toolbox/components/datagrid/renderer/adequacy-patch-area-grid.cpp toolbox/components/datagrid/renderer/area.h toolbox/components/datagrid/renderer/area.cpp toolbox/components/datagrid/renderer/analyzer/areas.h diff --git a/src/ui/simulator/cmake/windows-options.cmake b/src/ui/simulator/cmake/windows-options.cmake index e8aef3bfc6..10d4a08441 100644 --- a/src/ui/simulator/cmake/windows-options.cmake +++ b/src/ui/simulator/cmake/windows-options.cmake @@ -10,6 +10,10 @@ set(SRC_UI_WINDOWS_OPTIONS windows/options/select-output/select-output.cpp windows/options/playlist/playlist.h windows/options/playlist/playlist.cpp + windows/options/adequacy-patch/adequacy-patch-options.h + windows/options/adequacy-patch/adequacy-patch-options.cpp + windows/options/adequacy-patch/adequacy-patch-areas.h + windows/options/adequacy-patch/adequacy-patch-areas.cpp windows/options/optimization/optimization.h windows/options/optimization/optimization.cpp windows/options/advanced/advanced.h diff --git a/src/ui/simulator/toolbox/components/datagrid/gridhelper.cpp b/src/ui/simulator/toolbox/components/datagrid/gridhelper.cpp index 0bcc59c9f8..0fc11ab286 100644 --- a/src/ui/simulator/toolbox/components/datagrid/gridhelper.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/gridhelper.cpp @@ -199,6 +199,20 @@ class GridCellAttrProvider final : public wxGridCellAttrProvider pStyles[CellStyle::cellStyleFilterUndefined]->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE); } + // Adequacy patch areas + { + pStyles[CellStyle::cellStyleAdqPatchVirtual]->SetAlignment(wxALIGN_CENTRE, + wxALIGN_CENTRE); + pStyles[CellStyle::cellStyleAdqPatchVirtual]->SetTextColour(wxColour(0, 0, 0)); + + pStyles[CellStyle::cellStyleAdqPatchOutside]->SetAlignment(wxALIGN_CENTRE, + wxALIGN_CENTRE); + pStyles[CellStyle::cellStyleAdqPatchOutside]->SetTextColour(wxColour(204, 51, 0)); + + pStyles[CellStyle::cellStyleAdqPatchInside]->SetAlignment(wxALIGN_CENTRE, + wxALIGN_CENTRE); + pStyles[CellStyle::cellStyleAdqPatchInside]->SetTextColour(wxColour(0, 128, 0)); + } } virtual ~GridCellAttrProvider() @@ -302,6 +316,9 @@ class GridCellAttrProvider final : public wxGridCellAttrProvider internalAppendCSSCode(s, CellStyle::cellStyleFilterSynthesisOn); internalAppendCSSCode(s, CellStyle::cellStyleFilterSynthesisOff); internalAppendCSSCode(s, CellStyle::cellStyleFilterUndefined); + internalAppendCSSCode(s, CellStyle::cellStyleAdqPatchVirtual); + internalAppendCSSCode(s, CellStyle::cellStyleAdqPatchOutside); + internalAppendCSSCode(s, CellStyle::cellStyleAdqPatchInside); } void appendCSSForAllCellStyles2(Yuni::String& s) @@ -338,6 +355,9 @@ class GridCellAttrProvider final : public wxGridCellAttrProvider internalAppendCSSCode(s, CellStyle::cellStyleFilterSynthesisOn); internalAppendCSSCode(s, CellStyle::cellStyleFilterSynthesisOff); internalAppendCSSCode(s, CellStyle::cellStyleFilterUndefined); + internalAppendCSSCode(s, CellStyle::cellStyleAdqPatchVirtual); + internalAppendCSSCode(s, CellStyle::cellStyleAdqPatchOutside); + internalAppendCSSCode(s, CellStyle::cellStyleAdqPatchInside); } private: diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer.h b/src/ui/simulator/toolbox/components/datagrid/renderer.h index 785237679b..482af89d23 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer.h @@ -88,6 +88,10 @@ class IRenderer : public Yuni::IEventObserver cellStyleFilterSynthesisOn, cellStyleFilterSynthesisOff, cellStyleFilterUndefined, + cellStyleAdqPatchVirtual, + cellStyleAdqPatchOutside, + cellStyleAdqPatchInside, + cellStyleMax /* Max items in the list */ }; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/adequacy-patch-area-grid.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/adequacy-patch-area-grid.cpp new file mode 100644 index 0000000000..32c5bbc4d5 --- /dev/null +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/adequacy-patch-area-grid.cpp @@ -0,0 +1,155 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "adequacy-patch-area-grid.h" +#include + +using namespace Yuni; + +namespace Antares::Component::Datagrid::Renderer +{ +AdequacyPatchAreaGrid::AdequacyPatchAreaGrid() : pControl(nullptr) +{ +} + +AdequacyPatchAreaGrid::~AdequacyPatchAreaGrid() = default; + +bool AdequacyPatchAreaGrid::valid() const +{ + if (!study) + std::cout << "not valid ! \n"; + return !(!study); +} + +int AdequacyPatchAreaGrid::height() const +{ + return (!study) ? 0 : gridSize(); +} + +wxString AdequacyPatchAreaGrid::columnCaption(int) const +{ + return wxT(" Adequacy Patch Area \n Mode "); +} + +wxString AdequacyPatchAreaGrid::rowCaption(int rowIndx) const +{ + return (!(!study) && (uint)rowIndx < gridSize()) + ? wxStringFromUTF8(study->areas.byIndex[rowIndx]->name) + : wxString(); +} + +bool AdequacyPatchAreaGrid::cellValue(int, int row, const Yuni::String& value) +{ + if (!(!study) && (uint)row < gridSize()) + { + String s = value; + s.trim(); + s.toLower(); + + bool vir = s == "0" || s == "virtual" || s == "v"; + bool ins = s.to() == 2 || s == "inside" || s == "i"; + + if (vir) + study->areas.byIndex[row]->adequacyPatchMode = Data::AdequacyPatch::virtualArea; + else if (ins) + study->areas.byIndex[row]->adequacyPatchMode + = Data::AdequacyPatch::physicalAreaInsideAdqPatch; + else + study->areas.byIndex[row]->adequacyPatchMode + = Data::AdequacyPatch::physicalAreaOutsideAdqPatch; + + onTriggerUpdate(); + Dispatcher::GUI::Refresh(pControl); + return true; + } + return false; +} + +double AdequacyPatchAreaGrid::cellNumericValue(int, int row) const +{ + if (!(!study) && (uint)row < gridSize()) + { + assert(gridSize() != 0); + // for saving into *.txt file + switch (study->areas.byIndex[row]->adequacyPatchMode) + { + case Data::AdequacyPatch::virtualArea: + return 0.; + case Data::AdequacyPatch::physicalAreaOutsideAdqPatch: + return 1.; + case Data::AdequacyPatch::physicalAreaInsideAdqPatch: + return 2.; + default: + return 0.; + } + } + return 0.; +} + +wxString AdequacyPatchAreaGrid::cellValue(int, int row) const +{ + if (!(!study) && (uint)row < gridSize()) + { + switch (study->areas.byIndex[row]->adequacyPatchMode) + { + case Data::AdequacyPatch::virtualArea: + return wxT("virtual"); + case Data::AdequacyPatch::physicalAreaOutsideAdqPatch: + return wxT("outside"); + case Data::AdequacyPatch::physicalAreaInsideAdqPatch: + return wxT("inside"); + default: + return wxEmptyString; + } + } + return wxEmptyString; +} + +uint AdequacyPatchAreaGrid::gridSize() const +{ + return study->areas.size(); +} + +IRenderer::CellStyle AdequacyPatchAreaGrid::cellStyle(int, int row) const +{ + if (!(!study) && (uint)row < gridSize()) + { + switch (study->areas.byIndex[row]->adequacyPatchMode) + { + case Data::AdequacyPatch::virtualArea: + return IRenderer::cellStyleAdqPatchVirtual; + case Data::AdequacyPatch::physicalAreaOutsideAdqPatch: + return IRenderer::cellStyleAdqPatchOutside; + case Data::AdequacyPatch::physicalAreaInsideAdqPatch: + return IRenderer::cellStyleAdqPatchInside; + default: + return IRenderer::cellStyleConstraintNoWeight; + } + } + return IRenderer::cellStyleConstraintNoWeight; +} +} diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/adequacy-patch-area-grid.h b/src/ui/simulator/toolbox/components/datagrid/renderer/adequacy-patch-area-grid.h new file mode 100644 index 0000000000..7c6f14770c --- /dev/null +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/adequacy-patch-area-grid.h @@ -0,0 +1,89 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#ifndef __ANTARES_TOOLBOX_COMPONENT_DATAGRID_RENDERER_ADEQUACY_PATCH_AREAS_GRID_H__ +#define __ANTARES_TOOLBOX_COMPONENT_DATAGRID_RENDERER_ADEQUACY_PATCH_AREAS_GRID_H__ + +#include +#include "../renderer.h" +#include "../../../../application/study.h" + +namespace Antares::Component::Datagrid::Renderer +{ +class AdequacyPatchAreaGrid : public IRenderer +{ +public: + AdequacyPatchAreaGrid(); + ~AdequacyPatchAreaGrid() override; + + int width() const override + { + return 1; + } + virtual uint gridSize() const; + + virtual int height() const; + + virtual wxString columnCaption(int colIndx) const; + + virtual wxString rowCaption(int rowIndx) const; + + virtual wxString cellValue(int x, int y) const; + + virtual double cellNumericValue(int x, int y) const; + + virtual bool cellValue(int x, int y, const Yuni::String& value); + + void resetColors(int, int, wxColour&, wxColour&) const override + { + // Do nothing + } + + virtual bool valid() const; + + uint maxWidthResize() const override + { + return 0; + } + IRenderer::CellStyle cellStyle(int col, int row) const override; + + void control(wxWindow* control) + { + pControl = control; + } + + //! An item has been updated + Yuni::Bind onTriggerUpdate; + +private: + wxWindow* pControl; + +}; // class AdequacyPatchAreaGrid + +} + +#endif // __ANTARES_TOOLBOX_COMPONENT_DATAGRID_RENDERER_ADEQUACY_PATCH_AREAS_GRID_H__ diff --git a/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-areas.cpp b/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-areas.cpp new file mode 100644 index 0000000000..6d1936b23e --- /dev/null +++ b/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-areas.cpp @@ -0,0 +1,140 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "adequacy-patch-areas.h" +#include +#include +#include + +#include +#include "../../../toolbox/resources.h" +#include "../../../application/study.h" +#include "../../../application/main.h" +#include "../../../toolbox/resources.h" +#include "../../../toolbox/create.h" +#include "../../../application/wait.h" +#include "../../../toolbox/components/wizardheader.h" +#include "../../../toolbox/components/datagrid/renderer/adequacy-patch-area-grid.h" +#include "../../message.h" + +using namespace Yuni; + +namespace Antares::Window::Options +{ +BEGIN_EVENT_TABLE(AdequacyPatchAreas, wxDialog) +EVT_MOTION(AdequacyPatchAreas::mouseMoved) +END_EVENT_TABLE() + +AdequacyPatchAreas::AdequacyPatchAreas(wxFrame* parent) : + wxDialog(parent, + wxID_ANY, + wxT("Adequacy Patch Areas"), + wxDefaultPosition, + wxSize(380, 410), + wxCLOSE_BOX | wxCAPTION | wxRESIZE_BORDER) +{ + assert(parent); + + // The current study + auto study = Data::Study::Current::Get(); + + // Title of the Form + SetLabel(wxT("Adequacy Patch Areas")); + SetTitle(GetLabel()); + + auto* sizer = new wxBoxSizer(wxVERTICAL); + + // Header + sizer->Add( + Toolbox::Components::WizardHeader::Create(this, + wxT("Options"), + "images/32x32/orderedlist.png", + wxT("Configure areas mode for adequacy patch")), + 0, + wxALL | wxEXPAND | wxFIXED_MINSIZE); + + sizer->AddSpacer(20); + + // Panel + pPanel = new Component::Panel(this); + sizer->Add(pPanel, 1, wxALL | wxEXPAND | wxRESERVE_SPACE_EVEN_IF_HIDDEN); + + wxSizer* hz = new wxBoxSizer(wxHORIZONTAL); + wxSizer* rightSizer = new wxBoxSizer(wxVERTICAL); + wxButton* btn; + + // Datagrid + auto* renderer = new Component::Datagrid::Renderer::AdequacyPatchAreaGrid(); + renderer->study = study; + auto* grid + = new Component::Datagrid::Component(pPanel, renderer, wxEmptyString, false, true, true); + grid->SetBackgroundColour(GetBackgroundColour()); + pGrid = grid; + renderer->control(grid); + + hz->AddSpacer(13); + hz->Add(grid, 1, wxALL | wxEXPAND); + + hz->Add(rightSizer, 0, wxALL | wxEXPAND); + hz->AddSpacer(20); + pPanel->SetSizer(hz); + sizer->AddSpacer(5); + + sizer->Add(new wxStaticLine(this, wxID_ANY), 0, wxALL | wxEXPAND, 8); + + hz = new wxBoxSizer(wxHORIZONTAL); + btn = Component::CreateButton(this, wxT(" Close "), this, &AdequacyPatchAreas::onClose); + hz->AddStretchSpacer(); + hz->Add(btn, 0, wxEXPAND | wxALL); + hz->Add(20, 5); + sizer->Add(hz, 0, wxALL | wxEXPAND); + sizer->AddSpacer(8); + + sizer->Layout(); + SetSizer(sizer); + + // Recentre the window + Centre(wxBOTH); + + SetAutoLayout(true); + grid->forceRefresh(); +} + +AdequacyPatchAreas::~AdequacyPatchAreas() = default; + +void AdequacyPatchAreas::onClose(const void*) +{ + Dispatcher::GUI::Close(this); +} + +void AdequacyPatchAreas::mouseMoved(wxMouseEvent&) +{ + // Notify other components as well + Antares::Component::Panel::OnMouseMoveFromExternalComponent(); +} + +} diff --git a/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-areas.h b/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-areas.h new file mode 100644 index 0000000000..1712fc7aab --- /dev/null +++ b/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-areas.h @@ -0,0 +1,65 @@ +/* +** Copyright 2007-2023 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#ifndef __ANTARES_APPLICATION_WINDOWS_ADEQUACY_PATCH_AREAS_H__ +#define __ANTARES_APPLICATION_WINDOWS_ADEQUACY_PATCH_AREAS_H__ + +#include +#include "../../../toolbox/components/datagrid/component.h" +#include +#include + +namespace Antares::Window::Options +{ +class AdequacyPatchAreas final : public wxDialog +{ +public: + //! \name Constructor & Destructor + //@{ + /*! + ** \brief Default constructor + ** + ** \param parent The parent window + */ + explicit AdequacyPatchAreas(wxFrame* parent); + //! Destructor + ~AdequacyPatchAreas() override; + //@} + +private: + void mouseMoved(wxMouseEvent& evt); + void onClose(const void*); + + Component::Datagrid::Component* pGrid; + wxWindow* pPanel; + DECLARE_EVENT_TABLE() + +}; // class AdequacyPatchAreas + +} + +#endif // __ANTARES_APPLICATION_WINDOWS_ADEQUACY_PATCH_AREAS_H__ diff --git a/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-options.cpp b/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-options.cpp new file mode 100644 index 0000000000..857efe42e3 --- /dev/null +++ b/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-options.cpp @@ -0,0 +1,637 @@ +/* +** Copyright 2007-2018 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ + +#include "adequacy-patch-options.h" +#include +#include +#include +#include +#include "../../../toolbox/create.h" +#include "../../../toolbox/resources.h" +#include "../../../application/study.h" +#include "../../../application/menus.h" +#include "../../../windows/message.h" +#include +#include + +using namespace Yuni; +using namespace Data::AdequacyPatch; + +namespace Antares::Window::Options +{ +static void addLabelAdqPatch(wxWindow* parent, wxSizer* sizer, const wxChar* text) +{ + sizer->AddSpacer(25); + sizer->AddSpacer(25); + + auto* label = Component::CreateLabel(parent, text, true); + + sizer->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + sizer->AddSpacer(5); + sizer->AddSpacer(5); + sizer->AddSpacer(5); +} + +static void updateButton(Component::Button* button, bool value, std::string_view buttonType) +{ + char type; + if (buttonType == "ntc") + { + type = 'N'; + } + else + { + type = (buttonType == "pto") ? 'P' : 'S'; + } + + assert(button != NULL); + if (value) + { + switch (type) + { + case 'N': + button->image("images/16x16/light_orange.png"); + button->caption(wxT("set to null")); + break; + case 'P': + button->image("images/16x16/tag.png"); + button->caption(wxT("Load")); + break; + default: + button->image("images/16x16/light_green.png"); + button->caption(wxT("true")); + break; + } + } + else + { + switch (type) + { + case 'N': + button->image("images/16x16/light_green.png"); + button->caption(wxT("local values")); + break; + case 'P': + button->image("images/16x16/tag.png"); + button->caption(wxT("DENS")); + break; + default: + button->image("images/16x16/light_orange.png"); + button->caption(wxT("false")); + break; + } + } +} + +AdequacyPatchOptions::AdequacyPatchOptions(wxWindow* parent) : + wxDialog(parent, + wxID_ANY, + wxT("Adequacy Patch Options"), + wxDefaultPosition, + wxDefaultSize, + wxCLOSE_BOX | wxCAPTION | wxCLIP_CHILDREN), + pTargetRef(nullptr) +{ + assert(parent); + + // Title of the Form + SetLabel(wxT("Adequacy Patch Options")); + SetTitle(wxT("Adequacy Patch Options")); + + auto& study = *Data::Study::Current::Get(); + + // Background color + wxColour defaultBgColor = GetBackgroundColour(); + wxColour bgColor(255, 255, 255); + SetBackgroundColour(bgColor); + + auto* sizer = new wxBoxSizer(wxVERTICAL); + + auto* hz = new wxBoxSizer(wxHORIZONTAL); + hz->AddSpacer(6); + hz->Add(Resources::StaticBitmapLoadFromFile(this, wxID_ANY, "images/64x64/db.png"), + 0, + wxALL | wxALIGN_TOP | wxALIGN_CENTER); + hz->AddSpacer(35); + + auto* s = new wxFlexGridSizer(0, 2, 1, 10); + s->AddGrowableCol(0, 1); + hz->Add(s, 1, wxALL | wxEXPAND); + sizer->Add(hz, 0, wxALL | wxEXPAND, 20); + + wxStaticText* label; + Component::Button* button; + Yuni::Bind onPopup; + + { + label = Component::CreateLabel(this, wxT("Enable Adequacy patch")); + button = new Component::Button(this, wxT("true"), "images/16x16/light_green.png"); + button->SetBackgroundColour(bgColor); + button->menu(true); + onPopup.bind(this, + &AdequacyPatchOptions::onPopupMenuSpecify, + PopupInfo(study.parameters.adqPatch.enabled, wxT("true"))); + button->onPopupMenu(onPopup); + s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + s->Add(button, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pBtnAdequacyPatch = button; + } + // Transmission capacities (NTC) from physical areas outside adequacy patch (area type 1) to + // physical areas inside adequacy patch (area type 2). Used in the first step of adequacy patch + // local matching rule. + { + label = Component::CreateLabel( + this, wxT("NTC from physical areas outside to physical areas inside adequacy patch")); + button = new Component::Button(this, wxT("Day"), "images/16x16/light_green.png"); + button->SetBackgroundColour(bgColor); + button->menu(true); + onPopup.bind(this, + &AdequacyPatchOptions::onPopupMenuNTC, + PopupInfo(study.parameters.adqPatch.localMatching.setToZeroOutsideInsideLinks, + wxT("NTC"))); + button->onPopupMenu(onPopup); + s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + s->Add(button, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pBtnNTCfromOutToInAdqPatch = button; + } + // Transmission capacities (NTC) between physical areas outside adequacy patch (area type 1). + // Used in the first step of adequacy patch local matching rule. + { + label = Component::CreateLabel(this, wxT("NTC between physical areas outside adequacy patch")); + button = new Component::Button(this, wxT("Day"), "images/16x16/light_green.png"); + button->SetBackgroundColour(bgColor); + button->menu(true); + onPopup.bind(this, + &AdequacyPatchOptions::onPopupMenuNTC, + PopupInfo(study.parameters.adqPatch.localMatching.setToZeroOutsideOutsideLinks, + wxT("NTC"))); + button->onPopupMenu(onPopup); + s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + s->Add(button, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pBtnNTCfromOutToOutAdqPatch = button; + } + // PTO (Price Taking Order). User can choose between DENS and Load + { + label = Component::CreateLabel(this, wxT("Price taking order")); + button = new Component::Button(this, wxT("Day"), "images/16x16/tag.png"); + button->SetBackgroundColour(bgColor); + button->menu(true); + onPopup.bind(this, &AdequacyPatchOptions::onPopupMenuPTO); + button->onPopupMenu(onPopup); + s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + s->Add(button, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pBtnAdequacyPatchPTO = button; + } + // Select whether the hurdle cost will be included into curtailment sharing rule cost function + { + label = Component::CreateLabel(this, wxT("Include hurdle cost in CSR optimization")); + button = new Component::Button(this, wxT("true"), "images/16x16/light_green.png"); + button->SetBackgroundColour(bgColor); + button->menu(true); + onPopup.bind( + this, + &AdequacyPatchOptions::onPopupMenuSpecify, + PopupInfo(study.parameters.adqPatch.curtailmentSharing.includeHurdleCost, wxT("true"))); + button->onPopupMenu(onPopup); + s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + s->Add(button, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pBtnAdequacyPatchIncludeHurdleCostCsr = button; + } + // Select whether the CSR cost function will be compared prior and after CSR optimization and + // results provided accordingly + { + label = Component::CreateLabel(this, wxT("Check CSR cost function value prior and after CSR")); + button = new Component::Button(this, wxT("true"), "images/16x16/light_green.png"); + button->SetBackgroundColour(bgColor); + button->menu(true); + onPopup.bind( + this, + &AdequacyPatchOptions::onPopupMenuSpecify, + PopupInfo(study.parameters.adqPatch.curtailmentSharing.checkCsrCostFunction, wxT("true"))); + button->onPopupMenu(onPopup); + s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + s->Add(button, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + pBtnAdequacyPatchCheckCsrCostFunctionValue = button; + } + addLabelAdqPatch(this, s, wxT("Thresholds")); + // Threshold values + { + pThresholdCSRStart = nullptr; + pThresholdLMRviolations = nullptr; + pThresholdCSRVarBoundsRelaxation = nullptr; + pThresholdCSRStart + = insertEdit(this, + s, + wxStringFromUTF8("Initiate curtailment sharing rule"), + wxCommandEventHandler(AdequacyPatchOptions::onEditThresholds)); + pThresholdLMRviolations + = insertEdit(this, + s, + wxStringFromUTF8("Display local matching rule violations"), + wxCommandEventHandler(AdequacyPatchOptions::onEditThresholds)); + pThresholdCSRVarBoundsRelaxation + = insertEdit(this, + s, + wxStringFromUTF8("Relax CSR variable boundaries (10^-)"), + wxCommandEventHandler(AdequacyPatchOptions::onEditThresholds)); + } + + { + s->AddSpacer(2); + s->Add(105, 2); + } + + sizer->AddSpacer(10); + + // Buttons + auto panel = new Component::Panel(this); + panel->SetBackgroundColour(defaultBgColor); + auto pnlSizerBtns = new wxBoxSizer(wxHORIZONTAL); + auto pnlSizerBtnsV = new wxBoxSizer(wxVERTICAL); + panel->SetSizer(pnlSizerBtnsV); + pnlSizerBtnsV->AddSpacer(8); + pnlSizerBtnsV->Add(pnlSizerBtns, 1, wxALL | wxEXPAND); + pnlSizerBtnsV->AddSpacer(8); + + button = new Component::Button(panel, + wxT("Reset to default"), + "images/16x16/param_reset.png", + this, + &AdequacyPatchOptions::onResetToDefault); + pnlSizerBtns->Add(22, 5); + pnlSizerBtns->Add(button, 0, wxALL | wxEXPAND); + + pnlSizerBtns->AddStretchSpacer(); + wxButton* pBtnCancel + = Antares::Component::CreateButton(panel, wxT(" Close "), this, &AdequacyPatchOptions::onClose); + pBtnCancel->SetDefault(); + pnlSizerBtns->Add(pBtnCancel, 0, wxALL | wxEXPAND); + pnlSizerBtns->Add(25, 5); + + sizer->Add(new wxStaticLine(this, wxID_ANY), 0, wxALL | wxEXPAND); + sizer->Add(panel, 0, wxALL | wxEXPAND); + + // refresh + Connect(GetId(), wxEVT_MOTION, wxMouseEventHandler(AdequacyPatchOptions::onInternalMotion), nullptr, this); + + refresh(); + SetSizer(sizer); + sizer->Layout(); + + // Recentre the window + sizer->Fit(this); + Centre(wxBOTH); +} + +AdequacyPatchOptions::~AdequacyPatchOptions() = default; + +void AdequacyPatchOptions::onClose(const void*) +{ + Dispatcher::GUI::Close(this); +} + +void AdequacyPatchOptions::onResetToDefault(void*) +{ + auto studyptr = Data::Study::Current::Get(); + if (!(!studyptr)) + { + Window::Message message(this, + wxT("Adequacy Patch Options"), + wxT("Adequacy Patch Options"), + wxT("Do you really want to reset to the default values ?")); + message.add(Window::Message::btnContinue); + message.add(Window::Message::btnCancel, true); + + if (message.showModal() == Window::Message::btnContinue) + { + auto& study = *studyptr; + study.parameters.resetAdqPatchParameters(); + refresh(); + MarkTheStudyAsModified(); + return; + } + } +} + +void AdequacyPatchOptions::onInternalMotion(wxMouseEvent&) +{ + Component::Panel::OnMouseMoveFromExternalComponent(); +} + +void AdequacyPatchOptions::refresh() +{ + auto studyptr = Data::Study::Current::Get(); + if (!studyptr) + return; + // The current study + const auto& study = *studyptr; + + // Adequacy patch + std::string buttonType = "specify"; + // Include adequacy patch + updateButton(pBtnAdequacyPatch, study.parameters.adqPatch.enabled, buttonType); + // Include hurdle cost for CSR + updateButton(pBtnAdequacyPatchIncludeHurdleCostCsr, + study.parameters.adqPatch.curtailmentSharing.includeHurdleCost, + buttonType); + // Check CSR cost function value prior and after CSR optimization + updateButton(pBtnAdequacyPatchCheckCsrCostFunctionValue, + study.parameters.adqPatch.curtailmentSharing.checkCsrCostFunction, + buttonType); + // NTC from physical areas outside adequacy patch (area type 1) to physical areas inside + // adequacy patch (area type 2). Used in the first step of adequacy patch local matching rule. + buttonType = "ntc"; + updateButton(pBtnNTCfromOutToInAdqPatch, + study.parameters.adqPatch.localMatching.setToZeroOutsideInsideLinks, + buttonType); + // NTC between physical areas outside adequacy patch (area type 1). Used in the first step of + // adequacy patch local matching rule. + updateButton(pBtnNTCfromOutToOutAdqPatch, + study.parameters.adqPatch.localMatching.setToZeroOutsideOutsideLinks, + buttonType); + // Price taking order (PTO) for adequacy patch + buttonType = "pto"; + bool isPTOload + = (study.parameters.adqPatch.curtailmentSharing.priceTakingOrder == AdqPatchPTO::isLoad) ? true : false; + updateButton(pBtnAdequacyPatchPTO, isPTOload, buttonType); + + // Threshold values + { + if (pThresholdCSRStart) + pThresholdCSRStart->SetValue( + wxString() << study.parameters.adqPatch.curtailmentSharing.thresholdRun); + if (pThresholdLMRviolations) + pThresholdLMRviolations->SetValue( + wxString() + << study.parameters.adqPatch.curtailmentSharing.thresholdDisplayViolations); + if (pThresholdCSRVarBoundsRelaxation) + pThresholdCSRVarBoundsRelaxation->SetValue( + wxString() + << study.parameters.adqPatch.curtailmentSharing.thresholdVarBoundsRelaxation); + } +} + +void AdequacyPatchOptions::onPopupMenu(Component::Button&, wxMenu& menu, void*, const PopupInfo& info) +{ + pTargetRef = &info.rval; + wxMenuItem* it; + + it = Menu::CreateItem(&menu, + wxID_ANY, + wxString() << wxT("local values (") << info.text << wxT(")"), + "images/16x16/light_green.png", + wxEmptyString); + menu.Connect(it->GetId(), + wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(AdequacyPatchOptions::onSelectModeInclude), + nullptr, + this); + it = Menu::CreateItem( + &menu, wxID_ANY, wxT("ignore"), "images/16x16/light_orange.png", wxEmptyString); + menu.Connect(it->GetId(), + wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(AdequacyPatchOptions::onSelectModeIgnore), + nullptr, + this); +} + +void AdequacyPatchOptions::onPopupMenuNTC(Component::Button&, + wxMenu& menu, + void*, + const PopupInfo& info) +{ + pTargetRef = &info.rval; + wxMenuItem* it; + + it = Menu::CreateItem(&menu, + wxID_ANY, + wxString() << wxT("set to null"), + "images/16x16/light_orange.png", + wxEmptyString); + menu.Connect(it->GetId(), + wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(AdequacyPatchOptions::onSelectModeInclude), + nullptr, + this); + it = Menu::CreateItem(&menu, + wxID_ANY, + wxString() << wxT("local values (") << info.text << wxT(")"), + "images/16x16/light_green.png", + wxEmptyString); + menu.Connect(it->GetId(), + wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(AdequacyPatchOptions::onSelectModeIgnore), + nullptr, + this); +} + +void AdequacyPatchOptions::onPopupMenuPTO(Component::Button&, wxMenu& menu, void*) +{ + wxMenuItem* it; + + it = Menu::CreateItem( + &menu, wxID_ANY, wxString() << wxT("DENS"), "images/16x16/tag.png", wxEmptyString); + menu.Connect(it->GetId(), + wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(AdequacyPatchOptions::onSelectPtoIsDens), + nullptr, + this); + it = Menu::CreateItem( + &menu, wxID_ANY, wxT("Load"), "images/16x16/tag.png", wxEmptyString); + menu.Connect(it->GetId(), + wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(AdequacyPatchOptions::onSelectPtoIsLoad), + nullptr, + this); +} + +void AdequacyPatchOptions::onPopupMenuSpecify(Component::Button&, + wxMenu& menu, + void*, + const PopupInfo& info) +{ + pTargetRef = &info.rval; + wxMenuItem* it; + + it = Menu::CreateItem( + &menu, wxID_ANY, wxString() << info.text, "images/16x16/light_green.png", wxEmptyString); + menu.Connect(it->GetId(), + wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(AdequacyPatchOptions::onSelectModeInclude), + nullptr, + this); + it = Menu::CreateItem( + &menu, wxID_ANY, wxT("false"), "images/16x16/light_orange.png", wxEmptyString); + menu.Connect(it->GetId(), + wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler(AdequacyPatchOptions::onSelectModeIgnore), + nullptr, + this); +} + +void AdequacyPatchOptions::onSelectModeInclude(wxCommandEvent&) +{ + if (pTargetRef && !*pTargetRef) + { + *pTargetRef = true; + MarkTheStudyAsModified(); + refresh(); + } + pTargetRef = nullptr; +} + +void AdequacyPatchOptions::onSelectModeIgnore(wxCommandEvent&) +{ + if (pTargetRef && *pTargetRef) + { + *pTargetRef = false; + MarkTheStudyAsModified(); + refresh(); + } + pTargetRef = nullptr; +} + +void AdequacyPatchOptions::onSelectPtoIsDens(wxCommandEvent&) +{ + auto study = Data::Study::Current::Get(); + if ((!(!study)) + && (study->parameters.adqPatch.curtailmentSharing.priceTakingOrder != AdqPatchPTO::isDens)) + { + study->parameters.adqPatch.curtailmentSharing.priceTakingOrder = AdqPatchPTO::isDens; + refresh(); + MarkTheStudyAsModified(); + } +} + +void AdequacyPatchOptions::onSelectPtoIsLoad(wxCommandEvent&) +{ + auto study = Data::Study::Current::Get(); + if ((!(!study)) + && (study->parameters.adqPatch.curtailmentSharing.priceTakingOrder != AdqPatchPTO::isLoad)) + { + study->parameters.adqPatch.curtailmentSharing.priceTakingOrder = AdqPatchPTO::isLoad; + refresh(); + MarkTheStudyAsModified(); + } +} + +wxTextCtrl* AdequacyPatchOptions::insertEdit(wxWindow* parent, + wxSizer* sizer, + const wxString& text, + wxObjectEventFunction method) +{ + auto* label = Component::CreateLabel(parent, text); + auto* edit = new wxTextCtrl(parent, wxID_ANY, wxT("2"), wxDefaultPosition, wxSize(180, 20)); + sizer->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + sizer->Add(edit, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); + + // Connect event + edit->Connect(edit->GetId(), wxEVT_COMMAND_TEXT_UPDATED, method, nullptr, this); + return edit; +} + +void AdequacyPatchOptions::onEditThresholds(wxCommandEvent& evt) +{ + if (!Data::Study::Current::Valid()) + return; + auto& study = *Data::Study::Current::Get(); + + int id = evt.GetId(); + + if (pThresholdCSRStart && id == pThresholdCSRStart->GetId()) + { + String text; + wxStringToString(pThresholdCSRStart->GetValue(), text); + + float newthreshold; + if (!text.to(newthreshold)) + { + logs.error() << "impossible to update the seed for '" + << "Initiate curtailment sharing rule" + << "'"; + } + else + { + if (newthreshold != study.parameters.adqPatch.curtailmentSharing.thresholdRun) + { + study.parameters.adqPatch.curtailmentSharing.thresholdRun = newthreshold; + MarkTheStudyAsModified(); + } + } + return; + } + + if (pThresholdLMRviolations && id == pThresholdLMRviolations->GetId()) + { + String text; + wxStringToString(pThresholdLMRviolations->GetValue(), text); + + float newthreshold; + if (!text.to(newthreshold)) + { + logs.error() << "impossible to update the seed for '" + << "Display local matching rule violations" + << "'"; + } + else + { + if (newthreshold + != study.parameters.adqPatch.curtailmentSharing.thresholdDisplayViolations) + { + study.parameters.adqPatch.curtailmentSharing.thresholdDisplayViolations = newthreshold; + MarkTheStudyAsModified(); + } + } + return; + } + + if (pThresholdCSRVarBoundsRelaxation && id == pThresholdCSRVarBoundsRelaxation->GetId()) + { + String text; + wxStringToString(pThresholdCSRVarBoundsRelaxation->GetValue(), text); + + int newthreshold; + if (!text.to(newthreshold)) + { + logs.error() << "impossible to update the seed for '" + << "Relax CSR variable boundaries (10^-)" + << "'"; + } + else + { + if (newthreshold + != study.parameters.adqPatch.curtailmentSharing.thresholdVarBoundsRelaxation) + { + study.parameters.adqPatch.curtailmentSharing.thresholdVarBoundsRelaxation + = newthreshold; + MarkTheStudyAsModified(); + } + } + return; + } +} +} // namespace Antares::Window::Options diff --git a/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-options.h b/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-options.h new file mode 100644 index 0000000000..1a7a311750 --- /dev/null +++ b/src/ui/simulator/windows/options/adequacy-patch/adequacy-patch-options.h @@ -0,0 +1,103 @@ +/* +** Copyright 2007-2018 RTE +** Authors: Antares_Simulator Team +** +** This file is part of Antares_Simulator. +** +** Antares_Simulator is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** There are special exceptions to the terms and conditions of the +** license as they are applied to this software. View the full text of +** the exceptions in file COPYING.txt in the directory of this software +** distribution +** +** 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 +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with Antares_Simulator. If not, see . +** +** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions +*/ +#ifndef __ANTARES_APPLICATION_WINDOWS_OPTIONS_ADEQUACY_PATCH_H__ +#define __ANTARES_APPLICATION_WINDOWS_OPTIONS_ADEQUACY_PATCH_H__ + +#include +#include "../../../toolbox/components/button.h" +#include + +#include + +namespace Antares::Window::Options +{ +/*! +** \brief Startup Wizard User Interface +*/ +class AdequacyPatchOptions final : public wxDialog +{ +public: + //! \name Constructor & Destructor + //@{ + /*! + ** \brief Default constructor + ** + ** \param parent The parent window + */ + explicit AdequacyPatchOptions(wxWindow* parent); + //! Destructor + ~AdequacyPatchOptions() override; + //@} + +private: + class PopupInfo final + { + public: + PopupInfo(bool& r, const wxChar* const t) : rval(r), text(t) + { + } + bool& rval; + const wxChar* const text; + }; + + void refresh(); + void onClose(const void*); + void onResetToDefault(void*); + wxTextCtrl* insertEdit(wxWindow* parent, + wxSizer* sizer, + const wxString& text, + wxObjectEventFunction); + + void onSelectPtoIsDens(wxCommandEvent&); + void onSelectPtoIsLoad(wxCommandEvent&); + void onSelectModeInclude(wxCommandEvent& evt); + void onSelectModeIgnore(wxCommandEvent& evt); + + void onPopupMenu(Component::Button&, wxMenu& menu, void*, const PopupInfo& info); + void onPopupMenuSpecify(Component::Button&, wxMenu& menu, void*, const PopupInfo& info); + void onPopupMenuNTC(Component::Button&, wxMenu& menu, void*, const PopupInfo& info); + void onPopupMenuPTO(Component::Button&, wxMenu& menu, void*); + + void onInternalMotion(wxMouseEvent&); + void onEditThresholds(wxCommandEvent&); + + Component::Button* pBtnAdequacyPatch; + Component::Button* pBtnNTCfromOutToInAdqPatch; + Component::Button* pBtnNTCfromOutToOutAdqPatch; + Component::Button* pBtnAdequacyPatchPTO; + Component::Button* pBtnAdequacyPatchIncludeHurdleCostCsr; + Component::Button* pBtnAdequacyPatchCheckCsrCostFunctionValue; + wxTextCtrl* pThresholdCSRStart; + wxTextCtrl* pThresholdLMRviolations; + wxTextCtrl* pThresholdCSRVarBoundsRelaxation; + bool* pTargetRef; + +}; // class AdequacyPatchOptions + +} + +#endif // __ANTARES_APPLICATION_WINDOWS_OPTIONS_ADEQUACY_PATCH_H__ diff --git a/src/ui/simulator/windows/options/optimization/optimization.cpp b/src/ui/simulator/windows/options/optimization/optimization.cpp index e5924fdec8..f71e9e6a89 100644 --- a/src/ui/simulator/windows/options/optimization/optimization.cpp +++ b/src/ui/simulator/windows/options/optimization/optimization.cpp @@ -45,18 +45,6 @@ namespace Window { namespace Options { -static void SubTitle(wxWindow* parent, wxSizer* sizer, const wxChar* text) -{ - sizer->AddSpacer(25); - sizer->AddSpacer(25); - - auto* label = Component::CreateLabel(parent, text, true); - - sizer->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - sizer->AddSpacer(5); - sizer->AddSpacer(5); - sizer->AddSpacer(5); -} static void ResetButton(Component::Button* button, bool value) { assert(button != NULL); @@ -72,36 +60,6 @@ static void ResetButton(Component::Button* button, bool value) } } -static void ResetButtonAdequacyPatch(Component::Button* button, bool value) -{ - assert(button != NULL); - if (value) - { - button->image("images/16x16/light_orange.png"); - button->caption(wxT("set to null")); - } - else - { - button->image("images/16x16/light_green.png"); - button->caption(wxT("local values")); - } -} - -static void ResetButtonSpecify(Component::Button* button, bool value) -{ - assert(button != NULL); - if (value) - { - button->image("images/16x16/light_green.png"); - button->caption(wxT("true")); - } - else - { - button->image("images/16x16/light_orange.png"); - button->caption(wxT("false")); - } -} - static void ResetButton(Component::Button* button, Data::GlobalTransmissionCapacities value) { assert(button != NULL); @@ -389,57 +347,6 @@ Optimization::Optimization(wxWindow* parent) : s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); s->AddSpacer(2); } - SubTitle(this, s, wxT("Adequacy Patch")); - // Adequacy patch - { - label = Component::CreateLabel(this, wxT("Enable Adequacy patch")); - button = new Component::Button(this, wxT("true"), "images/16x16/light_green.png"); - button->SetBackgroundColour(bgColor); - button->menu(true); - onPopup.bind(this, - &Optimization::onPopupMenuSpecify, - PopupInfo(study.parameters.adqPatch.enabled, wxT("true"))); - button->onPopupMenu(onPopup); - s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - s->Add(button, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); - pBtnAdequacyPatch = button; - } - // Transmission capacities (NTC) from physical areas outside adequacy patch (area type 1) to - // physical areas inside adequacy patch (area type 2). Used in the first step of adequacy patch - // local matching rule. - { - label = Component::CreateLabel( - this, wxT("NTC from physical areas outside to physical areas inside adequacy patch")); - button = new Component::Button(this, wxT("Day"), "images/16x16/light_green.png"); - button->SetBackgroundColour(bgColor); - button->menu(true); - onPopup.bind(this, - &Optimization::onPopupMenuAdequacyPatch, - PopupInfo(study.parameters.adqPatch.localMatching.setToZeroOutsideInsideLinks, - wxT("NTC"))); - button->onPopupMenu(onPopup); - s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - s->Add(button, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); - pBtnAdqPatchOutsideInside = button; - } - // Transmission capacities (NTC) between physical areas outside adequacy patch (area type 1). - // Used in the first step of adequacy patch local matching rule. - { - label - = Component::CreateLabel(this, wxT("NTC between physical areas outside adequacy patch")); - button = new Component::Button(this, wxT("Day"), "images/16x16/light_green.png"); - button->SetBackgroundColour(bgColor); - button->menu(true); - onPopup.bind(this, - &Optimization::onPopupMenuAdequacyPatch, - PopupInfo(study.parameters.adqPatch.localMatching.setToZeroOutsideOutsideLinks, - wxT("NTC"))); - button->onPopupMenu(onPopup); - s->Add(label, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); - s->Add(button, 0, wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); - pBtnAdqPatchOutsideOutside = button; - } - { s->AddSpacer(2); s->Add(105, 2); @@ -523,11 +430,7 @@ void Optimization::onResetToDefault(void*) study.parameters.include.reserve.primary = true; study.parameters.include.reserve.spinning = true; study.parameters.include.exportMPS = Data::mpsExportStatus::NO_EXPORT; - study.parameters.adqPatch.enabled = false; - study.parameters.adqPatch.localMatching.setToZeroOutsideInsideLinks = true; - study.parameters.adqPatch.localMatching.setToZeroOutsideOutsideLinks = true; study.parameters.simplexOptimizationRange = Data::sorWeek; - study.parameters.include.unfeasibleProblemBehavior = Data::UnfeasibleProblemBehavior::ERROR_MPS; @@ -574,17 +477,7 @@ void Optimization::refresh() // Export mps pBtnExportMPS->image(mpsExportIcon(study.parameters.include.exportMPS)); pBtnExportMPS->caption(Data::mpsExportStatusToString(study.parameters.include.exportMPS)); - // Adequacy patch - ResetButtonSpecify(pBtnAdequacyPatch, study.parameters.adqPatch.enabled); - // NTC from physical areas outside adequacy patch (area type 1) to physical areas inside - // adequacy patch (area type 2). Used in the first step of adequacy patch local matching rule. - ResetButtonAdequacyPatch(pBtnAdqPatchOutsideInside, - study.parameters.adqPatch.localMatching.setToZeroOutsideInsideLinks); - // NTC between physical areas outside adequacy patch (area type 1). Used in the first step of - // adequacy patch local matching rule. - ResetButtonAdequacyPatch(pBtnAdqPatchOutsideOutside, - study.parameters.adqPatch.localMatching.setToZeroOutsideOutsideLinks); - + // Unfeasible problem behavior pBtnUnfeasibleProblemBehavior->image( Data::getIcon(study.parameters.include.unfeasibleProblemBehavior)); @@ -628,36 +521,6 @@ void Optimization::onPopupMenu(Component::Button&, wxMenu& menu, void*, const Po this); } -void Optimization::onPopupMenuAdequacyPatch(Component::Button&, - wxMenu& menu, - void*, - const PopupInfo& info) -{ - pTargetRef = &info.rval; - wxMenuItem* it; - - it = Menu::CreateItem(&menu, - wxID_ANY, - wxString() << wxT("set to null"), - "images/16x16/light_orange.png", - wxEmptyString); - menu.Connect(it->GetId(), - wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler(Optimization::onSelectModeInclude), - nullptr, - this); - it = Menu::CreateItem(&menu, - wxID_ANY, - wxString() << wxT("local values (") << info.text << wxT(")"), - "images/16x16/light_green.png", - wxEmptyString); - menu.Connect(it->GetId(), - wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler(Optimization::onSelectModeIgnore), - nullptr, - this); -} - void Optimization::onPopupMenuSpecify(Component::Button&, wxMenu& menu, void*, diff --git a/src/ui/simulator/windows/options/optimization/optimization.h b/src/ui/simulator/windows/options/optimization/optimization.h index 9ddaeea276..67aa412114 100644 --- a/src/ui/simulator/windows/options/optimization/optimization.h +++ b/src/ui/simulator/windows/options/optimization/optimization.h @@ -113,8 +113,7 @@ class Optimization final : public wxDialog void onPopupMenuLinkType(Component::Button&, wxMenu& menu, void*); void onPopupMenuExportMPSstatus(Component::Button&, wxMenu& menu, void*); void onPopupMenuUnfeasibleBehavior(Component::Button&, wxMenu& menu, void*); - void onPopupMenuAdequacyPatch(Component::Button&, wxMenu& menu, void*, const PopupInfo& info); - + void onInternalMotion(wxMouseEvent&); private: @@ -131,9 +130,6 @@ class Optimization final : public wxDialog Component::Button* pBtnSimplexOptimizationRange; Component::Button* pBtnExportMPS; - Component::Button* pBtnAdequacyPatch; - Component::Button* pBtnAdqPatchOutsideInside; - Component::Button* pBtnAdqPatchOutsideOutside; Component::Button* pBtnUnfeasibleProblemBehavior; bool* pTargetRef;