Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintActivitiesNotOverlapping Class Reference

This is a constraint. More...

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintActivitiesNotOverlapping ()
 ConstraintActivitiesNotOverlapping (double wp, int n_act, const QList< int > &act)
 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 _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 do not overlap. The number of conflicts is considered the number of overlapping hours.

Definition at line 445 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintActivitiesNotOverlapping::ConstraintActivitiesNotOverlapping ( double  wp,
int  n_act,
const QList< int > &  act 
)

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

Definition at line 1413 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));

       this->type=CONSTRAINT_ACTIVITIES_NOT_OVERLAPPING;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 1701 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0);
       
       return true;
}
bool ConstraintActivitiesNotOverlapping::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 1426 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 ConstraintActivitiesNotOverlapping::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 1556 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;

                                          //the number of overlapping hours
                                          int tt=0;
                                          if(day1==day2){
                                                 int start=max(hour1, hour2);
                                                 int stop=min(hour1+duration1, hour2+duration2);
                                                 if(stop>start)
                                                        tt+=stop-start;
                                          }
                                          
                                          nbroken+=tt;
                                   }
                            }
                     }
              }
       }
       //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;
       
                                          //the number of overlapping hours
                                          int tt=0;
                                          if(day1==day2){
                                                 int start=max(hour1, hour2);
                                                 int stop=min(hour1+duration1, hour2+duration2);
                                                 if(stop>start)
                                                        tt+=stop-start;
                                          }

                                          //The overlapping hours, considering weekly activities more important than fortnightly ones
                                          int tmp=tt;

                                          nbroken+=tmp;

                                          if(tt>0 && conflictsString!=NULL){

                                                 QString s=tr("Time constraint activities not overlapping broken: activity with id=%1 (%2) overlaps with activity with id=%3 (%4) on a number of %5 periods",
                                                  "%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);
                                                 s+=", ";
                                                 s+=tr("conflicts factor increase=%1").arg(CustomFETString::number(tmp*weightPercentage/100));
                                                 
                                                 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 1509 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("Activities not overlapping");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]);
              if(i<this->n_activities-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 1533 of file timeconstraint.cpp.

                                                                          {
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Activities must not overlap");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";
       }

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

                                                                     {
       Q_UNUSED(r);

       QString s="<ConstraintActivitiesNotOverlapping>\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+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintActivitiesNotOverlapping>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

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

{
       Q_UNUSED(r);
       return false;
}

Returns true if this constraint is related to this activity.

Implements TimeConstraint.

Definition at line 1656 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 1680 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 1687 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 1673 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 1666 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

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

{
       Q_UNUSED(r);
       assert(0); //should check hasWrongDayOrHour, firstly

       return true;
}

Member Data Documentation

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

Definition at line 469 of file timeconstraint.h.

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

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

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

The number of activities involved in this constraint.

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