Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintBreakTimes Class Reference

This is a constraint. More...

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintBreakTimes ()
 ConstraintBreakTimes (double wp, QList< int > d, QList< int > h)
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

QList< int > days
QList< int > hours
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 constrains the timetable to not schedule any activity in the specified day, during the start hour and end hour.

Definition at line 1185 of file timeconstraint.h.


Constructor & Destructor Documentation

Definition at line 5425 of file timeconstraint.cpp.

ConstraintBreakTimes::ConstraintBreakTimes ( double  wp,
QList< int >  d,
QList< int >  h 
)

Definition at line 5431 of file timeconstraint.cpp.

       : TimeConstraint(wp)
{
       this->days = d;
       this->hours = h;
       this->type = CONSTRAINT_BREAK_TIMES;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 5665 of file timeconstraint.cpp.

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

Here is the call graph for this function:

bool ConstraintBreakTimes::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 5529 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       
       assert(days.count()==hours.count());
       for(int k=0; k<days.count(); k++){
              if(this->days.at(k) >= r.nDaysPerWeek){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint break times 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->hours.at(k) >= r.nHoursPerDay){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint break times is wrong because an 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;
              }
       }

       return true;
}

Here is the call graph for this function:

double ConstraintBreakTimes::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 5554 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;
       }

       //DEPRECATED COMMENT
       //For the moment, this function sums the number of hours each teacher
       //is teaching in this break period.
       //This function consideres all the hours, I mean if there are for example 5 weekly courses
       //scheduled on that hour (which is already a broken hard restriction - we only
       //are allowed 1 weekly course for a certain teacher at a certain hour) we calculate
       //5 broken restrictions for this break period.
       //TODO: decide if it is better to consider only 2 or 10 as a return value in this particular case
       //(currently it is 10)
       
       int nbroken;
       
       nbroken=0;
              
       for(int i=0; i<r.nInternalActivities; i++){
              int dayact=c.times[i]%r.nDaysPerWeek;
              int houract=c.times[i]/r.nDaysPerWeek;
              
              assert(days.count()==hours.count());
              for(int kk=0; kk<days.count(); kk++){
                     int d=days.at(kk);
                     int h=hours.at(kk);
                     
                     int dur=r.internalActivitiesList[i].duration;
                     if(d==dayact && !(houract+dur<=h || houract>h))
                     {                    
                            nbroken++;

                            if(conflictsString!=NULL){
                                   QString s=tr("Time constraint break not respected for activity with id %1, on day %2, hours %3")
                                          .arg(r.internalActivitiesList[i].id)
                                          .arg(r.daysOfTheWeek[dayact])
                                          .arg(r.daysOfTheWeek[houract]);
                                   s+=". ";
                                   s+=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;
}

Here is the call graph for this function:

QString ConstraintBreakTimes::getDescription ( Rules r) [virtual]

Returns a small description string for this constraint.

Implements TimeConstraint.

Definition at line 5466 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;
       s+=tr("Break times");s+=", ";
       s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this->weightPercentage));s+=", ";

       s+=tr("B at:", "Break at");
       s+=" ";
       assert(days.count()==hours.count());
       for(int i=0; i<days.count(); i++){
              if(this->days.at(i)>=0){
                     s+=r.daysOfTheWeek[this->days.at(i)];
                     s+=" ";
              }
              if(this->hours.at(i)>=0){
                     s+=r.hoursOfTheDay[this->hours.at(i)];
              }
              if(i<days.count()-1)
                     s+="; ";
       }
       
       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 5497 of file timeconstraint.cpp.

                                                            {
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Break times");s+="\n";
       s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this->weightPercentage));s+="\n";

       s+=tr("Break at:"); s+="\n";
       assert(days.count()==hours.count());
       for(int i=0; i<days.count(); i++){
              if(this->days.at(i)>=0){
                     s+=r.daysOfTheWeek[this->days.at(i)];
                     s+=" ";
              }
              if(this->hours.at(i)>=0){
                     s+=r.hoursOfTheDay[this->hours.at(i)];
              }
              if(i<days.count()-1)
                     s+="; ";
       }
       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:

QString ConstraintBreakTimes::getXmlDescription ( Rules r) [virtual]

Returns an XML description of this constraint.

Implements TimeConstraint.

Definition at line 5445 of file timeconstraint.cpp.

                                                       {
       QString s="<ConstraintBreakTimes>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";

       s+="   <Number_of_Break_Times>"+CustomFETString::number(this->days.count())+"</Number_of_Break_Times>\n";
       assert(days.count()==hours.count());
       for(int i=0; i<days.count(); i++){
              s+="   <Break_Time>\n";
              if(this->days.at(i)>=0)
                     s+="          <Day>"+protect(r.daysOfTheWeek[this->days.at(i)])+"</Day>\n";
              if(this->hours.at(i)>=0)
                     s+="          <Hour>"+protect(r.hoursOfTheDay[this->hours.at(i)])+"</Hour>\n";
              s+="   </Break_Time>\n";
       }

       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintBreakTimes>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 5439 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Implements TimeConstraint.

Definition at line 5653 of file timeconstraint.cpp.

{
       assert(days.count()==hours.count());
       
       for(int i=0; i<days.count(); i++)
              if(days.at(i)<0 || days.at(i)>=r.nDaysPerWeek
               || hours.at(i)<0 || hours.at(i)>=r.nHoursPerDay)
                     return true;

       return false;
}

Here is the caller graph for this function:

bool ConstraintBreakTimes::isRelatedToActivity ( Rules r,
Activity a 
) [virtual]

Returns true if this constraint is related to this activity.

Implements TimeConstraint.

Definition at line 5616 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 5638 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 5645 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 5631 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 5624 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements TimeConstraint.

Definition at line 5672 of file timeconstraint.cpp.

{
       assert(hasWrongDayOrHour(r));
       
       assert(days.count()==hours.count());
       
       QList<int> newDays;
       QList<int> newHours;
       
       for(int i=0; i<days.count(); i++)
              if(days.at(i)>=0 && days.at(i)<r.nDaysPerWeek
               && hours.at(i)>=0 && hours.at(i)<r.nHoursPerDay){
                     newDays.append(days.at(i));
                     newHours.append(hours.at(i));
              }
       
       days=newDays;
       hours=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 1189 of file timeconstraint.h.

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