Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintBasicCompulsorySpace Class Reference

This class comprises all the basic compulsory constraints (constraints which must be fulfilled for any timetable) - the space allocation part. More...

#include <spaceconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintBasicCompulsorySpace ()
 ConstraintBasicCompulsorySpace (double wp)
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

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 class comprises all the basic compulsory constraints (constraints which must be fulfilled for any timetable) - the space allocation part.

Definition at line 197 of file spaceconstraint.h.


Constructor & Destructor Documentation

Definition at line 101 of file spaceconstraint.cpp.

Definition at line 108 of file spaceconstraint.cpp.


Member Function Documentation

Implements SpaceConstraint.

Definition at line 421 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       assert(0);

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

Computes the internal structure for this constraint.

Implements SpaceConstraint.

Definition at line 114 of file spaceconstraint.cpp.

{
       Q_UNUSED(parent);
       Q_UNUSED(r);
       
       return true;
}
double ConstraintBasicCompulsorySpace::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 184 of file spaceconstraint.cpp.

       {

       assert(r.internalStructureComputed);

       int roomsConflicts;

       //This constraint fitness calculation routine is called firstly,
       //so we can compute the rooms conflicts faster this way.
       if(!c.roomsMatrixReady){
              c.roomsMatrixReady=true;
              rooms_conflicts = roomsConflicts = c.getRoomsMatrix(r, roomsMatrix);
              
              c.changedForMatrixCalculation=false;
       }
       else{
              assert(rooms_conflicts>=0);
              roomsConflicts=rooms_conflicts;
       }

       int i;

       int unallocated; //unallocated activities
       int nre; //number of room exhaustions
       int nor; //number of overwhelmed rooms

       //part without logging....................................................................
       if(conflictsString==NULL){
              //Unallocated activities
              unallocated=0;
              nor=0;
              for(i=0; i<r.nInternalActivities; i++)
                     if(c.rooms[i]==UNALLOCATED_SPACE){
                            //Firstly, we consider a big clash each unallocated activity.
                            //Needs to be very a large constant, bigger than any other broken constraint.
                            unallocated += /*r.internalActivitiesList[i].duration * r.internalActivitiesList[i].nSubgroups * */ 10000;
                            //(an unallocated activity for a year is more important than an unallocated activity for a subgroup)
                     }
                     else if(c.rooms[i]!=UNSPECIFIED_ROOM){
                            //The capacity of each room must be respected
                            //(the number of students must be less than the capacity)
                            int rm=c.rooms[i];
                            if(r.internalActivitiesList[i].nTotalStudents>r.internalRoomsList[rm]->capacity){
                                   int tmp;
                                   //if(r.internalActivitiesList[i].parity==PARITY_WEEKLY)
                                   //     tmp=2;
                                   //else
                                          tmp=1;
       
                                   nor+=tmp;
                            }
                     }

              //Calculates the number of rooms exhaustion (when a room is occupied
              //for more than one activity at the same time)
              /*nre=0;
              for(i=0; i<r.nInternalRooms; i++)
                     for(int j=0; j<r.nDaysPerWeek; j++)
                            for(int k=0; k<r.nHoursPerDay; k++){
                                   int tmp=roomsMatrix[i][j][k]-1;
                                   if(tmp>0){
                                          if(conflictsString!=NULL){
                                                 QString s=tr("Space constraint basic compulsory: room with name %1 has more than one allocated activity on day %2, hour %3.")
                                                        .arg(r.internalRoomsList[i]->name)
                                                        .arg(r.daysOfTheWeek[j])
                                                        .arg(r.hoursOfTheDay[k]);
                                                 s+=" ";
                                                 s+=tr("This increases the conflicts total by %1").arg(tmp*weightPercentage/100);
                                          
                                                 dl.append(s);
                                                 cl.append(tmp*weightPercentage/100);
                                          
                                                 *conflictsString += s+"\n";
                                          }
                                          nre+=tmp;
                                   }
                            }
              */
              nre=roomsConflicts;
       }
       //part with logging....................................................................
       else{
              //Unallocated activities
              unallocated=0;
              nor=0;
              for(i=0; i<r.nInternalActivities; i++)
                     if(c.rooms[i]==UNALLOCATED_SPACE){
                            //Firstly, we consider a big clash each unallocated activity.
                            //Needs to be very a large constant, bigger than any other broken constraint.
                            unallocated += /*r.internalActivitiesList[i].duration * r.internalActivitiesList[i].nSubgroups * */ 10000;
                            //(an unallocated activity for a year is more important than an unallocated activity for a subgroup)
                            if(conflictsString!=NULL){
                                   QString s=tr("Space constraint basic compulsory broken: unallocated activity with id=%1 (%2)",
                                          "%2 is the detailed description of the activity").arg(r.internalActivitiesList[i].id).arg(getActivityDetailedDescription(r, r.internalActivitiesList[i].id));
                                   s+=QString(" - ");
                                   s+=tr("this increases the conflicts total by %1").arg(CustomFETString::number(weightPercentage/100*10000));
                                   
                                   dl.append(s);
                                   cl.append(weightPercentage/100 * 10000);
                                   
                                   *conflictsString+=s+"\n";

                                   /*(*conflictsString) += tr("Space constraint basic compulsory: unallocated activity with id=%1").arg(r.internalActivitiesList[i].id);
                                   (*conflictsString) += tr(" - this increases the conflicts total by %1")
                                          .arg(weight*10000);
                                   (*conflictsString) += "\n";*/
                            }
                     }
                     else if(c.rooms[i]!=UNSPECIFIED_ROOM){
                            //The capacity of each room must be respected
                            //(the number of students must be less than the capacity)
                            int rm=c.rooms[i];
                            if(r.internalActivitiesList[i].nTotalStudents>r.internalRoomsList[rm]->capacity){
                                   int tmp;
                                   //if(r.internalActivitiesList[i].parity==PARITY_WEEKLY)
                                   //     tmp=2;
                                   //else
                                          tmp=1;
       
                                   nor+=tmp;

                                   if(conflictsString!=NULL){
                                          QString s;
                                          s=tr("Space constraint basic compulsory: room %1 has allocated activity with id %2 (%3) and the capacity of the room is overloaded",
                                                 "%2 is act id, %3 is detailed description of activity")
                                          .arg(r.internalRoomsList[rm]->name)
                                          .arg(r.internalActivitiesList[i].id)
                                          .arg(getActivityDetailedDescription(r, r.internalActivitiesList[i].id));
                                          s+=". ";
                                          s+=tr("This increases conflicts total by %1").arg(CustomFETString::number(weightPercentage/100));
                                          
                                          dl.append(s);
                                          cl.append(weightPercentage/100);
                                          
                                          *conflictsString += s+"\n";
                                   }
                            }
                     }

              //Calculates the number of rooms exhaustion (when a room is occupied
              //for more than one activity at the same time)
              nre=0;
              for(i=0; i<r.nInternalRooms; i++)
                     for(int j=0; j<r.nDaysPerWeek; j++)
                            for(int k=0; k<r.nHoursPerDay; k++){
                                   int tmp=roomsMatrix[i][j][k]-1;
                                   if(tmp>0){
                                          if(conflictsString!=NULL){
                                                 QString s=tr("Space constraint basic compulsory: room with name %1 has more than one allocated activity on day %2, hour %3.")
                                                        .arg(r.internalRoomsList[i]->name)
                                                        .arg(r.daysOfTheWeek[j])
                                                        .arg(r.hoursOfTheDay[k]);
                                                 s+=" ";
                                                 s+=tr("This increases the conflicts total by %1").arg(CustomFETString::number(tmp*weightPercentage/100));
                                          
                                                 dl.append(s);
                                                 cl.append(tmp*weightPercentage/100);
                                          
                                                 *conflictsString += s+"\n";
                                                 /*(*conflictsString)+=tr("Space constraint basic compulsory: room with name %1 has more than one allocated activity on day %2, hour %3.")
                                                        .arg(r.internalRoomsList[i]->name)
                                                        .arg(r.daysOfTheWeek[j])
                                                        .arg(r.hoursOfTheDay[k]);
                                                 (*conflictsString)+=" ";
                                                 (*conflictsString)+=tr("This increases the conflicts total by %1").arg(tmp*weight);
                                                 (*conflictsString)+="\n";*/
                                          }
                                          nre+=tmp;
                                   }
                            }
       }
       /*if(roomsConflicts!=-1)
              assert(nre==roomsConflicts);*/ //just a check, works only on logged fitness calculation
              
       if(this->weightPercentage==100){
              //assert(unallocated==0);
              assert(nre==0);
              assert(nor==0);
       }

       return weightPercentage/100 * (unallocated + nre + nor); //fitness factor
}

Here is the call graph for this function:

Returns a small description string for this constraint.

Implements SpaceConstraint.

Definition at line 142 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("Basic compulsory constraints (space)");
       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 SpaceConstraint.

Definition at line 161 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);

       QString s=tr("These are the basic compulsory constraints (referring to rooms allocation) for any timetable");s+="\n";
       s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this->weightPercentage));s+="\n";

       s+=tr("The basic space constraints try to avoid:");s+="\n";
       s+=QString("- "); s+=tr("rooms assigned to more than one activity simultaneously"); s+="\n";
       s+=QString("- "); s+=tr("activities with more students than the capacity of the room"); 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:

Returns an XML description of this constraint.

Implements SpaceConstraint.

Definition at line 129 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);

       QString s = "<ConstraintBasicCompulsorySpace>\n";
       assert(this->weightPercentage==100.0);
       s+="   <Weight_Percentage>"+CustomFETString::number(this->weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintBasicCompulsorySpace>\n";
       return s;
}

Here is the call graph for this function:

Implements SpaceConstraint.

Definition at line 122 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       
       return false;
}

Implements SpaceConstraint.

Definition at line 415 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       return false;
}

Returns true if this constraint is related to this activity.

Implements SpaceConstraint.

Definition at line 372 of file spaceconstraint.cpp.

{
       Q_UNUSED(a);

       return false;
}

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

Implements SpaceConstraint.

Definition at line 393 of file spaceconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this room.

Implements SpaceConstraint.

Definition at line 408 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 400 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 386 of file spaceconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements SpaceConstraint.

Definition at line 379 of file spaceconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements SpaceConstraint.

Definition at line 429 of file spaceconstraint.cpp.

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

       return true;
}

Member Data Documentation

bool SpaceConstraint::active [inherited]

Definition at line 102 of file spaceconstraint.h.

QString SpaceConstraint::comments [inherited]

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