コード例 #1
0
ファイル: EtherMenu.cpp プロジェクト: Belsepubi/naali
        void EtherMenu::RectChanged(const QRectF& bounds)
        {
            boundaries_ = bounds;
            positions_.clear();

            if(bounds.height()< card_max_size_.height())
            {
                current_scale_factor_ = scale_factor_ - (1- (bounds.height()/ card_max_size_.height()));
                current_card_max_size_.setHeight( bounds.height() );

            }
            else
            {
                current_scale_factor_ = scale_factor_;
                current_card_max_size_.setHeight( card_max_size_.height() );
            }
            CalculateGap();
            CalculatePositions(positions_);
            InitializeObjectValues();
        }
コード例 #2
0
ファイル: EtherMenu.cpp プロジェクト: Belsepubi/naali
        void EtherMenu::Initialize(const QRectF& bounds, const QVector<InfoCard *>& items, const QRectF& max_size, qreal scalef, int visible_objects, qreal opacity_factor, qreal max_gap)
        {
            objects_.clear();
            positions_.clear();
            animations_->clear();
            priority_list_.clear();

            objects_ = items;
            boundaries_ = bounds;
            max_visible_objects_ = visible_objects;
            priority_list_.fill(0, objects_.size());
            current_card_max_size_ = card_max_size_ = max_size;
            opacity_factor_ = opacity_factor;
            current_scale_factor_ = scale_factor_ = scalef;
            max_gap_ = max_gap;

            CalculateGap();
            CalculatePositions(positions_);

            ConstructPriorityList();
            CalculateLimits();
            InitializeAnimations();
            InitializeObjectValues();
        }
コード例 #3
0
ファイル: main.cpp プロジェクト: davidlove/omrp
void run( int argc, char *argv[] )
{
   // ------------------------------------------------------------------------
   // ------------------------------------------------------------------------
   // Get important parameter values from command line input
   // ------------------------------------------------------------------------
   // ------------------------------------------------------------------------
   char           optionCharacter;
   //extern char*   optarg;
   extern int     optind;
                  //optopt;

   int            inputN = 0,
                  inputM = 0,
                  inputK = 0,
                  inputG = 0,
                  inputR = 300,
                  nkFlag = 0;
   string	  scenFileName;

   while( ( optionCharacter = getopt( argc, argv, "n:m:k:g:r:f:" ) ) != -1 )
   {
      switch( optionCharacter )
      {
         case 'n':
            inputN = atoi( argv[optind-1] );
            nkFlag++;
            break;
         case 'm':
            inputM = atoi( argv[optind-1] );
            break;
         case 'k':
            inputK = atoi( argv[optind-1] );
            nkFlag++;
            break;
         case 'g':
            inputG = atoi( argv[optind-1] );
            break;
         case 'r':
            inputR = atoi( argv[optind-1] );
            break;
	 case 'f':
	    scenFileName = argv[optind-1];
	    break;
         case ':':
         case '?':
            exit(1);
      }
   }

   // If g is not specified, use nonoverlapping batches
   if( !inputG )
   {
      inputG = inputM;
   }

   // If no scenario file name is given, quit
   if( scenFileName.empty() )
   {
      cerr << "Must specify a file for scenario information, -f filename" << endl;
      exit(1);
   }

   // Only one of n, k can be specified.  Enforce this
   if( !nkFlag )
   {
      inputK = 30;
      inputN = inputM * inputK;
   }
   else if( nkFlag > 1 )
   {
      cerr << "Can only specify one of n, k" << endl;
      exit(1);
   }
   else if( !inputN )
   {
      inputN = inputM * inputK;
   }
   else
   {
      inputK = inputN / inputM;
   }

   // m must be specified
   if( !inputM )
   {
      cerr << "Batch size m must be specified" << endl;
      exit(1);
   }
   // ------------------------------------------------------------------------
   // ------------------------------------------------------------------------
   // End of parsing the input
   // ------------------------------------------------------------------------
   // ------------------------------------------------------------------------

   // Get the distribution
   ReadScenarios( scenFileName );
   // Set up the vector to hold the batches
   batchScenarios = new double[inputM];

//****************************************************************************************

	//THIS SECTION IS THE MRP BY ITSELF...........
	
        // David Love -- Added number of nonoverlapping batches
        const int numNonOverBatches = inputK;  // Number of nonoverlapping batches
        const int batchSize = inputM;
        // David Love -- Delete gamma when I have a working gamma input
        const int gamma = inputG;

        // David Love -- Rewrote the number of batches to work with overlapping
	const int numBatches = floor( (numNonOverBatches - 1) * (double) batchSize / (double) gamma + 1 );      //this is the smaller loop for the MRP
        // David Love -- Degrees of freedom of variance operator
        const int sampleSize = batchSize + (numBatches-1)*gamma;
        // DESPERATION -- I'm chaning the degreesFreedom and ciDenom
        const double degreesFreedom = numBatches * ( (double) sampleSize / (double) batchSize - 1.0 );
        const double ciDenom = 1.0;

        // David Love -- Counters for calculating total average gap
        double *  indivGaps;     // Gap estimates for individual samples
        int    *  indivCounts;   // Counter for "vertical" part of total gap average
        double *  gapest;        // holds all of the gap estimators
	
	int kk, oo; 
	double *var, *gbar, *ci; 

	double *znstar, *znstarbar; 

	double zn; 
	
	double optg = 1282152.974;   //cep1, for xhat=(650,...,650, 150,...,150)  
		//2.833632377;   //pgp2, for xhat=(2.5, 6, 3.5, 4.5)
		//20.01728866212;  //pgp2, for xhat=(2, 7, 2, 5)
		//38129.093677509;   //cep1, for xhat=(0,125,875,2500,0,625,1375,3000)  
		//54.32289045997;  //pgp2, for xhat=(3, 4, 4,,  4) 
                //164.84;          //apl1p, for xhat = (1111.11, 2300)
		
		//11737.350015; //cep1, for xhat=(0,0,1166.67,2500,0,500,1666.67,3000) 
		
		
	double cov = 0.0; 

	double mns, vrs;		//mean and variance for the inner loop 

        // The following two variables are not defined in the code when I got it.  Had to add them myself.
	int numCIs = inputR;//1000;                  // Added by David Love
	double za = 1.282;              // Added by David Love


	var = new double[numCIs];
	gbar = new double[numCIs];
	ci = new double[numCIs];
	
	znstarbar = new double[numCIs];

	znstar = new double[numCIs*numBatches]; 

        // David Love -- Debug by listing all gap values
        //double gapValues[numCIs][numBatches];

        // David Love -- Testing that gamma, number of batches and degrees of freedom work correctly
        // printf( " gamma = %d \n num batches = %d \n degreesFreedom = %d\n", gamma, numBatches, degreesFreedom );
        // exit(0);
        
        // David Love -- Initializers for calculating total gap average
        indivGaps = new double[sampleSize];
        indivCounts = new int[sampleSize];
        gapest = new double[numBatches];

	for(kk=0; kk<numCIs; kk++){

		mns = 0.0; 
		vrs = 0.0; 
		zn  = 0.0; 

                // David Love -- Let the screen count where we are in numCIs
#if !MAKE_TRD
                printf( "Rep %d of %d, gamma = %d, m = %d, n = %d, nb = %d, degreesFreedom = %lf\n", kk, numCIs, gamma, batchSize, sampleSize, numBatches, degreesFreedom );
#endif

                // David Love -- Initialize gap counters
                for( int ii = 0; ii < sampleSize; ii++ )
                {
                   indivGaps[ii] = 0.0;
                   indivCounts[ii] = 0;
                }

		// David Love -- Generate a full selection of scenarios for each batch
                //printf( "j -- Beginning replication %d of %d\n", kk+1, numCIs );
		ReGenerateScenarios( batchSize, batchSize ); 
		for(oo = 0; oo<numBatches; oo++){
                        // David Love -- ReGenerate back at the end of the loop.  Initialized outside the looop
                        //printf( "j -- Batch %d of %d, overlap = %d\n", oo+1, numBatches, batchSize - gamma );
			ReGenerateScenarios( batchSize, gamma ); 


                        /* // @BEGIN Rebecca's code to print the scenarios
                        // Tested and Confirmed: Overlapping is working correctly!!!
                        printf( "SCEN Printing Scenarios\n" );
                        printf( "SCEN Batch %d of %d\n", oo+1, numBatches );
                        for (int scenCounter = 0; scenCounter < batchSize; scenCounter++)
                        {
                           printf( "SCEN " );
                           printf("%d ", scenCounter+1);
                           Scen->GetScenarioComponents(scenCounter);
                           printf("\n");
                        }
                        printf("SCEN\n");
                        */ // @END Rebecca's code

                        // DESPERATION -- Commenting out a couple things to see if it compiles
			//znstar[kk*numBatches+oo] = sol->result; 

                        // DESPERATION -- Commenting out a couple things to see if it compiles
			//zn += sol->result; 
			
			gapest[oo] = CalculateGap( batchSize );

                        // David Love -- Loop for the new "G Double Bar"
                        for( int gammaCounter = 0; gammaCounter < batchSize; gammaCounter++ )
                        {
                           //indivGaps[oo*gamma + gammaCounter] += ( master.GetIndivGap(gammaCounter) + master.GetIndivGap(batchSize) ) * pow(10.0, ObjScale);
                           indivGaps[oo*gamma + gammaCounter] += batchScenarios[gammaCounter];
#if MAKE_TRD
                           cout << batchScenarios[gammaCounter] << ' ';
#endif
                           indivCounts[oo*gamma + gammaCounter] += 1;
                           //printf( "indivGaps[%d] = %lf, indivCounts[%d] = %d\n", oo*gamma + gammaCounter, indivGaps[oo*gamma + gammaCounter], 
                                 //oo*gamma + gammaCounter, indivCounts[oo*gamma + gammaCounter] );
                           //printf( "ExpC[%d] = %lf, v[%d] = %lf\n", oo*gamma + gammaCounter, master.GetExpC(gammaCounter) + master.GetExpC(batchSize),
                                 //oo*gamma + gammaCounter, master.GetV(gammaCounter) + master.GetV(batchSize) );
                        }
#if MAKE_TRD
                        cout << endl;
#endif
		} //end of for with "oo" (0 == oo < numBatches). 


		//MRP calculations:

                // David Love -- New calculation of the gap estimate
                gbar[kk] = 0.0;
                for( int ii = 0; ii < sampleSize; ii++ )
                {
                   indivGaps[ii] /= indivCounts[ii];
                   gbar[kk] += indivGaps[ii];
                }
                gbar[kk] /= sampleSize;
                //printf( "gbar[%d]   = %lf\n", kk, gbar[kk] );
		//mns /= (double) numBatches; 
		//vrs /= (double) numBatches; 

                vrs = 0.0;
                for( int ii = 0; ii < numBatches; ii++ )
                {
                   vrs += pow( gapest[ii] - gbar[kk], 2 );
                }
                vrs /= (double) degreesFreedom;

		//vrs = vrs - pow(mns, 2) ;
                // David Love -- Had to change degrees of freedom
		// vrs = vrs * numBatches / (double) (numBatches-1); 
		// vrs = vrs * numBatches / (double) degreesFreedom; 

		//gbar[kk] = mns; 
		var[kk] = vrs; 

		ci[kk] = gbar[kk] + za*sqrt(var[kk]) / sqrt(ciDenom); 
		if(ci[kk] >= optg) cov++; 

		//also calculate znstarbar

		znstarbar[kk] = zn / (double) numBatches; 
		
	}  //end of loop with kk

        // David Love -- Statistics on variance calculations
        double avgVar = 0.0;
        for( kk = 0; kk < numCIs; kk++ )
                avgVar += var[kk];
        avgVar = avgVar / numCIs;
        double varVariance = 0.0;
        for( kk = 0; kk < numCIs; kk++ )
           varVariance += pow( var[kk] - avgVar, 2 );
        varVariance = varVariance / (numCIs-1);
        // David Love -- Statistics on confidence interval width
        double ciWidth = 0.0,
               varCIWidth = 0.0;
        for( kk = 0; kk < numCIs; kk++ )
                ciWidth += za * sqrt( var[kk] ) / sqrt( ciDenom );
        ciWidth = ciWidth / numCIs;
        for( kk = 0; kk < numCIs; kk++ )
           varCIWidth += pow( (za * sqrt( var[kk] ) / sqrt( ciDenom )) - ciWidth, 2 );
        varCIWidth = varCIWidth / (numCIs-1);
        // David Love -- Statistics on total CI size
        double ciSize = 0.0,
               varCISize = 0.0;
        for( kk = 0; kk < numCIs; kk++ )
                ciSize += znstarbar[kk] + za * sqrt( var[kk] ) / sqrt( ciDenom );
        ciSize = ciSize / numCIs;
        for( kk = 0; kk < numCIs; kk++ )
           varCISize += pow( (znstarbar[kk] + za * sqrt( var[kk] ) / sqrt( ciDenom )) - ciSize, 2 );
        varCISize = varCISize / (numCIs-1);

        //for( kk = 0; kk < numCIs; kk++ )
           //ciWidth += znstarbar[kk];
        //ciWidth /= numCIs;
        //ciWidth += za * sqrt(avgVar) / sqrt( ciDenom );

	//print results:
	cov = (double) cov / numCIs;  

        // David Love -- Clearing out printed information
	// printf ("Optimality Gap = %f\n\n", optg); 
	
        // David Love -- Clearing out printed information
	// printf ("\nMRP RESULTS:\n"); 
	// printf ("-----------------\n\n"); 
	// printf ("k:         GAP:			SVAR:		CI			znstarbar:\n"); 
	// for(kk=0; kk<numCIs; kk++){
		// printf ("%d\t%f\t%20.10E\t%f\t%f\n", kk+1, gbar[kk], var[kk], ci[kk], znstarbar[kk]);
	// }

        printf("BEGIN MRP\n");
        printf("Batch Size = %d\n", batchSize);
        printf("gamma = %d\n", gamma);
        printf("CI Width = %lf\n", ciWidth);
	printf ("Coverage, MRP: = %lf\n", cov); 
        printf ("Average Variance = %lf\n", avgVar );
        printf("Variance of Variance = %le\n", varVariance );
        printf("Number Batches = %d\n", numBatches);
        printf("Degrees Freedom = %lf\n", degreesFreedom);
        printf("CI Denom = %lf\n", (double) ciDenom);
        printf("Var CI Width = %lf\n", varCIWidth);
        printf("CI Sze = %lf\n", ciSize);
        printf("Var CI Size = %lf\n", varCISize);

	//print also the znbar
        // David Love -- Clearing out printed information
	// printf("\nznbar values:\n"); 
	// printf ("-----------------\n\n"); 
	// printf ("k:         znstar:\n"); 
	// for(kk=0; kk<numBatches*numCIs; kk++){
		// printf ("%d \t %f\n", kk+1, znstar[kk]);
	// }
        // David Love -- Some debugging code
        //printf( "Vales of mn\n" );
        //for( kk = 0; kk < numCIs; kk++ ) {
           //for( oo = 0; oo < numBatches; oo++ ) {
              //printf("%lf ", gapValues[kk][oo]);
           //}
           //printf("\n");
        //}
        //printf( "Variance Information\n" );
        //for( kk = 0; kk < numCIs; kk++ ) {
           //printf( "%lf\n", var[kk] );
        //}
	

	delete var; delete gbar; delete ci;
	var = NULL; gbar = NULL; ci = NULL;

        // David Love -- Clean up memory
        delete [] indivGaps;
        delete [] indivCounts;

        delete [] batchScenarios;

//****************************************************************************************
} // end of run