Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintActivitiesOccupyMaxDifferentRooms Class Reference

#include <spaceconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintActivitiesOccupyMaxDifferentRooms ()
 ConstraintActivitiesOccupyMaxDifferentRooms (double wp, QList< int > a_L, int max_rooms)
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.
void removeUseless (Rules &r)
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

QList< int > activitiesIds
int maxDifferentRooms
QList< int > _activitiesIndices
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

Definition at line 1435 of file spaceconstraint.h.


Constructor & Destructor Documentation

Definition at line 6795 of file spaceconstraint.cpp.


Member Function Documentation

Implements SpaceConstraint.

Definition at line 7035 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0);

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

Computes the internal structure for this constraint.

Implements SpaceConstraint.

Definition at line 6805 of file spaceconstraint.cpp.

{
       this->_activitiesIndices.clear();
       
       QSet<int> req=this->activitiesIds.toSet();
       assert(req.count()==this->activitiesIds.count());
       
       //this cares about inactive activities, also, so do not assert this->_actIndices.count()==this->actIds.count()
       int i;
       for(i=0; i<r.nInternalActivities; i++)
              if(req.contains(r.internalActivitiesList[i].id))
                     this->_activitiesIndices.append(i);
                     
       
       if(this->_activitiesIndices.count()<2){
              QMessageBox::warning(parent, tr("FET error in data"),
                     tr("Following constraint is wrong (refers to less than two activities). Please correct it:\n%1").arg(this->getDetailedDescription(r)));
              return false;
       }
       else{
              assert(this->_activitiesIndices.count()>=2);
              return true;
       }
}

Here is the call graph for this function:

double ConstraintActivitiesOccupyMaxDifferentRooms::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 6924 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=0;
       
       QSet<int> usedRooms;
       
       foreach(int ai, this->_activitiesIndices){
              if(c.rooms[ai]!=UNALLOCATED_SPACE && c.rooms[ai]!=UNSPECIFIED_ROOM)
                     if(!usedRooms.contains(c.rooms[ai]))
                            usedRooms.insert(c.rooms[ai]);
       }
       
       if(usedRooms.count() > this->maxDifferentRooms){
              nbroken=1;

              if(conflictsString!=NULL){
                     QString s=tr("Space constraint activities occupy max different rooms broken");
                     s += QString(". ");
                     s += tr("This increases the conflicts total by %1").arg(CustomFETString::number(nbroken*weightPercentage/100));
       
                     dl.append(s);
                     cl.append(nbroken*weightPercentage/100);
              
                     *conflictsString += s+"\n";
              }
       }
       
       if(this->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 SpaceConstraint.

Definition at line 6866 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 actids=QString("");
       foreach(int aid, this->activitiesIds)
              actids+=CustomFETString::number(aid)+QString(", ");
       actids.chop(2);
              
       QString s=tr("Activities occupy max different rooms, WP:%1, NA:%2, A: %3, MDR:%4", "Constraint description. WP means weight percentage, "
        "NA means the number of activities, A means activities list, MDR means max different rooms")
        .arg(CustomFETString::number(this->weightPercentage))
        .arg(CustomFETString::number(this->activitiesIds.count()))
        .arg(actids)
        .arg(CustomFETString::number(this->maxDifferentRooms));
       
       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 6893 of file spaceconstraint.cpp.

{
       QString actids=QString("");
       foreach(int aid, this->activitiesIds)
              actids+=CustomFETString::number(aid)+QString(", ");
       actids.chop(2);
              
       QString s=tr("Space constraint"); s+="\n";
       s+=tr("Activities occupy max different rooms"); s+="\n";
       s+=tr("Weight (percentage)=%1").arg(CustomFETString::number(this->weightPercentage)); s+="\n";
       s+=tr("Number of activities=%1").arg(CustomFETString::number(this->activitiesIds.count())); s+="\n";
       foreach(int id, this->activitiesIds){
              s+=tr("Activity with id=%1 (%2)", "%1 is the id, %2 is the detailed description of the activity")
               .arg(id)
               .arg(getActivityDetailedDescription(r, id));
              s+="\n";
       }
       s+=tr("Maximum number of different rooms=%1").arg(CustomFETString::number(this->maxDifferentRooms)); 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 6846 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);

       QString s="<ConstraintActivitiesOccupyMaxDifferentRooms>\n";
       
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";
       
       s+="   <Number_of_Activities>"+CustomFETString::number(this->activitiesIds.count())+"</Number_of_Activities>\n";
       foreach(int aid, this->activitiesIds)
              s+="   <Activity_Id>"+CustomFETString::number(aid)+"</Activity_Id>\n";
       
       s+="   <Max_Number_of_Different_Rooms>"+CustomFETString::number(this->maxDifferentRooms)+"</Max_Number_of_Different_Rooms>\n";
       
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintActivitiesOccupyMaxDifferentRooms>\n";
       return s;
}

Here is the call graph for this function:

Implements SpaceConstraint.

Definition at line 6831 of file spaceconstraint.cpp.

{
       //returns true if all or all but one activities are inactive
       
       int cnt=0;
       foreach(int aid, this->activitiesIds)
              if(r.inactiveActivities.contains(aid))
                     cnt++;
                     
       if(this->activitiesIds.count()>=2 && (cnt==this->activitiesIds.count() || cnt==this->activitiesIds.count()-1) )
              return true;
       else
              return false;
}

Implements SpaceConstraint.

Definition at line 7029 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Returns true if this constraint is related to this activity.

Implements SpaceConstraint.

Definition at line 6988 of file spaceconstraint.cpp.

{
       return this->activitiesIds.contains(a->id);
}

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

Implements SpaceConstraint.

Definition at line 7007 of file spaceconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this room.

Implements SpaceConstraint.

Definition at line 7022 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       
       return false;
}

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

Implements SpaceConstraint.

Definition at line 7014 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 7000 of file spaceconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements SpaceConstraint.

Definition at line 6993 of file spaceconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Definition at line 6972 of file spaceconstraint.cpp.

{
       QSet<int> validActs;
       
       foreach(Activity* act, r.activitiesList)
              validActs.insert(act->id);
              
       QList<int> newActs;
       
       foreach(int aid, activitiesIds)
              if(validActs.contains(aid))
                     newActs.append(aid);
                     
       activitiesIds=newActs;
}

Implements SpaceConstraint.

Definition at line 7043 of file spaceconstraint.cpp.

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

       return true;
}

Member Data Documentation

Definition at line 1444 of file spaceconstraint.h.

bool SpaceConstraint::active [inherited]

Definition at line 102 of file spaceconstraint.h.

Definition at line 1439 of file spaceconstraint.h.

QString SpaceConstraint::comments [inherited]

Definition at line 104 of file spaceconstraint.h.

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