Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintRoomNotAvailableTimes Class Reference

#include <spaceconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintRoomNotAvailableTimes ()
 ConstraintRoomNotAvailableTimes (double wp, const QString &rn, QList< int > d, QList< int > h)
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

QList< int > days
QList< int > hours
QString room
 The room's name.
int room_ID
 The room's id, or index in the rules.
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 234 of file spaceconstraint.h.


Constructor & Destructor Documentation

ConstraintRoomNotAvailableTimes::ConstraintRoomNotAvailableTimes ( double  wp,
const QString &  rn,
QList< int >  d,
QList< int >  h 
)

Definition at line 446 of file spaceconstraint.cpp.

       : SpaceConstraint(wp)
{
       this->room=rn;
       this->days=d;
       this->hours=h;
       this->type=CONSTRAINT_ROOM_NOT_AVAILABLE_TIMES;
}

Member Function Documentation

Implements SpaceConstraint.

Definition at line 696 of file spaceconstraint.cpp.

{
       assert(hasWrongDayOrHour(r));

       return true;
}

Here is the call graph for this function:

bool ConstraintRoomNotAvailableTimes::computeInternalStructure ( QWidget *  parent,
Rules r 
) [virtual]

Computes the internal structure for this constraint.

Implements SpaceConstraint.

Definition at line 549 of file spaceconstraint.cpp.

                                                                                       {
       this->room_ID=r.searchRoom(this->room);
       
       if(this->room_ID<0){
              QMessageBox::warning(parent, tr("FET warning"),
               tr("Constraint room not available times is wrong because it refers to inexistent room."
               " Please correct it (removing it might be a solution). Please report potential bug. Constraint is:\n%1").arg(this->getDetailedDescription(r)));
               
              return false;
       }      

       assert(days.count()==hours.count());
       for(int k=0; k<days.count(); k++){
              if(this->days.at(k) >= r.nDaysPerWeek){
                     QMessageBox::warning(parent, tr("FET information"),
                      tr("Constraint room not available times is wrong because it refers to removed day. Please correct"
                      " and try again. Correcting means editing the constraint and updating information. Constraint is:\n%1").arg(this->getDetailedDescription(r)));
               
                     return false;
              }             
              if(this->hours.at(k) >= r.nHoursPerDay){
                     QMessageBox::warning(parent, tr("FET information"),
                      tr("Constraint room not available times is wrong because an hour is too late (after the last acceptable slot). Please correct"
                      " and try again. Correcting means editing the constraint and updating information. Constraint is:\n%1").arg(this->getDetailedDescription(r)));
               
                     return false;
              }
       }
       
       assert(this->room_ID>=0);
       
       return true;
}

Here is the call graph for this function:

double ConstraintRoomNotAvailableTimes::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 583 of file spaceconstraint.cpp.

{
       //if the matrices 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 hours when the roomr is supposed to be occupied,
       //but it is not available
       //This function consideres all the hours, I mean if there are for example 5 weekly courses
       //scheduled on that hour (which is already a broken compulsory constraint - we only
       //are allowed 1 weekly activity for a certain room at a certain hour) we calculate
       //5 broken constraints for that function.
       //TODO: decide if it is better to consider only 2 or 10 as a return value in this particular case
       //(currently it is 10)
       int rm=this->room_ID;

       int nbroken;

       nbroken=0;

       assert(days.count()==hours.count());
       for(int k=0; k<days.count(); k++){
              int d=days.at(k);
              int h=hours.at(k);
              
              if(roomsMatrix[rm][d][h]>0){
                     nbroken+=roomsMatrix[rm][d][h];
       
                     if(conflictsString!=NULL){
                            QString s= tr("Space constraint room not available times broken for room: %1, on day %2, hour %3")
                             .arg(r.internalRoomsList[rm]->name)
                             .arg(r.daysOfTheWeek[d])
                             .arg(r.hoursOfTheDay[h]);
                            s += ". ";
                            s += tr("This increases the conflicts total by %1")
                             .arg(CustomFETString::number(roomsMatrix[rm][d][h]*weightPercentage/100));
                             
                            dl.append(s);
                            cl.append(roomsMatrix[rm][d][h]*weightPercentage/100);
                     
                            *conflictsString += s+"\n";
                     }
              }
       }
       
       if(this->weightPercentage==100)
              assert(nbroken==0);

       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 484 of file spaceconstraint.cpp.

                                                               {
       QString begin=QString("");
       if(!active)
              begin="X - ";

       QString end=QString("");
       if(!comments.isEmpty())
              end=", "+tr("C: %1", "Comments").arg(comments);

       QString s=tr("Room not available");s+=", ";
       s+=tr("WP:%1\%", "Weight percentage").arg(CustomFETString::number(this->weightPercentage));s+=", ";
       s+=tr("R:%1", "Room").arg(this->room);s+=", ";

       s+=tr("NA at:", "Not available at");
       s+=" ";
       assert(days.count()==hours.count());
       for(int i=0; i<days.count(); i++){
              if(this->days.at(i)>=0){
                     s+=r.daysOfTheWeek[this->days.at(i)];
                     s+=" ";
              }
              if(this->hours.at(i)>=0){
                     s+=r.hoursOfTheDay[this->hours.at(i)];
              }
              if(i<days.count()-1)
                     s+="; ";
       }

       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 515 of file spaceconstraint.cpp.

                                                                       {
       QString s=tr("Space constraint");s+="\n";
       s+=tr("Room not available");s+="\n";
       s+=tr("Weight (percentage)=%1\%").arg(CustomFETString::number(this->weightPercentage));s+="\n";
       s+=tr("Room=%1").arg(this->room);s+="\n";

       s+=tr("Not available at:");
       s+="\n";
       assert(days.count()==hours.count());
       for(int i=0; i<days.count(); i++){
              if(this->days.at(i)>=0){
                     s+=r.daysOfTheWeek[this->days.at(i)];
                     s+=" ";
              }
              if(this->hours.at(i)>=0){
                     s+=r.hoursOfTheDay[this->hours.at(i)];
              }
              if(i<days.count()-1)
                     s+="; ";
       }
       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 462 of file spaceconstraint.cpp.

                                                                  {
       QString s="<ConstraintRoomNotAvailableTimes>\n";
       s+="   <Weight_Percentage>"+CustomFETString::number(weightPercentage)+"</Weight_Percentage>\n";
       s+="   <Room>"+protect(this->room)+"</Room>\n";

       s+="   <Number_of_Not_Available_Times>"+CustomFETString::number(this->days.count())+"</Number_of_Not_Available_Times>\n";
       assert(days.count()==hours.count());
       for(int i=0; i<days.count(); i++){
              s+="   <Not_Available_Time>\n";
              if(this->days.at(i)>=0)
                     s+="          <Day>"+protect(r.daysOfTheWeek[this->days.at(i)])+"</Day>\n";
              if(this->hours.at(i)>=0)
                     s+="          <Hour>"+protect(r.hoursOfTheDay[this->hours.at(i)])+"</Hour>\n";
              s+="   </Not_Available_Time>\n";
       }

       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintRoomNotAvailableTimes>\n";
       return s;
}

Here is the call graph for this function:

Implements SpaceConstraint.

Definition at line 455 of file spaceconstraint.cpp.

{
       Q_UNUSED(r);
       
       return false;
}

Implements SpaceConstraint.

Definition at line 684 of file spaceconstraint.cpp.

{
       assert(days.count()==hours.count());
       
       for(int i=0; i<days.count(); i++)
              if(days.at(i)<0 || days.at(i)>=r.nDaysPerWeek
               || hours.at(i)<0 || hours.at(i)>=r.nHoursPerDay)
                     return true;

       return false;
}

Here is the caller graph for this function:

Returns true if this constraint is related to this activity.

Implements SpaceConstraint.

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

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this room.

Implements SpaceConstraint.

Definition at line 679 of file spaceconstraint.cpp.

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

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

Implements SpaceConstraint.

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

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements SpaceConstraint.

Definition at line 650 of file spaceconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Implements SpaceConstraint.

Definition at line 703 of file spaceconstraint.cpp.

{
       assert(hasWrongDayOrHour(r));
       
       assert(days.count()==hours.count());
       
       QList<int> newDays;
       QList<int> newHours;
       
       for(int i=0; i<days.count(); i++)
              if(days.at(i)>=0 && days.at(i)<r.nDaysPerWeek
               && hours.at(i)>=0 && hours.at(i)<r.nHoursPerDay){
                     newDays.append(days.at(i));
                     newHours.append(hours.at(i));
              }
       
       days=newDays;
       hours=newHours;
       
       r.internalStructureComputed=false;
       setRulesModifiedAndOtherThings(&r);

       return true;
}

Here is the call graph for this function:


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.

Definition at line 239 of file spaceconstraint.h.

Definition at line 240 of file spaceconstraint.h.

The room's name.

Definition at line 245 of file spaceconstraint.h.

The room's id, or index in the rules.

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