Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintStudentsSetActivityTagMaxHoursDaily Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintStudentsSetActivityTagMaxHoursDaily ()
 ConstraintStudentsSetActivityTagMaxHoursDaily (double wp, int maxnh, const QString &s, const QString &activityTag)
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 maxHoursDaily
QString students
 The students set name.
QString activityTagName
int activityTagIndex
QList< int > iSubgroupsList
 The number of subgroups.
QList< int > canonicalSubgroupsList
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

Definition at line 3437 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintStudentsSetActivityTagMaxHoursDaily::ConstraintStudentsSetActivityTagMaxHoursDaily ( double  wp,
int  maxnh,
const QString &  s,
const QString &  activityTag 
)

Definition at line 16528 of file timeconstraint.cpp.

       : TimeConstraint(wp)
{
       this->maxHoursDaily = maxnh;
       this->students = s;
       this->activityTagName=activityTag;
       this->type = CONSTRAINT_STUDENTS_SET_ACTIVITY_TAG_MAX_HOURS_DAILY;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 16792 of file timeconstraint.cpp.

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

Here is the call graph for this function:

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 16603 of file timeconstraint.cpp.

{
       this->activityTagIndex=r.searchActivityTag(this->activityTagName);
       assert(this->activityTagIndex>=0);

       StudentsSet* ss=r.searchAugmentedStudentsSet(this->students);
       
       if(ss==NULL){
              QMessageBox::warning(parent, tr("FET warning"),
               tr("Constraint students set max hours daily 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);
              
       this->canonicalSubgroupsList.clear();
       foreach(int i, this->iSubgroupsList){
              bool found=false;
       
              StudentsSubgroup* sbg=r.internalSubgroupsList[i];
              foreach(int actIndex, sbg->activitiesForSubgroup){
                     if(r.internalActivitiesList[actIndex].iActivityTagsSet.contains(this->activityTagIndex)){
                            found=true;
                            break;
                     }
              }
              
              if(found)
                     this->canonicalSubgroupsList.append(i);
       }

              
       return true;
}

Here is the call graph for this function:

double ConstraintStudentsSetActivityTagMaxHoursDaily::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 16680 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;
       
       foreach(int i, this->canonicalSubgroupsList){
              StudentsSubgroup* sbg=r.internalSubgroupsList[i];
              int crtSubgroupTimetableActivityTag[MAX_DAYS_PER_WEEK][MAX_HOURS_PER_DAY];
              for(int d=0; d<r.nDaysPerWeek; d++)
                     for(int h=0; h<r.nHoursPerDay; h++)
                            crtSubgroupTimetableActivityTag[d][h]=-1;
              foreach(int ai, sbg->activitiesForSubgroup)if(c.times[ai]!=UNALLOCATED_TIME){
                     int d=c.times[ai]%r.nDaysPerWeek;
                     int h=c.times[ai]/r.nDaysPerWeek;
                     for(int dur=0; dur<r.internalActivitiesList[ai].duration; dur++){
                            assert(h+dur<r.nHoursPerDay);
                            assert(crtSubgroupTimetableActivityTag[d][h+dur]==-1);
                            if(r.internalActivitiesList[ai].iActivityTagsSet.contains(this->activityTagIndex))
                                   crtSubgroupTimetableActivityTag[d][h+dur]=this->activityTagIndex;
                     }
              }

              for(int d=0; d<r.nDaysPerWeek; d++){
                     int nd=0;
                     for(int h=0; h<r.nHoursPerDay; h++)
                            if(crtSubgroupTimetableActivityTag[d][h]==this->activityTagIndex)
                                   nd++;
                            
                     if(nd>this->maxHoursDaily){
                            nbroken++;

                            if(conflictsString!=NULL){
                                   QString s=(tr(
                                    "Time constraint students set, activity tag %1, max %2 hours daily, broken for subgroup %3, on day %4, length=%5.")
                                    .arg(this->activityTagName)
                                    .arg(CustomFETString::number(this->maxHoursDaily))
                                    .arg(r.internalSubgroupsList[i]->name)
                                    .arg(r.daysOfTheWeek[d])
                                    .arg(nd)
                                    )
                                    +
                                    " "
                                    +
                                    (tr("This increases the conflicts total by %1").arg(CustomFETString::number(weightPercentage/100.0)));
                                   
                                   dl.append(s);
                                   cl.append(weightPercentage/100);
                            
                                   *conflictsString+= s+"\n";
                            }
                     }
              }
       }
       
       if(weightPercentage==100.0)
              assert(nbroken==0);
       return weightPercentage/100.0 * nbroken;
}

Here is the call graph for this function:

Returns a small description string for this constraint.

Implements TimeConstraint.

Definition at line 16558 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+="! ";
       s+=tr("Students set %1 for activity tag %2 has max %3 hours daily").arg(this->students).arg(this->activityTagName).arg(this->maxHoursDaily);
       s+=", ";
       s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this->weightPercentage));

       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 16579 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

       QString s=tr("Time constraint");s+="\n";
       s+=tr("(not perfect)", "It refers to a not perfect constraint"); s+="\n";
       s+=tr("A students set, for an activity tag, must respect the maximum number of hours daily"); s+="\n";
       s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this->weightPercentage));s+="\n";
       s+=tr("Students set=%1").arg(this->students);s+="\n";
       s+=tr("Activity tag=%1").arg(this->activityTagName);s+="\n";
       s+=tr("Maximum hours daily=%1").arg(this->maxHoursDaily);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 16543 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

       QString s="<ConstraintStudentsSetActivityTagMaxHoursDaily>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Maximum_Hours_Daily>"+CustomFETString::number(this->maxHoursDaily)+"</Maximum_Hours_Daily>\n";
       s+="   <Students>"+protect(this->students)+"</Students>\n";
       s+="   <Activity_Tag>"+protect(this->activityTagName)+"</Activity_Tag>\n";
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintStudentsSetActivityTagMaxHoursDaily>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 16537 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Implements TimeConstraint.

Definition at line 16784 of file timeconstraint.cpp.

{
       if(maxHoursDaily>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 16750 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 16772 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 16779 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 16765 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 16758 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements TimeConstraint.

Definition at line 16799 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.

Definition at line 3452 of file timeconstraint.h.

Definition at line 3448 of file timeconstraint.h.

Definition at line 3465 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 3463 of file timeconstraint.h.

Definition at line 3441 of file timeconstraint.h.

The students set name.

Definition at line 3446 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: