Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintTwoActivitiesGrouped Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintTwoActivitiesGrouped ()
 ConstraintTwoActivitiesGrouped (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 2717 of file timeconstraint.h.


Constructor & Destructor Documentation

Definition at line 12422 of file timeconstraint.cpp.

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

Definition at line 12428 of file timeconstraint.cpp.

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

Member Function Documentation

Implements TimeConstraint.

Definition at line 12685 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0);
       
       return true;
}
bool ConstraintTwoActivitiesGrouped::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 12436 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 ConstraintTwoActivitiesGrouped::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 12562 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(fd==sd && fh+r.internalActivitiesList[this->firstActivityIndex].duration <= sh){
                     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;
              }
              else if(fd==sd && sh+r.internalActivitiesList[this->secondActivityIndex].duration <= fh){
                     int h;
                     int d=sd;
                     assert(d==fd);
                     for(h=sh+r.internalActivitiesList[this->secondActivityIndex].duration; h<r.nHoursPerDay; h++)
                            if(!breakDayHour[d][h])
                                   break;
                                   
                     assert(h<=fh);       
                            
                     if(h!=fh)
                            nbroken=1;
              }
              else
                     nbroken=1;
       }
       
       assert(nbroken==0 || nbroken==1);

       if(conflictsString!=NULL && nbroken>0){
              QString s=tr("Time constraint two activities grouped 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 12506 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 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("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 12532 of file timeconstraint.cpp.

{
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Constraint two activities grouped (the activities must be placed in the same day, "
        "one immediately following the other, 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";

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

{
       Q_UNUSED(r);

       QString s="<ConstraintTwoActivitiesGrouped>\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+="</ConstraintTwoActivitiesGrouped>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

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

{
       Q_UNUSED(r);
       return false;
}

Returns true if this constraint is related to this activity.

Implements TimeConstraint.

Definition at line 12639 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 12664 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 12671 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 12657 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 12650 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements TimeConstraint.

Definition at line 12693 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 2724 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 2735 of file timeconstraint.h.

Second activity id.

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