Exemple #1
0
static void ProcessCtrlC(void)                                  // print system state to the console
{
  PrintParameters();

  size_t FreeHeap = xPortGetFreeHeapSize();

  xSemaphoreTake(UART1_Mutex, portMAX_DELAY);                   // ask exclusivity on UART1

  Format_String(UART1_Write, "Task  Pr. Stack, ");
  Format_UnsDec(UART1_Write, (uint32_t)FreeHeap, 4, 3);
  Format_String(UART1_Write, "kB free\n");
  // xSemaphoreGive(UART1_Mutex);                                  // give back UART1 to other tasks

  UBaseType_t uxArraySize = uxTaskGetNumberOfTasks();
  TaskStatus_t *pxTaskStatusArray = (TaskStatus_t *)pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
  if(pxTaskStatusArray==0) goto Exit;
  uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );
  for(UBaseType_t T=0; T<uxArraySize; T++)
  { TaskStatus_t *Task = pxTaskStatusArray+T;
    // uint8_t Len=strlen(Task->pcTaskName);
    // memcpy(Line, Task->pcTaskName, Len);
    uint8_t Len=Format_String(Line, Task->pcTaskName);
    for( ; Len<=configMAX_TASK_NAME_LEN; )
      Line[Len++]=' ';
    Line[Len++]='0'+Task->uxCurrentPriority; Line[Len++]=' ';
    Len+=Format_UnsDec(Line+Len, Task->usStackHighWaterMark, 3);
    Line[Len++]='\n'; Line[Len++]=0;
    // xSemaphoreTake(UART1_Mutex, portMAX_DELAY);                   // ask exclusivity on UART1
    Format_String(UART1_Write, Line);
    // xSemaphoreGive(UART1_Mutex);                                  // give back UART1 to other tasks
  }
  vPortFree( pxTaskStatusArray );
Exit:
  xSemaphoreGive(UART1_Mutex);                                       // give back UART1 to other tasks
}
int MEPdfPartialB::TryParameters(RooDataSet *ds){
  FixAll();
  pdf_part->fitTo(*ds,Verbose(),Timer(true));
  Draw(ds);
  PrintParameters();
  return 0;
}
Exemple #3
0
void TNote::Slide(TNote aNote)
{
	int i, n = 0;
	int FromFrequency, ToFrequency;
	if (GetFrequency() < aNote.GetFrequency())
	{
		FromFrequency = GetFrequency();
		ToFrequency = aNote.GetFrequency();
	}
	else
	{
		FromFrequency = aNote.GetFrequency();
		ToFrequency = GetFrequency();
	}
	Duration = Duration / 5;
	for (i = FromFrequency; i <= ToFrequency; i = i + (ToFrequency - FromFrequency) / 5)
	{
		SetFrequency(i);
		PrintParameters(0, 0, 0);
		std::cout << n << ' ';
		n++;
		Play();
	}
	Duration = Duration * 5;
}
int MEPdfPartialB::FitParameters(RooDataSet *ds,const bool etaggflag){
  FreeAll();
  if(etaggflag) k_s_mbc_part->setConstant(kTRUE);
  pdf_part->fitTo(*ds,Verbose(),Timer(true));
  Draw(ds);
  PrintParameters();
  return 0;
}
Exemple #5
0
void PrettyPrinter::PrintFunctionLiteral(FunctionLiteral* function) {
  Print("function ");
  PrintLiteral(function->name(), false);
  PrintParameters(function->scope());
  Print(" { ");
  PrintDeclarations(function->scope()->declarations());
  PrintStatements(function->body());
  Print(" }");
}
Exemple #6
0
/*-------------------------------------------------*/
void ParameterInit()
{
  printf("\n ParameterInit\n");
  masses = new double[4];
  ReadConfiguration();
  PulseLimitsInit();
  ADCInit();
  QDCInit();
  PrintParameters();
  printf("Finished initialising parameters - to the sorting!\n");
}
int main(int argc, const char * argv[])
{
    int errno = 0,i=0;
    //sigset(SIGINT, handler);
    
    
    if(argc<1 && argc>15){
        fprintf(stderr, "Error in argumentss/n");
        exit(1);
    }
    
    
    ReadCommandArguments(argc,argv);
    
    PrintParameters();
    SaveCurTimeOfDay();
    
    fprintf(stdout, "00000000.000ms: emulation begins\n");
    
    
    if((errno = pthread_create(&thrd[0], 0,Arrival, (void*)0 ))){
        fprintf(stderr, "pthread_create[0] %s\n",strerror(errno));
        pthread_exit(0);
    }
    if((errno = pthread_create(&thrd[1], 0,Token, (void*)1 ))){
        fprintf(stderr, "pthread_create[1] %s\n",strerror(errno));
        pthread_exit(0);
    }
    if((errno = pthread_create(&thrd[2], 0,Service, (void*)2 ))){
        fprintf(stderr, "pthread_create[2] %s\n",strerror(errno));
        pthread_exit(0);
    }
    
    for (i=0; i<N; i++) {
        if((errno = pthread_join(thrd[i], 0))){
            fprintf(stderr, "pthread_join[i] %s\n",strerror(errno));
            pthread_exit(0);
            
        }
        
    }
    
    emulation_ends = GetMTimeOfDay();
    fprintf(stdout, "%012.3lfms: emulation ends\n ",emulation_ends);
    
    //PrintStatistics();
    return 0;
}
void SGBM_cpu::SetParamaters()
{
	PrintParameters(parameters);

	int cn = imgL.channels();
	sgbm.numberOfDisparities = parameters->P0*16;
	sgbm.minDisparity = parameters->P1;
	sgbm.SADWindowSize = parameters->P2*2+1;
    sgbm.preFilterCap = parameters->P3;
    sgbm.uniquenessRatio = parameters->P4;
    sgbm.speckleWindowSize =  parameters->P5;
    sgbm.speckleRange = parameters->P6;
    sgbm.disp12MaxDiff = parameters->P7;
    sgbm.fullDP = parameters->P8;

	sgbm.P1 = 8*cn*sgbm.SADWindowSize*sgbm.SADWindowSize;
    sgbm.P2 = 32*cn*sgbm.SADWindowSize*sgbm.SADWindowSize;

}
Exemple #9
0
int App::Run() {
    Load();
    if (ParamsInputPath_.size()) {
        Params_.Load(ParamsInputPath_.c_str());
    }

    Builder_.SetParams(Params_);
    Builder_.SetInputCloud(Input_);
    PrintParameters();

    Builder_.GenerateTrainingSet();
    ExportForLibSVM();

    if (AlphaInputPath_.size()) {
        std::ifstream alphaInput(AlphaInputPath_.c_str());
        std::vector<SVMFloat> alphas;
        std::copy(std::istream_iterator<SVMFloat>(alphaInput), std::istream_iterator<SVMFloat>(),
                std::back_inserter(alphas));

        Builder_.InitSVM(alphas);
    } else {
        Builder_.Learn();
        TrainedModel_ = true;
    }
    if (AlphaOutputPath_.size()) {
        std::ofstream alphaOutput(AlphaOutputPath_.c_str());
        std::copy(Builder_.SVM().Alphas(), Builder_.SVM().Alphas() + Builder_.Objects->size(),
                std::ostream_iterator<SVMFloat>(alphaOutput, "\n"));
    }
    if (ParamsOutputPath_.size()) {
        Params_.Save(ParamsOutputPath_.c_str());
    }
    ExportAlphaMap();

    Builder_.CalcGradients();

    PrintStatistics();
    Visualize();
    return 0;
}
Exemple #10
0
static void ReadParameters(void)  // read parameters requested by the user in the NMEA sent.
{ if((!NMEA.hasCheck()) || NMEA.isChecked() )
  { const char *Parm; int8_t Val;
    Parm = (const char *)NMEA.ParmPtr(0);                                  // [0..15] aircraft-type: 1=glider, 2=towa plane, 3=helicopter, ...
    if(Parm)
    { Val=Read_Hex1(Parm[0]);
      if( (Val>=0) && (Val<16) ) Parameters.setAcftType(Val); }
    Parm = (const char *)NMEA.ParmPtr(1);                                  // [0..3] addr-type: 1=ICAO, 2=FLARM, 3=OGN
    if(Parm)
    { Val=Read_Hex1(Parm[0]);
      if( (Val>=0) && (Val<4) ) Parameters.setAddrType(Val); }
    Parm = (const char *)NMEA.ParmPtr(2);                                  // [HHHHHH] Address (ID): 6 hex digits, 24-bit
    uint32_t Addr;
    int8_t Len=Read_Hex(Addr, Parm);
    if( (Len==6) && (Addr<0x01000000) ) Parameters.setAddress(Addr);
    Parm = (const char *)NMEA.ParmPtr(3);                                  // [0..1] RFM69HW (up to +20dBm) or W (up to +13dBm)
    if(Parm)
    { Val=Read_Dec1(Parm[0]);
           if(Val==0) Parameters.clrTxTypeHW();
      else if(Val==1) Parameters.setTxTypeHW(); }
    Parm = (const char *)NMEA.ParmPtr(4);                                  // [dBm] Tx power
    int32_t TxPower;
    Len=Read_SignDec(TxPower, Parm);
    if( (Len>0) && (TxPower>=(-10)) && (TxPower<=20) ) Parameters.setTxPower(TxPower);
    Parm = (const char *)NMEA.ParmPtr(5);                                  // [Hz] Tx/Rx frequency correction
    int32_t FreqCorr;
    Len=Read_SignDec(FreqCorr, Parm);
    if( (Len>0) && (FreqCorr>=(-100000)) && (FreqCorr<=100000) ) Parameters.RFchipFreqCorr = (FreqCorr<<8)/15625;

    taskDISABLE_INTERRUPTS();                                              // disable all interrupts: Flash can not be read while being erased
    IWDG_ReloadCounter();                                                  // kick the watch-dog
    Parameters.WriteToFlash();                                             // erase and write the parameters into the last page of Flash
    if(Parameters.ReadFromFlash()<0) Parameters.setDefault();              // read the parameters back: if invalid, set defaults
    taskENABLE_INTERRUPTS();                                               // bring back interrupts and the system
  }
  PrintParameters();
}
Exemple #11
0
int main(void)
{

	printf("A sample on how to use RakVoice together with DirectSound.\n");
	printf("You need a microphone for this sample.\n");
	printf("RakVoice relies on Speex for voice encoding and decoding.\n");
	printf("See DependentExtensions/RakVoice/speex-1.2beta3 for speex projects.\n");
	printf("For windows, I had to define HAVE_CONFIG_H, include win32/config.h,\n");
	printf("and include the files under libspeex, except those that start with test.\n");
	printf("Difficulty: Advanced\n\n");

	bool mute=false;
	bool quit;
	char ch;

	char port[256];
	rakPeer = RakNetworkFactory::GetRakPeerInterface();
#if defined(INTERACTIVE)
	printf("Enter local port: ");
	gets(port);
	if (port[0]==0)
#endif
		strcpy(port, "60000");
	SocketDescriptor socketDescriptor(atoi(port),0);

	rakPeer->Startup(4, 30, &socketDescriptor, 1);

	rakPeer->SetMaximumIncomingConnections(4);
	rakPeer->AttachPlugin(&rakVoice);

	rakVoice.Init(SAMPLE_RATE, FRAMES_PER_BUFFER*sizeof(SAMPLE));

	// Initialize our connection with DirectSound
	if (!DSoundVoiceAdapter::Instance()->SetupAdapter(&rakVoice, GetConsoleHwnd(), DSSCL_EXCLUSIVE))
	{
		printf("An error occurred while initializing DirectSound.\n");
		exit(-1);
	}

	Packet *p;
	quit=false;
#if defined(INTERACTIVE)
	printf("(Q)uit. (C)onnect. (D)isconnect. (M)ute. ' ' for stats.\n");
	printf("(+/-)encoder complexity.  (N)oise filter on/off. (V)AD on/off. (B)vbr on/off.\n");
#else
	rakPeer->Connect("1.1.1.1", 60000, 0,0);
#endif
	PrintParameters();
	while (!quit)
	{
#if defined(INTERACTIVE)
		if (kbhit())
		{
			ch=getch();
			if (ch=='+'){
				// Increase encoder complexity
				int v = rakVoice.GetEncoderComplexity();
				if (v<10) rakVoice.SetEncoderComplexity(v+1);
				PrintParameters();
			}
			else if (ch=='-'){
				// Decrease encoder complexity
				int v = rakVoice.GetEncoderComplexity();
				if (v>0) rakVoice.SetEncoderComplexity(v-1);
				PrintParameters();
			}
			else if (ch=='n'){
				// Turn on/off noise filter
				rakVoice.SetNoiseFilter(!rakVoice.IsNoiseFilterActive());
				PrintParameters();
			}
			else if (ch=='v') {
				// Turn on/off Voice detection
				rakVoice.SetVAD(!rakVoice.IsVADActive());
				PrintParameters();
			}
			else if (ch=='b') {
				// Turn on/off VBR
				rakVoice.SetVBR(!rakVoice.IsVBRActive());
				PrintParameters();
			}
			else if (ch=='y')
			{
				quit=true;
			}
			else if (ch=='c')
			{
				char ip[256];
				printf("\nEnter IP of remote system: ");
				gets(ip);
				if (ip[0]==0)
					strcpy(ip, "127.0.0.1");
				printf("\nEnter port of remote system: ");
				gets(port);
				if (port[0]==0)
					strcpy(port, "60000");
				rakPeer->Connect(ip, atoi(port), 0,0);
			}
			else if (ch=='m')
			{
				mute=!mute;
				DSoundVoiceAdapter::Instance()->SetMute(mute);
				if (mute)
					printf("\nNow muted.\n");
				else
					printf("\nNo longer muted.\n");
			}
			else if (ch=='d')
			{
				rakPeer->Shutdown(100,0);
			}
			else if (ch==' ')
			{
				char message[2048];
				RakNetStatistics *rss=rakPeer->GetStatistics(rakPeer->GetSystemAddressFromIndex(0));
				StatisticsToString(rss, message, 2);
				printf("%s", message);
			}
			else if (ch=='q')
				quit=true;
			ch=0;
		}

#endif

		p=rakPeer->Receive();
		while (p)
		{
			if (p->data[0]==ID_CONNECTION_REQUEST_ACCEPTED)
			{
				printf("\nID_CONNECTION_REQUEST_ACCEPTED from %s\n", p->systemAddress.ToString());
				rakVoice.RequestVoiceChannel(p->systemAddress);
			}
			else if (p->data[0]==ID_RAKVOICE_OPEN_CHANNEL_REQUEST)
			{
				printf("\nOpen Channel request from %s\n", p->systemAddress.ToString());
			}
			else if (p->data[0]==ID_RAKVOICE_OPEN_CHANNEL_REPLY)
			{
				printf("\nGot new channel from %s\n", p->systemAddress.ToString());
			}

			rakPeer->DeallocatePacket(p);
			p=rakPeer->Receive();
		}
		
		// Update our connection with DirectSound
		DSoundVoiceAdapter::Instance()->Update();

		LogStats();
		RakSleep(20);
	}

	// Release any FMOD resources we used, and shutdown FMOD itself
	DSoundVoiceAdapter::Instance()->Release();

	rakPeer->Shutdown(300);
	RakNetworkFactory::DestroyRakPeerInterface(rakPeer);

	return 0;
}
Exemple #12
0
void ARBarFormat::print() const 
{ 
	PrintName (std::cout); 
	PrintParameters (std::cout);
}
Exemple #13
0
int main(int argc,char *argv[])
{

    int counter; 

    printf("\n %s compiled %s : %s\n\n",argv[0],__DATE__,__TIME__);
    
    if (argc<3) {
        Usage();
        exit(-1);
    }


    /* Get the parameters */
    for (counter=1; counter<argc; counter++) {

        if (!strcmp("-rn",argv[counter])) {
	  //            remoteNodeId = strtol(argv[counter+1],(char **) NULL,10);
            continue;
        } 

        if (!strcmp("-size",argv[counter])) {
            segmentSize = strtol(argv[counter+1],(char **) NULL,10);
            continue;
        } 

        if (!strcmp("-adapterno",argv[counter])) {
            localAdapterNo = strtol(argv[counter+1],(char **) NULL,10);
            continue;
        }

        if (!strcmp("-client",argv[counter])) {
            client = 1;
            continue;
        }

        if (!strcmp("-server",argv[counter])) {
            server = 1;
            continue;
        }

        if (!strcmp("-help",argv[counter])) {
            Usage();
            exit(0);
        }
    }

    //    if (remoteNodeId == 0) {
    //   fprintf(stderr,"Remote node-id is not specified. Use -rn <remote node-id>\n");
    //  exit(-1);
    //}

    if (server == 0 && client == 0) {
        fprintf(stderr,"You must specify a client node or a server node\n");
        exit(-1);
    }

    if (server == 1 && client == 1) {
        fprintf(stderr,"Both server node and client node is selected.\n"); 
        fprintf(stderr,"You must specify either a client or a server node\n");
        exit(-1);
    }


    /* Initialize the SISCI library */
    SCIInitialize(NO_FLAGS, &error);
    if (error != SCI_ERR_OK) {
        fprintf(stderr,"SCIInitialize failed - Error code: 0x%x\n",error);
        exit(error);
    }


    /* Open a file descriptor */
    SCIOpen(&sdOne,NO_FLAGS,&error);
    if (error != SCI_ERR_OK) {
        if (error == SCI_ERR_INCONSISTENT_VERSIONS) {
            fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n");
        }
        fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error);
        exit(error); 
    }

    /* Open a file descriptor */
    SCIOpen(&sdTwo,NO_FLAGS,&error);
    if (error != SCI_ERR_OK) {
        if (error == SCI_ERR_INCONSISTENT_VERSIONS) {
            fprintf(stderr,"Version mismatch between SISCI user library and SISCI driver\n");
        }
        fprintf(stderr,"SCIOpen failed - Error code 0x%x\n",error);
        exit(error); 
    }


    /* Get local node-id */
    error = GetLocalNodeId(localAdapterNo, &localNodeId1);
    error = GetLocalNodeId(standbyAdapterNo, &localNodeId2);
    if (error != SCI_ERR_OK) {
      fprintf(stderr,"Could not find the local adapter %d\n", localAdapterNo);
      SCIClose(sdOne,NO_FLAGS,&error);
      SCIClose(sdTwo,NO_FLAGS,&error);
      exit(-1);
    }
    

    /* Print parameters */
    PrintParameters();

    if (client) {
      remoteNodeId1=324;
      remoteNodeId2=328;
        ShmemClientNode();
    } else {
         remoteNodeId1=452;
	 remoteNodeId2=456;
        ShmemServerNode();
    }

    /* Close the file descriptor */
    SCIClose(sdOne,NO_FLAGS,&error);
    SCIClose(sdTwo,NO_FLAGS,&error);
    if (error != SCI_ERR_OK) {
        fprintf(stderr,"SCIClose failed - Error code: 0x%x\n",error);
    }


    /* Free allocated resources */
    SCITerminate();

    return SCI_ERR_OK;
}
Exemple #14
0
int main(int argc, char **argv)
{
   struct tms tmsstart, tmsend;
   clock_t startTime, endTime;
   static long clktck = 0;
   time_t iterationStartTime;
   time_t iterationEndTime;
   SubList *subList;
   Substructure *normSub = NULL;
   Parameters *parameters;
   FILE *outputFile;
   ULONG iteration;
   BOOLEAN done;

   clktck = sysconf(_SC_CLK_TCK);
   startTime = times(&tmsstart);
   printf("GBAD %s\n\n", GBAD_VERSION);
   parameters = GetParameters(argc, argv);

   // compress positive graphs with predefined subs, if given
   if (parameters->numPreSubs > 0)
      CompressWithPredefinedSubs(parameters);

   PrintParameters(parameters);

   if (parameters->iterations > 1)
      printf("----- Iteration 1 -----\n\n");

   iteration = 1;
   parameters->currentIteration = iteration;
   done = FALSE;

   while ((iteration <= parameters->iterations) && (!done))
   {
      iterationStartTime = time(NULL);
      if (iteration > 1)
         printf("----- Iteration %lu -----\n\n", iteration);

      printf("%lu positive graphs: %lu vertices, %lu edges",
             parameters->numPosEgs, parameters->posGraph->numVertices,
             parameters->posGraph->numEdges);

      if (parameters->evalMethod == EVAL_MDL)
         printf(", %.0f bits\n", parameters->posGraphDL);
      else
         printf("\n");
      printf("%lu unique labels\n", parameters->labelList->numLabels);
      printf("\n");

      if ((parameters->prob) && (iteration > 1))
      {
         //
         // If GBAD-P option chosen, after the first iteration, we no longer
         // care about minsize of maxsize after the first iteration (if the
         // user specified these parameters), as we are just dealing with
         // single extensions from the normative - so set it to where we
         // just look at substructures that are composed of the normative
         // pattern (SUB_) and the single vertex extension.
         //
         parameters->minVertices = 1;
         parameters->maxVertices = 2;
      }
      //
      // If the user has specified a normative pattern, on the first iteration
      // need to save the top-N substructures, where N is what the user
      // specified with the -norm parameter.
      //
      ULONG saveNumBestSubs = parameters->numBestSubs;
      if ((iteration == 1) && (!parameters->noAnomalyDetection) &&
          (parameters->norm > parameters->numBestSubs))
         parameters->numBestSubs = parameters->norm;
      //
      // -prune is useful to get to the initial normative pattern, but 
      // possibly detremental to discovering anomalies... so, turn off 
      // pruning (in case it was turned on), so that it is not used in 
      // future iterations.
      //
      if ((parameters->prob) && (iteration > 1))
      {
         parameters->prune = FALSE;
      }
 
      subList = DiscoverSubs(parameters, iteration);

      //
      // Now that we have the best substructure(s), return the user
      // specified number of best substructures to its original value.
      //
      if (iteration == 1)
         parameters->numBestSubs = saveNumBestSubs;

      if (subList->head == NULL) 
      {
         done = TRUE;
         printf("No substructures found.\n\n");
      }
      else 
      {
         //
         // GBAD-MDL
         //
         if (parameters->mdl)
            GBAD_MDL(subList,parameters);

         //
         // GBAD-MPS
         //
         if (parameters->mps)
         {
            GBAD_MPS(subList,parameters);
         }

         //
         // GBAD-P
         //
         if (parameters->prob)
         {
            normSub = GBAD_P(subList,iteration,parameters);
         }

         // write output to stdout
         if (parameters->outputLevel > 1) 
         {
            printf("\nBest %lu substructures:\n\n", CountSubs (subList));
            PrintSubList(subList, parameters);
         } 
         else 
         {
            printf("\nBest substructure: ");
            if ((CountSubs(subList) > 0) && (subList->head->sub != NULL))
               PrintSub(subList->head->sub, parameters);
            else
               printf("None.");
            printf("\n\n");
         }

         // write machine-readable output to file, if given
         if (parameters->outputToFile) 
         {
            outputFile = fopen(parameters->outFileName, "a");
            if (outputFile == NULL) 
            {
               printf("WARNING: unable to write to output file %s,",
                      parameters->outFileName);
               printf("disabling\n");
               parameters->outputToFile = FALSE;
            }
            WriteGraphToFile(outputFile, subList->head->sub->definition,
                             parameters->labelList, 0, 0,
                             subList->head->sub->definition->numVertices,
                             TRUE);
            fclose(outputFile);
         }

         if (iteration < parameters->iterations) 
         {                                    // Another iteration?
            if (parameters->evalMethod == EVAL_SETCOVER) 
            {
               printf("Removing positive examples covered by");
               printf(" best substructure.\n\n");
               RemovePosEgsCovered(subList->head->sub, parameters);
            } 
            else 
            {
               //
               // For the GBAD-P algorithm, multiple iterations will need
               // to be performed, and if it is the first iteration
	       // AND the user has specified a different normative
	       // pattern (other than the best one), we need to 
	       // use the substructure that was set above.
	       //
	       if ((iteration == 1) && (parameters->prob))
	       {
	          printf("Compressing graph by best substructure (%lu):\n",
	                 parameters->norm);
                  PrintSub(normSub,parameters);
	          printf("\n");
                  CompressFinalGraphs(normSub, parameters, 
	                              iteration, FALSE);
               } else
                  CompressFinalGraphs(subList->head->sub, parameters, 
	                              iteration, FALSE);
	    }

            // check for stopping condition
            // if set-covering, then no more positive examples
            // if MDL or size, then positive graph contains no edges
            if (parameters->evalMethod == EVAL_SETCOVER) 
            {
               if (parameters->numPosEgs == 0) 
               {
                  done = TRUE;
                  printf("Ending iterations - ");
                  printf("all positive examples covered.\n\n");
               }
            } 
            else 
            {
               if (parameters->posGraph->numEdges == 0) 
               {
                  done = TRUE;
                  printf("Ending iterations - graph fully compressed.\n\n");
               }
            }
         }
         if ((iteration == parameters->iterations) && (parameters->compress))
         {
            if (parameters->evalMethod == EVAL_SETCOVER)
               WriteUpdatedGraphToFile(subList->head->sub, parameters);
            else 
               WriteCompressedGraphToFile(subList->head->sub, parameters,
                                          iteration);
         }
      }

      //
      // Need to store information regarding initial best substructure, for use
      // in future GBAD-P calculations
      //
      if ((parameters->prob) && (iteration == 1) && (subList->head != NULL))
      {
         parameters->numPreviousInstances = subList->head->sub->numInstances;
      }
      if ((parameters->prob) && (iteration > 1) && (subList->head != NULL))
         parameters->numPreviousInstances = subList->head->sub->numInstances;

      FreeSubList(subList);
      if (parameters->iterations > 1) 
      {
         iterationEndTime = time(NULL);
         printf("Elapsed time for iteration %lu = %lu seconds.\n\n",
         iteration, (iterationEndTime - iterationStartTime));
      }
      iteration++;
      parameters->currentIteration = iteration;
   }
 
   FreeParameters(parameters);
   endTime = times(&tmsend);
   printf("\nGBAD done (elapsed CPU time = %7.2f seconds).\n",
          (endTime - startTime) / (double) clktck);
   return 0;
}
Exemple #15
0
void ReadProblem()
{
    int i, K;
    char *Line, *Keyword;

    if (!(ProblemFile = fopen(ProblemFileName, "r")))
        eprintf("Cannot open PROBLEM_FILE: \"%s\"", ProblemFileName);
    if (TraceLevel >= 1)
        printff("Reading PROBLEM_FILE: \"%s\" ... ", ProblemFileName);
    FreeStructures();
    FirstNode = 0;
    WeightType = WeightFormat = ProblemType = -1;
    CoordType = NO_COORDS;
    Name = Copy("Unnamed");
    Type = EdgeWeightType = EdgeWeightFormat = 0;
    EdgeDataFormat = NodeCoordType = DisplayDataType = 0;
    Distance = 0;
    C = 0;
    c = 0;
    while ((Line = ReadLine(ProblemFile))) {
        if (!(Keyword = strtok(Line, Delimiters)))
            continue;
        for (i = 0; i < (int) strlen(Keyword); i++)
            Keyword[i] = (char) toupper(Keyword[i]);
        if (!strcmp(Keyword, "COMMENT"));
        else if (!strcmp(Keyword, "DEMAND_SECTION"))
            eprintf("Not implemented: %s", Keyword);
        else if (!strcmp(Keyword, "DEPOT_SECTION"))
            eprintf("Not implemented: %s", Keyword);
        else if (!strcmp(Keyword, "DIMENSION"))
            Read_DIMENSION();
        else if (!strcmp(Keyword, "DISPLAY_DATA_SECTION"))
            Read_DISPLAY_DATA_SECTION();
        else if (!strcmp(Keyword, "DISPLAY_DATA_TYPE"))
            Read_DISPLAY_DATA_TYPE();
        else if (!strcmp(Keyword, "EDGE_DATA_FORMAT"))
            Read_EDGE_DATA_FORMAT();
        else if (!strcmp(Keyword, "EDGE_DATA_SECTION"))
            Read_EDGE_DATA_SECTION();
        else if (!strcmp(Keyword, "EDGE_WEIGHT_FORMAT"))
            Read_EDGE_WEIGHT_FORMAT();
        else if (!strcmp(Keyword, "EDGE_WEIGHT_SECTION"))
            Read_EDGE_WEIGHT_SECTION();
        else if (!strcmp(Keyword, "EDGE_WEIGHT_TYPE"))
            Read_EDGE_WEIGHT_TYPE();
        else if (!strcmp(Keyword, "EOF"))
            break;
        else if (!strcmp(Keyword, "FIXED_EDGES_SECTION"))
            Read_FIXED_EDGES_SECTION();
        else if (!strcmp(Keyword, "NAME"))
            Read_NAME();
        else if (!strcmp(Keyword, "NODE_COORD_SECTION"))
            Read_NODE_COORD_SECTION();
        else if (!strcmp(Keyword, "NODE_COORD_TYPE"))
            Read_NODE_COORD_TYPE();
        else if (!strcmp(Keyword, "TOUR_SECTION"))
            Read_TOUR_SECTION(&ProblemFile);
        else if (!strcmp(Keyword, "TYPE"))
            Read_TYPE();
        else
            eprintf("Unknown keyword: %s", Keyword);
    }
    Swaps = 0;

    /* Adjust parameters */
    if (Seed == 0)
        Seed = (unsigned) time(0);
    if (Precision == 0)
        Precision = 100;
    if (InitialStepSize == 0)
        InitialStepSize = 1;
    if (MaxSwaps < 0)
        MaxSwaps = Dimension;
    if (KickType > Dimension / 2)
        KickType = Dimension / 2;
    if (Runs == 0)
        Runs = 10;
    if (MaxCandidates > Dimension - 1)
        MaxCandidates = Dimension - 1;
    if (ExtraCandidates > Dimension - 1)
        ExtraCandidates = Dimension - 1;
    if (SubproblemSize >= Dimension)
        SubproblemSize = Dimension;
    else if (SubproblemSize == 0) {
        if (AscentCandidates > Dimension - 1)
            AscentCandidates = Dimension - 1;
        if (InitialPeriod < 0) {
            InitialPeriod = Dimension / 2;
            if (InitialPeriod < 100)
                InitialPeriod = 100;
        }
        if (Excess < 0)
            Excess = 1.0 / Dimension;
        if (MaxTrials == -1)
            MaxTrials = Dimension;
        MakeHeap(Dimension);
    }
    if (CostMatrix == 0 && Dimension <= MaxMatrixDimension && 
        Distance != 0 && Distance != Distance_1 && 
        Distance != Distance_ATSP && Distance != Distance_SPECIAL) {
        Node *Ni, *Nj;
        assert(CostMatrix =
               (int *) calloc((size_t) Dimension * (Dimension - 1) / 2,
                              sizeof(int)));
        Ni = FirstNode->Suc;
        do {
            Ni->C =
                &CostMatrix[(size_t) (Ni->Id - 1) * (Ni->Id - 2) / 2] - 1;
            if (ProblemType != HPP || Ni->Id < Dimension)
                for (Nj = FirstNode; Nj != Ni; Nj = Nj->Suc)
                    Ni->C[Nj->Id] = Fixed(Ni, Nj) ? 0 : Distance(Ni, Nj);
            else
                for (Nj = FirstNode; Nj != Ni; Nj = Nj->Suc)
                    Ni->C[Nj->Id] = 0;
        }
        while ((Ni = Ni->Suc) != FirstNode);
        WeightType = EXPLICIT;
        c = 0;
    }
    if (Precision > 1 && (WeightType == EXPLICIT || ProblemType == ATSP)) {
        int j, n = ProblemType == ATSP ? Dimension / 2 : Dimension;
        for (i = 2; i <= n; i++) {
            Node *N = &NodeSet[i];
            for (j = 1; j < i; j++)
                if (N->C[j] * Precision / Precision != N->C[j])
                    eprintf("PRECISION (= %d) is too large", Precision);
        }
    }
    C = WeightType == EXPLICIT ? C_EXPLICIT : C_FUNCTION;
    D = WeightType == EXPLICIT ? D_EXPLICIT : D_FUNCTION;
    if (SubsequentMoveType == 0)
        SubsequentMoveType = MoveType;
    K = MoveType >= SubsequentMoveType
        || !SubsequentPatching ? MoveType : SubsequentMoveType;
    if (PatchingC > K)
        PatchingC = K;
    if (PatchingA > 1 && PatchingA >= PatchingC)
        PatchingA = PatchingC > 2 ? PatchingC - 1 : 1;
    if (NonsequentialMoveType == -1 ||
        NonsequentialMoveType > K + PatchingC + PatchingA - 1)
        NonsequentialMoveType = K + PatchingC + PatchingA - 1;
    if (PatchingC >= 1 && NonsequentialMoveType >= 4) {
        BestMove = BestSubsequentMove = BestKOptMove;
        if (!SubsequentPatching && SubsequentMoveType <= 5) {
            MoveFunction BestOptMove[] =
                { 0, 0, Best2OptMove, Best3OptMove,
                Best4OptMove, Best5OptMove
            };
            BestSubsequentMove = BestOptMove[SubsequentMoveType];
        }
    } else {
        MoveFunction BestOptMove[] = { 0, 0, Best2OptMove, Best3OptMove,
            Best4OptMove, Best5OptMove
        };
        BestMove = MoveType <= 5 ? BestOptMove[MoveType] : BestKOptMove;
        BestSubsequentMove = SubsequentMoveType <= 5 ?
            BestOptMove[SubsequentMoveType] : BestKOptMove;
    }
    if (ProblemType == HCP || ProblemType == HPP)
        MaxCandidates = 0;
    if (TraceLevel >= 1) {
        printff("done\n");
        PrintParameters();
    } else
        printff("PROBLEM_FILE = %s\n",
                ProblemFileName ? ProblemFileName : "");
    fclose(ProblemFile);
    if (InitialTourFileName)
        ReadTour(InitialTourFileName, &InitialTourFile);
    if (InputTourFileName)
        ReadTour(InputTourFileName, &InputTourFile);
    if (SubproblemTourFileName && SubproblemSize > 0)
        ReadTour(SubproblemTourFileName, &SubproblemTourFile);
    if (MergeTourFiles >= 1) {
        free(MergeTourFile);
        assert(MergeTourFile =
               (FILE **) malloc(MergeTourFiles * sizeof(FILE *)));
        for (i = 0; i < MergeTourFiles; i++)
            ReadTour(MergeTourFileName[i], &MergeTourFile[i]);
    }
    free(LastLine);
    LastLine = 0;
}
Exemple #16
0
int main(void)
{
	FMOD_RESULT    result;
	unsigned int   version;

	/*
	Create a System object and initialize.
	*/
	result = FMOD::System_Create(&fmodSystem);
	RakAssert(result>=0);

	result = fmodSystem->getVersion(&version);
	RakAssert(result>=0);

	if (version < FMOD_VERSION)
	{
		printf("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", version, FMOD_VERSION);
		return -1;
	}

	//  result = fmodSystem->init(100, FMOD_INIT_NORMAL, (void *)&extradriverdata);
	result = fmodSystem->init(100, FMOD_INIT_NORMAL, 0);
	RakAssert(result>=0);
//	ERRCHECK(result);

	printf("A sample on how to use RakVoice. You need a microphone for this sample.\n");
	printf("RakVoice relies on Speex for voice encoding and decoding.\n");
	printf("See DependentExtensions/RakVoice/speex-1.1.12 for speex projects.\n");
	printf("For windows, I had to define HAVE_CONFIG_H, include win32/config.h,\n");
	printf("and include the files under libspeex, except those that start with test.\n");
	printf("Difficulty: Advanced\n\n");

	mute=false;
	bool quit;
	char ch;

	char port[256];
	rakPeer = RakNet::RakPeerInterface::GetInstance();
#if defined(INTERACTIVE)
	printf("Enter local port: ");
	Gets(port, sizeof(port));
	if (port[0]==0)
#endif
		strcpy(port, "60000");
	RakNet::SocketDescriptor socketDescriptor(atoi(port),0);

	rakPeer->Startup(4, &socketDescriptor, 1);

	rakPeer->SetMaximumIncomingConnections(4);
	rakPeer->AttachPlugin(&rakVoice);

	rakVoice.Init(SAMPLE_RATE, FRAMES_PER_BUFFER*sizeof(SAMPLE));


	// Initialize our connection with FMOD
	if (!RakNet::FMODVoiceAdapter::Instance()->SetupAdapter(fmodSystem, &rakVoice)){
			printf("An error occurred while initializing FMOD sounds.\n");
			exit(-1);
		}

	RakNet::Packet *p;
	quit=false;
#if defined(INTERACTIVE)
	printf("(Q)uit. (C)onnect. (D)isconnect. (M)ute. ' ' for stats.\n");
	printf("(+/-)encoder complexity.  (N)oise filter on/off. (V)AD on/off. (B)vbr on/off.\n");
#else
	rakPeer->Connect("1.1.1.1", 60000, 0,0);
#endif
	PrintParameters();
	while (!quit)
	{
#if defined(INTERACTIVE)
		if (kbhit())
		{
			ch=getch();
			if (ch=='+'){
				// Increase encoder complexity
				int v = rakVoice.GetEncoderComplexity();
				if (v<10) rakVoice.SetEncoderComplexity(v+1);
				PrintParameters();
			}
			else if (ch=='-'){
				// Decrease encoder complexity
				int v = rakVoice.GetEncoderComplexity();
				if (v>0) rakVoice.SetEncoderComplexity(v-1);
				PrintParameters();
			}
			else if (ch=='n'){
				// Turn on/off noise filter
				rakVoice.SetNoiseFilter(!rakVoice.IsNoiseFilterActive());
				PrintParameters();
			}
			else if (ch=='v') {
				// Turn on/off Voice detection
				rakVoice.SetVAD(!rakVoice.IsVADActive());
				PrintParameters();
			}
			else if (ch=='b') {
				// Turn on/off VBR
				rakVoice.SetVBR(!rakVoice.IsVBRActive());
				PrintParameters();
			}
			else if (ch=='y')
			{
				quit=true;
			}
			else if (ch=='c')
			{
				char ip[256];
				printf("\nEnter IP of remote system: ");
				Gets(ip, sizeof(ip));
				if (ip[0]==0)
					strcpy(ip, "127.0.0.1");
				printf("\nEnter port of remote system: ");
				Gets(port, sizeof(port));
				if (port[0]==0)
					strcpy(port, "60000");
				rakPeer->Connect(ip, atoi(port), 0,0);
			}
			else if (ch=='m')
			{
				mute=!mute;
				RakNet::FMODVoiceAdapter::Instance()->SetMute(mute);
				if (mute)
					printf("\nNow muted.\n");
				else
					printf("\nNo longer muted.\n");
			}
			else if (ch=='d')
			{
				rakPeer->Shutdown(100,0);
			}
			else if (ch==' ')
			{
				char message[2048];
				RakNet::RakNetStatistics *rss=rakPeer->GetStatistics(rakPeer->GetSystemAddressFromIndex(0));
				StatisticsToString(rss, message, 2);
				printf("%s", message);
			}
			else if (ch=='q')
				quit=true;
			ch=0;
		}

#endif

		p=rakPeer->Receive();
		while (p)
		{
			if (p->data[0]==ID_CONNECTION_REQUEST_ACCEPTED)
			{
				printf("\nID_CONNECTION_REQUEST_ACCEPTED from %s\n", p->systemAddress.ToString());
				rakVoice.RequestVoiceChannel(p->guid);
			}
			else if (p->data[0]==ID_RAKVOICE_OPEN_CHANNEL_REQUEST)
			{
				printf("\nOpen Channel request from %s\n", p->systemAddress.ToString());
			}
			else if (p->data[0]==ID_RAKVOICE_OPEN_CHANNEL_REPLY)
			{
				printf("\nGot new channel from %s\n", p->systemAddress.ToString());
			}

			rakPeer->DeallocatePacket(p);
			p=rakPeer->Receive();
		}

		fmodSystem->update();
		// Update or connection with FMOD
		RakNet::FMODVoiceAdapter::Instance()->Update();
	//	LogStats();
		RakSleep(20);

	}

	// Release any FMOD resources we used, and shutdown FMOD itself
	RakNet::FMODVoiceAdapter::Instance()->Release();
	fmodSystem->release();

	rakPeer->Shutdown(300);
	rakPeer->DetachPlugin(&rakVoice);
	RakNet::RakPeerInterface::DestroyInstance(rakPeer);

	return 0;
}