Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintActivitiesEndStudentsDay Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintActivitiesEndStudentsDay ()
 ConstraintActivitiesEndStudentsDay (double wp, QString te, QString st, QString su, QString sut)
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

QString teacherName
 The teacher.
QString studentsName
 The students.
QString subjectName
 The subject.
QString activityTagName
 The activity tag.
int nActivities
 The number of activities which are represented by the subject, teacher and students requirements.
QList< int > activitiesIndices
 The indices of the activities in the rules (from 0 to rules.nActivities-1) These are indices in the internal list -> Rules::internalActivitiesList.
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 3228 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintActivitiesEndStudentsDay::ConstraintActivitiesEndStudentsDay ( double  wp,
QString  te,
QString  st,
QString  su,
QString  sut 
)

Definition at line 15484 of file timeconstraint.cpp.


Member Function Documentation

Implements TimeConstraint.

Definition at line 15786 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0);
       
       return true;
}
bool ConstraintActivitiesEndStudentsDay::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 15495 of file timeconstraint.cpp.

{
       this->nActivities=0;
       this->activitiesIndices.clear();

       int it;
       Activity* act;
       int i;
       for(i=0; i<r.nInternalActivities; i++){
              act=&r.internalActivitiesList[i];

              //check if this activity has the corresponding teacher
              if(this->teacherName!=""){
                     it = act->teachersNames.indexOf(this->teacherName);
                     if(it==-1)
                            continue;
              }
              //check if this activity has the corresponding students
              if(this->studentsName!=""){
                     bool commonStudents=false;
                     foreach(QString st, act->studentsNames)
                            if(r.setsShareStudents(st, studentsName)){
                                   commonStudents=true;
                                   break;
                            }
              
                     if(!commonStudents)
                            continue;
              }
              //check if this activity has the corresponding subject
              if(this->subjectName!="" && act->subjectName!=this->subjectName){
                            continue;
              }
              //check if this activity has the corresponding activity tag
              if(this->activityTagName!="" && !act->activityTagsNames.contains(this->activityTagName)){
                            continue;
              }
       
              assert(this->nActivities < MAX_ACTIVITIES);      
              this->nActivities++;
              this->activitiesIndices.append(i);
       }
       
       assert(this->activitiesIndices.count()==this->nActivities);

       if(this->nActivities>0)
              return true;
       else{
              QMessageBox::warning(parent, tr("FET error in data"), 
                     tr("Following constraint is wrong (refers to no activities). Please correct it:\n%1").arg(this->getDetailedDescription(r)));
              return false;
       }
}

Here is the call graph for this function:

double ConstraintActivitiesEndStudentsDay::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 15663 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=0;

       assert(r.internalStructureComputed);

       for(int kk=0; kk<this->nActivities; kk++){
              int tmp=0;
              int ai=this->activitiesIndices[kk];
       
              if(c.times[ai]!=UNALLOCATED_TIME){
                     int d=c.times[ai]%r.nDaysPerWeek; //the day when this activity was scheduled
                     int h=c.times[ai]/r.nDaysPerWeek; //the hour
              
                     for(int j=0; j<r.internalActivitiesList[ai].iSubgroupsList.count(); j++){
                            int sb=r.internalActivitiesList[ai].iSubgroupsList.at(j);
                            for(int hh=h+r.internalActivitiesList[ai].duration; hh<r.nHoursPerDay; hh++)
                                   if(subgroupsMatrix[sb][d][hh]>0){
                                          nbroken++;
                                          tmp=1;
                                          break;
                                   }
                            if(tmp>0)
                                   break;
                     }

                     if(conflictsString!=NULL && tmp>0){
                            QString s=tr("Time constraint activities end students' day broken for activity with id=%1 (%2), increases conflicts total by %3",
                             "%1 is the id, %2 is the detailed description of the activity")
                             .arg(r.internalActivitiesList[ai].id)
                             .arg(getActivityDetailedDescription(r, r.internalActivitiesList[ai].id))
                             .arg(CustomFETString::number(weightPercentage/100*tmp));

                            dl.append(s);
                            cl.append(weightPercentage/100*tmp);
       
                            *conflictsString+= s+"\n";
                     }
              }
       }

       if(weightPercentage==100)
              assert(nbroken==0);
       return nbroken * weightPercentage/100;
}

Here is the call graph for this function:

Returns a small description string for this constraint.

Implements TimeConstraint.

Definition at line 15571 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 tc, st, su, at;
       
       if(this->teacherName!="")
              tc=tr("teacher=%1").arg(this->teacherName);
       else
              tc=tr("all teachers");
              
       if(this->studentsName!="")
              st=tr("students=%1").arg(this->studentsName);
       else
              st=tr("all students");
              
       if(this->subjectName!="")
              su=tr("subject=%1").arg(this->subjectName);
       else
              su=tr("all subjects");
              
       if(this->activityTagName!="")
              at+=tr("activity tag=%1").arg(this->activityTagName);
       else
              at+=tr("all activity tags");
       
       QString s;
       s+=tr("Activities with %1, %2, %3, %4, must end students' day", "%1...%4 are conditions for the activities").arg(tc).arg(st).arg(su).arg(at);

       s+=", ";

       s+=tr("WP:%1\%", "Abbreviation for 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 15615 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

       QString s=tr("Time constraint");s+="\n";
       s+=tr("Activities with:");s+="\n";

       if(this->teacherName!="")
              s+=tr("Teacher=%1").arg(this->teacherName);
       else
              s+=tr("All teachers");
       s+="\n";
              
       if(this->studentsName!="")
              s+=tr("Students=%1").arg(this->studentsName);
       else
              s+=tr("All students");
       s+="\n";
              
       if(this->subjectName!="")
              s+=tr("Subject=%1").arg(this->subjectName);
       else
              s+=tr("All subjects");
       s+="\n";
              
       if(this->activityTagName!="")
              s+=tr("Activity tag=%1").arg(this->activityTagName);
       else
              s+=tr("All activity tags");
       s+="\n";

       s+=tr("must end students' day");
       s+="\n";

       s+=tr("Weight (percentage)=%1").arg(CustomFETString::number(this->weightPercentage));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 15555 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

       QString s="<ConstraintActivitiesEndStudentsDay>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Teacher_Name>"+protect(this->teacherName)+"</Teacher_Name>\n";
       s+="   <Students_Name>"+protect(this->studentsName)+"</Students_Name>\n";
       s+="   <Subject_Name>"+protect(this->subjectName)+"</Subject_Name>\n";
       s+="   <Activity_Tag_Name>"+protect(this->activityTagName)+"</Activity_Tag_Name>\n";
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintActivitiesEndStudentsDay>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 15549 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Implements TimeConstraint.

Definition at line 15780 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Returns true if this constraint is related to this activity.

Implements TimeConstraint.

Definition at line 15719 of file timeconstraint.cpp.

{
       int it;

       //check if this activity has the corresponding teacher
       if(this->teacherName!=""){
              it = a->teachersNames.indexOf(this->teacherName);
              if(it==-1)
                     return false;
       }
       //check if this activity has the corresponding students
       if(this->studentsName!=""){
              bool commonStudents=false;
              foreach(QString st, a->studentsNames){
                     if(r.setsShareStudents(st, this->studentsName)){
                            commonStudents=true;
                            break;
                     }
              }
              if(!commonStudents)
                     return false;
       }
       //check if this activity has the corresponding subject
       if(this->subjectName!="" && a->subjectName!=this->subjectName)
              return false;
       //check if this activity has the corresponding activity tag
       if(this->activityTagName!="" && !a->activityTagsNames.contains(this->activityTagName))
              return false;

       return true;
}

Here is the call graph for this function:

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

Implements TimeConstraint.

Definition at line 15765 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 15772 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       Q_UNUSED(s);
              
       return false;
}

Returns true if this constraint is related to this subject.

Implements TimeConstraint.

Definition at line 15758 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 15751 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements TimeConstraint.

Definition at line 15794 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0); //should check hasWrongDayOrHour, firstly

       return true;
}

Member Data Documentation

bool TimeConstraint::active [inherited]

Definition at line 146 of file timeconstraint.h.

The indices of the activities in the rules (from 0 to rules.nActivities-1) These are indices in the internal list -> Rules::internalActivitiesList.

Definition at line 3265 of file timeconstraint.h.

The activity tag.

If void, all activity tags.

Definition at line 3250 of file timeconstraint.h.

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

The number of activities which are represented by the subject, teacher and students requirements.

Definition at line 3258 of file timeconstraint.h.

The students.

If void, all students.

Definition at line 3240 of file timeconstraint.h.

The subject.

If void, all subjects.

Definition at line 3245 of file timeconstraint.h.

The teacher.

If void, all teachers.

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