fet
5.18.0

This is a constraint, aimed at obtaining timetables which do not allow more than X hours in a row for any teacher. More...
#include <timeconstraint.h>
Public Member Functions  
ConstraintTeachersMaxHoursContinuously ()  
ConstraintTeachersMaxHoursContinuously (double wp, int maxhours)  
QString  getXmlDescription (Rules &r) 
Returns an XML description of this constraint.  
bool  computeInternalStructure (QWidget *parent, Rules &r) 
Computes the internal structure for 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 (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  maxHoursContinuously 
The maximum hours continuously.  
double  weightPercentage 
The percentage weight of this constraint, 100% compulsory, 0% noncompulsory.  
bool  active 
QString  comments 
int  type 
Specifies the type of this constraint (using the above constants). 
This is a constraint, aimed at obtaining timetables which do not allow more than X hours in a row for any teacher.
Definition at line 820 of file timeconstraint.h.
Definition at line 3133 of file timeconstraint.cpp.
: TimeConstraint() { this>type=CONSTRAINT_TEACHERS_MAX_HOURS_CONTINUOUSLY; }
ConstraintTeachersMaxHoursContinuously::ConstraintTeachersMaxHoursContinuously  (  double  wp, 
int  maxhours  
) 
Definition at line 3139 of file timeconstraint.cpp.
: TimeConstraint(wp) { assert(maxhours>0); this>maxHoursContinuously=maxhours; this>type=CONSTRAINT_TEACHERS_MAX_HOURS_CONTINUOUSLY; }
bool ConstraintTeachersMaxHoursContinuously::canRepairWrongDayOrHour  (  Rules &  r  )  [virtual] 
Implements TimeConstraint.
Definition at line 3337 of file timeconstraint.cpp.
{ assert(hasWrongDayOrHour(r)); return true; }
bool ConstraintTeachersMaxHoursContinuously::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 3148 of file timeconstraint.cpp.
{ Q_UNUSED(parent); Q_UNUSED(r); return true; }
double ConstraintTeachersMaxHoursContinuously::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 3213 of file timeconstraint.cpp.
{ //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 nbroken; nbroken=0; for(int i=0; i<r.nInternalTeachers; i++){ for(int d=0; d<r.nDaysPerWeek; d++){ int nc=0; for(int h=0; h<r.nHoursPerDay; h++){ if(teachersMatrix[i][d][h]>0) nc++; else{ if(nc>this>maxHoursContinuously){ nbroken++; if(conflictsString!=NULL){ QString s=(tr( "Time constraint teachers max %1 hours continuously broken for teacher %2, on day %3, length=%4.") .arg(CustomFETString::number(this>maxHoursContinuously)) .arg(r.internalTeachersList[i]>name) .arg(r.daysOfTheWeek[d]) .arg(nc) ) + " " + (tr("This increases the conflicts total by %1").arg(CustomFETString::number(weightPercentage/100))); dl.append(s); cl.append(weightPercentage/100); *conflictsString+= s+"\n"; } } nc=0; } } if(nc>this>maxHoursContinuously){ nbroken++; if(conflictsString!=NULL){ QString s=(tr( "Time constraint teachers max %1 hours continuously broken for teacher %2, on day %3, length=%4.") .arg(CustomFETString::number(this>maxHoursContinuously)) .arg(r.internalTeachersList[i]>name) .arg(r.daysOfTheWeek[d]) .arg(nc) ) + " " + (tr("This increases the conflicts total by %1").arg(CustomFETString::number(weightPercentage/100))); dl.append(s); cl.append(weightPercentage/100); *conflictsString+= s+"\n"; } } } } if(weightPercentage==100) assert(nbroken==0); return weightPercentage/100 * nbroken; }
QString ConstraintTeachersMaxHoursContinuously::getDescription  (  Rules &  r  )  [virtual] 
Returns a small description string for this constraint.
Implements TimeConstraint.
Definition at line 3174 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("Teachers max hours continuously");s+=", "; s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this>weightPercentage));s+=", "; s+=tr("MH:%1", "Maximum hours (continuously)").arg(this>maxHoursContinuously); return begin+s+end; }
QString ConstraintTeachersMaxHoursContinuously::getDetailedDescription  (  Rules &  r  )  [virtual] 
Returns a detailed description string for this constraint.
Implements TimeConstraint.
Definition at line 3193 of file timeconstraint.cpp.
{ Q_UNUSED(r); QString s=tr("Time constraint");s+="\n"; s+=tr("All teachers must respect the maximum number of hours continuously");s+="\n"; s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this>weightPercentage));s+="\n"; s+=tr("Maximum hours continuously=%1").arg(this>maxHoursContinuously);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; }
QString ConstraintTeachersMaxHoursContinuously::getXmlDescription  (  Rules &  r  )  [virtual] 
Returns an XML description of this constraint.
Implements TimeConstraint.
Definition at line 3162 of file timeconstraint.cpp.
{ Q_UNUSED(r); QString s="<ConstraintTeachersMaxHoursContinuously>\n"; s+=" <Weight_Percentage>"+CustomFETString::number(this>weightPercentage)+"</Weight_Percentage>\n"; s+=" <Maximum_Hours_Continuously>"+CustomFETString::number(this>maxHoursContinuously)+"</Maximum_Hours_Continuously>\n"; s+=" <Active>"+trueFalse(active)+"</Active>\n"; s+=" <Comments>"+protect(comments)+"</Comments>\n"; s+="</ConstraintTeachersMaxHoursContinuously>\n"; return s; }
bool ConstraintTeachersMaxHoursContinuously::hasInactiveActivities  (  Rules &  r  )  [virtual] 
Implements TimeConstraint.
Definition at line 3156 of file timeconstraint.cpp.
{ Q_UNUSED(r); return false; }
bool ConstraintTeachersMaxHoursContinuously::hasWrongDayOrHour  (  Rules &  r  )  [virtual] 
Implements TimeConstraint.
Definition at line 3329 of file timeconstraint.cpp.
{ if(maxHoursContinuously>r.nHoursPerDay) return true; return false; }
bool ConstraintTeachersMaxHoursContinuously::isRelatedToActivity  (  Rules &  r, 
Activity *  a  
)  [virtual] 
Returns true if this constraint is related to this activity.
Implements TimeConstraint.
Definition at line 3292 of file timeconstraint.cpp.
{ Q_UNUSED(r); Q_UNUSED(a); return false; }
bool ConstraintTeachersMaxHoursContinuously::isRelatedToActivityTag  (  ActivityTag *  s  )  [virtual] 
Returns true if this constraint is related to this activity tag.
Implements TimeConstraint.
Definition at line 3314 of file timeconstraint.cpp.
{ Q_UNUSED(s); return false; }
bool ConstraintTeachersMaxHoursContinuously::isRelatedToStudentsSet  (  Rules &  r, 
StudentsSet *  s  
)  [virtual] 
Returns true if this constraint is related to this students set.
Implements TimeConstraint.
Definition at line 3321 of file timeconstraint.cpp.
{ Q_UNUSED(r); Q_UNUSED(s); return false; }
bool ConstraintTeachersMaxHoursContinuously::isRelatedToSubject  (  Subject *  s  )  [virtual] 
Returns true if this constraint is related to this subject.
Implements TimeConstraint.
Definition at line 3307 of file timeconstraint.cpp.
{ Q_UNUSED(s); return false; }
bool ConstraintTeachersMaxHoursContinuously::isRelatedToTeacher  (  Teacher *  t  )  [virtual] 
Returns true if this constraint is related to this teacher.
Implements TimeConstraint.
Definition at line 3300 of file timeconstraint.cpp.
{ Q_UNUSED(t); return true; }
bool ConstraintTeachersMaxHoursContinuously::repairWrongDayOrHour  (  Rules &  r  )  [virtual] 
Implements TimeConstraint.
Definition at line 3344 of file timeconstraint.cpp.
{ assert(hasWrongDayOrHour(r)); if(maxHoursContinuously>r.nHoursPerDay) maxHoursContinuously=r.nHoursPerDay; return true; }
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 maximum hours continuously.
Definition at line 827 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.
double TimeConstraint::weightPercentage [inherited] 
The percentage weight of this constraint, 100% compulsory, 0% noncompulsory.
Definition at line 144 of file timeconstraint.h.