Back to index

fet  5.18.0
Public Member Functions | Public Attributes
ConstraintActivitiesMaxSimultaneousInSelectedTimeSlots Class Reference

#include <timeconstraint.h>

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

List of all members.

Public Member Functions

 ConstraintActivitiesMaxSimultaneousInSelectedTimeSlots ()
 ConstraintActivitiesMaxSimultaneousInSelectedTimeSlots (double wp, QList< int > a_L, QList< int > d_L, QList< int > h_L, int max_simultaneous)
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 maxSimultaneous
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 3636 of file timeconstraint.h.


Constructor & Destructor Documentation

ConstraintActivitiesMaxSimultaneousInSelectedTimeSlots::ConstraintActivitiesMaxSimultaneousInSelectedTimeSlots ( double  wp,
QList< int >  a_L,
QList< int >  d_L,
QList< int >  h_L,
int  max_simultaneous 
)

Definition at line 17654 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->maxSimultaneous=max_simultaneous;
       
       this->type=CONSTRAINT_ACTIVITIES_MAX_SIMULTANEOUS_IN_SELECTED_TIME_SLOTS;
}

Member Function Documentation

Implements TimeConstraint.

Definition at line 17965 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 17668 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 max simultaneous in selected time slots 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 max simultaneous in selected time slots 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 max simultaneous in selected time slots 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 max simultaneous in selected time slots 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 ConstraintActivitiesMaxSimultaneousInSelectedTimeSlots::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 17835 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<int> count;
       count.resize(r.nDaysPerWeek, r.nHoursPerDay);
       for(int d=0; d<r.nDaysPerWeek; d++)
              for(int h=0; h<r.nHoursPerDay; h++)
                     count[d][h]=0;
       
       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);
                            count[d][h+dur]++;
                     }
              }
       }

       nbroken=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(count[d][h] > this->maxSimultaneous)
                     nbroken++;
       }

       if(nbroken>0){
              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 17763 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 max simultaneous in selected time slots, WP:%1, NA:%2, A: %3, STS: %4, MS:%5", "Constraint description. WP means weight percentage, "
        "NA means the number of activities, A means activities list, STS means selected time slots, MS means max simultaneous (number of activities in each selected time slot)")
        .arg(CustomFETString::number(this->weightPercentage))
        .arg(CustomFETString::number(this->activitiesIds.count()))
        .arg(actids)
        .arg(timeslots)
        .arg(CustomFETString::number(this->maxSimultaneous));
       
       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 17796 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 max simultaneous in selected time slots"); 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 simultaneous activities in each selected time slot=%1").arg(CustomFETString::number(this->maxSimultaneous)); 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 17736 of file timeconstraint.cpp.

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

       QString s="<ConstraintActivitiesMaxSimultaneousInSelectedTimeSlots>\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_Simultaneous_Activities>"+CustomFETString::number(this->maxSimultaneous)+"</Max_Number_of_Simultaneous_Activities>\n";
       
       s+="   <Active>"+trueFalse(active)+"</Active>\n";
       s+="   <Comments>"+protect(comments)+"</Comments>\n";
       s+="</ConstraintActivitiesMaxSimultaneousInSelectedTimeSlots>\n";
       return s;
}

Here is the call graph for this function:

Implements TimeConstraint.

Definition at line 17725 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 17951 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;

       //Do not care about maxSimultaneous, which can be as high as MAX_ACTIVITIES

       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 17915 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 17936 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 17943 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 17929 of file timeconstraint.cpp.

{
       Q_UNUSED(s);

       return false;
}

Returns true if this constraint is related to this teacher.

Implements TimeConstraint.

Definition at line 17922 of file timeconstraint.cpp.

{
       Q_UNUSED(t);

       return false;
}

Definition at line 17899 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 17972 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;

       //Do not modify maxSimultaneous, which can be as high as MAX_ACTIVITIES
       
       r.internalStructureComputed=false;
       setRulesModifiedAndOtherThings(&r);

       return true;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 3648 of file timeconstraint.h.

bool TimeConstraint::active [inherited]

Definition at line 146 of file timeconstraint.h.

Definition at line 3640 of file timeconstraint.h.

QString TimeConstraint::comments [inherited]

Definition at line 148 of file timeconstraint.h.

Definition at line 3645 of file timeconstraint.h.

Definition at line 3642 of file timeconstraint.h.

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