Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintActivitiesOccupyMaxTimeSlotsFromSelection Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintActivitiesOccupyMaxTimeSlotsFromSelection ()
 ConstraintActivitiesOccupyMaxTimeSlotsFromSelection (double wp, QList< int > a_L, QList< int > d_L, QList< int > h_L, int max_slots)
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 (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

QList< int > activitiesIds
QList< int > selectedDays
QList< int > selectedHours
int maxOccupiedTimeSlots
QList< int > _activitiesIndices
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 3589 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintActivitiesOccupyMaxTimeSlotsFromSelection::ConstraintActivitiesOccupyMaxTimeSlotsFromSelection ( double  wp,
QList< int >  a_L,
QList< int >  d_L,
QList< int >  h_L,
int  max_slots 
)

Definition at line 17296 of file timeconstraint.cpp.

       : TimeConstraint(wp)
{
       assert(d_L.count()==h_L.count());

       this->activitiesIds=a_L;
       this->selectedDays=d_L;
       this->selectedHours=h_L;
       this->maxOccupiedTimeSlots=max_slots;
       
       this->type=CONSTRAINT_ACTIVITIES_OCCUPY_MAX_TIME_SLOTS_FROM_SELECTION;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 17610 of file timeconstraint.cpp.

{
       assert(hasWrongDayOrHour(r));
       
       return true;
}

Here is the call graph for this function:

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 17310 of file timeconstraint.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);
                     
       assert(this->selectedDays.count()==this->selectedHours.count());
       
       for(int k=0; k<this->selectedDays.count(); k++){
              if(this->selectedDays.at(k) >= r.nDaysPerWeek){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint activities occupy max time slots from selection 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->selectedHours.at(k) == r.nHoursPerDay){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint activities occupy max time slots from selection is wrong because a preferred 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;
              }
              if(this->selectedHours.at(k) > r.nHoursPerDay){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint activities occupy max time slots from selection is wrong because it refers to removed hour. 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->selectedDays.at(k)<0 || this->selectedHours.at(k)<0){
                     QMessageBox::information(parent, tr("FET information"),
                      tr("Constraint activities occupy max time slots from selection is wrong because hour or day is not specified for a slot (-1). 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->_activitiesIndices.count()>0)
              return true;
       else{
              QMessageBox::warning(parent, tr("FET error in data"), 
                     tr("Following constraint is wrong (refers to no activities). Please correct it:\n%1").arg(this->getDetailedDescription(r)));
              return false;
       }
}

Here is the call graph for this function:

double ConstraintActivitiesOccupyMaxTimeSlotsFromSelection::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 17477 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);

       Matrix2D<bool> used;
       used.resize(r.nDaysPerWeek, r.nHoursPerDay);
       for(int d=0; d<r.nDaysPerWeek; d++)
              for(int h=0; h<r.nHoursPerDay; h++)
                     used[d][h]=false;
       
       foreach(int ai, this->_activitiesIndices){
              if(c.times[ai]!=UNALLOCATED_TIME){
                     Activity* act=&r.internalActivitiesList[ai];
                     int d=c.times[ai]%r.nDaysPerWeek;
                     int h=c.times[ai]/r.nDaysPerWeek;
                     for(int dur=0; dur<act->duration; dur++){
                            assert(h+dur<r.nHoursPerDay);
                            used[d][h+dur]=true;
                     }
              }
       }

       int cnt=0;
       assert(this->selectedDays.count()==this->selectedHours.count());
       for(int t=0; t<this->selectedDays.count(); t++){
              int d=this->selectedDays.at(t);
              int h=this->selectedHours.at(t);
              
              if(used[d][h])
                     cnt++;
       }

       nbroken=0;
       
       if(cnt > this->maxOccupiedTimeSlots){
              nbroken=1;
       
              if(conflictsString!=NULL){
                     QString s=tr("Time constraint %1 broken - this should not happen, as this kind of constraint should "
                      "have only 100.0% weight. Please report error!").arg(this->getDescription(r));
                     
                     dl.append(s);
                     cl.append(weightPercentage/100.0);
              
                     *conflictsString+= s+"\n";
              }
       }

       if(weightPercentage==100.0)
              assert(nbroken==0);
       return nbroken * weightPercentage / 100.0;
}

Here is the call graph for this function:

Returns a small description string for this constraint.

Implements TimeConstraint.

Definition at line 17405 of file timeconstraint.cpp.

{
       QString begin=QString("");
       if(!active)
              begin="X - ";
              
       QString end=QString("");
       if(!comments.isEmpty())
              end=", "+tr("C: %1", "Comments").arg(comments);
              
       assert(this->selectedDays.count()==this->selectedHours.count());

       QString actids=QString("");
       foreach(int aid, this->activitiesIds)
              actids+=CustomFETString::number(aid)+QString(", ");
       actids.chop(2);
              
       QString timeslots=QString("");
       for(int i=0; i<this->selectedDays.count(); i++)
              timeslots+=r.daysOfTheWeek[selectedDays.at(i)]+QString(" ")+r.hoursOfTheDay[selectedHours.at(i)]+QString(", ");
       timeslots.chop(2);
       
       QString s=tr("Activities occupy max time slots from selection, WP:%1, NA:%2, A: %3, STS: %4, MTS:%5", "Constraint description. WP means weight percentage, "
        "NA means the number of activities, A means activities list, STS means selected time slots, MTS means max time slots")
        .arg(CustomFETString::number(this->weightPercentage))
        .arg(CustomFETString::number(this->activitiesIds.count()))
        .arg(actids)
        .arg(timeslots)
        .arg(CustomFETString::number(this->maxOccupiedTimeSlots));
       
       return begin+s+end;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns a detailed description string for this constraint.

Implements TimeConstraint.

Definition at line 17438 of file timeconstraint.cpp.

{
       assert(this->selectedDays.count()==this->selectedHours.count());

       QString actids=QString("");
       foreach(int aid, this->activitiesIds)
              actids+=CustomFETString::number(aid)+QString(", ");
       actids.chop(2);
              
       QString timeslots=QString("");
       for(int i=0; i<this->selectedDays.count(); i++)
              timeslots+=r.daysOfTheWeek[selectedDays.at(i)]+QString(" ")+r.hoursOfTheDay[selectedHours.at(i)]+QString(", ");
       timeslots.chop(2);
       
       QString s=tr("Time constraint"); s+="\n";
       s+=tr("Activities occupy max time slots from selection"); 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("Selected time slots: %1").arg(timeslots); s+="\n";
       s+=tr("Maximum number of occupied slots from selection=%1").arg(CustomFETString::number(this->maxOccupiedTimeSlots)); 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 17378 of file timeconstraint.cpp.

{
       assert(this->selectedDays.count()==this->selectedHours.count());

       QString s="<ConstraintActivitiesOccupyMaxTimeSlotsFromSelection>\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+="   <Number_of_Selected_Time_Slots>"+CustomFETString::number(this->selectedDays.count())+"</Number_of_Selected_Time_Slots>\n";
       for(int i=0; i<this->selectedDays.count(); i++){
              s+="   <Selected_Time_Slot>\n";
              s+="          <Selected_Day>"+protect(r.daysOfTheWeek[this->selectedDays.at(i)])+"</Selected_Day>\n";
              s+="          <Selected_Hour>"+protect(r.hoursOfTheDay[this->selectedHours.at(i)])+"</Selected_Hour>\n";
              s+="   </Selected_Time_Slot>\n";
       }
       s+="   <Max_Number_of_Occupied_Time_Slots>"+CustomFETString::number(this->maxOccupiedTimeSlots)+"</Max_Number_of_Occupied_Time_Slots>\n";
       
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintActivitiesOccupyMaxTimeSlotsFromSelection>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 17367 of file timeconstraint.cpp.

{
       //returns true if all activities are inactive
       
       foreach(int aid, this->activitiesIds)
              if(!r.inactiveActivities.contains(aid))
                     return false;

       return true;
}

Implements TimeConstraint.

Definition at line 17595 of file timeconstraint.cpp.

{
       assert(selectedDays.count()==selectedHours.count());
       
       for(int i=0; i<selectedDays.count(); i++)
              if(selectedDays.at(i)<0 || selectedDays.at(i)>=r.nDaysPerWeek
               || selectedHours.at(i)<0 || selectedHours.at(i)>=r.nHoursPerDay)
                     return true;
                     
       if(maxOccupiedTimeSlots>r.nDaysPerWeek*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 TimeConstraint.

Definition at line 17559 of file timeconstraint.cpp.

{
       Q_UNUSED(r);

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

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

Implements TimeConstraint.

Definition at line 17580 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 17587 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 17573 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 17566 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Definition at line 17543 of file timeconstraint.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 TimeConstraint.

Definition at line 17617 of file timeconstraint.cpp.

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

       return true;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 3601 of file timeconstraint.h.

bool TimeConstraint::active [inherited]

Definition at line 146 of file timeconstraint.h.

Definition at line 3593 of file timeconstraint.h.

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

Definition at line 3598 of file timeconstraint.h.

Definition at line 3595 of file timeconstraint.h.

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