Пример #1
0
int main(void)
{
	static uint8_t i = 20;
	initializeSystem();
	
	while(1)
	{
		//illuminate(true);
		if(i == 200)
		{
			getRGBIrradiance(&spectrum);
			printSpectrumIrradiance(spectrum);
			taos_irr = getTaosIrradiance();
			printTaosIrradiance(taos_irr);
			illuminateLEDIfThresholdMet(spectrum, taos_irr);
//			printTaosFrequency();
			i = 0;
		}
		else
		{
			i++;
		}
		checkPB();
		//illuminate(false);
		LoopTime();
	}

	return 0;
}
Пример #2
0
ReturnFlag ACS::run_()
{
	int i, j, dim;
	initializeSystem();
	dim = m_pop[0]->getNumDim();
	m_iter = 0;

	if (m_stopCriterion == MIN_COVER){
		dynamic_cast<TermMean*>(m_term.get())->initialize(DBL_MAX);
	}

	while (!ifTerminating())
	{
#ifdef OFEC_DEMON
		for (i = 0; i<this->getPopSize(); i++)
			updateBestArchive(this->m_pop[i]->self());
		vector<Algorithm*> vp;
		vp.push_back(this);
		msp_buffer->updateBuffer_(&vp);
#endif
		for (i = 0; i < m_popsize; i++)
		{
			for (j = 1; j < dim; j++)
			{
				double q = Global::msp_global->mp_uniformAlg->Next();
				if (q <= m_Q)
					m_pop[i]->selectNextCity_Greedy(mvv_phero, m_beta);
				else
					m_pop[i]->selectNextCity_Pro(mvv_phero, m_beta);
				local_updatePheromeno(i);
			}
			local_updatePheromeno(i, true);
		}
		global_updatePheromeno();
		resetAntsInfo();
		++m_iter;
		if (m_stopCriterion == MIN_COVER) {
			dynamic_cast<TermMean*>(m_term.get())->countSucIter(mean());
		}
		//cout<<" "<<Global::msp_global->mp_problem->getBestSolutionSoFar().getObjDistance(CAST_TSP->getGOpt()[0].data().m_obj)<<" "<<m_stopCount<<endl;
#ifdef OFEC_CONSOLE
		double tempdif = 0;
		for (int i = 0; i < m_popsize; i++)
			tempdif += m_pop[i]->self().getDistance(Solution<CodeVInt>::getBestSolutionSoFar());
		tempdif /= m_popsize;
		double impr = static_cast<double>(m_impRadio) / m_popsize;
		OptimalEdgeInfo::getOptimalEdgeInfo()->recordiffAndImp(Global::msp_global->m_runId, Global::msp_global->mp_problem->getEvaluations(), fabs(tempdif), impr);
#endif
	}
#ifdef OFEC_CONSOLE
	vector<int> bestIdx = findBest();
	OptimalEdgeInfo::getOptimalEdgeInfo()->recordEdgeInfo<Ant>(Global::msp_global.get(), Solution<CodeVInt>::getBestSolutionSoFar(), m_pop, m_num, m_popsize, m_saveFre, false);

	OptimalEdgeInfo::getOptimalEdgeInfo()->recordLastInfo(Global::msp_global->m_runId, Global::msp_global->mp_problem->getEvaluations());
#endif
	return Return_Terminate;
}
Пример #3
0
NBodySystem generateSystem(sf::Vector2u size)
{
	for(int i = 0; ; i++)
	{
		NBodySystem system = initializeSystem(size);
		if(test(system, size) || i > MAX_TESTS)
			return system;
	}
}
Пример #4
0
int main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    //printf("Restarted\n");
    float resistor_divider_multiplier;
    float adc_multiplier;
    float fudge_multiplier;
    uint16 offset;
    
    uint32 value;
    int i;
    
    offset = 402;
    resistor_divider_multiplier = ((220000 + 18000) / 18000);
    adc_multiplier = 2.048 / 65536;
    fudge_multiplier = 1.02534275031159;
    
    initializeSystem();
    
    for(;;) {
        elapsed = elapsed + 1;
        UART_UartPutChar(72u);//H
        UART_UartPutChar(101u);//e
        UART_UartPutChar(108u);//l
        UART_UartPutChar(108u);//l
        UART_UartPutChar(111u);//o
        iprintf(", World! %d", elapsed);
        UART_UartPutChar(13u);//CR
        UART_UartPutChar(10u);//LF
        
        
        TP1_Write(1u);
        /* Place your application code here. */
        CyBle_ProcessEvents();
        TP1_Write(0u);
        
        if (elapsed == 0) {
            //voltageReading = 29.6907207207207 * ((float)rawADCValue/0x7FFF);
            //voltageReading = 0.0009 * (float)rawADCValue + 0.4238;
            //voltageReading = 0.0005892 * (float)rawADCValue + 0.28026;
            
            value = 0;
            for (i = 0; i < 16; i++) {
                value += rawADCValues[i];
            }
            value = value / 16;
            voltageReading = fudge_multiplier * resistor_divider_multiplier * adc_multiplier * (float)(value - offset);
            SendVoltageMeasurementNotification(voltageReading);
            SendRawADCNotification(rawADCValue);
            //printf("Voltage: %f\n", voltageReading);
        }
    }
}
Пример #5
0
void setPosition(char * town,char* street)
{
	printf("Looking Up Address...%s,%s\n",town,street);
	struct coord result;
	struct navit * this_ = getNavit();
	search(town,street,&result);
	struct pcoord dest;
	dest.pro = projection_mg;
	dest.x = result.x;
	dest.y = result.y;
	if(&result != NULL)
	{
		initializeSystem(1600, 900, "red");
		navit_set_destination(this_,&dest,street,1);
	}
}
Пример #6
0
/*
 * transposeSystem() fills transpose with the transpose of original. Does not copy Vertex data members.
 *
 * original - pointer to the System struct containing the original graph representation
 * transpose - pointer to a declared but uninitialized System struct, to be filled with the transpose of original
 */
static void transposeSystem(System * original, System * transpose){
  initializeSystem( transpose, original->n, NULL );
  setSystemForSCC( transpose );
  for(VertexSign i = POSITIVE; i <= NEGATIVE; i++){
    for(int j = 0; j < original->n; j++){
      Edge * originalEdge = original->graph[i][j].first;
      while( originalEdge != NULL ){
        Edge * transposeEdge = (Edge *) malloc( sizeof(Edge) );
        transposeEdge->weight = originalEdge->weight;
        transposeEdge->head = &transpose->graph[ originalEdge->tail->sign ][ originalEdge->tail->index - 1 ];
        transposeEdge->tail = &transpose->graph[ originalEdge->head->sign ][ originalEdge->head->index - 1 ];
        transposeEdge->next = transposeEdge->tail->first;
        transposeEdge->tail->first = transposeEdge;
        transposeEdge->backtrackSeen = false;

        originalEdge = originalEdge->next;
      }
    }
  }
}
Пример #7
0
/*
 * onlySlacklessEdges() copies the subgraph of original consisting only of edges (u,v) where D(v) - D(u) = w(u,v) into subgraph.
 * Does not copy Vertex data members.
 *
 * original - pointer to the System struct containing the original graph representation
 * subgraph - pointer to a declared yet uninitialized System struct, to be filled with the subgraph of original consisting only of
 *   slackless edges
 */
static void onlySlacklessEdges(System * original, System * subgraph){
  initializeSystem( subgraph, original->n, NULL );
  setSystemForSCC( subgraph );
  for(VertexSign i = POSITIVE; i <= NEGATIVE; i++){
    for(int j = 0; j < original->n; j++){
      Edge * originalEdge = original->graph[i][j].first;
      while( originalEdge != NULL ){
        if( originalEdge->head->D - originalEdge->tail->D == originalEdge->weight ){
          Edge * subgraphEdge = (Edge *) malloc( sizeof(Edge) );
          subgraphEdge->weight = originalEdge->weight;
          subgraphEdge->head = &subgraph->graph[ originalEdge->head->sign ][ originalEdge->head->index - 1 ];
          subgraphEdge->tail = &subgraph->graph[ originalEdge->tail->sign ][ originalEdge->tail->index - 1 ];
          subgraphEdge->next = subgraphEdge->tail->first;
          subgraphEdge->tail->first = subgraphEdge;
          subgraphEdge->backtrackSeen = false;
        }
        originalEdge = originalEdge->next;
      }
    }
  }
}
Пример #8
0
int main(int argc, char **argv)
{
    //parse command line
    strcpy(autoip,"");
    for(int j=0; j<argc; j++)
    {
        if(strcmp(argv[j],"-full")==0)
            fullscreen=1;
        else if(strstr(argv[j],"-join")!=0)
            sscanf(argv[j],"-join:%s", autoip);
        else if(strstr(argv[j],"-port")!=0)
            sscanf(argv[j],"-port:%ld", &SERVER_PORT);
    }
    //strcpy(autoip,"127.0.0.1");//testing

    //init graphics
    initializeSystem();

    //setup
    setupClient();

    //startup
    term.newLine("^cMystera Legends Beta %.3f ^b- ^OZircon Release",client_version);
    //only for testing
    //initTestingMode();

    //checking for newer version or showing servers
    //if(!checkVer())showServers();
    //get available servers
    //initialize socket library
    if(!debug)
    {
        if(strlen(autoip)>2)
        {
            /*dialog=-1;
            //char show[128];
            cstate=1;
             //sprintf(show,"--- Attempting to connect to %s",autoip);
             //term.newLine(show);
             //term.render(0,480,246);
             //Renderer::Swap();
            if(!nc.connect(autoip,SERVER_PORT))
            	term.newLine("--- Error connecting. CTRL-Q to quit.");
            else
            {
            	term.newLine("--- Connected to %s.",autoip);
            	connected=1;
            }*/
            sips.size(1);
            strcpy(sips[0].ip,autoip);
            sprintf(sips[0].name,"^W%s",autoip);
            strcpy(sips[0].players," ");
            vDialog[0].w[2].addList(sips[0].name);
            dialog=0;
        }
        else
            showServers();
    }

    unsigned long loopnum   = 0;
    unsigned long lastsec   = 0;
    unsigned long loopdif   = 0;
    long second    = time(0);
    unsigned long sleeptime = 0;
    const long FPS = 50;

    //buildMapLayers();
    //application loop
    while(!done)
    {

        Input::Update();
        doFrame();

        if(time(0) == second + 1)
        {
            loopdif = loopnum - lastsec;
            lastsec = loopnum;
            sleeptime = float(1000/FPS);
            sleeptime -= loopdif/1000;
            second++;
        }

        loopnum++;
        Sleep(sleeptime);

        if(connected)
        {
            //term.newLine("I really am connected you know.");
            if(udpTimer.tick(1500))
            {
                //send udp packet
                char u=NULL_MSG;
                nc.send((unsigned char *)&u,1,SEND_NON_GUARANTEED);
            }

            int res = nc.update();
            if(res==-1 || servTimer.tick(1000000))
            {
                me=-1;
                player.size(0);
                player.size(10);
                world.size(0);
                world.size(10);
                item.size(0);
                term.newLine("--- Connection closed.");
                connected=0;
                servTimer.reset();
                dialog=0;

                Renderer::SetTitle("Mystera Legends Beta");
                nc.shutdown();
            }
        }
    }
    //shutdown
    fclose(chatLog);

    nc.shutdown();
    Mix_CloseAudio();

    Renderer::Shutdown();
    //if(restart)
    //	doRestart();

    return 0;
}
Пример #9
0
AppInitializer::AppInitializer(std::initializer_list<int> subsystem_flags) {
	for (auto it = subsystem_flags.begin(); it != subsystem_flags.end(); it++) {
		initializeSystem(*it);
	}
}
// public method responsible for controlling the RouteInputAnalyzer, ChoicePath, and ImageCreation
void processImageData(int valid)
{
	if(valid == 1)
	{
		// initialize program if it has not been done yet
		if(initialized == 0)
		{
			char projection_color[] = "red";
			initializeSystem(800, 600,projection_color, 400, 300);
		}

		// TODO: Need to figure out how to create a thread here that will constantly run until the program exits
		while(controller.map_data_up_to_date || controller.road_data_up_to_date)
		{
			// If new map and road data received process it
			if(controller.map_data_up_to_date && controller.road_data_up_to_date)
			{
				// calculate pixel box for arrow placement using GPS data
				//processGenericNavData(&controller);
				processNavData(&controller);

				// increase precision of pixel box for arrow placement using RoadTracking data
				processTrackingData(&controller);

				// create arrow and draw it to a file
				drawImage(&controller);

				// reset control so new data can be written to mapping and road tracking
				controller.road_data_up_to_date = 0;
				controller.map_data_up_to_date = 0;

				// Draw the image to the projector
				drawToProjector();
			}

			// If only new map data has been received then process it
			else if(controller.map_data_up_to_date)
			{
				// calculate pixel box for arrow placement using GPS data
				//processGenericNavData(&controller); // TOGGLE ON TO CREATE A GENERIC ARROW
				processNavData(&controller); // TOGGLE ON TO CREATE A DYNAMIC ARROW

				// create arrow and draw it to a file
				drawImage(&controller);

				// reset control so new data can be written to mapping
				controller.map_data_up_to_date = 0;

				// Draw the image to the projector
				drawToProjector();
			}

			// If only new road data has been received then process it
			else if(controller.road_data_up_to_date)
			{
				// increase precision of pixel box for arrow placement using RoadTracking data
				//processTrackingData(&controller);

				// create arrow and draw it to a file
				drawRoadTrackingImage(&controller);

				// reset control so new data can be written to road tracking
				controller.road_data_up_to_date = 0;

				// Draw the image to the projector
				drawToProjector();
			}
		}

	}
	else
	{
		drawBlankToProjector();
	}
}