Beispiel #1
0
void
incumbent_update_and_prune(solution_t *s)
{
  int updated = 0;
  int index = 0;

  // update incumbent if the new solution is better, and it satisfies
  // all constraints
  //
  while (!updated &&
         index < num_requested_solutions) {

    if (debug) {
      printf("comparing s->total_weight=%f, incumbent_set[index].total_weight=%f\n",
             s->total_weight, incumbent_set[index].total_weight);
    }

    if (s->total_weight > incumbent_set[index].total_weight &&
        solution_validates_constraints(s)) {

      if (incumbent_count != 0) {
        for (int i = incumbent_count-1; i > index; i--) {
          incumbent_set[i] = incumbent_set[i-1];
        }
      }

      if (incumbent_count < num_requested_solutions) {
        incumbent_count++;
      }

      incumbent_set[index] = *s;
      updated = 1;
    }

    index++;
  }

  if (updated && debug) {
    for (int i = 0; i < incumbent_count; i++) {
      printf("%s: incumbent %d -> weight %1.3f, at depth %d\n",
             __FUNCTION__, i, incumbent_set[i].total_weight,
             incumbent_set[i].total_depth);
    }
  }

  // we are done with this branch
  //
  prune_branch(s);
}
bool pre_processing_main(const V3DPluginArgList & input, V3DPluginArgList & output)
{
	printf("welcome to pre_processing\n");


	vector<char*>* inlist = (vector<char*>*)(input.at(0).p);
	vector<char*>* outlist = NULL;
	vector<char*>* paralist = NULL;

	if(input.size() != 2) 
	{
		printf("Please specify parameter set.\n");
		printHelp_pre_processing();
		return false;
	}
	paralist = (vector<char*>*)(input.at(1).p);


	if (paralist->size()!=1)
	{
		printf("Please specify all paramters in one text string.\n");
		printHelp_pre_processing();
		return false;
	}
	
	
	char * paras = paralist->at(0);
	int argc = 1;
	enum {kArgMax = 64};
	char *argv[kArgMax];
	
	//parsing parameters
	if (paras)
	{
		int len = strlen(paras);
		for (int i=0;i<len;i++)
		{
			if (paras[i]=='#')
				paras[i] = '-';
		}

		char* pch = strtok(paras, " ");
		while (pch && argc<kArgMax)
		{
			argv[argc++] = pch;
			pch = strtok(NULL, " ");
		}
	}
	else
		printHelp_pre_processing();


	//read arguments

	char *dfile_input = NULL;
	char *dfile_result = NULL;
	char *outfile = NULL;
	double step_size = 2;
	int skip_rotation = 1;
	
	int c;
    static char optstring[]="i:o:s:r:";
	extern char * optarg;
	extern int optind, opterr;
		
	while ((c = getopt(argc, argv, optstring))!=-1)
	{
		switch (c)
		{
			case 'h':
				printHelp_pre_processing();
				return 0;
				break;
			case 'i':
				if (strcmp(optarg,"(null)")==0 || optarg[0]=='-')
				{
					fprintf(stderr, "Found illegal or NULL parameter for the option -l.\n");
					return 1;
				}
				dfile_input = optarg;
				break;
			case 'o':
				if (strcmp(optarg,"(null)")==0 || optarg[0]=='-')
				{
					fprintf(stderr, "Found illegal or NULL parameter for the option -o.\n");
					return 1;
				}
				dfile_result = optarg;
				break;
			case 'r':
				if (strcmp(optarg,"(null)")==0 || optarg[0]=='-')
				{
					fprintf(stderr, "Found illegal or NULL parameter for the option -o.\n");
					return 1;
				}
				skip_rotation = atoi(optarg);
				break;
			case 's':
				if (strcmp(optarg,"(null)")==0 || optarg[0]=='-')
				{
					fprintf(stderr, "Found illegal or NULL parameter for the option -s.\n");
					return 1;
				}
				step_size = atof(optarg);
				if (step_size<=0)
				{
					fprintf(stderr, "Illegal step size. It must>0.\n");
				}
				break;
			case '?':
				fprintf(stderr,"Unknown option '-%c' or incomplete argument lists.\n",optopt);
				return 1;
				break;
		}
	}


	QString qs_input(dfile_input);
	NeuronTree nt = readSWC_file(qs_input);
	QString outfileName = QString(dfile_result);
	if (dfile_result==NULL)
	{
		outfileName = qs_input+"_preprocessed.swc";
	}

	printf("Pruning short branches\n");
	NeuronTree pruned;
	if (!prune_branch(nt, pruned))
	{
		fprintf(stderr,"Error in prune_short_branch.\n");
		return 1;
	}

	printf("Resampling along segments\n");
	NeuronTree resampled = resample(pruned, step_size);
	
	NeuronTree result;
	if (skip_rotation!=1)
	{
		printf("Aligning PCA axis\n");
		result = align_axis(resampled);
	}
	else
		result = resampled;
	if (export_listNeuron_2swc(result.listNeuron,qPrintable(outfileName)))
		printf("\t %s has been generated successfully.\n",qPrintable(outfileName));

	return 1;
}