male_violet
جمعه 02 فروردین 1392, 11:23 صبح
با سلام از دوستان و تبریک سال نو اگه ممکنه می خواستم نظر دوستان راجع به تبدیل این کد به دلفی رو بدونم ممنونم از همه
void Schedule::Mutation()
{
if( rand() % 100 > _mutationProbability )
return;
int numberOfClasses = (int)_classes.size();
int size = (int)_slots.size();
for( int i = _mutationSize; i > 0; i-- )
{
int mpos = rand() % numberOfClasses;
int pos1 = 0;
hash_map<CourseClass*, int>::iterator it = _classes.begin();
for( ; mpos > 0; it++, mpos-- )
;
pos1 = ( *it ).second;
CourseClass* cc1 = ( *it ).first;
int nr = Configuration::GetInstance().GetNumberOfRooms();
int dur = cc1->GetDuration();
int day = rand() % DAYS_NUM;
int room = rand() % nr;
int time = rand() % ( DAY_HOURS + 1 - dur );
int pos2 = day * nr * DAY_HOURS + room * DAY_HOURS + time;
for( int i = dur - 1; i >= 0; i-- )
{
list<CourseClass*>& cl = _slots[ pos1 + i ];
for( list<CourseClass*>::iterator it = cl.begin(); it != cl.end(); it++ )
{
if( *it == cc1 )
{
cl.erase( it );
break;
}
}
_slots.at( pos2 + i ).push_back( cc1 );
}
_classes[ cc1 ] = pos2;
}
inline const vector<list<CourseClass*>>& GetSlots() const { return _slots; }
CalculateFitness();
}
void Schedule::Mutation()
{
if( rand() % 100 > _mutationProbability )
return;
int numberOfClasses = (int)_classes.size();
int size = (int)_slots.size();
for( int i = _mutationSize; i > 0; i-- )
{
int mpos = rand() % numberOfClasses;
int pos1 = 0;
hash_map<CourseClass*, int>::iterator it = _classes.begin();
for( ; mpos > 0; it++, mpos-- )
;
pos1 = ( *it ).second;
CourseClass* cc1 = ( *it ).first;
int nr = Configuration::GetInstance().GetNumberOfRooms();
int dur = cc1->GetDuration();
int day = rand() % DAYS_NUM;
int room = rand() % nr;
int time = rand() % ( DAY_HOURS + 1 - dur );
int pos2 = day * nr * DAY_HOURS + room * DAY_HOURS + time;
for( int i = dur - 1; i >= 0; i-- )
{
list<CourseClass*>& cl = _slots[ pos1 + i ];
for( list<CourseClass*>::iterator it = cl.begin(); it != cl.end(); it++ )
{
if( *it == cc1 )
{
cl.erase( it );
break;
}
}
_slots.at( pos2 + i ).push_back( cc1 );
}
_classes[ cc1 ] = pos2;
}
inline const vector<list<CourseClass*>>& GetSlots() const { return _slots; }
CalculateFitness();
}