void
creat_file()
{
    int dev;
    u32 ino;
    char* parent;
    char* child;
    MINODE* pip;

    if ('/' == pathName[0])
    {
        dev = root->dev;
    }
    else
    {
        dev = running->cwd->dev;
    }

    parent = dir_name(pathName);
    child = base_name(pathName);

    if (0 == strcmp(child, "."))
    {
        printf("creat : provide a file name\n");
        return;
    }
    ino = getino(&dev, parent);
    pip = iget(dev, ino);

    // verify parent INODE is a DIR and child does not exist in the parent dir
    if ((0040000 == (pip->INODE.i_mode & 0040000)) && (0 == is_exist(pip, child)))
    {
        my_creat(pip, child);
    }
}
Example #2
0
t_result		*algo_result(t_result *r, t_tetrim *t, t_result *res)
{
	int			x;
	int			y;
	t_result	*tmp;

	x = -1;
	y = -1;
	while (++x < r->size)
	{
		while (++y < r->size)
		{
			if (is_exist(r, t, x, y))
			{
				tmp = place_tetrim(r, t, x, y);
				if (t->next)
					res = algo_result(tmp, t->next, res);
				else if (!t->next)
					return (add_result(res, tmp, r->size));
				if (res)
					return (res);
			}
		}
		y = -1;
	}
	return (new_result(r, t, res));
}
Example #3
0
int downloadtable_addnode(dNode* node){
	if(is_exist(node)>0){
		printf("Download table addnode fail: node already exist\n");
		return -1;
	}
	dNode* tmp=dtable->file;
	int i;
	for(i=0;i<dtable->dfilenum-1;i++){
		tmp=tmp->pNext;
	}
	dNode* tmpnode=(dNode*)malloc(sizeof(dNode));
	memset(tmpnode,0,sizeof(dNode));
	memcpy(tmpnode->name,node->name,strlen(node->name));
	tmpnode->size=node->size;
	tmpnode->timestamp=node->timestamp;
	tmpnode->pNext=NULL;
	if(tmp!=NULL){
		tmp->pNext=tmpnode;
	}
	else{
		dtable->file=tmpnode;
	}
	dtable->dfilenum++;
	return 1;
}
Example #4
0
void get_requested_file_info(const char * recv_buffer,uufile_t *fileinfo)
{
    char    visit_file_name_local[VISIT_FILE_NAME]={0,};
    char          visit_file_argv[VISIT_FILE_ARGV]={0,};
    get_visit_file_name_and_argv(recv_buffer,visit_file_name_local,visit_file_argv,VISIT_FILE_ARGV); 

    if( 0 != strlen(visit_file_argv)){
        strncpy(fileinfo->argv,visit_file_argv,ARGV_STRING_MAX);
    }

    strncpy(fileinfo->name,"www/",VISIT_FILE_NAME);
    if( 0 == strlen(visit_file_name_local)){
        strncat(fileinfo->name,"index.html",VISIT_FILE_NAME);
    }
    else{
        strncat(fileinfo->name,visit_file_name_local,VISIT_FILE_NAME);
    }
    if( FILE_NOT_EXIST == is_exist(fileinfo->name)){
        strncpy(fileinfo->name,"www/notfound.html",VISIT_FILE_NAME);
    }
    printf("all file name is: %s\n",fileinfo->name);

    fileinfo->type = get_file_type(fileinfo->name);
    fileinfo->size = get_file_size(fileinfo->name); 
}
Example #5
0
/**
 * @brief 
 *  压栈,counter+1
 * @param Ele
 *  压入的元素,  注意元素的范围是“0-max_size-1”
 * @return 成功1,失败0
 */
int  push(Ele ele)
{
    if(is_exist(ele) || is_full() )   return 0;
    stack[counter++] = ele;
    index[ele] = 1;             //标记元素存在
    printf("sizeof[index]=%d\n", sizeof(&index[0]));

    return 1;
}
Example #6
0
int	setenv_flag(t_tab *tab, t_btree **tree)
{
  int	i;

  i = -1;
  while ((*tree)->right->stock[++i]);
  if (i != 3)
    {
      write(2, "USAGE: setenv [NAME] [WORDS]\n", 29);
      return (-1);
    }
  is_exist(tab, tree);
  my_setenv(tab, tree);
  return (0);
}
Example #7
0
// ------ begin of function SerialRepository::add_unique --------//
// return true if newly added
int SerialRepository::add_unique(long num)
{
	if( max_history <= 0 )
		return 0;

	if( !is_exist(num) )
	{
		add( num );
		return 1;
	}
	else
	{
		return 0;
	}
}
int create(struct inode *dir, const char *name, int len, int mode, struct inode ** res_inode){
	/*判断目录是否有效*/
	if(dir->ext2_inode.i_block[0] != UINT_MAX){
		perror("inode_operations.c: create error! dir is a file!\n");
		return -1;
	}
	/*判断名字是否有效*/
	if(checkname(name) == -1){
		perror("inode_operations.c: create error! filename is illegal!\n");
		return -1;
	}
	/*判断是否已存在*/
	if(is_exist(dir,name) == 1){
		perror("inode_operations.c: create error! file is alreay exists!\n");
		return -1;
	}
	char buf[BLOCK_SIZE];
	struct ext2_dir_entry_2 *pentry;
	int dir_datablocks = dir->ext2_inode.i_blocks;/*数据块个数*/
	int i = 1;
	int num = BLOCK_SIZE/sizeof(struct ext2_dir_entry_2);
	while(i <= dir_datablocks){
		/*取出目录节点中第i块逻辑块所在的物理块的数据,放入buf*/
		get_block_data(dir->ext2_inode.i_block[i],buf);
		pentry = (struct ext2_dir_entry_2 *)buf;
		/*寻找pentry->inode为0的每一项,表示未使用,填写目录项*/
		//printf("inode_operations.c: create : dir_datablocks: %d\n",i);
		int j = 0;
		while(j<num){
			//printf("inode_operations.c: create : entry: %d\n",j);
			if(!pentry->inode){
				pentry->name_len = len;
				strcpy(pentry->name,name);
				pentry->file_type = mode;
				pentry->rec_len = 8 + len;
				pentry->inode = new_inode();
				write_block_data(dir->ext2_inode.i_block[i],buf);//更新该数据块
				*res_inode=(struct inode *)malloc(sizeof(struct inode));
				if(*res_inode != NULL){
					get_inode_data(pentry->inode,*res_inode);
					return 1;
				}
			}
			j++;
			pentry++;
		}
		i++;
	}
	/*数据块表项已满,则需申请新的数据块来存放新的目录项*/
	if(dir_datablocks>=14){
		perror("inode_operations.c create error! dir_entry is full,no more sub_dir!\n");
		return -1;
	}
	dir_datablocks = ++(dir->ext2_inode.i_blocks);
	dir->ext2_inode.i_block[dir_datablocks] = new_block();
	write_inode_data(dir->i_number,dir);//因为申请了新块,inode节点及时更新

	get_block_data(dir->ext2_inode.i_block[dir_datablocks],buf);
	pentry = (struct ext2_dir_entry_2 *)buf;
	pentry->name_len = len;
	strcpy(pentry->name,name);
	pentry->file_type = mode;
	pentry->rec_len = 8 + len;
	pentry->inode = new_inode();
	write_block_data(dir->ext2_inode.i_block[dir_datablocks],buf);//更新该数据块
	if((*res_inode=(struct inode *)malloc(sizeof(struct inode))) != NULL){
		get_inode_data(pentry->inode,*res_inode);
		return 1;
	}
	return -1;
}
int mkdir(struct inode *dir, const char *name, int len, int mode){
	/*判断目录是否有效*/
	if(dir->ext2_inode.i_block[0] != UINT_MAX){
		perror("inode_operations.c: mkdir error! dir is a file!\n");
		return -1;
	}
	/*判断名字是否有效*/
	if(checkname(name) == -1){
		perror("inode_operations.c: mkdir error! dirname is illegal!\n");
		return -1;
	}
	/*判断是否已存在*/
	if(is_exist(dir,name) == 1){
		perror("inode_operations.c: mkdir error! dirname is alreay exists!\n");
		return -1;
	}
	char buf[BLOCK_SIZE];
	struct inode *m_inode;
	struct ext2_dir_entry_2 *pentry;
	int dir_datablocks = dir->ext2_inode.i_blocks;/*数据块个数*/
	int i = 1;
	int num = BLOCK_SIZE/sizeof(struct ext2_dir_entry_2);
	while(i <= dir_datablocks){
		/*取出目录节点中第i块逻辑块所在的物理块的数据,放入buf*/
		get_block_data(dir->ext2_inode.i_block[i],buf);
		pentry = (struct ext2_dir_entry_2 *)buf;
		
		/*寻找pentry->inode为0的每一项,表示未使用*/
		int j = 0;
		while(j<num){
			if(!pentry->inode){
				pentry->name_len = len;
				strcpy(pentry->name,name);
				pentry->file_type = mode;
				pentry->rec_len = 8 + len;
				pentry->inode = new_inode();
				write_block_data(dir->ext2_inode.i_block[i],buf);//更新该数据块
				/*下面更新为目录项(文件夹)申请的inode节点信息,并为其预分配一块数据块,用于存放子目录或文件*/
				if((m_inode=(struct inode*)malloc(sizeof(struct inode))) != NULL){
					get_inode_data(pentry->inode,m_inode);
					m_inode->ext2_inode.i_block[0] = UINT_MAX;//表示该节点是目录节点
					m_inode->ext2_inode.i_block[1] = new_block();//为每个目录节点预分配一块数据块,存放目录项
					m_inode->ext2_inode.i_blocks = 1;		
					write_inode_data(pentry->inode,m_inode);
					free(m_inode);
					return 1;
				}
			}
			j++;
			pentry++;
		}
		i++;
	}
	/*数据块表项已满,则需申请新的数据块来存放新的目录项*/
	if(dir_datablocks>=14){
		perror("inode_operations.c mkdir error! dir_entry is full,no more sub_dir!\n");
		return -1;
	}
	dir_datablocks = ++dir->ext2_inode.i_blocks;
	dir->ext2_inode.i_block[dir_datablocks] = new_block();
	write_inode_data(dir->i_number,dir);//因为申请了新块,inode节点及时更新

	get_block_data(dir->ext2_inode.i_block[dir_datablocks],buf);
	pentry = (struct ext2_dir_entry_2 *)buf;
	pentry->name_len = len;
	strcpy(pentry->name,name);
	pentry->file_type = mode;
	pentry->rec_len = 8 + len;
	pentry->inode = new_inode();
	write_block_data(dir->ext2_inode.i_block[dir_datablocks],buf);//更新该数据块
	
	if((m_inode=(struct inode*)malloc(sizeof(struct inode))) != NULL){
		get_inode_data(pentry->inode,m_inode);
		m_inode->ext2_inode.i_block[0] = UINT_MAX;//表示该节点是目录节点
		m_inode->ext2_inode.i_block[1] = new_block();//为每个目录节点预分配一块数据块,存放目录项
		m_inode->ext2_inode.i_blocks = 1;		
		write_inode_data(pentry->inode,m_inode);
		free(m_inode);
		return 1;
	}

	return -1;
}
Example #10
0
/**
 * Main optimization loop
 * @param essProblem Contains all the variables needed by eSS
 * @param inp        Objective function `inp` struct
 * @param out        Objective function `out` struct
 */
void run_eSS(eSSType *eSSParams, void *inp, void *out){


	int label[eSSParams->n_refSet];				/*!< Uses to store the index of Individuals that should be replaced with their children. */
	memset(label, 0, eSSParams->n_refSet * sizeof(int));
	
	int candidate_index;						/*!< Store the index of candidate for replacement after recombination. */
	int n_currentUpdated;						/*!< Counter for all updated solutions either from recombination or goBeyond procedure. */
	int archive_index = 0;						/*!< Track the index of `archiveSet` for storing the best solutions found. */				



	/**
	 * It sets to 0 at first, and then increments until it hits the 100. Because we don't wanted
	 * to spend time and checking archive members that are not already assigned!
	 */
	eSSParams->archiveSet->size = 0;

	for (eSSParams->iter = 1; eSSParams->iter < eSSParams->max_iter; ++eSSParams->iter)
	{
		n_currentUpdated = 0;
		// int i_lCandidate = 0;
		for (int i = 0; i < eSSParams->n_refSet; ++i)
		{
			/**
			 * Generate a candidate set by combining the `i`th member of the refSet and returning
			 * the best candidate with respect to it's cost.
			 */
			candidate_index = recombine(eSSParams, &(eSSParams->refSet->members[i]), i, inp, out);

			if (-1 != candidate_index){
				
				eSSParams->stats->n_successful_recombination++;

				label[i] = 1;
				n_currentUpdated++;

				/**
				 * Copy the selected candidate into the childSet
				 */
				copy_Ind(eSSParams, &(eSSParams->childsSet->members[i]), &(eSSParams->candidateSet->members[candidate_index]));

				/**
				 * goBeyond for already selected candidate from recombinedSet which is copied to 
				 * the childsSet too. Note that the goBeyond function works with childsSet so it 
				 * need the `i` as a index not the `candidate_index`
				 */
				if (eSSParams->goBeyond_freqs != 0 && (eSSParams->iter % eSSParams->goBeyond_freqs == 0))
					goBeyond(eSSParams, i, inp, out);

				/**
				 * TODO: Implement the local search selection routine as described in the paper
				 */
				// copy_Ind(eSSParams, &(eSSParams->localSearchCandidateSet->members[i_lCandidate]), &(eSSParams->childsSet->members[i]));
				// i_lCandidate++;
				// eSSParams->localSearchCandidateSet->size = i_lCandidate;

				/**
				 * Check if the local search is activated and it is not activated only for best
				 * sol, if so, then check if it's a right moment to run the local search based on
				 * n1, and n2 values.
				 * Note that the local search won't apply here if it meant to apply only on best
				 * sol.
				 */
				if ( (eSSParams->perform_local_search && !eSSParams->local_onBest_Only) 
					 && ( (eSSParams->iter > eSSParams->local_N1) || ( eSSParams->iter % eSSParams->local_N2 == 0 ) ) )
					{
						/**
						 * This check will prevent the local search operation if the cost of the Individual
						 * is greater than some value.
						 */
						if (eSSParams->childsSet->members[i].cost < eSSParams->local_minCostCriteria ){
							/**
							 * Check if the selected child is close to the area that already the 
							 * local search applied on it or not
							 */
							///////////////////////////////////////
							///		  Flatzone Detection 	///
							///////////////////////////////////////	
							if (eSSParams->perform_flatzone_check){
								if ( !is_in_flatzone(eSSParams, eSSParams->refSet, &(eSSParams->childsSet->members[i])) ){
									goto local_search;

									local_search:
										if ( -1 == is_exist(eSSParams, eSSParams->archiveSet, &(eSSParams->childsSet->members[i])) )
										 {
											if (eSSParams->local_SolverMethod == 'n'){
												neldermead_localSearch(eSSParams, &(eSSParams->childsSet->members[i]), inp, out);
												eSSParams->stats->n_local_search_performed++;
											}else if (eSSParams->local_SolverMethod == 'l'){
												levmer_localSearch(eSSParams, &(eSSParams->childsSet->members[i]), inp, out);
												eSSParams->stats->n_local_search_performed++;
											}
										}else{
											eSSParams->stats->n_duplicate_found++;
										}
								}
							}else{
								goto local_search;
							}
						}
					}
			}

		}

		/**
		 * Update the refSet Individual based on the indexes flagged in `label`, if the n_stuck is
		 * greater than the max_stuck then the Individual will add to the archiveSet and then randomizes and n_not_randomized and all it's statistics will set to zero.
		 */
		for (int i = 0; i < eSSParams->n_refSet; ++i)
		{
			/**
			 * If an Individual marked, it will replace by its improved child
			 */
			if (label[i] == 1){
				/**
				 * Check if the candidate is very close to a member of a refSet, if so, then randomize the 
				 * duplicated members in refSet.
				 */
				int duplicate_index = is_exist(eSSParams, eSSParams->refSet, &(eSSParams->childsSet->members[i]));
				if ((duplicate_index != -1) && (duplicate_index != i) && (duplicate_index != 0)){
					eSSParams->stats->n_duplicate_found++;
					// TODO: I can do this better by picking a random value based on the frequency matrix; then I can promote areas that are not discovered enough yet.
					random_Ind(eSSParams, &(eSSParams->refSet->members[duplicate_index]), eSSParams->min_real_var, eSSParams->max_real_var);
					evaluate_Individual(eSSParams, &(eSSParams->refSet->members[duplicate_index]), inp, out);
				}

				/**
				 * Replace the parent with its better child! If it does pass the flatzone_detection_test
				 */
				if (eSSParams->perform_flatzone_check){
                  // todo: maybe i dont need to check this again since i already did it above then i wanted to perform the local search but if the local search is not active the i have to do it.
					if (!is_in_flatzone(eSSParams, eSSParams->refSet, &(eSSParams->childsSet->members[i])))
					{
						goto replace;

						replace:
							eSSParams->refSet->members[i].n_not_randomized++;
							copy_Ind(eSSParams, &(eSSParams->refSet->members[i]), &(eSSParams->childsSet->members[i]));
							eSSParams->refSet->members[i].n_stuck = 0;
					}
				}else{
					goto replace;
				}

				label[i] = 0;
			}else{
				/**
				 * Otherwise, the Individual randomzies and all of it's stats and counters set
				 * to 0. If the flag `perform_elite_presevation` is set true then the first `mac_preserve_elite` will
				 * be preserved in the refSet.
				 */
				eSSParams->refSet->members[i].n_stuck++;
				if (eSSParams->refSet->members[i].n_stuck > eSSParams->max_stuck
						&& (eSSParams->iter % eSSParams->n_randomization_Freqs == 0 ) 
							&& !( eSSParams->perform_elite_preservation && !(i > eSSParams->max_preserve_elite)) )
					{

					/* Add the stuck Individual to the archiveSet */
					if (archive_index == eSSParams->n_archiveSet)
						archive_index = 0;

					if ((archive_index < eSSParams->n_archiveSet) 
							&& (eSSParams->archiveSet->size < eSSParams->n_archiveSet))
						eSSParams->archiveSet->size++;
					
					copy_Ind(eSSParams, &(eSSParams->archiveSet->members[archive_index]), &(eSSParams->refSet->members[i]));
					archive_index++;

					/**
					 * Randomize the stuck refSet member.
					 */
					random_Ind(eSSParams, &(eSSParams->refSet->members[i]), 
										eSSParams->min_real_var, eSSParams->max_real_var);

					evaluate_Individual(eSSParams, &(eSSParams->refSet->members[i]), inp, out);

					/* Store number of all the stuck parameters. */
					eSSParams->stats->n_total_stuck++;
					eSSParams->refSet->members[i].n_not_randomized = 0;
					eSSParams->refSet->members[i].n_stuck = 0;
				}
				label[i] = 0;
			}
		}

		quickSort_Set(eSSParams, eSSParams->refSet, 0, eSSParams->n_refSet - 1, 'c');

		/**
		 * Apply the local search on the best solution
		 * The last condition avoid performing local search on solutions that are stuck, since
		 * the local search algorithm couldn't keep the parameters in boundary so, we have to stop
		 * over-applying it on solutions before make them really far from defined box constratins.
		 */
		if (eSSParams->perform_local_search 
				&& eSSParams->local_onBest_Only 
					&& (eSSParams->best->cost < eSSParams->local_minCostCriteria)
						&& eSSParams->best->n_stuck < eSSParams->max_stuck)		// avoid performing local search on the best solution which is stuck for a long time
		{
			neldermead_localSearch(eSSParams, eSSParams->best, inp, out);
			eSSParams->stats->n_local_search_performed++;
		}

		if (eSSParams->iter % eSSParams->save_freqs == 0){
			write_Set(eSSParams, eSSParams->refSet, refSet_history_file, eSSParams->iter);
			write_Ind(eSSParams, eSSParams->best, best_sols_history_file, eSSParams->iter);
		}

		/**
		 * Check if the best solution found is enough to the predicted solution. Usually this is
		 * not a good way to check the convergence of stochastic method but it the problem wasn't
		 * a multi-models problem then it saves a lot of unnecessary iterations.
		 */
		if (eSSParams->perform_cost_tol_stopping && 
			 	fabs( eSSParams->best->cost - eSSParams->sol ) < eSSParams->cost_tol ){
			printf("%s\n", KRED);
			printf("Best Solutions converged after %d iterations\n", eSSParams->iter);
			printf("%s\n", KNRM);
			break;
		}

		/**
		 * Check the difference between the cost of best solution and worst solution in the 
		 * refSet. This might not always be the indication of the convergence but it might be 
		 * the indication of saturated referenceSet.
		 */
		// if ( eSSParams->perform_refSet_convergence_stopping && 
		// 		fabs( eSSParams->refSet->members[0].cost - fabs(eSSParams->refSet->members[eSSParams->n_refSet - 1].cost)) < eSSParams->refSet_convergence_tol ){
		// 	printf("Converged or Stuck after %d iteration!\n", eSSParams->iter);
		// 	break;
		// }

		/**
		 * Compute the mean and standard deviation of the set in order to decide if the 
		 * randomization should be applied or not.
		 */
		
		if (eSSParams->compute_Set_Stats){

			compute_SetStats(eSSParams, eSSParams->refSet);

			fprintf(ref_set_stats_history_file, "%lf\t%lf\n", eSSParams->refSet->mean_cost, eSSParams->refSet->std_cost);

			/**
			 * Check if the standard deviation of the set is small and the number of 
			 * updatedMembers is less than 1/4 of the n_refSet then randomize the refSet.
			 * After randomization all the n_not_randomized values of refSet Individual will
			 * set to 0.
			 */
			if (eSSParams->perform_refSet_randomization && 
					eSSParams->refSet->std_cost < eSSParams->refSet_std_tol && n_currentUpdated < (eSSParams->n_refSet / 4)){
				/**
				 * Replace the last max_delete members of the refSet with the newly 
				 * randomized solutions in and sort the refSet at the end of the replacement.
				 */
				for (int i = eSSParams->refSet->size - 1; i > eSSParams->refSet->size - eSSParams->max_delete; --i)
				{
					random_Ind(eSSParams, &(eSSParams->refSet->members[i]), eSSParams->min_real_var, eSSParams->max_real_var);
					evaluate_Individual(eSSParams, &(eSSParams->refSet->members[i]), inp, out);
				}
				quickSort_Set(eSSParams, eSSParams->refSet, 0, eSSParams->refSet->size - 1, 'c');
				eSSParams->stats->n_refSet_randomized++;
			}
			
			// update_IndsStats(eSSParams, eSSParams->refSet);
          // todo: i can remove this, i dont do anything with it.
		}	
      


		if (eSSParams->iter % eSSParams->print_freqs == 0){
			print_Stats(eSSParams);
		}


		write_Stats(eSSParams, stats_file);
	}

	printf("Final refSet: \n");
	print_Set(eSSParams, eSSParams->refSet);

	printf("bestSol: \n");
	print_Ind(eSSParams, eSSParams->best);
	print_Stats(eSSParams);

	/**
	 * Performing the local search on the bestSol.
	 */
	if (eSSParams->perform_local_search && eSSParams->local_atEnd && !eSSParams->local_onBest_Only)
	{
		printf("Perforimg the last local search\n");
		if (eSSParams->local_SolverMethod == 'n')
			neldermead_localSearch(eSSParams, eSSParams->best, inp, out);
		else
			levmer_localSearch(eSSParams, eSSParams->best, inp, out);
	
		printf("Final Result: \n");
		print_Ind(eSSParams, eSSParams->best);
	}

	refSet_final_file     = fopen("ref_set_final.csv", "w");
	write_Set(eSSParams, eSSParams->refSet, refSet_final_file, -1);
	write_Set(eSSParams, eSSParams->archiveSet, archive_set_file, -1);
	write_Ind(eSSParams, eSSParams->best, best_sols_history_file, eSSParams->max_iter);	
	printf("ref_set_final.csv, ref_set_history_file.out, best_sols_history_file.out, and stats_file is generated. \n");


	fclose(refSet_final_file);
	fclose(best_sols_history_file);
	fclose(stats_file);
	// fclose(file)



}
Example #11
0
		bool is_exist(PCWSTR priv_name)
		{
			return is_exist(WinToken(), priv_name);
		}
Example #12
0
		bool is_exist(const LUID & priv)
		{
			return is_exist(WinToken(), priv);
		}
Example #13
0
		bool is_exist(HANDLE token, PCWSTR priv_name)
		{
			return is_exist(token, as_luid(priv_name));
		}
		bool is_exist(const wchar_t* priv_name)
		{
			return is_exist(Token(), priv_name);
		}
		bool is_exist(HANDLE token, const wchar_t* priv_name)
		{
			return is_exist(token, as_luid(priv_name));
		}