Back to index

fet  5.18.0
generate.h
Go to the documentation of this file.
00001 /*
00002 File generate.h
00003 */
00004 
00005 /*
00006 Copyright 2007 Lalescu Liviu.
00007 
00008 This file is part of FET.
00009 
00010 FET is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU General Public License as published by
00012 the Free Software Foundation; either version 2 of the License, or
00013 (at your option) any later version.
00014 
00015 FET is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with FET; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 #ifndef GENERATE_H
00026 #define GENERATE_H
00027 
00028 #include "timetable_defs.h"
00029 #include "solution.h"
00030 
00031 #include <QTextStream>
00032 
00033 class Activity;
00034 
00035 class QWidget;
00036 
00037 //a probabilistic function to say if we can skip a constraint based on its percentage weight
00038 bool skipRandom(double weightPercentage);
00039 
00040 //for sorting slots in ascending order of potential conflicts
00041 bool compareFunctionGenerate(int i, int j);
00042 
00046 class Generate: public QObject{
00047        Q_OBJECT
00048 
00049 public:
00050        Generate();
00051        ~Generate();
00052        
00053        inline void addAiToNewTimetable(int ai, const Activity* act, int d, int h);
00054        inline void removeAiFromNewTimetable(int ai, const Activity* act, int d, int h);
00055        
00056        inline void getTchTimetable(int tch, const QList<int>& conflActivities);
00057        inline void getSbgTimetable(int sbg, const QList<int>& conflActivities);
00058        
00059        inline void removeAi2FromTchTimetable(int ai2);
00060        inline void removeAi2FromSbgTimetable(int ai2);
00061 
00062        inline void updateTeachersNHoursGaps(Activity* act, int ai, int d);
00063        inline void updateSubgroupsNHoursGaps(Activity* act, int ai, int d);
00064        
00065        inline void updateTchNHoursGaps(int tch, int d);
00066        inline void updateSbgNHoursGaps(int sbg, int d);
00067        
00068        inline void tchGetNHoursGaps(int tch);
00069        inline void teacherGetNHoursGaps(int tch);
00070        inline bool teacherRemoveAnActivityFromBeginOrEnd(int tch, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00071        inline bool teacherRemoveAnActivityFromAnywhere(int tch, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00072        inline bool teacherRemoveAnActivityFromBeginOrEndCertainDay(int tch, int d2, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00073        inline bool teacherRemoveAnActivityFromAnywhereCertainDay(int tch, int d2, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00074 
00075        inline bool teacherRemoveAnActivityFromAnywhereCertainDayCertainActivityTag(int tch, int d2, int actTag, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00076 
00077        inline void sbgGetNHoursGaps(int sbg);
00078        inline void subgroupGetNHoursGaps(int sbg);
00079        inline bool subgroupRemoveAnActivityFromBegin(int sbg, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00080        inline bool subgroupRemoveAnActivityFromEnd(int sbg, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00081        inline bool subgroupRemoveAnActivityFromBeginOrEnd(int sbg, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00082        inline bool subgroupRemoveAnActivityFromAnywhere(int sbg, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00083        inline bool subgroupRemoveAnActivityFromBeginCertainDay(int sbg, int d2, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00084        inline bool subgroupRemoveAnActivityFromEndCertainDay(int sbg, int d2, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00085        inline bool subgroupRemoveAnActivityFromAnywhereCertainDay(int sbg, int d2, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00086 
00087        inline bool subgroupRemoveAnActivityFromAnywhereCertainDayCertainActivityTag(int sbg, int d2, int actTag, int level, int ai, QList<int>& conflActivities, int& nConflActivities, int& removedActivity);
00088        
00089        inline bool checkActivitiesOccupyMaxDifferentRooms(const QList<int>& globalConflActivities, int rm, int level, int ai, QList<int>& tmp_list);
00090 
00091        //only one out of sbg and tch is >=0, other one is -1
00092        inline bool checkBuildingChanges(int sbg, int tch, const QList<int>& globalConflActivities, int rm, int level, const Activity* act, int ai, int d, int h, QList<int>& tmp_list);
00093        inline bool chooseRoom(const QList<int>& listOfRooms, const QList<int>& globalConflActivities, int level, const Activity* act, int ai, int d, int h, int& roomSlot, int& selectedSlot, QList<int>& localConflActivities);
00094        inline bool getHomeRoom(const QList<int>& globalConflActivities, int level, const Activity* act, int ai, int d, int h, int& roomSlot, int& selectedSlot, QList<int>& localConflActivities);
00095        inline bool getPreferredRoom(const QList<int>& globalConflActivities, int level, const Activity* act, int ai, int d, int h, int& roomSlot, int& selectedSlot, QList<int>& localConflActivities, bool& canBeUnspecifiedPreferredRoom);
00096        inline bool getRoom(int level, const Activity* act, int ai, int d, int h, int& roomSlot, int& selectedSlot, QList<int>& conflActivities, int& nConflActivities);
00097 
00098        Solution c;
00099        
00100        int nPlacedActivities;
00101        
00102        //difficult activities
00103        int nDifficultActivities;
00104        int difficultActivities[MAX_ACTIVITIES];
00105        
00106        int searchTime; //seconds
00107        
00108        int timeToHighestStage; //seconds
00109        
00110        bool abortOptimization;
00111        
00112        bool precompute(QWidget* parent, QTextStream* maxPlacedActivityStream=NULL);
00113        
00114        void generate(int maxSeconds, bool& impossible, bool& timeExceeded, bool threaded, QTextStream* maxPlacedActivityStream=NULL);
00115        
00116        void moveActivity(int ai, int fromslot, int toslot, int fromroom, int toroom);
00117        
00118        void randomSwap(int ai, int level);
00119        
00120 signals:
00121        void activityPlaced(int);
00122        
00123        void simulationFinished();
00124        
00125        void impossibleToSolve();
00126        
00127 private:
00128        bool isThreaded;
00129 };
00130 
00131 #endif