Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintTwoActivitiesOrdered Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintTwoActivitiesOrdered ()
 ConstraintTwoActivitiesOrdered (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 2833 of file timeconstraint.h.


Constructor & Destructor Documentation

Definition at line 13067 of file timeconstraint.cpp.

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

Definition at line 13073 of file timeconstraint.cpp.

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

Member Function Documentation

Implements TimeConstraint.

Definition at line 13303 of file timeconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0);
       
       return true;
}
bool ConstraintTwoActivitiesOrdered::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 13081 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 ConstraintTwoActivitiesOrdered::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 13207 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
                + r.internalActivitiesList[this->firstActivityIndex].duration-1; //the end hour of first activity
              int sd=c.times[this->secondActivityIndex]%r.nDaysPerWeek; //the day when second activity was scheduled
              int sh=c.times[this->secondActivityIndex]/r.nDaysPerWeek; //the start hour of second activity
              
              if(!(fd<sd || (fd==sd && fh<sh)))
                     nbroken=1;
       }
       
       assert(nbroken==0 || nbroken==1);

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

{
       QString s=tr("Time constraint");s+="\n";
       s+=tr("Constraint two activities ordered (second activity must be placed at any time in the week after the first"
        " activity)"); 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 13137 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

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

Here is the call graph for this function:

Implements TimeConstraint.

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

{
       Q_UNUSED(r);
       return false;
}

Returns true if this constraint is related to this activity.

Implements TimeConstraint.

Definition at line 13257 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 13282 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 13289 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 13275 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 13268 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements TimeConstraint.

Definition at line 13311 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 2840 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 2851 of file timeconstraint.h.

Second activity id.

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