Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintStudentsSetMaxGapsPerWeek Class Reference

This is a constraint. More...

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintStudentsSetMaxGapsPerWeek ()
 ConstraintStudentsSetMaxGapsPerWeek (double wp, int mg, const QString &st)
bool computeInternalStructure (QWidget *parent, Rules &r)
 Computes the internal structure for this constraint.
bool hasInactiveActivities (Rules &r)
QString getXmlDescription (Rules &r)
 Returns an XML description of this constraint.
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 (Rules &r, 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 hasWrongDayOrHour (Rules &r)
bool canRepairWrongDayOrHour (Rules &r)
bool repairWrongDayOrHour (Rules &r)

Public Attributes

int maxGaps
QString students
 The name of the students set for this constraint.
QList< int > iSubgroupsList
 The number of subgroups.
double weightPercentage
 The percentage weight of this constraint, 100% compulsory, 0% non-compulsory.
bool active
QString comments
int type
 Specifies the type of this constraint (using the above constants).

Detailed Description

This is a constraint.

It adds, to the fitness of the solution, a conflicts factor computed from the gaps existing in the timetable (regarding the specified students set).

Definition at line 1271 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintStudentsSetMaxGapsPerWeek::ConstraintStudentsSetMaxGapsPerWeek ( double  wp,
int  mg,
const QString &  st 
)

Definition at line 5918 of file timeconstraint.cpp.


Member Function Documentation

Implements TimeConstraint.

Definition at line 6150 of file timeconstraint.cpp.

{
       assert(hasWrongDayOrHour(r));
       
       return true;
}

Here is the call graph for this function:

bool ConstraintStudentsSetMaxGapsPerWeek::computeInternalStructure ( QWidget *  parent,
Rules r 
) [virtual]

Computes the internal structure for this constraint.

It returns false if the constraint is an activity related one and it depends on only inactive activities.

Implements TimeConstraint.

Definition at line 5926 of file timeconstraint.cpp.

                                                                                           {
       StudentsSet* ss=r.searchAugmentedStudentsSet(this->students);

       if(ss==NULL){
              QMessageBox::warning(parent, tr("FET warning"),
               tr("Constraint students set max gaps per week 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;
       }      

       assert(ss);

       this->iSubgroupsList.clear();
       if(ss->type==STUDENTS_SUBGROUP){
              int tmp;
              tmp=((StudentsSubgroup*)ss)->indexInInternalSubgroupsList;
              assert(tmp>=0);
              assert(tmp<r.nInternalSubgroups);
              if(!this->iSubgroupsList.contains(tmp))
                     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);
                     if(!this->iSubgroupsList.contains(tmp))
                            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);
                            if(!this->iSubgroupsList.contains(tmp))
                                   this->iSubgroupsList.append(tmp);
                     }
              }
       }
       else
              assert(0);
              
       return true;
}

Here is the call graph for this function:

double ConstraintStudentsSetMaxGapsPerWeek::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. If conflictsString!=NULL, it will be initialized with a text explaining where this restriction is broken.

Implements TimeConstraint.

Definition at line 6042 of file timeconstraint.cpp.

{
       //OLD COMMENT
       //returns a number equal to the number of gaps of the subgroups (in hours)

       //if the matrices subgroupsMatrix and teachersMatrix are already calculated, do not calculate them again!
       if(!c.teachersMatrixReady || !c.subgroupsMatrixReady){
              c.teachersMatrixReady=true;
              c.subgroupsMatrixReady=true;
              subgroups_conflicts = c.getSubgroupsMatrix(r, subgroupsMatrix);
              teachers_conflicts = c.getTeachersMatrix(r, teachersMatrix);

              c.changedForMatrixCalculation=false;
       }
       
       int nGaps;
       int tmp;
       
       int tIllegalGaps=0;
       
       for(int sg=0; sg<this->iSubgroupsList.count(); sg++){
              nGaps=0;
              int i=this->iSubgroupsList.at(sg);
              for(int j=0; j<r.nDaysPerWeek; j++){
                     int k;
                     tmp=0;
                     for(k=0; k<r.nHoursPerDay; k++)
                            if(subgroupsMatrix[i][j][k]>0){
                                   assert(!breakDayHour[j][k] && !subgroupNotAvailableDayHour[i][j][k]);
                                   break;
                            }
                     for(; k<r.nHoursPerDay; k++) if(!breakDayHour[j][k] && !subgroupNotAvailableDayHour[i][j][k]){
                            if(subgroupsMatrix[i][j][k]>0){
                                   nGaps+=tmp;
                                   tmp=0;
                            }
                            else
                                   tmp++;
                     }
              }
              
              int illegalGaps=nGaps-this->maxGaps;
              if(illegalGaps<0)
                     illegalGaps=0;

              if(illegalGaps>0 && conflictsString!=NULL){
                     QString s=tr("Time constraint students set max gaps per week broken for subgroup: %1, extra gaps=%2, conflicts increase=%3")
                      .arg(r.internalSubgroupsList[i]->name)
                      .arg(illegalGaps)
                      .arg(CustomFETString::number(weightPercentage/100*illegalGaps));
                                           
                     dl.append(s);
                     cl.append(weightPercentage/100*illegalGaps);
                            
                     *conflictsString+= s+"\n";
              }
              
              tIllegalGaps+=illegalGaps;
       }

       if(c.nPlacedActivities==r.nInternalActivities)
              if(weightPercentage==100)     //for partial solutions it might be broken
                     assert(tIllegalGaps==0);
       return weightPercentage/100 * tIllegalGaps;
}

Here is the call graph for this function:

Returns a small description string for this constraint.

Implements TimeConstraint.

Definition at line 6000 of file timeconstraint.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;
       s+=tr("Students set max gaps per week"); s+=", ";
       s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this->weightPercentage)); s+=", ";
       s+=tr("MG:%1", "Max gaps (per week)").arg(this->maxGaps);s+=", ";
       s+=tr("St:%1", "Students").arg(this->students);

       return begin+s+end;
}

Here is the call graph for this function:

Returns a detailed description string for this constraint.

Implements TimeConstraint.

Definition at line 6020 of file timeconstraint.cpp.

                                                                           {
       Q_UNUSED(r);

       QString s=tr("Time constraint");s+="\n";
       s+=tr("A students set must respect the maximum number of gaps per week");s+="\n";
       s+=tr("(breaks and students set not available not counted)");s+="\n";
       s+=tr("Weight (percentage)=%1").arg(CustomFETString::number(this->weightPercentage));s+="\n";
       s+=tr("Maximum gaps per week=%1").arg(this->maxGaps);s+="\n";
       s+=tr("Students=%1").arg(this->students); 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 TimeConstraint.

Definition at line 5987 of file timeconstraint.cpp.

                                                                      {
       Q_UNUSED(r);

       QString s="<ConstraintStudentsSetMaxGapsPerWeek>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Max_Gaps>"+CustomFETString::number(this->maxGaps)+"</Max_Gaps>\n";
       s+="   <Students>"; s+=protect(this->students); s+="</Students>\n";
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintStudentsSetMaxGapsPerWeek>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 5981 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Implements TimeConstraint.

Definition at line 6142 of file timeconstraint.cpp.

{
       if(maxGaps>r.nDaysPerWeek*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 TimeConstraint.

Definition at line 6108 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       Q_UNUSED(a);

       return false;
}

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

Implements TimeConstraint.

Definition at line 6130 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

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

Implements TimeConstraint.

Definition at line 6137 of file timeconstraint.cpp.

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

Here is the call graph for this function:

Returns true if this constraint is related to this subject.

Implements TimeConstraint.

Definition at line 6123 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 6116 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements TimeConstraint.

Definition at line 6157 of file timeconstraint.cpp.

Here is the call graph for this function:


Member Data Documentation

bool TimeConstraint::active [inherited]

Definition at line 146 of file timeconstraint.h.

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

The number of subgroups.

The subgroups

Definition at line 1292 of file timeconstraint.h.

Definition at line 1275 of file timeconstraint.h.

The name of the students set for this constraint.

Definition at line 1280 of file timeconstraint.h.

int TimeConstraint::type [inherited]

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

Definition at line 153 of file timeconstraint.h.

The percentage weight of this constraint, 100% compulsory, 0% non-compulsory.

Definition at line 144 of file timeconstraint.h.


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