コード例 #1
0
/*
* Routine: void EvalTextExpr(expr_t *pExpr)
* Purpose: set the values to be used to replace a given tag for this query generation
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
*/
int 
EvalTextExpr(expr_t *pExpr, Expr_Val_t *pBuf, Expr_Val_t *pParams, int bIsParam)
{
	int i,
		nWeightTotal = 0,
		nModifierArg;
	expr_t *pReplacement;
	
	switch (pExpr->nFlags & (EXPR_FL_LIST | EXPR_FL_RANGE))
	{
	case EXPR_FL_LIST:	/* return a set of values */
		if (bIsParam)
			ReportError(QERR_MODIFIED_PARAM, NULL, 1);
		nModifierArg = (int)pParams[1].nValue;
		pExpr->pPermute = makePermutation(pExpr->pPermute, length(pExpr->ArgList) - 1, 0);
		for (i=0; i < nModifierArg; i++)
		{
			pReplacement = getItem(pExpr->ArgList, getPermutationEntry(pExpr->pPermute, i + 1));
			AddBuffer(pBuf[i].pBuf, GetBuffer(pReplacement->Value.pBuf));
			pBuf[i].bUseInt = 0;
		}
		break;
	case EXPR_FL_RANGE:
	case EXPR_FL_RANGE|EXPR_FL_LIST: /* only list() is permissible here */
		ReportError(QERR_RANGE_LIST, NULL, 1);
		break;
	default:
		/* 1. find a substitution from the weighted distribtuion */
		for (pReplacement = (expr_t *)getHead(pExpr->ArgList); 
		pReplacement; 
		pReplacement = (expr_t *)getNext(pExpr->ArgList))
			nWeightTotal += (int)pReplacement->Value.nValue;
		i = genrand_integer(NULL, DIST_UNIFORM, 1, nWeightTotal, 0, 0);
		for (pReplacement = (expr_t *)getHead(pExpr->ArgList); 
		pReplacement; 
		pReplacement = (expr_t *)getNext(pExpr->ArgList))
		{
			if (i <= (int)pReplacement->Value.nValue)
				break;
			i -= (int)pReplacement->Value.nValue;
		}
		
		/* 2. get the appropraite string */
		AddBuffer(pBuf->pBuf, GetBuffer(pReplacement->Value.pBuf));
		break;
	}
	
	return(DT_STR);
}
コード例 #2
0
int main( int argc, char** argv ) 
{ int i, *inputPermutation, *permutation, total_permutations=1;
  processArgs(argc,argv);
  //output first line of output
  for (i=1;i<=NUM_PACKETS;i++) total_permutations *= i;
  printf("%d %d %d // numNodes(or hops) numPackets numSuccessfulRuns(or data sets)\n",1,NUM_PACKETS,total_permutations);
  inputPermutation = (int*)malloc(sizeof(int)*NUM_PACKETS); 
  permutation = (int*)malloc(sizeof(int)*NUM_PACKETS); 
  /* init */
  for (i=0;i<NUM_PACKETS;i++)
      inputPermutation[i] = i;  // init initial permutation in perfect order
  /* initial call to permute items */ 
  makePermutation(permutation, 0, inputPermutation); 
  return EXIT_SUCCESS;
}
コード例 #3
0
// recursively creates permutation ina systematic way - when the
// permutation is created, the function evaluates the it
void makePermutation ( int* permutation, int curr_size, int* choices )
{ int i;
  if ( NUM_PACKETS > curr_size )
  { for (i=0; i < NUM_PACKETS; i++) 
    { if ( MARKED != choices[i] )
      { permutation[curr_size++] = i; choices[i] = MARKED;
        makePermutation(permutation, curr_size, choices);
        choices[i] = i; curr_size--;}
    }
  } 
  else {
    printf("%d: ",SINGLE_NODE);
    print_array(permutation,NUM_PACKETS);  
  }
}
コード例 #4
0
ファイル: s_warehouse.c プロジェクト: LH-Datarocks/tpcds-kit
/*
* Routine: 
* Purpose: 
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int
mk_s_warehouse (void* row, ds_key_t index)
{
   static int bInit = 0;
   static int *pPermutation;
   ds_key_t kIndex;

   if (!bInit)
   {
      pPermutation = makePermutation(NULL, (int)getIDCount(WAREHOUSE), S_WRHS_ID);
      bInit = 1;
   }

   kIndex = getPermutationEntry(pPermutation, (int)index);
   mk_w_warehouse(NULL, kIndex);

   return(0);
}
コード例 #5
0
/*
* mk_store_sales
*/
static void
mk_master (void *row, ds_key_t index)
{
	struct W_STORE_SALES_TBL *r;
	static decimal_t dMin,
		dMax;
	static int bInit = 0,
		nMaxItemCount;
	static ds_key_t kNewDateIndex = 0;

	if (row == NULL)
		r = &g_w_store_sales;
	else
		r = row;

	if (!bInit)
	{
      strtodec (&dMin, "1.00");
      strtodec (&dMax, "100000.00");
		nMaxItemCount = 20;
		jDate = skipDays(STORE_SALES, &kNewDateIndex);
		pItemPermutation = makePermutation(NULL, nItemCount = (int)getIDCount(ITEM), SS_PERMUTATION);
		
		bInit = 1;
	}

	
   while (index > kNewDateIndex)	/* need to move to a new date */
   {
      jDate += 1;
      kNewDateIndex += dateScaling(STORE_SALES, jDate);
   }
		r->ss_sold_store_sk = mk_join (SS_SOLD_STORE_SK, STORE, 1);
		r->ss_sold_time_sk = mk_join (SS_SOLD_TIME_SK, TIME, 1);
		r->ss_sold_date_sk = mk_join (SS_SOLD_DATE_SK, DATE, 1);
		r->ss_sold_customer_sk = mk_join (SS_SOLD_CUSTOMER_SK, CUSTOMER, 1);
		r->ss_sold_cdemo_sk = mk_join (SS_SOLD_CDEMO_SK, CUSTOMER_DEMOGRAPHICS, 1);
		r->ss_sold_hdemo_sk = mk_join (SS_SOLD_HDEMO_SK, HOUSEHOLD_DEMOGRAPHICS, 1);
		r->ss_sold_addr_sk = mk_join (SS_SOLD_ADDR_SK, CUSTOMER_ADDRESS, 1);
		r->ss_ticket_number = index;
		genrand_integer(&nItemIndex, DIST_UNIFORM, 1, nItemCount, 0, SS_SOLD_ITEM_SK);

      return;
}
コード例 #6
0
int
vld_s_item(int nTable, ds_key_t kRow, int *Permutation)
{
   static int bInit = 0;
   static int *pPermutation;
   table_func_t *pTF = getTdefFunctionsByNumber(ITEM);

   if (!bInit)
   {
      pPermutation = makePermutation(NULL, (int)getIDCount(ITEM),
      S_ITEM_PERMUTE);
      bInit = 1;
   }

   memset(&g_OldValues, 0, sizeof(struct W_ITEM_TBL));
   pTF->validate(S_ITEM, kRow, pPermutation);

   return(0);
}
コード例 #7
0
ファイル: s_promotion.c プロジェクト: LH-Datarocks/tpcds-kit
/*
* Routine: 
* Purpose: 
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int
mk_s_promotion (void* row, ds_key_t index)
{
   static int bInit = 0;
   static int *pPermutation;
   ds_key_t kIndex;

   if (!bInit)
   {
      pPermutation = makePermutation(NULL, (int)getIDCount(PROMOTION), S_PROMOTION_ID);
      bInit = 1;
   }

   kIndex = getPermutationEntry(pPermutation, (int)index);
   mk_w_promotion(NULL, kIndex);
   row_stop(PROMOTION);

   return(0);
}
コード例 #8
0
/*
* Routine: 
* Purpose: 
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int
mk_s_item (void* row, ds_key_t index)
{
   static int bInit = 0;
   static int *pPermutation;
   ds_key_t kIndex;

   if (!bInit)
   {
      pPermutation = makePermutation(NULL, (int)getIDCount(ITEM),
      S_ITEM_PERMUTE);
      bInit = 1;
   }

   kIndex = getPermutationEntry(pPermutation, (int)index);
   mk_w_item(NULL, getSKFromID(kIndex, S_ITEM_ID));
   row_stop(ITEM);

   return(0);
}
コード例 #9
0
ファイル: s_promotion.c プロジェクト: LH-Datarocks/tpcds-kit
int
vld_s_promotion(int nTable, ds_key_t kRow, int *Permutation)
{
   static int bInit = 0;
   static int *pPermutation;
   ds_key_t kIndex;
   table_func_t *pTF = getTdefFunctionsByNumber(PROMOTION);

   if (!bInit)
   {
      pPermutation = 
         makePermutation(NULL, (int)getIDCount(PROMOTION), S_PROMOTION_ID);
      bInit = 1;
   }

   kIndex = getPermutationEntry(pPermutation, (int)kRow);

   row_skip(PROMOTION, kRow - 1);
	pTF->builder(NULL, kIndex);
   row_stop(PROMOTION);

	return(0);
}
コード例 #10
0
static void
mk_detail (void *row, int bPrint)
{
	static int *pItemPermutation,
		nItemCount,
		bInit = 0;
	struct W_WEB_SALES_TBL *r;
	int nShipLag,
		nTemp;
   struct W_WEB_RETURNS_TBL w_web_returns;
   tdef *pT = getSimpleTdefsByNumber(WEB_SALES);


	if (!bInit)
	{
		jDate = skipDays(WEB_SALES, &kNewDateIndex);
		pItemPermutation = makePermutation(NULL, nItemCount = (int)getIDCount(ITEM), WS_PERMUTATION);
		
		bInit = 1;
	}

	if (row == NULL)
		r = &g_w_web_sales;
	else
		r = row;

	nullSet(&pT->kNullBitMap, WS_NULLS);


      /* orders are shipped some number of days after they are ordered,
      * and not all lineitems ship at the same time
      */
      genrand_integer (&nShipLag, DIST_UNIFORM, 
         WS_MIN_SHIP_DELAY, WS_MAX_SHIP_DELAY, 0, WS_SHIP_DATE_SK);
      r->ws_ship_date_sk = r->ws_sold_date_sk + nShipLag;

      if (++nItemIndex > nItemCount)
         nItemIndex = 1;
      r->ws_item_sk = matchSCDSK(getPermutationEntry(pItemPermutation, nItemIndex), r->ws_sold_date_sk, ITEM);

      /* the web page needs to be valid for the sale date */
      r->ws_web_page_sk = mk_join (WS_WEB_PAGE_SK, WEB_PAGE, r->ws_sold_date_sk);
      r->ws_web_site_sk = mk_join (WS_WEB_SITE_SK, WEB_SITE, r->ws_sold_date_sk);

      r->ws_ship_mode_sk = mk_join (WS_SHIP_MODE_SK, SHIP_MODE, 1);
      r->ws_warehouse_sk = mk_join (WS_WAREHOUSE_SK, WAREHOUSE, 1);
      r->ws_promo_sk = mk_join (WS_PROMO_SK, PROMOTION, 1);
      set_pricing(WS_PRICING, &r->ws_pricing);

      /** 
      * having gone to the trouble to make the sale, now let's see if it gets returned
      */
      if (!is_set("FILTER") || is_set("_CHILD_ONLY")) {
          genrand_integer(&nTemp, DIST_UNIFORM, 0, 99, 0, WR_IS_RETURNED);
          if (nTemp < WR_RETURN_PCT)
          {
             mk_w_web_returns(&w_web_returns, 1);
             if (bPrint)
                 pr_w_web_returns(&w_web_returns);
          }
      }

      /**
      * now we print out the order and lineitem together as a single row
      */
      if (bPrint && (!is_set("FILTER") || !is_set("_CHILD_ONLY")))
		  pr_w_web_sales(NULL);

	  return;
}
コード例 #11
0
/*
* Routine: void EvalDateExpr(expr_t *pExpr, StringBuffer_t *pBuf)
* Purpose: set the values to be used to replace a given tag for this query generation
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: 
*/
int
EvalDateExpr(expr_t *pExpr, Expr_Val_t *pBuf, Expr_Val_t *pParams, int bIsParam)
{
	date_t dBegin,
		dEnd,
		dResult;
	int nDay,
		nDay2,
		nDistributionType,
		nModifierArg,
		i,
		*pPermute = NULL,
		nTotal = 0,
		nDirection;
	
	/* pull the parameters from pParams */
	strtodt(&dBegin, GetBuffer(pParams->pBuf));
	strtodt(&dEnd, GetBuffer(pParams[1].pBuf));
	nDistributionType = pParams[2].nValue;
	
	/* and then check to see if more are required */
	switch (pExpr->nFlags & (EXPR_FL_LIST | EXPR_FL_RANGE))
	{
	case EXPR_FL_LIST:	/* return a set of values */
		if (bIsParam)
			ReportError(QERR_MODIFIED_PARAM, NULL, 1);
		nModifierArg = pParams[3].nValue;
		i = dBegin.julian - dBegin.julian;
		if (nModifierArg > i)
		{
			nModifierArg = i;
			ReportError(QERR_RANGE_OVERRUN, NULL, 0);
			pPermute = makePermutation(pPermute, i, 0);
		}
		for (i=0; i < nModifierArg; i++)
		{
			jtodt(&dResult, dBegin.julian + getPermutationEntry(pPermute, i + 1) - 1);
			AddBuffer(pBuf[i].pBuf, dttostr(&dBegin));
		}
		free(pPermute);
		break;
	case EXPR_FL_RANGE:	/* return end points of a range */
		if (bIsParam)
			ReportError(QERR_MODIFIED_PARAM, NULL, 1);
		nModifierArg = pParams[3].nValue;
		
		for (i=dBegin.julian; i < dEnd.julian; i++)
			nTotal += getDateWeightFromJulian(i, nDistributionType);
		nTotal *= nModifierArg;
		nTotal /= 100;
		
		genrand_date(&dResult, nDistributionType, &dBegin, &dEnd, NULL, 0);
		nDay = dResult.julian;
		nDay2 = nDay;
		
		nDirection = 1;
		while (nTotal > 0)
		{
			if (nDirection == 1)
			{
				nDay2 += 1;
				nTotal -= getDateWeightFromJulian(nDay2, nDistributionType);
				if (nDay2 == dEnd.julian)
					nDirection = -1;
			}
			else
			{
				nDay -= 1;
				nTotal -= getDateWeightFromJulian(nDay, nDistributionType);
			}
		}
		
		jtodt(&dResult, nDay);
		AddBuffer(pBuf->pBuf, dttostr(&dResult));
		jtodt(&dResult, nDay2);
		AddBuffer(pBuf[1].pBuf , dttostr(&dResult));
		break;
	case EXPR_FL_RANGE|EXPR_FL_LIST:	/* cannot use them both */
		ReportError(QERR_RANGE_LIST, NULL, 1);
		break;
	default:
		/* just do "normal" random date with a single return value */
		genrand_date(&dResult, nDistributionType, &dBegin, &dEnd, NULL, 0);
		AddBuffer(pBuf->pBuf, dttostr(&dResult));
		pBuf->bUseInt = 0;
		break;
	}
	
	
	return(DT_DATE);
}
コード例 #12
0
/*
* Routine: EvalDistopExpr(expr_t *pExpr, StringBuffer_t *pBuf);
* Purpose: set the values to be used to replace a given tag for this query generation
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: 
*/
int
EvalDistExpr(expr_t *pExpr, Expr_Val_t *pBuf, Expr_Val_t *pParams, int bIsParam)
{
	char *szName,
		*pChar = NULL;
	int nRow,
		nCol,
		nDataType,
		nOffset,
		nModifierArg,
		i,
      nTemp;
	
	szName = GetBuffer(pParams->pBuf);
	if (pParams[1].bUseInt)
		nRow = (int)pParams[1].nValue;
	else
		nRow = DistNameIndex(szName, VALUE_NAME, GetBuffer(pParams[1].pBuf));
	if (pParams[2].bUseInt)
		nCol = (int)pParams[2].nValue;
	else
		nCol = DistNameIndex(szName, WEIGHT_NAME, GetBuffer(pParams[2].pBuf));
	
	switch(pExpr->Value.nValue)
	{
	case KW_DISTMEMBER:
		nDataType = 
			(dist_type(szName, nCol) == TKN_INT)?DT_INT:DT_STR;
		if (nDataType == DT_STR)
		{
			dist_member(&pChar, szName, nRow, nCol);
			AddBuffer(pBuf->pBuf, pChar);
		}
		else
		{
			dist_member(&nTemp, szName, nRow, nCol);
         pBuf->nValue = nTemp;
			pBuf->bUseInt = 1;
		}
		break;
	case KW_DISTWEIGHT:	
		dist_weight(&nTemp, szName, nRow, nCol);
      pBuf->nValue = nTemp;
		pBuf->bUseInt = 1;
		nDataType = DT_INT;
		break;
	default:	/* regular call to DIST() */
		nDataType =	(dist_type(szName, nRow) == TKN_INT)?DT_INT:DT_STR;
		switch (pExpr->nFlags & (EXPR_FL_RANGE | EXPR_FL_LIST))
		{
		case EXPR_FL_RANGE:
			if (bIsParam)
				ReportError(QERR_MODIFIED_PARAM, NULL, 1);
			nModifierArg = (int)pParams[3].nValue;
			i = pick_distribution(NULL, szName, nRow, nCol, 0);
			nOffset = IntegrateDist(szName, nModifierArg, i, nCol);
			if (nDataType == DT_INT)
			{
				pBuf->bUseInt = 1;
				dist_member(&nTemp, szName, i, nRow);
            pBuf->nValue = nTemp;
				dist_member(&nTemp, szName, nOffset, nRow);
            pBuf[1].nValue = nTemp;
			}
			else
			{
				dist_member(pChar, szName, i, nRow);
				AddBuffer(pBuf->pBuf, pChar);
				dist_member(pChar, szName, nOffset, nRow);
				AddBuffer(pBuf[1].pBuf, pChar);
			}
			break;
		case EXPR_FL_LIST:
			if (bIsParam)
				ReportError(QERR_MODIFIED_PARAM, NULL, 1);
			nModifierArg = (int)pParams[3].nValue;
			
			/* permute it */
			if (nModifierArg > distsize(szName))
				ReportError(QERR_RANGE_ERROR, "", 1);
			if (!(pExpr->pPermute = makePermutation(pExpr->pPermute, distsize(szName), 0)))
				ReportError(QERR_RANGE_ERROR, NULL, 1);
			
			/* take the first n entries */
			for (i=1; i <= nModifierArg; i++)
			{
				if (nDataType == DT_INT)
				{
					pBuf[i - 1].bUseInt = 1;
					dist_member(&pBuf[i - 1].nValue, szName, getPermutationEntry(pExpr->pPermute, i), nRow);
				}
				else
				{
					dist_member(&pChar, szName, getPermutationEntry(pExpr->pPermute, i), nRow);
					AddBuffer(pBuf[i - 1].pBuf, pChar);
				}
			}
			break;
		case EXPR_FL_LIST | EXPR_FL_RANGE:
			ReportError(QERR_RANGE_LIST, NULL, 1);
			break;
		default:
			if (nDataType == DT_STR)
			{
				pick_distribution(&pChar, szName, nRow, nCol, 0);
				AddBuffer(pBuf->pBuf, pChar);
			}
			else
			{
				pick_distribution(&nTemp,  szName, nRow, nCol, 0);
				pBuf->nValue = nTemp;
				pBuf->bUseInt = 1;
			}
			break;
		}	/* end of generic DIST() switch case */
		break;
	}
	
	return(nDataType);
}
コード例 #13
0
double treeOptimizeRapid(tree *tr, int mintrav, int maxtrav, analdef *adef, bestlist *bt)
{
  int i, index,
    *perm = (int*)NULL;   

  nodeRectifier(tr);

  if (maxtrav > tr->ntips - 3)  
    maxtrav = tr->ntips - 3;  
    
  resetInfoList();
  
  resetBestTree(bt);
 
  tr->startLH = tr->endLH = tr->likelihood;
 
  if(tr->doCutoff)
    {
      if(tr->bigCutoff)
	{	  
	  if(tr->itCount == 0)    
	    tr->lhCutoff = 0.5 * (tr->likelihood / -1000.0);    
	  else    		 
	    tr->lhCutoff = 0.5 * ((tr->lhAVG) / ((double)(tr->lhDEC))); 	  
	}
      else
	{
	  if(tr->itCount == 0)    
	    tr->lhCutoff = tr->likelihood / -1000.0;    
	  else    		 
	    tr->lhCutoff = (tr->lhAVG) / ((double)(tr->lhDEC));   
	}    

      tr->itCount = tr->itCount + 1;
      tr->lhAVG = 0;
      tr->lhDEC = 0;
    }
  
  if(adef->permuteTreeoptimize)
    {
      int n = tr->mxtips + tr->mxtips - 2;   
      perm = (int *)rax_malloc(sizeof(int) * (n + 1));
      makePermutation(perm, n, adef);
    }

  for(i = 1; i <= tr->mxtips + tr->mxtips - 2; i++)
    {           
      tr->bestOfNode = unlikely;          

      if(adef->permuteTreeoptimize)
	index = perm[i];
      else
	index = i;
      


      if(rearrangeBIG(tr, tr->nodep[index], mintrav, maxtrav))
	{    
	  if(Thorough)
	    {
	      if(tr->endLH > tr->startLH)                 	
		{			   	     
		  restoreTreeFast(tr);	 	 
		  tr->startLH = tr->endLH = tr->likelihood;	 
		  saveBestTree(bt, tr);
		}
	      else
		{ 		  
		  if(tr->bestOfNode != unlikely)		    	     
		    restoreTopologyOnly(tr, bt);		    
		}	   
	    }
	  else
	    {
	      insertInfoList(tr->nodep[index], tr->bestOfNode);	    
	      if(tr->endLH > tr->startLH)                 	
		{		      
		  restoreTreeFast(tr);	  	      
		  tr->startLH = tr->endLH = tr->likelihood;	  	 	  	  	  	  	  	  
		}	    	  
	    }
	}     
    }     

  if(!Thorough)
    {           
      Thorough = 1;  
      
      for(i = 0; i < iList.valid; i++)
	{ 
	  

	  tr->bestOfNode = unlikely;
	  
	  if(rearrangeBIG(tr, iList.list[i].node, mintrav, maxtrav))
	    {	  
	      if(tr->endLH > tr->startLH)                 	
		{	 	     
		  restoreTreeFast(tr);	 	 
		  tr->startLH = tr->endLH = tr->likelihood;	 
		  saveBestTree(bt, tr);
		}
	      else
		{ 
	      
		  if(tr->bestOfNode != unlikely)
		    {	     
		      restoreTopologyOnly(tr, bt);
		    }	
		}      
	    }
	}       
          
      Thorough = 0;
    }

  if(adef->permuteTreeoptimize)
    rax_free(perm);

  return tr->startLH;     
}
コード例 #14
0
int determineRearrangementSetting(tree *tr,  analdef *adef, bestlist *bestT, bestlist *bt)
{
  int i, mintrav, maxtrav, bestTrav, impr, index, MaxFast,
    *perm = (int*)NULL;
  double startLH; 
  boolean cutoff;  

  MaxFast = 26;

  startLH = tr->likelihood;

  cutoff = tr->doCutoff;
  tr->doCutoff = FALSE;
 
    
  mintrav = 1;
  maxtrav = 5;

  bestTrav = maxtrav = 5;

  impr = 1;

  resetBestTree(bt);

  if(adef->permuteTreeoptimize)
    {
      int n = tr->mxtips + tr->mxtips - 2;   
      perm = (int *)rax_malloc(sizeof(int) * (n + 1));
      makePermutation(perm, n, adef);
    }
  

  while(impr && maxtrav < MaxFast)
    {	
      recallBestTree(bestT, 1, tr);     
      nodeRectifier(tr);
     
      
      if (maxtrav > tr->ntips - 3)  
	maxtrav = tr->ntips - 3;    
 
      tr->startLH = tr->endLH = tr->likelihood;
          
      for(i = 1; i <= tr->mxtips + tr->mxtips - 2; i++)
	{                



	  if(adef->permuteTreeoptimize)
	    index = perm[i];
	  else
	    index = i;	 	 

	  tr->bestOfNode = unlikely;
	  if(rearrangeBIG(tr, tr->nodep[index], mintrav, maxtrav))
	    {	     
	      if(tr->endLH > tr->startLH)                 	
		{		 	 	      
		  restoreTreeFast(tr);	        	  	 	  	      
		  tr->startLH = tr->endLH = tr->likelihood;	  	 	  	  	  	  	  	  	      
		}	         	       	
	    }
	}
      
      treeEvaluate(tr, 0.25);
      saveBestTree(bt, tr);                                    

      /*printf("DETERMINE_BEST: %d %f\n", maxtrav, tr->likelihood);*/

      if(tr->likelihood > startLH)
	{	 
	  startLH = tr->likelihood; 	  	  	  
	  printLog(tr, adef, FALSE);	  
	  bestTrav = maxtrav;	 
	  impr = 1;
	}
      else
	{
	  impr = 0;
	}
      maxtrav += 5;
      
      if(tr->doCutoff)
	{
	  tr->lhCutoff = (tr->lhAVG) / ((double)(tr->lhDEC));       
  
	  tr->itCount =  tr->itCount + 1;
	  tr->lhAVG = 0;
	  tr->lhDEC = 0;
	}
    }

  recallBestTree(bt, 1, tr);   
  tr->doCutoff = cutoff;

  if(adef->permuteTreeoptimize)
    rax_free(perm);

  
  return bestTrav;     
}
コード例 #15
0
/*
* Routine: 
* Purpose: 
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
void
generateQueryStreams(void)
{
	int nStream,
		nQuery,
		nQueryCount,
		*pPermutation = NULL,
		nVersionCount,
		nCount,
		nQID;
	FILE *pOutFile;
	FILE *pLogFile = NULL;
	char szPath[1024];

	nQueryCount = length(TemplateList);
	nVersionCount = get_int("COUNT");
	
	if (is_set("LOG"))
	{
#ifndef WIN32
		if ((pLogFile = fopen(get_str("LOG"), "w")) == NULL)
#else
		if ((pLogFile = fopen(get_str("LOG"), "wt")) == NULL)
#endif
		{
			SetErrorGlobals(get_str("LOG"), NULL);
			ReportErrorNoLine(QERR_OPEN_FAILED, get_str("LOG"), 1);
		}
	}

	for (nStream=0; nStream < get_int("STREAMS"); nStream++)
	{
		pPermutation = makePermutation(pPermutation, nQueryCount, 0);
	
		sprintf(szPath, "%s%squery_%d.sql",
			get_str("OUTPUT_DIR"),
			get_str("PATH_SEP"),
			nStream);
		if (!is_set("FILTER"))
		{
#ifndef WIN32
			if ((pOutFile = fopen(szPath, "w")) == NULL)
#else
				if ((pOutFile = fopen(szPath, "wt")) == NULL)
#endif
				{
					SetErrorGlobals(szPath, NULL);
					ReportErrorNoLine(QERR_OPEN_FAILED, szPath, 1);
				}
		}
		else
			pOutFile = stdout;

		g_nStreamNumber = nStream;
		if (pLogFile)
			fprintf(pLogFile, "BEGIN STREAM %d\n", nStream);
		for (nQuery = 1; nQuery <= nQueryCount; nQuery++)
		{
			for (nCount = 1; nCount <= nVersionCount; nCount++)
			{
			g_nQueryNumber = nQuery;
			if (is_set("QUALIFY"))
				nQID = nQuery;
			else
				nQID = getPermutationEntry(pPermutation, nQuery);
			GenerateQuery(pOutFile, pLogFile, nQID);
			if (pLogFile)
				fprintf(pLogFile, "\n");
			}
		}
		if (pLogFile)
			fprintf(pLogFile, "END STREAM %d\n", nStream);

		if (!is_set("FILTER"))
			fclose(pOutFile);
	}

	if (pLogFile)
		fclose(pLogFile);

	return;
}
コード例 #16
0
ファイル: s_customer.c プロジェクト: LH-Datarocks/tpcds-kit
/*
* Routine: 
* Purpose: 
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int
mk_s_customer (void *pDest, ds_key_t kIndex)
{
  static int bInit = 0;
  struct S_CUSTOMER_TBL *r;
  static date_t dtMin,
    dtMax, dtBirthMin, dtBirthMax, dtToday, dt1YearAgo, dt10YearsAgo;
  static decimal_t dMinIncome, dMaxIncome;
  int nTemp;
  ds_key_t kTempDemographic;
  char *szTemp;
  static int *pPermutation;

  if (pDest == NULL)
    r = &g_s_customer;
  else
    r = pDest;

  if (!bInit)
    {
      memset (&g_s_customer, 0, sizeof (struct S_CUSTOMER_TBL));
      setUpdateDateRange (S_CUSTOMER, &dtMin, &dtMax);
      strtodec (&dMinIncome, "0.00");
      strtodec (&dMaxIncome, "200000.00");
      r->pBirthCountry = strdup ("<UNKNOWN>");
      strtodt (&dtBirthMin, "1924-01-01");
      strtodt (&dtBirthMax, "1992-12-31");
      strtodt (&dtToday, TODAYS_DATE);
      jtodt (&dt1YearAgo, dtToday.julian - 365);
      jtodt (&dt10YearsAgo, dtToday.julian - 365);
      pPermutation =
	makePermutation (NULL, (int) getIDCount (CUSTOMER), S_CUST_ID);

      bInit = 1;
    }

  r->kID = getPermutationEntry (pPermutation, (int) kIndex);
  kTempDemographic = mk_join (S_CUST_GENDER, CUSTOMER_DEMOGRAPHICS, 1) - 1;
  bitmap_to_dist (&szTemp, "gender", &kTempDemographic, 1,
		  CUSTOMER_DEMOGRAPHICS);
  switch (*szTemp)
    {
    case 'M':			/* male */
      r->sGender[0] = 'M';
      pick_distribution (&r->pFirstName, "first_names", 1, 1,
			 S_CUST_FIRST_NAME);
      pick_distribution (&r->pSalutation, "salutations", 1, 2,
			 S_CUST_SALUTATION);
      break;
    case 'F':			/* female */
      r->sGender[0] = 'F';
      pick_distribution (&r->pFirstName, "first_names", 1, 2,
			 S_CUST_FIRST_NAME);
      pick_distribution (&r->pSalutation, "salutations", 1, 3,
			 S_CUST_SALUTATION);
      break;
    default:			/* gender neutral */
      r->sGender[0] = 'U';
      pick_distribution (&r->pFirstName, "first_names", 1, 3,
			 S_CUST_FIRST_NAME);
      pick_distribution (&r->pSalutation, "salutations", 1, 1,
			 S_CUST_SALUTATION);
      break;
    }
  bitmap_to_dist (&r->pMaritalStatus, "marital_status", &kTempDemographic, 1,
		  CUSTOMER_DEMOGRAPHICS);
  bitmap_to_dist (&r->pEducation, "education", &kTempDemographic, 1,
		  CUSTOMER_DEMOGRAPHICS);
  bitmap_to_dist (&r->nPurchaseEstimate, "purchase_band", &kTempDemographic,
		  1, CUSTOMER_DEMOGRAPHICS);
  bitmap_to_dist (&r->pCreditRating, "credit_rating", &kTempDemographic, 1,
		  CUSTOMER_DEMOGRAPHICS);
  r->nDependents = (int) (kTempDemographic % (ds_key_t) CD_MAX_CHILDREN);
  kTempDemographic /= (ds_key_t) CD_MAX_CHILDREN;
  r->nEmployed = (int) (kTempDemographic % (ds_key_t) CD_MAX_EMPLOYED);
  kTempDemographic /= (ds_key_t) CD_MAX_EMPLOYED;
  r->nCollege = (int) (kTempDemographic % (ds_key_t) CD_MAX_COLLEGE);

  pick_distribution (&r->pLastName, "last_names", 1, 1, S_CUST_LAST_NAME);
  r->bPreferredFlag =
    (genrand_integer (NULL, DIST_UNIFORM, 1, 100, 0, S_CUST_PREFERRED_FLAG) >
     50) ? 1 : 0;
  genrand_date (&r->dtBirthDate, DIST_UNIFORM, &dtBirthMin, &dtBirthMax, NULL,
		S_CUST_BIRTH_DATE);
  genrand_date (&r->dtFirstPurchaseDate, DIST_UNIFORM, &dt10YearsAgo,
		&dt1YearAgo, NULL, S_CUST_FIRST_PURCHASE_DATE);
  genrand_integer (&nTemp, DIST_UNIFORM, 1, 30, 0, S_CUST_FIRST_SHIPTO_DATE);
  jtodt (&r->dtFirstShipToDate, r->dtFirstPurchaseDate.julian + nTemp);
  gen_charset (r->szLogin, ALPHANUM, 5, RS_S_CUST_LOGIN, S_CUST_LOGIN);
  genrand_email (r->szEmail, r->pFirstName, r->pLastName, S_CUST_EMAIL);
  genrand_date (&r->dtLastLogin, DIST_UNIFORM, &dt1YearAgo, &dtToday, NULL,
		S_CUST_LAST_LOGIN);
  genrand_date (&r->dtReview, DIST_UNIFORM, &dt1YearAgo, &dtToday, NULL,
		S_CUST_LAST_REVIEW);
  genrand_ipaddr (r->szPrimaryMachine, S_CUST_PRIMARY_MACHINE);
  genrand_ipaddr (r->szSecondaryMachine, S_CUST_SECONDARY_MACHINE);
  pick_distribution (&r->pLocationType, "location_type", 1, 1,
		     S_CUST_LOCATION_TYPE);
  pick_distribution (&r->nVehicle, "vehicle_count", 1, 1, S_CUST_VEHICLE_CNT);
  genrand_decimal (&r->dIncome, DIST_UNIFORM, &dMinIncome, &dMaxIncome, NULL,
		   S_CUST_INCOME);
  pick_distribution (&r->pBuyPotential, "buy_potential", 1, 1,
		     S_CUST_PURCHASE_ESTIMATE);
  mk_w_customer_address (NULL, kIndex);

  return (0);
}
コード例 #17
0
/*
* Routine: int EvalRandomExpr(expr_t *pExpr, Expr_Val_t *pBuf, Expr_Val_t *pParams, int bIsParam)
* Purpose: set the values to be used to replace a given tag for this query generation
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: 
*/
int
EvalRandomExpr(expr_t *pExpr, Expr_Val_t *pBuf, Expr_Val_t *pParams, int bIsParam)
{
	int nMin,
		nMax,
		nModifierArg,
		i,
		nDirection,
		nTotal,
		nDistribution,
      nTemp;
	
	nMin = (int)pParams->nValue;
	nMax = (int)pParams[1].nValue;
	nDistribution = (int)pParams[2].nValue;
	
	switch (pExpr->nFlags & (EXPR_FL_LIST | EXPR_FL_RANGE))
	{
	case EXPR_FL_LIST:	/* return a set of values */
		if (bIsParam)
			ReportError(QERR_MODIFIED_PARAM, NULL, 1);
		nModifierArg = (int)pParams[3].nValue;
		pExpr->pPermute = makePermutation(pExpr->pPermute, nMax - nMin + 1, 0);
      /* 
       * the permutation is controlled by the number of values that are needed
       * once it is populated, than adjust the returned result based on the range of values that is permissible
       */
		for (i = 0; i < nModifierArg; i++)
		{
			pBuf[i].nValue = (getPermutationEntry(pExpr->pPermute, i + 1) % (nMax - nMin + 1)) + nMin;
			pBuf[i].bUseInt = 1;
		}
		break;
	case EXPR_FL_RANGE:	/* return end points of a range */
		if (bIsParam)
			ReportError(QERR_MODIFIED_PARAM, NULL, 1);
		nModifierArg = (int)pParams[3].nValue;
		
		genrand_integer(&nTemp, DIST_UNIFORM, nMin, nMax, nDistribution, 0);
      pBuf->nValue = nTemp;
		pBuf->bUseInt = 1;
		pBuf[1].nValue = pBuf->nValue;
		pBuf[1].bUseInt = 1;
		
		nDirection = 1;
		nTotal = nMax - nMin;
		nTotal *= nModifierArg;
		nTotal /= 100;
		
		while (nTotal)
		{
			if (nDirection == 1)
			{
				pBuf[1].nValue += 1;
				nTotal -= 1;
				if ((int)pBuf[1].nValue == nMax)
					nDirection = -1;
			}
			else
			{
				pBuf->nValue -= 1;
				nTotal -= 1;
			}
		}
		break;
	case EXPR_FL_RANGE|EXPR_FL_LIST:	/* cannot use them both */
		ReportError(QERR_RANGE_LIST, NULL, 1);
		break;
	default:
		genrand_integer(&nTemp, DIST_UNIFORM, nMin, nMax, nDistribution, 0);
      pBuf->nValue = nTemp;
		pBuf->bUseInt = 1;
		break;
	}
	
	
	return(DT_INT);
}