Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintStudentsSetMinGapsBetweenBuildingChanges Class Reference

#include <spaceconstraint.h>

Inheritance diagram for ConstraintStudentsSetMinGapsBetweenBuildingChanges:
Inheritance graph
[legend]
Collaboration diagram for ConstraintStudentsSetMinGapsBetweenBuildingChanges:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ConstraintStudentsSetMinGapsBetweenBuildingChanges ()
 ConstraintStudentsSetMinGapsBetweenBuildingChanges (double wp, QString st, int mg)
bool computeInternalStructure (QWidget *parent, Rules &r)
 Computes the internal structure for this constraint.
QString getXmlDescription (Rules &r)
 Returns an XML description of this constraint.
bool hasInactiveActivities (Rules &r)
QString getDescription (Rules &r)
 Returns a small description string for this constraint.
QString getDetailedDescription (Rules &r)
 Returns a detailed description string for this constraint.
double fitness (Solution &c, Rules &r, QList< double > &cl, QList< QString > &dl, QString *conflictsString=NULL)
 The function that calculates the fitness of a solution, according to this constraint.
bool isRelatedToActivity (Activity *a)
 Returns true if this constraint is related to this activity.
bool isRelatedToTeacher (Teacher *t)
 Returns true if this constraint is related to this teacher.
bool isRelatedToSubject (Subject *s)
 Returns true if this constraint is related to this subject.
bool isRelatedToActivityTag (ActivityTag *s)
 Returns true if this constraint is related to this activity tag.
bool isRelatedToStudentsSet (Rules &r, StudentsSet *s)
 Returns true if this constraint is related to this students set.
bool isRelatedToRoom (Room *r)
 Returns true if this constraint is related to this room.
bool hasWrongDayOrHour (Rules &r)
bool canRepairWrongDayOrHour (Rules &r)
bool repairWrongDayOrHour (Rules &r)

Public Attributes

QList< int > iSubgroupsList
int minGapsBetweenBuildingChanges
QString studentsName
double weightPercentage
 The weight (percentage) of this constraint.
bool active
QString comments
int type
 Specifies the type of this constraint (using the above constants).

Detailed Description

Definition at line 1091 of file spaceconstraint.h.


Constructor & Destructor Documentation


Member Function Documentation

Implements SpaceConstraint.

Definition at line 5034 of file spaceconstraint.cpp.

{
       assert(hasWrongDayOrHour(r));

       return true;
}

Here is the call graph for this function:

Computes the internal structure for this constraint.

Implements SpaceConstraint.

Definition at line 4771 of file spaceconstraint.cpp.

{
       this->iSubgroupsList.clear();
       
       StudentsSet* ss=r.searchAugmentedStudentsSet(this->studentsName);
                     
       if(ss==NULL){
              QMessageBox::warning(parent, tr("FET warning"),
               tr("Constraint students set min gaps between building changes is wrong because it refers to inexistent students set."
               " Please correct it (removing it might be a solution). Please report potential bug. Constraint is:\n%1").arg(this->getDetailedDescription(r)));
                                                                              
              return false;
       }                                                                                   
       
       if(ss->type==STUDENTS_SUBGROUP){
              int tmp;
              tmp=((StudentsSubgroup*)ss)->indexInInternalSubgroupsList;
              assert(tmp>=0);
              assert(tmp<r.nInternalSubgroups);
              this->iSubgroupsList.append(tmp);
       }
       else if(ss->type==STUDENTS_GROUP){
              StudentsGroup* stg=(StudentsGroup*)ss;
              for(int i=0; i<stg->subgroupsList.size(); i++){
                     StudentsSubgroup* sts=stg->subgroupsList[i];
                     int tmp;
                     tmp=sts->indexInInternalSubgroupsList;
                     assert(tmp>=0);
                     assert(tmp<r.nInternalSubgroups);
                     this->iSubgroupsList.append(tmp);
              }
       }
       else if(ss->type==STUDENTS_YEAR){
              StudentsYear* sty=(StudentsYear*)ss;
              for(int i=0; i<sty->groupsList.size(); i++){
                     StudentsGroup* stg=sty->groupsList[i];
                     for(int j=0; j<stg->subgroupsList.size(); j++){
                            StudentsSubgroup* sts=stg->subgroupsList[j];
                            int tmp;
                            tmp=sts->indexInInternalSubgroupsList;
                            assert(tmp>=0);
                            assert(tmp<r.nInternalSubgroups);
                            this->iSubgroupsList.append(tmp);
                     }
              }
       }
       else
              assert(0);

       return true;
}

Here is the call graph for this function:

double ConstraintStudentsSetMinGapsBetweenBuildingChanges::fitness ( Solution c,
Rules r,
QList< double > &  cl,
QList< QString > &  dl,
QString *  conflictsString = NULL 
) [virtual]

The function that calculates the fitness of a solution, according to this constraint.

We need the rules to compute this fitness factor. We need also the allocation of the activities on days and hours. If conflictsString!=NULL, it will be initialized with a text explaining where this restriction is broken.

Implements SpaceConstraint.

Definition at line 4895 of file spaceconstraint.cpp.

{
       //if the matrix roomsMatrix is already calculated, do not calculate it again!
       if(!c.roomsMatrixReady){
              c.roomsMatrixReady=true;
              rooms_conflicts = c.getRoomsMatrix(r, roomsMatrix);

              c.changedForMatrixCalculation=false;
       }

       int nbroken=0;
       
       foreach(int sbg, this->iSubgroupsList){
              //Better, less memory
              StudentsSubgroup* sts=r.internalSubgroupsList[sbg];
              int crtBuildingsTimetable[MAX_DAYS_PER_WEEK][MAX_HOURS_PER_DAY];
              for(int d2=0; d2<r.nDaysPerWeek; d2++)
                     for(int h2=0; h2<r.nHoursPerDay; h2++)
                            crtBuildingsTimetable[d2][h2]=-1;
                            
              foreach(int ai, sts->activitiesForSubgroup)
                     if(c.times[ai]!=UNALLOCATED_TIME){
                            int d2=c.times[ai]%r.nDaysPerWeek;
                            int h2=c.times[ai]/r.nDaysPerWeek;
                            
                            for(int dur=0; dur<r.internalActivitiesList[ai].duration; dur++){
                                   assert(h2+dur<r.nHoursPerDay);
                                   assert(crtBuildingsTimetable[d2][h2+dur]==-1);
                                   if(c.rooms[ai]!=UNSPECIFIED_ROOM && c.rooms[ai]!=UNALLOCATED_SPACE){
                                          assert(c.rooms[ai]>=0 && c.rooms[ai]<r.nInternalRooms);
                                          crtBuildingsTimetable[d2][h2+dur]=r.internalRoomsList[c.rooms[ai]]->buildingIndex;
                                   }
                            }
                     }

              for(int d2=0; d2<r.nDaysPerWeek; d2++){
                     int h2;
                     for(h2=0; h2<r.nHoursPerDay; h2++)
                            if(crtBuildingsTimetable[d2][h2]!=-1)
                                   break;

                     int crt_building=-1;                             
                     if(h2<r.nHoursPerDay)
                            crt_building=crtBuildingsTimetable[d2][h2];
                     
                     int cnt_gaps=0;
                     
                     for(h2++; h2<r.nHoursPerDay; h2++){
                            if(crtBuildingsTimetable[d2][h2]!=-1){
                                   if(crtBuildingsTimetable[d2][h2]==crt_building)
                                          cnt_gaps=0;
                                   else{
                                          if(cnt_gaps<this->minGapsBetweenBuildingChanges){
                                                 nbroken++;
                                          
                                                 if(conflictsString!=NULL){
                                                        QString s=tr("Space constraint students set min gaps between building changes broken for students=%1 on day %2")
                                                               .arg(this->studentsName)
                                                               .arg(r.daysOfTheWeek[d2]);
                                                        s += ". ";
                                                        s += tr("This increases the conflicts total by %1").arg(CustomFETString::number(weightPercentage/100*1));
                                   
                                                        dl.append(s);
                                                        cl.append(weightPercentage/100*1);
                                          
                                                        *conflictsString+=s+"\n";
                                                 }
                                          }
                                          
                                          crt_building=crtBuildingsTimetable[d2][h2];
                                          cnt_gaps=0;
                                   }
                            }
                            else
                                   cnt_gaps++;
                     }
              }
       }

       if(this->weightPercentage==100)
              assert(nbroken==0);

       return weightPercentage/100 * nbroken;
}

Here is the call graph for this function:

Returns a small description string for this constraint.

Implements SpaceConstraint.

Definition at line 4846 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);

       QString begin=QString("");
       if(!active)
              begin="X - ";

       QString end=QString("");
       if(!comments.isEmpty())
              end=", "+tr("C: %1", "Comments").arg(comments);

       QString s=tr("Students set min gaps between building changes"); s+=", ";

       s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this->weightPercentage));s+=", ";
       
       s+=tr("St:%1", "St means students").arg(this->studentsName);s+=", ";

       s+=tr("mG:%1", "mG means min gaps").arg(this->minGapsBetweenBuildingChanges);

       return begin+s+end;
}

Here is the call graph for this function:

Returns a detailed description string for this constraint.

Implements SpaceConstraint.

Definition at line 4869 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);

       QString s=tr("Space constraint"); s+="\n";

       s+=tr("Students set minimum gaps between building changes"); s+="\n";

       s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this->weightPercentage));s+="\n";

       s+=tr("Students=%1").arg(this->studentsName);s+="\n";

       s+=tr("Minimum gaps between building changes=%1").arg(this->minGapsBetweenBuildingChanges);s+="\n";

       if(!active){
              s+=tr("Active=%1", "Refers to a constraint").arg(yesNoTranslated(active));
              s+="\n";
       }
       if(!comments.isEmpty()){
              s+=tr("Comments=%1").arg(comments);
              s+="\n";
       }

       return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns an XML description of this constraint.

Implements SpaceConstraint.

Definition at line 4830 of file spaceconstraint.cpp.

                                                                                     {
       Q_UNUSED(r);

       QString s="<ConstraintStudentsSetMinGapsBetweenBuildingChanges>\n";

       s+="   <Weight_Percentage>"+CustomFETString::number(weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Students>"+protect(this->studentsName)+"</Students>\n";
       s+="   <Min_Gaps_Between_Building_Changes>"+CustomFETString::number(this->minGapsBetweenBuildingChanges)+"</Min_Gaps_Between_Building_Changes>\n";
              
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintStudentsSetMinGapsBetweenBuildingChanges>\n";

       return s;
}

Here is the call graph for this function:

Implements SpaceConstraint.

Definition at line 4823 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       
       return false;
}

Implements SpaceConstraint.

Definition at line 5026 of file spaceconstraint.cpp.

{
       if(minGapsBetweenBuildingChanges>r.nHoursPerDay)
              return true;
       
       return false;
}

Here is the caller graph for this function:

Returns true if this constraint is related to this activity.

Implements SpaceConstraint.

Definition at line 4986 of file spaceconstraint.cpp.

{
       Q_UNUSED(a);

       return false;
}

Returns true if this constraint is related to this activity tag.

Implements SpaceConstraint.

Definition at line 5007 of file spaceconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this room.

Implements SpaceConstraint.

Definition at line 5019 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       
       return false;
}

Returns true if this constraint is related to this students set.

Implements SpaceConstraint.

Definition at line 5014 of file spaceconstraint.cpp.

{
       return r.setsShareStudents(s->name, this->studentsName);
}

Here is the call graph for this function:

Returns true if this constraint is related to this subject.

Implements SpaceConstraint.

Definition at line 5000 of file spaceconstraint.cpp.

{
       Q_UNUSED(s);
       
       return false;
}

Returns true if this constraint is related to this teacher.

Implements SpaceConstraint.

Definition at line 4993 of file spaceconstraint.cpp.

{
       Q_UNUSED(t);
       
       return false;
}

Implements SpaceConstraint.

Definition at line 5041 of file spaceconstraint.cpp.

Here is the call graph for this function:


Member Data Documentation

bool SpaceConstraint::active [inherited]

Definition at line 102 of file spaceconstraint.h.

QString SpaceConstraint::comments [inherited]

Definition at line 104 of file spaceconstraint.h.

Definition at line 1096 of file spaceconstraint.h.

Definition at line 1100 of file spaceconstraint.h.

Definition at line 1102 of file spaceconstraint.h.

int SpaceConstraint::type [inherited]

Specifies the type of this constraint (using the above constants).

Definition at line 109 of file spaceconstraint.h.

The weight (percentage) of this constraint.

Definition at line 100 of file spaceconstraint.h.


The documentation for this class was generated from the following files: