Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintMinDaysBetweenActivities Class Reference

This is a constraint. More...

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintMinDaysBetweenActivities ()
 ConstraintMinDaysBetweenActivities (double wp, bool adjacentIfBroken, int n_act, const QList< int > &act, int n)
 Constructor, using: the weight, the number of activities and the list of activities.
bool operator== (ConstraintMinDaysBetweenActivities &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.
void removeUseless (Rules &r)
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

bool consecutiveIfSameDay
int n_activities
 The number of activities involved in this constraint.
QList< int > activitiesId
 The activities involved in this constraint (id)
int minDays
 The number of minimum days between each 2 activities.
int _n_activities
 The number of activities involved in this constraint - internal structure.
QList< int > _activities
 The activities involved in this constraint (index in the rules) - internal structure.
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 aims at scheduling a set of activities so that they have a minimum of N days between any two of them.

Definition at line 513 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintMinDaysBetweenActivities::ConstraintMinDaysBetweenActivities ( double  wp,
bool  adjacentIfBroken,
int  n_act,
const QList< int > &  act,
int  n 
)

Constructor, using: the weight, the number of activities and the list of activities.

Definition at line 1726 of file timeconstraint.cpp.

 : TimeConstraint(wp)
 {
       this->consecutiveIfSameDay=cisd;

       assert(nact>=2);
       assert(act.count()==nact);
       this->n_activities=nact;
       this->activitiesId.clear();
       for(int i=0; i<nact; i++)
              this->activitiesId.append(act.at(i));

       assert(n>0);
       this->minDays=n;

       this->type=CONSTRAINT_MIN_DAYS_BETWEEN_ACTIVITIES;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 2058 of file timeconstraint.cpp.

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

Here is the call graph for this function:

bool ConstraintMinDaysBetweenActivities::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 1762 of file timeconstraint.cpp.

{
       //compute the indices of the activities,
       //based on their unique ID

       assert(this->n_activities==this->activitiesId.count());

       this->_activities.clear();
       for(int i=0; i<this->n_activities; i++){
              int j;
              Activity* act;
              for(j=0; j<r.nInternalActivities; j++){
                     act=&r.internalActivitiesList[j];
                     if(act->id==this->activitiesId[i]){
                            this->_activities.append(j);
                            break;
                     }
              }
       }
       this->_n_activities=this->_activities.count();
       
       if(this->_n_activities<=1){
              QMessageBox::warning(parent, tr("FET error in data"), 
                     tr("Following constraint is wrong (because you need 2 or more activities. Please correct it):\n%1").arg(this->getDetailedDescription(r)));
              //assert(0);
              return false;
       }

       return true;
}

Here is the call graph for this function:

double ConstraintMinDaysBetweenActivities::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 1897 of file timeconstraint.cpp.

{
       assert(r.internalStructureComputed);

       int nbroken;

       //We do not use the matrices 'subgroupsMatrix' nor 'teachersMatrix'.

       //sum the overlapping hours for all pairs of activities.
       //without logging
       if(conflictsString==NULL){
              nbroken=0;
              for(int i=1; i<this->_n_activities; i++){
                     int t1=c.times[this->_activities[i]];
                     if(t1!=UNALLOCATED_TIME){
                            int day1=t1%r.nDaysPerWeek;
                            int hour1=t1/r.nDaysPerWeek;
                            int duration1=r.internalActivitiesList[this->_activities[i]].duration;

                            for(int j=0; j<i; j++){
                                   int t2=c.times[this->_activities[j]];
                                   if(t2!=UNALLOCATED_TIME){
                                          int day2=t2%r.nDaysPerWeek;
                                          int hour2=t2/r.nDaysPerWeek;
                                          int duration2=r.internalActivitiesList[this->_activities[j]].duration;
                                   
                                          int tmp;
                                          int tt=0;
                                          int dist=abs(day1-day2);
                                          if(dist<minDays){
                                                 tt=minDays-dist;
                                                 
                                                 if(this->consecutiveIfSameDay && day1==day2)
                                                        assert( day1==day2 && (hour1+duration1==hour2 || hour2+duration2==hour1) );
                                          }
                                          
                                          tmp=tt;
       
                                          nbroken+=tmp;
                                   }
                            }
                     }
              }
       }
       //with logging
       else{
              nbroken=0;
              for(int i=1; i<this->_n_activities; i++){
                     int t1=c.times[this->_activities[i]];
                     if(t1!=UNALLOCATED_TIME){
                            int day1=t1%r.nDaysPerWeek;
                            int hour1=t1/r.nDaysPerWeek;
                            int duration1=r.internalActivitiesList[this->_activities[i]].duration;

                            for(int j=0; j<i; j++){
                                   int t2=c.times[this->_activities[j]];
                                   if(t2!=UNALLOCATED_TIME){
                                          int day2=t2%r.nDaysPerWeek;
                                          int hour2=t2/r.nDaysPerWeek;
                                          int duration2=r.internalActivitiesList[this->_activities[j]].duration;
                                   
                                          int tmp;
                                          int tt=0;
                                          int dist=abs(day1-day2);

                                          if(dist<minDays){
                                                 tt=minDays-dist;
                                                 
                                                 if(this->consecutiveIfSameDay && day1==day2)
                                                        assert( day1==day2 && (hour1+duration1==hour2 || hour2+duration2==hour1) );
                                          }

                                          tmp=tt;
       
                                          nbroken+=tmp;

                                          if(tt>0 && conflictsString!=NULL){
                                                 QString s=tr("Time constraint min days between activities broken: activity with id=%1 (%2) conflicts with activity with id=%3 (%4), being %5 days too close, on days %6 and %7",
                                                  "%1 is the id, %2 is the detailed description of the activity, %3 id, %4 det. descr. Close here means near")
                                                  .arg(this->activitiesId[i])
                                                  .arg(getActivityDetailedDescription(r, this->activitiesId[i]))
                                                  .arg(this->activitiesId[j])
                                                  .arg(getActivityDetailedDescription(r, this->activitiesId[j]))
                                                  .arg(tt)
                                                  .arg(r.daysOfTheWeek[day1])
                                                  .arg(r.daysOfTheWeek[day2]);
                                                  ;

                                                 s+=", ";
                                                 s+=tr("conflicts factor increase=%1").arg(CustomFETString::number(tmp*weightPercentage/100));
                                                 s+=".";
                                                 
                                                 if(this->consecutiveIfSameDay && day1==day2){
                                                        s+=" ";
                                                        s+=tr("The activities are placed consecutively in the timetable, because you selected this option"
                                                         " in case the activities are in the same day");
                                                 }
                                                 
                                                 dl.append(s);
                                                 cl.append(tmp*weightPercentage/100);
                                                 
                                                 *conflictsString+= s+"\n";
                                          }
                                   }
                            }
                     }
              }
       }

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

Here is the call graph for this function:

Returns a small description string for this constraint.

Implements TimeConstraint.

Definition at line 1847 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("Min days between activities");s+=", ";
       s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this->weightPercentage));s+=", ";
       s+=tr("NA:%1", "Number of activities").arg(this->n_activities);s+=", ";
       for(int i=0; i<this->n_activities; i++){
              s+=tr("Id:%1", "Id of activity").arg(this->activitiesId[i]);s+=", ";
       }
       s+=tr("mD:%1", "Min days").arg(this->minDays);s+=", ";
       s+=tr("CSD:%1", "Consecutive if same day").arg(yesNoTranslated(this->consecutiveIfSameDay));

       return begin+s+end;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns a detailed description string for this constraint.

Implements TimeConstraint.

Definition at line 1871 of file timeconstraint.cpp.

                                                                          {
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Minimum number of days between activities");s+="\n";
       s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this->weightPercentage));s+="\n";
       s+=tr("Number of activities=%1").arg(this->n_activities);s+="\n";
       for(int i=0; i<this->n_activities; i++){
              s+=tr("Activity with id=%1 (%2)", "%1 is the id, %2 is the detailed description of the activity")
                     .arg(this->activitiesId[i])
                     .arg(getActivityDetailedDescription(r, this->activitiesId[i]));
              s+="\n";
       }
       s+=tr("Minimum number of days=%1").arg(this->minDays);s+="\n";
       s+=tr("Consecutive if same day=%1").arg(yesNoTranslated(this->consecutiveIfSameDay));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 1831 of file timeconstraint.cpp.

                                                                     {
       Q_UNUSED(r);

       QString s="<ConstraintMinDaysBetweenActivities>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Consecutive_If_Same_Day>";s+=trueFalse(this->consecutiveIfSameDay);s+="</Consecutive_If_Same_Day>\n";
       s+="   <Number_of_Activities>"+CustomFETString::number(this->n_activities)+"</Number_of_Activities>\n";
       for(int i=0; i<this->n_activities; i++)
              s+="   <Activity_Id>"+CustomFETString::number(this->activitiesId[i])+"</Activity_Id>\n";
       s+="   <MinDays>"+CustomFETString::number(this->minDays)+"</MinDays>\n";
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintMinDaysBetweenActivities>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 1817 of file timeconstraint.cpp.

{
       int count=0;

       for(int i=0; i<this->n_activities; i++)
              if(r.inactiveActivities.contains(this->activitiesId[i]))
                     count++;

       if(this->n_activities-count<=1)
              return true;
       else
              return false;
}

Implements TimeConstraint.

Definition at line 2050 of file timeconstraint.cpp.

{
       if(minDays>=r.nDaysPerWeek)
              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 2011 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

       for(int i=0; i<this->n_activities; i++)
              if(this->activitiesId[i]==a->id)
                     return true;
       return false;
}

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

Implements TimeConstraint.

Definition at line 2035 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 2042 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 2028 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 2021 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

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

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

Definition at line 1744 of file timeconstraint.cpp.

                                                                                        {
       assert(this->n_activities==this->activitiesId.count());
       assert(c.n_activities==c.activitiesId.count());

       if(this->n_activities!=c.n_activities)
              return false;
       for(int i=0; i<this->n_activities; i++)
              if(this->activitiesId[i]!=c.activitiesId[i])
                     return false;
       if(this->minDays!=c.minDays)
              return false;
       if(this->weightPercentage!=c.weightPercentage)
              return false;
       if(this->consecutiveIfSameDay!=c.consecutiveIfSameDay)
              return false;
       return true;
}

Definition at line 1793 of file timeconstraint.cpp.

{
       //remove the activitiesId which no longer exist (used after the deletion of an activity)
       
       assert(this->n_activities==this->activitiesId.count());

       QList<int> tmpList;

       for(int i=0; i<this->n_activities; i++){
              for(int k=0; k<r.activitiesList.size(); k++){
                     Activity* act=r.activitiesList[k];
                     if(act->id==this->activitiesId[i]){
                            tmpList.append(act->id);
                            break;
                     }
              }
       }
       
       this->activitiesId=tmpList;
       this->n_activities=this->activitiesId.count();

       r.internalStructureComputed=false;
}

Implements TimeConstraint.

Definition at line 2065 of file timeconstraint.cpp.

{
       assert(hasWrongDayOrHour(r));
       
       if(minDays>=r.nDaysPerWeek)
              minDays=r.nDaysPerWeek-1;

       return true;
}

Here is the call graph for this function:


Member Data Documentation

The activities involved in this constraint (index in the rules) - internal structure.

Definition at line 545 of file timeconstraint.h.

The number of activities involved in this constraint - internal structure.

Definition at line 540 of file timeconstraint.h.

bool TimeConstraint::active [inherited]

Definition at line 146 of file timeconstraint.h.

The activities involved in this constraint (id)

Definition at line 527 of file timeconstraint.h.

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

Definition at line 517 of file timeconstraint.h.

The number of minimum days between each 2 activities.

Definition at line 533 of file timeconstraint.h.

The number of activities involved in this constraint.

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