Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintSubactivitiesPreferredTimeSlots Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintSubactivitiesPreferredTimeSlots ()
 ConstraintSubactivitiesPreferredTimeSlots (double wp, int compNo, QString te, QString st, QString su, QString sut, int nPT_L, QList< int > d_L, QList< int > h_L)
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 componentNumber
QString p_teacherName
 The teacher.
QString p_studentsName
 The students.
QString p_subjectName
 The subject.
QString p_activityTagName
 The activity tag.
int p_nPreferredTimeSlots_L
 The number of preferred times.
QList< int > p_days_L
 The preferred days.
QList< int > p_hours_L
 The preferred hours.
int p_nActivities
 The number of activities which are represented by the subject, teacher and students requirements.
QList< int > p_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 2263 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintSubactivitiesPreferredTimeSlots::ConstraintSubactivitiesPreferredTimeSlots ( double  wp,
int  compNo,
QString  te,
QString  st,
QString  su,
QString  sut,
int  nPT_L,
QList< int >  d_L,
QList< int >  h_L 
)

Definition at line 9828 of file timeconstraint.cpp.

       : TimeConstraint(wp)
{
       assert(d_L.count()==nPT_L);
       assert(h_L.count()==nPT_L);

       this->componentNumber=compNo;
       this->p_teacherName=te;
       this->p_subjectName=su;
       this->p_activityTagName=sut;
       this->p_studentsName=st;
       this->p_nPreferredTimeSlots_L=nPT_L;
       this->p_days_L=d_L;
       this->p_hours_L=h_L;
       this->type=CONSTRAINT_SUBACTIVITIES_PREFERRED_TIME_SLOTS;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 10277 of file timeconstraint.cpp.

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

Here is the call graph for this function:

bool ConstraintSubactivitiesPreferredTimeSlots::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 9846 of file timeconstraint.cpp.

{
       this->p_nActivities=0;
       this->p_activitiesIndices.clear();

       int it;
       Activity* act;
       int i;
       for(i=0; i<r.nInternalActivities; i++){
              act=&r.internalActivitiesList[i];
              
              if(!act->representsComponentNumber(this->componentNumber))
                     continue;

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

       assert(this->p_nActivities==this->p_activitiesIndices.count());

       for(int k=0; k<p_nPreferredTimeSlots_L; k++){
              if(this->p_days_L[k] >= r.nDaysPerWeek){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint subactivities preferred time slots is wrong because it refers to removed day. Please correct"
                      " and try again. Correcting means editing the constraint and updating information. Constraint is:\n%1").arg(this->getDetailedDescription(r)));
               
                     return false;
              }
              if(this->p_hours_L[k] == r.nHoursPerDay){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint subactivities preferred time slots is wrong because a preferred hour is too late (after the last acceptable slot). Please correct"
                      " and try again. Correcting means editing the constraint and updating information. Constraint is:\n%1").arg(this->getDetailedDescription(r)));
               
                     return false;
              }
              if(this->p_hours_L[k] > r.nHoursPerDay){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint subactivities preferred time slots is wrong because it refers to removed hour. Please correct"
                      " and try again. Correcting means editing the constraint and updating information. Constraint is:\n%1").arg(this->getDetailedDescription(r)));
               
                     return false;
              }
              if(this->p_hours_L[k]<0 || this->p_days_L[k]<0){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint subactivities preferred time slots is wrong because hour or day is not specified for a slot (-1). Please correct"
                      " and try again. Correcting means editing the constraint and updating information. Constraint is:\n%1").arg(this->getDetailedDescription(r)));
               
                     return false;
              }
       }
       
       if(this->p_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 ConstraintSubactivitiesPreferredTimeSlots::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 10132 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;

       assert(r.internalStructureComputed);

       Matrix2D<bool> allowed;
       allowed.resize(r.nDaysPerWeek, r.nHoursPerDay);
       //bool allowed[MAX_DAYS_PER_WEEK][MAX_HOURS_PER_DAY];
       for(int d=0; d<r.nDaysPerWeek; d++)
              for(int h=0; h<r.nHoursPerDay; h++)
                     allowed[d][h]=false;
       for(int i=0; i<this->p_nPreferredTimeSlots_L; i++){
              if(this->p_days_L[i]>=0 && this->p_hours_L[i]>=0)
                     allowed[this->p_days_L[i]][this->p_hours_L[i]]=true;
              else
                     assert(0);
       }

       nbroken=0;
       int tmp;
       
       for(int i=0; i<this->p_nActivities; i++){
              tmp=0;
              int ai=this->p_activitiesIndices[i];
              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 dur=0; dur<r.internalActivitiesList[ai].duration; dur++)
                            if(!allowed[d][h+dur])
                                   tmp++;
              }
              nbroken+=tmp;
              if(conflictsString!=NULL && tmp>0){
                     QString s=tr("Time constraint subactivities preferred time slots broken"
                      " for activity with id=%1 (%2), component number %3, on %4 hours,"
                      " increases conflicts total by %5", "%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(componentNumber)
                      .arg(tmp)
                      .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.0;
}

Here is the call graph for this function:

Returns a small description string for this constraint.

Implements TimeConstraint.

Definition at line 10014 of file timeconstraint.cpp.

{
       QString begin=QString("");
       if(!active)
              begin="X - ";
              
       QString end=QString("");
       if(!comments.isEmpty())
              end=", "+tr("C: %1", "Comments").arg(comments);
              
       QString s;
       
       QString tc, st, su, at;
       
       if(this->p_teacherName!="")
              tc=tr("teacher=%1").arg(this->p_teacherName);
       else
              tc=tr("all teachers");
              
       if(this->p_studentsName!="")
              st=tr("students=%1").arg(this->p_studentsName);
       else
              st=tr("all students");
              
       if(this->p_subjectName!="")
              su=tr("subject=%1").arg(this->p_subjectName);
       else
              su=tr("all subjects");
              
       if(this->p_activityTagName!="")
              at+=tr("activity tag=%1").arg(this->p_activityTagName);
       else
              at+=tr("all activity tags");
       
       s+=tr("Subactivities with %1, %2, %3, %4, %5, have a set of preferred time slots:", "%1...%5 are conditions for the subactivities")
              .arg(tr("component number=%1").arg(this->componentNumber)).arg(tc).arg(st).arg(su).arg(at);
              
       s+=" ";
       
       for(int i=0; i<this->p_nPreferredTimeSlots_L; i++){
              if(this->p_days_L[i]>=0){
                     s+=r.daysOfTheWeek[this->p_days_L[i]];
                     s+=" ";
              }
              if(this->p_hours_L[i]>=0){
                     s+=r.hoursOfTheDay[this->p_hours_L[i]];
              }
              if(i<this->p_nPreferredTimeSlots_L-1)
                     s+="; ";
       }
       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 10071 of file timeconstraint.cpp.

{
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Subactivities with:");s+="\n";
       
       s+=tr("Component number=%1").arg(this->componentNumber);
       s+="\n";

       if(this->p_teacherName!="")
              s+=tr("Teacher=%1").arg(this->p_teacherName);
       else
              s+=tr("All teachers");
       s+="\n";
              
       if(this->p_studentsName!="")
              s+=tr("Students=%1").arg(this->p_studentsName);
       else
              s+=tr("All students");
       s+="\n";
       
       if(this->p_subjectName!="")
              s+=tr("Subject=%1").arg(this->p_subjectName);
       else
              s+=tr("All subjects");
       s+="\n";
       
       if(this->p_activityTagName!="")
              s+=tr("Activity tag=%1").arg(this->p_activityTagName);
       else
              s+=tr("All activity tags");
       s+="\n";

       s+=tr("have a set of preferred time slots (all hours of each affected subactivity must be in the allowed slots):");
       s+="\n";
       for(int i=0; i<this->p_nPreferredTimeSlots_L; i++){
              if(this->p_days_L[i]>=0){
                     s+=r.daysOfTheWeek[this->p_days_L[i]];
                     s+=" ";
              }
              if(this->p_hours_L[i]>=0){
                     s+=r.hoursOfTheDay[this->p_hours_L[i]];
              }
              if(i<this->p_nPreferredTimeSlots_L-1)
                     s+=";  ";
       }
       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 9990 of file timeconstraint.cpp.

{
       QString s="<ConstraintSubactivitiesPreferredTimeSlots>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Component_Number>"+CustomFETString::number(this->componentNumber)+"</Component_Number>\n";
       s+="   <Teacher_Name>"+protect(this->p_teacherName)+"</Teacher_Name>\n";
       s+="   <Students_Name>"+protect(this->p_studentsName)+"</Students_Name>\n";
       s+="   <Subject_Name>"+protect(this->p_subjectName)+"</Subject_Name>\n";
       s+="   <Activity_Tag_Name>"+protect(this->p_activityTagName)+"</Activity_Tag_Name>\n";
       s+="   <Number_of_Preferred_Time_Slots>"+CustomFETString::number(this->p_nPreferredTimeSlots_L)+"</Number_of_Preferred_Time_Slots>\n";
       for(int i=0; i<p_nPreferredTimeSlots_L; i++){
              s+="   <Preferred_Time_Slot>\n";
              if(this->p_days_L[i]>=0)
                     s+="          <Preferred_Day>"+protect(r.daysOfTheWeek[this->p_days_L[i]])+"</Preferred_Day>\n";
              if(this->p_hours_L[i]>=0)
                     s+="          <Preferred_Hour>"+protect(r.hoursOfTheDay[this->p_hours_L[i]])+"</Preferred_Hour>\n";
              s+="   </Preferred_Time_Slot>\n";
       }
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintSubactivitiesPreferredTimeSlots>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 9936 of file timeconstraint.cpp.

{
       QList<int> localActiveActs;
       QList<int> localAllActs;

       //returns true if all activities are inactive
       int it;
       Activity* act;
       int i;
       for(i=0; i<r.activitiesList.count(); i++){
              act=r.activitiesList.at(i);

              if(!act->representsComponentNumber(this->componentNumber))
                     continue;

              //check if this activity has the corresponding teacher
              if(this->p_teacherName!=""){
                     it = act->teachersNames.indexOf(this->p_teacherName);
                     if(it==-1)
                            continue;
              }
              //check if this activity has the corresponding students
              if(this->p_studentsName!=""){
                     bool commonStudents=false;
                     foreach(QString st, act->studentsNames)
                            if(r.setsShareStudents(st, p_studentsName)){
                                   commonStudents=true;
                                   break;
                            }
              
                     if(!commonStudents)
                            continue;
              }
              //check if this activity has the corresponding subject
              if(this->p_subjectName!="" && act->subjectName!=this->p_subjectName){
                            continue;
              }
              //check if this activity has the corresponding activity tag
              if(this->p_activityTagName!="" && !act->activityTagsNames.contains(this->p_activityTagName)){
                            continue;
              }
       
              if(!r.inactiveActivities.contains(act->id))
                     localActiveActs.append(act->id);
                     
              localAllActs.append(act->id);
       }

       if(localActiveActs.count()==0 && localAllActs.count()>0)
              return true;
       else
              return false;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 10264 of file timeconstraint.cpp.

{
       assert(p_nPreferredTimeSlots_L==p_days_L.count());
       assert(p_nPreferredTimeSlots_L==p_hours_L.count());
       
       for(int i=0; i<p_nPreferredTimeSlots_L; i++)
              if(p_days_L.at(i)<0 || p_days_L.at(i)>=r.nDaysPerWeek
               || p_hours_L.at(i)<0 || p_hours_L.at(i)>=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 10200 of file timeconstraint.cpp.

{
       if(!a->representsComponentNumber(this->componentNumber))
              return false;

       int it;

       //check if this activity has the corresponding teacher
       if(this->p_teacherName!=""){
              it = a->teachersNames.indexOf(this->p_teacherName);
              if(it==-1)
                     return false;
       }
       //check if this activity has the corresponding students
       if(this->p_studentsName!=""){
              bool commonStudents=false;
              foreach(QString st, a->studentsNames){
                     if(r.setsShareStudents(st, this->p_studentsName)){
                            commonStudents=true;
                            break;
                     }
              }
              if(!commonStudents)
                     return false;
       }
       //check if this activity has the corresponding subject
       if(this->p_subjectName!="" && a->subjectName!=this->p_subjectName)
              return false;
       //check if this activity has the corresponding activity tag
       if(this->p_activityTagName!="" && !a->activityTagsNames.contains(this->p_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 10249 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 10256 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 10242 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 10235 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements TimeConstraint.

Definition at line 10284 of file timeconstraint.cpp.

{
       assert(hasWrongDayOrHour(r));
       
       assert(p_nPreferredTimeSlots_L==p_days_L.count());
       assert(p_nPreferredTimeSlots_L==p_hours_L.count());
       
       QList<int> newDays;
       QList<int> newHours;
       int newNPref=0;
       
       for(int i=0; i<p_nPreferredTimeSlots_L; i++)
              if(p_days_L.at(i)>=0 && p_days_L.at(i)<r.nDaysPerWeek
               && p_hours_L.at(i)>=0 && p_hours_L.at(i)<r.nHoursPerDay){
                     newDays.append(p_days_L.at(i));
                     newHours.append(p_hours_L.at(i));
                     newNPref++;
              }
       
       p_nPreferredTimeSlots_L=newNPref;
       p_days_L=newDays;
       p_hours_L=newHours;
       
       r.internalStructureComputed=false;
       setRulesModifiedAndOtherThings(&r);

       return true;
}

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.

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

The activity tag.

If void, all activity tags.

Definition at line 2287 of file timeconstraint.h.

The preferred days.

If -1, then the user does not care about the day.

Definition at line 2298 of file timeconstraint.h.

The preferred hours.

If -1, then the user does not care about the hour.

Definition at line 2304 of file timeconstraint.h.

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

Definition at line 2311 of file timeconstraint.h.

The number of preferred times.

Definition at line 2292 of file timeconstraint.h.

The students.

If void, all students.

Definition at line 2277 of file timeconstraint.h.

The subject.

If void, all subjects.

Definition at line 2282 of file timeconstraint.h.

The teacher.

If void, all teachers.

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