Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintMaxDaysBetweenActivities Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintMaxDaysBetweenActivities ()
 ConstraintMaxDaysBetweenActivities (double wp, int n_act, const QList< int > &act, int n)
 Constructor, using: the weight, the number of activities and the list of activities.
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

int n_activities
 The number of activities involved in this constraint.
QList< int > activitiesId
 The activities involved in this constraint (id)
int maxDays
 The number of maximum 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

Definition at line 591 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintMaxDaysBetweenActivities::ConstraintMaxDaysBetweenActivities ( double  wp,
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 2084 of file timeconstraint.cpp.

 : TimeConstraint(wp)
 {
       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->maxDays=n;

       this->type=CONSTRAINT_MAX_DAYS_BETWEEN_ACTIVITIES;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 2386 of file timeconstraint.cpp.

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

Here is the call graph for this function:

bool ConstraintMaxDaysBetweenActivities::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 2100 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 ConstraintMaxDaysBetweenActivities::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 2232 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>maxDays){
                                                 tt=dist-maxDays;
                                                 
                                                 //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>maxDays){
                                                 tt=dist-maxDays;
                                                 
                                                 //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 max days between activities broken: activity with id=%1 (%2) conflicts with activity with id=%3 (%4), being %5 days too far away"
                                                  ", on days %6 and %7", "%1 is the id, %2 is the detailed description of the activity, %3 id, %4 det. descr.")
                                                  .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+=".";
                                                 
                                                 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 2184 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("Max 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", "Abbreviation for maximum days").arg(this->maxDays);

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

                                                                          {
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Maximum 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("Maximum number of days=%1").arg(this->maxDays);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 2169 of file timeconstraint.cpp.

                                                                     {
       Q_UNUSED(r);

       QString s="<ConstraintMaxDaysBetweenActivities>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\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+="   <MaxDays>"+CustomFETString::number(this->maxDays)+"</MaxDays>\n";
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintMaxDaysBetweenActivities>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

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

{
       if(maxDays>=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 2339 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 2363 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 2370 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 2356 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 2349 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

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

{
       assert(hasWrongDayOrHour(r));
       
       if(maxDays>=r.nDaysPerWeek)
              maxDays=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 620 of file timeconstraint.h.

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

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

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

The number of maximum days between each 2 activities.

Definition at line 608 of file timeconstraint.h.

The number of activities involved in this constraint.

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