Back to index

fet  5.18.0
studentsset.cpp
Go to the documentation of this file.
00001 //
00002 //
00003 // Description: This file is part of FET
00004 //
00005 //
00006 // Author: Liviu Lalescu <Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)>
00007 // Copyright (C) 2003 Liviu Lalescu <http://lalescu.ro/liviu/>
00008 //
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "studentsset.h"
00019 #include "rules.h"
00020 #include "timetable.h"
00021 
00022 extern Timetable gt;
00023 
00024 #include <iostream>
00025 using namespace std;
00026 
00027 StudentsSet::StudentsSet()
00028 {
00029        this->type=STUDENTS_SET;
00030        this->numberOfStudents=0;
00031 }
00032 
00033 StudentsSet::~StudentsSet()
00034 {
00035 }
00036 
00037 StudentsYear::StudentsYear()
00038        : StudentsSet()
00039 {
00040        this->type=STUDENTS_YEAR;
00041 
00042        indexInAugmentedYearsList=-1;
00043 }
00044 
00045 StudentsYear::~StudentsYear()
00046 {
00047        //it is possible that the removed group to be in another year
00048 
00049        /*while(!groupsList.isEmpty()){
00050               StudentsGroup* g=groupsList[0];
00051               
00052               foreach(StudentsYear* year, gt.rules.yearsList)
00053                      if(year!=this)
00054                             for(int i=0; i<year->groupsList.size(); i++)
00055                                    if(year->groupsList[i]==g)
00056                                           year->groupsList[i]=NULL;
00057        
00058               if(g!=NULL){
00059                      delete groupsList.takeFirst();
00060               }
00061               else
00062                      groupsList.removeFirst();
00063        }*/
00064 }
00065 
00066 QString StudentsYear::getXmlDescription()
00067 {
00068        QString s="";
00069        s+="<Year>\n";
00070        s+="<Name>"+protect(this->name)+"</Name>\n";
00071        s+="<Number_of_Students>"+CustomFETString::number(this->numberOfStudents)+"</Number_of_Students>\n";
00072        for(int i=0; i<this->groupsList.size(); i++){
00073               StudentsGroup* stg=this->groupsList[i];
00074               s+=stg->getXmlDescription();
00075        }
00076        s+="</Year>\n";
00077 
00078        return s;
00079 }
00080 
00081 QString StudentsYear::getDescription()
00082 {
00083        QString s;
00084        s+=tr("YN:%1", "Year name").arg(this->name);
00085        s+=", ";
00086        s+=tr("NoS:%1", "Number of students").arg(this->numberOfStudents);
00087 
00088        return s;
00089 }
00090 
00091 QString StudentsYear::getDetailedDescription()
00092 {
00093        QString s="";
00094        s+=tr("Students set - year");
00095        s+="\n";
00096        s+=tr("Year name=%1").arg(this->name);
00097        s+="\n";
00098        s+=tr("Number of students=%1").arg(this->numberOfStudents);
00099        s+="\n";
00100 
00101        return s;
00102 }
00103 
00104 QString StudentsYear::getDetailedDescriptionWithConstraints(Rules& r)
00105 {
00106        QString s=this->getDetailedDescription();
00107 
00108        s+="--------------------------------------------------\n";
00109        s+=tr("Time constraints directly related to this students year:");
00110        s+="\n";
00111        for(int i=0; i<r.timeConstraintsList.size(); i++){
00112               TimeConstraint* c=r.timeConstraintsList[i];
00113               if(c->isRelatedToStudentsSet(r, this)){
00114                      s+="\n";
00115                      s+=c->getDetailedDescription(r);
00116               }
00117        }
00118 
00119        s+="--------------------------------------------------\n";
00120        s+=tr("Space constraints directly related to this students year:");
00121        s+="\n";
00122        for(int i=0; i<r.spaceConstraintsList.size(); i++){
00123               SpaceConstraint* c=r.spaceConstraintsList[i];
00124               if(c->isRelatedToStudentsSet(r, this)){
00125                      s+="\n";
00126                      s+=c->getDetailedDescription(r);
00127               }
00128        }
00129        s+="--------------------------------------------------\n";
00130 
00131        return s;
00132 }
00133 
00134 
00135 StudentsGroup::StudentsGroup()
00136        : StudentsSet()
00137 {
00138        this->type=STUDENTS_GROUP;
00139 
00140        indexInInternalGroupsList=-1;
00141 }
00142 
00143 StudentsGroup::~StudentsGroup()
00144 {
00145        /*while(!subgroupsList.isEmpty()){
00146               StudentsSubgroup* s=subgroupsList[0];
00147               
00148               foreach(StudentsYear* year, gt.rules.yearsList)
00149                      foreach(StudentsGroup* group, year->groupsList)
00150                             if(group!=this)
00151                                    for(int i=0; i<group->subgroupsList.size(); i++)
00152                                           if(group->subgroupsList[i]==s){
00153                                                  cout<<"making NULL group->subgroupsList[i]->name=="<<qPrintable(group->subgroupsList[i]->name)<<endl;
00154                                                  group->subgroupsList[i]=NULL;
00155                                           }
00156                                           else
00157                                                  cout<<"ignoring group->subgroupsList[i]->name=="<<qPrintable(group->subgroupsList[i]->name)<<endl;
00158        
00159               if(s!=NULL){
00160                      assert(subgroupsList[0]!=NULL);
00161                      delete subgroupsList.takeFirst();
00162               }
00163               else
00164                      subgroupsList.removeFirst();
00165        }*/
00166 }
00167 
00168 QString StudentsGroup::getXmlDescription()
00169 {
00170        QString s="";
00171        s+="   <Group>\n";
00172        s+="   <Name>"+protect(this->name)+"</Name>\n";
00173        s+="   <Number_of_Students>"+CustomFETString::number(this->numberOfStudents)+"</Number_of_Students>\n";
00174        for(int i=0; i<this->subgroupsList.size(); i++){
00175               StudentsSubgroup* sts=this->subgroupsList[i];
00176               s+=sts->getXmlDescription();
00177        }
00178        s+="   </Group>\n";
00179 
00180        return s;
00181 }
00182 
00183 QString StudentsGroup::getDescription()
00184 {
00185        QString s="";
00186        s+=tr("GN:%1", "Group name").arg(this->name);
00187        s+=", ";
00188        s+=tr("NoS:%1", "Number of students").arg(this->numberOfStudents);
00189 
00190        return s;
00191 }
00192 
00193 QString StudentsGroup::getDetailedDescription()
00194 {
00195        QString s="";
00196        s+=tr("Students set - group");
00197        s+="\n";
00198        s+=tr("Group name=%1").arg(this->name);
00199        s+="\n";
00200        s+=tr("Number of students=%1").arg(this->numberOfStudents);
00201        s+="\n";
00202 
00203        return s;
00204 }
00205 
00206 QString StudentsGroup::getDetailedDescriptionWithConstraints(Rules& r)
00207 {
00208        QString s=this->getDetailedDescription();
00209 
00210        s+="--------------------------------------------------\n";
00211        s+=tr("Time constraints directly related to this students group:");
00212        s+="\n";
00213        for(int i=0; i<r.timeConstraintsList.size(); i++){
00214               TimeConstraint* c=r.timeConstraintsList[i];
00215               if(c->isRelatedToStudentsSet(r, this)){
00216                      s+="\n";
00217                      s+=c->getDetailedDescription(r);
00218               }
00219        }
00220 
00221        s+="--------------------------------------------------\n";
00222        s+=tr("Space constraints directly related to this students group:");
00223        s+="\n";
00224        for(int i=0; i<r.spaceConstraintsList.size(); i++){
00225               SpaceConstraint* c=r.spaceConstraintsList[i];
00226               if(c->isRelatedToStudentsSet(r, this)){
00227                      s+="\n";
00228                      s+=c->getDetailedDescription(r);
00229               }
00230        }
00231        s+="--------------------------------------------------\n";
00232 
00233        return s;
00234 }
00235 
00236 
00237 StudentsSubgroup::StudentsSubgroup()
00238        : StudentsSet()
00239 {
00240        this->type=STUDENTS_SUBGROUP;
00241        
00242        indexInInternalSubgroupsList=-1;
00243 }
00244 
00245 StudentsSubgroup::~StudentsSubgroup()
00246 {
00247 }
00248 
00249 QString StudentsSubgroup::getXmlDescription()
00250 {
00251        QString s="";
00252        s+="          <Subgroup>\n";
00253        s+="          <Name>"+protect(this->name)+"</Name>\n";
00254        s+="          <Number_of_Students>"+CustomFETString::number(this->numberOfStudents)+"</Number_of_Students>\n";
00255        s+="          </Subgroup>\n";
00256 
00257        return s;
00258 }
00259 
00260 QString StudentsSubgroup::getDescription()
00261 {
00262        QString s="";
00263        s+=tr("SgN:%1", "Subgroup name").arg(this->name);
00264        s+=", ";
00265        s+=tr("NoS:%1", "Number of students").arg(this->numberOfStudents);
00266 
00267        return s;
00268 }
00269 
00270 QString StudentsSubgroup::getDetailedDescription()
00271 {
00272        QString s="";
00273        s+=tr("Students set - subgroup");
00274        s+="\n";
00275        s+=tr("Subgroup name=%1").arg(this->name);
00276        s+="\n";
00277        s+=tr("Number of students=%1").arg(this->numberOfStudents);
00278        s+="\n";
00279 
00280        return s;
00281 }
00282 
00283 QString StudentsSubgroup::getDetailedDescriptionWithConstraints(Rules& r)
00284 {
00285        QString s=this->getDetailedDescription();
00286 
00287        s+="--------------------------------------------------\n";
00288        s+=tr("Time constraints directly related to this students subgroup:");
00289        s+="\n";
00290        for(int i=0; i<r.timeConstraintsList.size(); i++){
00291               TimeConstraint* c=r.timeConstraintsList[i];
00292               if(c->isRelatedToStudentsSet(r, this)){
00293                      s+="\n";
00294                      s+=c->getDetailedDescription(r);
00295               }
00296        }
00297 
00298        s+="--------------------------------------------------\n";
00299        s+=tr("Space constraints directly related to this students subgroup:");
00300        s+="\n";
00301        for(int i=0; i<r.spaceConstraintsList.size(); i++){
00302               SpaceConstraint* c=r.spaceConstraintsList[i];
00303               if(c->isRelatedToStudentsSet(r, this)){
00304                      s+="\n";
00305                      s+=c->getDetailedDescription(r);
00306               }
00307        }
00308        s+="--------------------------------------------------\n";
00309 
00310        return s;
00311 }
00312 
00313 int yearsAscending(const StudentsYear* y1, const StudentsYear* y2)
00314 {
00315        return y1->name < y2->name;
00316 }
00317 
00318 int groupsAscending(const StudentsGroup* g1, const StudentsGroup* g2)
00319 {
00320        return g1->name < g2->name;
00321 }
00322 
00323 int subgroupsAscending(const StudentsSubgroup* s1, const StudentsSubgroup* s2)
00324 {
00325        return s1->name < s2->name;
00326 }