Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintMinGapsBetweenActivities Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintMinGapsBetweenActivities ()
 ConstraintMinGapsBetweenActivities (double wp, int n_act, const QList< int > &actList, int ngaps)
 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 minGaps
 The number of minimum gaps between each 2 activities, if on the same day.
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 659 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintMinGapsBetweenActivities::ConstraintMinGapsBetweenActivities ( double  wp,
int  n_act,
const QList< int > &  actList,
int  ngaps 
)

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

Definition at line 2412 of file timeconstraint.cpp.

 : TimeConstraint(wp)
 {
       this->n_activities=nact;
       assert(nact==actList.count());
       this->activitiesId.clear();
       for(int i=0; i<nact; i++)
              this->activitiesId.append(actList.at(i));

       assert(ngaps>0);
       this->minGaps=ngaps;

       this->type=CONSTRAINT_MIN_GAPS_BETWEEN_ACTIVITIES;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 2680 of file timeconstraint.cpp.

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

Here is the call graph for this function:

bool ConstraintMinGapsBetweenActivities::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 2427 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 ConstraintMinGapsBetweenActivities::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 2559 of file timeconstraint.cpp.

{
       assert(r.internalStructureComputed);

       int nbroken;

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

       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==0){ //same day
                                          assert(day1==day2);
                                          if(hour2>=hour1){
                                                 //assert(hour1+duration1<=hour2); not true for activities which are not incompatible
                                                 if(hour1+duration1+minGaps > hour2)
                                                        tt = (hour1+duration1+minGaps) - hour2;
                                          }
                                          else{
                                                 //assert(hour2+duration2<=hour1); not true for activities which are not incompatible
                                                 if(hour2+duration2+minGaps > hour1)
                                                        tt = (hour2+duration2+minGaps) - hour1;
                                          }
                                   }

                                   tmp=tt;
       
                                   nbroken+=tmp;

                                   if(tt>0 && conflictsString!=NULL){
                                          QString s=tr("Time constraint min gaps between activities broken: activity with id=%1 (%2) conflicts with activity with id=%3 (%4), they are on the same day %5 and there are %6 extra hours between them",
                                                 "%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(r.daysOfTheWeek[day1])
                                           .arg(tt);

                                          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 2511 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 gaps 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("mG:%1", "Minimum number of gaps").arg(this->minGaps);

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

                                                                          {
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Minimum gaps between activities (if activities on the same day)");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 gaps=%1").arg(this->minGaps);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 2496 of file timeconstraint.cpp.

                                                                     {
       Q_UNUSED(r);

       QString s="<ConstraintMinGapsBetweenActivities>\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+="   <MinGaps>"+CustomFETString::number(this->minGaps)+"</MinGaps>\n";
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintMinGapsBetweenActivities>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

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

{
       if(minGaps>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 2633 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 2657 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 2664 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 2650 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 2643 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

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

{
       assert(hasWrongDayOrHour(r));
       
       if(minGaps>r.nHoursPerDay)
              minGaps=r.nHoursPerDay;

       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 688 of file timeconstraint.h.

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

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

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

The number of minimum gaps between each 2 activities, if on the same day.

Definition at line 676 of file timeconstraint.h.

The number of activities involved in this constraint.

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