Beispiel #1
0
KMfilterCenters KMlocal::execute()            // execute the algorithm
{
  reset();                              // resets everything
  while(!isDone()) {                         // while not done
    beginRun();                        // start a new run
    do {                              // do while run is not done
      beginStage();                  // start of stage processing
      KMalg method = selectMethod();      // select a method
      switch(method) {                  // apply one stage
      case LLOYD:                        // Lloyd's algorithm
        curr.lloyd1Stage();
        break;
      case SWAP:                        // swap heuristic
        curr.swap1Stage();
        break;
      case RANDOM:                  // get random centers
        curr.genRandom();
        break;
      default:                        // shouldn't come here
        assert(false);
        break;
      }
      endStage();                        // end of stage processing
    } while(!isRunDone());                   // while run is not done
    endRun();                        // end of run processing
    tryAcceptance();                  // accept if appropriate
  }
  return best;                        // return best solution
}
void Tresenv::sim_stop()
{
    disable_tracing = false;
    
    ::fflush(fout);
    simulation.callFinish();
    flushLastLine();
    
    checkFingerprint();
    
    // call endRun()
    if (startrun_done)
    {
        try
        {
            endRun();
        }
        catch (std::exception& e)
        {
            displayException(e);
        }
    }
    
    // delete network
    if (setupnetwork_done)
    {
        try
        {
            simulation.deleteNetwork();
        }
        catch (std::exception& e)
        {
            displayException(e);
        }
    }
    shutdown();
}
Beispiel #3
0
// Spike logic is driven by TrgSpikeParams:
// {periEvtSecs, refractSecs, inarow, nS, T}.
// Corresponding states defined above.
//
void TrigSpike::run()
{
    Debug() << "Trigger thread started.";

    setYieldPeriod_ms( 100 );

    initState();

    while( !isStopped() ) {

        double  loopT = getTime();
        bool    inactive;

        // -------
        // Active?
        // -------

        inactive = ISSTATE_Done || !isGateHi();

        if( inactive )
            goto next_loop;

        // -------------
        // If gate start
        // -------------

        // Set gateHiT as place from which to start
        // searching for edge in getEdge().

        if( !imCnt.edgeCt || !niCnt.edgeCt ) {

            usrFlt->reset();

            double  gateT = getGateHiT();

            if( imQ && !imQ->mapTime2Ct( imCnt.edgeCt, gateT ) )
                goto next_loop;

            if( niQ && !niQ->mapTime2Ct( niCnt.edgeCt, gateT ) )
                goto next_loop;
        }

        // --------------
        // Seek next edge
        // --------------

        if( ISSTATE_GetEdge ) {

            if( p.trgSpike.stream == "imec" ) {

                if( !getEdge( imCnt, imQ, niCnt, niQ ) )
                    goto next_loop;
            }
            else {

                if( !getEdge( niCnt, niQ, imCnt, imQ ) )
                    goto next_loop;
            }

            QMetaObject::invokeMethod(
                gw, "blinkTrigger",
                Qt::QueuedConnection );

            // ---------------
            // Start new files
            // ---------------

            imCnt.remCt = -1;
            niCnt.remCt = -1;

            {
                int ig, it;

                if( !newTrig( ig, it, false ) )
                    break;

                setSyncWriteMode();
            }

            SETSTATE_Write();
        }

        // ----------------
        // Handle this edge
        // ----------------

        if( ISSTATE_Write ) {

            if( !writeSome( DstImec, imQ, imCnt )
                || !writeSome( DstNidq, niQ, niCnt ) ) {

                break;
            }

            // -----
            // Done?
            // -----

            if( imCnt.remCt <= 0 && niCnt.remCt <= 0 ) {

                endTrig();

                usrFlt->reset();
                imCnt.edgeCt += imCnt.refracCt;
                niCnt.edgeCt += niCnt.refracCt;

                if( ++nS >= nCycMax )
                    SETSTATE_Done;
                else
                    SETSTATE_GetEdge;
            }
        }

        // ------
        // Status
        // ------

next_loop:
       if( loopT - statusT > 0.25 ) {

            QString sOn, sWr;
            int     ig, it;

            getGT( ig, it );
            statusOnSince( sOn, loopT, ig, it );
            statusWrPerf( sWr );

            Status() << sOn << sWr;

            statusT = loopT;
        }

        // -------------------
        // Moderate fetch rate
        // -------------------

        yield( loopT );
    }

    endRun();

    Debug() << "Trigger thread stopped.";

    emit finished();
}