示例#1
0
/*
**	Reset each relation until limit.
**	Reset will remove all tuples from the
**	relation but not destroy the relation.
**	The descriptor for the relation will be removed
**	from the cache.
**
**	The original relation is returned to
**	the range table.
**
**	If limit is -1 then all relations are done.
*/
void
reset_sq(qtree_t **sqlist, int *locrang, int limit)
{
	register qtree_t	*sq;
	register int	i, lim;
	int		old, reset;

	lim = limit == -1 ? MAX_RANGES : limit;
	reset = FALSE;
	initp();

	for (i = 0; i < lim; i++)
		if ((sq = sqlist[i]) && sq->left->sym.type != TREE) {
			old = new_range(i, locrang[i]);
			setp(PV_STR, rnum_convert(old), 0);
			specclose(old);
			reset = TRUE;
		}

	if (reset) {
		/*
		** Guarantee that OVQP will not reuse old
		** page of relation being reset
		*/
		De.de_newr = TRUE;
		call_dbu(mdRESETREL, FALSE);
	}
	else
		resetp();
}
/*
**	Check the range table to see if any
**	relations changed since the last call
**	to newquery. If so, they were caused
**	by reformat. Restore back the orig relation
**	Reopen it if reopen == TRUE.
*/
void
endquery(int *locrang, int reopen)
{
	register struct rang_tab	*rp;
	register int			*ip, i;
	int				old;
	bool				dstr_flag;

	rp = De.de_rangev;
	ip = locrang;

	dstr_flag = FALSE;
	initp();
	for (i = 0; i < MAX_RANGES; i++) {
		if (rp->relnum != *ip) {
#ifdef xDTR1
			if (tTf(63, -1))
			printf("reformat or reduct changed var %d (%d,%d)\n", i, *ip, rp->relnum);
#endif

			old = new_range(i, *ip);
			dstr_flag |= dstr_mark(old);
			if (reopen)
				openr1(i);
		}

		ip++;
		rp++;
	}

	if (dstr_flag)
		call_dbu(mdDESTROY, FALSE);
	else
		resetp();
}
示例#3
0
void initialize_modules(struct module_stub *list[])
{
	void (* initp)(void);
	struct module_stub **stubp;

	stubp = list;
	while (*stubp) {
		initp = (*stubp)->init;
		if (initp != 0)
			(void)initp();
		stubp++;
	}
}
示例#4
0
/*
**  UNDO_SQ
**
**	Undo the effects of one variable detachment on
**	the range table. The two parameters "limit" and
**	"maxlimit" describe how far down the list of
**	subqueries were processed.  Maxlimit represents
**	the furthest every attained and limit represents
**	the last variable processed the last time.
**
**	Trace Flags:
**		36
*/
void
undo_sq(qtree_t **sqlist, int *locrang, int *sqrange, int limit, int maxlimit, int reopen)
{
	register qtree_t	*sq;
	register int	i, lim;
	bool		dstr_flag;

	dstr_flag = 0;
#ifdef xDTR1
	if (tTf(36, 0))
		printf("UNDO_SQ--\n");
#endif

	initp();	/* setup parm vector for destroys */
	lim = limit == -1 ? MAX_RANGES : limit;
	if (maxlimit == -1)
		maxlimit = MAX_RANGES;

	for (i = 0; i < MAX_RANGES; i++)
		if ((sq = sqlist[i]) != 0) {
			if (sq->left->sym.type != TREE) {
				if (i < lim) {
					/* The query was run. Close the temp rel */
					closer1(i);
				}

				/* mark the temporary to be destroyed */
				dstr_mark(sqrange[i]);
				dstr_flag = TRUE;

				/* reopen the original relation. If maxlimit
				** never reached the variable "i" then the
				** original relation was never closed and thus
				** doesn't need to be reopened.
				*/
				rstrang(locrang, i);
				if (reopen && i < maxlimit)
					openr1(i);
			}
		}
	/* Only call destroy if there's something to destroy */
	if (dstr_flag)
		call_dbu(mdDESTROY, FALSE);
	else
		resetp();

}
示例#5
0
qryproc()
{
	register QTREE			*root;
	register QTREE			*q;
	register int			i;
	register int			mode;
	register int			result_num;
	register int			retr_uniq;
	extern long			AAccuread;
	extern long			AAccuwrite;
	extern long			AAccusread;
	extern int			derror();
	extern QTREE			*trbuild();
	extern QTREE			*readqry();

#	ifdef xDTM
	if (AAtTf(76, 1))
		timtrace(23, 0);
#	endif
#	ifdef xDTR1
	if (AAtTf(50, 0))
		AAccuread = AAccusread = AAccuwrite = 0;
#	endif

	/* initialize query buffer */
	initbuf(Qbuf, QBUFSIZ, QBUFFULL, derror);

	/* init various variables in decomp for start of this query */
	startdecomp();

	/* Read in query, range table and mode */
	root = readqry();
	mode = Qmode;

	/* Initialize relation descriptors */
	initdesc(mode);

	/* re-build the tree */
	root = trbuild(root);
	if (!root)
		derror(STACKFULL);


	/* locate pointers to QLEND and TREE nodes */
	for (q = root->right; q->sym.type != QLEND; q = q->right)
		continue;
	Qle = q;

	for (q = root->left; q->sym.type != TREE; q = q->left)
		continue;
	Tr = q;


	/* map the complete tree */
	mapvar(root, 0);

	/* set logical locks */
	lockit(root, Resultvar);

	/* If there is no result variable then this must be a retrieve to the terminal */
	Qry_mode = Resultvar < 0 ? (int) mdRETTERM : mode;

	/* if the mode is retrieve_unique, then make a result rel */
	retr_uniq = mode == (int) mdRET_UNI;
	if (retr_uniq)
	{
		mk_unique(root);
		mode = (int) mdRETR;
	}

	/* get id of result relation */
	if (Resultvar < 0)
		result_num = NORESULT;
	else
		result_num = Rangev[Resultvar].relnum;

	/* evaluate aggregates in query */
	aggregate(root);

	/* decompose and process aggregate free query */
	decomp(root, mode, result_num);

	/* If this is a retrieve unique, then retrieve results */
	if (retr_uniq)
		pr_unique(root, Resultvar);

	if (mode != (int) mdRETR)
		i = ACK;
	else
		i = NOACK;
	i = endovqp(i);

	/* call update processor if batch mode */
	if (i == UPDATE)
	{
		initp();
		call_dbu(mdUPDATE, -1);
	}


	/*
	** send eop back to parser to indicate completion
	** if UPDATE then return block comes from dbu else
	** return block comes from decomp
	*/
	writeback(i == UPDATE ? -1 : 1);

#	ifdef xDTM
	if(AAtTf(76, 1))
		timtrace(24, 0);
#	endif
#	ifdef xDTR1
	AAtTfp(50, 1, "DECOMP read %ld pages,%ld catalog pages,wrote %ld pages\n",
		AAccuread, AAccusread, AAccuwrite);
#	endif

	/* clean decomp */
	reinit();

	/* return */
}
示例#6
0
文件: main.cpp 项目: CCJY/coliru
int main(int argc, char **argv) {
    time_t t;
    /* Intializes random number generator */
   srand((unsigned) time(&t));
	char **population; //include every parent that is about to have childen
	int length = LENGTH;
	int max_population = PSIZE;
	double mutation_rate = MUTAION_RATE;
	int i;
	population = (char **) malloc(max_population * sizeof(char *));
	for (i = 0; i < max_population; i++) {
		population[i] = (char *) malloc(length * sizeof(char));
	}
//	puts("init..");
	initp(population);
//	print_population(population);
	int total_fitness = totalFitness(population);
	printf("total fitness: %d\n", total_fitness);

	double p_crossover = (double) 0.5; //this determines the crossover point in chrom
	int generation = 0;
	int limit = LENGTH * max_population;
	while (total_fitness < limit) {
		generation++;
		for (i = 0; i < max_population; i++) {
			char *child = crossover(population, p_crossover);
			mutate(child, mutation_rate);
			//printf("child: %s\n", child);
			population[i] = child;
		}
		printf("after %d generation\n", generation);
	//	print_population(population);
		total_fitness = totalFitness(population);
		printf("total fitness: %d\n", total_fitness);
	}

	//long long type can represent upto 20 bits of 1 and 0,
	//chroms longer than 20bits will be splited to array of long long numbers

	/*char chrom1[] = "10101010001101011";
	 char chrom2[] = "11010000110010010";
	 int length = sizeof(chrom1)-1;

	 double crossover = (double)0.5; //this determines the crossover point in chrom

	 //generate mask for crossover
	 char *mask1 = (char *) malloc(length*sizeof(char));
	 char *mask2 = (char *) malloc(length*sizeof(char));
	 generate_mask(mask1, mask2, length, crossover);
	 printf("input  1: %15s (%d) 2: %15s (%d) Length: %d\n", chrom1, fitness(chrom1,length), chrom2, fitness(chrom2, length), length);
	 printf("masks  1: %15s 2: %15s\n", mask1, mask2);
	 char *ptr1,*ptr2;

	 //convert the above 4 string values to decimal int following binary rule.
	 long long ret1 = strtoul(chrom1, &ptr1, 2);
	 long long ret2 = strtoul(chrom2, &ptr2, 2);
	 long long m1 = strtoul(mask1, &ptr1, 2);
	 long long m2 = strtoul(mask2, &ptr2, 2);

	 //crossover operation
	 long long ichild1 = (ret1 & m2) ^ (ret2 & m1);
	 long long ichild2 = (ret1 & m1) ^ (ret2 & m2);
	 //convert binary format childern to string, in order to add them to parent pool.
	 char *child1 = (char *)malloc(length * sizeof(char));
	 char *child2 = (char *)malloc(length * sizeof(char));
	 sprintf(child1,"%lld",int_to_binary(ichild1));
	 sprintf(child2,"%lld",int_to_binary(ichild2));

	 printf("child 1: %18s 2: %s",child1,child2);
	 */

	return 0;
}