Esempio n. 1
0
void draw_layer(TCanvas* c, TH2F* h, Int_t iHist, 
                Int_t nLayers, Double_t maxWeight)
{
   const Double_t MAX_NEURONS_NICE = 12;
   const Double_t LABEL_HEIGHT = 0.03;
   const Double_t LABEL_WIDTH  = 0.20;
   Double_t ratio = ((Double_t)(c->GetWindowHeight())) / c->GetWindowWidth();
   Double_t rad, cx1, *cy1, cx2, *cy2;

   // this is the smallest radius that will still display the activation images
   rad = 0.04*650/c->GetWindowHeight();

   Int_t nNeurons1 = h->GetNbinsX();
   cx1 = iHist*(1.0-LABEL_WIDTH)/nLayers + 1.0/(2.0*nLayers) + LABEL_WIDTH;
   cy1 = new Double_t[nNeurons1];

   Int_t nNeurons2 = h->GetNbinsY();
   cx2 = (iHist+1)*(1.0-LABEL_WIDTH)/nLayers + 1.0/(2.0*nLayers) + LABEL_WIDTH;
   cy2 = new Double_t[nNeurons2];

   Double_t effRad1 = rad;
   if (nNeurons1 > MAX_NEURONS_NICE)
      effRad1 = 0.8*(1.0-LABEL_HEIGHT)/(2.0*nNeurons1);


   for (Int_t i = 0; i < nNeurons1; i++) {
      cy1[nNeurons1-i-1] = i*(1.0-LABEL_HEIGHT)/nNeurons1 + 
         1.0/(2.0*nNeurons1) + LABEL_HEIGHT;

      if (iHist == 0) {

         TEllipse *ellipse 
            = new TEllipse(cx1, cy1[nNeurons1-i-1], 
                           effRad1*ratio, effRad1, 0, 360, 0);
         ellipse->SetFillColor(TColor::GetColor( "#fffffd" ));
         ellipse->SetFillStyle(1001);
         ellipse->Draw();

         if (i == 0) ellipse->SetLineColor(9);

         if (nNeurons1 > MAX_NEURONS_NICE) continue;

         Int_t whichActivation = 0;
         if (iHist==0 || iHist==nLayers-1 || i==0) whichActivation = 1;
         draw_activation(c, cx1, cy1[nNeurons1-i-1], 
                         rad*ratio, rad, whichActivation);
      }
   }

   if (iHist == 0) draw_input_labels(nNeurons1, cy1, rad, (1.0-LABEL_WIDTH)/nLayers);

   Double_t effRad2 = rad;
   if (nNeurons2 > MAX_NEURONS_NICE)
      effRad2 = 0.8*(1.0-LABEL_HEIGHT)/(2.0*nNeurons2);

   for (Int_t i = 0; i < nNeurons2; i++) {
      cy2[nNeurons2-i-1] = i*(1.0-LABEL_HEIGHT)/nNeurons2 + 1.0/(2.0*nNeurons2) + LABEL_HEIGHT;

      TEllipse *ellipse = 
         new TEllipse(cx2, cy2[nNeurons2-i-1], effRad2*ratio, effRad2, 0, 360, 0);
      ellipse->SetFillColor(TColor::GetColor( "#fffffd" ));
      ellipse->SetFillStyle(1001);
      ellipse->Draw();

      if (i == 0 && nNeurons2 > 1) ellipse->SetLineColor(9);

      if (nNeurons2 > MAX_NEURONS_NICE) continue;

      Int_t whichActivation = 0;
      if (iHist+1==0 || iHist+1==nLayers-1 || i==0) whichActivation = 1;
      draw_activation(c, cx2, cy2[nNeurons2-i-1], rad*ratio, rad, whichActivation);
   }

   for (Int_t i = 0; i < nNeurons1; i++) {
      for (Int_t j = 0; j < nNeurons2; j++) {
         draw_synapse(cx1, cy1[i], cx2, cy2[j], effRad1*ratio, effRad2*ratio,
                      h->GetBinContent(i+1, j+1)/maxWeight);
      }
   }

   delete[] cy1;
   delete[] cy2;
}
Esempio n. 2
0
int	main(void)
{
	  int 	unit = MILLI;
	  int	i, id, k;
	  int	c;						/* character from keyboard	*/
	  int   ntasks 	= 0;        	/* total number of activated tasks*/
	  int 	ret		= 0;
	  int 	tipo_prio = PRIO_EQUAL;
	  int 	sched 	= SCHED_RR;
	  int 	part	= GLOBAL;
	  int 	prot 	= NO_PROTOCOL;
	  int 	test 	= TASK_FUN;
	  int 	modeACT = MOD_NOW;		/* {MOD_NOW=0, MOD_DEF_OFFSET=1, MOD_DEF_NO_OFFS = 2} */
	  int   act_flag = NOW;

	  init(TASK_FUN);

	  int 	num_tasks = NUM_T_TEST;
	  int 	priority[num_tasks];
	  ptime v_offset[num_tasks];	/* time offset vector */

	  for(i = 0; i < num_tasks; i++) v_offset[i] = 0;

	  modeACT = select_act (v_offset, num_tasks); // {MOD_NOW=0, MOD_DEF_OFFSET=1, MOD_DEF_NO_OFFS = 2}
	  if ( modeACT == -1 ) {
		  allegro_exit();
	   	  return 0;
	   }

	   ptask_init(sched, part, prot);

	   /* Time reference for timeoffset */
	   time_t0 = ptask_gettime(MILLI);
	   ptime time_tmp;

	   if(modeACT == 0) {	// {MOD_NOW=0, MOD_DEF_OFFSET=1, MOD_DEF_NO_OFFS = 2}
		   act_flag = NOW;
	   }
	   else {
		   act_flag = DEFERRED;
	   }

	   init_vettore_prio(tipo_prio, priority, num_tasks);

	   draw_system_info(sched, part, prot, modeACT, tipo_prio, test, false);

	   draw_Timetask_info(modeACT);

	   pthread_mutex_lock(&mxa);
	   textprintf_ex(screen, font, 2, 25 + 15, FGC, BGC, " Time reference t0 = %ld (time creation/visualization of this screen)", time_t0);
	   pthread_mutex_unlock(&mxa);
	   const char* str_offset = "Time offset(ms) inseriti = ";

	   /* Creation of aperiodic task */
	   for ( i = 0; i < num_tasks; i++) {

	    	if (modeACT != MOD_DEF_OFFSET) {

	    		/* MODE WITHOUT OFFSET */
	    		time_tmp = ptask_gettime(MILLI);
	    		if(act_flag == NOW) {
	    			pthread_mutex_lock(&mxa);
	    			textprintf_ex(screen, font, X_LINE_VERT0 + 5, Y_TIMES + i * ALT_RIGA, FGC, BGC, "%ld            ", time_tmp);
	    			pthread_mutex_unlock(&mxa);
	    		}
	    		id = ptask_create(periodicLine_testSystemTask, PER, priority[i], act_flag);
	    	}
	    	else {
	    			/* MODE WITH OFFSET */
	    			time_tmp = ptask_gettime(MILLI);
	    			pthread_mutex_lock(&mxa);
	    			textprintf_ex(screen, font, (X_LINE_VERT0 + X_LINE_VERT1)/2, Y_TIMES + i * ALT_RIGA, FGC, BGC, "-");
	    			pthread_mutex_unlock(&mxa);
	    			id = ptask_create(periodicLine_testSystemTaskOFFSET, PER, priority[i], act_flag);
	    			printf("act_flag = %d, id = %d, v_offset[%d] = %ld\n", act_flag, id+1, id, v_offset[id]);
	    			ret = ptask_activate_at(id, v_offset[i]);

	    			if (ret != -1) {
	    				draw_activation (ntasks, i, priority[i], false);
	    				ntasks++;
	    				if (i == 0) {
	    					pthread_mutex_lock(&mxa);
	    					textout_ex(screen, font, str_offset, XMIN, BASE1 + 2 * ALT_RIGA, FGC, 0);
	    					pthread_mutex_unlock(&mxa);
	    				}
	    				pthread_mutex_lock(&mxa);
	    				textprintf_ex(screen, font, XMIN + (strlen(str_offset)+i*(NUM_CIF_OFFSET))*PIXEL_CHAR, BASE1 + 2 * ALT_RIGA,FGC, BGC, "%ld", v_offset[i]);
	    				pthread_mutex_unlock(&mxa);
	    			}
	    			else fprintf(stderr, "Task %d non può essere attivato o già avviato!!!\n", i+1);

	    	}
	       	if (id != -1) {
	       		char* temp = " e attivato!\n";
	       		if(act_flag == DEFERRED) {
	       			temp = "!\n";
	       		}
	       		printf("Task %d creato%s", id+1, temp);
	       	}
	       	else {
	       	    allegro_exit();
	       	    printf("Errore nella creazione(o anche attivazione NOW) del task!\n");
	       	    exit(-1);
	       	}
	   }

	   do {

		   	k = 0;
	   	   	if (keypressed()) {
	   	   		c = readkey();
	   	   		k = c >> 8;
	   	   	}

		   if ((k >= KEY_1) && (k <= KEY_0 + num_tasks) && (modeACT != MOD_DEF_OFFSET)) {

			   id = k - KEY_0 - 1;
			   time_tmp = ptask_gettime(unit);
			   ret = ptask_activate(id);

			   if (ret != -1) {
				   printf("Task %d attivato\n", id);
				   pthread_mutex_lock(&mxa);
				   textprintf_ex(screen, font, X_LINE_VERT0 + 5, Y_TIMES + (id) * ALT_RIGA,
						   FGC, BGC, "%ld            ", time_tmp);
				   pthread_mutex_unlock(&mxa);
				   draw_activation (ntasks, id, priority[id], false);
				   ntasks++;
			   }
			   else{

				   printf("Task %d non può essere attivato o già avviato!!!\n", id);
				   pthread_mutex_lock(&mxa);
				   textprintf_ex(screen, font, X_LINE_VERT0 + 5, Y_TIMES + id * ALT_RIGA,FGC, BGC, "T%d: Gia' attivo!   ", id);
				   pthread_mutex_unlock(&mxa);
			   }
		   }

	   } while (k != KEY_ESC);
	   allegro_exit();
	   return 0;
}