diff --git a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp index fe72e57d10..33b59d915e 100644 --- a/src/libs/antares/InfoCollection/StudyInfoCollector.cpp +++ b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp @@ -167,9 +167,6 @@ void SimulationInfoCollector::toFileContent(FileContent& file_content) { file_content.addItemToSection("optimization problem", "variables", opt_info_.nbVariables); file_content.addItemToSection("optimization problem", "constraints", opt_info_.nbConstraints); - file_content.addItemToSection("optimization problem", - "non-zero coefficients", - opt_info_.nbNonZeroCoeffs); } } // namespace Benchmarking diff --git a/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h b/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h index 96f83b38af..2ac5a06c12 100644 --- a/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h +++ b/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h @@ -62,7 +62,6 @@ struct OptimizationInfo { unsigned int nbVariables = 0; unsigned int nbConstraints = 0; - unsigned int nbNonZeroCoeffs = 0; }; class SimulationInfoCollector diff --git a/src/solver/optimisation/CMakeLists.txt b/src/solver/optimisation/CMakeLists.txt index e2472febd1..e8b46e6000 100644 --- a/src/solver/optimisation/CMakeLists.txt +++ b/src/solver/optimisation/CMakeLists.txt @@ -5,6 +5,7 @@ set(RTESOLVER_OPT opt_optimisation_lineaire.cpp opt_chainage_intercos.cpp include/antares/solver/optimisation/opt_fonctions.h + include/antares/solver/optimisation/SparseVector.hxx opt_pilotage_optimisation_lineaire.cpp opt_pilotage_optimisation_quadratique.cpp include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h diff --git a/src/solver/optimisation/HebdoProblemToLpsTranslator.cpp b/src/solver/optimisation/HebdoProblemToLpsTranslator.cpp index 9c67012c70..3e741652d8 100644 --- a/src/solver/optimisation/HebdoProblemToLpsTranslator.cpp +++ b/src/solver/optimisation/HebdoProblemToLpsTranslator.cpp @@ -43,6 +43,13 @@ void copy(const T& in, U& out) { std::ranges::copy(in, std::back_inserter(out)); } + +template +void copy(const SparseVector& in, U& out) +{ + copy(in.extract(), out); +} + } // namespace WeeklyDataFromAntares HebdoProblemToLpsTranslator::translate( 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 index 0aa61a969d..b480108379 100644 --- a/src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.cpp +++ b/src/solver/optimisation/adequacy_patch_csr/adq_patch_curtailment_sharing.cpp @@ -141,13 +141,9 @@ void HourlyCSRProblem::calculateCsrParameters() 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); + problemeAResoudre_.NombreDeContraintes = countConstraints(problemeHebdo_); + OPT_AllocateFromNumberOfVariableConstraints(&problemeAResoudre_); } void HourlyCSRProblem::buildProblemVariables() diff --git a/src/solver/optimisation/constraints/ConsistenceNumberOfDispatchableUnits.cpp b/src/solver/optimisation/constraints/ConsistenceNumberOfDispatchableUnits.cpp index 300cdbaef5..ab49f3e6d5 100644 --- a/src/solver/optimisation/constraints/ConsistenceNumberOfDispatchableUnits.cpp +++ b/src/solver/optimisation/constraints/ConsistenceNumberOfDispatchableUnits.cpp @@ -60,7 +60,6 @@ void ConsistenceNumberOfDispatchableUnits::add(int pays, int index, int pdt) } else { - builder.data.NbTermesContraintesPourLesCoutsDeDemarrage += 4; builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/constraints/ConstraintBuilder.cpp b/src/solver/optimisation/constraints/ConstraintBuilder.cpp index edac845526..ba4e70254a 100644 --- a/src/solver/optimisation/constraints/ConstraintBuilder.cpp +++ b/src/solver/optimisation/constraints/ConstraintBuilder.cpp @@ -188,11 +188,6 @@ void ConstraintBuilder::OPT_ChargerLaContrainteDansLaMatriceDesContraintes() = data.Pi[i]; data.IndicesColonnes[data.nombreDeTermesDansLaMatriceDeContrainte] = data.Colonne[i]; data.nombreDeTermesDansLaMatriceDeContrainte++; - if (data.nombreDeTermesDansLaMatriceDeContrainte - == data.NombreDeTermesAllouesDansLaMatriceDesContraintes) - { - OPT_AugmenterLaTailleDeLaMatriceDesContraintes(); - } } data.NombreDeTermesDesLignes[data.nombreDeContraintes] = nombreDeTermes_; @@ -201,20 +196,3 @@ void ConstraintBuilder::OPT_ChargerLaContrainteDansLaMatriceDesContraintes() return; } - -void ConstraintBuilder::OPT_AugmenterLaTailleDeLaMatriceDesContraintes() -{ - int NbTermes = data.NombreDeTermesAllouesDansLaMatriceDesContraintes; - NbTermes += data.IncrementDAllocationMatriceDesContraintes; - - logs.info(); - logs.info() << " Expected Number of Non-zero terms in Problem Matrix : increased to : " - << NbTermes; - logs.info(); - - data.CoefficientsDeLaMatriceDesContraintes.resize(NbTermes); - - data.IndicesColonnes.resize(NbTermes); - - data.NombreDeTermesAllouesDansLaMatriceDesContraintes = NbTermes; -} diff --git a/src/solver/optimisation/constraints/MinDownTime.cpp b/src/solver/optimisation/constraints/MinDownTime.cpp index a7467e742c..7d7505ee4d 100644 --- a/src/solver/optimisation/constraints/MinDownTime.cpp +++ b/src/solver/optimisation/constraints/MinDownTime.cpp @@ -66,8 +66,6 @@ void MinDownTime::add(int pays, int index, int pdt) } else { - builder.data.NbTermesContraintesPourLesCoutsDeDemarrage - += 1 + DureeMinimaleDArretDUnGroupeDuPalierThermique; builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/constraints/NbDispUnitsMinBoundSinceMinUpTime.cpp b/src/solver/optimisation/constraints/NbDispUnitsMinBoundSinceMinUpTime.cpp index 13f03df1c1..a1a73ef2fa 100644 --- a/src/solver/optimisation/constraints/NbDispUnitsMinBoundSinceMinUpTime.cpp +++ b/src/solver/optimisation/constraints/NbDispUnitsMinBoundSinceMinUpTime.cpp @@ -70,8 +70,6 @@ void NbDispUnitsMinBoundSinceMinUpTime::add(int pays, int index, int pdt) } else { - builder.data.NbTermesContraintesPourLesCoutsDeDemarrage - += 1 + 2 * DureeMinimaleDeMarcheDUnGroupeDuPalierThermique; builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/constraints/NbUnitsOutageLessThanNbUnitsStop.cpp b/src/solver/optimisation/constraints/NbUnitsOutageLessThanNbUnitsStop.cpp index 4d90766da3..bfa8fb52c2 100644 --- a/src/solver/optimisation/constraints/NbUnitsOutageLessThanNbUnitsStop.cpp +++ b/src/solver/optimisation/constraints/NbUnitsOutageLessThanNbUnitsStop.cpp @@ -50,7 +50,6 @@ void NbUnitsOutageLessThanNbUnitsStop::add(int pays, int index, int pdt) } else { - builder.data.NbTermesContraintesPourLesCoutsDeDemarrage += 2; builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/constraints/PMaxDispatchableGeneration.cpp b/src/solver/optimisation/constraints/PMaxDispatchableGeneration.cpp index a3d7fef5b8..466ebf81d2 100644 --- a/src/solver/optimisation/constraints/PMaxDispatchableGeneration.cpp +++ b/src/solver/optimisation/constraints/PMaxDispatchableGeneration.cpp @@ -48,7 +48,6 @@ void PMaxDispatchableGeneration::add(int pays, int index, int pdt) } else { - builder.data.NbTermesContraintesPourLesCoutsDeDemarrage += 2; builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/constraints/PMinDispatchableGeneration.cpp b/src/solver/optimisation/constraints/PMinDispatchableGeneration.cpp index df22497577..b6cf27fc8e 100644 --- a/src/solver/optimisation/constraints/PMinDispatchableGeneration.cpp +++ b/src/solver/optimisation/constraints/PMinDispatchableGeneration.cpp @@ -49,7 +49,6 @@ void PMinDispatchableGeneration::add(int pays, int index, int pdt) } else { - builder.data.NbTermesContraintesPourLesCoutsDeDemarrage += 2; builder.data.nombreDeContraintes++; } } diff --git a/src/solver/optimisation/constraints/constraint_builder_utils.cpp b/src/solver/optimisation/constraints/constraint_builder_utils.cpp index 77a3228999..585d0b6d81 100644 --- a/src/solver/optimisation/constraints/constraint_builder_utils.cpp +++ b/src/solver/optimisation/constraints/constraint_builder_utils.cpp @@ -32,7 +32,6 @@ ConstraintBuilderData NewGetConstraintBuilderFromProblemHebdoAndProblemAResoudre ProblemeAResoudre.IndicesDebutDeLigne, ProblemeAResoudre.CoefficientsDeLaMatriceDesContraintes, ProblemeAResoudre.IndicesColonnes, - ProblemeAResoudre.NombreDeTermesAllouesDansLaMatriceDesContraintes, ProblemeAResoudre.NombreDeTermesDesLignes, ProblemeAResoudre.Sens, ProblemeAResoudre.IncrementDAllocationMatriceDesContraintes, @@ -44,6 +43,5 @@ ConstraintBuilderData NewGetConstraintBuilderFromProblemHebdoAndProblemAResoudre problemeHebdo->NamedProblems, problemeHebdo->NomsDesPays, problemeHebdo->weekInTheYear, - problemeHebdo->NombreDePasDeTemps, - problemeHebdo->NbTermesContraintesPourLesCoutsDeDemarrage}; + problemeHebdo->NombreDePasDeTemps}; } diff --git a/src/solver/optimisation/include/antares/solver/optimisation/SparseVector.hxx b/src/solver/optimisation/include/antares/solver/optimisation/SparseVector.hxx new file mode 100644 index 0000000000..2b71ac4aec --- /dev/null +++ b/src/solver/optimisation/include/antares/solver/optimisation/SparseVector.hxx @@ -0,0 +1,44 @@ +#include + +template +class SparseVector +{ +public: + std::size_t size() const + { + return isExtracted ? v.size() : m.size(); + } + + T& operator[](std::size_t idx) + { + isExtracted = false; + m.push_back({idx, 0}); + return m.back().second; + } + + T* data() const + { + extract(); + return v.data(); + } + + std::vector& extract() const + { + if (!isExtracted) + { + isExtracted = true; + v.assign(m.size(), 0.); + for (auto [index, coeff]: m) + { + v[index] = coeff; + } + m.clear(); + } + return v; + } + +private: + mutable bool isExtracted = false; + mutable std::vector> m; + mutable std::vector v; +}; diff --git a/src/solver/optimisation/include/antares/solver/optimisation/constraints/ConstraintBuilder.h b/src/solver/optimisation/include/antares/solver/optimisation/constraints/ConstraintBuilder.h index 2dfdec8000..dd0a1ab1b6 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/constraints/ConstraintBuilder.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/constraints/ConstraintBuilder.h @@ -39,9 +39,8 @@ class ConstraintBuilderData int& nombreDeContraintes; int& nombreDeTermesDansLaMatriceDeContrainte; std::vector& IndicesDebutDeLigne; - std::vector& CoefficientsDeLaMatriceDesContraintes; - std::vector& IndicesColonnes; - int& NombreDeTermesAllouesDansLaMatriceDesContraintes; // TODO Check if ref is needed + SparseVector& CoefficientsDeLaMatriceDesContraintes; + SparseVector& IndicesColonnes; std::vector& NombreDeTermesDesLignes; std::string& Sens; int& IncrementDAllocationMatriceDesContraintes; @@ -54,7 +53,6 @@ class ConstraintBuilderData const std::vector& NomsDesPays; const uint32_t& weekInTheYear; const uint32_t& NombreDePasDeTemps; - uint32_t& NbTermesContraintesPourLesCoutsDeDemarrage; }; /*! \verbatim @@ -221,8 +219,6 @@ class ConstraintBuilder private: void OPT_ChargerLaContrainteDansLaMatriceDesContraintes(); - void OPT_AugmenterLaTailleDeLaMatriceDesContraintes(); - unsigned int hourInWeek_ = 0; char operator_ = '='; diff --git a/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h b/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h index 18551a08b5..bd27921f8f 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/opt_fonctions.h @@ -95,8 +95,7 @@ double OPT_CalculerAireMaxPminJour(int, int, int, int, std::vector&, std::v void OPT_ChainagesDesIntercoPartantDUnNoeud(PROBLEME_HEBDO*); -void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, - int); +void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre); void OPT_AllocDuProblemeAOptimiser(PROBLEME_HEBDO*); int OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO*); diff --git a/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h b/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h index 7641c23d4e..1079a2f147 100644 --- a/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h +++ b/src/solver/optimisation/include/antares/solver/optimisation/opt_structure_probleme_a_resoudre.h @@ -27,6 +27,7 @@ #include +#include "SparseVector.hxx" #include "opt_constants.h" /*--------------------------------------------------------------------------------------*/ @@ -45,9 +46,8 @@ struct PROBLEME_ANTARES_A_RESOUDRE std::string Sens; std::vector IndicesDebutDeLigne; std::vector NombreDeTermesDesLignes; - std::vector CoefficientsDeLaMatriceDesContraintes; - std::vector IndicesColonnes; - int NombreDeTermesAllouesDansLaMatriceDesContraintes; + SparseVector CoefficientsDeLaMatriceDesContraintes; + SparseVector IndicesColonnes; int IncrementDAllocationMatriceDesContraintes; int NombreDeTermesDansLaMatriceDesContraintes; /* Donnees variables de la matrice des contraintes */ diff --git a/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp b/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp index a9906ff21f..69e827fec5 100644 --- a/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp +++ b/src/solver/optimisation/opt_alloc_probleme_a_optimiser.cpp @@ -20,13 +20,11 @@ */ #include +#include "antares/solver/optimisation/opt_fonctions.h" #include "antares/solver/optimisation/opt_structure_probleme_a_resoudre.h" #include "antares/solver/simulation/sim_structure_probleme_economique.h" -int OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO*); - -void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre, - int NbTermes) +void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre) { const size_t nbVariables = ProblemeAResoudre->NombreDeVariables; const size_t nbConstraints = ProblemeAResoudre->NombreDeContraintes; @@ -35,12 +33,6 @@ void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* Pr ProblemeAResoudre->IndicesDebutDeLigne.assign(nbConstraints, 0); ProblemeAResoudre->NombreDeTermesDesLignes.assign(nbConstraints, 0); - ProblemeAResoudre->CoefficientsDeLaMatriceDesContraintes.assign(NbTermes, 0.); - ProblemeAResoudre->IndicesColonnes.assign(NbTermes, 0); - - ProblemeAResoudre->NombreDeTermesAllouesDansLaMatriceDesContraintes = NbTermes; - ProblemeAResoudre->IncrementDAllocationMatriceDesContraintes = (int)(0.1 * NbTermes); - ProblemeAResoudre->CoutQuadratique.assign(nbVariables, 0.); ProblemeAResoudre->CoutLineaire.assign(nbVariables, 0.); ProblemeAResoudre->TypeDeVariable.assign(nbVariables, 0); @@ -70,62 +62,20 @@ void OPT_AllocateFromNumberOfVariableConstraints(PROBLEME_ANTARES_A_RESOUDRE* Pr ProblemeAResoudre->VariablesEntieres.resize(nbVariables); } -static void optimisationAllocateProblem(PROBLEME_HEBDO* problemeHebdo, const int mxPaliers) +static void optimisationAllocateProblem(PROBLEME_HEBDO* problemeHebdo) { const auto& ProblemeAResoudre = problemeHebdo->ProblemeAResoudre; int NombreDePasDeTempsPourUneOptimisation = problemeHebdo ->NombreDePasDeTempsPourUneOptimisation; - int Sparsity = mxPaliers * problemeHebdo->NombreDePays; - Sparsity += problemeHebdo->NombreDInterconnexions; - if (Sparsity > 100) - { - Sparsity = 100; - } - - int NbTermes = 0; - NbTermes += ProblemeAResoudre->NombreDeContraintes; - - int Adder = mxPaliers; - Adder += 4; - Adder *= problemeHebdo->NombreDePays; - Adder += 2 * problemeHebdo->NombreDInterconnexions; - Adder *= NombreDePasDeTempsPourUneOptimisation; - - NbTermes += Adder; - - NbTermes += Adder; - - Adder = 3 * problemeHebdo->NombreDInterconnexions * NombreDePasDeTempsPourUneOptimisation; - NbTermes += Adder; - - Adder = Sparsity * problemeHebdo->NombreDeContraintesCouplantes; - Adder *= (NombreDePasDeTempsPourUneOptimisation); - Adder += Sparsity * (7 + 7) * problemeHebdo->NombreDeContraintesCouplantes; - - NbTermes += Adder; - - NbTermes += 3 * problemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation; - NbTermes += problemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation * 4; - NbTermes += problemeHebdo->NombreDePays * NombreDePasDeTempsPourUneOptimisation * 5; - - 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; - logs.info(); logs.info() << " Starting Memory Allocation for a Weekly Optimization problem in Canonical form "; logs.info() << " ( Problem Size :" << ProblemeAResoudre->NombreDeVariables << " variables " << ProblemeAResoudre->NombreDeContraintes << " Constraints) "; - logs.info() << " Expected Number of Non-zero terms in Problem Matrix : " << NbTermes; - logs.info(); - OPT_AllocateFromNumberOfVariableConstraints(problemeHebdo->ProblemeAResoudre.get(), NbTermes); + OPT_AllocateFromNumberOfVariableConstraints(problemeHebdo->ProblemeAResoudre.get()); int NbIntervalles = problemeHebdo->NombreDePasDeTemps / NombreDePasDeTempsPourUneOptimisation; @@ -140,7 +90,7 @@ void OPT_AllocDuProblemeAOptimiser(PROBLEME_HEBDO* problemeHebdo) { problemeHebdo->ProblemeAResoudre = std::make_unique(); - int mxPaliers = OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(problemeHebdo); + OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(problemeHebdo); - optimisationAllocateProblem(problemeHebdo, mxPaliers); + optimisationAllocateProblem(problemeHebdo); } diff --git a/src/solver/simulation/adequacy.cpp b/src/solver/simulation/adequacy.cpp index e0ef154020..d5eca92216 100644 --- a/src/solver/simulation/adequacy.cpp +++ b/src/solver/simulation/adequacy.cpp @@ -46,7 +46,6 @@ Benchmarking::OptimizationInfo Adequacy::getOptimizationInfo() const optInfo.nbVariables = Pb->NombreDeVariables; optInfo.nbConstraints = Pb->NombreDeContraintes; - optInfo.nbNonZeroCoeffs = Pb->NombreDeTermesAllouesDansLaMatriceDesContraintes; return optInfo; } diff --git a/src/solver/simulation/economy.cpp b/src/solver/simulation/economy.cpp index b6edbc4f6f..0b8b341148 100644 --- a/src/solver/simulation/economy.cpp +++ b/src/solver/simulation/economy.cpp @@ -51,7 +51,6 @@ Benchmarking::OptimizationInfo Economy::getOptimizationInfo() const optInfo.nbVariables = Pb->NombreDeVariables; optInfo.nbConstraints = Pb->NombreDeContraintes; - optInfo.nbNonZeroCoeffs = Pb->NombreDeTermesAllouesDansLaMatriceDesContraintes; return optInfo; } diff --git a/src/solver/simulation/include/antares/solver/simulation/sim_structure_probleme_economique.h b/src/solver/simulation/include/antares/solver/simulation/sim_structure_probleme_economique.h index 29dd7c38f5..3a261bf40f 100644 --- a/src/solver/simulation/include/antares/solver/simulation/sim_structure_probleme_economique.h +++ b/src/solver/simulation/include/antares/solver/simulation/sim_structure_probleme_economique.h @@ -502,7 +502,6 @@ struct PROBLEME_HEBDO std::vector<::ShortTermStorage::AREA_INPUT> ShortTermStorage; /* Optimization problem */ - uint32_t NbTermesContraintesPourLesCoutsDeDemarrage = 0; std::vector DefaillanceNegativeUtiliserPMinThermique; std::vector DefaillanceNegativeUtiliserHydro; std::vector DefaillanceNegativeUtiliserConsoAbattue; diff --git a/src/tests/src/solver/optimisation/translator/test_translator.cpp b/src/tests/src/solver/optimisation/translator/test_translator.cpp index 2430c74cb0..77591180cb 100644 --- a/src/tests/src/solver/optimisation/translator/test_translator.cpp +++ b/src/tests/src/solver/optimisation/translator/test_translator.cpp @@ -112,6 +112,15 @@ BOOST_AUTO_TEST_CASE(empty_problem_empty_const_data) BOOST_CHECK(ret == ConstantDataFromAntares()); } +template +static void fillSparseVector(SparseVector& v, int idxMax) +{ + for (int idx = 0; idx < idxMax; idx++) + { + v[idx] = idx; + } +} + BOOST_AUTO_TEST_CASE(common_data_properly_copied) { HebdoProblemToLpsTranslator translator; @@ -121,15 +130,17 @@ BOOST_AUTO_TEST_CASE(common_data_properly_copied) problemHebdo.TypeDeVariable = {0, 1, 2}; problemHebdo.IndicesDebutDeLigne = {0, 3}; problemHebdo.NombreDeTermesDesLignes = {3, 3}; - problemHebdo.CoefficientsDeLaMatriceDesContraintes = {0, 1, 2, 3, 4, 5}; - problemHebdo.IndicesColonnes = {0, 1, 2, 3, 4, 5}; + fillSparseVector(problemHebdo.CoefficientsDeLaMatriceDesContraintes, 6); + fillSparseVector(problemHebdo.IndicesColonnes, 6); auto ret = translator.commonProblemData(&problemHebdo); + BOOST_CHECK_EQUAL(ret.VariablesCount, problemHebdo.NombreDeVariables); BOOST_CHECK_EQUAL(ret.ConstraintesCount, problemHebdo.NombreDeContraintes); BOOST_CHECK(std::ranges::equal(ret.VariablesType, problemHebdo.TypeDeVariable)); - BOOST_CHECK(ret.ConstraintsMatrixCoeff == problemHebdo.CoefficientsDeLaMatriceDesContraintes); - BOOST_CHECK(std::ranges::equal(ret.ColumnIndexes, problemHebdo.IndicesColonnes)); + BOOST_CHECK(ret.ConstraintsMatrixCoeff + == problemHebdo.CoefficientsDeLaMatriceDesContraintes.extract()); + BOOST_CHECK(std::ranges::equal(ret.ColumnIndexes, problemHebdo.IndicesColonnes.extract())); auto expectedMdeb = problemHebdo.IndicesDebutDeLigne; expectedMdeb.push_back(problemHebdo.CoefficientsDeLaMatriceDesContraintes.size()); BOOST_CHECK(std::ranges::equal(ret.Mdeb, expectedMdeb)); @@ -183,8 +194,9 @@ BOOST_AUTO_TEST_CASE(NombreDeCoefficients_is_properly_computed) problemHebdo.NombreDeContraintes = 3; problemHebdo.IndicesDebutDeLigne = {0, 3, 6}; problemHebdo.NombreDeTermesDesLignes = {3, 3, 3}; - problemHebdo.CoefficientsDeLaMatriceDesContraintes = {0, 1, 2, 3, 4, 5, 6, 7, 8}; - problemHebdo.IndicesColonnes = {0, 1, 2, 3, 4, 5, 6, 7, 8}; + + fillSparseVector(problemHebdo.CoefficientsDeLaMatriceDesContraintes, 9); + fillSparseVector(problemHebdo.IndicesColonnes, 9); auto ret = translator.commonProblemData(&problemHebdo); BOOST_CHECK_EQUAL(ret.CoeffCount, 9);