Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintActivityPreferredRoom Class Reference

This is a constraint. More...

#include <spaceconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintActivityPreferredRoom ()
 ConstraintActivityPreferredRoom (double wp, int aid, const QString &room, bool perm)
bool operator== (ConstraintActivityPreferredRoom &c)
 Comparison operator - to be sure we do not introduce duplicates.
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 (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 isRelatedToRoom (Room *r)
 Returns true if this constraint is related to this room.
bool hasWrongDayOrHour (Rules &r)
bool canRepairWrongDayOrHour (Rules &r)
bool repairWrongDayOrHour (Rules &r)

Public Attributes

int _activity
int _room
int activityId
QString roomName
bool permanentlyLocked
double weightPercentage
 The weight (percentage) of this constraint.
bool active
QString comments
int type
 Specifies the type of this constraint (using the above constants).

Detailed Description

This is a constraint.

Its purpose: an activity must take part in the preferred room.

Definition at line 289 of file spaceconstraint.h.


Constructor & Destructor Documentation

ConstraintActivityPreferredRoom::ConstraintActivityPreferredRoom ( double  wp,
int  aid,
const QString &  room,
bool  perm 
)

Definition at line 737 of file spaceconstraint.cpp.


Member Function Documentation

Implements SpaceConstraint.

Definition at line 973 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0);

       return true;
}
bool ConstraintActivityPreferredRoom::computeInternalStructure ( QWidget *  parent,
Rules r 
) [virtual]

Computes the internal structure for this constraint.

Implements SpaceConstraint.

Definition at line 759 of file spaceconstraint.cpp.

{
       this->_activity=-1;
       int ac;
       for(ac=0; ac<r.nInternalActivities; ac++)
              if(r.internalActivitiesList[ac].id==this->activityId){
                     assert(this->_activity==-1);
                     this->_activity=ac;
                     break;
              }
       if(ac==r.nInternalActivities){
              QMessageBox::warning(parent, tr("FET error in data"), 
                     tr("Following constraint is wrong:\n%1").arg(this->getDetailedDescription(r)));

              return false;
       }
              
       this->_room = r.searchRoom(this->roomName);

       if(this->_room<0){
              QMessageBox::warning(parent, tr("FET error in data"), 
                     tr("Following constraint is wrong:\n%1").arg(this->getDetailedDescription(r)));
              return false;
       }

       assert(this->_room>=0);
       
       return true;
}

Here is the call graph for this function:

double ConstraintActivityPreferredRoom::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. We need also the allocation of the activities on days and hours. If conflictsString!=NULL, it will be initialized with a text explaining where this restriction is broken.

Implements SpaceConstraint.

Definition at line 874 of file spaceconstraint.cpp.

{
       //if the matrix roomsMatrix is already calculated, do not calculate it again!
       if(!c.roomsMatrixReady){
              c.roomsMatrixReady=true;
              rooms_conflicts = c.getRoomsMatrix(r, roomsMatrix);

              c.changedForMatrixCalculation=false;
       }

       //Calculates the number of conflicts

       int nbroken;
       
       bool ok=true;

       nbroken=0;

       int rm=c.rooms[this->_activity];
       if(/*rm!=UNALLOCATED_SPACE &&*/ rm!=this->_room){
              if(rm!=UNALLOCATED_SPACE){
                     ok=false;

                     if(conflictsString!=NULL){
                            QString s=tr("Space constraint activity preferred room broken for activity with id=%1 (%2), room=%3",
                                   "%1 is activity id, %2 is detailed description of activity")
                                   .arg(this->activityId)
                                   .arg(getActivityDetailedDescription(r, this->activityId))
                                   .arg(this->roomName);
                                   s += ". ";
                            s += tr("This increases the conflicts total by %1").arg(CustomFETString::number(weightPercentage/100* 1));
              
                            dl.append(s);
                            cl.append(1*weightPercentage/100);
                     
                            *conflictsString += s+"\n";
                     }
                     nbroken++;
              }
       }
       
       if(this->weightPercentage==100)
              assert(ok);

       return weightPercentage/100 * nbroken;
}

Here is the call graph for this function:

Returns a small description string for this constraint.

Implements SpaceConstraint.

Definition at line 814 of file spaceconstraint.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=tr("Activity preferred room"); s+=", ";
       s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this->weightPercentage));s+=", ";
       s+=tr("Id:%1 (%2)", "%1 is activity id, %2 is detailed description of activity")
              .arg(this->activityId)
              .arg(getActivityDetailedDescription(r, this->activityId));
       s+=", ";

       s+=tr("R:%1", "Room").arg(this->roomName);
       
       s+=", ";
       s+=tr("PL:%1", "Abbreviation for permanently locked").arg(yesNoTranslated(this->permanentlyLocked));

       return begin+s+end;
}

Here is the call graph for this function:

Returns a detailed description string for this constraint.

Implements SpaceConstraint.

Definition at line 840 of file spaceconstraint.cpp.

                                                                       {
       QString s=tr("Space constraint"); s+="\n";
       s+=tr("Activity preferred room"); s+="\n";
       s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this->weightPercentage));s+="\n";
       
       s+=tr("Activity id=%1 (%2)", "%1 is activity id, %2 is detailed description of activity")
              .arg(this->activityId)
              .arg(getActivityDetailedDescription(r, this->activityId));
       s+="\n";
       
       s+=tr("Room=%1").arg(this->roomName);s+="\n";
       
       if(this->permanentlyLocked){
              s+=tr("This activity is permanently locked, which means you cannot unlock it from the 'Timetable' menu"
              " (you can unlock this activity by removing the constraint from the constraints dialog or by setting the 'permanently"
              " locked' attribute false when editing this constraint)");
       }
       else{
              s+=tr("This activity is not permanently locked, which means you can unlock it from the 'Timetable' menu");
       }
       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 SpaceConstraint.

Definition at line 797 of file spaceconstraint.cpp.

                                                                  {
       Q_UNUSED(r);

       QString s="<ConstraintActivityPreferredRoom>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Activity_Id>"+CustomFETString::number(this->activityId)+"</Activity_Id>\n";
       s+="   <Room>"+protect(this->roomName)+"</Room>\n";
       
       s+="   <Permanently_Locked>";s+=trueFalse(this->permanentlyLocked);s+="</Permanently_Locked>\n";
              
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintActivityPreferredRoom>\n";

       return s;
}

Here is the call graph for this function:

Implements SpaceConstraint.

Definition at line 789 of file spaceconstraint.cpp.

{
       if(r.inactiveActivities.contains(this->activityId))
              return true;

       return false;
}

Implements SpaceConstraint.

Definition at line 967 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Returns true if this constraint is related to this activity.

Implements SpaceConstraint.

Definition at line 926 of file spaceconstraint.cpp.

{
       if(this->activityId==a->id)
              return true;
       return false;
}

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

Implements SpaceConstraint.

Definition at line 947 of file spaceconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this room.

Implements SpaceConstraint.

Definition at line 962 of file spaceconstraint.cpp.

{
       return r->name==this->roomName;
}

Returns true if this constraint is related to this students set.

Implements SpaceConstraint.

Definition at line 954 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this subject.

Implements SpaceConstraint.

Definition at line 940 of file spaceconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements SpaceConstraint.

Definition at line 933 of file spaceconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}
bool ConstraintActivityPreferredRoom::operator== ( ConstraintActivityPreferredRoom c)

Comparison operator - to be sure we do not introduce duplicates.

Definition at line 746 of file spaceconstraint.cpp.

                                                                                  {
       if(this->roomName!=c.roomName)
              return false;
       if(this->activityId!=c.activityId)
              return false;
       if(this->weightPercentage!=c.weightPercentage)
              return false;
       if(this->active!=c.active)
              return false;
       //no need to care about permanently locked
       return true;
}

Implements SpaceConstraint.

Definition at line 981 of file spaceconstraint.cpp.

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

       return true;
}

Member Data Documentation

Definition at line 296 of file spaceconstraint.h.

Definition at line 299 of file spaceconstraint.h.

bool SpaceConstraint::active [inherited]

Definition at line 102 of file spaceconstraint.h.

Definition at line 303 of file spaceconstraint.h.

QString SpaceConstraint::comments [inherited]

Definition at line 104 of file spaceconstraint.h.

Definition at line 307 of file spaceconstraint.h.

Definition at line 305 of file spaceconstraint.h.

int SpaceConstraint::type [inherited]

Specifies the type of this constraint (using the above constants).

Definition at line 109 of file spaceconstraint.h.

The weight (percentage) of this constraint.

Definition at line 100 of file spaceconstraint.h.


The documentation for this class was generated from the following files: