Example #1
0
static AtlasNode *insert(RoadMapImage *image, AtlasNode *node) {
   
   int n_width = node->rect.maxx - node->rect.minx + 1;
   int n_height = node->rect.maxy - node->rect.miny + 1;
   int width = (*image)->width;
   int height = (*image)->height;
   int dw, dh;
   AtlasNode *new_node;
   
   
   if (node->child[0] != NULL && 
       node->child[1] != NULL) {
      new_node = insert(image, node->child[0]);
      if (new_node != NULL)
         return new_node;
      
      return insert(image, node->child[1]);
   }
   

   if (node->image != NULL)
      return NULL;
   
   if (height > n_height -1 ||
       width > n_width -1)
      return NULL;
   
   if (height == n_height -1 &&
       width == n_width -1)
      return node;
   
   node->child[0] = create_new_node();
   node->child[1] = create_new_node();
   
   dw = n_width - width;
   dh = n_height - height;
  
   if (dw > dh) {
      node->child[0]->rect.minx = node->rect.minx;
      node->child[0]->rect.miny = node->rect.miny;
      node->child[0]->rect.maxx = node->rect.minx + width;
      node->child[0]->rect.maxy = node->rect.maxy;
      node->child[1]->rect.minx = node->rect.minx + width +1;
      node->child[1]->rect.miny = node->rect.miny;
      node->child[1]->rect.maxx = node->rect.maxx;
      node->child[1]->rect.maxy = node->rect.maxy;
   } else {
      node->child[0]->rect.minx = node->rect.minx;
      node->child[0]->rect.miny = node->rect.miny;
      node->child[0]->rect.maxx = node->rect.maxx;
      node->child[0]->rect.maxy = node->rect.miny + height;
      node->child[1]->rect.minx = node->rect.minx;
      node->child[1]->rect.miny = node->rect.miny + height +1;
      node->child[1]->rect.maxx = node->rect.maxx;
      node->child[1]->rect.maxy = node->rect.maxy;
   }
  
   return insert(image, node->child[0]);
}
Example #2
0
void main()
{
int info,a,c;
struct node *np;
char ch;
start=NULL;
clrscr();
do
{
printf("ENTER YOUR CHOICE:\n");
printf("Enter 1 to insert at begining\n");
printf("Enter 2 to insert after a given element\n");
printf("Enter 3 to insert at end\n");
printf("Enter 4 to delete a particular element\n");
printf("Enter 5 to reverse the current linked list\n");
scanf("%d",&a);
if(a==1)
{
printf("Enter the element: \n");
scanf("%d",&info);
np=create_new_node(info);
insertbeg(np);
}
else if(a==2)
{
printf("Enter the element\n");
scanf("%d",&info);
np=create_new_node(info);
insertmid(np);
}
else if(a==3)
{
printf("Enter the element\n");
scanf("%d",&info);
np=create_new_node(info);
insertend(np);
}
else if(a==4)
{
printf("Enter the element\n");
scanf("%d",&info);
np=create_new_node(info);
del(info);
}
else if(a==5)
{
reverse(c);
}
display(start);
c=count(start);
printf("The number of nodes are %d\n",c);
printf("\nDo you want to proceed? y/n\n");
scanf(" %c",&ch);
}
while(ch=='y');
getch();
}
Example #3
0
void insert_tree(int num, tree_node *node)
{
  if(node == NULL)
    {
      tree_root = create_new_node(num);
      return;
    }
  node->left = create_new_node(num);
  return;
}
Example #4
0
struct LList *create_empty_list(){
	struct LList *fin = malloc(sizeof(struct LList)); 

	struct LData *data = create_empty_data();

	struct LNode *root     = create_new_node(data); 
	struct LNode *sentinal = create_new_node(data);

	fin->root = root;
	fin->root->next = sentinal;
	fin->sentinal = sentinal;
	fin->size = 0;

	return fin;
}
Example #5
0
static int insert_at(unsigned int list_id, unsigned int index, data_t data)
{

    pgeneric_list_t p_list = get_list_from_allotted_list(list_id);
    if (CHECK_NULL(p_list) ||
            (index != 0 &&
            (index > p_list->node_count)))
        return -1;

    if (index == p_list->node_count)
        return insert(list_id, data);

    plist_node_t node = create_new_node(data);
    if (CHECK_NULL(node))
        return -1;

    plist_node_t temp = p_list->phead;
    for (index = p_list->node_count - (index + 1); index-- > 0; temp = temp->next)
        ;

    node->next = temp->next;
    temp->next = node;
    p_list->node_count++;
    return 0;
}
/* allocates a new node and links it to the list -- at the end */
int append_node(List **list, char *content)
{
  List *new_node;
  List *last;

  new_node = create_new_node(content);
  if (new_node == NULL)
    {
      return (1);
    }
  new_node->next = NULL;

  /* if this is the first node: */
  if (*list == NULL)
    {
      *list = new_node;
    }
  else
    {
      /* find the last node and designate the new node to follow */
      last = find_last_node(list);
      last->next = new_node;
    }

  return (0);
}
Example #7
0
/**
 * Create a linked list node pointing to the data object from the head list
 */
node *create_list_node(memory_layout *mem, node *data, node **head) {
	node *cur = create_new_node(mem);
	if(cur == NULL) return NULL;
	cur->next = *head;
	*head = cur;
	cur->data = data;
	return cur;
}
int btree_insert(BTree **tree, char *data)
{
  BTree *new_node;
  BTree *current_node;

  /* create a new node that we will store in the right position
     in the tree */
  new_node = create_new_node(data);
  /* in case of malloc failure, return error code */
  if (new_node == NULL)
    {
      return (-1);
    }

  /* if the root of the tree is empty, store the new node there */
  if (*tree == NULL)
    {
      *tree = new_node;
      return (0);
    }
  /* otherwise, traverse the tree to find the correct position */
  else
    {
      current_node = *tree;
      while (1)
	{
	  /* if string is less than current node we are comparing to,
	     we will place the new node in the current node's left branch
	     if it is empty, otherwise we'll move onto the left node and
	     compare our string to it */
	  if (strcmp(data, current_node->str) < 0)
	    {
	      if (current_node->left == NULL)
		{
		  current_node->left = new_node;
		  return (0);
		}
	      current_node = current_node->left;
	    }
	  /* if string is greater than or equal to the current node's str,
	     we will place the new node in the current node's right branch
	     if it is empty, otherwise we'll move onto the right node and
	     compare our string to it */
	  else
	    {
	        if (current_node->right == NULL)
		  {
		    current_node->right = new_node;
		    return (0);
		  }
		current_node = current_node->right;
	    }
	}
    }

  return (0);
}
Example #9
0
/**
 * Create a new node for the calling process and add it to the list.
 */
node *create_process_node(memory_layout *mem) {
	node *process = create_new_node(mem);
	if(process == NULL) return NULL;
	init_process_node(process);
	process->next = mem->processes;
	mem->processes = process;

	return process;
}
//this tree is a "trie"
void insert(int itemset[], TreeNode *node, int current_item, int *size, int first_item, TreeNode *set[], double lutil){

	TreeNode *N;
	int value = itemset[current_item];
	
	if(value == 1){
		if(node->first_child == NULL){
			N = create_new_node(current_item);
			N->parent = node;
			node->first_child = N;
			node->last_child = N;

		}
		else{
			N = match_child(current_item, node);
			if(N == NULL){
				N = create_new_node(current_item);
				N->parent = node;
				node->last_child->right_sibling = N;
				N->left_sibling = node->last_child;
				node->last_child = N;

			}
			else{
				(N->count) ++;
			}
		}
	}
	else{
		N = node;
	}
	if(current_item == MAXITEMS && is_root(N) == false){
		N->last_item = true;
		N->first_item = first_item;
		N->lutil = lutil;
		set[*size] = N;
		(*size) ++;
	}

	if(current_item < MAXITEMS){
		insert(itemset, N, current_item + 1, size, first_item, set, lutil);
	}

}
Example #11
0
void push(struct dll** head, int data)
{
	printf("Pushing Data : %d\n",data);
	struct dll* new_node = create_new_node(data);
	new_node->next = *head;
	if (*head)
		(*head)->prev = new_node;
	*head = new_node;
	return;
}
Example #12
0
/*
 * 初始化
 */
void init_game(void)
{
	int row, col;
	list_t * tmp;

	for(row = 0; row < ROW; row++)
		for(col = 0; col < COL; col++)
			if(0 == row || ROW - 1 == row || 0 == col || COL - 1 == col)
				game[row][col] = WALL;
			else	
				game[row][col] = SPACE;

//	game[row / 2][3] = SNAKE;		// 蛇头
	head = create_new_node();
	head->pos = &game[row/2][3];
	*(head->pos) = SNAKE;
	head->prev = NULL;
	head->next = NULL;

//	game[row / 2][1] = SNAKE;		// 蛇尾
	tail = create_new_node();
	tail->pos = &game[row/2][1];
	*(tail->pos) = SNAKE;
	tail->next = NULL;
	tail->prev = NULL;

//	game[row / 2][2] = SNAKE;		// 蛇尾的前一个
	tmp = create_new_node();
	tmp->pos = &game[row/2][2];
	*(tmp->pos) = SNAKE;
	tmp->next = tail;
	tmp->prev = head;

	head->next = tmp;
	tail->prev = tmp;

	direc = 'd';
	create_food();

}
/* add_element_to_BST: Adds a student id to the binary tree creating new nodes
 * and linking them as necessary.
 *
 * Params: the BST and the student id to add to the BST.
 *
 * Returns: void.
 */
BST add_element_to_BST(BST self, long value)
{
    if (self == NULL) {
        return create_new_node(value);
    }
    
    if (value < self->value) {
        self->left = add_element_to_BST(self->left, value);
    } else {
        self->right = add_element_to_BST(self->right, value);
    }
    return self;
}
Example #14
0
tree_t *convert_to_bst(int arr[], int start, int end)
{
	tree_t	*n = NULL;
	int	split;

	if (start > end) {
		return (NULL);
	}

	if (start == end) {
		n = create_new_node(arr[start]);
		return (n);
	}

	split = find_split(start, end);
	printf("convert_to_bst (start, end, split) : %d, %d, %d\n",
		start, end, split);
	n = create_new_node(arr[split]);
	n->right = convert_to_bst(arr, start, split - 1);
	n->left = convert_to_bst(arr, split + 1, end);
	return (n);
}
/* creates a node and then inserts it in a list at a specific index */
int insert_in_list(List **list, char *content, int index)
{
  List *new_node;
  List *preceding_node;
  int i;

  /* if the index is not valid, do nothing and ret 0 */
  if (index < 0)
    {
      return (0);
    }
  if (index == 0)
    {
      /* add a node at the beginning of the list
         and return whether it was successful or not */
      return add_node(list, content);
    }
  
  preceding_node = *list;
  /* find node that should precede the new node */
  for (i = 1; i < index && preceding_node->next != NULL; i++)
    {
      preceding_node = preceding_node->next;
    }

  /* if the index is greater than the list size: 
     just add a node  at the end of the list */
  if (preceding_node->next == NULL)
    {
      /* return whether it was successful or not */
      return append_node(list, content);
    }
  
  else
    {
      new_node = create_new_node(content);

      /* if allocating space for a new node and its contents 
	 was unsuccessful: */
      if (new_node == NULL)
	{
	  return (1);
	}

      new_node->next = preceding_node->next;
      preceding_node->next = new_node;
    }

  return (0);
}
Example #16
0
/**
 * If a file node with the given name exists, return it
 * Else create a new one with the given name, add it to the list, and return it
 */
node *find_or_create_file_node(memory_layout* mem, char *name) {
	node *cur = find_file_node(mem, name);

	if(cur == NULL) {
		cur = create_new_node(mem);
		if(cur == NULL) return NULL;
		cur->fp = NULL;
		strncpy(cur->name, name, sizeof(cur->name));
		cur->next = mem->resources;
		mem->resources = cur;
	}

	return cur;
}
Example #17
0
/*
 * 移动的前面是食物
 */
void move_if_FOOD(char * next_pos)
{
	list_t * tmp;

	tmp = create_new_node();
	tmp->next = head;
	tmp->pos = next_pos;
	*next_pos = SNAKE;
	tmp->prev = NULL;
	head->prev = tmp;
	
	head = tmp;
	len++;
	score++;
	create_food();
}
/* add_element_to_AVL: Adds a student id to the AVL tree creating new nodes
* and linking them as necessary. This also checks that the tree is still balanced
* after a student has been added.
*
* Params: the AVL and the student id to add to the AVL.
*
* Returns: the Root of the AVL.
*/
AVL add_element_to_AVL(AVL self, long student_id)
{
	if (self == NULL) {
		return create_new_node(student_id);
	}
	if (student_id < self->student_id) {
		self->left = add_element_to_AVL(self->left, student_id);

	} else {
		self->right = add_element_to_AVL(self->right, student_id);
	}

	self = rebalance_AVL(self, student_id);

	return self;
}
Example #19
0
static int insert(unsigned int list_id, data_t data)
{

    pgeneric_list_t p_list = get_list_from_allotted_list(list_id);
    if (CHECK_NULL(p_list))
        return -1;

    plist_node_t node = create_new_node(data);
    if (CHECK_NULL(node))
        return -1;

    node->next = p_list->phead;
    p_list->phead = node;
    p_list->node_count++;

    return 0;
}
Example #20
0
static AtlasRoot create_new_root (const char *hint, int min_filter, int mag_filter) {
   AtlasRoot root;
   GLuint texture;
   GLubyte* temp_buf;
   int i, j;
   
#ifdef ANDROID
   // Should be reduced when stable AGA
   roadmap_log (ROADMAP_WARNING, "roadmap_canvas_atlas - creating new root for hint '%s'", hint);
#else
   roadmap_log (ROADMAP_DEBUG, "roadmap_canvas_atlas - creating new root for hint '%s'", hint);
#endif

   glGenTextures( 1, &texture);
   roadmap_canvas_bind(texture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
   check_gl_error();
   temp_buf= malloc(4 * CANVAS_ATLAS_TEX_SIZE * CANVAS_ATLAS_TEX_SIZE);
   roadmap_check_allocated (temp_buf);
   for( j = 0; j < CANVAS_ATLAS_TEX_SIZE; j++) {
      for( i = 0; i < CANVAS_ATLAS_TEX_SIZE; i++){
         temp_buf[4*(i+j*CANVAS_ATLAS_TEX_SIZE)] = 255;
         temp_buf[4*(i+j*CANVAS_ATLAS_TEX_SIZE) +1] = 255;
         temp_buf[4*(i+j*CANVAS_ATLAS_TEX_SIZE) +2] = 255;
         temp_buf[4*(i+j*CANVAS_ATLAS_TEX_SIZE) +3] = 0;
      }
   }

   glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, CANVAS_ATLAS_TEX_SIZE, CANVAS_ATLAS_TEX_SIZE, 0,
                GL_RGBA, GL_UNSIGNED_BYTE, temp_buf );
   check_gl_error();
   free(temp_buf);
   
   root.root_node = create_new_node();
   root.root_node->rect.minx = root.root_node->rect.miny = 0;
   root.root_node->rect.maxx = root.root_node->rect.maxy = CANVAS_ATLAS_TEX_SIZE - 1;
   root.texture = texture;
   strncpy_safe (root.hint, hint, sizeof(root.hint));
   
   return root;
}
Example #21
0
// Adds the specified data to the end of the list
void add_last(struct LList *list, struct LData *data){
	print_data(data); printf("\n");
	if(list->size == 0){
		struct LNode *add = malloc(sizeof(struct LNode)); 

		add->data = data; 
		add->next = list->root;
		list->root = add;
		list->size++;
		return;
	}
	struct LNode *add = create_new_node(data); 
	add->data = data; 

	struct LNode *itr_node = list->root;
	while(itr_node->next->next != list->sentinal){
		itr_node = itr_node->next;
	}
	itr_node->next = add; 
	add->next = list->sentinal; 
	list->size++; 
}
Example #22
0
//------------------------------------------------------------------------
// Function: push
//------------------------------------------------------------------------
void push(stack_node_t **root, int data) {
  stack_node_t *new_node = create_new_node(data);
  new_node->next = *root;
  *root = new_node;
  printf("%d pushed to stack\n", data);
}
Example #23
0
void
insert_word(trie_t *root, char *start, char *end)
{
	trie_t	*curr;
	int	indx;
	int	word_len;
	int	match_len;
	char	next_ch;
	char	temp_ch;

	if (!start) {
		return;
	}

	while (*start == ' ' && start++ < end);
	if (start >= end) {
		return;
	}

	curr = root;
	word_len = end - start + 1;

	match_len = find_longest_match(curr, start, end);
	temp_ch = start[word_len];
	start[word_len] = '\0';
	printf("longest match in %s for %s is %d\n", curr->str, start, match_len);
	start[word_len] = temp_ch;

	/*
	 * split based on the length being matched
	 * match len has to be less than/equal to the curr node string
	 * if remaining in the current node, then
	 *	we need to create a new node, copy the remaining str
	 * 	null terminate
	 * if remaining in the current word, then,
	 *	we need to create a new node, copy the remaining str
	 */

	if (curr->len == 0) {
		next_ch = *(start + match_len);
		indx = tolower(next_ch) - 'a';
		if (indx > MAX_ALPHA) {
			g_stats.total_ignored++;
			return;
		}

		if (curr->child[indx] == NULL) {
			curr->child[indx] = create_new_node(start + match_len,
			    word_len - match_len);
		} else {
			insert_word(curr->child[indx], start + match_len,
			    end);
		}

		return;
	}

	if (match_len < curr->len) {
		next_ch = curr->str[match_len];
		indx = tolower(next_ch) - 'a';
		if (indx > MAX_ALPHA) {
			g_stats.total_ignored++;
			return;
		}
		curr->child[indx] = create_new_node(&curr->str[match_len],
		    curr->len - match_len);		
		if (curr->type == LEAF) {
			g_stats.total_leaf--;
		}
		curr->type = NODE;
	}

	curr->str[match_len] = '\0';
	curr->len = match_len;

	if (match_len == word_len) {
		curr->type = LEAF;
		g_stats.total_leaf++;
	} else {
		next_ch = *(start + match_len);
		indx = tolower(next_ch) - 'a';
		if (indx > MAX_ALPHA) {
			g_stats.total_ignored++;
			return;
		}

		if (curr->child[indx] == NULL) {
			curr->child[indx] = create_new_node(start + match_len,
			    word_len - match_len);
		} else {
			insert_word(curr->child[indx], start + match_len,
			    end);
		}
	}
}
void main()
{
	start=NULL;
	rear=NULL;
	char regex[100];
	int i,nodecount=0;
	printf("\nPlease Enter the regex:- ");
	scanf("%s",regex);	
	//printf("regex %s",regex); 
	for(i=0;regex[i]!='\0';i++)
	{
		if(regex[i]=='.')
		{
			struct node *np;
			np=create_new_node(++nodecount,regex[i-1],'$');
			insert(np,regex[i],2);
			np=create_new_node(++nodecount,'E','$');
			insert(np,regex[i],2);
			np=create_new_node(++nodecount,regex[i+1],'$');
			insert(np,regex[i],2);
			np=create_new_node(++nodecount,']','$');
			insert(np,regex[i],2);
			display(start,regex[i]);
			printf("\n");
		}
		else if(regex[i]=='*')
		{
			struct node *np;
			np=create_new_node(++nodecount,'E','E');
			insert(np,'*',2);
			np=create_new_node(++nodecount,regex[i-1],'$');
			insert(np,'*',2);
			np=create_new_node(++nodecount,'E','E');
			insert(np,'*',2);
			np=create_new_node(++nodecount,']','$');
			insert(np,'*',1);
			display(start,'*');
		}
		else if(regex[i]=='+')
		{
			struct node *np,*np1;
			np=create_new_node(++nodecount,'E','E');
			insert(np,'+',2);
			np=create_new_node(++nodecount,regex[i-1],'$');
			insert(np,'+',2);
			np=create_new_node(++nodecount,'E','$');
			insert(np,'+',2);
			np=create_new_node(++nodecount,']','$');
			insert(np,'+',2);
			np=create_new_node(++nodecount,regex[i+1],'$');
			start->q->next=np;
			np1=create_new_node(++nodecount,'E','$');
			np->p->next=np1;
			np1->p->next=rear;
			display(start,'+');
		}	
	}
}
int main(int argc, char *argv[]){

	struct timeval  start_time, end_time; /* structs for timer     */
	struct timezone zone;
	long int sec = 0, usec = 0; /* sec & microsec for the timer    */
	
	long int time_total_sec = 0;
     double time_total_msec = 0;
     long int time_total_usec = 0;

	int numTrans, pid, numItems, item, count, i , j;
	FILE *f_input, *f_utility, *f_output;
	int sizeDB;
	
	double minshare;
	int MV = 0;
	int ML = 0;
	int tempML = 0;
	
	if(argc != 7){
		fprintf(stderr, "Usage: %s transactionDB utilityTable outputFile min_util MAXITEMS MAXCANDIDATES\n", argv[0]);	
		exit(0);
	}
	
	f_input = fopen(argv[1], "r");
	f_utility = fopen(argv[2], "r");
	f_output = fopen(argv[3], "w");
	minshare = atof(argv[4]);
	MAXITEMS = atoi(argv[5]);
	MAXITEMSETS = atoi(argv[6]);
	
	if((f_input == NULL) || (f_utility == NULL) || (f_output == NULL)){
	    fprintf( stdout, "ERROR[%s]: Can't open %s or %s or %s\n", argv[0], argv[1], argv[2], argv[3] );
	    fprintf( stderr, "ERROR[%s]: Can't open %s or %s or %s\n", argv[0], argv[1], argv[2], argv[3] );
	    fprintf( stderr, "ERROR[%s]: Can't open %s or %s or %s\n", argv[0], argv[1], argv[2], argv[3] );
    		exit( 0 );
	}
	
	TreeNode *rootCk;
	rootCk = create_new_node(ROOT);

	TreeNode *rootRc;
	rootRc = create_new_node(ROOT);
	
	TreeNode *rootF;	//the tree for frequent itemsets
	rootF = create_new_node(ROOT);
	
	TreeNode *setRc[MAXITEMSETS + 1];
	TreeNode *setCk[MAXITEMSETS + 1];
	TreeNode *setF[MAXITEMSETS + 1];
	
	int sizeRc = 0;
	int sizeCk = 0;
	int sizeF = 0;
	
	double utility[MAXITEMS + 1];
	double TutilItem[MAXITEMS + 1];
	int items[MAXITEMS + 1];
	double lmv[MAXITEMS + 1];

	double TutilDB = 0;
	float cost;
	
	for(i = 1; i <= MAXITEMS; i ++){
		utility[i] = 0;
		TutilItem[i] = 0;
		items[i] = 0;
		lmv[i] = 0;
	}

	printf("===== %s %s %s %f =====\n\n", argv[0], argv[1], argv[2], minshare);
	
     //record the time for the first db scan
     if(gettimeofday(&start_time, &zone) == -1){
       fprintf(stderr, "gettimeofday error\n");
     }
    	
    	fscanf(f_utility, "%d ", &numItems); 
	for(i = 1; i <= numItems; i ++){
	
		fscanf(f_utility, "%d %f ", &item, &cost);
		utility[item] = cost;
	}
	
	fscanf(f_input, "%d ", &numTrans);
	double transUtil = 0;
	//read the whole db once to get candidate 1-itemsets
	for(i = 1; i <= numTrans; i ++){
	
		fscanf(f_input, "%d ", &pid);
		fscanf(f_input, "%d ", &numItems);
		//printf("\n%d %d ", pid, numItems);
		for(j = 1; j <= numItems; j ++){
			fscanf(f_input, "%d %d ", &item, &count);
			//printf("item %d count %d ", item, count);
			transUtil += count * utility[item];
			items[item] = 1;
			if(count > MV){
				MV = count;
			}
			tempML ++;

			//printf("\nitem: %d count: %d", item, count);
			lmv[item] += count;
		}
		for(j = 1; j <= MAXITEMS; j ++){
			if(items[j] == 1){
				TutilItem[j] += transUtil;
				items[j] = 0;
			}
		}
		if(tempML > ML){
			ML = tempML;
		}
		TutilDB += transUtil;
		transUtil = 0;
		tempML = 0;
	}
	sizeDB = numTrans;
	
	if(gettimeofday(&end_time, &zone) == 0){
      	if(end_time.tv_usec >= start_time.tv_usec){
      		sec  = end_time.tv_sec - start_time.tv_sec;
      		usec = end_time.tv_usec - start_time.tv_usec;
      	}else{
      		sec  = end_time.tv_sec - start_time.tv_sec - 1;
      		usec = end_time.tv_usec - start_time.tv_usec + 1000000;
      	}
      	time_total_sec += sec;
      	time_total_usec += usec;
      	
      	fprintf(stdout, "\n[FUM] Total runtime for first db scan is %ld sec. %.3f msec\n", sec, usec/1000.0);
      	f_output = fopen( argv[3], "a" );
      	fprintf(f_output, "\n[FUM] Total runtime for first db scan is %ld sec. %.3f msec\n", sec, usec/1000.0);
      	fclose( f_output );
      }
	
	if(DEBUG){
		for(i = 1; i <= MAXITEMS; i ++){
			printf("\nutil item (%d): %f", i, utility[i]);
		}
		printf("\n");
		for(i = 1; i <= MAXITEMS; i ++){
			printf("\nitem (%d) has Tutil: %f", i, TutilItem[i]);
		}
		printf("\n\nTutilDB: %f Min_Lutil: %f\n", TutilDB, MIN_LUTIL(TutilDB, minshare));
		printf("\nMV: %d ML: %d", MV, ML);
	}

	int isolated_itemsets[MAXITEMS + 1];
	int size = 0;
	
	//get candidate 1-itemsets
	for(i = 1; i <= MAXITEMS; i ++){
		if(utility[i] > 0){
			if(TutilItem[i] >= MIN_LUTIL(TutilDB, minshare)){

				Itemset I;
				init_itemset(&I);
				I.itemset[i] = 1;
				double lutil = (lmv[i] * utility[i]);
				insert(I.itemset, rootRc, 1, &sizeRc, i, setRc, lutil);
				free_itemset(&I);
			}
			else{
				isolated_itemsets[size] = i;
				size ++;
			}
		}
	}

	//int k_prime = 1; //needed for other version of critical function
	int c;
	for(c = 0; c < sizeRc; c ++){
		TreeNode *X = setRc[c];

		if(X->lutil >= MIN_LUTIL(TutilDB, minshare)){

			Itemset I;
			to_itemset(&I, X);
			insert(I.itemset, rootF, 1, &sizeF, 1, setF, X->lutil);
			free_itemset(&I);
		}
		//printf("\nCF: %f", CF(X->lutil, 1, MV, ML, k_prime));
		//if(CF(X->lutil, 1, MV, ML, k_prime) < MIN_LUTIL(TutilDB, minshare)){
		if(TutilItem[X->item] < MIN_LUTIL(TutilDB, minshare)){
			
			remove_itemset(X, setRc, c);
		}
	}
	adjust_set(setRc, &sizeRc);
	if(PRT_CNT){
		printf("\n\nIteration (%d)", 0);
		printf("\n|Ck| = %d", sizeCk);
		printf("\n|Rc| = %d", sizeRc);
		printf("\n|Fk| = %d", sizeF);
	}

	int k;
	int counterF = 0;
	boolean stop = false;
	int num_false_positives[MAXITEMSETS + 1];
	int sizeFP = 0;
	
	//record the time for mining
	if(gettimeofday(&start_time, &zone) == -1){
		fprintf(stderr, "gettimeofday error\n");
	}
	for(k = 1; sizeRc > 0 && stop == false; k ++){
	
		//apriori join + apriori prune
		generate(rootRc, setRc, sizeRc, setCk, &sizeCk, rootCk, k); 

		if(PRT_MEM){
			printf("\n\nIteration (%d)", k);
			int mem_counterCk = 0;
			count_nodes(rootCk, &mem_counterCk);
			printf("\nNode Count = [%d]", mem_counterCk);
			printf("\nNode Size = [%ld bytes]", sizeof(TreeNode));
			printf("\nMemory space required for candidate tree = %ld bytes", mem_counterCk * sizeof(TreeNode));
		}

		if(sizeCk > 0){

			double TransUtil;
			rewind(f_input);
			fscanf(f_input, "%d ", &numTrans);
			for(i = 1; i <= numTrans; i ++){

				fscanf(f_input, "%d ", &pid);
				fscanf(f_input, "%d ", &numItems);

				Transaction T;
				init_transaction(&T);
				for(j = 1; j <= numItems; j ++){

					fscanf(f_input, "%d %d ", &item, &count);
					if(is_isolated_item(item, isolated_itemsets, size) == false){
						T.itemset[item] += count;
						T.total_count += (count * utility[item]);
					}
				}
				TransUtil = T.total_count;
		
				for(j = 0; j < sizeCk; j ++){
					TreeNode *X = setCk[j];
					boolean in_transaction = true;
					double Lutil = 0;
					while(is_root(X) == false && in_transaction == true){ //first check if itemset in transaction
			
						if(T.itemset[X->item] == 0){
							in_transaction = false;
						}
						Lutil += (T.itemset[X->item] * utility[X->item]);
						X = X->parent;
					}
					if(in_transaction){
						TreeNode *last_node = setCk[j];
						last_node->lutil += Lutil;
						last_node->CF += TransUtil;
					}
				}
				free_transaction(&T);
			}
			if(PRT_CNT){
				printf("\n\nIteration (%d)", k);
				printf("\n|Ck| = %d", sizeCk);
			}
			if(PRT_FALSE_POS){
				num_false_positives[k] = sizeCk;
				sizeFP ++;
			}
			for(c = 0; c < sizeCk; c ++){
				TreeNode *X = setCk[c];
				//print_itemset(X);
				//printf(" lutil: %f minlutil: %f\n", X->lutil, MIN_LUTIL(TutilDB, minshare));
				if(X->lutil >= MIN_LUTIL(TutilDB, minshare)){

					counterF ++;
					Itemset I;
					to_itemset(&I, X);
					insert(I.itemset, rootF, 1, &sizeF, 1, setF, X->lutil);
					free_itemset(&I);
				}
				if(X->CF < MIN_LUTIL(TutilDB, minshare)){
				//if(CF(X->lutil, 1, MV, ML, k_prime) < MIN_LUTIL(TutilDB, minshare)){
					remove_itemset(X, setCk, c);
				}
			}
			adjust_set(setCk, &sizeCk);
			copy_tree(rootCk, setCk, &sizeCk, rootRc, setRc, &sizeRc);
			if(PRT_CNT){
				printf("\n|Rc| = %d", sizeRc);
				printf("\n|Fk| = %d", counterF);
			}
			if(PRT_FALSE_POS){
				num_false_positives[k] -= counterF;
				printf("\nFalse Positives Iteration (%d): %d", k, num_false_positives[k]);
			}
		}
		else{
			stop = true;
		}	
		counterF = 0;
	}
	if(gettimeofday(&end_time, &zone) == 0){
	 	if(end_time.tv_usec >= start_time.tv_usec){
	 		sec  = end_time.tv_sec - start_time.tv_sec;
	 		usec = end_time.tv_usec - start_time.tv_usec;
	 	}else{
	 		sec  = end_time.tv_sec - start_time.tv_sec - 1;
	 		usec = end_time.tv_usec - start_time.tv_usec + 1000000;
	 	}
      	time_total_sec += sec;
      	time_total_usec += usec;
      	
	 	fprintf(stdout, "\n[FUM] Total runtime for mining is %ld sec. %.3f msec\n", sec, usec/1000.0);
	 	f_output = fopen( argv[3], "a" );
	 	fprintf(f_output, "\n[FUM] Total runtime for mining is %ld sec. %.3f msec\n", sec, usec/1000.0);
	 	fclose( f_output );
 	}
	
	f_output = fopen(argv[3], "a");
	if(PRT_FALSE_POS){
		int total_FP = 0;
		for(k = 1; k <= sizeFP; k ++){
			total_FP += num_false_positives[k];
		}
		printf("\nTotal False Positives: %d", total_FP);
	}
	if(PRT_FP){
		printf("\n\nFound (%d) ShFrequent Itemsets:", sizeF);
		fprintf(f_output, "\n\nFound (%d) ShFrequent Itemsets:", sizeF);
		print_frequent_itemset(setF, sizeF, f_output);
	}
	if(PRT_MEM){
		int mem_counterF = 0;
		count_nodes(rootF, &mem_counterF);
		printf("\n\nNode Count = [%d]", mem_counterF);
		printf("\nNode Size = [%ld bytes]", sizeof(TreeNode));
		printf("\nMemory space required for frequent itemset tree = %ld bytes", mem_counterF * sizeof(TreeNode));
	}
	
	time_total_msec = time_total_usec / 1000.0;
  	if(time_total_msec >= 1000){
  		time_total_sec += floor(time_total_msec/1000);
  		time_total_msec = time_total_usec % 1000;
  	}
  	
  	//printf("\ntime sec: %ld time msec: %.3lf time usec: %ld", time_total_sec, time_total_msec, time_total_usec);

	fprintf(stdout, "\n\n[FUM] Total (aggregate) runtime is %ld sec. %.3lf msec\n", time_total_sec, time_total_msec);
	fprintf(f_output, "\n\n[FUM] Total (aggregate) runtime is %ld sec. %.3lf msec\n", time_total_sec, time_total_msec);
	
	free_tree(setRc, &sizeRc);
	free_tree(setCk, &sizeCk);
	free_tree(setF, &sizeF);
	fclose(f_input);
	fclose(f_output);
	fclose(f_utility);
	printf("\n\nProcessing Complete\n");
	return 0;
}
Example #26
0
void refine(T* EmTemp, HashTable* HT_Elem_Ptr, HashTable* HT_Node_Ptr, MatProps* matprops_ptr) {
	//printf("refining element %u %u \n",*(EmTemp->pass_key()), *(EmTemp->pass_key()+1));
	int which;
	Node *n1, *n2, *n3, *n4;

	unsigned* KeyTemp;
	Node* NodeTemp[9];
	unsigned NewNodeKey[16][KEYLENGTH];
	T* Quad9P;
	int numprocs, myid, i;
	T* neigh_elm;
	unsigned* neigh_node_key;
	int RefinedNeigh = 0;
	int info;
	int other_proc = 0;
	int boundary;
	int order[5];

	MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
	MPI_Comm_rank(MPI_COMM_WORLD, &myid);
	int elm_loc[2], my_elm_loc[2];
	int* fth_elm_loc = EmTemp->get_elm_loc();
	elm_loc[0] = 2 * fth_elm_loc[0];
	elm_loc[1] = 2 * fth_elm_loc[1];

	KeyTemp = EmTemp->getNode();

	for (i = 0; i < 8; i++) //-- corners and sides
	    {
		NodeTemp[i] = (Node*) HT_Node_Ptr->lookup(KeyTemp + i * KEYLENGTH);
		assert(NodeTemp[i]);
	}

	NodeTemp[8] = (Node*) HT_Node_Ptr->lookup(EmTemp->pass_key()); //-- bubble

	//SIDE 0
	if (*(EmTemp->get_neigh_proc()) == -1)
		boundary = 1;
	else
		boundary = 0;

	if (boundary == 1 || *(EmTemp->get_neigh_gen()) <= EmTemp->get_gen()) {
		RefinedNeigh = 0;
		info = S_S_CON;
		if (*(EmTemp->get_neigh_proc()) != myid) {
			other_proc = 1;
			info = -1;
		}

		which = 4;
		//---Fourth new node---
		n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 4);
		n2 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode());

		create_new_node(which, 0, 4, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
		    matprops_ptr);

		//---Fourth old node---
		if (RefinedNeigh || boundary)
			NodeTemp[4]->putinfo(CORNER);
		else if (other_proc)
			NodeTemp[4]->putinfo(-1);
		else
			NodeTemp[4]->putinfo(S_C_CON);

		//---Fifth new node---
		which = 5;
		n2 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH);

		create_new_node(which, 1, 4, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
		    matprops_ptr);
	} else {

		//Keith Added this if
		if ((*(EmTemp->get_neigh_proc()) != myid)
		    || ((*(EmTemp->get_neigh_proc() + 4) != myid) && (*(EmTemp->get_neigh_proc() + 4) != -2)))
			other_proc = 1;
		else
			other_proc = 0;

		// fourth new node
		neigh_elm = (T*) HT_Elem_Ptr->lookup(EmTemp->get_neighbors());
		i = 0;
		which = -1;
		while (i < 4 && which == -1) {
			if (compare_key(neigh_elm->get_neighbors() + i * KEYLENGTH, EmTemp->pass_key()))
				which = i;
			i++;
		}
		assert(which != -1);
		neigh_node_key = neigh_elm->getNode();
		for (i = 0; i < KEYLENGTH; i++)
			NewNodeKey[4][i] = neigh_node_key[i + (which + 4) * KEYLENGTH];
		n1 = (Node*) HT_Node_Ptr->lookup(NewNodeKey[4]);
		if (neigh_elm->get_refined_flag() == 0 || neigh_elm->get_refined_flag() == GHOST)
			n1->putinfo(SIDE);
		//else if(neigh_elm->get_refined_flag()==GHOST)
		//n1->putinfo(-1);
		else
			n1->putinfo(S_C_CON);
		//fourth old node
		NodeTemp[4]->putinfo(CORNER);
		if (other_proc) //ERROR: other_proc is never set, we never checked to see if the more refined neighbor was on another processor
			NodeTemp[4]->putinfo(-1);
		// fifth new node
		neigh_elm = (T*) HT_Elem_Ptr->lookup(EmTemp->get_neighbors() + 4 * KEYLENGTH);
		i = 0;
		which = -1;
		while (i < 4 && which == -1) {
			if (compare_key(neigh_elm->get_neighbors() + i * KEYLENGTH, EmTemp->pass_key()))
				which = i;
			i++;
		}
		assert(which != -1);
		neigh_node_key = neigh_elm->getNode();
		for (i = 0; i < KEYLENGTH; i++)
			NewNodeKey[5][i] = neigh_node_key[i + (which + 4) * KEYLENGTH];
		n1 = (Node*) HT_Node_Ptr->lookup(NewNodeKey[5]);
		if (neigh_elm->get_refined_flag() == 0 || neigh_elm->get_refined_flag() == GHOST)
			n1->putinfo(SIDE);
		//else if(neigh_elm->get_refined_flag()==GHOST)
		//n1->putinfo(-1);
		else
			n1->putinfo(S_C_CON);

	}

//+++++++++++++++++++++++++++SIDE1

	if (*(EmTemp->get_neigh_proc() + 1) == -1)
		boundary = 1;
	else
		boundary = 0;

	if (boundary == 1 || *(EmTemp->get_neigh_gen() + 1) <= EmTemp->get_gen()) {
		RefinedNeigh = 0;
		info = S_S_CON;
		if (*(EmTemp->get_neigh_proc() + 1) != myid) // && *(EmTemp->get_neigh_proc()+1)>0)
		    {
			other_proc = 1;
			info = -1;
		} else
			other_proc = 0;

		//---Eight new node---
		which = 8;
		n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 5);
		n2 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH);

		create_new_node(which, 1, 5, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
		    matprops_ptr);

		//---Fifth old node---
		if (RefinedNeigh || boundary)
			NodeTemp[5]->putinfo(CORNER);
		else {
			if (other_proc)
				NodeTemp[5]->putinfo(info);
			else
				NodeTemp[5]->putinfo(S_C_CON);
		}

		//---Thirteenth new node---
		which = 13;
		n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 5);
		n2 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 2);

		create_new_node(which, 2, 5, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
		    matprops_ptr);
	} else {
		//Keith Added this if
		if ((*(EmTemp->get_neigh_proc() + 1) != myid)
		    || ((*(EmTemp->get_neigh_proc() + 5) != myid) && (*(EmTemp->get_neigh_proc() + 5) != -2)))
			other_proc = 1;
		else
			other_proc = 0;

		// eighth new node
		neigh_elm = (T*) HT_Elem_Ptr->lookup(EmTemp->get_neighbors() + KEYLENGTH);
		i = 0;
		which = -1;
		while (i < 4 && which == -1) {
			if (compare_key(neigh_elm->get_neighbors() + i * KEYLENGTH, EmTemp->pass_key()))
				which = i;
			i++;
		}
		assert(which != -1);
		neigh_node_key = neigh_elm->getNode();
		for (i = 0; i < KEYLENGTH; i++)
			NewNodeKey[8][i] = neigh_node_key[i + (which + 4) * KEYLENGTH];
		n1 = (Node*) HT_Node_Ptr->lookup(NewNodeKey[8]);
		if (neigh_elm->get_refined_flag() == 0 || neigh_elm->get_refined_flag() == GHOST)
			n1->putinfo(SIDE);
		//else if(neigh_elm->get_refined_flag()==GHOST)
		//n1->putinfo(-1);
		else
			n1->putinfo(S_C_CON);
		// fifth old node
		NodeTemp[5]->putinfo(CORNER);
		if (other_proc) //ERROR: other_proc is set based on side 0 neigbor not being more refined or never set, we never checked to see if the more refined neighbor was on another processor
			NodeTemp[5]->putinfo(-1);
		// thirteenth new node
		neigh_elm = (T*) HT_Elem_Ptr->lookup(EmTemp->get_neighbors() + 5 * KEYLENGTH);
		i = 0;
		which = -1;
		while (i < 4 && which == -1) {
			if (compare_key(neigh_elm->get_neighbors() + i * KEYLENGTH, EmTemp->pass_key()))
				which = i;
			i++;
		}
		assert(which != -1);
		neigh_node_key = neigh_elm->getNode();
		for (i = 0; i < KEYLENGTH; i++)
			NewNodeKey[13][i] = neigh_node_key[i + (which + 4) * KEYLENGTH];
		n1 = (Node*) HT_Node_Ptr->lookup(NewNodeKey[13]);
		if (neigh_elm->get_refined_flag() == 0 || neigh_elm->get_refined_flag() == GHOST)
			n1->putinfo(SIDE);
		//else if(neigh_elm->get_refined_flag()==GHOST)
		//n1->putinfo(-1);
		else
			n1->putinfo(S_C_CON);
	}

	//+++++++++++++++++++++++++++SIDE2

	if (*(EmTemp->get_neigh_proc() + 2) == -1)
		boundary = 1;
	else
		boundary = 0;

	if (boundary == 1 || *(EmTemp->get_neigh_gen() + 2) <= EmTemp->get_gen()) {
		info = S_S_CON;

		if (*(EmTemp->get_neigh_proc() + 2) != myid) // && *(EmTemp->get_neigh_proc()+2)>0)
		    {
			other_proc = 1;
			info = -1;
		} else
			other_proc = 0;

		RefinedNeigh = 0;

		//---Fourteenth new node---
		which = 14;
		n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 3);
		n2 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 6);

		create_new_node(which, 3, 6, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
		    matprops_ptr);

		//---Sixth old node---
		if (RefinedNeigh || boundary)
			NodeTemp[6]->putinfo(CORNER);
		else if (other_proc)
			NodeTemp[6]->putinfo(-1);
		else
			NodeTemp[6]->putinfo(S_C_CON);

		//---Fifteenth new node---
		which = 15;
		// geoflow info
		n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 6);
		n2 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 2);

		create_new_node(which, 2, 6, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
		    matprops_ptr);
	} else {
		//Keith Added this if
		if ((*(EmTemp->get_neigh_proc() + 2) != myid)
		    || ((*(EmTemp->get_neigh_proc() + 6) != myid) && (*(EmTemp->get_neigh_proc() + 6) != -2)))
			other_proc = 1;
		else
			other_proc = 0;

		// fourteenth new node
		neigh_elm = (T*) HT_Elem_Ptr->lookup(EmTemp->get_neighbors() + 6 * KEYLENGTH);
		i = 0;
		which = -1;
		while (i < 4 && which == -1) {
			if (compare_key(neigh_elm->get_neighbors() + i * KEYLENGTH, EmTemp->pass_key()))
				which = i;
			i++;
		}
		assert(which != -1);
		neigh_node_key = neigh_elm->getNode();
		for (i = 0; i < KEYLENGTH; i++)
			NewNodeKey[14][i] = neigh_node_key[i + (which + 4) * KEYLENGTH];
		n1 = (Node*) HT_Node_Ptr->lookup(NewNodeKey[14]);
		if (neigh_elm->get_refined_flag() == 0 || neigh_elm->get_refined_flag() == GHOST)
			n1->putinfo(SIDE);
		//else if(neigh_elm->get_refined_flag()==GHOST)
		//n1->putinfo(-1);
		else
			n1->putinfo(S_C_CON);
		// sixth old node
		NodeTemp[6]->putinfo(CORNER);
		if (other_proc) //ERROR: other_proc is never set, we never checked to see if the more refined neighbor was on another processor
			NodeTemp[6]->putinfo(-1);
		// fifteenth new node
		neigh_elm = (T*) HT_Elem_Ptr->lookup(EmTemp->get_neighbors() + 2 * KEYLENGTH);
		i = 0;
		which = -1;
		while (i < 4 && which == -1) {
			if (compare_key(neigh_elm->get_neighbors() + i * KEYLENGTH, EmTemp->pass_key()))
				which = i;
			i++;
		}
		assert(which != -1);
		neigh_node_key = neigh_elm->getNode();
		for (i = 0; i < KEYLENGTH; i++)
			NewNodeKey[15][i] = neigh_node_key[i + (which + 4) * KEYLENGTH];
		n1 = (Node*) HT_Node_Ptr->lookup(NewNodeKey[15]);
		if (neigh_elm->get_refined_flag() == 0 || neigh_elm->get_refined_flag() == GHOST)
			n1->putinfo(SIDE);
		//else if(neigh_elm->get_refined_flag()==GHOST)
		//n1->putinfo(-1);
		else
			n1->putinfo(S_C_CON);
	}

	//+++++++++++++++++++++++++++SIDE 3

	if (*(EmTemp->get_neigh_proc() + 3) == -1)
		boundary = 1;
	else
		boundary = 0;

	if (boundary == 1 || *(EmTemp->get_neigh_gen() + 3) <= EmTemp->get_gen()) {
		info = S_S_CON;

		if (*(EmTemp->get_neigh_proc() + 3) != myid) //&& *(EmTemp->get_neigh_proc()+3)>0)
		    {
			other_proc = 1;
			info = -1;
		} else
			other_proc = 0;

		RefinedNeigh = 0;

		//---Sixth new node----
		which = 6;
		n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 7);
		n2 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode());

		create_new_node(which, 0, 7, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
		    matprops_ptr);

		//---Seventh old node---
		if (RefinedNeigh || boundary)
			NodeTemp[7]->putinfo(CORNER);
		else if (other_proc)
			NodeTemp[7]->putinfo(-1);
		else
			NodeTemp[7]->putinfo(S_C_CON);

		//---Eleventh new node---
		which = 11;
		n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 7);
		n2 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 3);

		create_new_node(which, 3, 7, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
		    matprops_ptr);
	} else {
		//Keith Added this if
		if ((*(EmTemp->get_neigh_proc() + 3) != myid)
		    || ((*(EmTemp->get_neigh_proc() + 7) != myid) && (*(EmTemp->get_neigh_proc() + 7) != -2)))
			other_proc = 1;
		else
			other_proc = 0;

		// sixth new node
		neigh_elm = (T*) HT_Elem_Ptr->lookup(EmTemp->get_neighbors() + 7 * KEYLENGTH);
		i = 0;
		which = -1;
		while (i < 4 && which == -1) {
			if (compare_key(neigh_elm->get_neighbors() + i * KEYLENGTH, EmTemp->pass_key()))
				which = i;
			i++;
		}
		assert(which != -1);
		neigh_node_key = neigh_elm->getNode();
		for (i = 0; i < KEYLENGTH; i++)
			NewNodeKey[6][i] = neigh_node_key[i + (which + 4) * KEYLENGTH];
		n1 = (Node*) HT_Node_Ptr->lookup(NewNodeKey[6]);
		if (neigh_elm->get_refined_flag() == 0 || neigh_elm->get_refined_flag() == GHOST)
			n1->putinfo(SIDE);
		//else if(neigh_elm->get_refined_flag()==GHOST)
		//n1->putinfo(-1);
		else
			n1->putinfo(S_C_CON);
		// seventh old node
		NodeTemp[7]->putinfo(CORNER);
		if (other_proc) //ERROR: other_proc is never set, we never checked to see if the more refined neighbor was on another processor
			NodeTemp[7]->putinfo(-1);
		// eleventh new node
		neigh_elm = (T*) HT_Elem_Ptr->lookup(EmTemp->get_neighbors() + 3 * KEYLENGTH);
		i = 0;
		which = -1;
		while (i < 4 && which == -1) {
			if (compare_key(neigh_elm->get_neighbors() + i * KEYLENGTH, EmTemp->pass_key()))
				which = i;
			i++;
		}
		assert(which != -1);
		neigh_node_key = neigh_elm->getNode();
		for (i = 0; i < KEYLENGTH; i++)
			NewNodeKey[11][i] = neigh_node_key[i + (which + 4) * KEYLENGTH];
		n1 = (Node*) HT_Node_Ptr->lookup(NewNodeKey[11]);
		if (neigh_elm->get_refined_flag() == 0 || neigh_elm->get_refined_flag() == GHOST)
			n1->putinfo(SIDE);
		//else if(neigh_elm->get_refined_flag()==GHOST)
		//n1->putinfo(-1);
		else
			n1->putinfo(S_C_CON);
	}
	//++++++++++++++++INTERNAL SIDE NODES 7, 8OLD, 12, 9, 10

	RefinedNeigh = 0;
	boundary = 0;
	info = SIDE;

	//---Seventh new node---

	which = 7;
	// geoflow info
	n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 4);
	n2 = (Node*) HT_Node_Ptr->lookup(EmTemp->pass_key());

	create_new_node(which, 4, 8, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
	    matprops_ptr);

	NodeTemp[8]->putinfo(CORNER);    //changing the old bubble

	//---Twelwth new node---

	which = 12;
	// geoflow info
	n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 6);

	create_new_node(which, 6, 8, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
	    matprops_ptr);

	//---Ninth new node---

	which = 9;
	// geoflow info
	n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 7);

	create_new_node(which, 7, 8, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
	    matprops_ptr);

	//---Tenth new node---

	which = 10;
	// geoflow info
	n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 5);

	create_new_node(which, 5, 8, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
	    matprops_ptr);

	//+++++++++++++++++++THE NEW BUBBLES 0, 1, 2, 3

	info = BUBBLE;

	//---0th new node---

	NodeTemp[0] = (Node*) HT_Node_Ptr->lookup(NewNodeKey[6]);
	NodeTemp[1] = (Node*) HT_Node_Ptr->lookup(NewNodeKey[7]);
	which = 0;
	n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode());
	n3 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 4);
	n4 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 7);

	create_new_node(which, 0, 1, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
	    matprops_ptr);

	//---1st new node---

	NodeTemp[0] = (Node*) HT_Node_Ptr->lookup(NewNodeKey[7]);
	NodeTemp[1] = (Node*) HT_Node_Ptr->lookup(NewNodeKey[8]);
	which = 1;
	n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH);
	n4 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 5);

	create_new_node(which, 0, 1, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
	    matprops_ptr);

	//---2nd new node---

	NodeTemp[0] = (Node*) HT_Node_Ptr->lookup(NewNodeKey[12]);
	NodeTemp[1] = (Node*) HT_Node_Ptr->lookup(NewNodeKey[13]);
	which = 2;
	n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 2);
	n3 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 5);
	n4 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 6);

	create_new_node(which, 0, 1, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
	    matprops_ptr);

	//---3rd new node---

	NodeTemp[0] = (Node*) HT_Node_Ptr->lookup(NewNodeKey[11]);
	NodeTemp[1] = (Node*) HT_Node_Ptr->lookup(NewNodeKey[12]);
	which = 3;
	n1 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 6);
	n3 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 3);
	n4 = (Node*) HT_Node_Ptr->lookup(EmTemp->getNode() + KEYLENGTH * 7);

	create_new_node(which, 0, 1, HT_Node_Ptr, NodeTemp, NewNodeKey, info, &RefinedNeigh, boundary,
	    matprops_ptr);

	//---NEW ELEMENTS---

	unsigned nodes[9][KEYLENGTH];
	unsigned neigh[8][KEYLENGTH];
	unsigned* orig_neighbors = EmTemp->get_neighbors();
	int* orig_neigh_proc = EmTemp->get_neigh_proc();
	int neigh_proc[8];
	int generation = EmTemp->get_gen() + 1;
	int* orig_neigh_gen = EmTemp->get_neigh_gen();
	int neigh_gen[4];
	int material = EmTemp->get_material();

	double coord[DIMENSION];
	//---0th new element---

	//the nodes

	for (i = 0; i < KEYLENGTH; i++) {
		nodes[0][i] = *(KeyTemp + i);
		nodes[1][i] = *(KeyTemp + 4 * KEYLENGTH + i);
		nodes[2][i] = *((EmTemp->pass_key()) + i);
		nodes[3][i] = *(KeyTemp + 7 * KEYLENGTH + i);
		nodes[4][i] = NewNodeKey[4][i];
		nodes[5][i] = NewNodeKey[7][i];
		nodes[6][i] = NewNodeKey[9][i];
		nodes[7][i] = NewNodeKey[6][i];
		nodes[8][i] = NewNodeKey[0][i];
	}
	n1 = (Node*) HT_Node_Ptr->lookup(&(nodes[8][0]));
	for (i = 0; i < DIMENSION; i++)
		coord[i] = *(n1->get_coord() + i);
	//neighbors

	for (i = 0; i < KEYLENGTH; i++) {
		neigh[0][i] = neigh[4][i] = *(orig_neighbors + i); //Why is this ok if not ok for 3 down
		neigh[1][i] = neigh[5][i] = NewNodeKey[1][i];
		neigh[2][i] = neigh[6][i] = NewNodeKey[3][i];
		if (*(EmTemp->get_neigh_proc() + 7) != -2)
			neigh[3][i] = neigh[7][i] = *(orig_neighbors + 7 * KEYLENGTH + i); //This should be okay no matter what
		else
			neigh[3][i] = neigh[7][i] = *(orig_neighbors + 3 * KEYLENGTH + i); //This is only ok if neigh_proc==-2
	}

	//process of the neighbors

	neigh_proc[0] = *(orig_neigh_proc);
	neigh_proc[1] = myid;
	neigh_proc[2] = myid;
	if (*(orig_neigh_proc + 7) != -2)
		neigh_proc[3] = *(orig_neigh_proc + 7); //depending if the neighboring element is already refined
	else
		neigh_proc[3] = *(orig_neigh_proc + 3);

	neigh_proc[4] = neigh_proc[5] = neigh_proc[6] = neigh_proc[7] = -2;

	neigh_gen[0] = *orig_neigh_gen;
	neigh_gen[1] = generation;
	neigh_gen[2] = generation;
	neigh_gen[3] = *(orig_neigh_gen + 3);

	double err = (*(EmTemp->get_el_error())) * .5; //added by jp oct11

	// son 0 can use elm_loc
	int iwetnodefather = EmTemp->get_iwetnode();
	double Awetfather = EmTemp->get_Awet();
	double dpson[2];
	dpson[0] = *(EmTemp->get_drypoint() + 0) * 2 + 0.5;
	dpson[1] = *(EmTemp->get_drypoint() + 1) * 2 + 0.5;
	Quad9P = new T(nodes, neigh, neigh_proc, generation, elm_loc, neigh_gen, material, EmTemp, coord,
	    HT_Elem_Ptr, HT_Node_Ptr, myid, matprops_ptr, iwetnodefather, Awetfather, dpson);
	double* state_vars = Quad9P->get_state_vars();

	Quad9P->put_which_son(0);  //--by jp, 0 means son 0

	T* old_elm = (T*) HT_Elem_Ptr->lookup(Quad9P->pass_key());
	if (old_elm != NULL) {
		old_elm->put_adapted_flag(TOBEDELETED); //this line shouldn't be necessary just being redundantly careful
		HT_Elem_Ptr->remove(old_elm->pass_key(), 1, stdout, myid, 16);
		delete old_elm;
	}

	HT_Elem_Ptr->add(nodes[8], Quad9P);

	//---1st new element---

	//the nodes

	for (i = 0; i < KEYLENGTH; i++) {
		nodes[0][i] = *(KeyTemp + 4 * KEYLENGTH + i);
		nodes[1][i] = *(KeyTemp + 1 * KEYLENGTH + i);
		nodes[2][i] = *(KeyTemp + 5 * KEYLENGTH + i);
		nodes[3][i] = *((EmTemp->pass_key()) + i);
		nodes[4][i] = NewNodeKey[5][i];
		nodes[5][i] = NewNodeKey[8][i];
		nodes[6][i] = NewNodeKey[10][i];
		nodes[7][i] = NewNodeKey[7][i];
		nodes[8][i] = NewNodeKey[1][i];
	}
	n1 = (Node*) HT_Node_Ptr->lookup(&(nodes[8][0]));
	for (i = 0; i < DIMENSION; i++)
		coord[i] = *(n1->get_coord() + i);

	//neighbors

	for (i = 0; i < KEYLENGTH; i++) {
		if (*(EmTemp->get_neigh_proc() + 4) != -2)
			neigh[0][i] = neigh[4][i] = *(orig_neighbors + 4 * KEYLENGTH + i); //this should be ok now matter what
		else
			neigh[0][i] = neigh[4][i] = *(orig_neighbors + 0 * KEYLENGTH + i); //this is only ok if neigh_proc==-2
		neigh[1][i] = neigh[5][i] = *(orig_neighbors + 1 * KEYLENGTH + i);
		neigh[2][i] = neigh[6][i] = NewNodeKey[2][i];
		neigh[3][i] = neigh[7][i] = NewNodeKey[0][i];

	}

	//process of the neighbors

	neigh_proc[0] = (*(orig_neigh_proc + 4) != -2) ? *(orig_neigh_proc + 4) : *(orig_neigh_proc);
	neigh_proc[1] = *(orig_neigh_proc + 1);
	neigh_proc[2] = myid;
	neigh_proc[3] = myid;

	neigh_proc[4] = neigh_proc[5] = neigh_proc[6] = neigh_proc[7] = -2;

	neigh_gen[0] = *orig_neigh_gen;
	neigh_gen[1] = *(orig_neigh_gen + 1);
	neigh_gen[2] = generation;
	neigh_gen[3] = generation;

	my_elm_loc[0] = elm_loc[0] + 1;
	my_elm_loc[1] = elm_loc[1];
	dpson[0] = *(EmTemp->get_drypoint() + 0) * 2 - 0.5;
	dpson[1] = *(EmTemp->get_drypoint() + 1) * 2 + 0.5;
	Quad9P = new T(nodes, neigh, neigh_proc, generation, my_elm_loc, neigh_gen, material, EmTemp,
	    coord, HT_Elem_Ptr, HT_Node_Ptr, myid, matprops_ptr, iwetnodefather, Awetfather, dpson);
	state_vars = Quad9P->get_state_vars();

	Quad9P->put_which_son(1); //--by jp

	old_elm = (T*) HT_Elem_Ptr->lookup(Quad9P->pass_key());
	if (old_elm != NULL) {
		old_elm->put_adapted_flag(TOBEDELETED); //this line shouldn't be necessary just being redundantly careful

		HT_Elem_Ptr->remove(old_elm->pass_key(), 1, stdout, myid, 17);
		delete old_elm;
	}

	HT_Elem_Ptr->add(nodes[8], Quad9P);

	//---2nd new element---

	//the nodes

	for (i = 0; i < KEYLENGTH; i++) {
		nodes[0][i] = *((EmTemp->pass_key()) + i);
		nodes[1][i] = *(KeyTemp + 5 * KEYLENGTH + i);
		nodes[2][i] = *(KeyTemp + 2 * KEYLENGTH + i);
		nodes[3][i] = *(KeyTemp + 6 * KEYLENGTH + i);
		nodes[4][i] = NewNodeKey[10][i];
		nodes[5][i] = NewNodeKey[13][i];
		nodes[6][i] = NewNodeKey[15][i];
		nodes[7][i] = NewNodeKey[12][i];
		nodes[8][i] = NewNodeKey[2][i];
	}
	n1 = (Node*) HT_Node_Ptr->lookup(&(nodes[8][0]));
	for (i = 0; i < DIMENSION; i++)
		coord[i] = *(n1->get_coord() + i);

	//neighbors

	for (i = 0; i < KEYLENGTH; i++) {
		neigh[0][i] = neigh[4][i] = NewNodeKey[1][i];
		if (*(EmTemp->get_neigh_proc() + 5) != -2)
			neigh[1][i] = neigh[5][i] = *(orig_neighbors + 5 * KEYLENGTH + i); //This should be ok no matter what
		else
			neigh[1][i] = neigh[5][i] = *(orig_neighbors + 1 * KEYLENGTH + i); //this is only ok is neigh_proc==-2
		neigh[2][i] = neigh[6][i] = *(orig_neighbors + 2 * KEYLENGTH + i);
		neigh[3][i] = neigh[6][i] = NewNodeKey[3][i];

	}

	//process of the neighbors

	neigh_proc[0] = myid;
	neigh_proc[1] = (*(orig_neigh_proc + 5) != -2) ? *(orig_neigh_proc + 5) : *(orig_neigh_proc + 1);
	neigh_proc[2] = *(orig_neigh_proc + 2);
	neigh_proc[3] = myid;

	neigh_proc[4] = neigh_proc[5] = neigh_proc[6] = neigh_proc[7] = -2;

	neigh_gen[0] = generation;
	neigh_gen[1] = *(orig_neigh_gen + 1);
	neigh_gen[2] = *(orig_neigh_gen + 2);
	neigh_gen[3] = generation;

	my_elm_loc[0] = elm_loc[0] + 1;
	my_elm_loc[1] = elm_loc[1] + 1;
	dpson[0] = *(EmTemp->get_drypoint() + 0) * 2 - 0.5;
	dpson[1] = *(EmTemp->get_drypoint() + 1) * 2 - 0.5;
	Quad9P = new T(nodes, neigh, neigh_proc, generation, my_elm_loc, neigh_gen, material, EmTemp,
	    coord, HT_Elem_Ptr, HT_Node_Ptr, myid, matprops_ptr, iwetnodefather, Awetfather, dpson);
	state_vars = Quad9P->get_state_vars();

	Quad9P->put_which_son(2); //--by jp

	old_elm = (T*) HT_Elem_Ptr->lookup(Quad9P->pass_key());
	if (old_elm != NULL) {
		old_elm->put_adapted_flag(TOBEDELETED); //this line shouldn't be necessary just being redundantly careful

		HT_Elem_Ptr->remove(old_elm->pass_key(), 1, stdout, myid, 18);
		delete old_elm;
	}

	HT_Elem_Ptr->add(nodes[8], Quad9P);

	//---3rd new element---

	//the nodes

	for (i = 0; i < KEYLENGTH; i++) {
		nodes[0][i] = *(KeyTemp + 7 * KEYLENGTH + i);
		nodes[1][i] = *((EmTemp->pass_key()) + i);
		nodes[2][i] = *(KeyTemp + 6 * KEYLENGTH + i);
		nodes[3][i] = *(KeyTemp + 3 * KEYLENGTH + i);
		nodes[4][i] = NewNodeKey[9][i];
		nodes[5][i] = NewNodeKey[12][i];
		nodes[6][i] = NewNodeKey[14][i];
		nodes[7][i] = NewNodeKey[11][i];
		nodes[8][i] = NewNodeKey[3][i];
	}
	n1 = (Node*) HT_Node_Ptr->lookup(&(nodes[8][0]));
	for (i = 0; i < DIMENSION; i++)
		coord[i] = *(n1->get_coord() + i);

	//neighbors
	for (i = 0; i < KEYLENGTH; i++) {
		neigh[0][i] = neigh[4][i] = NewNodeKey[0][i];
		neigh[1][i] = neigh[5][i] = NewNodeKey[2][i];
		if (*(EmTemp->get_neigh_proc() + 6) != -2)
			neigh[2][i] = neigh[6][i] = *(orig_neighbors + 6 * KEYLENGTH + i);
		else
			neigh[2][i] = neigh[6][i] = *(orig_neighbors + 2 * KEYLENGTH + i);

		neigh[3][i] = neigh[6][i] = *(orig_neighbors + 3 * KEYLENGTH + i);

	}

	//process of the neighbors

	neigh_proc[0] = myid;
	neigh_proc[1] = myid;
	neigh_proc[2] = (*(orig_neigh_proc + 6) != -2) ? *(orig_neigh_proc + 6) : *(orig_neigh_proc + 2);
	neigh_proc[3] = *(orig_neigh_proc + 3);

	neigh_proc[4] = neigh_proc[5] = neigh_proc[6] = neigh_proc[7] = -2;

	neigh_gen[0] = generation;
	neigh_gen[1] = generation;
	neigh_gen[2] = *(orig_neigh_gen + 2);
	neigh_gen[3] = *(orig_neigh_gen + 3);

	my_elm_loc[0] = elm_loc[0];
	my_elm_loc[1] = elm_loc[1] + 1;
	dpson[0] = *(EmTemp->get_drypoint() + 0) * 2 + 0.5;
	dpson[1] = *(EmTemp->get_drypoint() + 1) * 2 - 0.5;
	Quad9P = new T(nodes, neigh, neigh_proc, generation, my_elm_loc, neigh_gen, material, EmTemp,
	    coord, HT_Elem_Ptr, HT_Node_Ptr, myid, matprops_ptr, iwetnodefather, Awetfather, dpson);
	state_vars = Quad9P->get_state_vars();

	Quad9P->put_which_son(3); //--by jp
	old_elm = (T*) HT_Elem_Ptr->lookup(Quad9P->pass_key());
	if (old_elm != NULL) {
		old_elm->put_adapted_flag(TOBEDELETED); //this line shouldn't be necessary just being redundantly careful

		HT_Elem_Ptr->remove(old_elm->pass_key(), 1, stdout, myid, 19);
		delete old_elm;
	}

	HT_Elem_Ptr->add(nodes[8], Quad9P);

	//---CHANGING THE FATHER---
	EmTemp->putson(&NewNodeKey[0][0]);
	// putting in brother info
	for (i = 0; i < 4; i++) {
		EmTemp = (T*) HT_Elem_Ptr->lookup(&NewNodeKey[i][0]);
		EmTemp->putbrothers(&NewNodeKey[0][0]); //was  EmTemp->putbrothers(&NewNodeKey[i][0]);
	}

	return;
}
Example #27
0
int main()
{
	int z,y;
	int te=65;
	printf("\nPlease enter the number of files:- ");
	scanf("%d",&nop);
	for(z=0;z<nop;z++)
	{
		proc[z]=(char)te;
		te=te+1;
		printf("\nPlease Enter the file %d size in blocks:- ",z+1);
		scanf("%d",&size[z]);
		flg[z]=0;
	}
	start=rear=NULL;
	int a,j,random,f=0;
	int min=1,max=30;
	for(y=0;y<nop;y++)
	{
	for(j=0;j<size[y];j++)
	{
		if(ctr<mem)
		{
		random=call(min,max);
		for(loop=0;loop<mapvar;loop++)
		{
			if(random==map[loop])
			{
				f=1;
				break;
			}
			else
			{
				f=0;
			}
		}
		if(f==1)
		{
			j=j-1;
			continue;
		}
		else
		{
			map[mapvar]=random;
			mapvar=mapvar+1;
		}
		newptr=create_new_node(random);
		insert(newptr);
		}
		else
		{
			printf("\nCaution: Memory Full\n");
			exit(0);
		}
	}
	flg[y]=1;
	begin[y]=start->no;
	end[y]=rear->no;
	disp(y);
	display(start);
	start=rear=NULL;
	}
	printf("Memory Nodes Number:- %d\n",ctr);
	return 0;
}