Page principale | Hiérarchie des classes | Liste des composants | Liste des fichiers | Composants

incop.h

00001 
00005 class OpProblem;
00006 class IncompleteAlgorithm;
00007 class Metaheuristic;
00008 class NeighborhoodSearch;
00009 class Move;
00010 
00011 
00012 
00016 /* the main class Configuration */
00017 
00018 class Configuration 
00019 
00020 {public :
00021   int nbvar;
00023 /* the current values of the variables : implemented with an array of integers*/
00024   int* config;
00026 /* the configuration value */
00027   int valuation;
00029 /* the variables taking part to a conflict : implemented with a vector */
00030   vector<int> var_conflict;     
00032 /* indicates if the configuration has been regrouped before (for GWW) */
00033   int regrouped;
00034   virtual ~Configuration();
00035   Configuration();
00036   Configuration(int nbvar);
00038 /* copy a configuration config2 into this */
00039   virtual void copy_element (Configuration* config2);
00041 /* initialization to 0 of the conflict datastructure */
00042   virtual void init_conflicts ();
00044 /* store the conflict of (var,val) incremented by incr */
00045   virtual void incr_conflicts (int var, int val, int index, int incr);
00046 
00048 /* store the number of conflicts nbconf of (var,val) in the conflict datastructure */
00049   virtual  void set_conflicts (int var, int val, int index, int nbconf);
00050 
00052 /* get the number of conflicts (var,val) stored in the conflict datastructure*/
00053   virtual  int get_conflicts (int var, int val, int index);
00055 /* get the number of conflicts of (var,val), computed if not stored */
00056   virtual  int get_conflicts_problem (OpProblem* problem, int var, int val);
00057 
00059 /* update the conflict datastructure after a move is done */
00060   virtual void update_conflicts(OpProblem* problem, Move* move);
00061 };
00062 
00064 /* CSPConfiguration : for the CSPs */
00065 class CSPConfiguration: public Configuration
00066 {
00067  public :
00068  CSPConfiguration (int nbvar);
00069  CSPConfiguration(int nbvar, int nbcol);
00070 };
00071 
00074 /* Incremental evaluation with storage in the conflict datastructure
00075 tabconflicts the participation of the current values of the configuration */
00076 class IncrCSPConfiguration : public CSPConfiguration
00077 { public : 
00078   int* tabconflicts;
00079   IncrCSPConfiguration (int nbvar);
00080   IncrCSPConfiguration(int nbvar, int nbcol);
00081   ~IncrCSPConfiguration();
00082   void copy_element (Configuration* config2);
00083   void init_conflicts ();
00084   void incr_conflicts (int var, int val , int index, int incr);
00085   void set_conflicts (int var, int val, int index,  int nbconf);
00086   int get_conflicts (int var, int val , int index);
00087   int get_conflicts_problem (OpProblem* problem, int var, int val);
00088   virtual  void set_variableconflicts (int var, int nbconf);
00089   void update_conflicts(OpProblem* problem, Move* move);                
00090 };
00091 
00094 /* Full incremental evaluation : the participation of every value of every
00095 variable is stored in the 2 dimension array tabconflicts (variable, valueindex)
00096 */
00097 class FullincrCSPConfiguration : public CSPConfiguration
00098 { public :
00099   int tabconflictsize;
00100   int** tabconflicts;
00101   FullincrCSPConfiguration(int nbvar, int domainsize);
00102   ~FullincrCSPConfiguration();
00103   void copy_element (Configuration* config2);
00104   void init_conflicts ();
00105   void incr_conflicts (int var, int val , int index, int incr);
00106   void set_conflicts (int var, int val, int index, int nbconf);
00108 /* get the number of conflicts (var,val) stored in the conflict datastructure using the value index in the domain */
00109   int get_conflicts (int var, int val, int index);
00110   int get_conflicts_problem (OpProblem* problem, int var, int val);
00111   void update_conflicts(OpProblem* problem, Move* move);
00112 };
00113 
00115 /* root class Move */
00116 class Move 
00117 {public :
00118  int valuation;
00119  Move();
00120  virtual ~Move() {;};
00122 /* the test of equality of a move (used for searching a move in the tabu list) */
00123  virtual int eqmove(Move* move1);
00125 /* copy of move move1 into this */
00126  virtual void copymove(Move* move);
00128 /* the move to be put in the tabu list (to be implemented in the subclasses)*/
00129  virtual Move* computetabumove(Configuration* config){return 0;};
00130 };
00131 
00133 /* class CSPMove : a classical move for a CSP : variable, value */
00134 class CSPMove : public Move
00135 {public :
00136  int variable;
00137  int value;
00138  CSPMove();
00139  ~CSPMove() {;};
00140  int eqmove(Move* move);
00141  void copymove (Move* move);
00143 /* the move stored is the inverse of the move done */
00144  Move* computetabumove(Configuration* config);
00145 };
00146 
00147 
00149 /* Root class of Optimization Problems (minimization) */
00150 
00151 class OpProblem 
00152 {public :
00154 /* the best configuration found */
00155   Configuration* best_config;
00157 /* the number of variables */
00158   int nbvar;  
00160 /* given lower bound , is used as a stop condition when it is reached */
00161   int lower_bound;
00163 /* the current move being tested */
00164   Move* currentmove;
00166 /* the first feasible move tried in the neighborhood */
00167   Move* firstmove;
00169 /* the best move found in the neighborhood */
00170   Move* bestmove;
00171   OpProblem(){};
00172   virtual ~OpProblem(){};
00174 /* move execution (modification of the current configuration) */
00175   virtual void move_execution(Configuration* configuration, Move* move);
00177 /* update of  the conflict data structure (case IncrCSPConfiguration) */
00178   virtual void incr_update_conflicts(IncrCSPConfiguration* configuration,Move* move){};
00180 /* update of  the conflict data structure (case FullincrCSPConfiguration) */
00181   virtual void fullincr_update_conflicts(FullincrCSPConfiguration* configuration,Move* move){};
00183 /* creation of 3 Move objects (currentmove,bestmove,firstmove) */
00184   virtual void allocate_moves();
00186 /* creation of 1 Move object (the class of the Move depends on the problem) : this method
00187 is implemented in subclasses */
00188   virtual Move* create_move(){return 0;};
00190 /* adjustment of the neighborhood parameters (when the size of the actual neighborhood is greater than maxneighbors) */
00191   virtual void adjust_parameters(Configuration* configuration, int & maxneighbors, int & minneighbors){};
00193 /* next move to be tested (implemented in subclasses)*/
00194   virtual void next_move(Configuration* configuration, Move* move, NeighborhoodSearch* nbhs){}; 
00196 /* random assignment of the variables of a configuration */
00197   virtual void random_configuration(Configuration* configuration){};
00199 /* analysis of the best configuration */
00200   virtual void best_config_analysis(){};
00202 /* writing the best solution */
00203   virtual void best_config_write(){};
00204 
00206 /* verification of the best solution (its cost is recomputed) */
00207   virtual void best_config_verification();
00209 /* initialization of the population of size populationsize */
00210   virtual void init_population (Configuration** population,int populationsize) {};
00212 /* create a configuration (the exact class depends on the problem and must defined in subclasses) */
00213   virtual Configuration* create_configuration(){return 0;};
00215 /* computation of the participation of (var,val) to the configuration evaluation */
00216   virtual int compute_conflict (Configuration* configuration,int var, int val) {return 0;};
00218 /* evaluation of a configuration */
00219   virtual int config_evaluation(Configuration* configuration) {return 0;};
00221 /* evaluation of a configuration if the move is done */
00222   virtual int move_evaluation (Configuration* configuration,Move* move){return 0;};
00224 /* valueindex in the domain to value */
00225   virtual int index2value (int index, int var) {return index;};
00227 /* valueindex of value in its domain*/
00228   virtual int value2index(int value,int var) {return value;};
00230 /* compute the variables participating to a conflict in the configuration */
00231   virtual void compute_var_conflict (Configuration* configuration) {};
00232 };
00233   
00236 /* Class NeighborhoodSearch : how the neighborhood is explored */
00237 
00238 class NeighborhoodSearch
00239 {public :
00241 /* minimum number of visited neighbors */
00242   int minneighbors;
00244 /* maximum number of explored neighbors */
00245   int maxneighbors;
00248 /* behavior indicator when the neighborhood is exhausted and no neighbor has been accepted :
00249 0 stagnation, 1 the 1st feasible move is selected, 2 the best feasible move is selected */
00250   int finished;
00252 /* restriction indicator to variables participating in a conflict (0 no restriction, 1 restriction) */
00253   int var_conflict;
00255 /* restriction indicator to best values of a variable (0 no restriction , 1 restriction) */
00256   int val_conflict;
00257   NeighborhoodSearch( int maxneigh, int minneigh, int finish, int var_conf, int val_conf);
00258   int returnbestmove();
00259 };
00260 
00261 
00264 /* Root class of algorithms */
00265 
00266 class IncompleteAlgorithm
00267 {public :
00268   string methodname;
00271 /* a threshold can be used to forbid moves above this threshold (used in LSAlgorithms implementing walks inside GWW)*/
00272   int threshold;
00273   virtual ~IncompleteAlgorithm(){};
00275 /* walk for a particule */
00276   virtual void randomwalk (OpProblem* problem, Configuration* configuration);
00277   virtual void initthreshold(Configuration** population, int popsize){;};
00279 /* Run the algorithm on a population (array of configurations) */
00280   virtual void run (OpProblem *problem,Configuration ** population);
00281 
00282 };
00283 
00286 /* The class of local search algorithm on one particle : the random walk is 
00287 parameterized with the walk lengh,a neighborhood and a metaheuristics */
00288 
00289 class LSAlgorithm: public IncompleteAlgorithm
00290 {public :
00292 /* walk length */
00293   int walklength;
00295 /* the way the neighborhood is explored */
00296   NeighborhoodSearch * nbhsearch;  
00298 /* the metaheuristics used */
00299   Metaheuristic* mheur;
00301 /* number of move tries  (for statistics) */
00302   int nhtries;
00303   double avgnhtries;
00304   double avgsqnhtries;
00306 /* number of moves done */
00307   int nbmoves;
00308   LSAlgorithm(int nbmov);
00309   ~LSAlgorithm();
00311 /* feasability of a move (under or at threshold level pour GWW walks) */
00312   virtual int isfeasible(Move* move);
00313   void randomwalk   (OpProblem* problem, Configuration* configuration);
00316 /* Neighborhood exploration algorithm for selecting and do a move from the current configuration :
00317 returns 1 if a move has been done and 0 if no move has been done */
00318   virtual int configurationmove(OpProblem* problem,Configuration* configuration);
00319   void initthreshold(Configuration** population, int popsize);
00320   void run (OpProblem *problem, Configuration ** population);
00322 /* test if a global best configuration has been found (returns 1 in that case) */
00323   int test_bestfound( int value, int nbmov);
00324 
00325 };
00326 
00328 /* Root class for Metaheuritics */
00329 class Metaheuristic
00330 {public :
00331   virtual ~Metaheuristic(){};
00333 /* update of the metaheuristic data just before a move is performed */
00334   virtual void executebeforemove(Move* move, Configuration* configuration,OpProblem* problem);
00336 /* initialization of the meteheuristic data at the beginning of a local search */
00337   virtual void reinit();
00339 /* acceptance condition of a move : returns 1 if the move is accepted */
00340   virtual int acceptance(Move* move,Configuration*  config);
00341 };
00342 
00345 /* Walk with using a tabu list : this list of moves is implemented by a list<Move*> structure , the
00346 actual class of the moves depend on the problems */
00347 class TabuSearch: public Metaheuristic
00348 {public :
00350 /* maximum length of the tabulist */
00351   int tabulength;
00353 /* tabu list : implemented FIFO */
00354   list<Move*> move_list;
00355   TabuSearch(int tabul);
00357 /* acceptance of a move : not in the tabulist (the aspiration criterion of a best is in the configurationmove algorithm) */
00358   int acceptance (Move* move, Configuration* config);
00360 /* test of non presence in the tabulist (use of eqmove method) */
00361   int  nontabumove (Move* move);
00363 /* updating of the tabulist which is managed as a FIFO of maximum length tabulength */
00364   void executebeforemove(Move* move, Configuration* configuration, OpProblem* problem);
00366 /* the tabu list is cleared */
00367   void reinit();
00368 };
00369 
00371 /* Metropolis algorithm : a unique parameter - a constant temperature */
00372 class Metropolis: public Metaheuristic
00373 {public :
00374   double temperature;
00375   Metropolis(double temp);
00378 /* the classical Metropolis formula for accepting a bad move :  probability =  exp (-temperature/evaluationdelta) */
00379   int acceptance (Move* move, Configuration* config);
00380 };
00381 
00385 /* Threshold accepting Metaheuristics : a move must no deteriorate the evaluation more than the
00386 current threshod : the threshold goes down linearly from thresholdinit to 0 */
00387 class ThresholdAccepting: public Metaheuristic
00388 {public :
00390 /* initial threshold */
00391   double thresholdinit;
00393 /* constant step to lower the threshold */
00394   double delta;
00396 /* current value of the threshold */
00397   double thresholdaccept; // le seuil tel que géré par TA
00398 /* constructeur : 2 arguments seuil initial maxthreshold et nombre de pas, 
00399 le pas constant delta de baisse du seuil est calculé*/
00402   ThresholdAccepting(double maxthreshold, int walklength);
00404 /* acceptance condition : being under or at the threshold */
00405   int acceptance (Move* move,Configuration* config);
00407 /* the threshold is lowered by delta */
00408   void executebeforemove(Move* move, Configuration * configuration, OpProblem* problem);
00410 /* the threshold is initialized at thresholdinit */
00411   void reinit();
00412 };
00413 
00415 /* Simulated Annealing : linear temperature descent from inittemperature to 0*/
00416 class SimulatedAnnealing: public Metaheuristic
00417 {public :
00419 /* initial temperature */
00420   double inittemperature;
00422 /* constant step for lowering the temperature */ 
00423   double delta;
00425 /* current temperature */
00426   double temperature; 
00427 /* Constructeur : 2 arguments : température initiale et longueur de marche */
00430   SimulatedAnnealing(double initialtemperature, int walklength);
00435 /* Acceptance function of the temperature : classical simulated annealing formula
00436 for accepting a bad move :  probability =  exp (-temperature/evaluationdelta) */
00437   int acceptance (Move* move, Configuration* config);
00439 /* the temperature is lowered by delta */
00440   void executebeforemove(Move* move, Configuration * configuration, OpProblem* problem);
00441   void reinit();
00442 };
00443 
00444 
00446 /* Special Tabu search with complementary acceptance condition depending on the move direction */
00447 
00448 
00449 //                          liste taboue 
00450 
00451 class TabuAcceptingrate: public TabuSearch
00452 {public :
00454   /* probability of acceptance of a worsening move */
00455   float Pd;       
00457   /* probability of acceptance of a move with same cost */
00458   float P0;        
00459   TabuAcceptingrate(int tabul, float Pd, float P0);
00461 /* Acceptance condition : non tabu and probabilities depending on the move direction */
00462   int acceptance (Move* move, Configuration* config);
00463 };
00464 
00465 
00467 /* Random walk : every feasible neighbor is accepted */
00468 class RandomSearch: public Metaheuristic
00469 {public :
00470   RandomSearch();
00471   int acceptance (Move* move, Configuration* config);
00472 };
00473 
00475 /* Greedy walk : a neighbor with better or same cost as the current configuration is accepted */
00476 class GreedySearch: public Metaheuristic
00477 {public :
00478   GreedySearch();
00479   int acceptance (Move* move, Configuration* config);
00480 };
00481 
00482 //-------------------------------------------------------------------------------------------------
00483 
00484 
00489 /* the GWW (Go with the winners) algorithms : the different subclasses 
00490 differ by the way a threshold is managed and the particles are regrouped */
00491 
00492 class GWWAlgorithm: public IncompleteAlgorithm
00493 {public :
00495 /* number of particles */
00496   int populationsize;
00499 /* walk indicator : a walk is performed only is the particle has been regrouped : (1 yes, 0 no)
00500 (useful for a standard GWW with random walk (and no local search)) */
00501   int regrouptest;
00503 /* parameter if the threshold is lowered at the last move of the walk 
00504 (for trying to avoid the particle to be redistributed  (1 yes, 0 no)*/
00505   int lastmovedescent;
00507 /* elitism parameter : is the best particle put again in the population at each regroupment ( 1 yes, 0 no) */
00508   int elitism;
00510 /* parameter for stopping the walk in case of stagnation (1 yes, 0 no) */ 
00511   int nomovestop;
00513 /* the threshold decrement (compted by thresholdcomputedelta) */
00514   int thresholddelta;
00516 /* the maximum number of iterations : useful when no threshold is managed (NothresholdGWWAlgorithm) */
00517   int nbiteration;
00519 /* number of threshold changes (for the statistics) */
00520   int thresholdchanges;
00522 /* total number of move tries between 2 regroupments (for the statistics) */
00523   int total_nhtries;
00525 /* total number of moves between 2 regroupments (for the statistics) */
00526   int total_nbmoves;
00528 /* the local search algorithm used */
00529   LSAlgorithm* walkalgorithm;
00531   ~GWWAlgorithm();
00533 /* local search on the whole population */
00534   virtual  void populationrandomwalk (OpProblem* problem, Configuration** population);
00536 /* the number of particles at the threshold (for statistics) , the population being yet sorted at the function call*/
00537   virtual int nb_threshold_population(Configuration** population);
00539 /* a local search for a particle */
00540   void randomwalk   (OpProblem* problem, Configuration* configuration);
00542 /* intialization of the threshold */
00543   void initthreshold(Configuration** population, int popsize);
00545 /* method for lowering the threshold( the delta has already been computed) */
00546   virtual void thresholdupdate();
00548 /* method for computing the threshold decrement */
00549   virtual void thresholdcomputedelta(Configuration** population);
00551 /* main function for running the algorithm */
00552   void run (OpProblem *problem, Configuration** population);
00554 /* regrouping of the best particles on the good ones */
00555   virtual  void regrouping(Configuration** population);
00557 /* in case of elitism, the best particle is put into the population */
00558   void populationkeepbest (OpProblem* problem, Configuration** population);
00560 /* incrementing the threshold updates counter (for the statistics) */
00561   virtual  void thresholdchangesupdate();
00562 };
00563 
00565 /* Abstract class : GWW managing a threshold */
00566 class ThresholdGWWAlgorithm : public GWWAlgorithm
00567 {public :
00568   void thresholdupdate();
00569 void thresholdchangesupdate();
00570 void initthreshold(Configuration** population, int popsize);
00571 int nb_threshold_population(Configuration** population);
00572 };
00573 
00574 
00576 /* Standard GWW : threshold descent with a fixed rate */
00577 class StandardGWWAlgorithm : public ThresholdGWWAlgorithm
00578 {public :
00580 /* threshold descent constant rate */
00581   double thresholddescent;
00583 /* minimum of the threshold (corresponds generally to a known lowerbound) */
00584   int thresholdmin;  
00585   void regrouping(Configuration** population);
00586   StandardGWWAlgorithm(int population_size, int grtest,int lastmove, int elitisme,int stop, double thresdescent,int threshmin );
00587   void thresholdcomputedelta(Configuration** population);
00588 };
00589 
00591 /* StandardGWW with a threshold descent at least until the worst particle */
00592 class FastStandardGWWAlgorithm: public StandardGWWAlgorithm
00593 {public :
00594    void thresholdcomputedelta(Configuration** population);
00595    FastStandardGWWAlgorithm(int population_size, int grtest,int lastmove, int elitisme, int stop, double thresdescent,int threshmin );  
00596 };
00597 
00599 /* GWW with a threshold descent such as a given number of particles is regrouped */
00600 class AdaptiveGWWAlgorithm : public ThresholdGWWAlgorithm
00601 { public :
00603 /* number of bad particles to be regrouped on good ones */
00604   int nbkilled;
00605   AdaptiveGWWAlgorithm(int population_size, int grtest, int lastmove, int elitisme, int stop, int nbkilled );
00606   void regrouping(Configuration** population);
00607   void thresholdcomputedelta(Configuration** population);
00608 };
00609 
00612 /* GWW with a threshold descent at the lowest value obtained by AdaptiveGWWAlgorithm et FastStandardGWWAlgorithm
00613 using a number of particles to be redistributed and a rate */
00614 class FastAdaptGWWAlgorithm: public AdaptiveGWWAlgorithm
00615 {public :
00617 /* threshold descent rate */
00618   double thresholddescent;
00619   int nbmaxkilled;
00620   FastAdaptGWWAlgorithm(int population_size, int grtest, int lastmove, int elitisme, int stop, int nbkilled, int maxkilled, double thresholddescent);
00621   void thresholdcomputedelta(Configuration** population);
00622 };
00623 
00625 /* GWW with a descent depending on a distance between the worst and the median particle */
00626 class MedianAdaptGWWAlgorithm: public AdaptiveGWWAlgorithm
00627 {public :
00629 /* descent rate : porcentage of the distance between the worst and the median particles (between 0 and 1) */
00630   double mediandescent;
00631   MedianAdaptGWWAlgorithm(int population_size, int grtest, int lastmove, int elitisme, int stop, double mediandescent);
00632   void thresholdcomputedelta(Configuration** population);
00633 };
00634 
00636 /* GWW with a descent depending on a distance between the worst and the best particle */
00637 class BestAdaptGWWAlgorithm: public AdaptiveGWWAlgorithm
00638 {public :
00640 /* descent rate : porcentage of the distance between the worst and the best particles (between 0 and 1) */
00641 
00642   double bestdescent;
00643   BestAdaptGWWAlgorithm(int population_size, int grtest, int lastmove, int elitisme, int stop, double bestdescent);
00644   void thresholdcomputedelta(Configuration** population);
00645 };
00646 
00647 
00648 
00650 /* GWW without threshold management : 2 parameters : number of particles redistributed at each iteration , number of iterations */
00651 class NothresholdGWWAlgorithm : public GWWAlgorithm 
00652 {public :
00653   NothresholdGWWAlgorithm(int population_size, int grtest, int lastmove, int elitisme, int stop,
00654         int killed,  int nbiter);
00655   void regrouping(Configuration** population);
00657 /* number of particles to be regrouped at each iteration */
00658   int nbkilled;
00659 };
00660 
00661 
00662 
00663 

Généré le Fri Sep 26 16:54:19 2003 pour INCOP par doxygen 1.3.3