Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintThreeActivitiesGrouped Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintThreeActivitiesGrouped ()
 ConstraintThreeActivitiesGrouped (double wp, int firstActId, int secondActId, int thirdActId)
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 firstActivityId
 First activity id.
int secondActivityId
 Second activity id.
int thirdActivityId
int firstActivityIndex
 The index of the first activity in the rules (from 0 to rules.nActivities-1) - it is not the id of the activity.
int secondActivityIndex
 The index of the second activity in the rules (from 0 to rules.nActivities-1) - it is not the id of the activity.
int thirdActivityIndex
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 2773 of file timeconstraint.h.


Constructor & Destructor Documentation

Definition at line 12704 of file timeconstraint.cpp.

ConstraintThreeActivitiesGrouped::ConstraintThreeActivitiesGrouped ( double  wp,
int  firstActId,
int  secondActId,
int  thirdActId 
)

Definition at line 12710 of file timeconstraint.cpp.

       : TimeConstraint(wp)
{
       this->firstActivityId = firstActId;
       this->secondActivityId=secondActId;
       this->thirdActivityId=thirdActId;
       this->type = CONSTRAINT_THREE_ACTIVITIES_GROUPED;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 13048 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0);
       
       return true;
}
bool ConstraintThreeActivitiesGrouped::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 12719 of file timeconstraint.cpp.

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

       this->firstActivityIndex=i; 

       
       for(i=0; i<r.nInternalActivities; i++){
              act=&r.internalActivitiesList[i];
              if(act->id==this->secondActivityId)
                     break;
       }
       
       if(i==r.nInternalActivities){      
              //assert(0);
              QMessageBox::warning(parent, tr("FET error in data"), 
                     tr("Following constraint is wrong (refers to inexistent activity ids):\n%1").arg(this->getDetailedDescription(r)));
              return false;
       }

       this->secondActivityIndex=i;
       
       
       for(i=0; i<r.nInternalActivities; i++){
              act=&r.internalActivitiesList[i];
              if(act->id==this->thirdActivityId)
                     break;
       }
       
       if(i==r.nInternalActivities){      
              //assert(0);
              QMessageBox::warning(parent, tr("FET error in data"), 
                     tr("Following constraint is wrong (refers to inexistent activity ids):\n%1").arg(this->getDetailedDescription(r)));
              return false;
       }

       this->thirdActivityIndex=i;
       
       if(firstActivityIndex==secondActivityIndex || firstActivityIndex==thirdActivityIndex || secondActivityIndex==thirdActivityIndex){
              //assert(0);
              QMessageBox::warning(parent, tr("FET error in data"), 
                     tr("Following constraint is wrong (refers to same activities):\n%1").arg(this->getDetailedDescription(r)));
              return false;
       }
       assert(firstActivityIndex!=secondActivityIndex && firstActivityIndex!=thirdActivityIndex && secondActivityIndex!=thirdActivityIndex);
       
       return true;
}

Here is the call graph for this function:

double ConstraintThreeActivitiesGrouped::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 12872 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->firstActivityIndex]!=UNALLOCATED_TIME && c.times[this->secondActivityIndex]!=UNALLOCATED_TIME && c.times[this->thirdActivityIndex]!=UNALLOCATED_TIME){
              int fd=c.times[this->firstActivityIndex]%r.nDaysPerWeek; //the day when first activity was scheduled
              int fh=c.times[this->firstActivityIndex]/r.nDaysPerWeek; //the hour
              int sd=c.times[this->secondActivityIndex]%r.nDaysPerWeek; //the day when second activity was scheduled
              int sh=c.times[this->secondActivityIndex]/r.nDaysPerWeek; //the hour
              int td=c.times[this->thirdActivityIndex]%r.nDaysPerWeek; //the day when third activity was scheduled
              int th=c.times[this->thirdActivityIndex]/r.nDaysPerWeek; //the hour
              
              if(!(fd==sd && fd==td))
                     nbroken=1;
              else{
                     assert(fd==sd && fd==td && sd==td);
                     int a1=-1,a2=-1,a3=-1;
                     if(fh>=sh && fh>=th && sh>=th){
                            a1=thirdActivityIndex;
                            a2=secondActivityIndex;
                            a3=firstActivityIndex;
                            //out<<"321"<<endl;
                     }
                     else if(fh>=sh && fh>=th && th>=sh){
                            a1=secondActivityIndex;
                            a2=thirdActivityIndex;
                            a3=firstActivityIndex;
                            //out<<"231"<<endl;
                     }
                     else if(sh>=fh && sh>=th && fh>=th){
                            a1=thirdActivityIndex;
                            a2=firstActivityIndex;
                            a3=secondActivityIndex;
                            //out<<"312"<<endl;
                     }
                     else if(sh>=fh && sh>=th && th>=fh){
                            a1=firstActivityIndex;
                            a2=thirdActivityIndex;
                            a3=secondActivityIndex;
                            //out<<"132"<<endl;
                     }
                     else if(th>=fh && th>=sh && fh>=sh){
                            a1=secondActivityIndex;
                            a2=firstActivityIndex;
                            a3=thirdActivityIndex;
                            //out<<"213"<<endl;
                     }
                     else if(th>=fh && th>=sh && sh>=fh){
                            a1=firstActivityIndex;
                            a2=secondActivityIndex;
                            a3=thirdActivityIndex;
                            //out<<"123"<<endl;
                     }
                     else
                            assert(0);
                     
                     int a1d=c.times[a1]%r.nDaysPerWeek; //the day for a1
                     int a1h=c.times[a1]/r.nDaysPerWeek; //the day for a1
                     int a1dur=r.internalActivitiesList[a1].duration;

                     int a2d=c.times[a2]%r.nDaysPerWeek; //the day for a2
                     int a2h=c.times[a2]/r.nDaysPerWeek; //the day for a2
                     int a2dur=r.internalActivitiesList[a2].duration;

                     int a3d=c.times[a3]%r.nDaysPerWeek; //the day for a3
                     int a3h=c.times[a3]/r.nDaysPerWeek; //the day for a3
                     //int a3dur=r.internalActivitiesList[a3].duration;
                     
                     int hoursBetweenThem=-1;
                     
                     assert(a1d==a2d && a1d==a3d);
                     
                     if(a1h+a1dur<=a2h && a2h+a2dur<=a3h){
                            hoursBetweenThem=0;
                            for(int hh=a1h+a1dur; hh<a2h; hh++)
                                   if(!breakDayHour[a1d][hh])
                                          hoursBetweenThem++;

                            for(int hh=a2h+a2dur; hh<a3h; hh++)
                                   if(!breakDayHour[a2d][hh])
                                          hoursBetweenThem++;
                     }
                     
                     if(hoursBetweenThem==0)
                            nbroken=0;
                     else
                            nbroken=1;
              }
       }
       
       assert(nbroken==0 || nbroken==1);

       if(conflictsString!=NULL && nbroken>0){
              QString s=tr("Time constraint three activities grouped broken for first activity with id=%1 (%2), "
               "second activity with id=%3 (%4) and third activity with id=%5 (%6), increases conflicts total by %7",
               "%1 is the id, %2 is the detailed description of the activity, %3 id, %4 det. descr., %5 id, %6 det. descr.")
               .arg(this->firstActivityId)
               .arg(getActivityDetailedDescription(r, this->firstActivityId))
               .arg(this->secondActivityId)
               .arg(getActivityDetailedDescription(r, this->secondActivityId))
               .arg(this->thirdActivityId)
               .arg(getActivityDetailedDescription(r, this->thirdActivityId))
               .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 12809 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("Constraint three activities grouped:");
       s+=" ";
       
       s+=tr("first act. id: %1", "act.=activity").arg(this->firstActivityId);
       s+=", ";
       s+=tr("second act. id: %1", "act.=activity").arg(this->secondActivityId);
       s+=", ";
       s+=tr("third act. id: %1", "act.=activity").arg(this->thirdActivityId);
       s+=", ";
       s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this->weightPercentage));

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

{
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Constraint three activities grouped (the activities must be placed in the same day, "
        "one immediately following the other, as a block of three activities, in any order, possibly separated by breaks)"); s+="\n";
       
       s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this->weightPercentage));s+="\n";

       s+=tr("First activity id=%1 (%2)", "%1 is the id, %2 is the detailed description of the activity.")
              .arg(this->firstActivityId)
              .arg(getActivityDetailedDescription(r, this->firstActivityId));
       s+="\n";

       s+=tr("Second activity id=%1 (%2)", "%1 is the id, %2 is the detailed description of the activity.")
              .arg(this->secondActivityId)
              .arg(getActivityDetailedDescription(r, this->secondActivityId));
       s+="\n";
       
       s+=tr("Third activity id=%1 (%2)", "%1 is the id, %2 is the detailed description of the activity.")
              .arg(this->thirdActivityId)
              .arg(getActivityDetailedDescription(r, this->thirdActivityId));
       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 12794 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

       QString s="<ConstraintThreeActivitiesGrouped>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";
       s+="   <First_Activity_Id>"+CustomFETString::number(this->firstActivityId)+"</First_Activity_Id>\n";
       s+="   <Second_Activity_Id>"+CustomFETString::number(this->secondActivityId)+"</Second_Activity_Id>\n";
       s+="   <Third_Activity_Id>"+CustomFETString::number(this->thirdActivityId)+"</Third_Activity_Id>\n";
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintThreeActivitiesGrouped>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 12783 of file timeconstraint.cpp.

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

Implements TimeConstraint.

Definition at line 13042 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Returns true if this constraint is related to this activity.

Implements TimeConstraint.

Definition at line 13000 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

       if(this->firstActivityId==a->id)
              return true;
       if(this->secondActivityId==a->id)
              return true;
       if(this->thirdActivityId==a->id)
              return true;
       return false;
}

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

Implements TimeConstraint.

Definition at line 13027 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 13034 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 13020 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 13013 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements TimeConstraint.

Definition at line 13056 of file timeconstraint.cpp.

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

       return true;
}

Member Data Documentation

bool TimeConstraint::active [inherited]

Definition at line 146 of file timeconstraint.h.

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

First activity id.

Definition at line 2780 of file timeconstraint.h.

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

Definition at line 2793 of file timeconstraint.h.

Second activity id.

Definition at line 2785 of file timeconstraint.h.

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

Definition at line 2798 of file timeconstraint.h.

Definition at line 2787 of file timeconstraint.h.

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