Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintTwoActivitiesConsecutive Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintTwoActivitiesConsecutive ()
 ConstraintTwoActivitiesConsecutive (double wp, int firstActId, int secondActId)
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 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.
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 2661 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintTwoActivitiesConsecutive::ConstraintTwoActivitiesConsecutive ( double  wp,
int  firstActId,
int  secondActId 
)

Definition at line 12159 of file timeconstraint.cpp.

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

Member Function Documentation

Implements TimeConstraint.

Definition at line 12403 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0);
       
       return true;
}
bool ConstraintTwoActivitiesConsecutive::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 12167 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;
       
       if(firstActivityIndex==secondActivityIndex){     
              //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);
       
       return true;
}

Here is the call graph for this function:

double ConstraintTwoActivitiesConsecutive::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 12293 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){
              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
              
              if(fd!=sd)
                     nbroken=1;
              else if(fh+r.internalActivitiesList[this->firstActivityIndex].duration>sh)
                     nbroken=1;
              else if(fd==sd){
                     int h;
                     int d=fd;
                     assert(d==sd);
                     for(h=fh+r.internalActivitiesList[this->firstActivityIndex].duration; h<r.nHoursPerDay; h++)
                            if(!breakDayHour[d][h])
                                   break;
                                   
                     assert(h<=sh);       
                            
                     if(h!=sh)
                            nbroken=1;
              }
       }
       
       assert(nbroken==0 || nbroken==1);

       if(conflictsString!=NULL && nbroken>0){
              QString s=tr("Time constraint two activities consecutive broken for first activity with id=%1 (%2) and "
               "second activity with id=%3 (%4), increases conflicts total by %5", "%1 is the id, %2 is the detailed description of the activity, %3 id, %4 det. descr.")
               .arg(this->firstActivityId)
               .arg(getActivityDetailedDescription(r, this->firstActivityId))
               .arg(this->secondActivityId)
               .arg(getActivityDetailedDescription(r, this->secondActivityId))
               .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 12237 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 two activities consecutive:");
       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("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 12263 of file timeconstraint.cpp.

{
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Constraint two activities consecutive (second activity must be placed immediately after the first"
        " activity, in the same day, 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";

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

{
       Q_UNUSED(r);

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

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 12214 of file timeconstraint.cpp.

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

Implements TimeConstraint.

Definition at line 12397 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Returns true if this constraint is related to this activity.

Implements TimeConstraint.

Definition at line 12357 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

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

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

Implements TimeConstraint.

Definition at line 12382 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 12389 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 12375 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 12368 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements TimeConstraint.

Definition at line 12411 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 2668 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 2679 of file timeconstraint.h.

Second activity id.

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