Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintActivityPreferredStartingTime Class Reference

This is a constraint. More...

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintActivityPreferredStartingTime ()
 ConstraintActivityPreferredStartingTime (double wp, int actId, int d, int h, bool perm)
bool operator== (ConstraintActivityPreferredStartingTime &c)
 Comparison operator - to be sure that we do not introduce duplicates.
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 activityId
 Activity id.
int day
 The preferred day.
int hour
 The preferred hour.
bool permanentlyLocked
int activityIndex
 The index of the activity in the rules (from 0 to rules.nActivities-1) - it is not the id of the activity.
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 adds, to the fitness of the solution, a fitness factor that grows as the activity is scheduled farther from the wanted time For the moment, fitness factor increases with one unit for every hour and one unit for every day.

Definition at line 1971 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintActivityPreferredStartingTime::ConstraintActivityPreferredStartingTime ( double  wp,
int  actId,
int  d,
int  h,
bool  perm 
)

Definition at line 8762 of file timeconstraint.cpp.

       : TimeConstraint(wp)
{
       this->activityId = actId;
       this->day = d;
       this->hour = h;
       this->type = CONSTRAINT_ACTIVITY_PREFERRED_STARTING_TIME;
       this->permanentlyLocked=perm;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 9011 of file timeconstraint.cpp.

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

Here is the call graph for this function:

bool ConstraintActivityPreferredStartingTime::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 8787 of file timeconstraint.cpp.

{
       Activity* act;
       int i;
       for(i=0; i<r.nInternalActivities; i++){
              act=&r.internalActivitiesList[i];
              if(act->id==this->activityId)
                     break;
       }
       
       if(i==r.nInternalActivities){
              //assert(0);
              QMessageBox::warning(parent, tr("FET error in data"), 
                     tr("Following constraint is wrong (because it refers to invalid activity id. Please correct (maybe removing it is a solution)):\n%1").arg(this->getDetailedDescription(r)));
              return false;
       }

       if(this->day >= r.nDaysPerWeek){
              QMessageBox::information(parent, tr("FET information"),
               tr("Constraint activity preferred time 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->hour == r.nHoursPerDay){
              QMessageBox::information(parent, tr("FET information"),
               tr("Constraint activity preferred time is wrong because 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->hour > r.nHoursPerDay){
              QMessageBox::information(parent, tr("FET information"),
               tr("Constraint activity preferred time 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;
       }

       this->activityIndex=i;      
       return true;
}

Here is the call graph for this function:

double ConstraintActivityPreferredStartingTime::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 8920 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);

       nbroken=0;
       if(c.times[this->activityIndex]!=UNALLOCATED_TIME){
              int d=c.times[this->activityIndex]%r.nDaysPerWeek; //the day when this activity was scheduled
              int h=c.times[this->activityIndex]/r.nDaysPerWeek; //the hour
              if(this->day>=0)
                     nbroken+=abs(this->day-d);
              if(this->hour>=0)
                     nbroken+=abs(this->hour-h);
       }
       if(nbroken>0)
              nbroken=1;

       if(conflictsString!=NULL && nbroken>0){
              QString s=tr("Time constraint activity preferred starting time 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(this->activityId)
                     .arg(getActivityDetailedDescription(r, this->activityId))
                     .arg(CustomFETString::number(weightPercentage/100*nbroken));

              dl.append(s);
              cl.append(weightPercentage/100*nbroken);
       
              *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 8855 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("Act. id: %1 (%2) has a preferred starting time: %3", "%1 is the id, %2 is the detailed description of the activity. %3 is time (day and hour)")
        .arg(this->activityId)
        .arg(getActivityDetailedDescription(r, this->activityId))
        .arg(r.daysOfTheWeek[this->day]+" "+r.hoursOfTheDay[this->hour]);

       s+=", ";

       s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this->weightPercentage));
       s+=", ";
       s+=tr("PL:%1", "Abbreviation for permanently locked").arg(yesNoTranslated(this->permanentlyLocked));

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

{
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Activity with id=%1 (%2)", "%1 is the id, %2 is the detailed description of the activity")
              .arg(this->activityId)
              .arg(getActivityDetailedDescription(r, this->activityId));
       s+="\n";

       s+=tr("has a preferred starting time:");
       s+="\n";
       s+=tr("Day=%1").arg(r.daysOfTheWeek[this->day]);
       s+="\n";
       s+=tr("Hour=%1").arg(r.hoursOfTheDay[this->hour]);
       s+="\n";

       s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this->weightPercentage));s+="\n";
       if(this->permanentlyLocked){
              s+=tr("This activity is permanently locked, which means you cannot unlock it from the 'Timetable' menu"
              " (you can unlock this activity by removing the constraint from the constraints dialog or by setting the 'permanently"
              " locked' attribute false when editing this constraint)");
       }
       else{
              s+=tr("This activity is not permanently locked, which means you can unlock it from the 'Timetable' menu");
       }
       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 8837 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

       QString s="<ConstraintActivityPreferredStartingTime>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Activity_Id>"+CustomFETString::number(this->activityId)+"</Activity_Id>\n";
       if(this->day>=0)
              s+="   <Preferred_Day>"+protect(r.daysOfTheWeek[this->day])+"</Preferred_Day>\n";
       if(this->hour>=0)
              s+="   <Preferred_Hour>"+protect(r.hoursOfTheDay[this->hour])+"</Preferred_Hour>\n";
       s+="   <Permanently_Locked>";s+=trueFalse(this->permanentlyLocked);s+="</Permanently_Locked>\n";
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintActivityPreferredStartingTime>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 8830 of file timeconstraint.cpp.

{
       if(r.inactiveActivities.contains(this->activityId))
              return true;
       return false;
}

Implements TimeConstraint.

Definition at line 9004 of file timeconstraint.cpp.

{
       if(day<0 || day>=r.nDaysPerWeek || hour<0 || hour>=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 8966 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

       if(this->activityId==a->id)
              return true;
       return false;
}

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

Implements TimeConstraint.

Definition at line 8989 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 8996 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 8982 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 8975 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}
bool ConstraintActivityPreferredStartingTime::operator== ( ConstraintActivityPreferredStartingTime c)

Comparison operator - to be sure that we do not introduce duplicates.

Definition at line 8772 of file timeconstraint.cpp.

                                                                                                  {
       if(this->day!=c.day)
              return false;
       if(this->hour!=c.hour)
              return false;
       if(this->activityId!=c.activityId)
              return false;
       if(this->weightPercentage!=c.weightPercentage)
              return false;
       if(this->active!=c.active)
              return false;
       //no need to care about permanently locked
       return true;
}

Implements TimeConstraint.

Definition at line 9018 of file timeconstraint.cpp.

{
       assert(hasWrongDayOrHour(r));

       return false;
}

Here is the call graph for this function:


Member Data Documentation

bool TimeConstraint::active [inherited]

Definition at line 146 of file timeconstraint.h.

Activity id.

Definition at line 1978 of file timeconstraint.h.

The index of the activity in the rules (from 0 to rules.nActivities-1) - it is not the id of the activity.

Definition at line 1996 of file timeconstraint.h.

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

The preferred day.

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

Definition at line 1983 of file timeconstraint.h.

The preferred hour.

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

Definition at line 1988 of file timeconstraint.h.

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