Exemple #1
0
void MyWindow::reorderMarkers()
{

	//based on the assumption that only one marker can be occuluded.
	int numMarkers = static_cast<int>(mMarkerPos.size());
	vector<vector<int> > candidateLabels = GetPermutation(0, numMarkers);
	int numCandidates = static_cast<int>(candidateLabels.size());
	vector<double> candidateDistances;
	candidateDistances.resize(numCandidates);
	vector<vector<double> > currentMarkerDistance = computeMarkerDistances();
	for (int i = 0; i < numCandidates; ++i)
	{
		candidateDistances[i] = computeDistanceOfMarkerDistances(candidateLabels[i], currentMarkerDistance);
	}
	vector<double>::const_iterator labelIt = std::min_element(candidateDistances.begin(), candidateDistances.end());
	vector<int> newLabel = candidateLabels[labelIt - candidateDistances.begin()];

	vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > orderedMarkerPos;
	orderedMarkerPos.resize(numMarkers);
	vector<int> orderedMarkerOcculuded;
	orderedMarkerOcculuded.resize(numMarkers);

	for (int i = 0; i < numMarkers; ++i)
	{
		if (i != newLabel[i])
			LOG(WARNING) << "The markers are relabeled.";
		orderedMarkerPos[newLabel[i]] = mMarkerPos[i];
		orderedMarkerOcculuded[newLabel[i]] = mMarkerOccluded[i];


	}
	mMarkerPos = orderedMarkerPos;
	mMarkerOccluded = orderedMarkerOcculuded;
}
int main() {
    for (int i = 1; i <= 30; i++)
        std::cout << "The " << i << "th permutation of 4 is " << GetPermutation(4, i) << std::endl;
    return 0;
}
Exemple #3
0
/*
 *  Loads the Orders table 
 *  Also loads the Order_Line table on the fly 
 *
 *  w_id - warehouse id 
 *  d_id - district id
 */
int
Orders(long d_id, long w_id)
{

    long    o_id;
    long    o_c_id;
    long    o_d_id;
    long    o_w_id;
    long    o_carrier_id;
    long    o_ol_cnt;
    long    ol;
    long    ol_i_id;
    long    ol_supply_w_id;
    long    ol_quantity;
    long    ol_amount;
    char    ol_dist_info[25];
    float   i_price;
    float   c_discount;
    
    int     err;
    DBT     key, data;
    
    ORDER_PRIMARY_KEY     o_key;
    ORDER_PRIMARY_DATA    o_data;

    ORDERLINE_PRIMARY_KEY  ol_key;
    ORDERLINE_PRIMARY_DATA ol_data;

    NEWORDER_PRIMARY_KEY   no_key;


    printf("Loading Orders for D=%ld, W= %ld\n", d_id, w_id);

    o_d_id=d_id;
    o_w_id=w_id;
    InitPermutation();           /* initialize permutation of customer numbers */


    for (o_id=1; o_id<=ORD_PER_DIST; o_id++) 
    {
	memset(&o_key, 0, sizeof(ORDER_PRIMARY_KEY));
	memset(&o_data, 0, sizeof(ORDER_PRIMARY_DATA));

	o_key.O_D_ID = o_d_id;
	o_key.O_W_ID = o_w_id;	
	o_key.O_ID = o_id;
	
	/* Generate Order Data */
	o_c_id = GetPermutation();
	o_carrier_id = random1(1L,10L); 
	o_ol_cnt=random1(5L,15L); 
  
	o_data.O_C_ID = o_c_id;
	o_data.O_ALL_LOCAL = 1;
	o_data.O_OL_CNT = o_ol_cnt;
	memcpy(&o_data.O_ENTRY_D, timestamp, 26);


	if (o_id > 2100)         /* the last 900 orders have not been delivered) */
	{
	    memset(&no_key, 0, sizeof(NEWORDER_PRIMARY_KEY));

	    o_data.O_CARRIER_ID = 0;
	    
	    memset(&key, 0, sizeof(DBT));
	    key.data = &o_key;
	    key.size = sizeof(ORDER_PRIMARY_KEY);

	    memset(&data, 0, sizeof(DBT));
	    data.data = &o_data;
	    data.size = sizeof(ORDER_PRIMARY_DATA);
	    
	    if((err=dbp_order->put(dbp_order, 0, &key, &data, 0)))
	    {
		db_error("DB->put", err);
		return -1;
	    }
	 
	    no_key.NO_O_ID = o_id;
	    no_key.NO_D_ID = o_d_id;
	    no_key.NO_W_ID = o_w_id;
	    
	    memset(&key, 0, sizeof(DBT));
	    key.data = &no_key;
	    key.size = sizeof(NEWORDER_PRIMARY_KEY);

	    memset(&data, 0, sizeof(DBT));
	    
	    if((err=dbp_neworder->put(dbp_neworder, 0, &key, &data, 0)))
	    {
		db_error("DB->put", err);
		return -1;
	    }
	}
	else
	{
	    o_data.O_CARRIER_ID = o_carrier_id;
        
	    memset(&key, 0, sizeof(DBT));
	    key.data = &o_key;
	    key.size = sizeof(ORDER_PRIMARY_KEY);

	    memset(&data, 0, sizeof(DBT));
	    data.data = &o_data;
	    data.size = sizeof(ORDER_PRIMARY_DATA);
	    
	    if((err=dbp_order->put(dbp_order, 0, &key, &data, 0)))
	    {
		db_error("DB->put", err);
		return -1;
	    }

	}

	if ( option_debug )
	    printf( "OID = %ld, CID = %ld, DID = %ld, WID = %ld\n",
		    o_id, o_c_id, o_d_id, o_w_id);
      
	for (ol=1; ol<=o_ol_cnt; ol++) 
	{
	    memset(&ol_key, 0, sizeof(ORDERLINE_PRIMARY_KEY));
	    memset(&ol_data, 0, sizeof(ORDERLINE_PRIMARY_DATA));

	    /* Generate Order Line Data */
	    ol_i_id=random1(1L,MAXITEMS); 
	    ol_supply_w_id=o_w_id; 
	    ol_quantity=5; 
	    ol_amount=0.0;

	    MakeAlphaString(24,24,ol_dist_info);

	    ol_key.OL_W_ID = o_w_id;
	    ol_key.OL_D_ID = o_d_id;
	    ol_key.OL_O_ID = o_id;
	    ol_key.OL_NUMBER = ol;

	    ol_data.OL_I_ID = ol_i_id;
	    ol_data.OL_SUPPLY_W_ID = o_w_id;
	    ol_data.OL_QUANTITY = ol_quantity;
	    memcpy(&ol_data.OL_DIST_INFO, &ol_dist_info, 25);

	    
	    if (o_id > 2100)
	    {
		ol_data.OL_AMOUNT = ol_amount;

		memset(&key, 0, sizeof(DBT));
		key.data = &ol_key;
		key.size = sizeof(ORDERLINE_PRIMARY_KEY);

		memset(&data, 0, sizeof(DBT));
		data.data = &ol_data;
		data.size = sizeof(ORDERLINE_PRIMARY_DATA);

		if((err=dbp_orderline->put(dbp_orderline, 0, &key, &data, 0)))
		{
		    db_error("DB->put", err);
		    return -1;
		}
	    }
	    else
	    {
		const int dt_size = 26;
		char datetime[dt_size];
		time_t t_clock;

		if((int)time(&t_clock) == -1)
		{
		    error("time");
		    exit(1);
		}
		ctime_r(&t_clock, (char*)datetime);


		ol_data.OL_AMOUNT =(float)(random1(10L, 10000L))/100.0; 
		memcpy(&ol_data.OL_DELIVERY_D, datetime, dt_size);
		
		memset(&key, 0, sizeof(DBT));
		key.data = &ol_key;
		key.size = sizeof(ORDERLINE_PRIMARY_KEY);

		memset(&data, 0, sizeof(DBT));
		data.data = &ol_data;
		data.size = sizeof(ORDERLINE_PRIMARY_DATA);

		if((err=dbp_orderline->put(dbp_orderline, 0, &key, &data, 0)))
		{
		    db_error("DB->put", err);
		    return -1;
		}
	    }

	    if ( option_debug )
		printf( "OL = %ld, IID = %ld, QUAN = %ld, AMT = %8.2f\n",
			ol, ol_i_id, ol_quantity, ol_data.OL_AMOUNT);

      }
	if ( !(o_id % 100) ) {
	    printf(".");
	    
	    if ( !(o_id % 1000) ) printf(" %ld\n",o_id);
	}
    }

    printf("Orders Done.\n");
    return 0;
}