From 60538e6b738d3b659eb5e0f7e02f488d79bb166a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Boull=C3=A9?= Date: Wed, 11 Oct 2023 13:58:43 +0200 Subject: [PATCH] Refactor method KWDataGridVNSOptimizer::VNSOptimizeVarPartDataGrid KWDataGridVNSOptimizer::VNSOptimizeVarPartDataGrid - utilise maintenant la methode VNSDataGridPostOptimizeVarPart pour la post-optimisation VarPart - on garde pour l'instant l'ancienne implementation dans DEPRECATED_VNSOptimizeVarPartDataGrid KWDataGrid - Set|GetLabel: ajout de ces methodes temporaire permettant d'annoter une grille pour aider a la mise au point des algorithmes d'optimisation --- src/Learning/KWDataPreparation/KWDataGrid.cpp | 10 ++++ src/Learning/KWDataPreparation/KWDataGrid.h | 11 +++++ .../KWDataPreparation/KWDataGridOptimizer.cpp | 48 +++++++++---------- .../KWDataPreparation/KWDataGridOptimizer.h | 17 +++---- src/Learning/MODL/MODL.cpp | 1 - .../MODL_Coclustering/MODL_Coclustering.cpp | 1 + 6 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/Learning/KWDataPreparation/KWDataGrid.cpp b/src/Learning/KWDataPreparation/KWDataGrid.cpp index 345a603eb..0cd7cf19a 100644 --- a/src/Learning/KWDataPreparation/KWDataGrid.cpp +++ b/src/Learning/KWDataPreparation/KWDataGrid.cpp @@ -5455,6 +5455,16 @@ int KWDGCellCompareDecreasingFrequency(const void* elem1, const void* elem2) return nCompare; } +void KWDataGrid::SetLabel(const ALString& sValue) +{ + sLabel = sValue; +} + +const ALString& KWDataGrid::GetLabel() const +{ + return sLabel; +} + void KWDataGrid::SetTargetAttribute(KWDGAttribute* attribute) { targetAttribute = attribute; diff --git a/src/Learning/KWDataPreparation/KWDataGrid.h b/src/Learning/KWDataPreparation/KWDataGrid.h index 971b75b45..b54f66ab5 100644 --- a/src/Learning/KWDataPreparation/KWDataGrid.h +++ b/src/Learning/KWDataPreparation/KWDataGrid.h @@ -371,6 +371,13 @@ class KWDataGrid : public Object /////////////////////////////// //// Implementation + + // CH IV Refactoring: parametrage d'un libelle associe, pour aider a la mise au point des grilles + // CH IV Refactoring: a supprimer une fois les nouveaux algorithmes mi au point + // Libelle associe a la grille + void SetLabel(const ALString& sValue); + const ALString& GetLabel() const; + protected: friend class KWDGAttribute; @@ -435,6 +442,10 @@ class KWDataGrid : public Object // Positionne par l'attribut lors de l'initialsaition de son type s'il est de type VarPart // Permet egalement de savoir si la grille est de type VarPart KWDGAttribute* varPartAttribute; + + // CH IV Refactoring: a supprimer une fois les nouveaux algorithmes mi au point + // Libelle associe a la grille + ALString sLabel; }; // Comparaison de deux grilles de donnees, sur la valeur de tri (SortValue), diff --git a/src/Learning/KWDataPreparation/KWDataGridOptimizer.cpp b/src/Learning/KWDataPreparation/KWDataGridOptimizer.cpp index bdc456b7e..b5ff2f66c 100644 --- a/src/Learning/KWDataPreparation/KWDataGridOptimizer.cpp +++ b/src/Learning/KWDataPreparation/KWDataGridOptimizer.cpp @@ -1627,9 +1627,10 @@ double KWDataGridVNSOptimizer::VNSOptimizeDataGrid(const KWDataGrid* initialData } // CH IV Begin -double KWDataGridVNSOptimizer::PROTO_VNSDataGridPostOptimizeVarPart( - const KWDataGrid* initialDataGrid, KWDataGridMerger* neighbourDataGrid, double dNeighbourDataGridCost, - KWDataGrid* mergedDataGrid, KWDataGrid* partitionedReferencePostMergedDataGrid) const +double KWDataGridVNSOptimizer::VNSDataGridPostOptimizeVarPart(const KWDataGrid* initialDataGrid, + KWDataGridMerger* neighbourDataGrid, + double dNeighbourDataGridCost, KWDataGrid* mergedDataGrid, + KWDataGrid* partitionedReferencePostMergedDataGrid) const { double dCost; double dMergedCost; @@ -1848,11 +1849,10 @@ double KWDataGridVNSOptimizer::PROTO_VNSDataGridPostOptimizeVarPart( return dMergedCost; } -double KWDataGridVNSOptimizer::PROTO_VNSOptimizeVarPartDataGrid(const KWDataGrid* initialDataGrid, - double dDecreaseFactor, int nMinIndex, int nMaxIndex, - KWDataGrid* optimizedDataGrid, - double dOptimizedDataGridCost, - double& dBestMergedDataGridCost) const +double KWDataGridVNSOptimizer::VNSOptimizeVarPartDataGrid(const KWDataGrid* initialDataGrid, double dDecreaseFactor, + int nMinIndex, int nMaxIndex, KWDataGrid* optimizedDataGrid, + double dOptimizedDataGridCost, + double& dBestMergedDataGridCost) const { double dBestCost; double dCost; @@ -1872,6 +1872,14 @@ double KWDataGridVNSOptimizer::PROTO_VNSOptimizeVarPartDataGrid(const KWDataGrid require(nMinIndex <= nMaxIndex); require(fabs(dOptimizedDataGridCost - dataGridCosts->ComputeDataGridTotalCost(optimizedDataGrid)) < dEpsilon); + // CH IV Refactoring : DDDDD + // Test du remplacement de la methode actuelle, par son proto + boolean bDeprecatedVersion = false; + if (bDeprecatedVersion) + return DEPRECATED_VNSOptimizeVarPartDataGrid(initialDataGrid, dDecreaseFactor, nMinIndex, nMaxIndex, + optimizedDataGrid, dOptimizedDataGridCost, + dBestMergedDataGridCost); + // Initialisations dataGridManager.SetSourceDataGrid(initialDataGrid); neighbourDataGrid.SetDataGridCosts(dataGridCosts); @@ -1908,9 +1916,9 @@ double KWDataGridVNSOptimizer::PROTO_VNSOptimizeVarPartDataGrid(const KWDataGrid // A terme, a deplacer dans OptimizeSolution dMergedCost = dCost; if (initialDataGrid->IsVarPartDataGrid()) - dMergedCost = PROTO_VNSDataGridPostOptimizeVarPart(initialDataGrid, &neighbourDataGrid, dCost, - &mergedDataGrid, - &partitionedReferencePostMergedDataGrid); + dMergedCost = + VNSDataGridPostOptimizeVarPart(initialDataGrid, &neighbourDataGrid, dCost, &mergedDataGrid, + &partitionedReferencePostMergedDataGrid); // Si amelioration: on la memorise if (dMergedCost < dBestMergedCost - dEpsilon) @@ -1981,10 +1989,11 @@ double KWDataGridVNSOptimizer::PROTO_VNSOptimizeVarPartDataGrid(const KWDataGrid return dBestCost; } -double KWDataGridVNSOptimizer::VNSOptimizeVarPartDataGrid(const KWDataGrid* initialDataGrid, double dDecreaseFactor, - int nMinIndex, int nMaxIndex, KWDataGrid* optimizedDataGrid, - double dOptimizedDataGridCost, - double& dBestMergedDataGridCost) const +double KWDataGridVNSOptimizer::DEPRECATED_VNSOptimizeVarPartDataGrid(const KWDataGrid* initialDataGrid, + double dDecreaseFactor, int nMinIndex, + int nMaxIndex, KWDataGrid* optimizedDataGrid, + double dOptimizedDataGridCost, + double& dBestMergedDataGridCost) const { double dBestCost; double dCost; @@ -2006,15 +2015,6 @@ double KWDataGridVNSOptimizer::VNSOptimizeVarPartDataGrid(const KWDataGrid* init require(nMinIndex <= nMaxIndex); require(fabs(dOptimizedDataGridCost - dataGridCosts->ComputeDataGridTotalCost(optimizedDataGrid)) < dEpsilon); - // CH IV Refactoring : DDDDD - // Test du remplacement de la methode actuelle, par son proto - boolean bProto = false; - //DDD bProto = true; - if (bProto) - return PROTO_VNSOptimizeVarPartDataGrid(initialDataGrid, dDecreaseFactor, nMinIndex, nMaxIndex, - optimizedDataGrid, dOptimizedDataGridCost, - dBestMergedDataGridCost); - // Initialisations dataGridManager.SetSourceDataGrid(initialDataGrid); neighbourDataGrid.SetDataGridCosts(dataGridCosts); diff --git a/src/Learning/KWDataPreparation/KWDataGridOptimizer.h b/src/Learning/KWDataPreparation/KWDataGridOptimizer.h index 208d49053..e554015f3 100644 --- a/src/Learning/KWDataPreparation/KWDataGridOptimizer.h +++ b/src/Learning/KWDataPreparation/KWDataGridOptimizer.h @@ -257,10 +257,9 @@ class KWDataGridVNSOptimizer : public Object // - Greedy merge optimization // - Post-optimization // - Post-optimization IV - double PROTO_VNSDataGridPostOptimizeVarPart(const KWDataGrid* initialDataGrid, - KWDataGridMerger* neighbourDataGrid, double dNeighbourDataGridCost, - KWDataGrid* mergedDataGrid, - KWDataGrid* partitionedReferencePostMergedDataGrid) const; + double VNSDataGridPostOptimizeVarPart(const KWDataGrid* initialDataGrid, KWDataGridMerger* neighbourDataGrid, + double dNeighbourDataGridCost, KWDataGrid* mergedDataGrid, + KWDataGrid* partitionedReferencePostMergedDataGrid) const; // CH IV Begin // Pilotage de la meta heuristique VNS, avec des voisinages successifs de taille décroissante @@ -269,13 +268,15 @@ class KWDataGridVNSOptimizer : public Object // des grilles de meilleur cout apres post-fusion En sortie : optimizedDataGrid contient la grille antecedent // avant post-fusion de la meilleure grille post-fusionne Le cout renvoye est le cout de cette optimizedDataGrid // dBestMergedDataGridCost contient le cout de la meilleure grille apres post-fusion (meilleur cout) - // CH IV Refactoring: proto en vue de fusionner la methode avec VNSOptimizeDataGrid (plnate actuellement) - double PROTO_VNSOptimizeVarPartDataGrid(const KWDataGrid* initialDataGrid, double dDecreaseFactor, - int nMinIndex, int nMaxIndex, KWDataGrid* optimizedDataGrid, - double dOptimizedDataGridCost, double& dBestMergedDataGridCost) const; + // CH IV Refactoring: proto en vue de fusionner la methode avec VNSOptimizeDataGrid double VNSOptimizeVarPartDataGrid(const KWDataGrid* initialDataGrid, double dDecreaseFactor, int nMinIndex, int nMaxIndex, KWDataGrid* optimizedDataGrid, double dOptimizedDataGridCost, double& dBestMergedDataGridCost) const; + // CH IV Refactoring: ancienne version avant decoupage en VNSOptimizeVarPartDataGrid et VNSDataGridPostOptimizeVarPart + double DEPRECATED_VNSOptimizeVarPartDataGrid(const KWDataGrid* initialDataGrid, double dDecreaseFactor, + int nMinIndex, int nMaxIndex, KWDataGrid* optimizedDataGrid, + double dOptimizedDataGridCost, + double& dBestMergedDataGridCost) const; // CH IV End // Optimisation d'une solution diff --git a/src/Learning/MODL/MODL.cpp b/src/Learning/MODL/MODL.cpp index d2dd00629..c379e44c4 100644 --- a/src/Learning/MODL/MODL.cpp +++ b/src/Learning/MODL/MODL.cpp @@ -35,7 +35,6 @@ int main(int argc, char** argv) // Choix du repertoire de lancement pour le debugage sous Windows (a commenter apres fin du debug) // SetWindowsDebugDir("Standard", "IrisLight"); - SetWindowsDebugDir("BugsMultiTables", "BugDeployedCoclustering"); // Parametrage des logs memoires depuis les variables d'environnement, pris en compte dans KWLearningProject // KhiopsMemStatsLogFileName, KhiopsMemStatsLogFrequency, KhiopsMemStatsLogToCollect diff --git a/src/Learning/MODL_Coclustering/MODL_Coclustering.cpp b/src/Learning/MODL_Coclustering/MODL_Coclustering.cpp index f50a79823..1fd1b50ab 100644 --- a/src/Learning/MODL_Coclustering/MODL_Coclustering.cpp +++ b/src/Learning/MODL_Coclustering/MODL_Coclustering.cpp @@ -36,6 +36,7 @@ int main(int argc, char** argv) // Choix du repertoire de lancement pour le debugage sous Windows (a commenter apres fin du debug) //SetWindowsDebugDir("y_CoclusteringIV_Standard", "IrisLight"); //SetWindowsDebugDir("y_CoclusteringIV_Standard", "Iris"); + //SetWindowsDebugDir("Standard", "Iris"); // Point d'arret sur l'allocation d'un bloc memoire // MemSetAllocIndexExit(77);