emilibase.cpp
/**
 * Tie Braking First improvement local search
 */
Tie Braking First improvement local search
Tie Braking First improvement local search
emili::Solution* emili::TieBrakingFirstImprovementSearch::search(emili::Solution* initial)
{
        termcriterion->reset();
        neighbh->reset();
        emili::Solution* incumbent = initial->clone();
        emili::Solution* ithSolution;
        Neighborhood::NeighborhoodIterator end = neighbh->end();
        do{
            *bestSoFar = *incumbent;
            Neighborhood::NeighborhoodIterator iter = neighbh->begin(incumbent);
            ithSolution = *iter;
            for(;iter!=end;++iter)
            {
                if(incumbent->operator >(*ithSolution)){
                    *incumbent=*ithSolution;
                    printSolstats(incumbent);
                    break;
                }else if(incumbent->operator ==( *ithSolution))
                {
                   if(tiebraker.calcObjectiveFunctionValue(*incumbent) >
                           tiebraker.calcObjectiveFunctionValue((*ithSolution)))
                   {
                       *incumbent = *ithSolution;
                       printSolstats(incumbent);
                       break;
                   }
                }
            }
            delete ithSolution;
        }while(!termcriterion->terminate(bestSoFar,incumbent));
        if(*bestSoFar > *incumbent)
        {
            *bestSoFar = *incumbent;
        }
        delete incumbent;
        return bestSoFar->clone();
}
emili :: Solution * emili :: TieBrakingFirstImprovementSearch :: search ( emili :: Solution * initial ) { termcriterion -> reset ( ) ; neighbh -> reset ( ) ; emili :: Solution * incumbent = initial -> clone ( ) ; emili :: Solution * ithSolution ; Neighborhood :: NeighborhoodIterator end = neighbh -> end ( ) ; do { * bestSoFar = * incumbent ; Neighborhood :: NeighborhoodIterator iter = neighbh -> begin ( incumbent ) ; ithSolution = * iter ; for ( ; iter != end ; ++ iter ) { if ( incumbent -> operator > ( * ithSolution ) ) { * incumbent = * ithSolution ; printSolstats ( incumbent ) ; break ; } else if ( incumbent -> operator == ( * ithSolution ) ) { if ( tiebraker . calcObjectiveFunctionValue ( * incumbent ) > tiebraker . calcObjectiveFunctionValue ( ( * ithSolution ) ) ) { * incumbent = * ithSolution ; printSolstats ( incumbent ) ; break ; } } } delete ithSolution ; } while ( ! termcriterion -> terminate ( bestSoFar , incumbent ) ) ; if ( * bestSoFar > * incumbent ) { * bestSoFar = * incumbent ; } delete incumbent ; return bestSoFar -> clone ( ) ; }
Tie Braking First improvement local search
Tie Braking First improvement local search
//bestSoFar->setSolutionValue(bestSoFar->getSolutionValue()+1); // if the two solution have the same cost //Compare the two solution using the cost for another problem